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