Misc EOL w/s and spaces-instead-of-tabs fixes. One day I'll get around to nagging...
[lhc/web/wiklou.git] / includes / Linker.php
1 <?php
2 /**
3 * Some internal bits split of from Skin.php. These functions are used
4 * for primarily page content: links, embedded images, table of contents. Links
5 * are also used in the skin.
6 *
7 * @ingroup Skins
8 */
9 class Linker {
10
11 /**
12 * Flags for userToolLinks()
13 */
14 const TOOL_LINKS_NOBLOCK = 1;
15
16 /**
17 * Get the appropriate HTML attributes to add to the "a" element of an ex-
18 * ternal link, as created by [wikisyntax].
19 *
20 * @param $class String: the contents of the class attribute; if an empty
21 * string is passed, which is the default value, defaults to 'external'.
22 * @deprecated since 1.18 Just pass the external class directly to something using Html::expandAttributes
23 */
24 static function getExternalLinkAttributes( $class = 'external' ) {
25 wfDeprecated( __METHOD__ );
26 return self::getLinkAttributesInternal( '', $class );
27 }
28
29 /**
30 * Get the appropriate HTML attributes to add to the "a" element of an in-
31 * terwiki link.
32 *
33 * @param $title String: the title text for the link, URL-encoded (???) but
34 * not HTML-escaped
35 * @param $unused String: unused
36 * @param $class String: the contents of the class attribute; if an empty
37 * string is passed, which is the default value, defaults to 'external'.
38 */
39 static function getInterwikiLinkAttributes( $title, $unused = null, $class = 'external' ) {
40 global $wgContLang;
41
42 # @todo FIXME: We have a whole bunch of handling here that doesn't happen in
43 # getExternalLinkAttributes, why?
44 $title = urldecode( $title );
45 $title = $wgContLang->checkTitleEncoding( $title );
46 $title = preg_replace( '/[\\x00-\\x1f]/', ' ', $title );
47
48 return self::getLinkAttributesInternal( $title, $class );
49 }
50
51 /**
52 * Get the appropriate HTML attributes to add to the "a" element of an in-
53 * ternal link.
54 *
55 * @param $title String: the title text for the link, URL-encoded (???) but
56 * not HTML-escaped
57 * @param $unused String: unused
58 * @param $class String: the contents of the class attribute, default none
59 */
60 static function getInternalLinkAttributes( $title, $unused = null, $class = '' ) {
61 $title = urldecode( $title );
62 $title = str_replace( '_', ' ', $title );
63 return self::getLinkAttributesInternal( $title, $class );
64 }
65
66 /**
67 * Get the appropriate HTML attributes to add to the "a" element of an in-
68 * ternal link, given the Title object for the page we want to link to.
69 *
70 * @param $nt Title
71 * @param $unused String: unused
72 * @param $class String: the contents of the class attribute, default none
73 * @param $title Mixed: optional (unescaped) string to use in the title
74 * attribute; if false, default to the name of the page we're linking to
75 */
76 static function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) {
77 if ( $title === false ) {
78 $title = $nt->getPrefixedText();
79 }
80 return self::getLinkAttributesInternal( $title, $class );
81 }
82
83 /**
84 * Common code for getLinkAttributesX functions
85 */
86 private static function getLinkAttributesInternal( $title, $class ) {
87 $title = htmlspecialchars( $title );
88 $class = htmlspecialchars( $class );
89 $r = '';
90 if ( $class != '' ) {
91 $r .= " class=\"$class\"";
92 }
93 if ( $title != '' ) {
94 $r .= " title=\"$title\"";
95 }
96 return $r;
97 }
98
99 /**
100 * Return the CSS colour of a known link
101 *
102 * @param $t Title object
103 * @param $threshold Integer: user defined threshold
104 * @return String: CSS class
105 */
106 static function getLinkColour( $t, $threshold ) {
107 $colour = '';
108 if ( $t->isRedirect() ) {
109 # Page is a redirect
110 $colour = 'mw-redirect';
111 } elseif ( $threshold > 0 &&
112 $t->exists() && $t->getLength() < $threshold &&
113 $t->isContentPage() ) {
114 # Page is a stub
115 $colour = 'stub';
116 }
117 return $colour;
118 }
119
120 /**
121 * This function returns an HTML link to the given target. It serves a few
122 * purposes:
123 * 1) If $target is a Title, the correct URL to link to will be figured
124 * out automatically.
125 * 2) It automatically adds the usual classes for various types of link
126 * targets: "new" for red links, "stub" for short articles, etc.
127 * 3) It escapes all attribute values safely so there's no risk of XSS.
128 * 4) It provides a default tooltip if the target is a Title (the page
129 * name of the target).
130 * link() replaces the old functions in the makeLink() family.
131 *
132 * @param $target Title Can currently only be a Title, but this may
133 * change to support Images, literal URLs, etc.
134 * @param $text string The HTML contents of the <a> element, i.e.,
135 * the link text. This is raw HTML and will not be escaped. If null,
136 * defaults to the prefixed text of the Title; or if the Title is just a
137 * fragment, the contents of the fragment.
138 * @param $customAttribs array A key => value array of extra HTML attri-
139 * butes, such as title and class. (href is ignored.) Classes will be
140 * merged with the default classes, while other attributes will replace
141 * default attributes. All passed attribute values will be HTML-escaped.
142 * A false attribute value means to suppress that attribute.
143 * @param $query array The query string to append to the URL
144 * you're linking to, in key => value array form. Query keys and values
145 * will be URL-encoded.
146 * @param $options mixed String or array of strings:
147 * 'known': Page is known to exist, so don't check if it does.
148 * 'broken': Page is known not to exist, so don't check if it does.
149 * 'noclasses': Don't add any classes automatically (includes "new",
150 * "stub", "mw-redirect", "extiw"). Only use the class attribute
151 * provided, if any, so you get a simple blue link with no funny i-
152 * cons.
153 * 'forcearticlepath': Use the article path always, even with a querystring.
154 * Has compatibility issues on some setups, so avoid wherever possible.
155 * @return string HTML <a> attribute
156 */
157 public static function link(
158 $target, $html = null, $customAttribs = array(), $query = array(), $options = array()
159 ) {
160 wfProfileIn( __METHOD__ );
161 if ( !$target instanceof Title ) {
162 wfProfileOut( __METHOD__ );
163 return "<!-- ERROR -->$html";
164 }
165 $options = (array)$options;
166
167 $dummy = new DummyLinker; // dummy linker instance for bc on the hooks
168
169 $ret = null;
170 if ( !wfRunHooks( 'LinkBegin', array( $dummy, $target, &$html,
171 &$customAttribs, &$query, &$options, &$ret ) ) ) {
172 wfProfileOut( __METHOD__ );
173 return $ret;
174 }
175
176 # Normalize the Title if it's a special page
177 $target = self::normaliseSpecialPage( $target );
178
179 # If we don't know whether the page exists, let's find out.
180 wfProfileIn( __METHOD__ . '-checkPageExistence' );
181 if ( !in_array( 'known', $options ) and !in_array( 'broken', $options ) ) {
182 if ( $target->isKnown() ) {
183 $options[] = 'known';
184 } else {
185 $options[] = 'broken';
186 }
187 }
188 wfProfileOut( __METHOD__ . '-checkPageExistence' );
189
190 $oldquery = array();
191 if ( in_array( "forcearticlepath", $options ) && $query ) {
192 $oldquery = $query;
193 $query = array();
194 }
195
196 # Note: we want the href attribute first, for prettiness.
197 $attribs = array( 'href' => self::linkUrl( $target, $query, $options ) );
198 if ( in_array( 'forcearticlepath', $options ) && $oldquery ) {
199 $attribs['href'] = wfAppendQuery( $attribs['href'], wfArrayToCgi( $oldquery ) );
200 }
201
202 $attribs = array_merge(
203 $attribs,
204 self::linkAttribs( $target, $customAttribs, $options )
205 );
206 if ( is_null( $html ) ) {
207 $html = self::linkText( $target );
208 }
209
210 $ret = null;
211 if ( wfRunHooks( 'LinkEnd', array( $dummy, $target, $options, &$html, &$attribs, &$ret ) ) ) {
212 $ret = Html::rawElement( 'a', $attribs, $html );
213 }
214
215 wfProfileOut( __METHOD__ );
216 return $ret;
217 }
218
219 /**
220 * Identical to link(), except $options defaults to 'known'.
221 */
222 public static function linkKnown(
223 $target, $text = null, $customAttribs = array(),
224 $query = array(), $options = array( 'known', 'noclasses' ) )
225 {
226 return self::link( $target, $text, $customAttribs, $query, $options );
227 }
228
229 /**
230 * Returns the Url used to link to a Title
231 *
232 * @param $target Title
233 */
234 private static function linkUrl( $target, $query, $options ) {
235 wfProfileIn( __METHOD__ );
236 # We don't want to include fragments for broken links, because they
237 # generally make no sense.
238 if ( in_array( 'broken', $options ) && $target->mFragment !== '' ) {
239 $target = clone $target;
240 $target->mFragment = '';
241 }
242
243 # If it's a broken link, add the appropriate query pieces, unless
244 # there's already an action specified, or unless 'edit' makes no sense
245 # (i.e., for a nonexistent special page).
246 if ( in_array( 'broken', $options ) && empty( $query['action'] )
247 && $target->getNamespace() != NS_SPECIAL ) {
248 $query['action'] = 'edit';
249 $query['redlink'] = '1';
250 }
251 $ret = $target->getLinkUrl( $query );
252 wfProfileOut( __METHOD__ );
253 return $ret;
254 }
255
256 /**
257 * Returns the array of attributes used when linking to the Title $target
258 *
259 * @param $target Title
260 */
261 private static function linkAttribs( $target, $attribs, $options ) {
262 wfProfileIn( __METHOD__ );
263 global $wgUser;
264 $defaults = array();
265
266 if ( !in_array( 'noclasses', $options ) ) {
267 wfProfileIn( __METHOD__ . '-getClasses' );
268 # Now build the classes.
269 $classes = array();
270
271 if ( in_array( 'broken', $options ) ) {
272 $classes[] = 'new';
273 }
274
275 if ( $target->isExternal() ) {
276 $classes[] = 'extiw';
277 }
278
279 if ( !in_array( 'broken', $options ) ) { # Avoid useless calls to LinkCache (see r50387)
280 $colour = self::getLinkColour( $target, $wgUser->getStubThreshold() );
281 if ( $colour !== '' ) {
282 $classes[] = $colour; # mw-redirect or stub
283 }
284 }
285 if ( $classes != array() ) {
286 $defaults['class'] = implode( ' ', $classes );
287 }
288 wfProfileOut( __METHOD__ . '-getClasses' );
289 }
290
291 # Get a default title attribute.
292 if ( $target->getPrefixedText() == '' ) {
293 # A link like [[#Foo]]. This used to mean an empty title
294 # attribute, but that's silly. Just don't output a title.
295 } elseif ( in_array( 'known', $options ) ) {
296 $defaults['title'] = $target->getPrefixedText();
297 } else {
298 $defaults['title'] = wfMsg( 'red-link-title', $target->getPrefixedText() );
299 }
300
301 # Finally, merge the custom attribs with the default ones, and iterate
302 # over that, deleting all "false" attributes.
303 $ret = array();
304 $merged = Sanitizer::mergeAttributes( $defaults, $attribs );
305 foreach ( $merged as $key => $val ) {
306 # A false value suppresses the attribute, and we don't want the
307 # href attribute to be overridden.
308 if ( $key != 'href' and $val !== false ) {
309 $ret[$key] = $val;
310 }
311 }
312 wfProfileOut( __METHOD__ );
313 return $ret;
314 }
315
316 /**
317 * Default text of the links to the Title $target
318 *
319 * @param $target Title
320 *
321 * @return string
322 */
323 private static function linkText( $target ) {
324 # We might be passed a non-Title by make*LinkObj(). Fail gracefully.
325 if ( !$target instanceof Title ) {
326 return '';
327 }
328
329 # If the target is just a fragment, with no title, we return the frag-
330 # ment text. Otherwise, we return the title text itself.
331 if ( $target->getPrefixedText() === '' && $target->getFragment() !== '' ) {
332 return htmlspecialchars( $target->getFragment() );
333 }
334 return htmlspecialchars( $target->getPrefixedText() );
335 }
336
337 /**
338 * Generate either a normal exists-style link or a stub link, depending
339 * on the given page size.
340 *
341 * @param $size Integer
342 * @param $nt Title object.
343 * @param $text String
344 * @param $query String
345 * @param $trail String
346 * @param $prefix String
347 * @return string HTML of link
348 * @deprecated since 1.17
349 */
350 static function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
351 global $wgUser;
352 wfDeprecated( __METHOD__ );
353
354 $threshold = $wgUser->getStubThreshold();
355 $colour = ( $size < $threshold ) ? 'stub' : '';
356 // @todo FIXME: Replace deprecated makeColouredLinkObj by link()
357 return self::makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
358 }
359
360 /**
361 * Make appropriate markup for a link to the current article. This is currently rendered
362 * as the bold link text. The calling sequence is the same as the other make*LinkObj static functions,
363 * despite $query not being used.
364 *
365 * @param $nt Title
366 *
367 * @return string
368 */
369 static function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
370 if ( $text == '' ) {
371 $text = htmlspecialchars( $nt->getPrefixedText() );
372 }
373 list( $inside, $trail ) = self::splitTrail( $trail );
374 return "<strong class=\"selflink\">{$prefix}{$text}{$inside}</strong>{$trail}";
375 }
376
377 /**
378 * @param $title Title
379 * @return Title
380 */
381 static function normaliseSpecialPage( Title $title ) {
382 if ( $title->getNamespace() == NS_SPECIAL ) {
383 list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
384 if ( !$name ) {
385 return $title;
386 }
387 $ret = SpecialPage::getTitleFor( $name, $subpage );
388 $ret->mFragment = $title->getFragment();
389 return $ret;
390 } else {
391 return $title;
392 }
393 }
394
395 /**
396 * Returns the filename part of an url.
397 * Used as alternative text for external images.
398 *
399 * @param $url string
400 *
401 * @return string
402 */
403 static function fnamePart( $url ) {
404 $basename = strrchr( $url, '/' );
405 if ( false === $basename ) {
406 $basename = $url;
407 } else {
408 $basename = substr( $basename, 1 );
409 }
410 return $basename;
411 }
412
413 /**
414 * Return the code for images which were added via external links,
415 * via Parser::maybeMakeExternalImage().
416 *
417 * @param $url
418 * @param $alt
419 *
420 * @return string
421 */
422 static function makeExternalImage( $url, $alt = '' ) {
423 if ( $alt == '' ) {
424 $alt = self::fnamePart( $url );
425 }
426 $img = '';
427 $success = wfRunHooks( 'LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
428 if ( !$success ) {
429 wfDebug( "Hook LinkerMakeExternalImage changed the output of external image with url {$url} and alt text {$alt} to {$img}\n", true );
430 return $img;
431 }
432 return Html::element( 'img',
433 array(
434 'src' => $url,
435 'alt' => $alt ) );
436 }
437
438 /**
439 * Given parameters derived from [[Image:Foo|options...]], generate the
440 * HTML that that syntax inserts in the page.
441 *
442 * @param $title Title object
443 * @param $file File object, or false if it doesn't exist
444 * @param $frameParams Array: associative array of parameters external to the media handler.
445 * Boolean parameters are indicated by presence or absence, the value is arbitrary and
446 * will often be false.
447 * thumbnail If present, downscale and frame
448 * manualthumb Image name to use as a thumbnail, instead of automatic scaling
449 * framed Shows image in original size in a frame
450 * frameless Downscale but don't frame
451 * upright If present, tweak default sizes for portrait orientation
452 * upright_factor Fudge factor for "upright" tweak (default 0.75)
453 * border If present, show a border around the image
454 * align Horizontal alignment (left, right, center, none)
455 * valign Vertical alignment (baseline, sub, super, top, text-top, middle,
456 * bottom, text-bottom)
457 * alt Alternate text for image (i.e. alt attribute). Plain text.
458 * caption HTML for image caption.
459 * link-url URL to link to
460 * link-title Title object to link to
461 * link-target Value for the target attribue, only with link-url
462 * no-link Boolean, suppress description link
463 *
464 * @param $handlerParams Array: associative array of media handler parameters, to be passed
465 * to transform(). Typical keys are "width" and "page".
466 * @param $time String: timestamp of the file, set as false for current
467 * @param $query String: query params for desc url
468 * @param $widthOption: Used by the parser to remember the user preference thumbnailsize
469 * @return String: HTML for an image, with links, wrappers, etc.
470 */
471 static function makeImageLink2( Title $title, $file, $frameParams = array(),
472 $handlerParams = array(), $time = false, $query = "", $widthOption = null )
473 {
474 $res = null;
475 $dummy = new DummyLinker;
476 if ( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$dummy, &$title,
477 &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
478 return $res;
479 }
480
481 if ( $file && !$file->allowInlineDisplay() ) {
482 wfDebug( __METHOD__ . ': ' . $title->getPrefixedDBkey() . " does not allow inline display\n" );
483 return self::link( $title );
484 }
485
486 // Shortcuts
487 $fp =& $frameParams;
488 $hp =& $handlerParams;
489
490 // Clean up parameters
491 $page = isset( $hp['page'] ) ? $hp['page'] : false;
492 if ( !isset( $fp['align'] ) ) {
493 $fp['align'] = '';
494 }
495 if ( !isset( $fp['alt'] ) ) {
496 $fp['alt'] = '';
497 }
498 if ( !isset( $fp['title'] ) ) {
499 $fp['title'] = '';
500 }
501
502 $prefix = $postfix = '';
503
504 if ( 'center' == $fp['align'] ) {
505 $prefix = '<div class="center">';
506 $postfix = '</div>';
507 $fp['align'] = 'none';
508 }
509 if ( $file && !isset( $hp['width'] ) ) {
510 if ( isset( $hp['height'] ) && $file->isVectorized() ) {
511 // If its a vector image, and user only specifies height
512 // we don't want it to be limited by its "normal" width.
513 global $wgSVGMaxSize;
514 $hp['width'] = $wgSVGMaxSize;
515 } else {
516 $hp['width'] = $file->getWidth( $page );
517 }
518
519 if ( isset( $fp['thumbnail'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) || !$hp['width'] ) {
520 global $wgThumbLimits, $wgThumbUpright;
521 if ( !isset( $widthOption ) || !isset( $wgThumbLimits[$widthOption] ) ) {
522 $widthOption = User::getDefaultOption( 'thumbsize' );
523 }
524
525 // Reduce width for upright images when parameter 'upright' is used
526 if ( isset( $fp['upright'] ) && $fp['upright'] == 0 ) {
527 $fp['upright'] = $wgThumbUpright;
528 }
529 // For caching health: If width scaled down due to upright parameter, round to full __0 pixel to avoid the creation of a lot of odd thumbs
530 $prefWidth = isset( $fp['upright'] ) ?
531 round( $wgThumbLimits[$widthOption] * $fp['upright'], -1 ) :
532 $wgThumbLimits[$widthOption];
533
534 // Use width which is smaller: real image width or user preference width
535 // Unless image is scalable vector.
536 if ( !isset( $hp['height'] ) && ( $hp['width'] <= 0 ||
537 $prefWidth < $hp['width'] || $file->isVectorized() ) ) {
538 $hp['width'] = $prefWidth;
539 }
540 }
541 }
542
543 if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) ) {
544 global $wgContLang;
545 # Create a thumbnail. Alignment depends on language
546 # writing direction, # right aligned for left-to-right-
547 # languages ("Western languages"), left-aligned
548 # for right-to-left-languages ("Semitic languages")
549 #
550 # If thumbnail width has not been provided, it is set
551 # to the default user option as specified in Language*.php
552 if ( $fp['align'] == '' ) {
553 $fp['align'] = $wgContLang->alignEnd();
554 }
555 return $prefix . self::makeThumbLink2( $title, $file, $fp, $hp, $time, $query ) . $postfix;
556 }
557
558 if ( $file && isset( $fp['frameless'] ) ) {
559 $srcWidth = $file->getWidth( $page );
560 # For "frameless" option: do not present an image bigger than the source (for bitmap-style images)
561 # This is the same behaviour as the "thumb" option does it already.
562 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
563 $hp['width'] = $srcWidth;
564 }
565 }
566
567 if ( $file && isset( $hp['width'] ) ) {
568 # Create a resized image, without the additional thumbnail features
569 $thumb = $file->transform( $hp );
570 } else {
571 $thumb = false;
572 }
573
574 if ( !$thumb ) {
575 $s = self::makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time == true );
576 } else {
577 $params = array(
578 'alt' => $fp['alt'],
579 'title' => $fp['title'],
580 'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false ,
581 'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false );
582 $params = self::getImageLinkMTOParams( $fp, $query ) + $params;
583
584 $s = $thumb->toHtml( $params );
585 }
586 if ( $fp['align'] != '' ) {
587 $s = "<div class=\"float{$fp['align']}\">{$s}</div>";
588 }
589 return str_replace( "\n", ' ', $prefix . $s . $postfix );
590 }
591
592 /**
593 * Get the link parameters for MediaTransformOutput::toHtml() from given
594 * frame parameters supplied by the Parser.
595 * @param $frameParams The frame parameters
596 * @param $query An optional query string to add to description page links
597 */
598 static function getImageLinkMTOParams( $frameParams, $query = '' ) {
599 $mtoParams = array();
600 if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) {
601 $mtoParams['custom-url-link'] = $frameParams['link-url'];
602 if ( isset( $frameParams['link-target'] ) ) {
603 $mtoParams['custom-target-link'] = $frameParams['link-target'];
604 }
605 } elseif ( isset( $frameParams['link-title'] ) && $frameParams['link-title'] !== '' ) {
606 $mtoParams['custom-title-link'] = self::normaliseSpecialPage( $frameParams['link-title'] );
607 } elseif ( !empty( $frameParams['no-link'] ) ) {
608 // No link
609 } else {
610 $mtoParams['desc-link'] = true;
611 $mtoParams['desc-query'] = $query;
612 }
613 return $mtoParams;
614 }
615
616 /**
617 * Make HTML for a thumbnail including image, border and caption
618 * @param $title Title object
619 * @param $file File object or false if it doesn't exist
620 * @param $label String
621 * @param $alt String
622 * @param $align String
623 * @param $params Array
624 * @param $framed Boolean
625 * @param $manualthumb String
626 */
627 static function makeThumbLinkObj( Title $title, $file, $label = '', $alt,
628 $align = 'right', $params = array(), $framed = false , $manualthumb = "" )
629 {
630 $frameParams = array(
631 'alt' => $alt,
632 'caption' => $label,
633 'align' => $align
634 );
635 if ( $framed ) {
636 $frameParams['framed'] = true;
637 }
638 if ( $manualthumb ) {
639 $frameParams['manualthumb'] = $manualthumb;
640 }
641 return self::makeThumbLink2( $title, $file, $frameParams, $params );
642 }
643
644 /**
645 * @param $title Title
646 * @param $file File
647 * @param array $frameParams
648 * @param array $handlerParams
649 * @param bool $time
650 * @param string $query
651 * @return mixed
652 */
653 static function makeThumbLink2( Title $title, $file, $frameParams = array(),
654 $handlerParams = array(), $time = false, $query = "" )
655 {
656 global $wgStylePath, $wgContLang;
657 $exists = $file && $file->exists();
658
659 # Shortcuts
660 $fp =& $frameParams;
661 $hp =& $handlerParams;
662
663 $page = isset( $hp['page'] ) ? $hp['page'] : false;
664 if ( !isset( $fp['align'] ) ) $fp['align'] = 'right';
665 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
666 if ( !isset( $fp['title'] ) ) $fp['title'] = '';
667 if ( !isset( $fp['caption'] ) ) $fp['caption'] = '';
668
669 if ( empty( $hp['width'] ) ) {
670 // Reduce width for upright images when parameter 'upright' is used
671 $hp['width'] = isset( $fp['upright'] ) ? 130 : 180;
672 }
673 $thumb = false;
674
675 if ( !$exists ) {
676 $outerWidth = $hp['width'] + 2;
677 } else {
678 if ( isset( $fp['manualthumb'] ) ) {
679 # Use manually specified thumbnail
680 $manual_title = Title::makeTitleSafe( NS_FILE, $fp['manualthumb'] );
681 if ( $manual_title ) {
682 $manual_img = wfFindFile( $manual_title );
683 if ( $manual_img ) {
684 $thumb = $manual_img->getUnscaledThumb( $hp );
685 } else {
686 $exists = false;
687 }
688 }
689 } elseif ( isset( $fp['framed'] ) ) {
690 // Use image dimensions, don't scale
691 $thumb = $file->getUnscaledThumb( $hp );
692 } else {
693 # Do not present an image bigger than the source, for bitmap-style images
694 # This is a hack to maintain compatibility with arbitrary pre-1.10 behaviour
695 $srcWidth = $file->getWidth( $page );
696 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
697 $hp['width'] = $srcWidth;
698 }
699 $thumb = $file->transform( $hp );
700 }
701
702 if ( $thumb ) {
703 $outerWidth = $thumb->getWidth() + 2;
704 } else {
705 $outerWidth = $hp['width'] + 2;
706 }
707 }
708
709 # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
710 # So we don't need to pass it here in $query. However, the URL for the
711 # zoom icon still needs it, so we make a unique query for it. See bug 14771
712 $url = $title->getLocalURL( $query );
713 if ( $page ) {
714 $url = wfAppendQuery( $url, 'page=' . urlencode( $page ) );
715 }
716
717 $s = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
718 if ( !$exists ) {
719 $s .= self::makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time == true );
720 $zoomIcon = '';
721 } elseif ( !$thumb ) {
722 $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
723 $zoomIcon = '';
724 } else {
725 $params = array(
726 'alt' => $fp['alt'],
727 'title' => $fp['title'],
728 'img-class' => 'thumbimage' );
729 $params = self::getImageLinkMTOParams( $fp, $query ) + $params;
730 $s .= $thumb->toHtml( $params );
731 if ( isset( $fp['framed'] ) ) {
732 $zoomIcon = "";
733 } else {
734 $zoomIcon = Html::rawElement( 'div', array( 'class' => 'magnify' ),
735 Html::rawElement( 'a', array(
736 'href' => $url,
737 'class' => 'internal',
738 'title' => wfMsg( 'thumbnail-more' ) ),
739 Html::element( 'img', array(
740 'src' => $wgStylePath . '/common/images/magnify-clip' . ( $wgContLang->isRTL() ? '-rtl' : '' ) . '.png',
741 'width' => 15,
742 'height' => 11,
743 'alt' => "" ) ) ) );
744 }
745 }
746 $s .= ' <div class="thumbcaption">' . $zoomIcon . $fp['caption'] . "</div></div></div>";
747 return str_replace( "\n", ' ', $s );
748 }
749
750 /**
751 * Make a "broken" link to an image
752 *
753 * @param $title Title object
754 * @param $text String: link label in unescaped text form
755 * @param $query String: query string
756 * @param $trail String: link trail (HTML fragment)
757 * @param $prefix String: link prefix (HTML fragment)
758 * @param $time Boolean: a file of a certain timestamp was requested
759 * @return String
760 */
761 public static function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '', $time = false ) {
762 global $wgEnableUploads, $wgUploadMissingFileUrl;
763 if ( ! $title instanceof Title ) {
764 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
765 }
766 wfProfileIn( __METHOD__ );
767 $currentExists = $time ? ( wfFindFile( $title ) != false ) : false;
768
769 list( $inside, $trail ) = self::splitTrail( $trail );
770 if ( $text == '' )
771 $text = htmlspecialchars( $title->getPrefixedText() );
772
773 if ( ( $wgUploadMissingFileUrl || $wgEnableUploads ) && !$currentExists ) {
774 $redir = RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title );
775
776 if ( $redir ) {
777 wfProfileOut( __METHOD__ );
778 return self::linkKnown( $title, "$prefix$text$inside", array(), $query ) . $trail;
779 }
780
781 $href = self::getUploadUrl( $title, $query );
782
783 wfProfileOut( __METHOD__ );
784 return '<a href="' . htmlspecialchars( $href ) . '" class="new" title="' .
785 htmlspecialchars( $title->getPrefixedText(), ENT_QUOTES ) . '">' .
786 "$prefix$text$inside</a>$trail";
787 } else {
788 wfProfileOut( __METHOD__ );
789 return self::linkKnown( $title, "$prefix$text$inside", array(), $query ) . $trail;
790 }
791 }
792
793 /**
794 * Get the URL to upload a certain file
795 *
796 * @param $destFile Title object of the file to upload
797 * @param $query String: urlencoded query string to prepend
798 * @return String: urlencoded URL
799 */
800 protected static function getUploadUrl( $destFile, $query = '' ) {
801 global $wgUploadMissingFileUrl;
802 $q = 'wpDestFile=' . $destFile->getPartialUrl();
803 if ( $query != '' )
804 $q .= '&' . $query;
805
806 if ( $wgUploadMissingFileUrl ) {
807 return wfAppendQuery( $wgUploadMissingFileUrl, $q );
808 } else {
809 $upload = SpecialPage::getTitleFor( 'Upload' );
810 return $upload->getLocalUrl( $q );
811 }
812 }
813
814 /**
815 * Create a direct link to a given uploaded file.
816 *
817 * @param $title Title object.
818 * @param $text String: pre-sanitized HTML
819 * @param $time string: MW timestamp of file creation time
820 * @return String: HTML
821 */
822 public static function makeMediaLinkObj( $title, $text = '', $time = false ) {
823 $img = wfFindFile( $title, array( 'time' => $time ) );
824 return self::makeMediaLinkFile( $title, $img, $text );
825 }
826
827 /**
828 * Create a direct link to a given uploaded file.
829 * This will make a broken link if $file is false.
830 *
831 * @param $title Title object.
832 * @param $file mixed File object or false
833 * @param $text String: pre-sanitized HTML
834 * @return String: HTML
835 *
836 * @todo Handle invalid or missing images better.
837 */
838 public static function makeMediaLinkFile( Title $title, $file, $text = '' ) {
839 if ( $file && $file->exists() ) {
840 $url = $file->getURL();
841 $class = 'internal';
842 } else {
843 $url = self::getUploadUrl( $title );
844 $class = 'new';
845 }
846 $alt = htmlspecialchars( $title->getText(), ENT_QUOTES );
847 if ( $text == '' ) {
848 $text = $alt;
849 }
850 $u = htmlspecialchars( $url );
851 return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\">{$text}</a>";
852 }
853
854 /**
855 * Make a link to a special page given its name and, optionally,
856 * a message key from the link text.
857 * Usage example: $skin->specialLink( 'recentchanges' )
858 */
859 static function specialLink( $name, $key = '' ) {
860 if ( $key == '' ) { $key = strtolower( $name ); }
861
862 return self::linkKnown( SpecialPage::getTitleFor( $name ) , wfMsg( $key ) );
863 }
864
865 /**
866 * Make an external link
867 * @param $url String: URL to link to
868 * @param $text String: text of link
869 * @param $escape Boolean: do we escape the link text?
870 * @param $linktype String: type of external link. Gets added to the classes
871 * @param $attribs Array of extra attributes to <a>
872 */
873 static function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) {
874 $class = "external";
875 if ( isset($linktype) && $linktype ) {
876 $class .= " $linktype";
877 }
878 if ( isset($attribs['class']) && $attribs['class'] ) {
879 $class .= " {$attribs['class']}";
880 }
881 $attribs['class'] = $class;
882
883 if ( $escape ) {
884 $text = htmlspecialchars( $text );
885 }
886 $link = '';
887 $success = wfRunHooks( 'LinkerMakeExternalLink',
888 array( &$url, &$text, &$link, &$attribs, $linktype ) );
889 if ( !$success ) {
890 wfDebug( "Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}\n", true );
891 return $link;
892 }
893 $attribs['href'] = $url;
894 return Html::rawElement( 'a', $attribs, $text );
895 }
896
897 /**
898 * Make user link (or user contributions for unregistered users)
899 * @param $userId Integer: user id in database.
900 * @param $userText String: user name in database
901 * @return String: HTML fragment
902 * @private
903 */
904 static function userLink( $userId, $userText ) {
905 if ( $userId == 0 ) {
906 $page = SpecialPage::getTitleFor( 'Contributions', $userText );
907 } else {
908 $page = Title::makeTitle( NS_USER, $userText );
909 }
910 return self::link( $page, htmlspecialchars( $userText ), array( 'class' => 'mw-userlink' ) );
911 }
912
913 /**
914 * Generate standard user tool links (talk, contributions, block link, etc.)
915 *
916 * @param $userId Integer: user identifier
917 * @param $userText String: user name or IP address
918 * @param $redContribsWhenNoEdits Boolean: should the contributions link be
919 * red if the user has no edits?
920 * @param $flags Integer: customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK)
921 * @param $edits Integer: user edit count (optional, for performance)
922 * @return String: HTML fragment
923 */
924 public static function userToolLinks(
925 $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits = null
926 ) {
927 global $wgUser, $wgDisableAnonTalk, $wgLang;
928 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
929 $blockable = !$flags & self::TOOL_LINKS_NOBLOCK;
930
931 $items = array();
932 if ( $talkable ) {
933 $items[] = self::userTalkLink( $userId, $userText );
934 }
935 if ( $userId ) {
936 // check if the user has an edit
937 $attribs = array();
938 if ( $redContribsWhenNoEdits ) {
939 $count = !is_null( $edits ) ? $edits : User::edits( $userId );
940 if ( $count == 0 ) {
941 $attribs['class'] = 'new';
942 }
943 }
944 $contribsPage = SpecialPage::getTitleFor( 'Contributions', $userText );
945
946 $items[] = self::link( $contribsPage, wfMsgHtml( 'contribslink' ), $attribs );
947 }
948 if ( $blockable && $wgUser->isAllowed( 'block' ) ) {
949 $items[] = self::blockLink( $userId, $userText );
950 }
951
952 if ( $items ) {
953 return ' <span class="mw-usertoollinks">(' . $wgLang->pipeList( $items ) . ')</span>';
954 } else {
955 return '';
956 }
957 }
958
959 /**
960 * Alias for userToolLinks( $userId, $userText, true );
961 * @param $userId Integer: user identifier
962 * @param $userText String: user name or IP address
963 * @param $edits Integer: user edit count (optional, for performance)
964 */
965 public static function userToolLinksRedContribs( $userId, $userText, $edits = null ) {
966 return self::userToolLinks( $userId, $userText, true, 0, $edits );
967 }
968
969
970 /**
971 * @param $userId Integer: user id in database.
972 * @param $userText String: user name in database.
973 * @return String: HTML fragment with user talk link
974 * @private
975 */
976 static function userTalkLink( $userId, $userText ) {
977 $userTalkPage = Title::makeTitle( NS_USER_TALK, $userText );
978 $userTalkLink = self::link( $userTalkPage, wfMsgHtml( 'talkpagelinktext' ) );
979 return $userTalkLink;
980 }
981
982 /**
983 * @param $userId Integer: userid
984 * @param $userText String: user name in database.
985 * @return String: HTML fragment with block link
986 * @private
987 */
988 static function blockLink( $userId, $userText ) {
989 $blockPage = SpecialPage::getTitleFor( 'Block', $userText );
990 $blockLink = self::link( $blockPage, wfMsgHtml( 'blocklink' ) );
991 return $blockLink;
992 }
993
994 /**
995 * Generate a user link if the current user is allowed to view it
996 * @param $rev Revision object.
997 * @param $isPublic Boolean: show only if all users can see it
998 * @return String: HTML fragment
999 */
1000 static function revUserLink( $rev, $isPublic = false ) {
1001 if ( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
1002 $link = wfMsgHtml( 'rev-deleted-user' );
1003 } else if ( $rev->userCan( Revision::DELETED_USER ) ) {
1004 $link = self::userLink( $rev->getUser( Revision::FOR_THIS_USER ),
1005 $rev->getUserText( Revision::FOR_THIS_USER ) );
1006 } else {
1007 $link = wfMsgHtml( 'rev-deleted-user' );
1008 }
1009 if ( $rev->isDeleted( Revision::DELETED_USER ) ) {
1010 return '<span class="history-deleted">' . $link . '</span>';
1011 }
1012 return $link;
1013 }
1014
1015 /**
1016 * Generate a user tool link cluster if the current user is allowed to view it
1017 * @param $rev Revision object.
1018 * @param $isPublic Boolean: show only if all users can see it
1019 * @return string HTML
1020 */
1021 static function revUserTools( $rev, $isPublic = false ) {
1022 if ( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
1023 $link = wfMsgHtml( 'rev-deleted-user' );
1024 } else if ( $rev->userCan( Revision::DELETED_USER ) ) {
1025 $userId = $rev->getUser( Revision::FOR_THIS_USER );
1026 $userText = $rev->getUserText( Revision::FOR_THIS_USER );
1027 $link = self::userLink( $userId, $userText ) .
1028 ' ' . self::userToolLinks( $userId, $userText );
1029 } else {
1030 $link = wfMsgHtml( 'rev-deleted-user' );
1031 }
1032 if ( $rev->isDeleted( Revision::DELETED_USER ) ) {
1033 return ' <span class="history-deleted">' . $link . '</span>';
1034 }
1035 return $link;
1036 }
1037
1038 /**
1039 * This function is called by all recent changes variants, by the page history,
1040 * and by the user contributions list. It is responsible for formatting edit
1041 * comments. It escapes any HTML in the comment, but adds some CSS to format
1042 * auto-generated comments (from section editing) and formats [[wikilinks]].
1043 *
1044 * @author Erik Moeller <moeller@scireview.de>
1045 *
1046 * Note: there's not always a title to pass to this function.
1047 * Since you can't set a default parameter for a reference, I've turned it
1048 * temporarily to a value pass. Should be adjusted further. --brion
1049 *
1050 * @param $comment String
1051 * @param $title Mixed: Title object (to generate link to the section in autocomment) or null
1052 * @param $local Boolean: whether section links should refer to local page
1053 */
1054 static function formatComment( $comment, $title = null, $local = false ) {
1055 wfProfileIn( __METHOD__ );
1056
1057 # Sanitize text a bit:
1058 $comment = str_replace( "\n", " ", $comment );
1059 # Allow HTML entities (for bug 13815)
1060 $comment = Sanitizer::escapeHtmlAllowEntities( $comment );
1061
1062 # Render autocomments and make links:
1063 $comment = self::formatAutocomments( $comment, $title, $local );
1064 $comment = self::formatLinksInComment( $comment, $title, $local );
1065
1066 wfProfileOut( __METHOD__ );
1067 return $comment;
1068 }
1069
1070 static $autocommentTitle;
1071 static $autocommentLocal;
1072
1073 /**
1074 * The pattern for autogen comments is / * foo * /, which makes for
1075 * some nasty regex.
1076 * We look for all comments, match any text before and after the comment,
1077 * add a separator where needed and format the comment itself with CSS
1078 * Called by Linker::formatComment.
1079 *
1080 * @param $comment String: comment text
1081 * @param $title An optional title object used to links to sections
1082 * @param $local Boolean: whether section links should refer to local page
1083 * @return String: formatted comment
1084 */
1085 private static function formatAutocomments( $comment, $title = null, $local = false ) {
1086 // Bah!
1087 self::$autocommentTitle = $title;
1088 self::$autocommentLocal = $local;
1089 $comment = preg_replace_callback(
1090 '!(.*)/\*\s*(.*?)\s*\*/(.*)!',
1091 array( 'Linker', 'formatAutocommentsCallback' ),
1092 $comment );
1093 self::$autocommentTitle = null;
1094 self::$autocommentLocal = null;
1095 return $comment;
1096 }
1097
1098 private static function formatAutocommentsCallback( $match ) {
1099 $title = self::$autocommentTitle;
1100 $local = self::$autocommentLocal;
1101
1102 $pre = $match[1];
1103 $auto = $match[2];
1104 $post = $match[3];
1105 $link = '';
1106 if ( $title ) {
1107 $section = $auto;
1108
1109 # Remove links that a user may have manually put in the autosummary
1110 # This could be improved by copying as much of Parser::stripSectionName as desired.
1111 $section = str_replace( '[[:', '', $section );
1112 $section = str_replace( '[[', '', $section );
1113 $section = str_replace( ']]', '', $section );
1114
1115 $section = Sanitizer::normalizeSectionNameWhitespace( $section ); # bug 22784
1116 if ( $local ) {
1117 $sectionTitle = Title::newFromText( '#' . $section );
1118 } else {
1119 $sectionTitle = Title::makeTitleSafe( $title->getNamespace(),
1120 $title->getDBkey(), $section );
1121 }
1122 if ( $sectionTitle ) {
1123 $link = self::link( $sectionTitle,
1124 htmlspecialchars( wfMsgForContent( 'sectionlink' ) ), array(), array(),
1125 'noclasses' );
1126 } else {
1127 $link = '';
1128 }
1129 }
1130 $auto = "$link$auto";
1131 if ( $pre ) {
1132 # written summary $presep autocomment (summary /* section */)
1133 $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
1134 }
1135 if ( $post ) {
1136 # autocomment $postsep written summary (/* section */ summary)
1137 $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
1138 }
1139 $auto = '<span class="autocomment">' . $auto . '</span>';
1140 $comment = $pre . $auto . $post;
1141 return $comment;
1142 }
1143
1144 static $commentContextTitle;
1145 static $commentLocal;
1146
1147 /**
1148 * Formats wiki links and media links in text; all other wiki formatting
1149 * is ignored
1150 *
1151 * @todo FIXME: Doesn't handle sub-links as in image thumb texts like the main parser
1152 * @param $comment String: text to format links in
1153 * @param $title An optional title object used to links to sections
1154 * @param $local Boolean: whether section links should refer to local page
1155 * @return String
1156 */
1157 public static function formatLinksInComment( $comment, $title = null, $local = false ) {
1158 self::$commentContextTitle = $title;
1159 self::$commentLocal = $local;
1160 $html = preg_replace_callback(
1161 '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
1162 array( 'Linker', 'formatLinksInCommentCallback' ),
1163 $comment );
1164 self::$commentContextTitle = null;
1165 self::$commentLocal = null;
1166 return $html;
1167 }
1168
1169 protected static function formatLinksInCommentCallback( $match ) {
1170 global $wgContLang;
1171
1172 $medians = '(?:' . preg_quote( MWNamespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
1173 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA ), '/' ) . '):';
1174
1175 $comment = $match[0];
1176
1177 # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
1178 if ( strpos( $match[1], '%' ) !== false ) {
1179 $match[1] = str_replace( array( '<', '>' ), array( '&lt;', '&gt;' ), rawurldecode( $match[1] ) );
1180 }
1181
1182 # Handle link renaming [[foo|text]] will show link as "text"
1183 if ( $match[3] != "" ) {
1184 $text = $match[3];
1185 } else {
1186 $text = $match[1];
1187 }
1188 $submatch = array();
1189 $thelink = null;
1190 if ( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1191 # Media link; trail not supported.
1192 $linkRegexp = '/\[\[(.*?)\]\]/';
1193 $title = Title::makeTitleSafe( NS_FILE, $submatch[1] );
1194 $thelink = self::makeMediaLinkObj( $title, $text );
1195 } else {
1196 # Other kind of link
1197 if ( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
1198 $trail = $submatch[1];
1199 } else {
1200 $trail = "";
1201 }
1202 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1203 if ( isset( $match[1][0] ) && $match[1][0] == ':' )
1204 $match[1] = substr( $match[1], 1 );
1205 list( $inside, $trail ) = self::splitTrail( $trail );
1206
1207 $linkText = $text;
1208 $linkTarget = self::normalizeSubpageLink( self::$commentContextTitle,
1209 $match[1], $linkText );
1210
1211 $target = Title::newFromText( $linkTarget );
1212 if ( $target ) {
1213 if ( $target->getText() == '' && $target->getInterwiki() === ''
1214 && !self::$commentLocal && self::$commentContextTitle )
1215 {
1216 $newTarget = clone ( self::$commentContextTitle );
1217 $newTarget->setFragment( '#' . $target->getFragment() );
1218 $target = $newTarget;
1219 }
1220 $thelink = self::link(
1221 $target,
1222 $linkText . $inside
1223 ) . $trail;
1224 }
1225 }
1226 if ( $thelink ) {
1227 // If the link is still valid, go ahead and replace it in!
1228 $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 );
1229 }
1230
1231 return $comment;
1232 }
1233
1234 /**
1235 * @param $contextTitle Title
1236 * @param $target
1237 * @param $text
1238 * @return string
1239 */
1240 static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
1241 # Valid link forms:
1242 # Foobar -- normal
1243 # :Foobar -- override special treatment of prefix (images, language links)
1244 # /Foobar -- convert to CurrentPage/Foobar
1245 # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text
1246 # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1247 # ../Foobar -- convert to CurrentPage/Foobar, from CurrentPage/CurrentSubPage
1248
1249 wfProfileIn( __METHOD__ );
1250 $ret = $target; # default return value is no change
1251
1252 # Some namespaces don't allow subpages,
1253 # so only perform processing if subpages are allowed
1254 if ( $contextTitle && MWNamespace::hasSubpages( $contextTitle->getNamespace() ) ) {
1255 $hash = strpos( $target, '#' );
1256 if ( $hash !== false ) {
1257 $suffix = substr( $target, $hash );
1258 $target = substr( $target, 0, $hash );
1259 } else {
1260 $suffix = '';
1261 }
1262 # bug 7425
1263 $target = trim( $target );
1264 # Look at the first character
1265 if ( $target != '' && $target { 0 } === '/' ) {
1266 # / at end means we don't want the slash to be shown
1267 $m = array();
1268 $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
1269 if ( $trailingSlashes ) {
1270 $noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
1271 } else {
1272 $noslash = substr( $target, 1 );
1273 }
1274
1275 $ret = $contextTitle->getPrefixedText() . '/' . trim( $noslash ) . $suffix;
1276 if ( $text === '' ) {
1277 $text = $target . $suffix;
1278 } # this might be changed for ugliness reasons
1279 } else {
1280 # check for .. subpage backlinks
1281 $dotdotcount = 0;
1282 $nodotdot = $target;
1283 while ( strncmp( $nodotdot, "../", 3 ) == 0 ) {
1284 ++$dotdotcount;
1285 $nodotdot = substr( $nodotdot, 3 );
1286 }
1287 if ( $dotdotcount > 0 ) {
1288 $exploded = explode( '/', $contextTitle->GetPrefixedText() );
1289 if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1290 $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
1291 # / at the end means don't show full path
1292 if ( substr( $nodotdot, -1, 1 ) === '/' ) {
1293 $nodotdot = substr( $nodotdot, 0, -1 );
1294 if ( $text === '' ) {
1295 $text = $nodotdot . $suffix;
1296 }
1297 }
1298 $nodotdot = trim( $nodotdot );
1299 if ( $nodotdot != '' ) {
1300 $ret .= '/' . $nodotdot;
1301 }
1302 $ret .= $suffix;
1303 }
1304 }
1305 }
1306 }
1307
1308 wfProfileOut( __METHOD__ );
1309 return $ret;
1310 }
1311
1312 /**
1313 * Wrap a comment in standard punctuation and formatting if
1314 * it's non-empty, otherwise return empty string.
1315 *
1316 * @param $comment String
1317 * @param $title Mixed: Title object (to generate link to section in autocomment) or null
1318 * @param $local Boolean: whether section links should refer to local page
1319 * @param $embraced Boolean: whether the formatted comment should be embraced with ()
1320 * @return string
1321 */
1322 static function commentBlock( $comment, $title = null, $local = false, $embraced = true ) {
1323 // '*' used to be the comment inserted by the software way back
1324 // in antiquity in case none was provided, here for backwards
1325 // compatability, acc. to brion -ævar
1326 if ( $comment == '' || $comment == '*' ) {
1327 return '';
1328 } else {
1329 $formatted = self::formatComment( $comment, $title, $local );
1330 if ( $embraced ) {
1331 $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped();
1332 }
1333 return Html::rawElement( 'span', array( 'class' => 'comment' ), $formatted );
1334 }
1335 }
1336
1337 /**
1338 * Wrap and format the given revision's comment block, if the current
1339 * user is allowed to view it.
1340 *
1341 * @param $rev Revision object
1342 * @param $local Boolean: whether section links should refer to local page
1343 * @param $isPublic Boolean: show only if all users can see it
1344 * @return String: HTML fragment
1345 */
1346 static function revComment( Revision $rev, $local = false, $isPublic = false ) {
1347 if ( $rev->getRawComment() == "" ) {
1348 return "";
1349 }
1350 if ( $rev->isDeleted( Revision::DELETED_COMMENT ) && $isPublic ) {
1351 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1352 } else if ( $rev->userCan( Revision::DELETED_COMMENT ) ) {
1353 $block = self::commentBlock( $rev->getComment( Revision::FOR_THIS_USER ),
1354 $rev->getTitle(), $local );
1355 } else {
1356 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1357 }
1358 if ( $rev->isDeleted( Revision::DELETED_COMMENT ) ) {
1359 return " <span class=\"history-deleted\">$block</span>";
1360 }
1361 return $block;
1362 }
1363
1364 public static function formatRevisionSize( $size ) {
1365 if ( $size == 0 ) {
1366 $stxt = wfMsgExt( 'historyempty', 'parsemag' );
1367 } else {
1368 global $wgLang;
1369 $stxt = wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $size ) );
1370 $stxt = "($stxt)";
1371 }
1372 $stxt = htmlspecialchars( $stxt );
1373 return "<span class=\"history-size\">$stxt</span>";
1374 }
1375
1376 /**
1377 * Add another level to the Table of Contents
1378 */
1379 static function tocIndent() {
1380 return "\n<ul>";
1381 }
1382
1383 /**
1384 * Finish one or more sublevels on the Table of Contents
1385 */
1386 static function tocUnindent( $level ) {
1387 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level > 0 ? $level : 0 );
1388 }
1389
1390 /**
1391 * parameter level defines if we are on an indentation level
1392 */
1393 static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
1394 $classes = "toclevel-$level";
1395 if ( $sectionIndex !== false )
1396 $classes .= " tocsection-$sectionIndex";
1397 return "\n<li class=\"$classes\"><a href=\"#" .
1398 $anchor . '"><span class="tocnumber">' .
1399 $tocnumber . '</span> <span class="toctext">' .
1400 $tocline . '</span></a>';
1401 }
1402
1403 /**
1404 * End a Table Of Contents line.
1405 * tocUnindent() will be used instead if we're ending a line below
1406 * the new level.
1407 */
1408 static function tocLineEnd() {
1409 return "</li>\n";
1410 }
1411
1412 /**
1413 * Wraps the TOC in a table and provides the hide/collapse javascript.
1414 *
1415 * @param $toc String: html of the Table Of Contents
1416 * @param $lang mixed: Language code for the toc title
1417 * @return String: full html of the TOC
1418 */
1419 static function tocList( $toc, $lang = false ) {
1420 $title = wfMsgExt( 'toc', array( 'language' => $lang, 'escape' ) );
1421 return
1422 '<table id="toc" class="toc"><tr><td>'
1423 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
1424 . $toc
1425 . "</ul>\n</td></tr></table>\n";
1426 }
1427
1428 /**
1429 * Generate a table of contents from a section tree
1430 * Currently unused.
1431 *
1432 * @param $tree Return value of ParserOutput::getSections()
1433 * @return String: HTML fragment
1434 */
1435 public static function generateTOC( $tree ) {
1436 $toc = '';
1437 $lastLevel = 0;
1438 foreach ( $tree as $section ) {
1439 if ( $section['toclevel'] > $lastLevel )
1440 $toc .= self::tocIndent();
1441 else if ( $section['toclevel'] < $lastLevel )
1442 $toc .= self::tocUnindent(
1443 $lastLevel - $section['toclevel'] );
1444 else
1445 $toc .= self::tocLineEnd();
1446
1447 $toc .= self::tocLine( $section['anchor'],
1448 $section['line'], $section['number'],
1449 $section['toclevel'], $section['index'] );
1450 $lastLevel = $section['toclevel'];
1451 }
1452 $toc .= self::tocLineEnd();
1453 return self::tocList( $toc );
1454 }
1455
1456 /**
1457 * Create a headline for content
1458 *
1459 * @param $level Integer: the level of the headline (1-6)
1460 * @param $attribs String: any attributes for the headline, starting with
1461 * a space and ending with '>'
1462 * This *must* be at least '>' for no attribs
1463 * @param $anchor String: the anchor to give the headline (the bit after the #)
1464 * @param $text String: the text of the header
1465 * @param $link String: HTML to add for the section edit link
1466 * @param $legacyAnchor Mixed: a second, optional anchor to give for
1467 * backward compatibility (false to omit)
1468 *
1469 * @return String: HTML headline
1470 */
1471 public static function makeHeadline( $level, $attribs, $anchor, $text, $link, $legacyAnchor = false ) {
1472 $ret = "<h$level$attribs"
1473 . $link
1474 . " <span class=\"mw-headline\" id=\"$anchor\">$text</span>"
1475 . "</h$level>";
1476 if ( $legacyAnchor !== false ) {
1477 $ret = "<div id=\"$legacyAnchor\"></div>$ret";
1478 }
1479 return $ret;
1480 }
1481
1482 /**
1483 * Split a link trail, return the "inside" portion and the remainder of the trail
1484 * as a two-element array
1485 */
1486 static function splitTrail( $trail ) {
1487 global $wgContLang;
1488 $regex = $wgContLang->linkTrail();
1489 $inside = '';
1490 if ( $trail !== '' ) {
1491 $m = array();
1492 if ( preg_match( $regex, $trail, $m ) ) {
1493 $inside = $m[1];
1494 $trail = $m[2];
1495 }
1496 }
1497 return array( $inside, $trail );
1498 }
1499
1500 /**
1501 * Generate a rollback link for a given revision. Currently it's the
1502 * caller's responsibility to ensure that the revision is the top one. If
1503 * it's not, of course, the user will get an error message.
1504 *
1505 * If the calling page is called with the parameter &bot=1, all rollback
1506 * links also get that parameter. It causes the edit itself and the rollback
1507 * to be marked as "bot" edits. Bot edits are hidden by default from recent
1508 * changes, so this allows sysops to combat a busy vandal without bothering
1509 * other users.
1510 *
1511 * @param $rev Revision object
1512 */
1513 static function generateRollback( $rev ) {
1514 return '<span class="mw-rollback-link">['
1515 . self::buildRollbackLink( $rev )
1516 . ']</span>';
1517 }
1518
1519 /**
1520 * Build a raw rollback link, useful for collections of "tool" links
1521 *
1522 * @param $rev Revision object
1523 * @return String: HTML fragment
1524 */
1525 public static function buildRollbackLink( $rev ) {
1526 global $wgRequest, $wgUser;
1527 $title = $rev->getTitle();
1528 $query = array(
1529 'action' => 'rollback',
1530 'from' => $rev->getUserText(),
1531 'token' => $wgUser->editToken( array( $title->getPrefixedText(), $rev->getUserText() ) ),
1532 );
1533 if ( $wgRequest->getBool( 'bot' ) ) {
1534 $query['bot'] = '1';
1535 $query['hidediff'] = '1'; // bug 15999
1536 }
1537 return self::link(
1538 $title,
1539 wfMsgHtml( 'rollbacklink' ),
1540 array( 'title' => wfMsg( 'tooltip-rollback' ) ),
1541 $query,
1542 array( 'known', 'noclasses' )
1543 );
1544 }
1545
1546 /**
1547 * Returns HTML for the "templates used on this page" list.
1548 *
1549 * @param $templates Array of templates from Article::getUsedTemplate
1550 * or similar
1551 * @param $preview Boolean: whether this is for a preview
1552 * @param $section Boolean: whether this is for a section edit
1553 * @return String: HTML output
1554 */
1555 public static function formatTemplates( $templates, $preview = false, $section = false ) {
1556 wfProfileIn( __METHOD__ );
1557
1558 $outText = '';
1559 if ( count( $templates ) > 0 ) {
1560 # Do a batch existence check
1561 $batch = new LinkBatch;
1562 foreach ( $templates as $title ) {
1563 $batch->addObj( $title );
1564 }
1565 $batch->execute();
1566
1567 # Construct the HTML
1568 $outText = '<div class="mw-templatesUsedExplanation">';
1569 if ( $preview ) {
1570 $outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ), count( $templates ) );
1571 } elseif ( $section ) {
1572 $outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ), count( $templates ) );
1573 } else {
1574 $outText .= wfMsgExt( 'templatesused', array( 'parse' ), count( $templates ) );
1575 }
1576 $outText .= "</div><ul>\n";
1577
1578 usort( $templates, array( 'Title', 'compare' ) );
1579 foreach ( $templates as $titleObj ) {
1580 $r = $titleObj->getRestrictions( 'edit' );
1581 if ( in_array( 'sysop', $r ) ) {
1582 $protected = wfMsgExt( 'template-protected', array( 'parseinline' ) );
1583 } elseif ( in_array( 'autoconfirmed', $r ) ) {
1584 $protected = wfMsgExt( 'template-semiprotected', array( 'parseinline' ) );
1585 } else {
1586 $protected = '';
1587 }
1588 if ( $titleObj->quickUserCan( 'edit' ) ) {
1589 $editLink = self::link(
1590 $titleObj,
1591 wfMsg( 'editlink' ),
1592 array(),
1593 array( 'action' => 'edit' )
1594 );
1595 } else {
1596 $editLink = self::link(
1597 $titleObj,
1598 wfMsg( 'viewsourcelink' ),
1599 array(),
1600 array( 'action' => 'edit' )
1601 );
1602 }
1603 $outText .= '<li>' . self::link( $titleObj ) . ' (' . $editLink . ') ' . $protected . '</li>';
1604 }
1605 $outText .= '</ul>';
1606 }
1607 wfProfileOut( __METHOD__ );
1608 return $outText;
1609 }
1610
1611 /**
1612 * Returns HTML for the "hidden categories on this page" list.
1613 *
1614 * @param $hiddencats Array of hidden categories from Article::getHiddenCategories
1615 * or similar
1616 * @return String: HTML output
1617 */
1618 public static function formatHiddenCategories( $hiddencats ) {
1619 global $wgLang;
1620 wfProfileIn( __METHOD__ );
1621
1622 $outText = '';
1623 if ( count( $hiddencats ) > 0 ) {
1624 # Construct the HTML
1625 $outText = '<div class="mw-hiddenCategoriesExplanation">';
1626 $outText .= wfMsgExt( 'hiddencategories', array( 'parse' ), $wgLang->formatnum( count( $hiddencats ) ) );
1627 $outText .= "</div><ul>\n";
1628
1629 foreach ( $hiddencats as $titleObj ) {
1630 $outText .= '<li>' . self::link( $titleObj, null, array(), array(), 'known' ) . "</li>\n"; # If it's hidden, it must exist - no need to check with a LinkBatch
1631 }
1632 $outText .= '</ul>';
1633 }
1634 wfProfileOut( __METHOD__ );
1635 return $outText;
1636 }
1637
1638 /**
1639 * Format a size in bytes for output, using an appropriate
1640 * unit (B, KB, MB or GB) according to the magnitude in question
1641 *
1642 * @param $size Size to format
1643 * @return String
1644 */
1645 public static function formatSize( $size ) {
1646 global $wgLang;
1647 return htmlspecialchars( $wgLang->formatSize( $size ) );
1648 }
1649
1650 /**
1651 * Given the id of an interface element, constructs the appropriate title
1652 * attribute from the system messages. (Note, this is usually the id but
1653 * isn't always, because sometimes the accesskey needs to go on a different
1654 * element than the id, for reverse-compatibility, etc.)
1655 *
1656 * @param $name String: id of the element, minus prefixes.
1657 * @param $options Mixed: null or the string 'withaccess' to add an access-
1658 * key hint
1659 * @return String: contents of the title attribute (which you must HTML-
1660 * escape), or false for no title attribute
1661 */
1662 public static function titleAttrib( $name, $options = null ) {
1663 wfProfileIn( __METHOD__ );
1664
1665 $message = wfMessage( "tooltip-$name" );
1666
1667 if ( !$message->exists() ) {
1668 $tooltip = false;
1669 } else {
1670 $tooltip = $message->text();
1671 # Compatibility: formerly some tooltips had [alt-.] hardcoded
1672 $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
1673 # Message equal to '-' means suppress it.
1674 if ( $tooltip == '-' ) {
1675 $tooltip = false;
1676 }
1677 }
1678
1679 if ( $options == 'withaccess' ) {
1680 $accesskey = self::accesskey( $name );
1681 if ( $accesskey !== false ) {
1682 if ( $tooltip === false || $tooltip === '' ) {
1683 $tooltip = "[$accesskey]";
1684 } else {
1685 $tooltip .= " [$accesskey]";
1686 }
1687 }
1688 }
1689
1690 wfProfileOut( __METHOD__ );
1691 return $tooltip;
1692 }
1693
1694 static $accesskeycache;
1695
1696 /**
1697 * Given the id of an interface element, constructs the appropriate
1698 * accesskey attribute from the system messages. (Note, this is usually
1699 * the id but isn't always, because sometimes the accesskey needs to go on
1700 * a different element than the id, for reverse-compatibility, etc.)
1701 *
1702 * @param $name String: id of the element, minus prefixes.
1703 * @return String: contents of the accesskey attribute (which you must HTML-
1704 * escape), or false for no accesskey attribute
1705 */
1706 public static function accesskey( $name ) {
1707 if ( isset( self::$accesskeycache[$name] ) ) {
1708 return self::$accesskeycache[$name];
1709 }
1710 wfProfileIn( __METHOD__ );
1711
1712 $message = wfMessage( "accesskey-$name" );
1713
1714 if ( !$message->exists() ) {
1715 $accesskey = false;
1716 } else {
1717 $accesskey = $message->plain();
1718 if ( $accesskey === '' || $accesskey === '-' ) {
1719 # @todo FIXME: Per standard MW behavior, a value of '-' means to suppress the
1720 # attribute, but this is broken for accesskey: that might be a useful
1721 # value.
1722 $accesskey = false;
1723 }
1724 }
1725
1726 wfProfileOut( __METHOD__ );
1727 return self::$accesskeycache[$name] = $accesskey;
1728 }
1729
1730 /**
1731 * Creates a (show/hide) link for deleting revisions/log entries
1732 *
1733 * @param $query Array: query parameters to be passed to link()
1734 * @param $restricted Boolean: set to true to use a <strong> instead of a <span>
1735 * @param $delete Boolean: set to true to use (show/hide) rather than (show)
1736 *
1737 * @return String: HTML <a> link to Special:Revisiondelete, wrapped in a
1738 * span to allow for customization of appearance with CSS
1739 */
1740 public static function revDeleteLink( $query = array(), $restricted = false, $delete = true ) {
1741 $sp = SpecialPage::getTitleFor( 'Revisiondelete' );
1742 $text = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' );
1743 $tag = $restricted ? 'strong' : 'span';
1744 $link = self::link( $sp, $text, array(), $query, array( 'known', 'noclasses' ) );
1745 return Xml::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), "($link)" );
1746 }
1747
1748 /**
1749 * Creates a dead (show/hide) link for deleting revisions/log entries
1750 *
1751 * @param $delete Boolean: set to true to use (show/hide) rather than (show)
1752 *
1753 * @return string HTML text wrapped in a span to allow for customization
1754 * of appearance with CSS
1755 */
1756 public static function revDeleteLinkDisabled( $delete = true ) {
1757 $text = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' );
1758 return Xml::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), "($text)" );
1759 }
1760
1761 /* Deprecated methods */
1762
1763 /**
1764 * @deprecated since 1.16 Use link()
1765 *
1766 * This function is a shortcut to makeBrokenLinkObj(Title::newFromText($title),...). Do not call
1767 * it if you already have a title object handy. See makeBrokenLinkObj for further documentation.
1768 *
1769 * @param $title String: The text of the title
1770 * @param $text String: Link text
1771 * @param $query String: Optional query part
1772 * @param $trail String: Optional trail. Alphabetic characters at the start of this string will
1773 * be included in the link text. Other characters will be appended after
1774 * the end of the link.
1775 */
1776 static function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
1777 $nt = Title::newFromText( $title );
1778 if ( $nt instanceof Title ) {
1779 return self::makeBrokenLinkObj( $nt, $text, $query, $trail );
1780 } else {
1781 wfDebug( 'Invalid title passed to self::makeBrokenLink(): "' . $title . "\"\n" );
1782 return $text == '' ? $title : $text;
1783 }
1784 }
1785
1786 /**
1787 * @deprecated since 1.16 Use link()
1788 *
1789 * Make a link for a title which may or may not be in the database. If you need to
1790 * call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
1791 * call to this will result in a DB query.
1792 *
1793 * @param $nt Title: the title object to make the link from, e.g. from
1794 * Title::newFromText.
1795 * @param $text String: link text
1796 * @param $query String: optional query part
1797 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1798 * be included in the link text. Other characters will be appended after
1799 * the end of the link.
1800 * @param $prefix String: optional prefix. As trail, only before instead of after.
1801 */
1802 static function makeLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1803 wfProfileIn( __METHOD__ );
1804 $query = wfCgiToArray( $query );
1805 list( $inside, $trail ) = self::splitTrail( $trail );
1806 if ( $text === '' ) {
1807 $text = self::linkText( $nt );
1808 }
1809
1810 $ret = self::link( $nt, "$prefix$text$inside", array(), $query ) . $trail;
1811
1812 wfProfileOut( __METHOD__ );
1813 return $ret;
1814 }
1815
1816 /**
1817 * @deprecated since 1.16 Use link()
1818 *
1819 * Make a link for a title which definitely exists. This is faster than makeLinkObj because
1820 * it doesn't have to do a database query. It's also valid for interwiki titles and special
1821 * pages.
1822 *
1823 * @param $title Title object of target page
1824 * @param $text String: text to replace the title
1825 * @param $query String: link target
1826 * @param $trail String: text after link
1827 * @param $prefix String: text before link text
1828 * @param $aprops String: extra attributes to the a-element
1829 * @param $style String: style to apply - if empty, use getInternalLinkAttributesObj instead
1830 * @return the a-element
1831 */
1832 static function makeKnownLinkObj(
1833 $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = ''
1834 ) {
1835 wfProfileIn( __METHOD__ );
1836
1837 if ( $text == '' ) {
1838 $text = self::linkText( $title );
1839 }
1840 $attribs = Sanitizer::mergeAttributes(
1841 Sanitizer::decodeTagAttributes( $aprops ),
1842 Sanitizer::decodeTagAttributes( $style )
1843 );
1844 $query = wfCgiToArray( $query );
1845 list( $inside, $trail ) = self::splitTrail( $trail );
1846
1847 $ret = self::link( $title, "$prefix$text$inside", $attribs, $query,
1848 array( 'known', 'noclasses' ) ) . $trail;
1849
1850 wfProfileOut( __METHOD__ );
1851 return $ret;
1852 }
1853
1854 /**
1855 * @deprecated since 1.16 Use link()
1856 *
1857 * Make a red link to the edit page of a given title.
1858 *
1859 * @param $title Title object of the target page
1860 * @param $text String: Link text
1861 * @param $query String: Optional query part
1862 * @param $trail String: Optional trail. Alphabetic characters at the start of this string will
1863 * be included in the link text. Other characters will be appended after
1864 * the end of the link.
1865 * @param $prefix String: Optional prefix
1866 */
1867 static function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
1868 wfProfileIn( __METHOD__ );
1869
1870 list( $inside, $trail ) = self::splitTrail( $trail );
1871 if ( $text === '' ) {
1872 $text = self::linkText( $title );
1873 }
1874
1875 $ret = self::link( $title, "$prefix$text$inside", array(),
1876 wfCgiToArray( $query ), 'broken' ) . $trail;
1877
1878 wfProfileOut( __METHOD__ );
1879 return $ret;
1880 }
1881
1882 /**
1883 * @deprecated since 1.16 Use link()
1884 *
1885 * Make a coloured link.
1886 *
1887 * @param $nt Title object of the target page
1888 * @param $colour Integer: colour of the link
1889 * @param $text String: link text
1890 * @param $query String: optional query part
1891 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1892 * be included in the link text. Other characters will be appended after
1893 * the end of the link.
1894 * @param $prefix String: Optional prefix
1895 */
1896 static function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
1897 if ( $colour != '' ) {
1898 $style = self::getInternalLinkAttributesObj( $nt, $text, $colour );
1899 } else {
1900 $style = '';
1901 }
1902 return self::makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style );
1903 }
1904
1905 /**
1906 * Returns the attributes for the tooltip and access key.
1907 */
1908 public static function tooltipAndAccesskeyAttribs( $name ) {
1909 global $wgEnableTooltipsAndAccesskeys;
1910 if ( !$wgEnableTooltipsAndAccesskeys )
1911 return array();
1912 # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
1913 # no attribute" instead of "output '' as value for attribute", this
1914 # would be three lines.
1915 $attribs = array(
1916 'title' => self::titleAttrib( $name, 'withaccess' ),
1917 'accesskey' => self::accesskey( $name )
1918 );
1919 if ( $attribs['title'] === false ) {
1920 unset( $attribs['title'] );
1921 }
1922 if ( $attribs['accesskey'] === false ) {
1923 unset( $attribs['accesskey'] );
1924 }
1925 return $attribs;
1926 }
1927
1928 /**
1929 * @deprecated since 1.14
1930 * Returns raw bits of HTML, use titleAttrib()
1931 */
1932 public static function tooltip( $name, $options = null ) {
1933 global $wgEnableTooltipsAndAccesskeys;
1934 if ( !$wgEnableTooltipsAndAccesskeys )
1935 return '';
1936 # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
1937 # no attribute" instead of "output '' as value for attribute", this
1938 # would be two lines.
1939 $tooltip = self::titleAttrib( $name, $options );
1940 if ( $tooltip === false ) {
1941 return '';
1942 }
1943 return Xml::expandAttributes( array(
1944 'title' => $tooltip
1945 ) );
1946 }
1947 }
1948
1949 class DummyLinker {
1950
1951 /**
1952 * Use PHP's magic __call handler to transform instance calls to a dummy instance
1953 * into static calls to the new Linker for backwards compatibility.
1954 *
1955 * @param $fname String Name of called method
1956 * @param $args Array Arguments to the method
1957 */
1958 function __call( $fname, $args ) {
1959 return call_user_func_array( array( 'Linker', $fname ), $args );
1960 }
1961
1962 }
1963