Title attributes are now always blank on framed and thumbnailed images, and default...
[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 if ( !isset( $fp['title'] ) ) $fp['title'] = '';
451
452 $prefix = $postfix = '';
453
454 if ( 'center' == $fp['align'] ) {
455 $prefix = '<div class="center">';
456 $postfix = '</div>';
457 $fp['align'] = 'none';
458 }
459 if ( $file && !isset( $hp['width'] ) ) {
460 $hp['width'] = $file->getWidth( $page );
461
462 if( isset( $fp['thumbnail'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) || !$hp['width'] ) {
463 $wopt = $wgUser->getOption( 'thumbsize' );
464
465 if( !isset( $wgThumbLimits[$wopt] ) ) {
466 $wopt = User::getDefaultOption( 'thumbsize' );
467 }
468
469 // Reduce width for upright images when parameter 'upright' is used
470 if ( isset( $fp['upright'] ) && $fp['upright'] == 0 ) {
471 $fp['upright'] = $wgThumbUpright;
472 }
473 // Use width which is smaller: real image width or user preference width
474 // 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
475 $prefWidth = isset( $fp['upright'] ) ?
476 round( $wgThumbLimits[$wopt] * $fp['upright'], -1 ) :
477 $wgThumbLimits[$wopt];
478 if ( $hp['width'] <= 0 || $prefWidth < $hp['width'] ) {
479 $hp['width'] = $prefWidth;
480 }
481 }
482 }
483
484 if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) ) {
485 # Create a thumbnail. Alignment depends on language
486 # writing direction, # right aligned for left-to-right-
487 # languages ("Western languages"), left-aligned
488 # for right-to-left-languages ("Semitic languages")
489 #
490 # If thumbnail width has not been provided, it is set
491 # to the default user option as specified in Language*.php
492 if ( $fp['align'] == '' ) {
493 $fp['align'] = $wgContLang->isRTL() ? 'left' : 'right';
494 }
495 return $prefix.$this->makeThumbLink2( $title, $file, $fp, $hp, $time, $query ).$postfix;
496 }
497
498 if ( $file && isset( $fp['frameless'] ) ) {
499 $srcWidth = $file->getWidth( $page );
500 # For "frameless" option: do not present an image bigger than the source (for bitmap-style images)
501 # This is the same behaviour as the "thumb" option does it already.
502 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
503 $hp['width'] = $srcWidth;
504 }
505 }
506
507 if ( $file && $hp['width'] ) {
508 # Create a resized image, without the additional thumbnail features
509 $thumb = $file->transform( $hp );
510 } else {
511 $thumb = false;
512 }
513
514 if ( !$thumb ) {
515 $s = $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
516 } else {
517 $params = array(
518 'alt' => $fp['alt'],
519 'title' => $fp['title'],
520 'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false ,
521 'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false );
522 if ( !empty( $fp['link-url'] ) ) {
523 $params['custom-url-link'] = $fp['link-url'];
524 } elseif ( !empty( $fp['link-title'] ) ) {
525 $params['custom-title-link'] = $fp['link-title'];
526 } elseif ( !empty( $fp['no-link'] ) ) {
527 // No link
528 } else {
529 $params['desc-link'] = true;
530 $params['desc-query'] = $query;
531 }
532
533 $s = $thumb->toHtml( $params );
534 }
535 if ( '' != $fp['align'] ) {
536 $s = "<div class=\"float{$fp['align']}\">{$s}</div>";
537 }
538 return str_replace("\n", ' ',$prefix.$s.$postfix);
539 }
540
541 /**
542 * Make HTML for a thumbnail including image, border and caption
543 * @param Title $title
544 * @param File $file File object or false if it doesn't exist
545 */
546 function makeThumbLinkObj( Title $title, $file, $label = '', $alt, $align = 'right', $params = array(), $framed=false , $manualthumb = "" ) {
547 $frameParams = array(
548 'alt' => $alt,
549 'caption' => $label,
550 'align' => $align
551 );
552 if ( $framed ) $frameParams['framed'] = true;
553 if ( $manualthumb ) $frameParams['manualthumb'] = $manualthumb;
554 return $this->makeThumbLink2( $title, $file, $frameParams, $params );
555 }
556
557 function makeThumbLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
558 global $wgStylePath, $wgContLang;
559 $exists = $file && $file->exists();
560
561 # Shortcuts
562 $fp =& $frameParams;
563 $hp =& $handlerParams;
564
565 $page = isset( $hp['page'] ) ? $hp['page'] : false;
566 if ( !isset( $fp['align'] ) ) $fp['align'] = 'right';
567 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
568 if ( !isset( $fp['title'] ) ) $fp['title'] = '';
569 if ( !isset( $fp['caption'] ) ) $fp['caption'] = '';
570
571 if ( empty( $hp['width'] ) ) {
572 // Reduce width for upright images when parameter 'upright' is used
573 $hp['width'] = isset( $fp['upright'] ) ? 130 : 180;
574 }
575 $thumb = false;
576
577 if ( !$exists ) {
578 $outerWidth = $hp['width'] + 2;
579 } else {
580 if ( isset( $fp['manualthumb'] ) ) {
581 # Use manually specified thumbnail
582 $manual_title = Title::makeTitleSafe( NS_FILE, $fp['manualthumb'] );
583 if( $manual_title ) {
584 $manual_img = wfFindFile( $manual_title );
585 if ( $manual_img ) {
586 $thumb = $manual_img->getUnscaledThumb();
587 } else {
588 $exists = false;
589 }
590 }
591 } elseif ( isset( $fp['framed'] ) ) {
592 // Use image dimensions, don't scale
593 $thumb = $file->getUnscaledThumb( $page );
594 } else {
595 # Do not present an image bigger than the source, for bitmap-style images
596 # This is a hack to maintain compatibility with arbitrary pre-1.10 behaviour
597 $srcWidth = $file->getWidth( $page );
598 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
599 $hp['width'] = $srcWidth;
600 }
601 $thumb = $file->transform( $hp );
602 }
603
604 if ( $thumb ) {
605 $outerWidth = $thumb->getWidth() + 2;
606 } else {
607 $outerWidth = $hp['width'] + 2;
608 }
609 }
610
611 # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
612 # So we don't need to pass it here in $query. However, the URL for the
613 # zoom icon still needs it, so we make a unique query for it. See bug 14771
614 $url = $title->getLocalURL( $query );
615 if( $page ) {
616 $url = wfAppendQuery( $url, 'page=' . urlencode( $page ) );
617 }
618
619 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
620
621 $s = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
622 if( !$exists ) {
623 $s .= $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
624 $zoomicon = '';
625 } elseif ( !$thumb ) {
626 $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
627 $zoomicon = '';
628 } else {
629 $s .= $thumb->toHtml( array(
630 'alt' => $fp['alt'],
631 'title' => $fp['title'],
632 'img-class' => 'thumbimage',
633 'desc-link' => true,
634 'desc-query' => $query ) );
635 if ( isset( $fp['framed'] ) ) {
636 $zoomicon="";
637 } else {
638 $zoomicon = '<div class="magnify">'.
639 '<a href="'.$url.'" class="internal" title="'.$more.'">'.
640 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
641 'width="15" height="11" alt="" /></a></div>';
642 }
643 }
644 $s .= ' <div class="thumbcaption">'.$zoomicon.$fp['caption']."</div></div></div>";
645 return str_replace("\n", ' ', $s);
646 }
647
648 /**
649 * Make a "broken" link to an image
650 *
651 * @param Title $title Image title
652 * @param string $text Link label
653 * @param string $query Query string
654 * @param string $trail Link trail
655 * @param string $prefix Link prefix
656 * @param bool $time, a file of a certain timestamp was requested
657 * @return string
658 */
659 public function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '', $time = false ) {
660 global $wgEnableUploads;
661 if( $title instanceof Title ) {
662 wfProfileIn( __METHOD__ );
663 $currentExists = $time ? ( wfFindFile( $title ) != false ) : false;
664 if( $wgEnableUploads && !$currentExists ) {
665 $upload = SpecialPage::getTitleFor( 'Upload' );
666 if( $text == '' )
667 $text = htmlspecialchars( $title->getPrefixedText() );
668 $redir = RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title );
669 if( $redir ) {
670 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
671 }
672 $q = 'wpDestFile=' . $title->getPartialUrl();
673 if( $query != '' )
674 $q .= '&' . $query;
675 list( $inside, $trail ) = self::splitTrail( $trail );
676 $style = $this->getInternalLinkAttributesObj( $title, $text, 'new' );
677 wfProfileOut( __METHOD__ );
678 return '<a href="' . $upload->escapeLocalUrl( $q ) . '"'
679 . $style . '>' . $prefix . $text . $inside . '</a>' . $trail;
680 } else {
681 wfProfileOut( __METHOD__ );
682 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
683 }
684 } else {
685 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
686 }
687 }
688
689 /**
690 * Create a direct link to a given uploaded file.
691 *
692 * @param $title Title object.
693 * @param $text String: pre-sanitized HTML
694 * @param $time string: time image was created
695 * @return string HTML
696 *
697 * @public
698 * @todo Handle invalid or missing images better.
699 */
700 function makeMediaLinkObj( $title, $text = '', $time = false ) {
701 if( is_null( $title ) ) {
702 ### HOTFIX. Instead of breaking, return empty string.
703 return $text;
704 } else {
705 $img = wfFindFile( $title, $time );
706 if( $img ) {
707 $url = $img->getURL();
708 $class = 'internal';
709 } else {
710 $upload = SpecialPage::getTitleFor( 'Upload' );
711 $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $title->getDBkey() ) );
712 $class = 'new';
713 }
714 $alt = htmlspecialchars( $title->getText() );
715 if( $text == '' ) {
716 $text = $alt;
717 }
718 $u = htmlspecialchars( $url );
719 return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\">{$text}</a>";
720 }
721 }
722
723 /** @todo document */
724 function specialLink( $name, $key = '' ) {
725 global $wgContLang;
726
727 if ( '' == $key ) { $key = strtolower( $name ); }
728 $pn = $wgContLang->ucfirst( $name );
729 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
730 wfMsg( $key ) );
731 }
732
733 /**
734 * Make an external link
735 * @param String $url URL to link to
736 * @param String $text text of link
737 * @param boolean $escape Do we escape the link text?
738 * @param String $linktype Type of external link. Gets added to the classes
739 * @param array $attribs Array of extra attributes to <a>
740 *
741 * @TODO! @FIXME! This is a really crappy implementation. $linktype and
742 * 'external' are mashed into the class attrib for the link (which is made
743 * into a string). Then, if we've got additional params in $attribs, we
744 * add to it. People using this might want to change the classes (or other
745 * default link attributes), but passing $attribsText is just messy. Would
746 * make a lot more sense to make put the classes into $attribs, let the
747 * hook play with them, *then* expand it all at once.
748 */
749 function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) {
750 $attribsText = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
751 $url = htmlspecialchars( $url );
752 if( $escape ) {
753 $text = htmlspecialchars( $text );
754 }
755 $link = '';
756 $success = wfRunHooks('LinkerMakeExternalLink', array( &$url, &$text, &$link, &$attribs, $linktype ) );
757 if(!$success) {
758 wfDebug("Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}\n", true);
759 return $link;
760 }
761 if ( $attribs ) {
762 $attribsText .= Xml::expandAttributes( $attribs );
763 }
764 return '<a href="'.$url.'"'.$attribsText.'>'.$text.'</a>';
765 }
766
767 /**
768 * Make user link (or user contributions for unregistered users)
769 * @param $userId Integer: user id in database.
770 * @param $userText String: user name in database
771 * @return string HTML fragment
772 * @private
773 */
774 function userLink( $userId, $userText ) {
775 if( $userId == 0 ) {
776 $page = SpecialPage::getTitleFor( 'Contributions', $userText );
777 } else {
778 $page = Title::makeTitle( NS_USER, $userText );
779 }
780 return $this->link( $page, htmlspecialchars( $userText ), array( 'class' => 'mw-userlink' ) );
781 }
782
783 /**
784 * Generate standard user tool links (talk, contributions, block link, etc.)
785 *
786 * @param int $userId User identifier
787 * @param string $userText User name or IP address
788 * @param bool $redContribsWhenNoEdits Should the contributions link be red if the user has no edits?
789 * @param int $flags Customisation flags (e.g. self::TOOL_LINKS_NOBLOCK)
790 * @param int $edits, user edit count (optional, for performance)
791 * @return string
792 */
793 public function userToolLinks( $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits=null ) {
794 global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans, $wgLang;
795 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
796 $blockable = ( $wgSysopUserBans || 0 == $userId ) && !$flags & self::TOOL_LINKS_NOBLOCK;
797
798 $items = array();
799 if( $talkable ) {
800 $items[] = $this->userTalkLink( $userId, $userText );
801 }
802 if( $userId ) {
803 // check if the user has an edit
804 $attribs = array();
805 if( $redContribsWhenNoEdits ) {
806 $count = !is_null($edits) ? $edits : User::edits( $userId );
807 if( $count == 0 ) {
808 $attribs['class'] = 'new';
809 }
810 }
811 $contribsPage = SpecialPage::getTitleFor( 'Contributions', $userText );
812
813 $items[] = $this->link( $contribsPage, wfMsgHtml( 'contribslink' ), $attribs );
814 }
815 if( $blockable && $wgUser->isAllowed( 'block' ) ) {
816 $items[] = $this->blockLink( $userId, $userText );
817 }
818
819 if( $items ) {
820 return ' <span class="mw-usertoollinks">(' . $wgLang->pipeList( $items ) . ')</span>';
821 } else {
822 return '';
823 }
824 }
825
826 /**
827 * Alias for userToolLinks( $userId, $userText, true );
828 * @param int $userId User identifier
829 * @param string $userText User name or IP address
830 * @param int $edits, user edit count (optional, for performance)
831 */
832 public function userToolLinksRedContribs( $userId, $userText, $edits=null ) {
833 return $this->userToolLinks( $userId, $userText, true, 0, $edits );
834 }
835
836
837 /**
838 * @param $userId Integer: user id in database.
839 * @param $userText String: user name in database.
840 * @return string HTML fragment with user talk link
841 * @private
842 */
843 function userTalkLink( $userId, $userText ) {
844 $userTalkPage = Title::makeTitle( NS_USER_TALK, $userText );
845 $userTalkLink = $this->link( $userTalkPage, wfMsgHtml( 'talkpagelinktext' ) );
846 return $userTalkLink;
847 }
848
849 /**
850 * @param $userId Integer: userid
851 * @param $userText String: user name in database.
852 * @return string HTML fragment with block link
853 * @private
854 */
855 function blockLink( $userId, $userText ) {
856 $blockPage = SpecialPage::getTitleFor( 'Blockip', $userText );
857 $blockLink = $this->link( $blockPage, wfMsgHtml( 'blocklink' ) );
858 return $blockLink;
859 }
860
861 /**
862 * Generate a user link if the current user is allowed to view it
863 * @param $rev Revision object.
864 * @param $isPublic, bool, show only if all users can see it
865 * @return string HTML
866 */
867 function revUserLink( $rev, $isPublic = false ) {
868 if( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
869 $link = wfMsgHtml( 'rev-deleted-user' );
870 } else if( $rev->userCan( Revision::DELETED_USER ) ) {
871 $link = $this->userLink( $rev->getUser( Revision::FOR_THIS_USER ),
872 $rev->getUserText( Revision::FOR_THIS_USER ) );
873 } else {
874 $link = wfMsgHtml( 'rev-deleted-user' );
875 }
876 if( $rev->isDeleted( Revision::DELETED_USER ) ) {
877 return '<span class="history-deleted">' . $link . '</span>';
878 }
879 return $link;
880 }
881
882 /**
883 * Generate a user tool link cluster if the current user is allowed to view it
884 * @param $rev Revision object.
885 * @param $isPublic, bool, show only if all users can see it
886 * @return string HTML
887 */
888 function revUserTools( $rev, $isPublic = false ) {
889 if( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
890 $link = wfMsgHtml( 'rev-deleted-user' );
891 } else if( $rev->userCan( Revision::DELETED_USER ) ) {
892 $userId = $rev->getUser( Revision::FOR_THIS_USER );
893 $userText = $rev->getUserText( Revision::FOR_THIS_USER );
894 $link = $this->userLink( $userId, $userText ) .
895 ' ' . $this->userToolLinks( $userId, $userText );
896 } else {
897 $link = wfMsgHtml( 'rev-deleted-user' );
898 }
899 if( $rev->isDeleted( Revision::DELETED_USER ) ) {
900 return ' <span class="history-deleted">' . $link . '</span>';
901 }
902 return $link;
903 }
904
905 /**
906 * This function is called by all recent changes variants, by the page history,
907 * and by the user contributions list. It is responsible for formatting edit
908 * comments. It escapes any HTML in the comment, but adds some CSS to format
909 * auto-generated comments (from section editing) and formats [[wikilinks]].
910 *
911 * @author Erik Moeller <moeller@scireview.de>
912 *
913 * Note: there's not always a title to pass to this function.
914 * Since you can't set a default parameter for a reference, I've turned it
915 * temporarily to a value pass. Should be adjusted further. --brion
916 *
917 * @param string $comment
918 * @param mixed $title Title object (to generate link to the section in autocomment) or null
919 * @param bool $local Whether section links should refer to local page
920 */
921 function formatComment($comment, $title = NULL, $local = false) {
922 wfProfileIn( __METHOD__ );
923
924 # Sanitize text a bit:
925 $comment = str_replace( "\n", " ", $comment );
926 # Allow HTML entities (for bug 13815)
927 $comment = Sanitizer::escapeHtmlAllowEntities( $comment );
928
929 # Render autocomments and make links:
930 $comment = $this->formatAutoComments( $comment, $title, $local );
931 $comment = $this->formatLinksInComment( $comment );
932
933 wfProfileOut( __METHOD__ );
934 return $comment;
935 }
936
937 /**
938 * The pattern for autogen comments is / * foo * /, which makes for
939 * some nasty regex.
940 * We look for all comments, match any text before and after the comment,
941 * add a separator where needed and format the comment itself with CSS
942 * Called by Linker::formatComment.
943 *
944 * @param string $comment Comment text
945 * @param object $title An optional title object used to links to sections
946 * @return string $comment formatted comment
947 *
948 * @todo Document the $local parameter.
949 */
950 private function formatAutocomments( $comment, $title = null, $local = false ) {
951 // Bah!
952 $this->autocommentTitle = $title;
953 $this->autocommentLocal = $local;
954 $comment = preg_replace_callback(
955 '!(.*)/\*\s*(.*?)\s*\*/(.*)!',
956 array( $this, 'formatAutocommentsCallback' ),
957 $comment );
958 unset( $this->autocommentTitle );
959 unset( $this->autocommentLocal );
960 return $comment;
961 }
962
963 private function formatAutocommentsCallback( $match ) {
964 $title = $this->autocommentTitle;
965 $local = $this->autocommentLocal;
966
967 $pre=$match[1];
968 $auto=$match[2];
969 $post=$match[3];
970 $link='';
971 if( $title ) {
972 $section = $auto;
973
974 # Generate a valid anchor name from the section title.
975 # Hackish, but should generally work - we strip wiki
976 # syntax, including the magic [[: that is used to
977 # "link rather than show" in case of images and
978 # interlanguage links.
979 $section = str_replace( '[[:', '', $section );
980 $section = str_replace( '[[', '', $section );
981 $section = str_replace( ']]', '', $section );
982 if ( $local ) {
983 $sectionTitle = Title::newFromText( '#' . $section );
984 } else {
985 $sectionTitle = Title::makeTitleSafe( $title->getNamespace(),
986 $title->getDBkey(), $section );
987 }
988 if ( $sectionTitle ) {
989 $link = $this->link( $sectionTitle,
990 htmlspecialchars( wfMsgForContent( 'sectionlink' ) ), array(), array(),
991 'noclasses' );
992 } else {
993 $link = '';
994 }
995 }
996 $auto = "$link$auto";
997 if( $pre ) {
998 # written summary $presep autocomment (summary /* section */)
999 $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
1000 }
1001 if( $post ) {
1002 # autocomment $postsep written summary (/* section */ summary)
1003 $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
1004 }
1005 $auto = '<span class="autocomment">' . $auto . '</span>';
1006 $comment = $pre . $auto . $post;
1007 return $comment;
1008 }
1009
1010 /**
1011 * Formats wiki links and media links in text; all other wiki formatting
1012 * is ignored
1013 *
1014 * @fixme doesn't handle sub-links as in image thumb texts like the main parser
1015 * @param string $comment Text to format links in
1016 * @return string
1017 */
1018 public function formatLinksInComment( $comment ) {
1019 return preg_replace_callback(
1020 '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
1021 array( $this, 'formatLinksInCommentCallback' ),
1022 $comment );
1023 }
1024
1025 protected function formatLinksInCommentCallback( $match ) {
1026 global $wgContLang;
1027
1028 $medians = '(?:' . preg_quote( MWNamespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
1029 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA ), '/' ) . '):';
1030
1031 $comment = $match[0];
1032
1033 # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
1034 if( strpos( $match[1], '%' ) !== false ) {
1035 $match[1] = str_replace( array('<', '>'), array('&lt;', '&gt;'), urldecode($match[1]) );
1036 }
1037
1038 # Handle link renaming [[foo|text]] will show link as "text"
1039 if( "" != $match[3] ) {
1040 $text = $match[3];
1041 } else {
1042 $text = $match[1];
1043 }
1044 $submatch = array();
1045 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1046 # Media link; trail not supported.
1047 $linkRegexp = '/\[\[(.*?)\]\]/';
1048 $title = Title::makeTitleSafe( NS_FILE, $submatch[1] );
1049 $thelink = $this->makeMediaLinkObj( $title, $text );
1050 } else {
1051 # Other kind of link
1052 if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
1053 $trail = $submatch[1];
1054 } else {
1055 $trail = "";
1056 }
1057 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1058 if (isset($match[1][0]) && $match[1][0] == ':')
1059 $match[1] = substr($match[1], 1);
1060 list( $inside, $trail ) = Linker::splitTrail( $trail );
1061 $thelink = $this->link(
1062 Title::newFromText( $match[1] ),
1063 $text . $inside
1064 ) . $trail;
1065 }
1066 $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 );
1067
1068 return $comment;
1069 }
1070
1071 /**
1072 * Wrap a comment in standard punctuation and formatting if
1073 * it's non-empty, otherwise return empty string.
1074 *
1075 * @param string $comment
1076 * @param mixed $title Title object (to generate link to section in autocomment) or null
1077 * @param bool $local Whether section links should refer to local page
1078 *
1079 * @return string
1080 */
1081 function commentBlock( $comment, $title = NULL, $local = false ) {
1082 // '*' used to be the comment inserted by the software way back
1083 // in antiquity in case none was provided, here for backwards
1084 // compatability, acc. to brion -ævar
1085 if( $comment == '' || $comment == '*' ) {
1086 return '';
1087 } else {
1088 $formatted = $this->formatComment( $comment, $title, $local );
1089 return " <span class=\"comment\">($formatted)</span>";
1090 }
1091 }
1092
1093 /**
1094 * Wrap and format the given revision's comment block, if the current
1095 * user is allowed to view it.
1096 *
1097 * @param Revision $rev
1098 * @param bool $local Whether section links should refer to local page
1099 * @param $isPublic, show only if all users can see it
1100 * @return string HTML
1101 */
1102 function revComment( Revision $rev, $local = false, $isPublic = false ) {
1103 if( $rev->getRawComment() == "" ) return "";
1104 if( $rev->isDeleted( Revision::DELETED_COMMENT ) && $isPublic ) {
1105 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1106 } else if( $rev->userCan( Revision::DELETED_COMMENT ) ) {
1107 $block = $this->commentBlock( $rev->getComment( Revision::FOR_THIS_USER ),
1108 $rev->getTitle(), $local );
1109 } else {
1110 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1111 }
1112 if( $rev->isDeleted( Revision::DELETED_COMMENT ) ) {
1113 return " <span class=\"history-deleted\">$block</span>";
1114 }
1115 return $block;
1116 }
1117
1118 public function formatRevisionSize( $size ) {
1119 if ( $size == 0 ) {
1120 $stxt = wfMsgExt( 'historyempty', 'parsemag' );
1121 } else {
1122 global $wgLang;
1123 $stxt = wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $size ) );
1124 $stxt = "($stxt)";
1125 }
1126 $stxt = htmlspecialchars( $stxt );
1127 return "<span class=\"history-size\">$stxt</span>";
1128 }
1129
1130 /** @todo document */
1131 function tocIndent() {
1132 return "\n<ul>";
1133 }
1134
1135 /** @todo document */
1136 function tocUnindent($level) {
1137 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ? $level : 0 );
1138 }
1139
1140 /**
1141 * parameter level defines if we are on an indentation level
1142 */
1143 function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
1144 $classes = "toclevel-$level";
1145 if ( $sectionIndex !== false )
1146 $classes .= " tocsection-$sectionIndex";
1147 return "\n<li class=\"$classes\"><a href=\"#" .
1148 $anchor . '"><span class="tocnumber">' .
1149 $tocnumber . '</span> <span class="toctext">' .
1150 $tocline . '</span></a>';
1151 }
1152
1153 /** @todo document */
1154 function tocLineEnd() {
1155 return "</li>\n";
1156 }
1157
1158 /** @todo document */
1159 function tocList($toc) {
1160 global $wgJsMimeType;
1161 $title = wfMsgHtml('toc') ;
1162 return
1163 '<table id="toc" class="toc" summary="' . $title .'"><tr><td>'
1164 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
1165 . $toc
1166 # no trailing newline, script should not be wrapped in a
1167 # paragraph
1168 . "</ul>\n</td></tr></table>"
1169 . '<script type="' . $wgJsMimeType . '">'
1170 . ' if (window.showTocToggle) {'
1171 . ' var tocShowText = "' . Xml::escapeJsString( wfMsg('showtoc') ) . '";'
1172 . ' var tocHideText = "' . Xml::escapeJsString( wfMsg('hidetoc') ) . '";'
1173 . ' showTocToggle();'
1174 . ' } '
1175 . "</script>\n";
1176 }
1177
1178 /**
1179 * Generate a table of contents from a section tree
1180 * @param $tree Return value of ParserOutput::getSections()
1181 * @return string HTML
1182 */
1183 public function generateTOC( $tree ) {
1184 $toc = '';
1185 $lastLevel = 0;
1186 foreach ( $tree as $section ) {
1187 if ( $section['toclevel'] > $lastLevel )
1188 $toc .= $this->tocIndent();
1189 else if ( $secton['toclevel'] < $lastLevel )
1190 $toc .= $this->tocUnindent(
1191 $lastLevel - $section['toclevel'] );
1192 else
1193 $toc .= $this->tocLineEnd();
1194
1195 $toc .= $this->tocLine( $section['anchor'],
1196 $section['line'], $section['number'],
1197 $section['toclevel'], $section['index'] );
1198 $lastLevel = $section['toclevel'];
1199 }
1200 $toc .= $this->tocLineEnd();
1201 return $this->tocList( $toc );
1202 }
1203
1204 /**
1205 * Create a section edit link. This supersedes editSectionLink() and
1206 * editSectionLinkForOther().
1207 *
1208 * @param $nt Title The title being linked to (may not be the same as
1209 * $wgTitle, if the section is included from a template)
1210 * @param $section string The designation of the section being pointed to,
1211 * to be included in the link, like "&section=$section"
1212 * @param $tooltip string The tooltip to use for the link: will be escaped
1213 * and wrapped in the 'editsectionhint' message
1214 * @return string HTML to use for edit link
1215 */
1216 public function doEditSectionLink( Title $nt, $section, $tooltip = null ) {
1217 $attribs = array();
1218 if( !is_null( $tooltip ) ) {
1219 $attribs['title'] = wfMsg( 'editsectionhint', $tooltip );
1220 }
1221 $link = $this->link( $nt, wfMsg('editsection'),
1222 $attribs,
1223 array( 'action' => 'edit', 'section' => $section ),
1224 array( 'noclasses', 'known' )
1225 );
1226
1227 # Run the old hook. This takes up half of the function . . . hopefully
1228 # we can rid of it someday.
1229 $attribs = '';
1230 if( $tooltip ) {
1231 $attribs = wfMsgHtml( 'editsectionhint', htmlspecialchars( $tooltip ) );
1232 $attribs = " title=\"$attribs\"";
1233 }
1234 $result = null;
1235 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result ) );
1236 if( !is_null( $result ) ) {
1237 # For reverse compatibility, add the brackets *after* the hook is
1238 # run, and even add them to hook-provided text. (This is the main
1239 # reason that the EditSectionLink hook is deprecated in favor of
1240 # DoEditSectionLink: it can't change the brackets or the span.)
1241 $result = wfMsgHtml( 'editsection-brackets', $result );
1242 return "<span class=\"editsection\">$result</span>";
1243 }
1244
1245 # Add the brackets and the span, and *then* run the nice new hook, with
1246 # clean and non-redundant arguments.
1247 $result = wfMsgHtml( 'editsection-brackets', $link );
1248 $result = "<span class=\"editsection\">$result</span>";
1249
1250 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result ) );
1251 return $result;
1252 }
1253
1254 /**
1255 * Create a headline for content
1256 *
1257 * @param int $level The level of the headline (1-6)
1258 * @param string $attribs Any attributes for the headline, starting with a space and ending with '>'
1259 * This *must* be at least '>' for no attribs
1260 * @param string $anchor The anchor to give the headline (the bit after the #)
1261 * @param string $text The text of the header
1262 * @param string $link HTML to add for the section edit link
1263 * @param mixed $legacyAnchor A second, optional anchor to give for
1264 * backward compatibility (false to omit)
1265 *
1266 * @return string HTML headline
1267 */
1268 public function makeHeadline( $level, $attribs, $anchor, $text, $link, $legacyAnchor = false ) {
1269 $ret = "<a name=\"$anchor\" id=\"$anchor\"></a>"
1270 . "<h$level$attribs"
1271 . $link
1272 . " <span class=\"mw-headline\">$text</span>"
1273 . "</h$level>";
1274 if ( $legacyAnchor !== false ) {
1275 $ret = "<a name=\"$legacyAnchor\" id=\"$legacyAnchor\"></a>$ret";
1276 }
1277 return $ret;
1278 }
1279
1280 /**
1281 * Split a link trail, return the "inside" portion and the remainder of the trail
1282 * as a two-element array
1283 *
1284 * @static
1285 */
1286 static function splitTrail( $trail ) {
1287 static $regex = false;
1288 if ( $regex === false ) {
1289 global $wgContLang;
1290 $regex = $wgContLang->linkTrail();
1291 }
1292 $inside = '';
1293 if ( '' != $trail ) {
1294 $m = array();
1295 if ( preg_match( $regex, $trail, $m ) ) {
1296 $inside = $m[1];
1297 $trail = $m[2];
1298 }
1299 }
1300 return array( $inside, $trail );
1301 }
1302
1303 /**
1304 * Generate a rollback link for a given revision. Currently it's the
1305 * caller's responsibility to ensure that the revision is the top one. If
1306 * it's not, of course, the user will get an error message.
1307 *
1308 * If the calling page is called with the parameter &bot=1, all rollback
1309 * links also get that parameter. It causes the edit itself and the rollback
1310 * to be marked as "bot" edits. Bot edits are hidden by default from recent
1311 * changes, so this allows sysops to combat a busy vandal without bothering
1312 * other users.
1313 *
1314 * @param Revision $rev
1315 */
1316 function generateRollback( $rev ) {
1317 return '<span class="mw-rollback-link">['
1318 . $this->buildRollbackLink( $rev )
1319 . ']</span>';
1320 }
1321
1322 /**
1323 * Build a raw rollback link, useful for collections of "tool" links
1324 *
1325 * @param Revision $rev
1326 * @return string
1327 */
1328 public function buildRollbackLink( $rev ) {
1329 global $wgRequest, $wgUser;
1330 $title = $rev->getTitle();
1331 $query = array(
1332 'action' => 'rollback',
1333 'from' => $rev->getUserText()
1334 );
1335 if( $wgRequest->getBool( 'bot' ) ) {
1336 $query['bot'] = '1';
1337 $query['hidediff'] = '1'; // bug 15999
1338 }
1339 $query['token'] = $wgUser->editToken( array( $title->getPrefixedText(),
1340 $rev->getUserText() ) );
1341 return $this->link( $title, wfMsgHtml( 'rollbacklink' ),
1342 array( 'title' => wfMsg( 'tooltip-rollback' ) ),
1343 $query, array( 'known', 'noclasses' ) );
1344 }
1345
1346 /**
1347 * Returns HTML for the "templates used on this page" list.
1348 *
1349 * @param array $templates Array of templates from Article::getUsedTemplate
1350 * or similar
1351 * @param bool $preview Whether this is for a preview
1352 * @param bool $section Whether this is for a section edit
1353 * @return string HTML output
1354 */
1355 public function formatTemplates( $templates, $preview = false, $section = false ) {
1356 wfProfileIn( __METHOD__ );
1357
1358 $outText = '';
1359 if ( count( $templates ) > 0 ) {
1360 # Do a batch existence check
1361 $batch = new LinkBatch;
1362 foreach( $templates as $title ) {
1363 $batch->addObj( $title );
1364 }
1365 $batch->execute();
1366
1367 # Construct the HTML
1368 $outText = '<div class="mw-templatesUsedExplanation">';
1369 if ( $preview ) {
1370 $outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ) );
1371 } elseif ( $section ) {
1372 $outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ) );
1373 } else {
1374 $outText .= wfMsgExt( 'templatesused', array( 'parse' ) );
1375 }
1376 $outText .= "</div><ul>\n";
1377
1378 usort( $templates, array( 'Title', 'compare' ) );
1379 foreach ( $templates as $titleObj ) {
1380 $r = $titleObj->getRestrictions( 'edit' );
1381 if ( in_array( 'sysop', $r ) ) {
1382 $protected = wfMsgExt( 'template-protected', array( 'parseinline' ) );
1383 } elseif ( in_array( 'autoconfirmed', $r ) ) {
1384 $protected = wfMsgExt( 'template-semiprotected', array( 'parseinline' ) );
1385 } else {
1386 $protected = '';
1387 }
1388 if( $titleObj->quickUserCan( 'edit' ) ) {
1389 $editLink = $this->link(
1390 $titleObj,
1391 wfMsg( 'editlink' ),
1392 array(),
1393 array( 'action' => 'edit' )
1394 );
1395 } else {
1396 $editLink = $this->link(
1397 $titleObj,
1398 wfMsg( 'viewsourcelink' ),
1399 array(),
1400 array( 'action' => 'edit' )
1401 );
1402 }
1403 $outText .= '<li>' . $this->link( $titleObj ) . ' (' . $editLink . ') ' . $protected . '</li>';
1404 }
1405 $outText .= '</ul>';
1406 }
1407 wfProfileOut( __METHOD__ );
1408 return $outText;
1409 }
1410
1411 /**
1412 * Returns HTML for the "hidden categories on this page" list.
1413 *
1414 * @param array $hiddencats Array of hidden categories from Article::getHiddenCategories
1415 * or similar
1416 * @return string HTML output
1417 */
1418 public function formatHiddenCategories( $hiddencats ) {
1419 global $wgLang;
1420 wfProfileIn( __METHOD__ );
1421
1422 $outText = '';
1423 if ( count( $hiddencats ) > 0 ) {
1424 # Construct the HTML
1425 $outText = '<div class="mw-hiddenCategoriesExplanation">';
1426 $outText .= wfMsgExt( 'hiddencategories', array( 'parse' ), $wgLang->formatnum( count( $hiddencats ) ) );
1427 $outText .= "</div><ul>\n";
1428
1429 foreach ( $hiddencats as $titleObj ) {
1430 $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
1431 }
1432 $outText .= '</ul>';
1433 }
1434 wfProfileOut( __METHOD__ );
1435 return $outText;
1436 }
1437
1438 /**
1439 * Format a size in bytes for output, using an appropriate
1440 * unit (B, KB, MB or GB) according to the magnitude in question
1441 *
1442 * @param $size Size to format
1443 * @return string
1444 */
1445 public function formatSize( $size ) {
1446 global $wgLang;
1447 return htmlspecialchars( $wgLang->formatSize( $size ) );
1448 }
1449
1450 /**
1451 * Given the id of an interface element, constructs the appropriate title
1452 * attribute from the system messages. (Note, this is usually the id but
1453 * isn't always, because sometimes the accesskey needs to go on a different
1454 * element than the id, for reverse-compatibility, etc.)
1455 *
1456 * @param string $name Id of the element, minus prefixes.
1457 * @param mixed $options null or the string 'withaccess' to add an access-
1458 * key hint
1459 * @return string Contents of the title attribute (which you must HTML-
1460 * escape), or false for no title attribute
1461 */
1462 public function titleAttrib( $name, $options = null ) {
1463 wfProfileIn( __METHOD__ );
1464
1465 $tooltip = wfMsg( "tooltip-$name" );
1466 # Compatibility: formerly some tooltips had [alt-.] hardcoded
1467 $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
1468
1469 # Message equal to '-' means suppress it.
1470 if ( wfEmptyMsg( "tooltip-$name", $tooltip ) || $tooltip == '-' ) {
1471 $tooltip = false;
1472 }
1473
1474 if ( $options == 'withaccess' ) {
1475 $accesskey = $this->accesskey( $name );
1476 if( $accesskey !== false ) {
1477 if ( $tooltip === false || $tooltip === '' ) {
1478 $tooltip = "[$accesskey]";
1479 } else {
1480 $tooltip .= " [$accesskey]";
1481 }
1482 }
1483 }
1484
1485 wfProfileOut( __METHOD__ );
1486 return $tooltip;
1487 }
1488
1489 /**
1490 * Given the id of an interface element, constructs the appropriate
1491 * accesskey attribute from the system messages. (Note, this is usually
1492 * the id but isn't always, because sometimes the accesskey needs to go on
1493 * a different element than the id, for reverse-compatibility, etc.)
1494 *
1495 * @param string $name Id of the element, minus prefixes.
1496 * @return string Contents of the accesskey attribute (which you must HTML-
1497 * escape), or false for no accesskey attribute
1498 */
1499 public function accesskey( $name ) {
1500 wfProfileIn( __METHOD__ );
1501
1502 $accesskey = wfMsg( "accesskey-$name" );
1503
1504 # FIXME: Per standard MW behavior, a value of '-' means to suppress the
1505 # attribute, but this is broken for accesskey: that might be a useful
1506 # value.
1507 if( $accesskey != '' && $accesskey != '-' && !wfEmptyMsg( "accesskey-$name", $accesskey ) ) {
1508 wfProfileOut( __METHOD__ );
1509 return $accesskey;
1510 }
1511
1512 wfProfileOut( __METHOD__ );
1513 return false;
1514 }
1515
1516 /**
1517 * Creates a (show/hide) link for deleting revisions/log entries
1518 *
1519 * @param array $query Query parameters to be passed to link()
1520 * @param bool $restricted Set to true to use a <strong> instead of a <span>
1521 *
1522 * @return string HTML <a> link to Special:Revisiondelete, wrapped in a
1523 * span to allow for customization of appearance with CSS
1524 */
1525 public function revDeleteLink( $query = array(), $restricted = false ) {
1526 $sp = SpecialPage::getTitleFor( 'Revisiondelete' );
1527 $text = wfMsgHtml( 'rev-delundel' );
1528 $tag = $restricted ? 'strong' : 'span';
1529 $link = $this->link( $sp, $text, array(), $query, array( 'known', 'noclasses' ) );
1530 return Xml::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), "($link)" );
1531 }
1532
1533 /* Deprecated methods */
1534
1535 /**
1536 * @deprecated
1537 */
1538 function postParseLinkColour( $s = null ) {
1539 wfDeprecated( __METHOD__ );
1540 return null;
1541 }
1542
1543
1544 /**
1545 * @deprecated Use link()
1546 *
1547 * This function is a shortcut to makeLinkObj(Title::newFromText($title),...). Do not call
1548 * it if you already have a title object handy. See makeLinkObj for further documentation.
1549 *
1550 * @param $title String: the text of the title
1551 * @param $text String: link text
1552 * @param $query String: optional query part
1553 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1554 * be included in the link text. Other characters will be appended after
1555 * the end of the link.
1556 */
1557 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
1558 wfProfileIn( __METHOD__ );
1559 $nt = Title::newFromText( $title );
1560 if ( $nt instanceof Title ) {
1561 $result = $this->makeLinkObj( $nt, $text, $query, $trail );
1562 } else {
1563 wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" );
1564 $result = $text == "" ? $title : $text;
1565 }
1566
1567 wfProfileOut( __METHOD__ );
1568 return $result;
1569 }
1570
1571 /**
1572 * @deprecated Use link()
1573 *
1574 * This function is a shortcut to makeKnownLinkObj(Title::newFromText($title),...). Do not call
1575 * it if you already have a title object handy. See makeKnownLinkObj for further documentation.
1576 *
1577 * @param $title String: the text of the title
1578 * @param $text String: link text
1579 * @param $query String: optional query part
1580 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1581 * be included in the link text. Other characters will be appended after
1582 * the end of the link.
1583 */
1584 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
1585 $nt = Title::newFromText( $title );
1586 if ( $nt instanceof Title ) {
1587 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix , $aprops );
1588 } else {
1589 wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" );
1590 return $text == '' ? $title : $text;
1591 }
1592 }
1593
1594 /**
1595 * @deprecated Use link()
1596 *
1597 * This function is a shortcut to makeBrokenLinkObj(Title::newFromText($title),...). Do not call
1598 * it if you already have a title object handy. See makeBrokenLinkObj for further documentation.
1599 *
1600 * @param string $title The text of the title
1601 * @param string $text Link text
1602 * @param string $query Optional query part
1603 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
1604 * be included in the link text. Other characters will be appended after
1605 * the end of the link.
1606 */
1607 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
1608 $nt = Title::newFromText( $title );
1609 if ( $nt instanceof Title ) {
1610 return $this->makeBrokenLinkObj( $nt, $text, $query, $trail );
1611 } else {
1612 wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" );
1613 return $text == '' ? $title : $text;
1614 }
1615 }
1616
1617 /**
1618 * @deprecated Use link()
1619 *
1620 * This function is a shortcut to makeStubLinkObj(Title::newFromText($title),...). Do not call
1621 * it if you already have a title object handy. See makeStubLinkObj for further documentation.
1622 *
1623 * @param $title String: the text of the title
1624 * @param $text String: link text
1625 * @param $query String: optional query part
1626 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1627 * be included in the link text. Other characters will be appended after
1628 * the end of the link.
1629 */
1630 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
1631 wfDeprecated( __METHOD__ );
1632 $nt = Title::newFromText( $title );
1633 if ( $nt instanceof Title ) {
1634 return $this->makeStubLinkObj( $nt, $text, $query, $trail );
1635 } else {
1636 wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" );
1637 return $text == '' ? $title : $text;
1638 }
1639 }
1640
1641 /**
1642 * @deprecated Use link()
1643 *
1644 * Make a link for a title which may or may not be in the database. If you need to
1645 * call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
1646 * call to this will result in a DB query.
1647 *
1648 * @param $nt Title: the title object to make the link from, e.g. from
1649 * Title::newFromText.
1650 * @param $text String: link text
1651 * @param $query String: optional query part
1652 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1653 * be included in the link text. Other characters will be appended after
1654 * the end of the link.
1655 * @param $prefix String: optional prefix. As trail, only before instead of after.
1656 */
1657 function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
1658 wfProfileIn( __METHOD__ );
1659
1660 $query = wfCgiToArray( $query );
1661 list( $inside, $trail ) = Linker::splitTrail( $trail );
1662 if( $text === '' ) {
1663 $text = $this->linkText( $nt );
1664 }
1665
1666 $ret = $this->link( $nt, "$prefix$text$inside", array(), $query ) . $trail;
1667
1668 wfProfileOut( __METHOD__ );
1669 return $ret;
1670 }
1671
1672 /**
1673 * @deprecated Use link()
1674 *
1675 * Make a link for a title which definitely exists. This is faster than makeLinkObj because
1676 * it doesn't have to do a database query. It's also valid for interwiki titles and special
1677 * pages.
1678 *
1679 * @param $nt Title object of target page
1680 * @param $text String: text to replace the title
1681 * @param $query String: link target
1682 * @param $trail String: text after link
1683 * @param $prefix String: text before link text
1684 * @param $aprops String: extra attributes to the a-element
1685 * @param $style String: style to apply - if empty, use getInternalLinkAttributesObj instead
1686 * @return the a-element
1687 */
1688 function makeKnownLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
1689 wfProfileIn( __METHOD__ );
1690
1691 if ( $text == '' ) {
1692 $text = $this->linkText( $title );
1693 }
1694 $attribs = Sanitizer::mergeAttributes(
1695 Sanitizer::decodeTagAttributes( $aprops ),
1696 Sanitizer::decodeTagAttributes( $style )
1697 );
1698 $query = wfCgiToArray( $query );
1699 list( $inside, $trail ) = Linker::splitTrail( $trail );
1700
1701 $ret = $this->link( $title, "$prefix$text$inside", $attribs, $query,
1702 array( 'known', 'noclasses' ) ) . $trail;
1703
1704 wfProfileOut( __METHOD__ );
1705 return $ret;
1706 }
1707
1708 /**
1709 * @deprecated Use link()
1710 *
1711 * Make a red link to the edit page of a given title.
1712 *
1713 * @param $nt Title object of the target page
1714 * @param $text String: Link text
1715 * @param $query String: Optional query part
1716 * @param $trail String: Optional trail. Alphabetic characters at the start of this string will
1717 * be included in the link text. Other characters will be appended after
1718 * the end of the link.
1719 */
1720 function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
1721 wfProfileIn( __METHOD__ );
1722
1723 list( $inside, $trail ) = Linker::splitTrail( $trail );
1724 if( $text === '' ) {
1725 $text = $this->linkText( $title );
1726 }
1727 $nt = $this->normaliseSpecialPage( $title );
1728
1729 $ret = $this->link( $title, "$prefix$text$inside", array(),
1730 wfCgiToArray( $query ), 'broken' ) . $trail;
1731
1732 wfProfileOut( __METHOD__ );
1733 return $ret;
1734 }
1735
1736 /**
1737 * @deprecated Use link()
1738 *
1739 * Make a brown link to a short article.
1740 *
1741 * @param $nt Title object of the target page
1742 * @param $text String: link text
1743 * @param $query String: optional query part
1744 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1745 * be included in the link text. Other characters will be appended after
1746 * the end of the link.
1747 */
1748 function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1749 wfDeprecated( __METHOD__ );
1750 return $this->makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix );
1751 }
1752
1753 /**
1754 * @deprecated Use link()
1755 *
1756 * Make a coloured link.
1757 *
1758 * @param $nt Title object of the target page
1759 * @param $colour Integer: colour of the link
1760 * @param $text String: link text
1761 * @param $query String: optional query part
1762 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
1763 * be included in the link text. Other characters will be appended after
1764 * the end of the link.
1765 */
1766 function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
1767 if($colour != ''){
1768 $style = $this->getInternalLinkAttributesObj( $nt, $text, $colour );
1769 } else $style = '';
1770 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style );
1771 }
1772
1773 /** Obsolete alias */
1774 function makeImage( $url, $alt = '' ) {
1775 wfDeprecated( __METHOD__ );
1776 return $this->makeExternalImage( $url, $alt );
1777 }
1778
1779 /**
1780 * Creates the HTML source for images
1781 * @deprecated use makeImageLink2
1782 *
1783 * @param object $title
1784 * @param string $label label text
1785 * @param string $alt alt text
1786 * @param string $align horizontal alignment: none, left, center, right)
1787 * @param array $handlerParams Parameters to be passed to the media handler
1788 * @param boolean $framed shows image in original size in a frame
1789 * @param boolean $thumb shows image as thumbnail in a frame
1790 * @param string $manualthumb image name for the manual thumbnail
1791 * @param string $valign vertical alignment: baseline, sub, super, top, text-top, middle, bottom, text-bottom
1792 * @param string $time, timestamp of the file, set as false for current
1793 * @return string
1794 */
1795 function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(), $framed = false,
1796 $thumb = false, $manualthumb = '', $valign = '', $time = false )
1797 {
1798 $frameParams = array( 'alt' => $alt, 'caption' => $label );
1799 if ( $align ) {
1800 $frameParams['align'] = $align;
1801 }
1802 if ( $framed ) {
1803 $frameParams['framed'] = true;
1804 }
1805 if ( $thumb ) {
1806 $frameParams['thumbnail'] = true;
1807 }
1808 if ( $manualthumb ) {
1809 $frameParams['manualthumb'] = $manualthumb;
1810 }
1811 if ( $valign ) {
1812 $frameParams['valign'] = $valign;
1813 }
1814 $file = wfFindFile( $title, $time );
1815 return $this->makeImageLink2( $title, $file, $frameParams, $handlerParams, $time );
1816 }
1817
1818 /** @deprecated use Linker::makeMediaLinkObj() */
1819 function makeMediaLink( $name, $unused = '', $text = '', $time = false ) {
1820 $nt = Title::makeTitleSafe( NS_FILE, $name );
1821 return $this->makeMediaLinkObj( $nt, $text, $time );
1822 }
1823
1824 /**
1825 * Used to generate section edit links that point to "other" pages
1826 * (sections that are really part of included pages).
1827 *
1828 * @deprecated use Linker::doEditSectionLink()
1829 * @param $title Title string.
1830 * @param $section Integer: section number.
1831 */
1832 public function editSectionLinkForOther( $title, $section ) {
1833 wfDeprecated( __METHOD__ );
1834 $title = Title::newFromText( $title );
1835 return $this->doEditSectionLink( $title, $section );
1836 }
1837
1838 /**
1839 * @deprecated use Linker::doEditSectionLink()
1840 * @param $nt Title object.
1841 * @param $section Integer: section number.
1842 * @param $hint Link String: title, or default if omitted or empty
1843 */
1844 public function editSectionLink( Title $nt, $section, $hint = '' ) {
1845 wfDeprecated( __METHOD__ );
1846 if( $hint === '' ) {
1847 # No way to pass an actual empty $hint here! The new interface al-
1848 # lows this, so we have to do this for compatibility.
1849 $hint = null;
1850 }
1851 return $this->doEditSectionLink( $nt, $section, $hint );
1852 }
1853
1854 /**
1855 * @deprecated Returns raw bits of HTML, use titleAttrib() and accesskey()
1856 */
1857 public function tooltipAndAccesskey( $name ) {
1858 # FIXME: If Sanitizer::expandAttributes() treated "false" as "output
1859 # no attribute" instead of "output '' as value for attribute", this
1860 # would be three lines.
1861 $attribs = array(
1862 'title' => $this->titleAttrib( $name, 'withaccess' ),
1863 'accesskey' => $this->accesskey( $name )
1864 );
1865 if ( $attribs['title'] === false ) {
1866 unset( $attribs['title'] );
1867 }
1868 if ( $attribs['accesskey'] === false ) {
1869 unset( $attribs['accesskey'] );
1870 }
1871 return Xml::expandAttributes( $attribs );
1872 }
1873
1874 /** @deprecated Returns raw bits of HTML, use titleAttrib() */
1875 public function tooltip( $name, $options = null ) {
1876 # FIXME: If Sanitizer::expandAttributes() treated "false" as "output
1877 # no attribute" instead of "output '' as value for attribute", this
1878 # would be two lines.
1879 $tooltip = $this->titleAttrib( $name, $options );
1880 if ( $tooltip === false ) {
1881 return '';
1882 }
1883 return Xml::expandAttributes( array(
1884 'title' => $this->titleAttrib( $name, $options )
1885 ) );
1886 }
1887 }