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