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
22 use MediaWiki\Linker\LinkTarget
;
25 * Some internal bits split of from Skin.php. These functions are used
26 * for primarily page content: links, embedded images, table of contents. Links
27 * are also used in the skin.
29 * @todo turn this into a legacy interface for HtmlPageLinkRenderer and similar services.
35 * Flags for userToolLinks()
37 const TOOL_LINKS_NOBLOCK
= 1;
38 const TOOL_LINKS_EMAIL
= 2;
41 * Get the appropriate HTML attributes to add to the "a" element of an interwiki link.
44 * @deprecated since 1.25
46 * @param string $title The title text for the link, URL-encoded (???) but
48 * @param string $unused Unused
49 * @param string $class The contents of the class attribute; if an empty
50 * string is passed, which is the default value, defaults to 'external'.
53 static function getInterwikiLinkAttributes( $title, $unused = null, $class = 'external' ) {
56 wfDeprecated( __METHOD__
, '1.25' );
58 # @todo FIXME: We have a whole bunch of handling here that doesn't happen in
59 # getExternalLinkAttributes, why?
60 $title = urldecode( $title );
61 $title = $wgContLang->checkTitleEncoding( $title );
62 $title = preg_replace( '/[\\x00-\\x1f]/', ' ', $title );
64 return self
::getLinkAttributesInternal( $title, $class );
68 * Get the appropriate HTML attributes to add to the "a" element of an internal link.
71 * @deprecated since 1.25
73 * @param string $title The title text for the link, URL-encoded (???) but
75 * @param string $unused Unused
76 * @param string $class The contents of the class attribute, default none
79 static function getInternalLinkAttributes( $title, $unused = null, $class = '' ) {
80 wfDeprecated( __METHOD__
, '1.25' );
82 $title = urldecode( $title );
83 $title = strtr( $title, '_', ' ' );
84 return self
::getLinkAttributesInternal( $title, $class );
88 * Get the appropriate HTML attributes to add to the "a" element of an internal
89 * link, given the Title object for the page we want to link to.
92 * @deprecated since 1.25
95 * @param string $unused Unused
96 * @param string $class The contents of the class attribute, default none
97 * @param string|bool $title Optional (unescaped) string to use in the title
98 * attribute; if false, default to the name of the page we're linking to
101 static function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) {
102 wfDeprecated( __METHOD__
, '1.25' );
104 if ( $title === false ) {
105 $title = $nt->getPrefixedText();
107 return self
::getLinkAttributesInternal( $title, $class );
111 * Common code for getLinkAttributesX functions
114 * @deprecated since 1.25
116 * @param string $title
117 * @param string $class
121 private static function getLinkAttributesInternal( $title, $class ) {
122 wfDeprecated( __METHOD__
, '1.25' );
124 $title = htmlspecialchars( $title );
125 $class = htmlspecialchars( $class );
127 if ( $class != '' ) {
128 $r .= " class=\"$class\"";
130 if ( $title != '' ) {
131 $r .= " title=\"$title\"";
137 * Return the CSS colour of a known link
141 * @param int $threshold User defined threshold
142 * @return string CSS class
144 public static function getLinkColour( $t, $threshold ) {
146 if ( $t->isRedirect() ) {
148 $colour = 'mw-redirect';
149 } elseif ( $threshold > 0 && $t->isContentPage() &&
150 $t->exists() && $t->getLength() < $threshold
159 * This function returns an HTML link to the given target. It serves a few
161 * 1) If $target is a Title, the correct URL to link to will be figured
163 * 2) It automatically adds the usual classes for various types of link
164 * targets: "new" for red links, "stub" for short articles, etc.
165 * 3) It escapes all attribute values safely so there's no risk of XSS.
166 * 4) It provides a default tooltip if the target is a Title (the page
167 * name of the target).
168 * link() replaces the old functions in the makeLink() family.
170 * @since 1.18 Method exists since 1.16 as non-static, made static in 1.18.
172 * @param Title $target Can currently only be a Title, but this may
173 * change to support Images, literal URLs, etc.
174 * @param string $html The HTML contents of the <a> element, i.e.,
175 * the link text. This is raw HTML and will not be escaped. If null,
176 * defaults to the prefixed text of the Title; or if the Title is just a
177 * fragment, the contents of the fragment.
178 * @param array $customAttribs A key => value array of extra HTML attributes,
179 * such as title and class. (href is ignored.) Classes will be
180 * merged with the default classes, while other attributes will replace
181 * default attributes. All passed attribute values will be HTML-escaped.
182 * A false attribute value means to suppress that attribute.
183 * @param array $query The query string to append to the URL
184 * you're linking to, in key => value array form. Query keys and values
185 * will be URL-encoded.
186 * @param string|array $options String or array of strings:
187 * 'known': Page is known to exist, so don't check if it does.
188 * 'broken': Page is known not to exist, so don't check if it does.
189 * 'noclasses': Don't add any classes automatically (includes "new",
190 * "stub", "mw-redirect", "extiw"). Only use the class attribute
191 * provided, if any, so you get a simple blue link with no funny i-
193 * 'forcearticlepath': Use the article path always, even with a querystring.
194 * Has compatibility issues on some setups, so avoid wherever possible.
195 * 'http': Force a full URL with http:// as the scheme.
196 * 'https': Force a full URL with https:// as the scheme.
197 * 'stubThreshold' => (int): Stub threshold to use when determining link classes.
198 * @return string HTML <a> attribute
200 public static function link(
201 $target, $html = null, $customAttribs = [], $query = [], $options = []
203 if ( !$target instanceof Title
) {
204 wfWarn( __METHOD__
. ': Requires $target to be a Title object.', 2 );
205 return "<!-- ERROR -->$html";
208 if ( is_string( $query ) ) {
209 // some functions withing core using this still hand over query strings
210 wfDeprecated( __METHOD__
. ' with parameter $query as string (should be array)', '1.20' );
211 $query = wfCgiToArray( $query );
213 $options = (array)$options;
215 $dummy = new DummyLinker
; // dummy linker instance for bc on the hooks
218 if ( !Hooks
::run( 'LinkBegin',
219 [ $dummy, $target, &$html, &$customAttribs, &$query, &$options, &$ret ] )
224 # Normalize the Title if it's a special page
225 $target = self
::normaliseSpecialPage( $target );
227 # If we don't know whether the page exists, let's find out.
228 if ( !in_array( 'known', $options, true ) && !in_array( 'broken', $options, true ) ) {
229 if ( $target->isKnown() ) {
230 $options[] = 'known';
232 $options[] = 'broken';
237 if ( in_array( "forcearticlepath", $options, true ) && $query ) {
242 # Note: we want the href attribute first, for prettiness.
243 $attribs = [ 'href' => self
::linkUrl( $target, $query, $options ) ];
244 if ( in_array( 'forcearticlepath', $options, true ) && $oldquery ) {
245 $attribs['href'] = wfAppendQuery( $attribs['href'], $oldquery );
248 $attribs = array_merge(
250 self
::linkAttribs( $target, $customAttribs, $options )
252 if ( is_null( $html ) ) {
253 $html = self
::linkText( $target );
257 if ( Hooks
::run( 'LinkEnd', [ $dummy, $target, $options, &$html, &$attribs, &$ret ] ) ) {
258 $ret = Html
::rawElement( 'a', $attribs, $html );
265 * Identical to link(), except $options defaults to 'known'.
270 public static function linkKnown(
271 $target, $html = null, $customAttribs = [],
272 $query = [], $options = [ 'known' ]
274 return self
::link( $target, $html, $customAttribs, $query, $options );
278 * Returns the Url used to link to a Title
280 * @param LinkTarget $target
281 * @param array $query Query parameters
282 * @param array $options
285 private static function linkUrl( LinkTarget
$target, $query, $options ) {
286 # We don't want to include fragments for broken links, because they
287 # generally make no sense.
288 if ( in_array( 'broken', $options, true ) && $target->hasFragment() ) {
289 $target = $target->createFragmentTarget( '' );
292 # If it's a broken link, add the appropriate query pieces, unless
293 # there's already an action specified, or unless 'edit' makes no sense
294 # (i.e., for a nonexistent special page).
295 if ( in_array( 'broken', $options, true ) && empty( $query['action'] )
296 && $target->getNamespace() !== NS_SPECIAL
) {
297 $query['action'] = 'edit';
298 $query['redlink'] = '1';
301 if ( in_array( 'http', $options, true ) ) {
303 } elseif ( in_array( 'https', $options, true ) ) {
304 $proto = PROTO_HTTPS
;
306 $proto = PROTO_RELATIVE
;
309 $title = Title
::newFromLinkTarget( $target );
310 $ret = $title->getLinkURL( $query, false, $proto );
315 * Returns the array of attributes used when linking to the Title $target
317 * @param Title $target
318 * @param array $attribs
319 * @param array $options
323 private static function linkAttribs( $target, $attribs, $options ) {
327 if ( !in_array( 'noclasses', $options, true ) ) {
328 # Now build the classes.
331 if ( in_array( 'broken', $options, true ) ) {
335 if ( $target->isExternal() ) {
336 $classes[] = 'extiw';
339 if ( !in_array( 'broken', $options, true ) ) { # Avoid useless calls to LinkCache (see r50387)
340 $colour = self
::getLinkColour(
342 isset( $options['stubThreshold'] ) ?
$options['stubThreshold'] : $wgUser->getStubThreshold()
344 if ( $colour !== '' ) {
345 $classes[] = $colour; # mw-redirect or stub
348 if ( $classes != [] ) {
349 $defaults['class'] = implode( ' ', $classes );
353 # Get a default title attribute.
354 if ( $target->getPrefixedText() == '' ) {
355 # A link like [[#Foo]]. This used to mean an empty title
356 # attribute, but that's silly. Just don't output a title.
357 } elseif ( in_array( 'known', $options, true ) ) {
358 $defaults['title'] = $target->getPrefixedText();
360 // This ends up in parser cache!
361 $defaults['title'] = wfMessage( 'red-link-title', $target->getPrefixedText() )
362 ->inContentLanguage()
366 # Finally, merge the custom attribs with the default ones, and iterate
367 # over that, deleting all "false" attributes.
369 $merged = Sanitizer
::mergeAttributes( $defaults, $attribs );
370 foreach ( $merged as $key => $val ) {
371 # A false value suppresses the attribute, and we don't want the
372 # href attribute to be overridden.
373 if ( $key != 'href' && $val !== false ) {
381 * Default text of the links to the Title $target
383 * @param Title $target
387 private static function linkText( $target ) {
388 if ( !$target instanceof Title
) {
389 wfWarn( __METHOD__
. ': Requires $target to be a Title object.' );
392 // If the target is just a fragment, with no title, we return the fragment
393 // text. Otherwise, we return the title text itself.
394 if ( $target->getPrefixedText() === '' && $target->hasFragment() ) {
395 return htmlspecialchars( $target->getFragment() );
398 return htmlspecialchars( $target->getPrefixedText() );
402 * Make appropriate markup for a link to the current article. This is
403 * currently rendered as the bold link text. The calling sequence is the
404 * same as the other make*LinkObj static functions, despite $query not
409 * @param string $html [optional]
410 * @param string $query [optional]
411 * @param string $trail [optional]
412 * @param string $prefix [optional]
416 public static function makeSelfLinkObj( $nt, $html = '', $query = '', $trail = '', $prefix = '' ) {
417 $ret = "<strong class=\"selflink\">{$prefix}{$html}</strong>{$trail}";
418 if ( !Hooks
::run( 'SelfLinkBegin', [ $nt, &$html, &$trail, &$prefix, &$ret ] ) ) {
423 $html = htmlspecialchars( $nt->getPrefixedText() );
425 list( $inside, $trail ) = self
::splitTrail( $trail );
426 return "<strong class=\"selflink\">{$prefix}{$html}{$inside}</strong>{$trail}";
430 * Get a message saying that an invalid title was encountered.
431 * This should be called after a method like Title::makeTitleSafe() returned
432 * a value indicating that the title object is invalid.
434 * @param IContextSource $context Context to use to get the messages
435 * @param int $namespace Namespace number
436 * @param string $title Text of the title, without the namespace part
439 public static function getInvalidTitleDescription( IContextSource
$context, $namespace, $title ) {
442 // First we check whether the namespace exists or not.
443 if ( MWNamespace
::exists( $namespace ) ) {
444 if ( $namespace == NS_MAIN
) {
445 $name = $context->msg( 'blanknamespace' )->text();
447 $name = $wgContLang->getFormattedNsText( $namespace );
449 return $context->msg( 'invalidtitle-knownnamespace', $namespace, $name, $title )->text();
451 return $context->msg( 'invalidtitle-unknownnamespace', $namespace, $title )->text();
457 * @param LinkTarget $target
458 * @return LinkTarget|Title You will get back the same type you passed in, or a Title object
460 public static function normaliseSpecialPage( LinkTarget
$target ) {
461 if ( $target->getNamespace() == NS_SPECIAL
) {
462 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $target->getDBkey() );
466 $ret = SpecialPage
::getTitleFor( $name, $subpage, $target->getFragment() );
474 * Returns the filename part of an url.
475 * Used as alternative text for external images.
481 private static function fnamePart( $url ) {
482 $basename = strrchr( $url, '/' );
483 if ( false === $basename ) {
486 $basename = substr( $basename, 1 );
492 * Return the code for images which were added via external links,
493 * via Parser::maybeMakeExternalImage().
501 public static function makeExternalImage( $url, $alt = '' ) {
503 $alt = self
::fnamePart( $url );
506 $success = Hooks
::run( 'LinkerMakeExternalImage', [ &$url, &$alt, &$img ] );
508 wfDebug( "Hook LinkerMakeExternalImage changed the output of external image "
509 . "with url {$url} and alt text {$alt} to {$img}\n", true );
512 return Html
::element( 'img',
519 * Given parameters derived from [[Image:Foo|options...]], generate the
520 * HTML that that syntax inserts in the page.
522 * @param Parser $parser
523 * @param Title $title Title object of the file (not the currently viewed page)
524 * @param File $file File object, or false if it doesn't exist
525 * @param array $frameParams Associative array of parameters external to the media handler.
526 * Boolean parameters are indicated by presence or absence, the value is arbitrary and
527 * will often be false.
528 * thumbnail If present, downscale and frame
529 * manualthumb Image name to use as a thumbnail, instead of automatic scaling
530 * framed Shows image in original size in a frame
531 * frameless Downscale but don't frame
532 * upright If present, tweak default sizes for portrait orientation
533 * upright_factor Fudge factor for "upright" tweak (default 0.75)
534 * border If present, show a border around the image
535 * align Horizontal alignment (left, right, center, none)
536 * valign Vertical alignment (baseline, sub, super, top, text-top, middle,
537 * bottom, text-bottom)
538 * alt Alternate text for image (i.e. alt attribute). Plain text.
539 * class HTML for image classes. Plain text.
540 * caption HTML for image caption.
541 * link-url URL to link to
542 * link-title Title object to link to
543 * link-target Value for the target attribute, only with link-url
544 * no-link Boolean, suppress description link
546 * @param array $handlerParams Associative array of media handler parameters, to be passed
547 * to transform(). Typical keys are "width" and "page".
548 * @param string|bool $time Timestamp of the file, set as false for current
549 * @param string $query Query params for desc url
550 * @param int|null $widthOption Used by the parser to remember the user preference thumbnailsize
552 * @return string HTML for an image, with links, wrappers, etc.
554 public static function makeImageLink( Parser
$parser, Title
$title,
555 $file, $frameParams = [], $handlerParams = [], $time = false,
556 $query = "", $widthOption = null
559 $dummy = new DummyLinker
;
560 if ( !Hooks
::run( 'ImageBeforeProduceHTML', [ &$dummy, &$title,
561 &$file, &$frameParams, &$handlerParams, &$time, &$res ] ) ) {
565 if ( $file && !$file->allowInlineDisplay() ) {
566 wfDebug( __METHOD__
. ': ' . $title->getPrefixedDBkey() . " does not allow inline display\n" );
567 return self
::link( $title );
572 $hp =& $handlerParams;
574 // Clean up parameters
575 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
576 if ( !isset( $fp['align'] ) ) {
579 if ( !isset( $fp['alt'] ) ) {
582 if ( !isset( $fp['title'] ) ) {
585 if ( !isset( $fp['class'] ) ) {
589 $prefix = $postfix = '';
591 if ( 'center' == $fp['align'] ) {
592 $prefix = '<div class="center">';
594 $fp['align'] = 'none';
596 if ( $file && !isset( $hp['width'] ) ) {
597 if ( isset( $hp['height'] ) && $file->isVectorized() ) {
598 // If its a vector image, and user only specifies height
599 // we don't want it to be limited by its "normal" width.
600 global $wgSVGMaxSize;
601 $hp['width'] = $wgSVGMaxSize;
603 $hp['width'] = $file->getWidth( $page );
606 if ( isset( $fp['thumbnail'] )
607 ||
isset( $fp['manualthumb'] )
608 ||
isset( $fp['framed'] )
609 ||
isset( $fp['frameless'] )
612 global $wgThumbLimits, $wgThumbUpright;
614 if ( $widthOption === null ||
!isset( $wgThumbLimits[$widthOption] ) ) {
615 $widthOption = User
::getDefaultOption( 'thumbsize' );
618 // Reduce width for upright images when parameter 'upright' is used
619 if ( isset( $fp['upright'] ) && $fp['upright'] == 0 ) {
620 $fp['upright'] = $wgThumbUpright;
623 // For caching health: If width scaled down due to upright
624 // parameter, round to full __0 pixel to avoid the creation of a
625 // lot of odd thumbs.
626 $prefWidth = isset( $fp['upright'] ) ?
627 round( $wgThumbLimits[$widthOption] * $fp['upright'], -1 ) :
628 $wgThumbLimits[$widthOption];
630 // Use width which is smaller: real image width or user preference width
631 // Unless image is scalable vector.
632 if ( !isset( $hp['height'] ) && ( $hp['width'] <= 0 ||
633 $prefWidth < $hp['width'] ||
$file->isVectorized() ) ) {
634 $hp['width'] = $prefWidth;
639 if ( isset( $fp['thumbnail'] ) ||
isset( $fp['manualthumb'] ) ||
isset( $fp['framed'] ) ) {
640 # Create a thumbnail. Alignment depends on the writing direction of
641 # the page content language (right-aligned for LTR languages,
642 # left-aligned for RTL languages)
643 # If a thumbnail width has not been provided, it is set
644 # to the default user option as specified in Language*.php
645 if ( $fp['align'] == '' ) {
646 $fp['align'] = $parser->getTargetLanguage()->alignEnd();
648 return $prefix . self
::makeThumbLink2( $title, $file, $fp, $hp, $time, $query ) . $postfix;
651 if ( $file && isset( $fp['frameless'] ) ) {
652 $srcWidth = $file->getWidth( $page );
653 # For "frameless" option: do not present an image bigger than the
654 # source (for bitmap-style images). This is the same behavior as the
655 # "thumb" option does it already.
656 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
657 $hp['width'] = $srcWidth;
661 if ( $file && isset( $hp['width'] ) ) {
662 # Create a resized image, without the additional thumbnail features
663 $thumb = $file->transform( $hp );
669 $s = self
::makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time == true );
671 self
::processResponsiveImages( $file, $thumb, $hp );
674 'title' => $fp['title'],
675 'valign' => isset( $fp['valign'] ) ?
$fp['valign'] : false,
676 'img-class' => $fp['class'] ];
677 if ( isset( $fp['border'] ) ) {
678 $params['img-class'] .= ( $params['img-class'] !== '' ?
' ' : '' ) . 'thumbborder';
680 $params = self
::getImageLinkMTOParams( $fp, $query, $parser ) +
$params;
682 $s = $thumb->toHtml( $params );
684 if ( $fp['align'] != '' ) {
685 $s = "<div class=\"float{$fp['align']}\">{$s}</div>";
687 return str_replace( "\n", ' ', $prefix . $s . $postfix );
691 * Get the link parameters for MediaTransformOutput::toHtml() from given
692 * frame parameters supplied by the Parser.
693 * @param array $frameParams The frame parameters
694 * @param string $query An optional query string to add to description page links
695 * @param Parser|null $parser
698 private static function getImageLinkMTOParams( $frameParams, $query = '', $parser = null ) {
700 if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) {
701 $mtoParams['custom-url-link'] = $frameParams['link-url'];
702 if ( isset( $frameParams['link-target'] ) ) {
703 $mtoParams['custom-target-link'] = $frameParams['link-target'];
706 $extLinkAttrs = $parser->getExternalLinkAttribs( $frameParams['link-url'] );
707 foreach ( $extLinkAttrs as $name => $val ) {
708 // Currently could include 'rel' and 'target'
709 $mtoParams['parser-extlink-' . $name] = $val;
712 } elseif ( isset( $frameParams['link-title'] ) && $frameParams['link-title'] !== '' ) {
713 $mtoParams['custom-title-link'] = self
::normaliseSpecialPage( $frameParams['link-title'] );
714 } elseif ( !empty( $frameParams['no-link'] ) ) {
717 $mtoParams['desc-link'] = true;
718 $mtoParams['desc-query'] = $query;
724 * Make HTML for a thumbnail including image, border and caption
725 * @param Title $title
726 * @param File|bool $file File object or false if it doesn't exist
727 * @param string $label
729 * @param string $align
730 * @param array $params
731 * @param bool $framed
732 * @param string $manualthumb
735 public static function makeThumbLinkObj( Title
$title, $file, $label = '', $alt,
736 $align = 'right', $params = [], $framed = false, $manualthumb = ""
744 $frameParams['framed'] = true;
746 if ( $manualthumb ) {
747 $frameParams['manualthumb'] = $manualthumb;
749 return self
::makeThumbLink2( $title, $file, $frameParams, $params );
753 * @param Title $title
755 * @param array $frameParams
756 * @param array $handlerParams
758 * @param string $query
761 public static function makeThumbLink2( Title
$title, $file, $frameParams = [],
762 $handlerParams = [], $time = false, $query = ""
764 $exists = $file && $file->exists();
768 $hp =& $handlerParams;
770 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
771 if ( !isset( $fp['align'] ) ) {
772 $fp['align'] = 'right';
774 if ( !isset( $fp['alt'] ) ) {
777 if ( !isset( $fp['title'] ) ) {
780 if ( !isset( $fp['caption'] ) ) {
784 if ( empty( $hp['width'] ) ) {
785 // Reduce width for upright images when parameter 'upright' is used
786 $hp['width'] = isset( $fp['upright'] ) ?
130 : 180;
790 $manualthumb = false;
793 $outerWidth = $hp['width'] +
2;
795 if ( isset( $fp['manualthumb'] ) ) {
796 # Use manually specified thumbnail
797 $manual_title = Title
::makeTitleSafe( NS_FILE
, $fp['manualthumb'] );
798 if ( $manual_title ) {
799 $manual_img = wfFindFile( $manual_title );
801 $thumb = $manual_img->getUnscaledThumb( $hp );
807 } elseif ( isset( $fp['framed'] ) ) {
808 // Use image dimensions, don't scale
809 $thumb = $file->getUnscaledThumb( $hp );
812 # Do not present an image bigger than the source, for bitmap-style images
813 # This is a hack to maintain compatibility with arbitrary pre-1.10 behavior
814 $srcWidth = $file->getWidth( $page );
815 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
816 $hp['width'] = $srcWidth;
818 $thumb = $file->transform( $hp );
822 $outerWidth = $thumb->getWidth() +
2;
824 $outerWidth = $hp['width'] +
2;
828 # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
829 # So we don't need to pass it here in $query. However, the URL for the
830 # zoom icon still needs it, so we make a unique query for it. See bug 14771
831 $url = $title->getLocalURL( $query );
833 $url = wfAppendQuery( $url, [ 'page' => $page ] );
836 && !isset( $fp['link-title'] )
837 && !isset( $fp['link-url'] )
838 && !isset( $fp['no-link'] ) ) {
839 $fp['link-url'] = $url;
842 $s = "<div class=\"thumb t{$fp['align']}\">"
843 . "<div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
846 $s .= self
::makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time == true );
848 } elseif ( !$thumb ) {
849 $s .= wfMessage( 'thumbnail_error', '' )->escaped();
852 if ( !$noscale && !$manualthumb ) {
853 self
::processResponsiveImages( $file, $thumb, $hp );
857 'title' => $fp['title'],
858 'img-class' => ( isset( $fp['class'] ) && $fp['class'] !== ''
860 : '' ) . 'thumbimage'
862 $params = self
::getImageLinkMTOParams( $fp, $query ) +
$params;
863 $s .= $thumb->toHtml( $params );
864 if ( isset( $fp['framed'] ) ) {
867 $zoomIcon = Html
::rawElement( 'div', [ 'class' => 'magnify' ],
868 Html
::rawElement( 'a', [
870 'class' => 'internal',
871 'title' => wfMessage( 'thumbnail-more' )->text() ],
875 $s .= ' <div class="thumbcaption">' . $zoomIcon . $fp['caption'] . "</div></div></div>";
876 return str_replace( "\n", ' ', $s );
880 * Process responsive images: add 1.5x and 2x subimages to the thumbnail, where
884 * @param MediaTransformOutput $thumb
885 * @param array $hp Image parameters
887 public static function processResponsiveImages( $file, $thumb, $hp ) {
888 global $wgResponsiveImages;
889 if ( $wgResponsiveImages && $thumb && !$thumb->isError() ) {
891 $hp15['width'] = round( $hp['width'] * 1.5 );
893 $hp20['width'] = $hp['width'] * 2;
894 if ( isset( $hp['height'] ) ) {
895 $hp15['height'] = round( $hp['height'] * 1.5 );
896 $hp20['height'] = $hp['height'] * 2;
899 $thumb15 = $file->transform( $hp15 );
900 $thumb20 = $file->transform( $hp20 );
901 if ( $thumb15 && !$thumb15->isError() && $thumb15->getUrl() !== $thumb->getUrl() ) {
902 $thumb->responsiveUrls
['1.5'] = $thumb15->getUrl();
904 if ( $thumb20 && !$thumb20->isError() && $thumb20->getUrl() !== $thumb->getUrl() ) {
905 $thumb->responsiveUrls
['2'] = $thumb20->getUrl();
911 * Make a "broken" link to an image
914 * @param Title $title
915 * @param string $label Link label (plain text)
916 * @param string $query Query string
917 * @param string $unused1 Unused parameter kept for b/c
918 * @param string $unused2 Unused parameter kept for b/c
919 * @param bool $time A file of a certain timestamp was requested
922 public static function makeBrokenImageLinkObj( $title, $label = '',
923 $query = '', $unused1 = '', $unused2 = '', $time = false
925 if ( !$title instanceof Title
) {
926 wfWarn( __METHOD__
. ': Requires $title to be a Title object.' );
927 return "<!-- ERROR -->" . htmlspecialchars( $label );
930 global $wgEnableUploads, $wgUploadMissingFileUrl, $wgUploadNavigationUrl;
931 if ( $label == '' ) {
932 $label = $title->getPrefixedText();
934 $encLabel = htmlspecialchars( $label );
935 $currentExists = $time ?
( wfFindFile( $title ) != false ) : false;
937 if ( ( $wgUploadMissingFileUrl ||
$wgUploadNavigationUrl ||
$wgEnableUploads )
940 $redir = RepoGroup
::singleton()->getLocalRepo()->checkRedirect( $title );
943 // We already know it's a redirect, so mark it
948 [ 'class' => 'mw-redirect' ],
949 wfCgiToArray( $query ),
950 [ 'known', 'noclasses' ]
954 $href = self
::getUploadUrl( $title, $query );
956 return '<a href="' . htmlspecialchars( $href ) . '" class="new" title="' .
957 htmlspecialchars( $title->getPrefixedText(), ENT_QUOTES
) . '">' .
961 return self
::link( $title, $encLabel, [], wfCgiToArray( $query ), [ 'known', 'noclasses' ] );
965 * Get the URL to upload a certain file
968 * @param Title $destFile Title object of the file to upload
969 * @param string $query Urlencoded query string to prepend
970 * @return string Urlencoded URL
972 protected static function getUploadUrl( $destFile, $query = '' ) {
973 global $wgUploadMissingFileUrl, $wgUploadNavigationUrl;
974 $q = 'wpDestFile=' . $destFile->getPartialURL();
975 if ( $query != '' ) {
979 if ( $wgUploadMissingFileUrl ) {
980 return wfAppendQuery( $wgUploadMissingFileUrl, $q );
981 } elseif ( $wgUploadNavigationUrl ) {
982 return wfAppendQuery( $wgUploadNavigationUrl, $q );
984 $upload = SpecialPage
::getTitleFor( 'Upload' );
985 return $upload->getLocalURL( $q );
990 * Create a direct link to a given uploaded file.
993 * @param Title $title
994 * @param string $html Pre-sanitized HTML
995 * @param string $time MW timestamp of file creation time
996 * @return string HTML
998 public static function makeMediaLinkObj( $title, $html = '', $time = false ) {
999 $img = wfFindFile( $title, [ 'time' => $time ] );
1000 return self
::makeMediaLinkFile( $title, $img, $html );
1004 * Create a direct link to a given uploaded file.
1005 * This will make a broken link if $file is false.
1008 * @param Title $title
1009 * @param File|bool $file File object or false
1010 * @param string $html Pre-sanitized HTML
1011 * @return string HTML
1013 * @todo Handle invalid or missing images better.
1015 public static function makeMediaLinkFile( Title
$title, $file, $html = '' ) {
1016 if ( $file && $file->exists() ) {
1017 $url = $file->getUrl();
1018 $class = 'internal';
1020 $url = self
::getUploadUrl( $title );
1024 $alt = $title->getText();
1025 if ( $html == '' ) {
1036 if ( !Hooks
::run( 'LinkerMakeMediaLinkFile',
1037 [ $title, $file, &$html, &$attribs, &$ret ] ) ) {
1038 wfDebug( "Hook LinkerMakeMediaLinkFile changed the output of link "
1039 . "with url {$url} and text {$html} to {$ret}\n", true );
1043 return Html
::rawElement( 'a', $attribs, $html );
1047 * Make a link to a special page given its name and, optionally,
1048 * a message key from the link text.
1049 * Usage example: Linker::specialLink( 'Recentchanges' )
1052 * @param string $name
1053 * @param string $key
1056 public static function specialLink( $name, $key = '' ) {
1058 $key = strtolower( $name );
1061 return self
::linkKnown( SpecialPage
::getTitleFor( $name ), wfMessage( $key )->text() );
1065 * Make an external link
1066 * @since 1.16.3. $title added in 1.21
1067 * @param string $url URL to link to
1068 * @param string $text Text of link
1069 * @param bool $escape Do we escape the link text?
1070 * @param string $linktype Type of external link. Gets added to the classes
1071 * @param array $attribs Array of extra attributes to <a>
1072 * @param Title|null $title Title object used for title specific link attributes
1075 public static function makeExternalLink( $url, $text, $escape = true,
1076 $linktype = '', $attribs = [], $title = null
1079 $class = "external";
1081 $class .= " $linktype";
1083 if ( isset( $attribs['class'] ) && $attribs['class'] ) {
1084 $class .= " {$attribs['class']}";
1086 $attribs['class'] = $class;
1089 $text = htmlspecialchars( $text );
1095 $newRel = Parser
::getExternalLinkRel( $url, $title );
1096 if ( !isset( $attribs['rel'] ) ||
$attribs['rel'] === '' ) {
1097 $attribs['rel'] = $newRel;
1098 } elseif ( $newRel !== '' ) {
1099 // Merge the rel attributes.
1100 $newRels = explode( ' ', $newRel );
1101 $oldRels = explode( ' ', $attribs['rel'] );
1102 $combined = array_unique( array_merge( $newRels, $oldRels ) );
1103 $attribs['rel'] = implode( ' ', $combined );
1106 $success = Hooks
::run( 'LinkerMakeExternalLink',
1107 [ &$url, &$text, &$link, &$attribs, $linktype ] );
1109 wfDebug( "Hook LinkerMakeExternalLink changed the output of link "
1110 . "with url {$url} and text {$text} to {$link}\n", true );
1113 $attribs['href'] = $url;
1114 return Html
::rawElement( 'a', $attribs, $text );
1118 * Make user link (or user contributions for unregistered users)
1119 * @param int $userId User id in database.
1120 * @param string $userName User name in database.
1121 * @param string $altUserName Text to display instead of the user name (optional)
1122 * @return string HTML fragment
1123 * @since 1.16.3. $altUserName was added in 1.19.
1125 public static function userLink( $userId, $userName, $altUserName = false ) {
1126 $classes = 'mw-userlink';
1127 if ( $userId == 0 ) {
1128 $page = SpecialPage
::getTitleFor( 'Contributions', $userName );
1129 if ( $altUserName === false ) {
1130 $altUserName = IP
::prettifyIP( $userName );
1132 $classes .= ' mw-anonuserlink'; // Separate link class for anons (bug 43179)
1134 $page = Title
::makeTitle( NS_USER
, $userName );
1139 htmlspecialchars( $altUserName !== false ?
$altUserName : $userName ),
1140 [ 'class' => $classes ]
1145 * Generate standard user tool links (talk, contributions, block link, etc.)
1148 * @param int $userId User identifier
1149 * @param string $userText User name or IP address
1150 * @param bool $redContribsWhenNoEdits Should the contributions link be
1151 * red if the user has no edits?
1152 * @param int $flags Customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK
1153 * and Linker::TOOL_LINKS_EMAIL).
1154 * @param int $edits User edit count (optional, for performance)
1155 * @return string HTML fragment
1157 public static function userToolLinks(
1158 $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits = null
1160 global $wgUser, $wgDisableAnonTalk, $wgLang;
1161 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
1162 $blockable = !( $flags & self
::TOOL_LINKS_NOBLOCK
);
1163 $addEmailLink = $flags & self
::TOOL_LINKS_EMAIL
&& $userId;
1167 $items[] = self
::userTalkLink( $userId, $userText );
1170 // check if the user has an edit
1172 if ( $redContribsWhenNoEdits ) {
1173 if ( intval( $edits ) === 0 && $edits !== 0 ) {
1174 $user = User
::newFromId( $userId );
1175 $edits = $user->getEditCount();
1177 if ( $edits === 0 ) {
1178 $attribs['class'] = 'new';
1181 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $userText );
1183 $items[] = self
::link( $contribsPage, wfMessage( 'contribslink' )->escaped(), $attribs );
1185 if ( $blockable && $wgUser->isAllowed( 'block' ) ) {
1186 $items[] = self
::blockLink( $userId, $userText );
1189 if ( $addEmailLink && $wgUser->canSendEmail() ) {
1190 $items[] = self
::emailLink( $userId, $userText );
1193 Hooks
::run( 'UserToolLinksEdit', [ $userId, $userText, &$items ] );
1196 return wfMessage( 'word-separator' )->escaped()
1197 . '<span class="mw-usertoollinks">'
1198 . wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped()
1206 * Alias for userToolLinks( $userId, $userText, true );
1208 * @param int $userId User identifier
1209 * @param string $userText User name or IP address
1210 * @param int $edits User edit count (optional, for performance)
1213 public static function userToolLinksRedContribs( $userId, $userText, $edits = null ) {
1214 return self
::userToolLinks( $userId, $userText, true, 0, $edits );
1219 * @param int $userId User id in database.
1220 * @param string $userText User name in database.
1221 * @return string HTML fragment with user talk link
1223 public static function userTalkLink( $userId, $userText ) {
1224 $userTalkPage = Title
::makeTitle( NS_USER_TALK
, $userText );
1225 $userTalkLink = self
::link( $userTalkPage, wfMessage( 'talkpagelinktext' )->escaped() );
1226 return $userTalkLink;
1231 * @param int $userId Userid
1232 * @param string $userText User name in database.
1233 * @return string HTML fragment with block link
1235 public static function blockLink( $userId, $userText ) {
1236 $blockPage = SpecialPage
::getTitleFor( 'Block', $userText );
1237 $blockLink = self
::link( $blockPage, wfMessage( 'blocklink' )->escaped() );
1242 * @param int $userId Userid
1243 * @param string $userText User name in database.
1244 * @return string HTML fragment with e-mail user link
1246 public static function emailLink( $userId, $userText ) {
1247 $emailPage = SpecialPage
::getTitleFor( 'Emailuser', $userText );
1248 $emailLink = self
::link( $emailPage, wfMessage( 'emaillink' )->escaped() );
1253 * Generate a user link if the current user is allowed to view it
1255 * @param Revision $rev
1256 * @param bool $isPublic Show only if all users can see it
1257 * @return string HTML fragment
1259 public static function revUserLink( $rev, $isPublic = false ) {
1260 if ( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1261 $link = wfMessage( 'rev-deleted-user' )->escaped();
1262 } elseif ( $rev->userCan( Revision
::DELETED_USER
) ) {
1263 $link = self
::userLink( $rev->getUser( Revision
::FOR_THIS_USER
),
1264 $rev->getUserText( Revision
::FOR_THIS_USER
) );
1266 $link = wfMessage( 'rev-deleted-user' )->escaped();
1268 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1269 return '<span class="history-deleted">' . $link . '</span>';
1275 * Generate a user tool link cluster if the current user is allowed to view it
1277 * @param Revision $rev
1278 * @param bool $isPublic Show only if all users can see it
1279 * @return string HTML
1281 public static function revUserTools( $rev, $isPublic = false ) {
1282 if ( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1283 $link = wfMessage( 'rev-deleted-user' )->escaped();
1284 } elseif ( $rev->userCan( Revision
::DELETED_USER
) ) {
1285 $userId = $rev->getUser( Revision
::FOR_THIS_USER
);
1286 $userText = $rev->getUserText( Revision
::FOR_THIS_USER
);
1287 $link = self
::userLink( $userId, $userText )
1288 . self
::userToolLinks( $userId, $userText );
1290 $link = wfMessage( 'rev-deleted-user' )->escaped();
1292 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1293 return ' <span class="history-deleted">' . $link . '</span>';
1299 * This function is called by all recent changes variants, by the page history,
1300 * and by the user contributions list. It is responsible for formatting edit
1301 * summaries. It escapes any HTML in the summary, but adds some CSS to format
1302 * auto-generated comments (from section editing) and formats [[wikilinks]].
1304 * @author Erik Moeller <moeller@scireview.de>
1305 * @since 1.16.3. $wikiId added in 1.26
1307 * Note: there's not always a title to pass to this function.
1308 * Since you can't set a default parameter for a reference, I've turned it
1309 * temporarily to a value pass. Should be adjusted further. --brion
1311 * @param string $comment
1312 * @param Title|null $title Title object (to generate link to the section in autocomment)
1314 * @param bool $local Whether section links should refer to local page
1315 * @param string|null $wikiId Id (as used by WikiMap) of the wiki to generate links to.
1316 * For use with external changes.
1318 * @return mixed|string
1320 public static function formatComment(
1321 $comment, $title = null, $local = false, $wikiId = null
1323 # Sanitize text a bit:
1324 $comment = str_replace( "\n", " ", $comment );
1325 # Allow HTML entities (for bug 13815)
1326 $comment = Sanitizer
::escapeHtmlAllowEntities( $comment );
1328 # Render autocomments and make links:
1329 $comment = self
::formatAutocomments( $comment, $title, $local, $wikiId );
1330 $comment = self
::formatLinksInComment( $comment, $title, $local, $wikiId );
1336 * Converts autogenerated comments in edit summaries into section links.
1338 * The pattern for autogen comments is / * foo * /, which makes for
1340 * We look for all comments, match any text before and after the comment,
1341 * add a separator where needed and format the comment itself with CSS
1342 * Called by Linker::formatComment.
1344 * @param string $comment Comment text
1345 * @param Title|null $title An optional title object used to links to sections
1346 * @param bool $local Whether section links should refer to local page
1347 * @param string|null $wikiId Id of the wiki to link to (if not the local wiki),
1348 * as used by WikiMap.
1350 * @return string Formatted comment (wikitext)
1352 private static function formatAutocomments(
1353 $comment, $title = null, $local = false, $wikiId = null
1355 // @todo $append here is something of a hack to preserve the status
1356 // quo. Someone who knows more about bidi and such should decide
1357 // (1) what sane rendering even *is* for an LTR edit summary on an RTL
1358 // wiki, both when autocomments exist and when they don't, and
1359 // (2) what markup will make that actually happen.
1361 $comment = preg_replace_callback(
1362 // To detect the presence of content before or after the
1363 // auto-comment, we use capturing groups inside optional zero-width
1364 // assertions. But older versions of PCRE can't directly make
1365 // zero-width assertions optional, so wrap them in a non-capturing
1367 '!(?:(?<=(.)))?/\*\s*(.*?)\s*\*/(?:(?=(.)))?!',
1368 function ( $match ) use ( $title, $local, $wikiId, &$append ) {
1371 // Ensure all match positions are defined
1372 $match +
= [ '', '', '', '' ];
1374 $pre = $match[1] !== '';
1376 $post = $match[3] !== '';
1380 'FormatAutocomments',
1381 [ &$comment, $pre, $auto, $post, $title, $local, $wikiId ]
1384 if ( $comment === null ) {
1388 # Remove links that a user may have manually put in the autosummary
1389 # This could be improved by copying as much of Parser::stripSectionName as desired.
1390 $section = str_replace( '[[:', '', $section );
1391 $section = str_replace( '[[', '', $section );
1392 $section = str_replace( ']]', '', $section );
1394 $section = Sanitizer
::normalizeSectionNameWhitespace( $section ); # bug 22784
1396 $sectionTitle = Title
::newFromText( '#' . $section );
1398 $sectionTitle = Title
::makeTitleSafe( $title->getNamespace(),
1399 $title->getDBkey(), $section );
1401 if ( $sectionTitle ) {
1402 $link = Linker
::makeCommentLink( $sectionTitle, $wgLang->getArrow(), $wikiId, 'noclasses' );
1408 # written summary $presep autocomment (summary /* section */)
1409 $pre = wfMessage( 'autocomment-prefix' )->inContentLanguage()->escaped();
1412 # autocomment $postsep written summary (/* section */ summary)
1413 $auto .= wfMessage( 'colon-separator' )->inContentLanguage()->escaped();
1415 $auto = '<span class="autocomment">' . $auto . '</span>';
1416 $comment = $pre . $link . $wgLang->getDirMark()
1417 . '<span dir="auto">' . $auto;
1418 $append .= '</span>';
1424 return $comment . $append;
1428 * Formats wiki links and media links in text; all other wiki formatting
1431 * @since 1.16.3. $wikiId added in 1.26
1432 * @todo FIXME: Doesn't handle sub-links as in image thumb texts like the main parser
1434 * @param string $comment Text to format links in. WARNING! Since the output of this
1435 * function is html, $comment must be sanitized for use as html. You probably want
1436 * to pass $comment through Sanitizer::escapeHtmlAllowEntities() before calling
1438 * @param Title|null $title An optional title object used to links to sections
1439 * @param bool $local Whether section links should refer to local page
1440 * @param string|null $wikiId Id of the wiki to link to (if not the local wiki),
1441 * as used by WikiMap.
1445 public static function formatLinksInComment(
1446 $comment, $title = null, $local = false, $wikiId = null
1448 return preg_replace_callback(
1451 :? # ignore optional leading colon
1452 ([^\]|]+) # 1. link target; page names cannot include ] or |
1454 # 2. a pipe-separated substring; only the last is captured
1455 # Stop matching at | and ]] without relying on backtracking.
1459 ([^[]*) # 3. link trail (the text up until the next link)
1461 function ( $match ) use ( $title, $local, $wikiId ) {
1464 $medians = '(?:' . preg_quote( MWNamespace
::getCanonicalName( NS_MEDIA
), '/' ) . '|';
1465 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA
), '/' ) . '):';
1467 $comment = $match[0];
1469 # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
1470 if ( strpos( $match[1], '%' ) !== false ) {
1472 rawurldecode( $match[1] ),
1473 [ '<' => '<', '>' => '>' ]
1477 # Handle link renaming [[foo|text]] will show link as "text"
1478 if ( $match[2] != "" ) {
1485 if ( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1486 # Media link; trail not supported.
1487 $linkRegexp = '/\[\[(.*?)\]\]/';
1488 $title = Title
::makeTitleSafe( NS_FILE
, $submatch[1] );
1490 $thelink = Linker
::makeMediaLinkObj( $title, $text );
1493 # Other kind of link
1494 # Make sure its target is non-empty
1495 if ( isset( $match[1][0] ) && $match[1][0] == ':' ) {
1496 $match[1] = substr( $match[1], 1 );
1498 if ( $match[1] !== false && $match[1] !== '' ) {
1499 if ( preg_match( $wgContLang->linkTrail(), $match[3], $submatch ) ) {
1500 $trail = $submatch[1];
1504 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1505 list( $inside, $trail ) = Linker
::splitTrail( $trail );
1508 $linkTarget = Linker
::normalizeSubpageLink( $title, $match[1], $linkText );
1510 $target = Title
::newFromText( $linkTarget );
1512 if ( $target->getText() == '' && !$target->isExternal()
1513 && !$local && $title
1515 $newTarget = clone $title;
1516 $newTarget->setFragment( '#' . $target->getFragment() );
1517 $target = $newTarget;
1520 $thelink = Linker
::makeCommentLink( $target, $linkText . $inside, $wikiId ) . $trail;
1525 // If the link is still valid, go ahead and replace it in!
1526 $comment = preg_replace(
1528 StringUtils
::escapeRegexReplacement( $thelink ),
1541 * Generates a link to the given Title
1543 * @note This is only public for technical reasons. It's not intended for use outside Linker.
1545 * @param Title $title
1546 * @param string $text
1547 * @param string|null $wikiId Id of the wiki to link to (if not the local wiki),
1548 * as used by WikiMap.
1549 * @param string|string[] $options See the $options parameter in Linker::link.
1551 * @return string HTML link
1553 public static function makeCommentLink(
1554 Title
$title, $text, $wikiId = null, $options = []
1556 if ( $wikiId !== null && !$title->isExternal() ) {
1557 $link = Linker
::makeExternalLink(
1558 WikiMap
::getForeignURL(
1560 $title->getPrefixedText(),
1561 $title->getFragment()
1564 /* escape = */ false // Already escaped
1567 $link = Linker
::link( $title, $text, [], [], $options );
1574 * @param Title $contextTitle
1575 * @param string $target
1576 * @param string $text
1579 public static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
1582 # :Foobar -- override special treatment of prefix (images, language links)
1583 # /Foobar -- convert to CurrentPage/Foobar
1584 # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial and final / from text
1585 # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1586 # ../Foobar -- convert to CurrentPage/Foobar,
1587 # (from CurrentPage/CurrentSubPage)
1588 # ../Foobar/ -- convert to CurrentPage/Foobar, use 'Foobar' as text
1589 # (from CurrentPage/CurrentSubPage)
1591 $ret = $target; # default return value is no change
1593 # Some namespaces don't allow subpages,
1594 # so only perform processing if subpages are allowed
1595 if ( $contextTitle && MWNamespace
::hasSubpages( $contextTitle->getNamespace() ) ) {
1596 $hash = strpos( $target, '#' );
1597 if ( $hash !== false ) {
1598 $suffix = substr( $target, $hash );
1599 $target = substr( $target, 0, $hash );
1604 $target = trim( $target );
1605 # Look at the first character
1606 if ( $target != '' && $target[0] === '/' ) {
1607 # / at end means we don't want the slash to be shown
1609 $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
1610 if ( $trailingSlashes ) {
1611 $noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
1613 $noslash = substr( $target, 1 );
1616 $ret = $contextTitle->getPrefixedText() . '/' . trim( $noslash ) . $suffix;
1617 if ( $text === '' ) {
1618 $text = $target . $suffix;
1619 } # this might be changed for ugliness reasons
1621 # check for .. subpage backlinks
1623 $nodotdot = $target;
1624 while ( strncmp( $nodotdot, "../", 3 ) == 0 ) {
1626 $nodotdot = substr( $nodotdot, 3 );
1628 if ( $dotdotcount > 0 ) {
1629 $exploded = explode( '/', $contextTitle->getPrefixedText() );
1630 if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1631 $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
1632 # / at the end means don't show full path
1633 if ( substr( $nodotdot, -1, 1 ) === '/' ) {
1634 $nodotdot = rtrim( $nodotdot, '/' );
1635 if ( $text === '' ) {
1636 $text = $nodotdot . $suffix;
1639 $nodotdot = trim( $nodotdot );
1640 if ( $nodotdot != '' ) {
1641 $ret .= '/' . $nodotdot;
1653 * Wrap a comment in standard punctuation and formatting if
1654 * it's non-empty, otherwise return empty string.
1656 * @since 1.16.3. $wikiId added in 1.26
1657 * @param string $comment
1658 * @param Title|null $title Title object (to generate link to section in autocomment) or null
1659 * @param bool $local Whether section links should refer to local page
1660 * @param string|null $wikiId Id (as used by WikiMap) of the wiki to generate links to.
1661 * For use with external changes.
1665 public static function commentBlock(
1666 $comment, $title = null, $local = false, $wikiId = null
1668 // '*' used to be the comment inserted by the software way back
1669 // in antiquity in case none was provided, here for backwards
1670 // compatibility, acc. to brion -ævar
1671 if ( $comment == '' ||
$comment == '*' ) {
1674 $formatted = self
::formatComment( $comment, $title, $local, $wikiId );
1675 $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped();
1676 return " <span class=\"comment\">$formatted</span>";
1681 * Wrap and format the given revision's comment block, if the current
1682 * user is allowed to view it.
1685 * @param Revision $rev
1686 * @param bool $local Whether section links should refer to local page
1687 * @param bool $isPublic Show only if all users can see it
1688 * @return string HTML fragment
1690 public static function revComment( Revision
$rev, $local = false, $isPublic = false ) {
1691 if ( $rev->getComment( Revision
::RAW
) == "" ) {
1694 if ( $rev->isDeleted( Revision
::DELETED_COMMENT
) && $isPublic ) {
1695 $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>";
1696 } elseif ( $rev->userCan( Revision
::DELETED_COMMENT
) ) {
1697 $block = self
::commentBlock( $rev->getComment( Revision
::FOR_THIS_USER
),
1698 $rev->getTitle(), $local );
1700 $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>";
1702 if ( $rev->isDeleted( Revision
::DELETED_COMMENT
) ) {
1703 return " <span class=\"history-deleted\">$block</span>";
1713 public static function formatRevisionSize( $size ) {
1715 $stxt = wfMessage( 'historyempty' )->escaped();
1717 $stxt = wfMessage( 'nbytes' )->numParams( $size )->escaped();
1718 $stxt = wfMessage( 'parentheses' )->rawParams( $stxt )->escaped();
1720 return "<span class=\"history-size\">$stxt</span>";
1724 * Add another level to the Table of Contents
1729 public static function tocIndent() {
1734 * Finish one or more sublevels on the Table of Contents
1740 public static function tocUnindent( $level ) {
1741 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level > 0 ?
$level : 0 );
1745 * parameter level defines if we are on an indentation level
1748 * @param string $anchor
1749 * @param string $tocline
1750 * @param string $tocnumber
1751 * @param string $level
1752 * @param string|bool $sectionIndex
1755 public static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
1756 $classes = "toclevel-$level";
1757 if ( $sectionIndex !== false ) {
1758 $classes .= " tocsection-$sectionIndex";
1760 return "\n<li class=\"$classes\"><a href=\"#" .
1761 $anchor . '"><span class="tocnumber">' .
1762 $tocnumber . '</span> <span class="toctext">' .
1763 $tocline . '</span></a>';
1767 * End a Table Of Contents line.
1768 * tocUnindent() will be used instead if we're ending a line below
1773 public static function tocLineEnd() {
1778 * Wraps the TOC in a table and provides the hide/collapse javascript.
1781 * @param string $toc Html of the Table Of Contents
1782 * @param string|Language|bool $lang Language for the toc title, defaults to user language
1783 * @return string Full html of the TOC
1785 public static function tocList( $toc, $lang = false ) {
1786 $lang = wfGetLangObj( $lang );
1787 $title = wfMessage( 'toc' )->inLanguage( $lang )->escaped();
1789 return '<div id="toc" class="toc">'
1790 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
1792 . "</ul>\n</div>\n";
1796 * Generate a table of contents from a section tree.
1798 * @since 1.16.3. $lang added in 1.17
1799 * @param array $tree Return value of ParserOutput::getSections()
1800 * @param string|Language|bool $lang Language for the toc title, defaults to user language
1801 * @return string HTML fragment
1803 public static function generateTOC( $tree, $lang = false ) {
1806 foreach ( $tree as $section ) {
1807 if ( $section['toclevel'] > $lastLevel ) {
1808 $toc .= self
::tocIndent();
1809 } elseif ( $section['toclevel'] < $lastLevel ) {
1810 $toc .= self
::tocUnindent(
1811 $lastLevel - $section['toclevel'] );
1813 $toc .= self
::tocLineEnd();
1816 $toc .= self
::tocLine( $section['anchor'],
1817 $section['line'], $section['number'],
1818 $section['toclevel'], $section['index'] );
1819 $lastLevel = $section['toclevel'];
1821 $toc .= self
::tocLineEnd();
1822 return self
::tocList( $toc, $lang );
1826 * Create a headline for content
1829 * @param int $level The level of the headline (1-6)
1830 * @param string $attribs Any attributes for the headline, starting with
1831 * a space and ending with '>'
1832 * This *must* be at least '>' for no attribs
1833 * @param string $anchor The anchor to give the headline (the bit after the #)
1834 * @param string $html Html for the text of the header
1835 * @param string $link HTML to add for the section edit link
1836 * @param bool|string $legacyAnchor A second, optional anchor to give for
1837 * backward compatibility (false to omit)
1839 * @return string HTML headline
1841 public static function makeHeadline( $level, $attribs, $anchor, $html,
1842 $link, $legacyAnchor = false
1844 $ret = "<h$level$attribs"
1845 . "<span class=\"mw-headline\" id=\"$anchor\">$html</span>"
1848 if ( $legacyAnchor !== false ) {
1849 $ret = "<div id=\"$legacyAnchor\"></div>$ret";
1855 * Split a link trail, return the "inside" portion and the remainder of the trail
1856 * as a two-element array
1857 * @param string $trail
1860 static function splitTrail( $trail ) {
1862 $regex = $wgContLang->linkTrail();
1864 if ( $trail !== '' ) {
1866 if ( preg_match( $regex, $trail, $m ) ) {
1871 return [ $inside, $trail ];
1875 * Generate a rollback link for a given revision. Currently it's the
1876 * caller's responsibility to ensure that the revision is the top one. If
1877 * it's not, of course, the user will get an error message.
1879 * If the calling page is called with the parameter &bot=1, all rollback
1880 * links also get that parameter. It causes the edit itself and the rollback
1881 * to be marked as "bot" edits. Bot edits are hidden by default from recent
1882 * changes, so this allows sysops to combat a busy vandal without bothering
1885 * If the option verify is set this function will return the link only in case the
1886 * revision can be reverted. Please note that due to performance limitations
1887 * it might be assumed that a user isn't the only contributor of a page while
1888 * (s)he is, which will lead to useless rollback links. Furthermore this wont
1889 * work if $wgShowRollbackEditCount is disabled, so this can only function
1890 * as an additional check.
1892 * If the option noBrackets is set the rollback link wont be enclosed in "[]".
1894 * See the "mediawiki.page.rollback" module for the client-side handling of this link.
1896 * @since 1.16.3. $context added in 1.20. $options added in 1.21
1898 * @param Revision $rev
1899 * @param IContextSource $context Context to use or null for the main context.
1900 * @param array $options
1903 public static function generateRollback( $rev, IContextSource
$context = null,
1904 $options = [ 'verify' ]
1906 if ( $context === null ) {
1907 $context = RequestContext
::getMain();
1911 if ( in_array( 'verify', $options, true ) ) {
1912 $editCount = self
::getRollbackEditCount( $rev, true );
1913 if ( $editCount === false ) {
1918 $inner = self
::buildRollbackLink( $rev, $context, $editCount );
1920 if ( !in_array( 'noBrackets', $options, true ) ) {
1921 $inner = $context->msg( 'brackets' )->rawParams( $inner )->escaped();
1924 $context->getOutput()->addModules( 'mediawiki.page.rollback' );
1926 return '<span class="mw-rollback-link">' . $inner . '</span>';
1930 * This function will return the number of revisions which a rollback
1931 * would revert and, if $verify is set it will verify that a revision
1932 * can be reverted (that the user isn't the only contributor and the
1933 * revision we might rollback to isn't deleted). These checks can only
1934 * function as an additional check as this function only checks against
1935 * the last $wgShowRollbackEditCount edits.
1937 * Returns null if $wgShowRollbackEditCount is disabled or false if $verify
1938 * is set and the user is the only contributor of the page.
1940 * @param Revision $rev
1941 * @param bool $verify Try to verify that this revision can really be rolled back
1942 * @return int|bool|null
1944 public static function getRollbackEditCount( $rev, $verify ) {
1945 global $wgShowRollbackEditCount;
1946 if ( !is_int( $wgShowRollbackEditCount ) ||
!$wgShowRollbackEditCount > 0 ) {
1947 // Nothing has happened, indicate this by returning 'null'
1951 $dbr = wfGetDB( DB_SLAVE
);
1953 // Up to the value of $wgShowRollbackEditCount revisions are counted
1954 $res = $dbr->select(
1956 [ 'rev_user_text', 'rev_deleted' ],
1957 // $rev->getPage() returns null sometimes
1958 [ 'rev_page' => $rev->getTitle()->getArticleID() ],
1961 'USE INDEX' => [ 'revision' => 'page_timestamp' ],
1962 'ORDER BY' => 'rev_timestamp DESC',
1963 'LIMIT' => $wgShowRollbackEditCount +
1
1969 foreach ( $res as $row ) {
1970 if ( $rev->getUserText( Revision
::RAW
) != $row->rev_user_text
) {
1972 ( $row->rev_deleted
& Revision
::DELETED_TEXT
1973 ||
$row->rev_deleted
& Revision
::DELETED_USER
1975 // If the user or the text of the revision we might rollback
1976 // to is deleted in some way we can't rollback. Similar to
1977 // the sanity checks in WikiPage::commitRollback.
1986 if ( $verify && $editCount <= $wgShowRollbackEditCount && !$moreRevs ) {
1987 // We didn't find at least $wgShowRollbackEditCount revisions made by the current user
1988 // and there weren't any other revisions. That means that the current user is the only
1989 // editor, so we can't rollback
1996 * Build a raw rollback link, useful for collections of "tool" links
1998 * @since 1.16.3. $context added in 1.20. $editCount added in 1.21
1999 * @param Revision $rev
2000 * @param IContextSource|null $context Context to use or null for the main context.
2001 * @param int $editCount Number of edits that would be reverted
2002 * @return string HTML fragment
2004 public static function buildRollbackLink( $rev, IContextSource
$context = null,
2007 global $wgShowRollbackEditCount, $wgMiserMode;
2009 // To config which pages are affected by miser mode
2010 $disableRollbackEditCountSpecialPage = [ 'Recentchanges', 'Watchlist' ];
2012 if ( $context === null ) {
2013 $context = RequestContext
::getMain();
2016 $title = $rev->getTitle();
2018 'action' => 'rollback',
2019 'from' => $rev->getUserText(),
2022 'data-mw' => 'interface',
2023 'title' => $context->msg( 'tooltip-rollback' )->text(),
2025 $options = [ 'known', 'noclasses' ];
2027 if ( $context->getRequest()->getBool( 'bot' ) ) {
2028 $query['bot'] = '1';
2029 $query['hidediff'] = '1'; // bug 15999
2032 $disableRollbackEditCount = false;
2033 if ( $wgMiserMode ) {
2034 foreach ( $disableRollbackEditCountSpecialPage as $specialPage ) {
2035 if ( $context->getTitle()->isSpecial( $specialPage ) ) {
2036 $disableRollbackEditCount = true;
2042 if ( !$disableRollbackEditCount
2043 && is_int( $wgShowRollbackEditCount )
2044 && $wgShowRollbackEditCount > 0
2046 if ( !is_numeric( $editCount ) ) {
2047 $editCount = self
::getRollbackEditCount( $rev, false );
2050 if ( $editCount > $wgShowRollbackEditCount ) {
2051 $html = $context->msg( 'rollbacklinkcount-morethan' )
2052 ->numParams( $wgShowRollbackEditCount )->parse();
2054 $html = $context->msg( 'rollbacklinkcount' )->numParams( $editCount )->parse();
2057 return self
::link( $title, $html, $attrs, $query, $options );
2059 $html = $context->msg( 'rollbacklink' )->escaped();
2060 return self
::link( $title, $html, $attrs, $query, $options );
2065 * Returns HTML for the "templates used on this page" list.
2067 * Make an HTML list of templates, and then add a "More..." link at
2068 * the bottom. If $more is null, do not add a "More..." link. If $more
2069 * is a Title, make a link to that title and use it. If $more is a string,
2070 * directly paste it in as the link (escaping needs to be done manually).
2071 * Finally, if $more is a Message, call toString().
2073 * @since 1.16.3. $more added in 1.21
2074 * @param Title[] $templates Array of templates
2075 * @param bool $preview Whether this is for a preview
2076 * @param bool $section Whether this is for a section edit
2077 * @param Title|Message|string|null $more An escaped link for "More..." of the templates
2078 * @return string HTML output
2080 public static function formatTemplates( $templates, $preview = false,
2081 $section = false, $more = null
2086 if ( count( $templates ) > 0 ) {
2087 # Do a batch existence check
2088 $batch = new LinkBatch
;
2089 foreach ( $templates as $title ) {
2090 $batch->addObj( $title );
2094 # Construct the HTML
2095 $outText = '<div class="mw-templatesUsedExplanation">';
2097 $outText .= wfMessage( 'templatesusedpreview' )->numParams( count( $templates ) )
2099 } elseif ( $section ) {
2100 $outText .= wfMessage( 'templatesusedsection' )->numParams( count( $templates ) )
2103 $outText .= wfMessage( 'templatesused' )->numParams( count( $templates ) )
2106 $outText .= "</div><ul>\n";
2108 usort( $templates, 'Title::compare' );
2109 foreach ( $templates as $titleObj ) {
2111 $restrictions = $titleObj->getRestrictions( 'edit' );
2112 if ( $restrictions ) {
2113 // Check backwards-compatible messages
2115 if ( $restrictions === [ 'sysop' ] ) {
2116 $msg = wfMessage( 'template-protected' );
2117 } elseif ( $restrictions === [ 'autoconfirmed' ] ) {
2118 $msg = wfMessage( 'template-semiprotected' );
2120 if ( $msg && !$msg->isDisabled() ) {
2121 $protected = $msg->parse();
2123 // Construct the message from restriction-level-*
2124 // e.g. restriction-level-sysop, restriction-level-autoconfirmed
2126 foreach ( $restrictions as $r ) {
2127 $msgs[] = wfMessage( "restriction-level-$r" )->parse();
2129 $protected = wfMessage( 'parentheses' )
2130 ->rawParams( $wgLang->commaList( $msgs ) )->escaped();
2133 if ( $titleObj->quickUserCan( 'edit' ) ) {
2134 $editLink = self
::link(
2136 wfMessage( 'editlink' )->escaped(),
2138 [ 'action' => 'edit' ]
2141 $editLink = self
::link(
2143 wfMessage( 'viewsourcelink' )->escaped(),
2145 [ 'action' => 'edit' ]
2148 $outText .= '<li>' . self
::link( $titleObj )
2149 . wfMessage( 'word-separator' )->escaped()
2150 . wfMessage( 'parentheses' )->rawParams( $editLink )->escaped()
2151 . wfMessage( 'word-separator' )->escaped()
2152 . $protected . '</li>';
2155 if ( $more instanceof Title
) {
2156 $outText .= '<li>' . self
::link( $more, wfMessage( 'moredotdotdot' ) ) . '</li>';
2157 } elseif ( $more ) {
2158 $outText .= "<li>$more</li>";
2161 $outText .= '</ul>';
2167 * Returns HTML for the "hidden categories on this page" list.
2170 * @param array $hiddencats Array of hidden categories from Article::getHiddenCategories
2172 * @return string HTML output
2174 public static function formatHiddenCategories( $hiddencats ) {
2177 if ( count( $hiddencats ) > 0 ) {
2178 # Construct the HTML
2179 $outText = '<div class="mw-hiddenCategoriesExplanation">';
2180 $outText .= wfMessage( 'hiddencategories' )->numParams( count( $hiddencats ) )->parseAsBlock();
2181 $outText .= "</div><ul>\n";
2183 foreach ( $hiddencats as $titleObj ) {
2184 # If it's hidden, it must exist - no need to check with a LinkBatch
2186 . self
::link( $titleObj, null, [], [], 'known' )
2189 $outText .= '</ul>';
2195 * Format a size in bytes for output, using an appropriate
2196 * unit (B, KB, MB or GB) according to the magnitude in question
2199 * @param int $size Size to format
2202 public static function formatSize( $size ) {
2204 return htmlspecialchars( $wgLang->formatSize( $size ) );
2208 * Given the id of an interface element, constructs the appropriate title
2209 * attribute from the system messages. (Note, this is usually the id but
2210 * isn't always, because sometimes the accesskey needs to go on a different
2211 * element than the id, for reverse-compatibility, etc.)
2213 * @since 1.16.3 $msgParams added in 1.27
2214 * @param string $name Id of the element, minus prefixes.
2215 * @param string|null $options Null or the string 'withaccess' to add an access-
2217 * @param array $msgParams Parameters to pass to the message
2219 * @return string Contents of the title attribute (which you must HTML-
2220 * escape), or false for no title attribute
2222 public static function titleAttrib( $name, $options = null, array $msgParams = [] ) {
2223 $message = wfMessage( "tooltip-$name", $msgParams );
2224 if ( !$message->exists() ) {
2227 $tooltip = $message->text();
2228 # Compatibility: formerly some tooltips had [alt-.] hardcoded
2229 $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
2230 # Message equal to '-' means suppress it.
2231 if ( $tooltip == '-' ) {
2236 if ( $options == 'withaccess' ) {
2237 $accesskey = self
::accesskey( $name );
2238 if ( $accesskey !== false ) {
2239 // Should be build the same as in jquery.accessKeyLabel.js
2240 if ( $tooltip === false ||
$tooltip === '' ) {
2241 $tooltip = wfMessage( 'brackets', $accesskey )->text();
2243 $tooltip .= wfMessage( 'word-separator' )->text();
2244 $tooltip .= wfMessage( 'brackets', $accesskey )->text();
2252 public static $accesskeycache;
2255 * Given the id of an interface element, constructs the appropriate
2256 * accesskey attribute from the system messages. (Note, this is usually
2257 * the id but isn't always, because sometimes the accesskey needs to go on
2258 * a different element than the id, for reverse-compatibility, etc.)
2261 * @param string $name Id of the element, minus prefixes.
2262 * @return string Contents of the accesskey attribute (which you must HTML-
2263 * escape), or false for no accesskey attribute
2265 public static function accesskey( $name ) {
2266 if ( isset( self
::$accesskeycache[$name] ) ) {
2267 return self
::$accesskeycache[$name];
2270 $message = wfMessage( "accesskey-$name" );
2272 if ( !$message->exists() ) {
2275 $accesskey = $message->plain();
2276 if ( $accesskey === '' ||
$accesskey === '-' ) {
2277 # @todo FIXME: Per standard MW behavior, a value of '-' means to suppress the
2278 # attribute, but this is broken for accesskey: that might be a useful
2284 self
::$accesskeycache[$name] = $accesskey;
2285 return self
::$accesskeycache[$name];
2289 * Get a revision-deletion link, or disabled link, or nothing, depending
2290 * on user permissions & the settings on the revision.
2292 * Will use forward-compatible revision ID in the Special:RevDelete link
2293 * if possible, otherwise the timestamp-based ID which may break after
2297 * @param Revision $rev
2298 * @param Title $title
2299 * @return string HTML fragment
2301 public static function getRevDeleteLink( User
$user, Revision
$rev, Title
$title ) {
2302 $canHide = $user->isAllowed( 'deleterevision' );
2303 if ( !$canHide && !( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) ) {
2307 if ( !$rev->userCan( Revision
::DELETED_RESTRICTED
, $user ) ) {
2308 return Linker
::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
2310 if ( $rev->getId() ) {
2311 // RevDelete links using revision ID are stable across
2312 // page deletion and undeletion; use when possible.
2314 'type' => 'revision',
2315 'target' => $title->getPrefixedDBkey(),
2316 'ids' => $rev->getId()
2319 // Older deleted entries didn't save a revision ID.
2320 // We have to refer to these by timestamp, ick!
2322 'type' => 'archive',
2323 'target' => $title->getPrefixedDBkey(),
2324 'ids' => $rev->getTimestamp()
2327 return Linker
::revDeleteLink( $query,
2328 $rev->isDeleted( Revision
::DELETED_RESTRICTED
), $canHide );
2333 * Creates a (show/hide) link for deleting revisions/log entries
2335 * @param array $query Query parameters to be passed to link()
2336 * @param bool $restricted Set to true to use a "<strong>" instead of a "<span>"
2337 * @param bool $delete Set to true to use (show/hide) rather than (show)
2339 * @return string HTML "<a>" link to Special:Revisiondelete, wrapped in a
2340 * span to allow for customization of appearance with CSS
2342 public static function revDeleteLink( $query = [], $restricted = false, $delete = true ) {
2343 $sp = SpecialPage
::getTitleFor( 'Revisiondelete' );
2344 $msgKey = $delete ?
'rev-delundel' : 'rev-showdeleted';
2345 $html = wfMessage( $msgKey )->escaped();
2346 $tag = $restricted ?
'strong' : 'span';
2347 $link = self
::link( $sp, $html, [], $query, [ 'known', 'noclasses' ] );
2350 [ 'class' => 'mw-revdelundel-link' ],
2351 wfMessage( 'parentheses' )->rawParams( $link )->escaped()
2356 * Creates a dead (show/hide) link for deleting revisions/log entries
2359 * @param bool $delete Set to true to use (show/hide) rather than (show)
2361 * @return string HTML text wrapped in a span to allow for customization
2362 * of appearance with CSS
2364 public static function revDeleteLinkDisabled( $delete = true ) {
2365 $msgKey = $delete ?
'rev-delundel' : 'rev-showdeleted';
2366 $html = wfMessage( $msgKey )->escaped();
2367 $htmlParentheses = wfMessage( 'parentheses' )->rawParams( $html )->escaped();
2368 return Xml
::tags( 'span', [ 'class' => 'mw-revdelundel-link' ], $htmlParentheses );
2371 /* Deprecated methods */
2374 * Returns the attributes for the tooltip and access key.
2376 * @since 1.16.3. $msgParams introduced in 1.27
2377 * @param string $name
2378 * @param array $msgParams Params for constructing the message
2382 public static function tooltipAndAccesskeyAttribs( $name, array $msgParams = [] ) {
2383 # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
2384 # no attribute" instead of "output '' as value for attribute", this
2385 # would be three lines.
2387 'title' => self
::titleAttrib( $name, 'withaccess', $msgParams ),
2388 'accesskey' => self
::accesskey( $name )
2390 if ( $attribs['title'] === false ) {
2391 unset( $attribs['title'] );
2393 if ( $attribs['accesskey'] === false ) {
2394 unset( $attribs['accesskey'] );
2400 * Returns raw bits of HTML, use titleAttrib()
2402 * @param string $name
2403 * @param array|null $options
2404 * @return null|string
2406 public static function tooltip( $name, $options = null ) {
2407 # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
2408 # no attribute" instead of "output '' as value for attribute", this
2409 # would be two lines.
2410 $tooltip = self
::titleAttrib( $name, $options );
2411 if ( $tooltip === false ) {
2414 return Xml
::expandAttributes( [