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