These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use SMW\ApplicationFactory; |
||
4 | use SMW\DIProperty; |
||
5 | |||
6 | /** |
||
7 | * @ingroup SMWDataValues |
||
8 | */ |
||
9 | |||
10 | /** |
||
11 | * This datavalue implements special processing suitable for defining |
||
12 | * wikipages as values of properties. |
||
13 | * |
||
14 | * The class can support general wiki pages, or pages of a fixed |
||
15 | * namespace, Whether a namespace is fixed is decided based on the |
||
16 | * type ID when the object is constructed. |
||
17 | * |
||
18 | * The short display simulates the behavior of the MediaWiki "pipe trick" |
||
19 | * but always includes fragments. This can be overwritten by setting a |
||
20 | * caption, which is also done by default when generating a value from user |
||
21 | * input. The long display always includes all relevant information. Only if a |
||
22 | * fixed namespace is used for the datatype, the namespace prefix is omitted. |
||
23 | * This behavior has changed in SMW 1.7: up to this time, short displays have |
||
24 | * always inlcuded the namespace and long displays used the pipe trick, leading |
||
25 | * to a paradoxical confusion of "long" and "short". |
||
26 | * |
||
27 | * @author Nikolas Iwan |
||
28 | * @author Markus Krötzsch |
||
29 | * @ingroup SMWDataValues |
||
30 | */ |
||
31 | class SMWWikiPageValue extends SMWDataValue { |
||
32 | |||
33 | /** |
||
34 | * Fragment text for user-specified title. Not stored, but kept for |
||
35 | * printout on page. |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $m_fragment = ''; |
||
39 | |||
40 | /** |
||
41 | * Full titletext with prefixes, including interwiki prefix. |
||
42 | * Set to empty string if not computed yet. |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $m_prefixedtext = ''; |
||
46 | |||
47 | /** |
||
48 | * Cache for the related MW page ID. |
||
49 | * Set to -1 if not computed yet. |
||
50 | * @var integer |
||
51 | */ |
||
52 | protected $m_id = -1; |
||
53 | |||
54 | /** |
||
55 | * Cache for the related MW title object. |
||
56 | * Set to null if not computed yet. |
||
57 | * @var Title |
||
58 | */ |
||
59 | protected $m_title = null; |
||
60 | |||
61 | /** |
||
62 | * If this has a value other than NS_MAIN, the datavalue will only |
||
63 | * accept pages in this namespace. This field is initialized when |
||
64 | * creating the object (based on the type id or base on the preference |
||
65 | * of some subclass); it is not usually changed afterwards. |
||
66 | * @var integer |
||
67 | */ |
||
68 | protected $m_fixNamespace = NS_MAIN; |
||
69 | |||
70 | 175 | public function __construct( $typeid ) { |
|
71 | 175 | parent::__construct( $typeid ); |
|
72 | switch ( $typeid ) { |
||
73 | 175 | case '__typ': |
|
74 | $this->m_fixNamespace = SMW_NS_TYPE; |
||
75 | break; |
||
76 | 175 | case '_wpp' : case '__sup': |
|
77 | 4 | $this->m_fixNamespace = SMW_NS_PROPERTY; |
|
78 | 4 | break; |
|
79 | 174 | case '_wpc' : case '__suc': case '__sin': |
|
80 | 25 | $this->m_fixNamespace = NS_CATEGORY; |
|
81 | 25 | break; |
|
82 | 169 | case '_wpf' : case '__spf': |
|
83 | $this->m_fixNamespace = SF_NS_FORM; |
||
84 | break; |
||
85 | default: // case '_wpg': |
||
86 | 169 | $this->m_fixNamespace = NS_MAIN; |
|
87 | } |
||
88 | 175 | } |
|
89 | |||
90 | 124 | protected function parseUserValue( $value ) { |
|
91 | 124 | global $wgContLang; |
|
0 ignored issues
–
show
|
|||
92 | |||
93 | // support inputs like " [[Test]] "; |
||
94 | // note that this only works in pages if $smwgLinksInValues is set to true |
||
95 | 124 | $value = ltrim( rtrim( $value, ' ]' ), ' [' ); |
|
96 | |||
97 | // #1066, Manipulate the output only for when the value has no caption |
||
98 | // assigned and only if a single :Foo is being present, ::Foo is not permitted |
||
99 | 124 | if ( $this->m_caption === false && isset( $value[2] ) && $value[0] === ':' && $value[1] !== ':' ) { |
|
100 | 7 | $value = substr( $value, 1 ); |
|
101 | } |
||
102 | |||
103 | 124 | if ( $this->m_caption === false ) { |
|
104 | 124 | $this->m_caption = $value; |
|
105 | } |
||
106 | |||
107 | 124 | if ( $value !== '' ) { |
|
108 | 124 | if ( $value[0] == '#' ) { |
|
109 | if ( is_null( $this->m_contextPage ) ) { |
||
110 | $this->addError( wfMessage( 'smw_notitle', $value )->inContentLanguage()->text() ); |
||
111 | return; |
||
112 | } else { |
||
113 | $this->m_title = Title::makeTitle( $this->m_contextPage->getNamespace(), |
||
114 | $this->m_contextPage->getDBkey(), substr( $value, 1 ), |
||
115 | $this->m_contextPage->getInterwiki() ); |
||
116 | } |
||
117 | } else { |
||
118 | 124 | $this->m_title = Title::newFromText( $value, $this->m_fixNamespace ); |
|
119 | } |
||
120 | |||
121 | /// TODO: Escape the text so users can see punctuation problems (bug 11666). |
||
122 | 124 | if ( is_null( $this->m_title ) ) { |
|
123 | 5 | $this->addError( wfMessage( 'smw_notitle', $value )->inContentLanguage()->text() ); |
|
124 | 124 | } elseif ( ( $this->m_fixNamespace != NS_MAIN ) && |
|
125 | 124 | ( $this->m_fixNamespace != $this->m_title->getNamespace() ) ) { |
|
126 | $this->addError( wfMessage( 'smw_wrong_namespace', |
||
127 | $wgContLang->getNsText( $this->m_fixNamespace ) )->inContentLanguage()->text() ); |
||
128 | } else { |
||
129 | 124 | $this->m_fragment = str_replace( ' ', '_', $this->m_title->getFragment() ); |
|
130 | 124 | $this->m_prefixedtext = ''; |
|
131 | 124 | $this->m_id = -1; // unset id |
|
132 | 124 | $this->m_dataitem = SMWDIWikiPage::newFromTitle( $this->m_title, $this->m_typeid ); |
|
133 | } |
||
134 | } else { |
||
135 | $this->addError( wfMessage( 'smw_notitle', $value )->inContentLanguage()->text() ); |
||
136 | } |
||
137 | 124 | } |
|
138 | |||
139 | /** |
||
140 | * @see SMWDataValue::loadDataItem() |
||
141 | * @param $dataitem SMWDataItem |
||
142 | * @return boolean |
||
143 | */ |
||
144 | 121 | protected function loadDataItem( SMWDataItem $dataItem ) { |
|
145 | 121 | if ( $dataItem->getDIType() == SMWDataItem::TYPE_CONTAINER ) { |
|
146 | // might throw an exception, we just pass it through |
||
147 | $dataItem = $dataItem->getSemanticData()->getSubject(); |
||
148 | } |
||
149 | |||
150 | 121 | if ( $dataItem->getDIType() !== SMWDataItem::TYPE_WIKIPAGE ) { |
|
151 | return false; |
||
152 | } |
||
153 | |||
154 | 121 | $this->m_dataitem = $dataItem; |
|
155 | 121 | $this->m_id = -1; |
|
156 | 121 | $this->m_title = null; |
|
157 | 121 | $this->m_fragment = $dataItem->getSubobjectName(); |
|
158 | 121 | $this->m_prefixedtext = ''; |
|
159 | 121 | $this->m_caption = false; // this class can handle this |
|
160 | |||
161 | 121 | if ( ( $this->m_fixNamespace != NS_MAIN ) && |
|
162 | 121 | ( $this->m_fixNamespace != $dataItem->getNamespace() ) ) { |
|
163 | global $wgContLang; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||
164 | $this->addError( wfMessage( 'smw_wrong_namespace', |
||
165 | $wgContLang->getNsText( $this->m_fixNamespace ) )->inContentLanguage()->text() ); |
||
166 | } |
||
167 | |||
168 | 121 | return true; |
|
169 | } |
||
170 | |||
171 | /** |
||
172 | * Display the value on a wiki page. This is used to display the value |
||
173 | * in the place where it was annotated on a wiki page. The desired |
||
174 | * behavior is that the display in this case looks as if no property |
||
175 | * annotation had been given, i.e. an annotation [[property::page|foo]] |
||
176 | * should display like [[page|foo]] in MediaWiki. But this should lead |
||
177 | * to a link, not to a category assignment. This means that: |
||
178 | * |
||
179 | * (1) If Image: is used (instead of Media:) then let MediaWiki embed |
||
180 | * the image. |
||
181 | * |
||
182 | * (2) If Category: is used, treat it as a page and link to it (do not |
||
183 | * categorize the page) |
||
184 | * |
||
185 | * (3) Preserve everything given after "|" for display (caption, image |
||
186 | * parameters, ...) |
||
187 | * |
||
188 | * (4) Use the (default) caption for display. When the value comes from |
||
189 | * user input, this includes the full value that one would also see in |
||
190 | * MediaWiki. |
||
191 | * |
||
192 | * @param $linked mixed generate links if not null or false |
||
193 | * @return string |
||
194 | */ |
||
195 | 95 | public function getShortWikiText( $linked = null ) { |
|
196 | |||
197 | 95 | if ( is_null( $linked ) || $linked === false || |
|
198 | 93 | $this->m_outformat == '-' || !$this->isValid() || |
|
199 | 95 | $this->m_caption === '' ) { |
|
200 | 22 | return $this->m_caption !== false ? $this->m_caption : $this->getWikiValue(); |
|
201 | } |
||
202 | |||
203 | 93 | if ( $this->m_dataitem->getNamespace() == NS_FILE && $this->m_dataitem->getInterwiki() === '' ) { |
|
204 | 3 | $linkEscape = ''; |
|
205 | 3 | $defaultCaption = '|' . $this->getShortCaptionText() . '|frameless|border|text-top'; |
|
206 | } else { |
||
207 | 91 | $linkEscape = ':'; |
|
208 | 91 | $defaultCaption = '|' . $this->getShortCaptionText(); |
|
209 | } |
||
210 | |||
211 | 93 | if ( $this->m_caption === false ) { |
|
212 | 29 | $link = '[[' . $linkEscape . $this->getWikiLinkTarget() . $defaultCaption . ']]'; |
|
213 | } else { |
||
214 | 87 | $link = '[[' . $linkEscape . $this->getWikiLinkTarget() . '|' . $this->m_caption . ']]'; |
|
215 | } |
||
216 | |||
217 | 93 | if ( $this->m_fragment !== '' ) { |
|
218 | 7 | $link = \Html::rawElement( |
|
219 | 7 | 'span', |
|
220 | array( |
||
221 | 'class' => 'smw-subobject-entity' |
||
222 | 7 | ), |
|
223 | $link |
||
224 | ); |
||
225 | } |
||
226 | |||
227 | 93 | return $link; |
|
228 | } |
||
229 | |||
230 | /** |
||
231 | * Display the value as in getShortWikiText() but create HTML. |
||
232 | * The only difference is that images are not embedded. |
||
233 | * |
||
234 | * @param Linker $linker mixed the Linker object to use or null if no linking is desired |
||
235 | * @return string |
||
236 | */ |
||
237 | 3 | public function getShortHTMLText( $linker = null ) { |
|
238 | |||
239 | $attributes = array( |
||
240 | 3 | 'class' => $this->m_fragment !== '' ? 'smw-subobject-entity' : '' |
|
241 | ); |
||
242 | |||
243 | // init the Title object, may reveal hitherto unnoticed errors: |
||
244 | 3 | if ( !is_null( $linker ) && $linker !== false && |
|
245 | 3 | $this->m_caption !== '' && $this->m_outformat != '-' ) { |
|
246 | 2 | $this->getTitle(); |
|
247 | } |
||
248 | |||
249 | 3 | $displayTitle = $this->getDisplayTitle(); |
|
250 | |||
251 | 3 | if ( $displayTitle !== '' && $linker === null ) { |
|
252 | return htmlspecialchars( $displayTitle ); |
||
253 | } |
||
254 | |||
255 | 3 | if ( is_null( $linker ) || $linker === false || !$this->isValid() || |
|
256 | 3 | $this->m_outformat == '-' || $this->m_caption === '' ) { |
|
257 | |||
258 | 1 | $caption = $this->m_caption === false ? $this->getWikiValue() : $this->m_caption; |
|
259 | 1 | return htmlspecialchars( $caption ); |
|
260 | } |
||
261 | |||
262 | 2 | $caption = $this->m_caption === false ? $this->getShortCaptionText() : $this->m_caption; |
|
263 | 2 | $caption = htmlspecialchars( $caption ); |
|
264 | |||
265 | 2 | if ( $this->getNamespace() == NS_MEDIA ) { // this extra case *is* needed |
|
266 | return $linker->makeMediaLinkObj( $this->getTitle(), $caption ); |
||
267 | } |
||
268 | |||
269 | 2 | return $linker->link( |
|
270 | 2 | $this->getTitle(), |
|
271 | $caption, |
||
272 | $attributes |
||
273 | ); |
||
274 | } |
||
275 | |||
276 | /** |
||
277 | * Display the "long" value on a wiki page. This behaves largely like |
||
278 | * getShortWikiText() but does not use the caption. Instead, it always |
||
279 | * takes the long display form (wiki value). |
||
280 | * |
||
281 | * @param $linked mixed if true the result will be linked |
||
282 | * @return string |
||
283 | */ |
||
284 | 12 | public function getLongWikiText( $linked = null ) { |
|
285 | 12 | if ( !$this->isValid() ) { |
|
286 | return $this->getErrorText(); |
||
287 | } |
||
288 | |||
289 | 12 | if ( is_null( $linked ) || $linked === false || $this->m_outformat == '-' ) { |
|
290 | 3 | return $this->getWikiValue(); |
|
291 | 11 | } elseif ( $this->m_dataitem->getNamespace() == NS_FILE && $this->m_dataitem->getInterwiki() === '' ) { |
|
292 | // Embed images and other files |
||
293 | // Note that the embedded file links to the image, hence needs no additional link text. |
||
294 | // There should not be a linebreak after an impage, just like there is no linebreak after |
||
295 | // other values (whether formatted or not). |
||
296 | return '[[' . $this->getWikiLinkTarget() . '|' . |
||
297 | $this->getLongCaptionText() . '|frameless|border|text-top]]'; |
||
298 | } |
||
299 | |||
300 | 11 | $link = '[[:' . $this->getWikiLinkTarget() . '|' . $this->getLongCaptionText() . ']]'; |
|
301 | |||
302 | 11 | if ( $this->m_fragment !== '' ) { |
|
303 | $link = \Html::rawElement( |
||
304 | 'span', |
||
305 | array( |
||
306 | 'class' => 'smw-subobject-entity' |
||
307 | ), |
||
308 | $link |
||
309 | ); |
||
310 | } |
||
311 | |||
312 | 11 | return $link; |
|
313 | } |
||
314 | |||
315 | /** |
||
316 | * Display the "long" value in HTML. This behaves largely like |
||
317 | * getLongWikiText() but does not embed images. |
||
318 | * |
||
319 | * @param $linker mixed if a Linker is given, the result will be linked |
||
320 | * @return string |
||
321 | */ |
||
322 | 1 | public function getLongHTMLText( $linker = null ) { |
|
323 | |||
324 | $attributes = array( |
||
325 | 1 | 'class' => $this->m_fragment !== '' ? 'smw-subobject-entity' : '' |
|
326 | ); |
||
327 | |||
328 | // init the Title object, may reveal hitherto unnoticed errors: |
||
329 | 1 | if ( !is_null( $linker ) && ( $this->m_outformat != '-' ) ) { |
|
330 | 1 | $this->getTitle(); |
|
331 | } |
||
332 | |||
333 | 1 | if ( !$this->isValid() ) { |
|
334 | return $this->getErrorText(); |
||
335 | } |
||
336 | |||
337 | 1 | if ( is_null( $linker ) || $this->m_outformat == '-' ) { |
|
338 | return htmlspecialchars( $this->getWikiValue() ); |
||
339 | 1 | } elseif ( $this->getNamespace() == NS_MEDIA ) { // this extra case is really needed |
|
340 | return $linker->makeMediaLinkObj( $this->getTitle(), |
||
341 | htmlspecialchars( $this->getLongCaptionText() ) ); |
||
342 | } |
||
343 | |||
344 | // all others use default linking, no embedding of images here |
||
345 | 1 | return $linker->link( $this->getTitle(), |
|
346 | 1 | htmlspecialchars( $this->getLongCaptionText() ), |
|
347 | $attributes |
||
348 | ); |
||
349 | } |
||
350 | |||
351 | /** |
||
352 | * Return a string that could be used in an in-page property assignment |
||
353 | * for setting this value. This does not include initial ":" for |
||
354 | * escaping things like Category: links since the property value does |
||
355 | * not include such escapes either. Fragment information is included. |
||
356 | * Namespaces are omitted if a fixed namespace is used, since they are |
||
357 | * not needed in this case when making a property assignment. |
||
358 | * |
||
359 | * @return string |
||
360 | */ |
||
361 | 75 | public function getWikiValue() { |
|
362 | 75 | return ( $this->m_fixNamespace == NS_MAIN ? $this->getPrefixedText() : $this->getText() ) . |
|
363 | 75 | ( $this->m_fragment !== '' ? "#{$this->m_fragment}" : '' ); |
|
364 | } |
||
365 | |||
366 | public function getHash() { |
||
367 | return $this->isValid() ? $this->getPrefixedText() : implode( "\t", $this->getErrors() ); |
||
368 | } |
||
369 | |||
370 | /** |
||
371 | * Create links to mapping services based on a wiki-editable message. |
||
372 | * The parameters available to the message are: |
||
373 | * $1: urlencoded article name (no namespace) |
||
374 | * |
||
375 | * @return array |
||
376 | */ |
||
377 | protected function getServiceLinkParams() { |
||
378 | if ( $this->isValid() ) { |
||
379 | return array( rawurlencode( str_replace( '_', ' ', $this->m_dataitem->getDBkey() ) ) ); |
||
380 | } else { |
||
381 | return array(); |
||
382 | } |
||
383 | } |
||
384 | |||
385 | ///// special interface for wiki page values |
||
386 | |||
387 | /** |
||
388 | * Return according Title object or null if no valid value was set. |
||
389 | * null can be returned even if this object returns true for isValid(), |
||
390 | * since the latter function does not check whether MediaWiki can really |
||
391 | * make a Title out of the given data. |
||
392 | * However, isValid() will return false *after* this function failed in |
||
393 | * trying to create a title. |
||
394 | * |
||
395 | * @return Title |
||
396 | */ |
||
397 | 2 | public function getTitle() { |
|
398 | 2 | if ( ( $this->isValid() ) && is_null( $this->m_title ) ) { |
|
399 | 2 | $this->m_title = $this->m_dataitem->getTitle(); |
|
400 | |||
401 | 2 | if ( is_null( $this->m_title ) ) { // should not normally happen, but anyway ... |
|
402 | global $wgContLang; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||
403 | $this->addError( wfMessage( |
||
404 | 'smw_notitle', |
||
405 | $wgContLang->getNsText( $this->m_dataitem->getNamespace() ) . ':' . $this->m_dataitem->getDBkey() |
||
406 | )->inContentLanguage()->text() ); |
||
407 | } |
||
408 | } |
||
409 | |||
410 | 2 | return $this->m_title; |
|
411 | } |
||
412 | |||
413 | /** |
||
414 | * Get MediaWiki's ID for this value or 0 if not available. |
||
415 | * |
||
416 | * @return integer |
||
417 | */ |
||
418 | public function getArticleID() { |
||
419 | if ( $this->m_id === false ) { |
||
420 | $this->m_id = !is_null( $this->getTitle() ) ? $this->m_title->getArticleID() : 0; |
||
421 | } |
||
422 | |||
423 | return $this->m_id; |
||
424 | } |
||
425 | |||
426 | /** |
||
427 | * Get namespace constant for this value. |
||
428 | * |
||
429 | * @return integer |
||
430 | */ |
||
431 | 2 | public function getNamespace() { |
|
432 | 2 | return $this->m_dataitem->getNamespace(); |
|
433 | } |
||
434 | |||
435 | /** |
||
436 | * Get DBKey for this value. Subclasses that allow for values that do not |
||
437 | * correspond to wiki pages may choose a DB key that is not a legal title |
||
438 | * DB key but rather another suitable internal ID. Thus it is not suitable |
||
439 | * to use this method in places where only MediaWiki Title keys are allowed. |
||
440 | * |
||
441 | * @return string |
||
442 | */ |
||
443 | public function getDBkey() { |
||
444 | return $this->m_dataitem->getDBkey(); |
||
445 | } |
||
446 | |||
447 | /** |
||
448 | * Get text label for this value, just like Title::getText(). |
||
449 | * |
||
450 | * @return string |
||
451 | */ |
||
452 | 124 | public function getText() { |
|
453 | 124 | return str_replace( '_', ' ', $this->m_dataitem->getDBkey() ); |
|
454 | } |
||
455 | |||
456 | /** |
||
457 | * Get the prefixed text for this value, including a localized namespace |
||
458 | * prefix. |
||
459 | * |
||
460 | * @return string |
||
461 | */ |
||
462 | 117 | public function getPrefixedText() { |
|
463 | 117 | global $wgContLang; |
|
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||
464 | 117 | if ( $this->m_prefixedtext === '' ) { |
|
465 | 117 | if ( $this->isValid() ) { |
|
466 | 117 | $nstext = $wgContLang->getNSText( $this->m_dataitem->getNamespace() ); |
|
467 | 117 | $this->m_prefixedtext = |
|
468 | 117 | ( $this->m_dataitem->getInterwiki() !== '' ? |
|
469 | 117 | $this->m_dataitem->getInterwiki() . ':' : '' ) . |
|
470 | 117 | ( $nstext !== '' ? "$nstext:" : '' ) . $this->getText(); |
|
471 | } else { |
||
472 | $this->m_prefixedtext = 'NO_VALID_VALUE'; |
||
473 | } |
||
474 | } |
||
475 | 117 | return $this->m_prefixedtext; |
|
476 | } |
||
477 | |||
478 | /** |
||
479 | * Get interwiki prefix or empty string. |
||
480 | * |
||
481 | * @return string |
||
482 | */ |
||
483 | public function getInterwiki() { |
||
484 | return $this->m_dataitem->getInterwiki(); |
||
485 | } |
||
486 | |||
487 | /** |
||
488 | * Get a short caption used to label this value. In particular, this |
||
489 | * omits namespace and interwiki prefixes (similar to the MediaWiki |
||
490 | * "pipe trick"). Fragments are included unless they start with an |
||
491 | * underscore (used for generated fragment names that are not helpful |
||
492 | * for users and that might change easily). |
||
493 | * |
||
494 | * @since 1.7 |
||
495 | * @return string |
||
496 | */ |
||
497 | 94 | protected function getShortCaptionText() { |
|
498 | 94 | if ( $this->m_fragment !== '' && $this->m_fragment[0] != '_' ) { |
|
499 | 1 | $fragmentText = '#' . $this->m_fragment; |
|
500 | } else { |
||
501 | 94 | $fragmentText = ''; |
|
502 | } |
||
503 | |||
504 | 94 | $displayTitle = $this->getDisplayTitle(); |
|
505 | |||
506 | 94 | if ( $displayTitle === '' ) { |
|
507 | 94 | $displayTitle = $this->getText(); |
|
508 | } |
||
509 | |||
510 | 94 | return $displayTitle . $fragmentText; |
|
511 | } |
||
512 | |||
513 | /** |
||
514 | * Get a long caption used to label this value. In particular, this |
||
515 | * includes namespace and interwiki prefixes, while fragments are only |
||
516 | * included if they do not start with an underscore (used for generated |
||
517 | * fragment names that are not helpful for users and that might change |
||
518 | * easily). |
||
519 | * |
||
520 | * @since 1.7 |
||
521 | * @return string |
||
522 | */ |
||
523 | 12 | protected function getLongCaptionText() { |
|
524 | 12 | if ( $this->m_fragment !== '' && $this->m_fragment[0] != '_' ) { |
|
525 | $fragmentText = '#' . $this->m_fragment; |
||
526 | } else { |
||
527 | 12 | $fragmentText = ''; |
|
528 | } |
||
529 | |||
530 | 12 | $displayTitle = $this->getDisplayTitle(); |
|
531 | |||
532 | 12 | if ( $displayTitle === '' ) { |
|
533 | 12 | $displayTitle = $this->m_fixNamespace == NS_MAIN ? $this->getPrefixedText() : $this->getText(); |
|
534 | } |
||
535 | |||
536 | 12 | return $displayTitle . $fragmentText; |
|
537 | } |
||
538 | |||
539 | /** |
||
540 | * Compute a text that can be used in wiki text to link to this |
||
541 | * datavalue. Processing includes some escaping and adding the |
||
542 | * fragment. |
||
543 | * |
||
544 | * @since 1.7 |
||
545 | * @return string |
||
546 | */ |
||
547 | 97 | protected function getWikiLinkTarget() { |
|
548 | 97 | return str_replace( "'", ''', $this->getPrefixedText() ) . |
|
549 | 97 | ( $this->m_fragment !== '' ? "#{$this->m_fragment}" : '' ); |
|
550 | } |
||
551 | |||
552 | /** |
||
553 | * Find the sortkey for this object. |
||
554 | * |
||
555 | * @deprecated Use SMWStore::getWikiPageSortKey(). Will vanish before SMW 1.7 |
||
556 | * |
||
557 | * @return string sortkey |
||
558 | */ |
||
559 | public function getSortKey() { |
||
560 | return ApplicationFactory::getInstance()->getStore()->getWikiPageSortKey( $this->m_dataitem ); |
||
561 | } |
||
562 | |||
563 | /** |
||
564 | * @since 2.4 |
||
565 | * |
||
566 | * @return string |
||
567 | */ |
||
568 | 107 | public function getDisplayTitle() { |
|
569 | |||
570 | 107 | if ( $this->m_dataitem === null || ( $this->getOptionValueFor( 'smwgDVFeatures' ) & SMW_DV_WPV_DTITLE ) == 0 ) { |
|
571 | return ''; |
||
572 | } |
||
573 | |||
574 | 107 | return $this->findDisplayTitleFor( $this->m_dataitem ); |
|
575 | } |
||
576 | |||
577 | /** |
||
578 | * Static function for creating a new wikipage object from |
||
579 | * data as it is typically stored internally. In particular, |
||
580 | * the title string is supposed to be in DB key form. |
||
581 | * |
||
582 | * @note The resulting wikipage object might be invalid if |
||
583 | * the provided title is not allowed. An object is returned |
||
584 | * in any case. |
||
585 | * |
||
586 | * @deprecated This method will vanish before SMW 1.7. If you really need this, simply copy its code. |
||
587 | * |
||
588 | * @return SMWWikiPageValue |
||
589 | */ |
||
590 | static public function makePage( $dbkey, $namespace, $ignoredParameter = '', $interwiki = '' ) { |
||
591 | $diWikiPage = new SMWDIWikiPage( $dbkey, $namespace, $interwiki ); |
||
592 | $dvWikiPage = new SMWWikiPageValue( '_wpg' ); |
||
593 | $dvWikiPage->setDataItem( $diWikiPage ); |
||
594 | return $dvWikiPage; |
||
595 | } |
||
596 | |||
597 | /** |
||
598 | * Static function for creating a new wikipage object from a |
||
599 | * MediaWiki Title object. |
||
600 | * |
||
601 | * @deprecated This method will vanish before SMW 1.7. If you really need this, simply copy its code. |
||
602 | * |
||
603 | * @return SMWWikiPageValue |
||
604 | */ |
||
605 | static public function makePageFromTitle( Title $title ) { |
||
606 | $dvWikiPage = new SMWWikiPageValue( '_wpg' ); |
||
607 | $diWikiPage = SMWDIWikiPage::newFromTitle( $title ); |
||
608 | $dvWikiPage->setDataItem( $diWikiPage ); |
||
609 | $dvWikiPage->m_title = $title; // optional, just for efficiency |
||
610 | return $dvWikiPage; |
||
611 | } |
||
612 | |||
613 | 107 | private function findDisplayTitleFor( $subject ) { |
|
614 | |||
615 | 107 | $displayTitle = ''; |
|
616 | |||
617 | 107 | $dataItems = ApplicationFactory::getInstance()->getCachedPropertyValuesPrefetcher()->getPropertyValues( |
|
618 | $subject, |
||
619 | 107 | new DIProperty( '_DTITLE' ) |
|
620 | ); |
||
621 | |||
622 | 107 | if ( $dataItems !== null && $dataItems !== array() ) { |
|
623 | 1 | $displayTitle = end( $dataItems )->getString(); |
|
624 | 107 | } elseif ( $subject->getSubobjectName() !== '' ) { |
|
625 | // Check whether the base subject has a DISPLAYTITLE |
||
626 | 7 | return $this->findDisplayTitleFor( $subject->asBase() ); |
|
627 | } |
||
628 | |||
629 | 107 | return $displayTitle; |
|
630 | } |
||
631 | |||
632 | } |
||
633 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state