3 * Methods to make links and related items.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Some internal bits split of from Skin.php. These functions are used
25 * for primarily page content: links, embedded images, table of contents. Links
26 * are also used in the skin.
28 * @todo turn this into a legacy interface for HtmlPageLinkRenderer and similar services.
34 * Flags for userToolLinks()
36 const TOOL_LINKS_NOBLOCK
= 1;
37 const TOOL_LINKS_EMAIL
= 2;
40 * Get the appropriate HTML attributes to add to the "a" element of an interwiki link.
42 * @param string $title The title text for the link, URL-encoded (???) but
44 * @param string $unused Unused
45 * @param string $class The contents of the class attribute; if an empty
46 * string is passed, which is the default value, defaults to 'external'.
49 static function getInterwikiLinkAttributes( $title, $unused = null, $class = 'external' ) {
52 # @todo FIXME: We have a whole bunch of handling here that doesn't happen in
53 # getExternalLinkAttributes, why?
54 $title = urldecode( $title );
55 $title = $wgContLang->checkTitleEncoding( $title );
56 $title = preg_replace( '/[\\x00-\\x1f]/', ' ', $title );
58 return self
::getLinkAttributesInternal( $title, $class );
62 * Get the appropriate HTML attributes to add to the "a" element of an internal link.
64 * @param string $title The title text for the link, URL-encoded (???) but
66 * @param string $unused Unused
67 * @param string $class The contents of the class attribute, default none
70 static function getInternalLinkAttributes( $title, $unused = null, $class = '' ) {
71 $title = urldecode( $title );
72 $title = str_replace( '_', ' ', $title );
73 return self
::getLinkAttributesInternal( $title, $class );
77 * Get the appropriate HTML attributes to add to the "a" element of an internal
78 * link, given the Title object for the page we want to link to.
81 * @param string $unused Unused
82 * @param string $class The contents of the class attribute, default none
83 * @param string|bool $title Optional (unescaped) string to use in the title
84 * attribute; if false, default to the name of the page we're linking to
87 static function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) {
88 if ( $title === false ) {
89 $title = $nt->getPrefixedText();
91 return self
::getLinkAttributesInternal( $title, $class );
95 * Common code for getLinkAttributesX functions
97 * @param string $title
98 * @param string $class
102 private static function getLinkAttributesInternal( $title, $class ) {
103 $title = htmlspecialchars( $title );
104 $class = htmlspecialchars( $class );
106 if ( $class != '' ) {
107 $r .= " class=\"$class\"";
109 if ( $title != '' ) {
110 $r .= " title=\"$title\"";
116 * Return the CSS colour of a known link
119 * @param int $threshold User defined threshold
120 * @return string CSS class
122 public static function getLinkColour( $t, $threshold ) {
124 if ( $t->isRedirect() ) {
126 $colour = 'mw-redirect';
127 } elseif ( $threshold > 0 && $t->isContentPage() &&
128 $t->exists() && $t->getLength() < $threshold
137 * This function returns an HTML link to the given target. It serves a few
139 * 1) If $target is a Title, the correct URL to link to will be figured
141 * 2) It automatically adds the usual classes for various types of link
142 * targets: "new" for red links, "stub" for short articles, etc.
143 * 3) It escapes all attribute values safely so there's no risk of XSS.
144 * 4) It provides a default tooltip if the target is a Title (the page
145 * name of the target).
146 * link() replaces the old functions in the makeLink() family.
148 * @since 1.18 Method exists since 1.16 as non-static, made static in 1.18.
150 * @param Title $target Can currently only be a Title, but this may
151 * change to support Images, literal URLs, etc.
152 * @param string $html The HTML contents of the <a> element, i.e.,
153 * the link text. This is raw HTML and will not be escaped. If null,
154 * defaults to the prefixed text of the Title; or if the Title is just a
155 * fragment, the contents of the fragment.
156 * @param array $customAttribs A key => value array of extra HTML attributes,
157 * such as title and class. (href is ignored.) Classes will be
158 * merged with the default classes, while other attributes will replace
159 * default attributes. All passed attribute values will be HTML-escaped.
160 * A false attribute value means to suppress that attribute.
161 * @param array $query The query string to append to the URL
162 * you're linking to, in key => value array form. Query keys and values
163 * will be URL-encoded.
164 * @param string|array $options String or array of strings:
165 * 'known': Page is known to exist, so don't check if it does.
166 * 'broken': Page is known not to exist, so don't check if it does.
167 * 'noclasses': Don't add any classes automatically (includes "new",
168 * "stub", "mw-redirect", "extiw"). Only use the class attribute
169 * provided, if any, so you get a simple blue link with no funny i-
171 * 'forcearticlepath': Use the article path always, even with a querystring.
172 * Has compatibility issues on some setups, so avoid wherever possible.
173 * 'http': Force a full URL with http:// as the scheme.
174 * 'https': Force a full URL with https:// as the scheme.
175 * @return string HTML <a> attribute
177 public static function link(
178 $target, $html = null, $customAttribs = array(), $query = array(), $options = array()
180 if ( !$target instanceof Title
) {
181 wfWarn( __METHOD__
. ': Requires $target to be a Title object.', 2 );
182 return "<!-- ERROR -->$html";
184 wfProfileIn( __METHOD__
);
186 if ( is_string( $query ) ) {
187 // some functions withing core using this still hand over query strings
188 wfDeprecated( __METHOD__
. ' with parameter $query as string (should be array)', '1.20' );
189 $query = wfCgiToArray( $query );
191 $options = (array)$options;
193 $dummy = new DummyLinker
; // dummy linker instance for bc on the hooks
196 if ( !wfRunHooks( 'LinkBegin', array( $dummy, $target, &$html,
197 &$customAttribs, &$query, &$options, &$ret ) ) ) {
198 wfProfileOut( __METHOD__
);
202 # Normalize the Title if it's a special page
203 $target = self
::normaliseSpecialPage( $target );
205 # If we don't know whether the page exists, let's find out.
206 wfProfileIn( __METHOD__
. '-checkPageExistence' );
207 if ( !in_array( 'known', $options ) && !in_array( 'broken', $options ) ) {
208 if ( $target->isKnown() ) {
209 $options[] = 'known';
211 $options[] = 'broken';
214 wfProfileOut( __METHOD__
. '-checkPageExistence' );
217 if ( in_array( "forcearticlepath", $options ) && $query ) {
222 # Note: we want the href attribute first, for prettiness.
223 $attribs = array( 'href' => self
::linkUrl( $target, $query, $options ) );
224 if ( in_array( 'forcearticlepath', $options ) && $oldquery ) {
225 $attribs['href'] = wfAppendQuery( $attribs['href'], $oldquery );
228 $attribs = array_merge(
230 self
::linkAttribs( $target, $customAttribs, $options )
232 if ( is_null( $html ) ) {
233 $html = self
::linkText( $target );
237 if ( wfRunHooks( 'LinkEnd', array( $dummy, $target, $options, &$html, &$attribs, &$ret ) ) ) {
238 $ret = Html
::rawElement( 'a', $attribs, $html );
241 wfProfileOut( __METHOD__
);
246 * Identical to link(), except $options defaults to 'known'.
250 public static function linkKnown(
251 $target, $html = null, $customAttribs = array(),
252 $query = array(), $options = array( 'known', 'noclasses' )
254 return self
::link( $target, $html, $customAttribs, $query, $options );
258 * Returns the Url used to link to a Title
260 * @param Title $target
261 * @param array $query Query parameters
262 * @param array $options
265 private static function linkUrl( $target, $query, $options ) {
266 wfProfileIn( __METHOD__
);
267 # We don't want to include fragments for broken links, because they
268 # generally make no sense.
269 if ( in_array( 'broken', $options ) && $target->hasFragment() ) {
270 $target = clone $target;
271 $target->setFragment( '' );
274 # If it's a broken link, add the appropriate query pieces, unless
275 # there's already an action specified, or unless 'edit' makes no sense
276 # (i.e., for a nonexistent special page).
277 if ( in_array( 'broken', $options ) && empty( $query['action'] )
278 && !$target->isSpecialPage() ) {
279 $query['action'] = 'edit';
280 $query['redlink'] = '1';
283 if ( in_array( 'http', $options ) ) {
285 } elseif ( in_array( 'https', $options ) ) {
286 $proto = PROTO_HTTPS
;
288 $proto = PROTO_RELATIVE
;
291 $ret = $target->getLinkURL( $query, false, $proto );
292 wfProfileOut( __METHOD__
);
297 * Returns the array of attributes used when linking to the Title $target
299 * @param Title $target
300 * @param array $attribs
301 * @param array $options
305 private static function linkAttribs( $target, $attribs, $options ) {
306 wfProfileIn( __METHOD__
);
310 if ( !in_array( 'noclasses', $options ) ) {
311 wfProfileIn( __METHOD__
. '-getClasses' );
312 # Now build the classes.
315 if ( in_array( 'broken', $options ) ) {
319 if ( $target->isExternal() ) {
320 $classes[] = 'extiw';
323 if ( !in_array( 'broken', $options ) ) { # Avoid useless calls to LinkCache (see r50387)
324 $colour = self
::getLinkColour( $target, $wgUser->getStubThreshold() );
325 if ( $colour !== '' ) {
326 $classes[] = $colour; # mw-redirect or stub
329 if ( $classes != array() ) {
330 $defaults['class'] = implode( ' ', $classes );
332 wfProfileOut( __METHOD__
. '-getClasses' );
335 # Get a default title attribute.
336 if ( $target->getPrefixedText() == '' ) {
337 # A link like [[#Foo]]. This used to mean an empty title
338 # attribute, but that's silly. Just don't output a title.
339 } elseif ( in_array( 'known', $options ) ) {
340 $defaults['title'] = $target->getPrefixedText();
342 $defaults['title'] = wfMessage( 'red-link-title', $target->getPrefixedText() )->text();
345 # Finally, merge the custom attribs with the default ones, and iterate
346 # over that, deleting all "false" attributes.
348 $merged = Sanitizer
::mergeAttributes( $defaults, $attribs );
349 foreach ( $merged as $key => $val ) {
350 # A false value suppresses the attribute, and we don't want the
351 # href attribute to be overridden.
352 if ( $key != 'href' && $val !== false ) {
356 wfProfileOut( __METHOD__
);
361 * Default text of the links to the Title $target
363 * @param Title $target
367 private static function linkText( $target ) {
368 if ( !$target instanceof Title
) {
369 wfWarn( __METHOD__
. ': Requires $target to be a Title object.' );
372 // If the target is just a fragment, with no title, we return the fragment
373 // text. Otherwise, we return the title text itself.
374 if ( $target->getPrefixedText() === '' && $target->hasFragment() ) {
375 return htmlspecialchars( $target->getFragment() );
378 return htmlspecialchars( $target->getPrefixedText() );
382 * Make appropriate markup for a link to the current article. This is
383 * currently rendered as the bold link text. The calling sequence is the
384 * same as the other make*LinkObj static functions, despite $query not
388 * @param string $html [optional]
389 * @param string $query [optional]
390 * @param string $trail [optional]
391 * @param string $prefix [optional]
395 public static function makeSelfLinkObj( $nt, $html = '', $query = '', $trail = '', $prefix = '' ) {
396 $ret = "<strong class=\"selflink\">{$prefix}{$html}</strong>{$trail}";
397 if ( !wfRunHooks( 'SelfLinkBegin', array( $nt, &$html, &$trail, &$prefix, &$ret ) ) ) {
402 $html = htmlspecialchars( $nt->getPrefixedText() );
404 list( $inside, $trail ) = self
::splitTrail( $trail );
405 return "<strong class=\"selflink\">{$prefix}{$html}{$inside}</strong>{$trail}";
409 * Get a message saying that an invalid title was encountered.
410 * This should be called after a method like Title::makeTitleSafe() returned
411 * a value indicating that the title object is invalid.
413 * @param IContextSource $context Context to use to get the messages
414 * @param int $namespace Namespace number
415 * @param string $title Text of the title, without the namespace part
418 public static function getInvalidTitleDescription( IContextSource
$context, $namespace, $title ) {
421 // First we check whether the namespace exists or not.
422 if ( MWNamespace
::exists( $namespace ) ) {
423 if ( $namespace == NS_MAIN
) {
424 $name = $context->msg( 'blanknamespace' )->text();
426 $name = $wgContLang->getFormattedNsText( $namespace );
428 return $context->msg( 'invalidtitle-knownnamespace', $namespace, $name, $title )->text();
430 return $context->msg( 'invalidtitle-unknownnamespace', $namespace, $title )->text();
435 * @param Title $title
438 static function normaliseSpecialPage( Title
$title ) {
439 if ( $title->isSpecialPage() ) {
440 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
444 $ret = SpecialPage
::getTitleFor( $name, $subpage, $title->getFragment() );
452 * Returns the filename part of an url.
453 * Used as alternative text for external images.
459 private static function fnamePart( $url ) {
460 $basename = strrchr( $url, '/' );
461 if ( false === $basename ) {
464 $basename = substr( $basename, 1 );
470 * Return the code for images which were added via external links,
471 * via Parser::maybeMakeExternalImage().
478 public static function makeExternalImage( $url, $alt = '' ) {
480 $alt = self
::fnamePart( $url );
483 $success = wfRunHooks( 'LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
485 wfDebug( "Hook LinkerMakeExternalImage changed the output of external image "
486 . "with url {$url} and alt text {$alt} to {$img}\n", true );
489 return Html
::element( 'img',
496 * Given parameters derived from [[Image:Foo|options...]], generate the
497 * HTML that that syntax inserts in the page.
499 * @param Parser $parser
500 * @param Title $title Title object of the file (not the currently viewed page)
501 * @param File $file File object, or false if it doesn't exist
502 * @param array $frameParams Associative array of parameters external to the media handler.
503 * Boolean parameters are indicated by presence or absence, the value is arbitrary and
504 * will often be false.
505 * thumbnail If present, downscale and frame
506 * manualthumb Image name to use as a thumbnail, instead of automatic scaling
507 * framed Shows image in original size in a frame
508 * frameless Downscale but don't frame
509 * upright If present, tweak default sizes for portrait orientation
510 * upright_factor Fudge factor for "upright" tweak (default 0.75)
511 * border If present, show a border around the image
512 * align Horizontal alignment (left, right, center, none)
513 * valign Vertical alignment (baseline, sub, super, top, text-top, middle,
514 * bottom, text-bottom)
515 * alt Alternate text for image (i.e. alt attribute). Plain text.
516 * class HTML for image classes. Plain text.
517 * caption HTML for image caption.
518 * link-url URL to link to
519 * link-title Title object to link to
520 * link-target Value for the target attribute, only with link-url
521 * no-link Boolean, suppress description link
523 * @param array $handlerParams Associative array of media handler parameters, to be passed
524 * to transform(). Typical keys are "width" and "page".
525 * @param string|bool $time Timestamp of the file, set as false for current
526 * @param string $query Query params for desc url
527 * @param int|null $widthOption Used by the parser to remember the user preference thumbnailsize
529 * @return string HTML for an image, with links, wrappers, etc.
531 public static function makeImageLink( Parser
$parser, Title
$title,
532 $file, $frameParams = array(), $handlerParams = array(), $time = false,
533 $query = "", $widthOption = null
536 $dummy = new DummyLinker
;
537 if ( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$dummy, &$title,
538 &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
542 if ( $file && !$file->allowInlineDisplay() ) {
543 wfDebug( __METHOD__
. ': ' . $title->getPrefixedDBkey() . " does not allow inline display\n" );
544 return self
::link( $title );
549 $hp =& $handlerParams;
551 // Clean up parameters
552 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
553 if ( !isset( $fp['align'] ) ) {
556 if ( !isset( $fp['alt'] ) ) {
559 if ( !isset( $fp['title'] ) ) {
562 if ( !isset( $fp['class'] ) ) {
566 $prefix = $postfix = '';
568 if ( 'center' == $fp['align'] ) {
569 $prefix = '<div class="center">';
571 $fp['align'] = 'none';
573 if ( $file && !isset( $hp['width'] ) ) {
574 if ( isset( $hp['height'] ) && $file->isVectorized() ) {
575 // If its a vector image, and user only specifies height
576 // we don't want it to be limited by its "normal" width.
577 global $wgSVGMaxSize;
578 $hp['width'] = $wgSVGMaxSize;
580 $hp['width'] = $file->getWidth( $page );
583 if ( isset( $fp['thumbnail'] )
584 ||
isset( $fp['manualthumb'] )
585 ||
isset( $fp['framed'] )
586 ||
isset( $fp['frameless'] )
589 global $wgThumbLimits, $wgThumbUpright;
591 if ( $widthOption === null ||
!isset( $wgThumbLimits[$widthOption] ) ) {
592 $widthOption = User
::getDefaultOption( 'thumbsize' );
595 // Reduce width for upright images when parameter 'upright' is used
596 if ( isset( $fp['upright'] ) && $fp['upright'] == 0 ) {
597 $fp['upright'] = $wgThumbUpright;
600 // For caching health: If width scaled down due to upright
601 // parameter, round to full __0 pixel to avoid the creation of a
602 // lot of odd thumbs.
603 $prefWidth = isset( $fp['upright'] ) ?
604 round( $wgThumbLimits[$widthOption] * $fp['upright'], -1 ) :
605 $wgThumbLimits[$widthOption];
607 // Use width which is smaller: real image width or user preference width
608 // Unless image is scalable vector.
609 if ( !isset( $hp['height'] ) && ( $hp['width'] <= 0 ||
610 $prefWidth < $hp['width'] ||
$file->isVectorized() ) ) {
611 $hp['width'] = $prefWidth;
616 if ( isset( $fp['thumbnail'] ) ||
isset( $fp['manualthumb'] ) ||
isset( $fp['framed'] ) ) {
617 # Create a thumbnail. Alignment depends on the writing direction of
618 # the page content language (right-aligned for LTR languages,
619 # left-aligned for RTL languages)
621 # If a thumbnail width has not been provided, it is set
622 # to the default user option as specified in Language*.php
623 if ( $fp['align'] == '' ) {
624 $fp['align'] = $parser->getTargetLanguage()->alignEnd();
626 return $prefix . self
::makeThumbLink2( $title, $file, $fp, $hp, $time, $query ) . $postfix;
629 if ( $file && isset( $fp['frameless'] ) ) {
630 $srcWidth = $file->getWidth( $page );
631 # For "frameless" option: do not present an image bigger than the
632 # source (for bitmap-style images). This is the same behavior as the
633 # "thumb" option does it already.
634 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
635 $hp['width'] = $srcWidth;
639 if ( $file && isset( $hp['width'] ) ) {
640 # Create a resized image, without the additional thumbnail features
641 $thumb = $file->transform( $hp );
647 $s = self
::makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time == true );
649 self
::processResponsiveImages( $file, $thumb, $hp );
652 'title' => $fp['title'],
653 'valign' => isset( $fp['valign'] ) ?
$fp['valign'] : false,
654 'img-class' => $fp['class'] );
655 if ( isset( $fp['border'] ) ) {
656 $params['img-class'] .= ( $params['img-class'] !== '' ?
' ' : '' ) . 'thumbborder';
658 $params = self
::getImageLinkMTOParams( $fp, $query, $parser ) +
$params;
660 $s = $thumb->toHtml( $params );
662 if ( $fp['align'] != '' ) {
663 $s = "<div class=\"float{$fp['align']}\">{$s}</div>";
665 return str_replace( "\n", ' ', $prefix . $s . $postfix );
669 * See makeImageLink()
670 * When this function is removed, remove if( $parser instanceof Parser ) check there too
671 * @deprecated since 1.20
673 public static function makeImageLink2( Title
$title, $file, $frameParams = array(),
674 $handlerParams = array(), $time = false, $query = "", $widthOption = null ) {
675 return self
::makeImageLink( null, $title, $file, $frameParams,
676 $handlerParams, $time, $query, $widthOption );
680 * Get the link parameters for MediaTransformOutput::toHtml() from given
681 * frame parameters supplied by the Parser.
682 * @param array $frameParams The frame parameters
683 * @param string $query An optional query string to add to description page links
684 * @param Parser|null $parser
687 private static function getImageLinkMTOParams( $frameParams, $query = '', $parser = null ) {
688 $mtoParams = array();
689 if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) {
690 $mtoParams['custom-url-link'] = $frameParams['link-url'];
691 if ( isset( $frameParams['link-target'] ) ) {
692 $mtoParams['custom-target-link'] = $frameParams['link-target'];
695 $extLinkAttrs = $parser->getExternalLinkAttribs( $frameParams['link-url'] );
696 foreach ( $extLinkAttrs as $name => $val ) {
697 // Currently could include 'rel' and 'target'
698 $mtoParams['parser-extlink-' . $name] = $val;
701 } elseif ( isset( $frameParams['link-title'] ) && $frameParams['link-title'] !== '' ) {
702 $mtoParams['custom-title-link'] = self
::normaliseSpecialPage( $frameParams['link-title'] );
703 } elseif ( !empty( $frameParams['no-link'] ) ) {
706 $mtoParams['desc-link'] = true;
707 $mtoParams['desc-query'] = $query;
713 * Make HTML for a thumbnail including image, border and caption
714 * @param Title $title
715 * @param File|bool $file File object or false if it doesn't exist
716 * @param string $label
718 * @param string $align
719 * @param array $params
720 * @param bool $framed
721 * @param string $manualthumb
724 public static function makeThumbLinkObj( Title
$title, $file, $label = '', $alt,
725 $align = 'right', $params = array(), $framed = false, $manualthumb = ""
727 $frameParams = array(
733 $frameParams['framed'] = true;
735 if ( $manualthumb ) {
736 $frameParams['manualthumb'] = $manualthumb;
738 return self
::makeThumbLink2( $title, $file, $frameParams, $params );
742 * @param Title $title
744 * @param array $frameParams
745 * @param array $handlerParams
747 * @param string $query
750 public static function makeThumbLink2( Title
$title, $file, $frameParams = array(),
751 $handlerParams = array(), $time = false, $query = ""
753 $exists = $file && $file->exists();
757 $hp =& $handlerParams;
759 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
760 if ( !isset( $fp['align'] ) ) {
761 $fp['align'] = 'right';
763 if ( !isset( $fp['alt'] ) ) {
766 if ( !isset( $fp['title'] ) ) {
769 if ( !isset( $fp['caption'] ) ) {
773 if ( empty( $hp['width'] ) ) {
774 // Reduce width for upright images when parameter 'upright' is used
775 $hp['width'] = isset( $fp['upright'] ) ?
130 : 180;
779 $manualthumb = false;
782 $outerWidth = $hp['width'] +
2;
784 if ( isset( $fp['manualthumb'] ) ) {
785 # Use manually specified thumbnail
786 $manual_title = Title
::makeTitleSafe( NS_FILE
, $fp['manualthumb'] );
787 if ( $manual_title ) {
788 $manual_img = wfFindFile( $manual_title );
790 $thumb = $manual_img->getUnscaledThumb( $hp );
796 } elseif ( isset( $fp['framed'] ) ) {
797 // Use image dimensions, don't scale
798 $thumb = $file->getUnscaledThumb( $hp );
801 # Do not present an image bigger than the source, for bitmap-style images
802 # This is a hack to maintain compatibility with arbitrary pre-1.10 behavior
803 $srcWidth = $file->getWidth( $page );
804 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
805 $hp['width'] = $srcWidth;
807 $thumb = $file->transform( $hp );
811 $outerWidth = $thumb->getWidth() +
2;
813 $outerWidth = $hp['width'] +
2;
817 # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
818 # So we don't need to pass it here in $query. However, the URL for the
819 # zoom icon still needs it, so we make a unique query for it. See bug 14771
820 $url = $title->getLocalURL( $query );
822 $url = wfAppendQuery( $url, array( 'page' => $page ) );
825 && !isset( $fp['link-title'] )
826 && !isset( $fp['link-url'] )
827 && !isset( $fp['no-link'] ) ) {
828 $fp['link-url'] = $url;
831 $s = "<div class=\"thumb t{$fp['align']}\">"
832 . "<div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
835 $s .= self
::makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time == true );
837 } elseif ( !$thumb ) {
838 $s .= wfMessage( 'thumbnail_error', '' )->escaped();
841 if ( !$noscale && !$manualthumb ) {
842 self
::processResponsiveImages( $file, $thumb, $hp );
846 'title' => $fp['title'],
847 'img-class' => ( isset( $fp['class'] ) && $fp['class'] !== ''
849 : '' ) . 'thumbimage'
851 $params = self
::getImageLinkMTOParams( $fp, $query ) +
$params;
852 $s .= $thumb->toHtml( $params );
853 if ( isset( $fp['framed'] ) ) {
856 $zoomIcon = Html
::rawElement( 'div', array( 'class' => 'magnify' ),
857 Html
::rawElement( 'a', array(
859 'class' => 'internal',
860 'title' => wfMessage( 'thumbnail-more' )->text() ),
864 $s .= ' <div class="thumbcaption">' . $zoomIcon . $fp['caption'] . "</div></div></div>";
865 return str_replace( "\n", ' ', $s );
869 * Process responsive images: add 1.5x and 2x subimages to the thumbnail, where
873 * @param MediaTransformOutput $thumb
874 * @param array $hp Image parameters
876 public static function processResponsiveImages( $file, $thumb, $hp ) {
877 global $wgResponsiveImages;
878 if ( $wgResponsiveImages && $thumb && !$thumb->isError() ) {
880 $hp15['width'] = round( $hp['width'] * 1.5 );
882 $hp20['width'] = $hp['width'] * 2;
883 if ( isset( $hp['height'] ) ) {
884 $hp15['height'] = round( $hp['height'] * 1.5 );
885 $hp20['height'] = $hp['height'] * 2;
888 $thumb15 = $file->transform( $hp15 );
889 $thumb20 = $file->transform( $hp20 );
890 if ( $thumb15 && !$thumb15->isError() && $thumb15->getUrl() !== $thumb->getUrl() ) {
891 $thumb->responsiveUrls
['1.5'] = $thumb15->getUrl();
893 if ( $thumb20 && !$thumb20->isError() && $thumb20->getUrl() !== $thumb->getUrl() ) {
894 $thumb->responsiveUrls
['2'] = $thumb20->getUrl();
900 * Make a "broken" link to an image
902 * @param Title $title
903 * @param string $label Link label (plain text)
904 * @param string $query Query string
905 * @param string $unused1 Unused parameter kept for b/c
906 * @param string $unused2 Unused parameter kept for b/c
907 * @param bool $time A file of a certain timestamp was requested
910 public static function makeBrokenImageLinkObj( $title, $label = '',
911 $query = '', $unused1 = '', $unused2 = '', $time = false
913 if ( !$title instanceof Title
) {
914 wfWarn( __METHOD__
. ': Requires $title to be a Title object.' );
915 return "<!-- ERROR -->" . htmlspecialchars( $label );
918 global $wgEnableUploads, $wgUploadMissingFileUrl, $wgUploadNavigationUrl;
919 wfProfileIn( __METHOD__
);
920 if ( $label == '' ) {
921 $label = $title->getPrefixedText();
923 $encLabel = htmlspecialchars( $label );
924 $currentExists = $time ?
( wfFindFile( $title ) != false ) : false;
926 if ( ( $wgUploadMissingFileUrl ||
$wgUploadNavigationUrl ||
$wgEnableUploads )
929 $redir = RepoGroup
::singleton()->getLocalRepo()->checkRedirect( $title );
932 wfProfileOut( __METHOD__
);
933 return self
::linkKnown( $title, $encLabel, array(), wfCgiToArray( $query ) );
936 $href = self
::getUploadUrl( $title, $query );
938 wfProfileOut( __METHOD__
);
939 return '<a href="' . htmlspecialchars( $href ) . '" class="new" title="' .
940 htmlspecialchars( $title->getPrefixedText(), ENT_QUOTES
) . '">' .
944 wfProfileOut( __METHOD__
);
945 return self
::linkKnown( $title, $encLabel, array(), wfCgiToArray( $query ) );
949 * Get the URL to upload a certain file
951 * @param Title $destFile Title object of the file to upload
952 * @param string $query Urlencoded query string to prepend
953 * @return string Urlencoded URL
955 protected static function getUploadUrl( $destFile, $query = '' ) {
956 global $wgUploadMissingFileUrl, $wgUploadNavigationUrl;
957 $q = 'wpDestFile=' . $destFile->getPartialURL();
958 if ( $query != '' ) {
962 if ( $wgUploadMissingFileUrl ) {
963 return wfAppendQuery( $wgUploadMissingFileUrl, $q );
964 } elseif ( $wgUploadNavigationUrl ) {
965 return wfAppendQuery( $wgUploadNavigationUrl, $q );
967 $upload = SpecialPage
::getTitleFor( 'Upload' );
968 return $upload->getLocalURL( $q );
973 * Create a direct link to a given uploaded file.
975 * @param Title $title
976 * @param string $html Pre-sanitized HTML
977 * @param string $time MW timestamp of file creation time
978 * @return string HTML
980 public static function makeMediaLinkObj( $title, $html = '', $time = false ) {
981 $img = wfFindFile( $title, array( 'time' => $time ) );
982 return self
::makeMediaLinkFile( $title, $img, $html );
986 * Create a direct link to a given uploaded file.
987 * This will make a broken link if $file is false.
989 * @param Title $title
990 * @param File|bool $file File object or false
991 * @param string $html Pre-sanitized HTML
992 * @return string HTML
994 * @todo Handle invalid or missing images better.
996 public static function makeMediaLinkFile( Title
$title, $file, $html = '' ) {
997 if ( $file && $file->exists() ) {
998 $url = $file->getURL();
1001 $url = self
::getUploadUrl( $title );
1005 $alt = $title->getText();
1006 if ( $html == '' ) {
1017 if ( !wfRunHooks( 'LinkerMakeMediaLinkFile',
1018 array( $title, $file, &$html, &$attribs, &$ret ) ) ) {
1019 wfDebug( "Hook LinkerMakeMediaLinkFile changed the output of link "
1020 . "with url {$url} and text {$html} to {$ret}\n", true );
1024 return Html
::rawElement( 'a', $attribs, $html );
1028 * Make a link to a special page given its name and, optionally,
1029 * a message key from the link text.
1030 * Usage example: Linker::specialLink( 'Recentchanges' )
1032 * @param string $name
1033 * @param string $key
1036 public static function specialLink( $name, $key = '' ) {
1038 $key = strtolower( $name );
1041 return self
::linkKnown( SpecialPage
::getTitleFor( $name ), wfMessage( $key )->text() );
1045 * Make an external link
1046 * @param string $url URL to link to
1047 * @param string $text Text of link
1048 * @param bool $escape Do we escape the link text?
1049 * @param string $linktype Type of external link. Gets added to the classes
1050 * @param array $attribs Array of extra attributes to <a>
1051 * @param Title|null $title Title object used for title specific link attributes
1054 public static function makeExternalLink( $url, $text, $escape = true,
1055 $linktype = '', $attribs = array(), $title = null
1058 $class = "external";
1060 $class .= " $linktype";
1062 if ( isset( $attribs['class'] ) && $attribs['class'] ) {
1063 $class .= " {$attribs['class']}";
1065 $attribs['class'] = $class;
1068 $text = htmlspecialchars( $text );
1074 $attribs['rel'] = Parser
::getExternalLinkRel( $url, $title );
1076 $success = wfRunHooks( 'LinkerMakeExternalLink',
1077 array( &$url, &$text, &$link, &$attribs, $linktype ) );
1079 wfDebug( "Hook LinkerMakeExternalLink changed the output of link "
1080 . "with url {$url} and text {$text} to {$link}\n", true );
1083 $attribs['href'] = $url;
1084 return Html
::rawElement( 'a', $attribs, $text );
1088 * Make user link (or user contributions for unregistered users)
1089 * @param int $userId User id in database.
1090 * @param string $userName User name in database.
1091 * @param string $altUserName Text to display instead of the user name (optional)
1092 * @return string HTML fragment
1093 * @since 1.19 Method exists for a long time. $altUserName was added in 1.19.
1095 public static function userLink( $userId, $userName, $altUserName = false ) {
1096 $classes = 'mw-userlink';
1097 if ( $userId == 0 ) {
1098 $page = SpecialPage
::getTitleFor( 'Contributions', $userName );
1099 if ( $altUserName === false ) {
1100 $altUserName = IP
::prettifyIP( $userName );
1102 $classes .= ' mw-anonuserlink'; // Separate link class for anons (bug 43179)
1104 $page = Title
::makeTitle( NS_USER
, $userName );
1109 htmlspecialchars( $altUserName !== false ?
$altUserName : $userName ),
1110 array( 'class' => $classes )
1115 * Generate standard user tool links (talk, contributions, block link, etc.)
1117 * @param int $userId User identifier
1118 * @param string $userText User name or IP address
1119 * @param bool $redContribsWhenNoEdits Should the contributions link be
1120 * red if the user has no edits?
1121 * @param int $flags Customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK
1122 * and Linker::TOOL_LINKS_EMAIL).
1123 * @param int $edits User edit count (optional, for performance)
1124 * @return string HTML fragment
1126 public static function userToolLinks(
1127 $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits = null
1129 global $wgUser, $wgDisableAnonTalk, $wgLang;
1130 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
1131 $blockable = !( $flags & self
::TOOL_LINKS_NOBLOCK
);
1132 $addEmailLink = $flags & self
::TOOL_LINKS_EMAIL
&& $userId;
1136 $items[] = self
::userTalkLink( $userId, $userText );
1139 // check if the user has an edit
1141 if ( $redContribsWhenNoEdits ) {
1142 if ( intval( $edits ) === 0 && $edits !== 0 ) {
1143 $user = User
::newFromId( $userId );
1144 $edits = $user->getEditCount();
1146 if ( $edits === 0 ) {
1147 $attribs['class'] = 'new';
1150 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $userText );
1152 $items[] = self
::link( $contribsPage, wfMessage( 'contribslink' )->escaped(), $attribs );
1154 if ( $blockable && $wgUser->isAllowed( 'block' ) ) {
1155 $items[] = self
::blockLink( $userId, $userText );
1158 if ( $addEmailLink && $wgUser->canSendEmail() ) {
1159 $items[] = self
::emailLink( $userId, $userText );
1162 wfRunHooks( 'UserToolLinksEdit', array( $userId, $userText, &$items ) );
1165 return wfMessage( 'word-separator' )->plain()
1166 . '<span class="mw-usertoollinks">'
1167 . wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped()
1175 * Alias for userToolLinks( $userId, $userText, true );
1176 * @param int $userId User identifier
1177 * @param string $userText User name or IP address
1178 * @param int $edits User edit count (optional, for performance)
1181 public static function userToolLinksRedContribs( $userId, $userText, $edits = null ) {
1182 return self
::userToolLinks( $userId, $userText, true, 0, $edits );
1186 * @param int $userId User id in database.
1187 * @param string $userText User name in database.
1188 * @return string HTML fragment with user talk link
1190 public static function userTalkLink( $userId, $userText ) {
1191 $userTalkPage = Title
::makeTitle( NS_USER_TALK
, $userText );
1192 $userTalkLink = self
::link( $userTalkPage, wfMessage( 'talkpagelinktext' )->escaped() );
1193 return $userTalkLink;
1197 * @param int $userId Userid
1198 * @param string $userText User name in database.
1199 * @return string HTML fragment with block link
1201 public static function blockLink( $userId, $userText ) {
1202 $blockPage = SpecialPage
::getTitleFor( 'Block', $userText );
1203 $blockLink = self
::link( $blockPage, wfMessage( 'blocklink' )->escaped() );
1208 * @param int $userId Userid
1209 * @param string $userText User name in database.
1210 * @return string HTML fragment with e-mail user link
1212 public static function emailLink( $userId, $userText ) {
1213 $emailPage = SpecialPage
::getTitleFor( 'Emailuser', $userText );
1214 $emailLink = self
::link( $emailPage, wfMessage( 'emaillink' )->escaped() );
1219 * Generate a user link if the current user is allowed to view it
1220 * @param Revision $rev
1221 * @param bool $isPublic Show only if all users can see it
1222 * @return string HTML fragment
1224 public static function revUserLink( $rev, $isPublic = false ) {
1225 if ( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1226 $link = wfMessage( 'rev-deleted-user' )->escaped();
1227 } elseif ( $rev->userCan( Revision
::DELETED_USER
) ) {
1228 $link = self
::userLink( $rev->getUser( Revision
::FOR_THIS_USER
),
1229 $rev->getUserText( Revision
::FOR_THIS_USER
) );
1231 $link = wfMessage( 'rev-deleted-user' )->escaped();
1233 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1234 return '<span class="history-deleted">' . $link . '</span>';
1240 * Generate a user tool link cluster if the current user is allowed to view it
1241 * @param Revision $rev
1242 * @param bool $isPublic Show only if all users can see it
1243 * @return string HTML
1245 public static function revUserTools( $rev, $isPublic = false ) {
1246 if ( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1247 $link = wfMessage( 'rev-deleted-user' )->escaped();
1248 } elseif ( $rev->userCan( Revision
::DELETED_USER
) ) {
1249 $userId = $rev->getUser( Revision
::FOR_THIS_USER
);
1250 $userText = $rev->getUserText( Revision
::FOR_THIS_USER
);
1251 $link = self
::userLink( $userId, $userText )
1252 . wfMessage( 'word-separator' )->plain()
1253 . self
::userToolLinks( $userId, $userText );
1255 $link = wfMessage( 'rev-deleted-user' )->escaped();
1257 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1258 return ' <span class="history-deleted">' . $link . '</span>';
1264 * This function is called by all recent changes variants, by the page history,
1265 * and by the user contributions list. It is responsible for formatting edit
1266 * summaries. It escapes any HTML in the summary, but adds some CSS to format
1267 * auto-generated comments (from section editing) and formats [[wikilinks]].
1269 * @author Erik Moeller <moeller@scireview.de>
1271 * Note: there's not always a title to pass to this function.
1272 * Since you can't set a default parameter for a reference, I've turned it
1273 * temporarily to a value pass. Should be adjusted further. --brion
1275 * @param string $comment
1276 * @param Title|null $title Title object (to generate link to the section in autocomment) or null
1277 * @param bool $local Whether section links should refer to local page
1278 * @return mixed|string
1280 public static function formatComment( $comment, $title = null, $local = false ) {
1281 wfProfileIn( __METHOD__
);
1283 # Sanitize text a bit:
1284 $comment = str_replace( "\n", " ", $comment );
1285 # Allow HTML entities (for bug 13815)
1286 $comment = Sanitizer
::escapeHtmlAllowEntities( $comment );
1288 # Render autocomments and make links:
1289 $comment = self
::formatAutocomments( $comment, $title, $local );
1290 $comment = self
::formatLinksInComment( $comment, $title, $local );
1292 wfProfileOut( __METHOD__
);
1297 * Converts autogenerated comments in edit summaries into section links.
1298 * The pattern for autogen comments is / * foo * /, which makes for
1300 * We look for all comments, match any text before and after the comment,
1301 * add a separator where needed and format the comment itself with CSS
1302 * Called by Linker::formatComment.
1304 * @param string $comment Comment text
1305 * @param Title|null $title An optional title object used to links to sections
1306 * @param bool $local Whether section links should refer to local page
1307 * @return string Formatted comment
1309 private static function formatAutocomments( $comment, $title = null, $local = false ) {
1310 return preg_replace_callback(
1311 '!(.*)/\*\s*(.*?)\s*\*/(.*)!',
1312 function ( $match ) use ( $title, $local ) {
1319 wfRunHooks( 'FormatAutocomments', array( &$comment, $pre, $auto, $post, $title, $local ) );
1320 if ( $comment === null ) {
1324 # Remove links that a user may have manually put in the autosummary
1325 # This could be improved by copying as much of Parser::stripSectionName as desired.
1326 $section = str_replace( '[[:', '', $section );
1327 $section = str_replace( '[[', '', $section );
1328 $section = str_replace( ']]', '', $section );
1330 $section = Sanitizer
::normalizeSectionNameWhitespace( $section ); # bug 22784
1332 $sectionTitle = Title
::newFromText( '#' . $section );
1334 $sectionTitle = Title
::makeTitleSafe( $title->getNamespace(),
1335 $title->getDBkey(), $section );
1337 if ( $sectionTitle ) {
1338 $link = Linker
::link( $sectionTitle,
1339 $wgLang->getArrow(), array(), array(),
1346 # written summary $presep autocomment (summary /* section */)
1347 $pre .= wfMessage( 'autocomment-prefix' )->inContentLanguage()->escaped();
1350 # autocomment $postsep written summary (/* section */ summary)
1351 $auto .= wfMessage( 'colon-separator' )->inContentLanguage()->escaped();
1353 $auto = '<span class="autocomment">' . $auto . '</span>';
1354 $comment = $pre . $link . $wgLang->getDirMark()
1355 . '<span dir="auto">' . $auto . $post . '</span>';
1364 * Formats wiki links and media links in text; all other wiki formatting
1367 * @todo FIXME: Doesn't handle sub-links as in image thumb texts like the main parser
1368 * @param string $comment Text to format links in
1369 * @param Title|null $title An optional title object used to links to sections
1370 * @param bool $local Whether section links should refer to local page
1373 public static function formatLinksInComment( $comment, $title = null, $local = false ) {
1374 return preg_replace_callback(
1377 :? # ignore optional leading colon
1378 ([^\]|]+) # 1. link target; page names cannot include ] or |
1380 # 2. a pipe-separated substring; only the last is captured
1381 # Stop matching at | and ]] without relying on backtracking.
1385 ([^[]*) # 3. link trail (the text up until the next link)
1387 function ( $match ) use ( $title, $local ) {
1390 $medians = '(?:' . preg_quote( MWNamespace
::getCanonicalName( NS_MEDIA
), '/' ) . '|';
1391 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA
), '/' ) . '):';
1393 $comment = $match[0];
1395 # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
1396 if ( strpos( $match[1], '%' ) !== false ) {
1397 $match[1] = str_replace(
1399 array( '<', '>' ),
1400 rawurldecode( $match[1] )
1404 # Handle link renaming [[foo|text]] will show link as "text"
1405 if ( $match[2] != "" ) {
1410 $submatch = array();
1412 if ( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1413 # Media link; trail not supported.
1414 $linkRegexp = '/\[\[(.*?)\]\]/';
1415 $title = Title
::makeTitleSafe( NS_FILE
, $submatch[1] );
1417 $thelink = Linker
::makeMediaLinkObj( $title, $text );
1420 # Other kind of link
1421 if ( preg_match( $wgContLang->linkTrail(), $match[3], $submatch ) ) {
1422 $trail = $submatch[1];
1426 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1427 if ( isset( $match[1][0] ) && $match[1][0] == ':' ) {
1428 $match[1] = substr( $match[1], 1 );
1430 list( $inside, $trail ) = Linker
::splitTrail( $trail );
1433 $linkTarget = Linker
::normalizeSubpageLink( $title, $match[1], $linkText );
1435 $target = Title
::newFromText( $linkTarget );
1437 if ( $target->getText() == '' && !$target->isExternal()
1438 && !$local && $title
1440 $newTarget = clone ( $title );
1441 $newTarget->setFragment( '#' . $target->getFragment() );
1442 $target = $newTarget;
1444 $thelink = Linker
::link(
1451 // If the link is still valid, go ahead and replace it in!
1452 $comment = preg_replace(
1454 StringUtils
::escapeRegexReplacement( $thelink ),
1467 * @param Title $contextTitle
1468 * @param string $target
1469 * @param string $text
1472 public static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
1475 # :Foobar -- override special treatment of prefix (images, language links)
1476 # /Foobar -- convert to CurrentPage/Foobar
1477 # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text
1478 # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1479 # ../Foobar -- convert to CurrentPage/Foobar, from CurrentPage/CurrentSubPage
1481 wfProfileIn( __METHOD__
);
1482 $ret = $target; # default return value is no change
1484 # Some namespaces don't allow subpages,
1485 # so only perform processing if subpages are allowed
1486 if ( $contextTitle && MWNamespace
::hasSubpages( $contextTitle->getNamespace() ) ) {
1487 $hash = strpos( $target, '#' );
1488 if ( $hash !== false ) {
1489 $suffix = substr( $target, $hash );
1490 $target = substr( $target, 0, $hash );
1495 $target = trim( $target );
1496 # Look at the first character
1497 if ( $target != '' && $target[0] === '/' ) {
1498 # / at end means we don't want the slash to be shown
1500 $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
1501 if ( $trailingSlashes ) {
1502 $noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
1504 $noslash = substr( $target, 1 );
1507 $ret = $contextTitle->getPrefixedText() . '/' . trim( $noslash ) . $suffix;
1508 if ( $text === '' ) {
1509 $text = $target . $suffix;
1510 } # this might be changed for ugliness reasons
1512 # check for .. subpage backlinks
1514 $nodotdot = $target;
1515 while ( strncmp( $nodotdot, "../", 3 ) == 0 ) {
1517 $nodotdot = substr( $nodotdot, 3 );
1519 if ( $dotdotcount > 0 ) {
1520 $exploded = explode( '/', $contextTitle->getPrefixedText() );
1521 if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1522 $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
1523 # / at the end means don't show full path
1524 if ( substr( $nodotdot, -1, 1 ) === '/' ) {
1525 $nodotdot = substr( $nodotdot, 0, -1 );
1526 if ( $text === '' ) {
1527 $text = $nodotdot . $suffix;
1530 $nodotdot = trim( $nodotdot );
1531 if ( $nodotdot != '' ) {
1532 $ret .= '/' . $nodotdot;
1540 wfProfileOut( __METHOD__
);
1545 * Wrap a comment in standard punctuation and formatting if
1546 * it's non-empty, otherwise return empty string.
1548 * @param string $comment
1549 * @param Title|null $title Title object (to generate link to section in autocomment) or null
1550 * @param bool $local Whether section links should refer to local page
1554 public static function commentBlock( $comment, $title = null, $local = false ) {
1555 // '*' used to be the comment inserted by the software way back
1556 // in antiquity in case none was provided, here for backwards
1557 // compatibility, acc. to brion -ævar
1558 if ( $comment == '' ||
$comment == '*' ) {
1561 $formatted = self
::formatComment( $comment, $title, $local );
1562 $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped();
1563 return " <span class=\"comment\">$formatted</span>";
1568 * Wrap and format the given revision's comment block, if the current
1569 * user is allowed to view it.
1571 * @param Revision $rev
1572 * @param bool $local Whether section links should refer to local page
1573 * @param bool $isPublic Show only if all users can see it
1574 * @return string HTML fragment
1576 public static function revComment( Revision
$rev, $local = false, $isPublic = false ) {
1577 if ( $rev->getRawComment() == "" ) {
1580 if ( $rev->isDeleted( Revision
::DELETED_COMMENT
) && $isPublic ) {
1581 $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>";
1582 } elseif ( $rev->userCan( Revision
::DELETED_COMMENT
) ) {
1583 $block = self
::commentBlock( $rev->getComment( Revision
::FOR_THIS_USER
),
1584 $rev->getTitle(), $local );
1586 $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>";
1588 if ( $rev->isDeleted( Revision
::DELETED_COMMENT
) ) {
1589 return " <span class=\"history-deleted\">$block</span>";
1598 public static function formatRevisionSize( $size ) {
1600 $stxt = wfMessage( 'historyempty' )->escaped();
1602 $stxt = wfMessage( 'nbytes' )->numParams( $size )->escaped();
1603 $stxt = wfMessage( 'parentheses' )->rawParams( $stxt )->escaped();
1605 return "<span class=\"history-size\">$stxt</span>";
1609 * Add another level to the Table of Contents
1613 public static function tocIndent() {
1618 * Finish one or more sublevels on the Table of Contents
1623 public static function tocUnindent( $level ) {
1624 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level > 0 ?
$level : 0 );
1628 * parameter level defines if we are on an indentation level
1630 * @param string $anchor
1631 * @param string $tocline
1632 * @param string $tocnumber
1633 * @param string $level
1634 * @param string|bool $sectionIndex
1637 public static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
1638 $classes = "toclevel-$level";
1639 if ( $sectionIndex !== false ) {
1640 $classes .= " tocsection-$sectionIndex";
1642 return "\n<li class=\"$classes\"><a href=\"#" .
1643 $anchor . '"><span class="tocnumber">' .
1644 $tocnumber . '</span> <span class="toctext">' .
1645 $tocline . '</span></a>';
1649 * End a Table Of Contents line.
1650 * tocUnindent() will be used instead if we're ending a line below
1654 public static function tocLineEnd() {
1659 * Wraps the TOC in a table and provides the hide/collapse javascript.
1661 * @param string $toc Html of the Table Of Contents
1662 * @param string|Language|bool $lang Language for the toc title, defaults to user language
1663 * @return string Full html of the TOC
1665 public static function tocList( $toc, $lang = false ) {
1666 $lang = wfGetLangObj( $lang );
1667 $title = wfMessage( 'toc' )->inLanguage( $lang )->escaped();
1669 return '<div id="toc" class="toc">'
1670 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
1672 . "</ul>\n</div>\n";
1676 * Generate a table of contents from a section tree
1679 * @param array $tree Return value of ParserOutput::getSections()
1680 * @return string HTML fragment
1682 public static function generateTOC( $tree ) {
1685 foreach ( $tree as $section ) {
1686 if ( $section['toclevel'] > $lastLevel ) {
1687 $toc .= self
::tocIndent();
1688 } elseif ( $section['toclevel'] < $lastLevel ) {
1689 $toc .= self
::tocUnindent(
1690 $lastLevel - $section['toclevel'] );
1692 $toc .= self
::tocLineEnd();
1695 $toc .= self
::tocLine( $section['anchor'],
1696 $section['line'], $section['number'],
1697 $section['toclevel'], $section['index'] );
1698 $lastLevel = $section['toclevel'];
1700 $toc .= self
::tocLineEnd();
1701 return self
::tocList( $toc );
1705 * Create a headline for content
1707 * @param int $level The level of the headline (1-6)
1708 * @param string $attribs Any attributes for the headline, starting with
1709 * a space and ending with '>'
1710 * This *must* be at least '>' for no attribs
1711 * @param string $anchor The anchor to give the headline (the bit after the #)
1712 * @param string $html Html for the text of the header
1713 * @param string $link HTML to add for the section edit link
1714 * @param bool|string $legacyAnchor A second, optional anchor to give for
1715 * backward compatibility (false to omit)
1717 * @return string HTML headline
1719 public static function makeHeadline( $level, $attribs, $anchor, $html,
1720 $link, $legacyAnchor = false
1722 $ret = "<h$level$attribs"
1723 . "<span class=\"mw-headline\" id=\"$anchor\">$html</span>"
1726 if ( $legacyAnchor !== false ) {
1727 $ret = "<div id=\"$legacyAnchor\"></div>$ret";
1733 * Split a link trail, return the "inside" portion and the remainder of the trail
1734 * as a two-element array
1735 * @param string $trail
1738 static function splitTrail( $trail ) {
1740 $regex = $wgContLang->linkTrail();
1742 if ( $trail !== '' ) {
1744 if ( preg_match( $regex, $trail, $m ) ) {
1749 return array( $inside, $trail );
1753 * Generate a rollback link for a given revision. Currently it's the
1754 * caller's responsibility to ensure that the revision is the top one. If
1755 * it's not, of course, the user will get an error message.
1757 * If the calling page is called with the parameter &bot=1, all rollback
1758 * links also get that parameter. It causes the edit itself and the rollback
1759 * to be marked as "bot" edits. Bot edits are hidden by default from recent
1760 * changes, so this allows sysops to combat a busy vandal without bothering
1763 * If the option verify is set this function will return the link only in case the
1764 * revision can be reverted. Please note that due to performance limitations
1765 * it might be assumed that a user isn't the only contributor of a page while
1766 * (s)he is, which will lead to useless rollback links. Furthermore this wont
1767 * work if $wgShowRollbackEditCount is disabled, so this can only function
1768 * as an additional check.
1770 * If the option noBrackets is set the rollback link wont be enclosed in []
1772 * @param Revision $rev
1773 * @param IContextSource $context Context to use or null for the main context.
1774 * @param array $options
1777 public static function generateRollback( $rev, IContextSource
$context = null,
1778 $options = array( 'verify' )
1780 if ( $context === null ) {
1781 $context = RequestContext
::getMain();
1785 if ( in_array( 'verify', $options ) ) {
1786 $editCount = self
::getRollbackEditCount( $rev, true );
1787 if ( $editCount === false ) {
1792 $inner = self
::buildRollbackLink( $rev, $context, $editCount );
1794 if ( !in_array( 'noBrackets', $options ) ) {
1795 $inner = $context->msg( 'brackets' )->rawParams( $inner )->plain();
1798 return '<span class="mw-rollback-link">' . $inner . '</span>';
1802 * This function will return the number of revisions which a rollback
1803 * would revert and, if $verify is set it will verify that a revision
1804 * can be reverted (that the user isn't the only contributor and the
1805 * revision we might rollback to isn't deleted). These checks can only
1806 * function as an additional check as this function only checks against
1807 * the last $wgShowRollbackEditCount edits.
1809 * Returns null if $wgShowRollbackEditCount is disabled or false if $verify
1810 * is set and the user is the only contributor of the page.
1812 * @param Revision $rev
1813 * @param bool $verify Try to verify that this revision can really be rolled back
1814 * @return int|bool|null
1816 public static function getRollbackEditCount( $rev, $verify ) {
1817 global $wgShowRollbackEditCount;
1818 if ( !is_int( $wgShowRollbackEditCount ) ||
!$wgShowRollbackEditCount > 0 ) {
1819 // Nothing has happened, indicate this by returning 'null'
1823 $dbr = wfGetDB( DB_SLAVE
);
1825 // Up to the value of $wgShowRollbackEditCount revisions are counted
1826 $res = $dbr->select(
1828 array( 'rev_user_text', 'rev_deleted' ),
1829 // $rev->getPage() returns null sometimes
1830 array( 'rev_page' => $rev->getTitle()->getArticleID() ),
1833 'USE INDEX' => array( 'revision' => 'page_timestamp' ),
1834 'ORDER BY' => 'rev_timestamp DESC',
1835 'LIMIT' => $wgShowRollbackEditCount +
1
1841 foreach ( $res as $row ) {
1842 if ( $rev->getRawUserText() != $row->rev_user_text
) {
1844 ( $row->rev_deleted
& Revision
::DELETED_TEXT
1845 ||
$row->rev_deleted
& Revision
::DELETED_USER
1847 // If the user or the text of the revision we might rollback
1848 // to is deleted in some way we can't rollback. Similar to
1849 // the sanity checks in WikiPage::commitRollback.
1858 if ( $verify && $editCount <= $wgShowRollbackEditCount && !$moreRevs ) {
1859 // We didn't find at least $wgShowRollbackEditCount revisions made by the current user
1860 // and there weren't any other revisions. That means that the current user is the only
1861 // editor, so we can't rollback
1868 * Build a raw rollback link, useful for collections of "tool" links
1870 * @param Revision $rev
1871 * @param IContextSource|null $context Context to use or null for the main context.
1872 * @param int $editCount Number of edits that would be reverted
1873 * @return string HTML fragment
1875 public static function buildRollbackLink( $rev, IContextSource
$context = null,
1878 global $wgShowRollbackEditCount, $wgMiserMode;
1880 // To config which pages are effected by miser mode
1881 $disableRollbackEditCountSpecialPage = array( 'Recentchanges', 'Watchlist' );
1883 if ( $context === null ) {
1884 $context = RequestContext
::getMain();
1887 $title = $rev->getTitle();
1889 'action' => 'rollback',
1890 'from' => $rev->getUserText(),
1891 'token' => $context->getUser()->getEditToken( array(
1892 $title->getPrefixedText(),
1896 if ( $context->getRequest()->getBool( 'bot' ) ) {
1897 $query['bot'] = '1';
1898 $query['hidediff'] = '1'; // bug 15999
1901 $disableRollbackEditCount = false;
1902 if ( $wgMiserMode ) {
1903 foreach ( $disableRollbackEditCountSpecialPage as $specialPage ) {
1904 if ( $context->getTitle()->isSpecial( $specialPage ) ) {
1905 $disableRollbackEditCount = true;
1911 if ( !$disableRollbackEditCount
1912 && is_int( $wgShowRollbackEditCount )
1913 && $wgShowRollbackEditCount > 0
1915 if ( !is_numeric( $editCount ) ) {
1916 $editCount = self
::getRollbackEditCount( $rev, false );
1919 if ( $editCount > $wgShowRollbackEditCount ) {
1920 $editCount_output = $context->msg( 'rollbacklinkcount-morethan' )
1921 ->numParams( $wgShowRollbackEditCount )->parse();
1923 $editCount_output = $context->msg( 'rollbacklinkcount' )->numParams( $editCount )->parse();
1929 array( 'title' => $context->msg( 'tooltip-rollback' )->text() ),
1931 array( 'known', 'noclasses' )
1936 $context->msg( 'rollbacklink' )->escaped(),
1937 array( 'title' => $context->msg( 'tooltip-rollback' )->text() ),
1939 array( 'known', 'noclasses' )
1945 * Returns HTML for the "templates used on this page" list.
1947 * Make an HTML list of templates, and then add a "More..." link at
1948 * the bottom. If $more is null, do not add a "More..." link. If $more
1949 * is a Title, make a link to that title and use it. If $more is a string,
1950 * directly paste it in as the link (escaping needs to be done manually).
1951 * Finally, if $more is a Message, call toString().
1953 * @param array $templates Array of templates from Article::getUsedTemplate or similar
1954 * @param bool $preview Whether this is for a preview
1955 * @param bool $section Whether this is for a section edit
1956 * @param Title|Message|string|null $more An escaped link for "More..." of the templates
1957 * @return string HTML output
1959 public static function formatTemplates( $templates, $preview = false,
1960 $section = false, $more = null
1963 wfProfileIn( __METHOD__
);
1966 if ( count( $templates ) > 0 ) {
1967 # Do a batch existence check
1968 $batch = new LinkBatch
;
1969 foreach ( $templates as $title ) {
1970 $batch->addObj( $title );
1974 # Construct the HTML
1975 $outText = '<div class="mw-templatesUsedExplanation">';
1977 $outText .= wfMessage( 'templatesusedpreview' )->numParams( count( $templates ) )
1979 } elseif ( $section ) {
1980 $outText .= wfMessage( 'templatesusedsection' )->numParams( count( $templates ) )
1983 $outText .= wfMessage( 'templatesused' )->numParams( count( $templates ) )
1986 $outText .= "</div><ul>\n";
1988 usort( $templates, 'Title::compare' );
1989 foreach ( $templates as $titleObj ) {
1991 $restrictions = $titleObj->getRestrictions( 'edit' );
1992 if ( $restrictions ) {
1993 // Check backwards-compatible messages
1995 if ( $restrictions === array( 'sysop' ) ) {
1996 $msg = wfMessage( 'template-protected' );
1997 } elseif ( $restrictions === array( 'autoconfirmed' ) ) {
1998 $msg = wfMessage( 'template-semiprotected' );
2000 if ( $msg && !$msg->isDisabled() ) {
2001 $protected = $msg->parse();
2003 // Construct the message from restriction-level-*
2004 // e.g. restriction-level-sysop, restriction-level-autoconfirmed
2006 foreach ( $restrictions as $r ) {
2007 $msgs[] = wfMessage( "restriction-level-$r" )->parse();
2009 $protected = wfMessage( 'parentheses' )
2010 ->rawParams( $wgLang->commaList( $msgs ) )->escaped();
2013 if ( $titleObj->quickUserCan( 'edit' ) ) {
2014 $editLink = self
::link(
2016 wfMessage( 'editlink' )->text(),
2018 array( 'action' => 'edit' )
2021 $editLink = self
::link(
2023 wfMessage( 'viewsourcelink' )->text(),
2025 array( 'action' => 'edit' )
2028 $outText .= '<li>' . self
::link( $titleObj )
2029 . wfMessage( 'word-separator' )->escaped()
2030 . wfMessage( 'parentheses' )->rawParams( $editLink )->escaped()
2031 . wfMessage( 'word-separator' )->escaped()
2032 . $protected . '</li>';
2035 if ( $more instanceof Title
) {
2036 $outText .= '<li>' . self
::link( $more, wfMessage( 'moredotdotdot' ) ) . '</li>';
2037 } elseif ( $more ) {
2038 $outText .= "<li>$more</li>";
2041 $outText .= '</ul>';
2043 wfProfileOut( __METHOD__
);
2048 * Returns HTML for the "hidden categories on this page" list.
2050 * @param array $hiddencats Array of hidden categories from Article::getHiddenCategories
2052 * @return string HTML output
2054 public static function formatHiddenCategories( $hiddencats ) {
2055 wfProfileIn( __METHOD__
);
2058 if ( count( $hiddencats ) > 0 ) {
2059 # Construct the HTML
2060 $outText = '<div class="mw-hiddenCategoriesExplanation">';
2061 $outText .= wfMessage( 'hiddencategories' )->numParams( count( $hiddencats ) )->parseAsBlock();
2062 $outText .= "</div><ul>\n";
2064 foreach ( $hiddencats as $titleObj ) {
2065 # If it's hidden, it must exist - no need to check with a LinkBatch
2067 . self
::link( $titleObj, null, array(), array(), 'known' )
2070 $outText .= '</ul>';
2072 wfProfileOut( __METHOD__
);
2077 * Format a size in bytes for output, using an appropriate
2078 * unit (B, KB, MB or GB) according to the magnitude in question
2080 * @param int $size Size to format
2083 public static function formatSize( $size ) {
2085 return htmlspecialchars( $wgLang->formatSize( $size ) );
2089 * Given the id of an interface element, constructs the appropriate title
2090 * attribute from the system messages. (Note, this is usually the id but
2091 * isn't always, because sometimes the accesskey needs to go on a different
2092 * element than the id, for reverse-compatibility, etc.)
2094 * @param string $name Id of the element, minus prefixes.
2095 * @param string|null $options Null or the string 'withaccess' to add an access-
2097 * @return string Contents of the title attribute (which you must HTML-
2098 * escape), or false for no title attribute
2100 public static function titleAttrib( $name, $options = null ) {
2101 wfProfileIn( __METHOD__
);
2103 $message = wfMessage( "tooltip-$name" );
2105 if ( !$message->exists() ) {
2108 $tooltip = $message->text();
2109 # Compatibility: formerly some tooltips had [alt-.] hardcoded
2110 $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
2111 # Message equal to '-' means suppress it.
2112 if ( $tooltip == '-' ) {
2117 if ( $options == 'withaccess' ) {
2118 $accesskey = self
::accesskey( $name );
2119 if ( $accesskey !== false ) {
2120 // Should be build the same as in jquery.accessKeyLabel.js
2121 if ( $tooltip === false ||
$tooltip === '' ) {
2122 $tooltip = wfMessage( 'brackets', $accesskey )->text();
2124 $tooltip .= wfMessage( 'word-separator' )->text();
2125 $tooltip .= wfMessage( 'brackets', $accesskey )->text();
2130 wfProfileOut( __METHOD__
);
2134 public static $accesskeycache;
2137 * Given the id of an interface element, constructs the appropriate
2138 * accesskey attribute from the system messages. (Note, this is usually
2139 * the id but isn't always, because sometimes the accesskey needs to go on
2140 * a different element than the id, for reverse-compatibility, etc.)
2142 * @param string $name Id of the element, minus prefixes.
2143 * @return string Contents of the accesskey attribute (which you must HTML-
2144 * escape), or false for no accesskey attribute
2146 public static function accesskey( $name ) {
2147 if ( isset( self
::$accesskeycache[$name] ) ) {
2148 return self
::$accesskeycache[$name];
2150 wfProfileIn( __METHOD__
);
2152 $message = wfMessage( "accesskey-$name" );
2154 if ( !$message->exists() ) {
2157 $accesskey = $message->plain();
2158 if ( $accesskey === '' ||
$accesskey === '-' ) {
2159 # @todo FIXME: Per standard MW behavior, a value of '-' means to suppress the
2160 # attribute, but this is broken for accesskey: that might be a useful
2166 wfProfileOut( __METHOD__
);
2167 self
::$accesskeycache[$name] = $accesskey;
2168 return self
::$accesskeycache[$name];
2172 * Get a revision-deletion link, or disabled link, or nothing, depending
2173 * on user permissions & the settings on the revision.
2175 * Will use forward-compatible revision ID in the Special:RevDelete link
2176 * if possible, otherwise the timestamp-based ID which may break after
2180 * @param Revision $rev
2181 * @param Title $title
2182 * @return string HTML fragment
2184 public static function getRevDeleteLink( User
$user, Revision
$rev, Title
$title ) {
2185 $canHide = $user->isAllowed( 'deleterevision' );
2186 if ( !$canHide && !( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) ) {
2190 if ( !$rev->userCan( Revision
::DELETED_RESTRICTED
, $user ) ) {
2191 return Linker
::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
2193 if ( $rev->getId() ) {
2194 // RevDelete links using revision ID are stable across
2195 // page deletion and undeletion; use when possible.
2197 'type' => 'revision',
2198 'target' => $title->getPrefixedDBkey(),
2199 'ids' => $rev->getId()
2202 // Older deleted entries didn't save a revision ID.
2203 // We have to refer to these by timestamp, ick!
2205 'type' => 'archive',
2206 'target' => $title->getPrefixedDBkey(),
2207 'ids' => $rev->getTimestamp()
2210 return Linker
::revDeleteLink( $query,
2211 $rev->isDeleted( Revision
::DELETED_RESTRICTED
), $canHide );
2216 * Creates a (show/hide) link for deleting revisions/log entries
2218 * @param array $query Query parameters to be passed to link()
2219 * @param bool $restricted Set to true to use a "<strong>" instead of a "<span>"
2220 * @param bool $delete Set to true to use (show/hide) rather than (show)
2222 * @return string HTML "<a>" link to Special:Revisiondelete, wrapped in a
2223 * span to allow for customization of appearance with CSS
2225 public static function revDeleteLink( $query = array(), $restricted = false, $delete = true ) {
2226 $sp = SpecialPage
::getTitleFor( 'Revisiondelete' );
2227 $msgKey = $delete ?
'rev-delundel' : 'rev-showdeleted';
2228 $html = wfMessage( $msgKey )->escaped();
2229 $tag = $restricted ?
'strong' : 'span';
2230 $link = self
::link( $sp, $html, array(), $query, array( 'known', 'noclasses' ) );
2233 array( 'class' => 'mw-revdelundel-link' ),
2234 wfMessage( 'parentheses' )->rawParams( $link )->escaped()
2239 * Creates a dead (show/hide) link for deleting revisions/log entries
2241 * @param bool $delete Set to true to use (show/hide) rather than (show)
2243 * @return string HTML text wrapped in a span to allow for customization
2244 * of appearance with CSS
2246 public static function revDeleteLinkDisabled( $delete = true ) {
2247 $msgKey = $delete ?
'rev-delundel' : 'rev-showdeleted';
2248 $html = wfMessage( $msgKey )->escaped();
2249 $htmlParentheses = wfMessage( 'parentheses' )->rawParams( $html )->escaped();
2250 return Xml
::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), $htmlParentheses );
2253 /* Deprecated methods */
2256 * @deprecated since 1.16 Use link(); warnings since 1.21
2258 * Make a link for a title which may or may not be in the database. If you need to
2259 * call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
2260 * call to this will result in a DB query.
2262 * @param Title $nt The title object to make the link from, e.g. from Title::newFromText.
2263 * @param string $text Link text
2264 * @param string $query Optional query part
2265 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
2266 * be included in the link text. Other characters will be appended after
2267 * the end of the link.
2268 * @param string $prefix Optional prefix. As trail, only before instead of after.
2271 static function makeLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
2272 wfDeprecated( __METHOD__
, '1.21' );
2274 wfProfileIn( __METHOD__
);
2275 $query = wfCgiToArray( $query );
2276 list( $inside, $trail ) = self
::splitTrail( $trail );
2277 if ( $text === '' ) {
2278 $text = self
::linkText( $nt );
2281 $ret = self
::link( $nt, "$prefix$text$inside", array(), $query ) . $trail;
2283 wfProfileOut( __METHOD__
);
2288 * @deprecated since 1.16 Use link(); warnings since 1.21
2290 * Make a link for a title which definitely exists. This is faster than makeLinkObj because
2291 * it doesn't have to do a database query. It's also valid for interwiki titles and special
2294 * @param Title $title Title object of target page
2295 * @param string $text Text to replace the title
2296 * @param string $query Link target
2297 * @param string $trail Text after link
2298 * @param string $prefix Text before link text
2299 * @param string $aprops Extra attributes to the a-element
2300 * @param string $style Style to apply - if empty, use getInternalLinkAttributesObj instead
2301 * @return string The a-element
2303 static function makeKnownLinkObj(
2304 $title, $text = '', $query = '', $trail = '', $prefix = '', $aprops = '', $style = ''
2306 wfDeprecated( __METHOD__
, '1.21' );
2308 wfProfileIn( __METHOD__
);
2310 if ( $text == '' ) {
2311 $text = self
::linkText( $title );
2313 $attribs = Sanitizer
::mergeAttributes(
2314 Sanitizer
::decodeTagAttributes( $aprops ),
2315 Sanitizer
::decodeTagAttributes( $style )
2317 $query = wfCgiToArray( $query );
2318 list( $inside, $trail ) = self
::splitTrail( $trail );
2320 $ret = self
::link( $title, "$prefix$text$inside", $attribs, $query,
2321 array( 'known', 'noclasses' ) ) . $trail;
2323 wfProfileOut( __METHOD__
);
2328 * Returns the attributes for the tooltip and access key.
2329 * @param string $name
2332 public static function tooltipAndAccesskeyAttribs( $name ) {
2333 # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
2334 # no attribute" instead of "output '' as value for attribute", this
2335 # would be three lines.
2337 'title' => self
::titleAttrib( $name, 'withaccess' ),
2338 'accesskey' => self
::accesskey( $name )
2340 if ( $attribs['title'] === false ) {
2341 unset( $attribs['title'] );
2343 if ( $attribs['accesskey'] === false ) {
2344 unset( $attribs['accesskey'] );
2350 * Returns raw bits of HTML, use titleAttrib()
2351 * @param string $name
2352 * @param array|null $options
2353 * @return null|string
2355 public static function tooltip( $name, $options = null ) {
2356 # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
2357 # no attribute" instead of "output '' as value for attribute", this
2358 # would be two lines.
2359 $tooltip = self
::titleAttrib( $name, $options );
2360 if ( $tooltip === false ) {
2363 return Xml
::expandAttributes( array(
2375 * Use PHP's magic __call handler to transform instance calls to a dummy instance
2376 * into static calls to the new Linker for backwards compatibility.
2378 * @param string $fname Name of called method
2379 * @param array $args Arguments to the method
2382 public function __call( $fname, $args ) {
2383 return call_user_func_array( array( 'Linker', $fname ), $args );