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.
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
42 * external link, as created by [wikisyntax].
44 * @param string $class the contents of the class attribute; if an empty
45 * string is passed, which is the default value, defaults to 'external'.
47 * @deprecated since 1.18 Just pass the external class directly to something using Html::expandAttributes
49 static function getExternalLinkAttributes( $class = 'external' ) {
50 wfDeprecated( __METHOD__
, '1.18' );
51 return self
::getLinkAttributesInternal( '', $class );
55 * Get the appropriate HTML attributes to add to the "a" element of an interwiki link.
57 * @param string $title the title text for the link, URL-encoded (???) but
59 * @param string $unused unused
60 * @param string $class the contents of the class attribute; if an empty
61 * string is passed, which is the default value, defaults to 'external'.
64 static function getInterwikiLinkAttributes( $title, $unused = null, $class = 'external' ) {
67 # @todo FIXME: We have a whole bunch of handling here that doesn't happen in
68 # getExternalLinkAttributes, why?
69 $title = urldecode( $title );
70 $title = $wgContLang->checkTitleEncoding( $title );
71 $title = preg_replace( '/[\\x00-\\x1f]/', ' ', $title );
73 return self
::getLinkAttributesInternal( $title, $class );
77 * Get the appropriate HTML attributes to add to the "a" element of an internal link.
79 * @param string $title the title text for the link, URL-encoded (???) but
81 * @param string $unused unused
82 * @param string $class the contents of the class attribute, default none
85 static function getInternalLinkAttributes( $title, $unused = null, $class = '' ) {
86 $title = urldecode( $title );
87 $title = str_replace( '_', ' ', $title );
88 return self
::getLinkAttributesInternal( $title, $class );
92 * Get the appropriate HTML attributes to add to the "a" element of an internal
93 * link, given the Title object for the page we want to link to.
96 * @param string $unused Unused
97 * @param string $class The contents of the class attribute, default none
98 * @param string|bool $title Optional (unescaped) string to use in the title
99 * attribute; if false, default to the name of the page we're linking to
102 static function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) {
103 if ( $title === false ) {
104 $title = $nt->getPrefixedText();
106 return self
::getLinkAttributesInternal( $title, $class );
110 * Common code for getLinkAttributesX functions
112 * @param $title string
113 * @param $class string
117 private static function getLinkAttributesInternal( $title, $class ) {
118 $title = htmlspecialchars( $title );
119 $class = htmlspecialchars( $class );
121 if ( $class != '' ) {
122 $r .= " class=\"$class\"";
124 if ( $title != '' ) {
125 $r .= " title=\"$title\"";
131 * Return the CSS colour of a known link
134 * @param int $threshold User defined threshold
135 * @return string CSS class
137 public static function getLinkColour( $t, $threshold ) {
139 if ( $t->isRedirect() ) {
141 $colour = 'mw-redirect';
142 } elseif ( $threshold > 0 && $t->isContentPage() &&
143 $t->exists() && $t->getLength() < $threshold
152 * This function returns an HTML link to the given target. It serves a few
154 * 1) If $target is a Title, the correct URL to link to will be figured
156 * 2) It automatically adds the usual classes for various types of link
157 * targets: "new" for red links, "stub" for short articles, etc.
158 * 3) It escapes all attribute values safely so there's no risk of XSS.
159 * 4) It provides a default tooltip if the target is a Title (the page
160 * name of the target).
161 * link() replaces the old functions in the makeLink() family.
163 * @since 1.18 Method exists since 1.16 as non-static, made static in 1.18.
165 * @param Title $target Can currently only be a Title, but this may
166 * change to support Images, literal URLs, etc.
167 * @param string $html The HTML contents of the <a> element, i.e.,
168 * the link text. This is raw HTML and will not be escaped. If null,
169 * defaults to the prefixed text of the Title; or if the Title is just a
170 * fragment, the contents of the fragment.
171 * @param array $customAttribs A key => value array of extra HTML attributes,
172 * such as title and class. (href is ignored.) Classes will be
173 * merged with the default classes, while other attributes will replace
174 * default attributes. All passed attribute values will be HTML-escaped.
175 * A false attribute value means to suppress that attribute.
176 * @param array $query The query string to append to the URL
177 * you're linking to, in key => value array form. Query keys and values
178 * will be URL-encoded.
179 * @param string|array $options String or array of strings:
180 * 'known': Page is known to exist, so don't check if it does.
181 * 'broken': Page is known not to exist, so don't check if it does.
182 * 'noclasses': Don't add any classes automatically (includes "new",
183 * "stub", "mw-redirect", "extiw"). Only use the class attribute
184 * provided, if any, so you get a simple blue link with no funny i-
186 * 'forcearticlepath': Use the article path always, even with a querystring.
187 * Has compatibility issues on some setups, so avoid wherever possible.
188 * 'http': Force a full URL with http:// as the scheme.
189 * 'https': Force a full URL with https:// as the scheme.
190 * @return string HTML <a> attribute
192 public static function link(
193 $target, $html = null, $customAttribs = array(), $query = array(), $options = array()
195 wfProfileIn( __METHOD__
);
196 if ( !$target instanceof Title
) {
197 wfProfileOut( __METHOD__
);
198 return "<!-- ERROR -->$html";
201 if ( is_string( $query ) ) {
202 // some functions withing core using this still hand over query strings
203 wfDeprecated( __METHOD__
. ' with parameter $query as string (should be array)', '1.20' );
204 $query = wfCgiToArray( $query );
206 $options = (array)$options;
208 $dummy = new DummyLinker
; // dummy linker instance for bc on the hooks
211 if ( !wfRunHooks( 'LinkBegin', array( $dummy, $target, &$html,
212 &$customAttribs, &$query, &$options, &$ret ) ) ) {
213 wfProfileOut( __METHOD__
);
217 # Normalize the Title if it's a special page
218 $target = self
::normaliseSpecialPage( $target );
220 # If we don't know whether the page exists, let's find out.
221 wfProfileIn( __METHOD__
. '-checkPageExistence' );
222 if ( !in_array( 'known', $options ) and !in_array( 'broken', $options ) ) {
223 if ( $target->isKnown() ) {
224 $options[] = 'known';
226 $options[] = 'broken';
229 wfProfileOut( __METHOD__
. '-checkPageExistence' );
232 if ( in_array( "forcearticlepath", $options ) && $query ) {
237 # Note: we want the href attribute first, for prettiness.
238 $attribs = array( 'href' => self
::linkUrl( $target, $query, $options ) );
239 if ( in_array( 'forcearticlepath', $options ) && $oldquery ) {
240 $attribs['href'] = wfAppendQuery( $attribs['href'], $oldquery );
243 $attribs = array_merge(
245 self
::linkAttribs( $target, $customAttribs, $options )
247 if ( is_null( $html ) ) {
248 $html = self
::linkText( $target );
252 if ( wfRunHooks( 'LinkEnd', array( $dummy, $target, $options, &$html, &$attribs, &$ret ) ) ) {
253 $ret = Html
::rawElement( 'a', $attribs, $html );
256 wfProfileOut( __METHOD__
);
261 * Identical to link(), except $options defaults to 'known'.
264 public static function linkKnown(
265 $target, $html = null, $customAttribs = array(),
266 $query = array(), $options = array( 'known', 'noclasses' )
268 return self
::link( $target, $html, $customAttribs, $query, $options );
272 * Returns the Url used to link to a Title
274 * @param $target Title
275 * @param array $query query parameters
276 * @param $options Array
279 private static function linkUrl( $target, $query, $options ) {
280 wfProfileIn( __METHOD__
);
281 # We don't want to include fragments for broken links, because they
282 # generally make no sense.
283 if ( in_array( 'broken', $options ) && $target->hasFragment() ) {
284 $target = clone $target;
285 $target->setFragment( '' );
288 # If it's a broken link, add the appropriate query pieces, unless
289 # there's already an action specified, or unless 'edit' makes no sense
290 # (i.e., for a nonexistent special page).
291 if ( in_array( 'broken', $options ) && empty( $query['action'] )
292 && !$target->isSpecialPage() ) {
293 $query['action'] = 'edit';
294 $query['redlink'] = '1';
297 if ( in_array( 'http', $options ) ) {
299 } elseif ( in_array( 'https', $options ) ) {
300 $proto = PROTO_HTTPS
;
302 $proto = PROTO_RELATIVE
;
305 $ret = $target->getLinkURL( $query, false, $proto );
306 wfProfileOut( __METHOD__
);
311 * Returns the array of attributes used when linking to the Title $target
313 * @param $target Title
319 private static function linkAttribs( $target, $attribs, $options ) {
320 wfProfileIn( __METHOD__
);
324 if ( !in_array( 'noclasses', $options ) ) {
325 wfProfileIn( __METHOD__
. '-getClasses' );
326 # Now build the classes.
329 if ( in_array( 'broken', $options ) ) {
333 if ( $target->isExternal() ) {
334 $classes[] = 'extiw';
337 if ( !in_array( 'broken', $options ) ) { # Avoid useless calls to LinkCache (see r50387)
338 $colour = self
::getLinkColour( $target, $wgUser->getStubThreshold() );
339 if ( $colour !== '' ) {
340 $classes[] = $colour; # mw-redirect or stub
343 if ( $classes != array() ) {
344 $defaults['class'] = implode( ' ', $classes );
346 wfProfileOut( __METHOD__
. '-getClasses' );
349 # Get a default title attribute.
350 if ( $target->getPrefixedText() == '' ) {
351 # A link like [[#Foo]]. This used to mean an empty title
352 # attribute, but that's silly. Just don't output a title.
353 } elseif ( in_array( 'known', $options ) ) {
354 $defaults['title'] = $target->getPrefixedText();
356 $defaults['title'] = wfMessage( 'red-link-title', $target->getPrefixedText() )->text();
359 # Finally, merge the custom attribs with the default ones, and iterate
360 # over that, deleting all "false" attributes.
362 $merged = Sanitizer
::mergeAttributes( $defaults, $attribs );
363 foreach ( $merged as $key => $val ) {
364 # A false value suppresses the attribute, and we don't want the
365 # href attribute to be overridden.
366 if ( $key != 'href' and $val !== false ) {
370 wfProfileOut( __METHOD__
);
375 * Default text of the links to the Title $target
377 * @param $target Title
381 private static function linkText( $target ) {
382 // We might be passed a non-Title by make*LinkObj(). Fail gracefully.
383 if ( !$target instanceof Title
) {
387 // If the target is just a fragment, with no title, we return the fragment
388 // text. Otherwise, we return the title text itself.
389 if ( $target->getPrefixedText() === '' && $target->hasFragment() ) {
390 return htmlspecialchars( $target->getFragment() );
392 return htmlspecialchars( $target->getPrefixedText() );
396 * Make appropriate markup for a link to the current article. This is currently rendered
397 * as the bold link text. The calling sequence is the same as the other make*LinkObj static functions,
398 * despite $query not being used.
401 * @param string $html [optional]
402 * @param string $query [optional]
403 * @param string $trail [optional]
404 * @param string $prefix [optional]
409 public static function makeSelfLinkObj( $nt, $html = '', $query = '', $trail = '', $prefix = '' ) {
411 $html = htmlspecialchars( $nt->getPrefixedText() );
413 list( $inside, $trail ) = self
::splitTrail( $trail );
414 return "<strong class=\"selflink\">{$prefix}{$html}{$inside}</strong>{$trail}";
418 * Get a message saying that an invalid title was encountered.
419 * This should be called after a method like Title::makeTitleSafe() returned
420 * a value indicating that the title object is invalid.
422 * @param $context IContextSource context to use to get the messages
423 * @param int $namespace Namespace number
424 * @param string $title Text of the title, without the namespace part
427 public static function getInvalidTitleDescription( IContextSource
$context, $namespace, $title ) {
430 // First we check whether the namespace exists or not.
431 if ( MWNamespace
::exists( $namespace ) ) {
432 if ( $namespace == NS_MAIN
) {
433 $name = $context->msg( 'blanknamespace' )->text();
435 $name = $wgContLang->getFormattedNsText( $namespace );
437 return $context->msg( 'invalidtitle-knownnamespace', $namespace, $name, $title )->text();
439 return $context->msg( 'invalidtitle-unknownnamespace', $namespace, $title )->text();
444 * @param $title Title
447 static function normaliseSpecialPage( Title
$title ) {
448 if ( $title->isSpecialPage() ) {
449 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
453 $ret = SpecialPage
::getTitleFor( $name, $subpage, $title->getFragment() );
461 * Returns the filename part of an url.
462 * Used as alternative text for external images.
468 private static function fnamePart( $url ) {
469 $basename = strrchr( $url, '/' );
470 if ( false === $basename ) {
473 $basename = substr( $basename, 1 );
479 * Return the code for images which were added via external links,
480 * via Parser::maybeMakeExternalImage().
487 public static function makeExternalImage( $url, $alt = '' ) {
489 $alt = self
::fnamePart( $url );
492 $success = wfRunHooks( 'LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
494 wfDebug( "Hook LinkerMakeExternalImage changed the output of external image with url {$url} and alt text {$alt} to {$img}\n", true );
497 return Html
::element( 'img',
504 * Given parameters derived from [[Image:Foo|options...]], generate the
505 * HTML that that syntax inserts in the page.
507 * @param $parser Parser object
508 * @param $title Title object of the file (not the currently viewed page)
509 * @param $file File object, or false if it doesn't exist
510 * @param array $frameParams associative array of parameters external to the media handler.
511 * Boolean parameters are indicated by presence or absence, the value is arbitrary and
512 * will often be false.
513 * thumbnail If present, downscale and frame
514 * manualthumb Image name to use as a thumbnail, instead of automatic scaling
515 * framed Shows image in original size in a frame
516 * frameless Downscale but don't frame
517 * upright If present, tweak default sizes for portrait orientation
518 * upright_factor Fudge factor for "upright" tweak (default 0.75)
519 * border If present, show a border around the image
520 * align Horizontal alignment (left, right, center, none)
521 * valign Vertical alignment (baseline, sub, super, top, text-top, middle,
522 * bottom, text-bottom)
523 * alt Alternate text for image (i.e. alt attribute). Plain text.
524 * class HTML for image classes. Plain text.
525 * caption HTML for image caption.
526 * link-url URL to link to
527 * link-title Title object to link to
528 * link-target Value for the target attribute, only with link-url
529 * no-link Boolean, suppress description link
531 * @param array $handlerParams Associative array of media handler parameters, to be passed
532 * to transform(). Typical keys are "width" and "page".
533 * @param string $time Timestamp of the file, set as false for current
534 * @param string $query Query params for desc url
535 * @param int|null $widthOption Used by the parser to remember the user preference thumbnailsize
537 * @return string HTML for an image, with links, wrappers, etc.
539 public static function makeImageLink( /*Parser*/ $parser, Title
$title, $file, $frameParams = array(),
540 $handlerParams = array(), $time = false, $query = "", $widthOption = null
543 $dummy = new DummyLinker
;
544 if ( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$dummy, &$title,
545 &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
549 if ( $file && !$file->allowInlineDisplay() ) {
550 wfDebug( __METHOD__
. ': ' . $title->getPrefixedDBkey() . " does not allow inline display\n" );
551 return self
::link( $title );
556 $hp =& $handlerParams;
558 // Clean up parameters
559 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
560 if ( !isset( $fp['align'] ) ) {
563 if ( !isset( $fp['alt'] ) ) {
566 if ( !isset( $fp['title'] ) ) {
569 if ( !isset( $fp['class'] ) ) {
573 $prefix = $postfix = '';
575 if ( 'center' == $fp['align'] ) {
576 $prefix = '<div class="center">';
578 $fp['align'] = 'none';
580 if ( $file && !isset( $hp['width'] ) ) {
581 if ( isset( $hp['height'] ) && $file->isVectorized() ) {
582 // If its a vector image, and user only specifies height
583 // we don't want it to be limited by its "normal" width.
584 global $wgSVGMaxSize;
585 $hp['width'] = $wgSVGMaxSize;
587 $hp['width'] = $file->getWidth( $page );
590 if ( isset( $fp['thumbnail'] ) ||
isset( $fp['manualthumb'] ) ||
isset( $fp['framed'] ) ||
isset( $fp['frameless'] ) ||
!$hp['width'] ) {
591 global $wgThumbLimits, $wgThumbUpright;
592 if ( $widthOption === null ||
!isset( $wgThumbLimits[$widthOption] ) ) {
593 $widthOption = User
::getDefaultOption( 'thumbsize' );
596 // Reduce width for upright images when parameter 'upright' is used
597 if ( isset( $fp['upright'] ) && $fp['upright'] == 0 ) {
598 $fp['upright'] = $wgThumbUpright;
600 // For caching health: If width scaled down due to upright parameter, round to full __0 pixel to avoid the creation of a lot of odd thumbs
601 $prefWidth = isset( $fp['upright'] ) ?
602 round( $wgThumbLimits[$widthOption] * $fp['upright'], -1 ) :
603 $wgThumbLimits[$widthOption];
605 // Use width which is smaller: real image width or user preference width
606 // Unless image is scalable vector.
607 if ( !isset( $hp['height'] ) && ( $hp['width'] <= 0 ||
608 $prefWidth < $hp['width'] ||
$file->isVectorized() ) ) {
609 $hp['width'] = $prefWidth;
614 if ( isset( $fp['thumbnail'] ) ||
isset( $fp['manualthumb'] ) ||
isset( $fp['framed'] ) ) {
615 # Create a thumbnail. Alignment depends on the writing direction of
616 # the page content language (right-aligned for LTR languages,
617 # left-aligned for RTL languages)
619 # If a thumbnail width has not been provided, it is set
620 # to the default user option as specified in Language*.php
621 if ( $fp['align'] == '' ) {
622 if ( $parser instanceof Parser
) {
623 $fp['align'] = $parser->getTargetLanguage()->alignEnd();
625 # backwards compatibility, remove with makeImageLink2()
627 $fp['align'] = $wgContLang->alignEnd();
630 return $prefix . self
::makeThumbLink2( $title, $file, $fp, $hp, $time, $query ) . $postfix;
633 if ( $file && isset( $fp['frameless'] ) ) {
634 $srcWidth = $file->getWidth( $page );
635 # For "frameless" option: do not present an image bigger than the source (for bitmap-style images)
636 # This is the same behavior as the "thumb" option does it already.
637 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
638 $hp['width'] = $srcWidth;
642 if ( $file && isset( $hp['width'] ) ) {
643 # Create a resized image, without the additional thumbnail features
644 $thumb = $file->transform( $hp );
650 $s = self
::makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time == true );
652 self
::processResponsiveImages( $file, $thumb, $hp );
655 'title' => $fp['title'],
656 'valign' => isset( $fp['valign'] ) ?
$fp['valign'] : false,
657 'img-class' => $fp['class'] );
658 if ( isset( $fp['border'] ) ) {
659 $params['img-class'] .= ( $params['img-class'] !== '' ?
' ' : '' ) . 'thumbborder';
661 $params = self
::getImageLinkMTOParams( $fp, $query, $parser ) +
$params;
663 $s = $thumb->toHtml( $params );
665 if ( $fp['align'] != '' ) {
666 $s = "<div class=\"float{$fp['align']}\">{$s}</div>";
668 return str_replace( "\n", ' ', $prefix . $s . $postfix );
672 * See makeImageLink()
673 * When this function is removed, remove if( $parser instanceof Parser ) check there too
674 * @deprecated since 1.20
676 public static function makeImageLink2( Title
$title, $file, $frameParams = array(),
677 $handlerParams = array(), $time = false, $query = "", $widthOption = null ) {
678 return self
::makeImageLink( null, $title, $file, $frameParams,
679 $handlerParams, $time, $query, $widthOption );
683 * Get the link parameters for MediaTransformOutput::toHtml() from given
684 * frame parameters supplied by the Parser.
685 * @param array $frameParams The frame parameters
686 * @param string $query An optional query string to add to description page links
689 private static function getImageLinkMTOParams( $frameParams, $query = '', $parser = null ) {
690 $mtoParams = array();
691 if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) {
692 $mtoParams['custom-url-link'] = $frameParams['link-url'];
693 if ( isset( $frameParams['link-target'] ) ) {
694 $mtoParams['custom-target-link'] = $frameParams['link-target'];
697 $extLinkAttrs = $parser->getExternalLinkAttribs( $frameParams['link-url'] );
698 foreach ( $extLinkAttrs as $name => $val ) {
699 // Currently could include 'rel' and 'target'
700 $mtoParams['parser-extlink-' . $name] = $val;
703 } elseif ( isset( $frameParams['link-title'] ) && $frameParams['link-title'] !== '' ) {
704 $mtoParams['custom-title-link'] = self
::normaliseSpecialPage( $frameParams['link-title'] );
705 } elseif ( !empty( $frameParams['no-link'] ) ) {
708 $mtoParams['desc-link'] = true;
709 $mtoParams['desc-query'] = $query;
715 * Make HTML for a thumbnail including image, border and caption
716 * @param $title Title object
717 * @param $file File object or false if it doesn't exist
718 * @param $label String
720 * @param $align String
721 * @param $params Array
722 * @param $framed Boolean
723 * @param $manualthumb String
726 public static function makeThumbLinkObj( Title
$title, $file, $label = '', $alt,
727 $align = 'right', $params = array(), $framed = false, $manualthumb = ""
729 $frameParams = array(
735 $frameParams['framed'] = true;
737 if ( $manualthumb ) {
738 $frameParams['manualthumb'] = $manualthumb;
740 return self
::makeThumbLink2( $title, $file, $frameParams, $params );
744 * @param $title Title
746 * @param array $frameParams
747 * @param array $handlerParams
749 * @param string $query
752 public static function makeThumbLink2( Title
$title, $file, $frameParams = array(),
753 $handlerParams = array(), $time = false, $query = ""
755 global $wgStylePath, $wgContLang;
756 $exists = $file && $file->exists();
760 $hp =& $handlerParams;
762 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
763 if ( !isset( $fp['align'] ) ) {
764 $fp['align'] = 'right';
766 if ( !isset( $fp['alt'] ) ) {
769 if ( !isset( $fp['title'] ) ) {
772 if ( !isset( $fp['caption'] ) ) {
776 if ( empty( $hp['width'] ) ) {
777 // Reduce width for upright images when parameter 'upright' is used
778 $hp['width'] = isset( $fp['upright'] ) ?
130 : 180;
782 $manualthumb = false;
785 $outerWidth = $hp['width'] +
2;
787 if ( isset( $fp['manualthumb'] ) ) {
788 # Use manually specified thumbnail
789 $manual_title = Title
::makeTitleSafe( NS_FILE
, $fp['manualthumb'] );
790 if ( $manual_title ) {
791 $manual_img = wfFindFile( $manual_title );
793 $thumb = $manual_img->getUnscaledThumb( $hp );
799 } elseif ( isset( $fp['framed'] ) ) {
800 // Use image dimensions, don't scale
801 $thumb = $file->getUnscaledThumb( $hp );
804 # Do not present an image bigger than the source, for bitmap-style images
805 # This is a hack to maintain compatibility with arbitrary pre-1.10 behavior
806 $srcWidth = $file->getWidth( $page );
807 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
808 $hp['width'] = $srcWidth;
810 $thumb = $file->transform( $hp );
814 $outerWidth = $thumb->getWidth() +
2;
816 $outerWidth = $hp['width'] +
2;
820 # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
821 # So we don't need to pass it here in $query. However, the URL for the
822 # zoom icon still needs it, so we make a unique query for it. See bug 14771
823 $url = $title->getLocalURL( $query );
825 $url = wfAppendQuery( $url, array( 'page' => $page ) );
828 && !isset( $fp['link-title'] )
829 && !isset( $fp['link-url'] )
830 && !isset( $fp['no-link'] ) ) {
831 $fp['link-url'] = $url;
834 $s = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
836 $s .= self
::makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time == true );
838 } elseif ( !$thumb ) {
839 $s .= wfMessage( 'thumbnail_error', '' )->escaped();
842 if ( !$noscale && !$manualthumb ) {
843 self
::processResponsiveImages( $file, $thumb, $hp );
847 'title' => $fp['title'],
848 'img-class' => ( isset( $fp['class'] ) && $fp['class'] !== '' ?
$fp['class'] . ' ' : '' ) . 'thumbimage'
850 $params = self
::getImageLinkMTOParams( $fp, $query ) +
$params;
851 $s .= $thumb->toHtml( $params );
852 if ( isset( $fp['framed'] ) ) {
855 $zoomIcon = Html
::rawElement( 'div', array( 'class' => 'magnify' ),
856 Html
::rawElement( 'a', array(
858 'class' => 'internal',
859 'title' => wfMessage( 'thumbnail-more' )->text() ),
860 Html
::element( 'img', array(
861 'src' => $wgStylePath . '/common/images/magnify-clip' . ( $wgContLang->isRTL() ?
'-rtl' : '' ) . '.png',
867 $s .= ' <div class="thumbcaption">' . $zoomIcon . $fp['caption'] . "</div></div></div>";
868 return str_replace( "\n", ' ', $s );
872 * Process responsive images: add 1.5x and 2x subimages to the thumbnail, where
876 * @param MediaTransformOutput $thumb
877 * @param array $hp image parameters
879 public static function processResponsiveImages( $file, $thumb, $hp ) {
880 global $wgResponsiveImages;
881 if ( $wgResponsiveImages ) {
883 $hp15['width'] = round( $hp['width'] * 1.5 );
885 $hp20['width'] = $hp['width'] * 2;
886 if ( isset( $hp['height'] ) ) {
887 $hp15['height'] = round( $hp['height'] * 1.5 );
888 $hp20['height'] = $hp['height'] * 2;
891 $thumb15 = $file->transform( $hp15 );
892 $thumb20 = $file->transform( $hp20 );
893 if ( $thumb15 && $thumb15->getUrl() !== $thumb->getUrl() ) {
894 $thumb->responsiveUrls
['1.5'] = $thumb15->getUrl();
896 if ( $thumb20 && $thumb20->getUrl() !== $thumb->getUrl() ) {
897 $thumb->responsiveUrls
['2'] = $thumb20->getUrl();
903 * Make a "broken" link to an image
905 * @param Title $title
906 * @param string $label link label (plain text)
907 * @param string $query query string
908 * @param string $unused1 Unused parameter kept for b/c
909 * @param string $unused2 Unused parameter kept for b/c
910 * @param bool $time a file of a certain timestamp was requested
913 public static function makeBrokenImageLinkObj( $title, $label = '', $query = '', $unused1 = '', $unused2 = '', $time = false ) {
914 global $wgEnableUploads, $wgUploadMissingFileUrl, $wgUploadNavigationUrl;
915 if ( ! $title instanceof Title
) {
916 return "<!-- ERROR -->" . htmlspecialchars( $label );
918 wfProfileIn( __METHOD__
);
919 if ( $label == '' ) {
920 $label = $title->getPrefixedText();
922 $encLabel = htmlspecialchars( $label );
923 $currentExists = $time ?
( wfFindFile( $title ) != false ) : false;
925 if ( ( $wgUploadMissingFileUrl ||
$wgUploadNavigationUrl ||
$wgEnableUploads ) && !$currentExists ) {
926 $redir = RepoGroup
::singleton()->getLocalRepo()->checkRedirect( $title );
929 wfProfileOut( __METHOD__
);
930 return self
::linkKnown( $title, $encLabel, array(), wfCgiToArray( $query ) );
933 $href = self
::getUploadUrl( $title, $query );
935 wfProfileOut( __METHOD__
);
936 return '<a href="' . htmlspecialchars( $href ) . '" class="new" title="' .
937 htmlspecialchars( $title->getPrefixedText(), ENT_QUOTES
) . '">' .
941 wfProfileOut( __METHOD__
);
942 return self
::linkKnown( $title, $encLabel, array(), wfCgiToArray( $query ) );
946 * Get the URL to upload a certain file
948 * @param Title $destFile Title object of the file to upload
949 * @param string $query Urlencoded query string to prepend
950 * @return string Urlencoded URL
952 protected static function getUploadUrl( $destFile, $query = '' ) {
953 global $wgUploadMissingFileUrl, $wgUploadNavigationUrl;
954 $q = 'wpDestFile=' . $destFile->getPartialURL();
955 if ( $query != '' ) {
959 if ( $wgUploadMissingFileUrl ) {
960 return wfAppendQuery( $wgUploadMissingFileUrl, $q );
961 } elseif ( $wgUploadNavigationUrl ) {
962 return wfAppendQuery( $wgUploadNavigationUrl, $q );
964 $upload = SpecialPage
::getTitleFor( 'Upload' );
965 return $upload->getLocalURL( $q );
970 * Create a direct link to a given uploaded file.
972 * @param Title $title
973 * @param string $html Pre-sanitized HTML
974 * @param string $time MW timestamp of file creation time
975 * @return string HTML
977 public static function makeMediaLinkObj( $title, $html = '', $time = false ) {
978 $img = wfFindFile( $title, array( 'time' => $time ) );
979 return self
::makeMediaLinkFile( $title, $img, $html );
983 * Create a direct link to a given uploaded file.
984 * This will make a broken link if $file is false.
986 * @param Title $title
987 * @param File|bool $file File object or false
988 * @param string $html Pre-sanitized HTML
989 * @return string HTML
991 * @todo Handle invalid or missing images better.
993 public static function makeMediaLinkFile( Title
$title, $file, $html = '' ) {
994 if ( $file && $file->exists() ) {
995 $url = $file->getURL();
998 $url = self
::getUploadUrl( $title );
1002 $alt = $title->getText();
1003 if ( $html == '' ) {
1014 if ( !wfRunHooks( 'LinkerMakeMediaLinkFile',
1015 array( $title, $file, &$html, &$attribs, &$ret ) ) ) {
1016 wfDebug( "Hook LinkerMakeMediaLinkFile changed the output of link with url {$url} and text {$html} to {$ret}\n", true );
1020 return Html
::rawElement( 'a', $attribs, $html );
1024 * Make a link to a special page given its name and, optionally,
1025 * a message key from the link text.
1026 * Usage example: Linker::specialLink( 'Recentchanges' )
1030 public static function specialLink( $name, $key = '' ) {
1032 $key = strtolower( $name );
1035 return self
::linkKnown( SpecialPage
::getTitleFor( $name ), wfMessage( $key )->text() );
1039 * Make an external link
1040 * @param string $url URL to link to
1041 * @param string $text Text of link
1042 * @param bool $escape Do we escape the link text?
1043 * @param string $linktype Type of external link. Gets added to the classes
1044 * @param array $attribs Array of extra attributes to <a>
1045 * @param Title|null $title Title object used for title specific link attributes
1048 public static function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array(), $title = null ) {
1050 $class = "external";
1052 $class .= " $linktype";
1054 if ( isset( $attribs['class'] ) && $attribs['class'] ) {
1055 $class .= " {$attribs['class']}";
1057 $attribs['class'] = $class;
1060 $text = htmlspecialchars( $text );
1066 $attribs['rel'] = Parser
::getExternalLinkRel( $url, $title );
1068 $success = wfRunHooks( 'LinkerMakeExternalLink',
1069 array( &$url, &$text, &$link, &$attribs, $linktype ) );
1071 wfDebug( "Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}\n", true );
1074 $attribs['href'] = $url;
1075 return Html
::rawElement( 'a', $attribs, $text );
1079 * Make user link (or user contributions for unregistered users)
1080 * @param int $userId User id in database.
1081 * @param string $userName User name in database.
1082 * @param string $altUserName Text to display instead of the user name (optional)
1083 * @return string HTML fragment
1084 * @since 1.19 Method exists for a long time. $altUserName was added in 1.19.
1086 public static function userLink( $userId, $userName, $altUserName = false ) {
1087 $classes = 'mw-userlink';
1088 if ( $userId == 0 ) {
1089 $page = SpecialPage
::getTitleFor( 'Contributions', $userName );
1090 if ( $altUserName === false ) {
1091 $altUserName = IP
::prettifyIP( $userName );
1093 $classes .= ' mw-anonuserlink'; // Separate link class for anons (bug 43179)
1095 $page = Title
::makeTitle( NS_USER
, $userName );
1100 htmlspecialchars( $altUserName !== false ?
$altUserName : $userName ),
1101 array( 'class' => $classes )
1106 * Generate standard user tool links (talk, contributions, block link, etc.)
1108 * @param int $userId User identifier
1109 * @param string $userText User name or IP address
1110 * @param bool $redContribsWhenNoEdits Should the contributions link be
1111 * red if the user has no edits?
1112 * @param int $flags Customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK and Linker::TOOL_LINKS_EMAIL)
1113 * @param int $edits User edit count (optional, for performance)
1114 * @return string HTML fragment
1116 public static function userToolLinks(
1117 $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits = null
1119 global $wgUser, $wgDisableAnonTalk, $wgLang;
1120 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
1121 $blockable = !( $flags & self
::TOOL_LINKS_NOBLOCK
);
1122 $addEmailLink = $flags & self
::TOOL_LINKS_EMAIL
&& $userId;
1126 $items[] = self
::userTalkLink( $userId, $userText );
1129 // check if the user has an edit
1131 if ( $redContribsWhenNoEdits ) {
1132 if ( intval( $edits ) === 0 && $edits !== 0 ) {
1133 $user = User
::newFromId( $userId );
1134 $edits = $user->getEditCount();
1136 if ( $edits === 0 ) {
1137 $attribs['class'] = 'new';
1140 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $userText );
1142 $items[] = self
::link( $contribsPage, wfMessage( 'contribslink' )->escaped(), $attribs );
1144 if ( $blockable && $wgUser->isAllowed( 'block' ) ) {
1145 $items[] = self
::blockLink( $userId, $userText );
1148 if ( $addEmailLink && $wgUser->canSendEmail() ) {
1149 $items[] = self
::emailLink( $userId, $userText );
1152 wfRunHooks( 'UserToolLinksEdit', array( $userId, $userText, &$items ) );
1155 return wfMessage( 'word-separator' )->plain()
1156 . '<span class="mw-usertoollinks">'
1157 . wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped()
1165 * Alias for userToolLinks( $userId, $userText, true );
1166 * @param int $userId User identifier
1167 * @param string $userText User name or IP address
1168 * @param int $edits User edit count (optional, for performance)
1171 public static function userToolLinksRedContribs( $userId, $userText, $edits = null ) {
1172 return self
::userToolLinks( $userId, $userText, true, 0, $edits );
1176 * @param int $userId User id in database.
1177 * @param string $userText User name in database.
1178 * @return string HTML fragment with user talk link
1180 public static function userTalkLink( $userId, $userText ) {
1181 $userTalkPage = Title
::makeTitle( NS_USER_TALK
, $userText );
1182 $userTalkLink = self
::link( $userTalkPage, wfMessage( 'talkpagelinktext' )->escaped() );
1183 return $userTalkLink;
1187 * @param int $userId Userid
1188 * @param string $userText User name in database.
1189 * @return string HTML fragment with block link
1191 public static function blockLink( $userId, $userText ) {
1192 $blockPage = SpecialPage
::getTitleFor( 'Block', $userText );
1193 $blockLink = self
::link( $blockPage, wfMessage( 'blocklink' )->escaped() );
1198 * @param int $userId Userid
1199 * @param string $userText User name in database.
1200 * @return string HTML fragment with e-mail user link
1202 public static function emailLink( $userId, $userText ) {
1203 $emailPage = SpecialPage
::getTitleFor( 'Emailuser', $userText );
1204 $emailLink = self
::link( $emailPage, wfMessage( 'emaillink' )->escaped() );
1209 * Generate a user link if the current user is allowed to view it
1210 * @param Revision $rev
1211 * @param bool $isPublic Show only if all users can see it
1212 * @return String HTML fragment
1214 public static function revUserLink( $rev, $isPublic = false ) {
1215 if ( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1216 $link = wfMessage( 'rev-deleted-user' )->escaped();
1217 } elseif ( $rev->userCan( Revision
::DELETED_USER
) ) {
1218 $link = self
::userLink( $rev->getUser( Revision
::FOR_THIS_USER
),
1219 $rev->getUserText( Revision
::FOR_THIS_USER
) );
1221 $link = wfMessage( 'rev-deleted-user' )->escaped();
1223 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1224 return '<span class="history-deleted">' . $link . '</span>';
1230 * Generate a user tool link cluster if the current user is allowed to view it
1231 * @param Revision $rev
1232 * @param bool $isPublic Show only if all users can see it
1233 * @return string HTML
1235 public static function revUserTools( $rev, $isPublic = false ) {
1236 if ( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1237 $link = wfMessage( 'rev-deleted-user' )->escaped();
1238 } elseif ( $rev->userCan( Revision
::DELETED_USER
) ) {
1239 $userId = $rev->getUser( Revision
::FOR_THIS_USER
);
1240 $userText = $rev->getUserText( Revision
::FOR_THIS_USER
);
1241 $link = self
::userLink( $userId, $userText )
1242 . wfMessage( 'word-separator' )->plain()
1243 . self
::userToolLinks( $userId, $userText );
1245 $link = wfMessage( 'rev-deleted-user' )->escaped();
1247 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1248 return ' <span class="history-deleted">' . $link . '</span>';
1254 * This function is called by all recent changes variants, by the page history,
1255 * and by the user contributions list. It is responsible for formatting edit
1256 * summaries. It escapes any HTML in the summary, but adds some CSS to format
1257 * auto-generated comments (from section editing) and formats [[wikilinks]].
1259 * @author Erik Moeller <moeller@scireview.de>
1261 * Note: there's not always a title to pass to this function.
1262 * Since you can't set a default parameter for a reference, I've turned it
1263 * temporarily to a value pass. Should be adjusted further. --brion
1265 * @param string $comment
1266 * @param Title|null $title Title object (to generate link to the section in autocomment) or null
1267 * @param bool $local Whether section links should refer to local page
1268 * @return mixed|String
1270 public static function formatComment( $comment, $title = null, $local = false ) {
1271 wfProfileIn( __METHOD__
);
1273 # Sanitize text a bit:
1274 $comment = str_replace( "\n", " ", $comment );
1275 # Allow HTML entities (for bug 13815)
1276 $comment = Sanitizer
::escapeHtmlAllowEntities( $comment );
1278 # Render autocomments and make links:
1279 $comment = self
::formatAutocomments( $comment, $title, $local );
1280 $comment = self
::formatLinksInComment( $comment, $title, $local );
1282 wfProfileOut( __METHOD__
);
1289 static $autocommentTitle;
1290 static $autocommentLocal;
1293 * Converts autogenerated comments in edit summaries into section links.
1294 * The pattern for autogen comments is / * foo * /, which makes for
1296 * We look for all comments, match any text before and after the comment,
1297 * add a separator where needed and format the comment itself with CSS
1298 * Called by Linker::formatComment.
1300 * @param string $comment Comment text
1301 * @param Title|null $title An optional title object used to links to sections
1302 * @param bool $local Whether section links should refer to local page
1303 * @return string Formatted comment
1305 private static function formatAutocomments( $comment, $title = null, $local = false ) {
1307 self
::$autocommentTitle = $title;
1308 self
::$autocommentLocal = $local;
1309 $comment = preg_replace_callback(
1310 '!(.*)/\*\s*(.*?)\s*\*/(.*)!',
1311 array( 'Linker', 'formatAutocommentsCallback' ),
1313 self
::$autocommentTitle = null;
1314 self
::$autocommentLocal = null;
1319 * Helper function for Linker::formatAutocomments
1323 private static function formatAutocommentsCallback( $match ) {
1325 $title = self
::$autocommentTitle;
1326 $local = self
::$autocommentLocal;
1332 wfRunHooks( 'FormatAutocomments', array( &$comment, $pre, $auto, $post, $title, $local ) );
1333 if ( $comment === null ) {
1338 # Remove links that a user may have manually put in the autosummary
1339 # This could be improved by copying as much of Parser::stripSectionName as desired.
1340 $section = str_replace( '[[:', '', $section );
1341 $section = str_replace( '[[', '', $section );
1342 $section = str_replace( ']]', '', $section );
1344 $section = Sanitizer
::normalizeSectionNameWhitespace( $section ); # bug 22784
1346 $sectionTitle = Title
::newFromText( '#' . $section );
1348 $sectionTitle = Title
::makeTitleSafe( $title->getNamespace(),
1349 $title->getDBkey(), $section );
1351 if ( $sectionTitle ) {
1352 $link = self
::link( $sectionTitle,
1353 $wgLang->getArrow(), array(), array(),
1360 # written summary $presep autocomment (summary /* section */)
1361 $pre .= wfMessage( 'autocomment-prefix' )->inContentLanguage()->escaped();
1364 # autocomment $postsep written summary (/* section */ summary)
1365 $auto .= wfMessage( 'colon-separator' )->inContentLanguage()->escaped();
1367 $auto = '<span class="autocomment">' . $auto . '</span>';
1368 $comment = $pre . $link . $wgLang->getDirMark() . '<span dir="auto">' . $auto . $post . '</span>';
1376 static $commentContextTitle;
1377 static $commentLocal;
1380 * Formats wiki links and media links in text; all other wiki formatting
1383 * @todo FIXME: Doesn't handle sub-links as in image thumb texts like the main parser
1384 * @param string $comment Text to format links in
1385 * @param Title|null $title An optional title object used to links to sections
1386 * @param bool $local Whether section links should refer to local page
1389 public static function formatLinksInComment( $comment, $title = null, $local = false ) {
1390 self
::$commentContextTitle = $title;
1391 self
::$commentLocal = $local;
1392 $html = preg_replace_callback(
1395 :? # ignore optional leading colon
1396 ([^\]|]+) # 1. link target; page names cannot include ] or |
1398 # 2. a pipe-separated substring; only the last is captured
1399 # Stop matching at | and ]] without relying on backtracking.
1403 ([^[]*) # 3. link trail (the text up until the next link)
1405 array( 'Linker', 'formatLinksInCommentCallback' ),
1407 self
::$commentContextTitle = null;
1408 self
::$commentLocal = null;
1416 protected static function formatLinksInCommentCallback( $match ) {
1419 $medians = '(?:' . preg_quote( MWNamespace
::getCanonicalName( NS_MEDIA
), '/' ) . '|';
1420 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA
), '/' ) . '):';
1422 $comment = $match[0];
1424 # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
1425 if ( strpos( $match[1], '%' ) !== false ) {
1426 $match[1] = str_replace( array( '<', '>' ), array( '<', '>' ), rawurldecode( $match[1] ) );
1429 # Handle link renaming [[foo|text]] will show link as "text"
1430 if ( $match[2] != "" ) {
1435 $submatch = array();
1437 if ( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1438 # Media link; trail not supported.
1439 $linkRegexp = '/\[\[(.*?)\]\]/';
1440 $title = Title
::makeTitleSafe( NS_FILE
, $submatch[1] );
1442 $thelink = self
::makeMediaLinkObj( $title, $text );
1445 # Other kind of link
1446 if ( preg_match( $wgContLang->linkTrail(), $match[3], $submatch ) ) {
1447 $trail = $submatch[1];
1451 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1452 if ( isset( $match[1][0] ) && $match[1][0] == ':' ) {
1453 $match[1] = substr( $match[1], 1 );
1455 list( $inside, $trail ) = self
::splitTrail( $trail );
1458 $linkTarget = self
::normalizeSubpageLink( self
::$commentContextTitle,
1459 $match[1], $linkText );
1461 $target = Title
::newFromText( $linkTarget );
1463 if ( $target->getText() == '' && !$target->isExternal()
1464 && !self
::$commentLocal && self
::$commentContextTitle
1466 $newTarget = clone ( self
::$commentContextTitle );
1467 $newTarget->setFragment( '#' . $target->getFragment() );
1468 $target = $newTarget;
1470 $thelink = self
::link(
1477 // If the link is still valid, go ahead and replace it in!
1478 $comment = preg_replace( $linkRegexp, StringUtils
::escapeRegexReplacement( $thelink ), $comment, 1 );
1485 * @param $contextTitle Title
1490 public static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
1493 # :Foobar -- override special treatment of prefix (images, language links)
1494 # /Foobar -- convert to CurrentPage/Foobar
1495 # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text
1496 # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1497 # ../Foobar -- convert to CurrentPage/Foobar, from CurrentPage/CurrentSubPage
1499 wfProfileIn( __METHOD__
);
1500 $ret = $target; # default return value is no change
1502 # Some namespaces don't allow subpages,
1503 # so only perform processing if subpages are allowed
1504 if ( $contextTitle && MWNamespace
::hasSubpages( $contextTitle->getNamespace() ) ) {
1505 $hash = strpos( $target, '#' );
1506 if ( $hash !== false ) {
1507 $suffix = substr( $target, $hash );
1508 $target = substr( $target, 0, $hash );
1513 $target = trim( $target );
1514 # Look at the first character
1515 if ( $target != '' && $target[0] === '/' ) {
1516 # / at end means we don't want the slash to be shown
1518 $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
1519 if ( $trailingSlashes ) {
1520 $noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
1522 $noslash = substr( $target, 1 );
1525 $ret = $contextTitle->getPrefixedText() . '/' . trim( $noslash ) . $suffix;
1526 if ( $text === '' ) {
1527 $text = $target . $suffix;
1528 } # this might be changed for ugliness reasons
1530 # check for .. subpage backlinks
1532 $nodotdot = $target;
1533 while ( strncmp( $nodotdot, "../", 3 ) == 0 ) {
1535 $nodotdot = substr( $nodotdot, 3 );
1537 if ( $dotdotcount > 0 ) {
1538 $exploded = explode( '/', $contextTitle->getPrefixedText() );
1539 if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1540 $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
1541 # / at the end means don't show full path
1542 if ( substr( $nodotdot, -1, 1 ) === '/' ) {
1543 $nodotdot = substr( $nodotdot, 0, -1 );
1544 if ( $text === '' ) {
1545 $text = $nodotdot . $suffix;
1548 $nodotdot = trim( $nodotdot );
1549 if ( $nodotdot != '' ) {
1550 $ret .= '/' . $nodotdot;
1558 wfProfileOut( __METHOD__
);
1563 * Wrap a comment in standard punctuation and formatting if
1564 * it's non-empty, otherwise return empty string.
1566 * @param string $comment
1567 * @param Title|null $title Title object (to generate link to section in autocomment) or null
1568 * @param bool $local Whether section links should refer to local page
1572 public static function commentBlock( $comment, $title = null, $local = false ) {
1573 // '*' used to be the comment inserted by the software way back
1574 // in antiquity in case none was provided, here for backwards
1575 // compatibility, acc. to brion -ævar
1576 if ( $comment == '' ||
$comment == '*' ) {
1579 $formatted = self
::formatComment( $comment, $title, $local );
1580 $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped();
1581 return " <span class=\"comment\">$formatted</span>";
1586 * Wrap and format the given revision's comment block, if the current
1587 * user is allowed to view it.
1589 * @param Revision $rev
1590 * @param bool $local Whether section links should refer to local page
1591 * @param bool $isPublic Show only if all users can see it
1592 * @return string HTML fragment
1594 public static function revComment( Revision
$rev, $local = false, $isPublic = false ) {
1595 if ( $rev->getRawComment() == "" ) {
1598 if ( $rev->isDeleted( Revision
::DELETED_COMMENT
) && $isPublic ) {
1599 $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>";
1600 } elseif ( $rev->userCan( Revision
::DELETED_COMMENT
) ) {
1601 $block = self
::commentBlock( $rev->getComment( Revision
::FOR_THIS_USER
),
1602 $rev->getTitle(), $local );
1604 $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>";
1606 if ( $rev->isDeleted( Revision
::DELETED_COMMENT
) ) {
1607 return " <span class=\"history-deleted\">$block</span>";
1616 public static function formatRevisionSize( $size ) {
1618 $stxt = wfMessage( 'historyempty' )->escaped();
1620 $stxt = wfMessage( 'nbytes' )->numParams( $size )->escaped();
1621 $stxt = wfMessage( 'parentheses' )->rawParams( $stxt )->escaped();
1623 return "<span class=\"history-size\">$stxt</span>";
1627 * Add another level to the Table of Contents
1631 public static function tocIndent() {
1636 * Finish one or more sublevels on the Table of Contents
1640 public static function tocUnindent( $level ) {
1641 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level > 0 ?
$level : 0 );
1645 * parameter level defines if we are on an indentation level
1649 public static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
1650 $classes = "toclevel-$level";
1651 if ( $sectionIndex !== false ) {
1652 $classes .= " tocsection-$sectionIndex";
1654 return "\n<li class=\"$classes\"><a href=\"#" .
1655 $anchor . '"><span class="tocnumber">' .
1656 $tocnumber . '</span> <span class="toctext">' .
1657 $tocline . '</span></a>';
1661 * End a Table Of Contents line.
1662 * tocUnindent() will be used instead if we're ending a line below
1666 public static function tocLineEnd() {
1671 * Wraps the TOC in a table and provides the hide/collapse javascript.
1673 * @param string $toc Html of the Table Of Contents
1674 * @param string|Language|false $lang Language for the toc title, defaults to user language
1675 * @return string Full html of the TOC
1677 public static function tocList( $toc, $lang = false ) {
1678 $lang = wfGetLangObj( $lang );
1679 $title = wfMessage( 'toc' )->inLanguage( $lang )->escaped();
1681 return '<div id="toc" class="toc">'
1682 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
1684 . "</ul>\n</div>\n";
1688 * Generate a table of contents from a section tree
1691 * @param array $tree Return value of ParserOutput::getSections()
1692 * @return string HTML fragment
1694 public static function generateTOC( $tree ) {
1697 foreach ( $tree as $section ) {
1698 if ( $section['toclevel'] > $lastLevel ) {
1699 $toc .= self
::tocIndent();
1700 } elseif ( $section['toclevel'] < $lastLevel ) {
1701 $toc .= self
::tocUnindent(
1702 $lastLevel - $section['toclevel'] );
1704 $toc .= self
::tocLineEnd();
1707 $toc .= self
::tocLine( $section['anchor'],
1708 $section['line'], $section['number'],
1709 $section['toclevel'], $section['index'] );
1710 $lastLevel = $section['toclevel'];
1712 $toc .= self
::tocLineEnd();
1713 return self
::tocList( $toc );
1717 * Create a headline for content
1719 * @param int $level The level of the headline (1-6)
1720 * @param string $attribs Any attributes for the headline, starting with
1721 * a space and ending with '>'
1722 * This *must* be at least '>' for no attribs
1723 * @param string $anchor the anchor to give the headline (the bit after the #)
1724 * @param string $html html for the text of the header
1725 * @param string $link HTML to add for the section edit link
1726 * @param bool|string $legacyAnchor a second, optional anchor to give for
1727 * backward compatibility (false to omit)
1729 * @return string HTML headline
1731 public static function makeHeadline( $level, $attribs, $anchor, $html, $link, $legacyAnchor = false ) {
1732 $ret = "<h$level$attribs"
1733 . "<span class=\"mw-headline\" id=\"$anchor\">$html</span>"
1736 if ( $legacyAnchor !== false ) {
1737 $ret = "<div id=\"$legacyAnchor\"></div>$ret";
1743 * Split a link trail, return the "inside" portion and the remainder of the trail
1744 * as a two-element array
1747 static function splitTrail( $trail ) {
1749 $regex = $wgContLang->linkTrail();
1751 if ( $trail !== '' ) {
1753 if ( preg_match( $regex, $trail, $m ) ) {
1758 return array( $inside, $trail );
1762 * Generate a rollback link for a given revision. Currently it's the
1763 * caller's responsibility to ensure that the revision is the top one. If
1764 * it's not, of course, the user will get an error message.
1766 * If the calling page is called with the parameter &bot=1, all rollback
1767 * links also get that parameter. It causes the edit itself and the rollback
1768 * to be marked as "bot" edits. Bot edits are hidden by default from recent
1769 * changes, so this allows sysops to combat a busy vandal without bothering
1772 * If the option verify is set this function will return the link only in case the
1773 * revision can be reverted. Please note that due to performance limitations
1774 * it might be assumed that a user isn't the only contributor of a page while
1775 * (s)he is, which will lead to useless rollback links. Furthermore this wont
1776 * work if $wgShowRollbackEditCount is disabled, so this can only function
1777 * as an additional check.
1779 * If the option noBrackets is set the rollback link wont be enclosed in []
1781 * @param $rev Revision object
1782 * @param $context IContextSource context to use or null for the main context.
1783 * @param $options array
1786 public static function generateRollback( $rev, IContextSource
$context = null, $options = array( 'verify' ) ) {
1787 if ( $context === null ) {
1788 $context = RequestContext
::getMain();
1791 if ( in_array( 'verify', $options ) ) {
1792 $editCount = self
::getRollbackEditCount( $rev, true );
1793 if ( $editCount === false ) {
1798 $inner = self
::buildRollbackLink( $rev, $context, $editCount );
1800 if ( !in_array( 'noBrackets', $options ) ) {
1801 $inner = $context->msg( 'brackets' )->rawParams( $inner )->plain();
1804 return '<span class="mw-rollback-link">' . $inner . '</span>';
1808 * This function will return the number of revisions which a rollback
1809 * would revert and, if $verify is set it will verify that a revision
1810 * can be reverted (that the user isn't the only contributor and the
1811 * revision we might rollback to isn't deleted). These checks can only
1812 * function as an additional check as this function only checks against
1813 * the last $wgShowRollbackEditCount edits.
1815 * Returns null if $wgShowRollbackEditCount is disabled or false if $verify
1816 * is set and the user is the only contributor of the page.
1818 * @param $rev Revision object
1819 * @param bool $verify Try to verify that this revision can really be rolled back
1820 * @return integer|bool|null
1822 public static function getRollbackEditCount( $rev, $verify ) {
1823 global $wgShowRollbackEditCount;
1824 if ( !is_int( $wgShowRollbackEditCount ) ||
!$wgShowRollbackEditCount > 0 ) {
1825 // Nothing has happened, indicate this by returning 'null'
1829 $dbr = wfGetDB( DB_SLAVE
);
1831 // Up to the value of $wgShowRollbackEditCount revisions are counted
1832 $res = $dbr->select(
1834 array( 'rev_user_text', 'rev_deleted' ),
1835 // $rev->getPage() returns null sometimes
1836 array( 'rev_page' => $rev->getTitle()->getArticleID() ),
1839 'USE INDEX' => array( 'revision' => 'page_timestamp' ),
1840 'ORDER BY' => 'rev_timestamp DESC',
1841 'LIMIT' => $wgShowRollbackEditCount +
1
1847 foreach ( $res as $row ) {
1848 if ( $rev->getRawUserText() != $row->rev_user_text
) {
1849 if ( $verify && ( $row->rev_deleted
& Revision
::DELETED_TEXT ||
$row->rev_deleted
& Revision
::DELETED_USER
) ) {
1850 // If the user or the text of the revision we might rollback to is deleted in some way we can't rollback
1851 // Similar to the sanity checks in WikiPage::commitRollback
1860 if ( $verify && $editCount <= $wgShowRollbackEditCount && !$moreRevs ) {
1861 // We didn't find at least $wgShowRollbackEditCount revisions made by the current user
1862 // and there weren't any other revisions. That means that the current user is the only
1863 // editor, so we can't rollback
1870 * Build a raw rollback link, useful for collections of "tool" links
1872 * @param Revision $rev
1873 * @param IContextSource|null $context Context to use or null for the main context.
1874 * @param int $editCount Number of edits that would be reverted
1875 * @return string HTML fragment
1877 public static function buildRollbackLink( $rev, IContextSource
$context = null, $editCount = false ) {
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( $title->getPrefixedText(), $rev->getUserText() ) ),
1893 if ( $context->getRequest()->getBool( 'bot' ) ) {
1894 $query['bot'] = '1';
1895 $query['hidediff'] = '1'; // bug 15999
1898 $disableRollbackEditCount = false;
1899 if ( $wgMiserMode ) {
1900 foreach ( $disableRollbackEditCountSpecialPage as $specialPage ) {
1901 if ( $context->getTitle()->isSpecial( $specialPage ) ) {
1902 $disableRollbackEditCount = true;
1908 if ( !$disableRollbackEditCount && is_int( $wgShowRollbackEditCount ) && $wgShowRollbackEditCount > 0 ) {
1909 if ( !is_numeric( $editCount ) ) {
1910 $editCount = self
::getRollbackEditCount( $rev, false );
1913 if ( $editCount > $wgShowRollbackEditCount ) {
1914 $editCount_output = $context->msg( 'rollbacklinkcount-morethan' )->numParams( $wgShowRollbackEditCount )->parse();
1916 $editCount_output = $context->msg( 'rollbacklinkcount' )->numParams( $editCount )->parse();
1922 array( 'title' => $context->msg( 'tooltip-rollback' )->text() ),
1924 array( 'known', 'noclasses' )
1929 $context->msg( 'rollbacklink' )->escaped(),
1930 array( 'title' => $context->msg( 'tooltip-rollback' )->text() ),
1932 array( 'known', 'noclasses' )
1938 * Returns HTML for the "templates used on this page" list.
1940 * Make an HTML list of templates, and then add a "More..." link at
1941 * the bottom. If $more is null, do not add a "More..." link. If $more
1942 * is a Title, make a link to that title and use it. If $more is a string,
1943 * directly paste it in as the link (escaping needs to be done manually).
1944 * Finally, if $more is a Message, call toString().
1946 * @param array $templates Array of templates from Article::getUsedTemplate or similar
1947 * @param bool $preview Whether this is for a preview
1948 * @param bool $section Whether this is for a section edit
1949 * @param Title|Message|string|null $more An escaped link for "More..." of the templates
1950 * @return string HTML output
1952 public static function formatTemplates( $templates, $preview = false, $section = false, $more = null ) {
1954 wfProfileIn( __METHOD__
);
1957 if ( count( $templates ) > 0 ) {
1958 # Do a batch existence check
1959 $batch = new LinkBatch
;
1960 foreach ( $templates as $title ) {
1961 $batch->addObj( $title );
1965 # Construct the HTML
1966 $outText = '<div class="mw-templatesUsedExplanation">';
1968 $outText .= wfMessage( 'templatesusedpreview' )->numParams( count( $templates ) )
1970 } elseif ( $section ) {
1971 $outText .= wfMessage( 'templatesusedsection' )->numParams( count( $templates ) )
1974 $outText .= wfMessage( 'templatesused' )->numParams( count( $templates ) )
1977 $outText .= "</div><ul>\n";
1979 usort( $templates, 'Title::compare' );
1980 foreach ( $templates as $titleObj ) {
1982 $restrictions = $titleObj->getRestrictions( 'edit' );
1983 if ( $restrictions ) {
1984 // Check backwards-compatible messages
1986 if ( $restrictions === array( 'sysop' ) ) {
1987 $msg = wfMessage( 'template-protected' );
1988 } elseif ( $restrictions === array( 'autoconfirmed' ) ) {
1989 $msg = wfMessage( 'template-semiprotected' );
1991 if ( $msg && !$msg->isDisabled() ) {
1992 $protected = $msg->parse();
1994 // Construct the message from restriction-level-*
1995 // e.g. restriction-level-sysop, restriction-level-autoconfirmed
1997 foreach ( $restrictions as $r ) {
1998 $msgs[] = wfMessage( "restriction-level-$r" )->parse();
2000 $protected = wfMessage( 'parentheses' )
2001 ->rawParams( $wgLang->commaList( $msgs ) )->escaped();
2004 if ( $titleObj->quickUserCan( 'edit' ) ) {
2005 $editLink = self
::link(
2007 wfMessage( 'editlink' )->text(),
2009 array( 'action' => 'edit' )
2012 $editLink = self
::link(
2014 wfMessage( 'viewsourcelink' )->text(),
2016 array( 'action' => 'edit' )
2019 $outText .= '<li>' . self
::link( $titleObj )
2020 . wfMessage( 'word-separator' )->escaped()
2021 . wfMessage( 'parentheses' )->rawParams( $editLink )->escaped()
2022 . wfMessage( 'word-separator' )->escaped()
2023 . $protected . '</li>';
2026 if ( $more instanceof Title
) {
2027 $outText .= '<li>' . self
::link( $more, wfMessage( 'moredotdotdot' ) ) . '</li>';
2028 } elseif ( $more ) {
2029 $outText .= "<li>$more</li>";
2032 $outText .= '</ul>';
2034 wfProfileOut( __METHOD__
);
2039 * Returns HTML for the "hidden categories on this page" list.
2041 * @param array $hiddencats Array of hidden categories from Article::getHiddenCategories
2043 * @return String HTML output
2045 public static function formatHiddenCategories( $hiddencats ) {
2046 wfProfileIn( __METHOD__
);
2049 if ( count( $hiddencats ) > 0 ) {
2050 # Construct the HTML
2051 $outText = '<div class="mw-hiddenCategoriesExplanation">';
2052 $outText .= wfMessage( 'hiddencategories' )->numParams( count( $hiddencats ) )->parseAsBlock();
2053 $outText .= "</div><ul>\n";
2055 foreach ( $hiddencats as $titleObj ) {
2056 $outText .= '<li>' . self
::link( $titleObj, null, array(), array(), 'known' ) . "</li>\n"; # If it's hidden, it must exist - no need to check with a LinkBatch
2058 $outText .= '</ul>';
2060 wfProfileOut( __METHOD__
);
2065 * Format a size in bytes for output, using an appropriate
2066 * unit (B, KB, MB or GB) according to the magnitude in question
2068 * @param int $size Size to format
2071 public static function formatSize( $size ) {
2073 return htmlspecialchars( $wgLang->formatSize( $size ) );
2077 * Given the id of an interface element, constructs the appropriate title
2078 * attribute from the system messages. (Note, this is usually the id but
2079 * isn't always, because sometimes the accesskey needs to go on a different
2080 * element than the id, for reverse-compatibility, etc.)
2082 * @param string $name Id of the element, minus prefixes.
2083 * @param string|null $options null or the string 'withaccess' to add an access-
2085 * @return string Contents of the title attribute (which you must HTML-
2086 * escape), or false for no title attribute
2088 public static function titleAttrib( $name, $options = null ) {
2089 wfProfileIn( __METHOD__
);
2091 $message = wfMessage( "tooltip-$name" );
2093 if ( !$message->exists() ) {
2096 $tooltip = $message->text();
2097 # Compatibility: formerly some tooltips had [alt-.] hardcoded
2098 $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
2099 # Message equal to '-' means suppress it.
2100 if ( $tooltip == '-' ) {
2105 if ( $options == 'withaccess' ) {
2106 $accesskey = self
::accesskey( $name );
2107 if ( $accesskey !== false ) {
2108 if ( $tooltip === false ||
$tooltip === '' ) {
2109 $tooltip = wfMessage( 'brackets', $accesskey )->escaped();
2111 $tooltip .= wfMessage( 'word-separator' )->escaped();
2112 $tooltip .= wfMessage( 'brackets', $accesskey )->escaped();
2117 wfProfileOut( __METHOD__
);
2121 static $accesskeycache;
2124 * Given the id of an interface element, constructs the appropriate
2125 * accesskey attribute from the system messages. (Note, this is usually
2126 * the id but isn't always, because sometimes the accesskey needs to go on
2127 * a different element than the id, for reverse-compatibility, etc.)
2129 * @param string $name Id of the element, minus prefixes.
2130 * @return string Contents of the accesskey attribute (which you must HTML-
2131 * escape), or false for no accesskey attribute
2133 public static function accesskey( $name ) {
2134 if ( isset( self
::$accesskeycache[$name] ) ) {
2135 return self
::$accesskeycache[$name];
2137 wfProfileIn( __METHOD__
);
2139 $message = wfMessage( "accesskey-$name" );
2141 if ( !$message->exists() ) {
2144 $accesskey = $message->plain();
2145 if ( $accesskey === '' ||
$accesskey === '-' ) {
2146 # @todo FIXME: Per standard MW behavior, a value of '-' means to suppress the
2147 # attribute, but this is broken for accesskey: that might be a useful
2153 wfProfileOut( __METHOD__
);
2154 self
::$accesskeycache[$name] = $accesskey;
2155 return self
::$accesskeycache[$name];
2159 * Get a revision-deletion link, or disabled link, or nothing, depending
2160 * on user permissions & the settings on the revision.
2162 * Will use forward-compatible revision ID in the Special:RevDelete link
2163 * if possible, otherwise the timestamp-based ID which may break after
2167 * @param Revision $rev
2168 * @param Revision $title
2169 * @return string HTML fragment
2171 public static function getRevDeleteLink( User
$user, Revision
$rev, Title
$title ) {
2172 $canHide = $user->isAllowed( 'deleterevision' );
2173 if ( !$canHide && !( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) ) {
2177 if ( !$rev->userCan( Revision
::DELETED_RESTRICTED
, $user ) ) {
2178 return Linker
::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
2180 if ( $rev->getId() ) {
2181 // RevDelete links using revision ID are stable across
2182 // page deletion and undeletion; use when possible.
2184 'type' => 'revision',
2185 'target' => $title->getPrefixedDBkey(),
2186 'ids' => $rev->getId()
2189 // Older deleted entries didn't save a revision ID.
2190 // We have to refer to these by timestamp, ick!
2192 'type' => 'archive',
2193 'target' => $title->getPrefixedDBkey(),
2194 'ids' => $rev->getTimestamp()
2197 return Linker
::revDeleteLink( $query,
2198 $rev->isDeleted( Revision
::DELETED_RESTRICTED
), $canHide );
2203 * Creates a (show/hide) link for deleting revisions/log entries
2205 * @param array $query Query parameters to be passed to link()
2206 * @param bool $restricted Set to true to use a "<strong>" instead of a "<span>"
2207 * @param bool $delete Set to true to use (show/hide) rather than (show)
2209 * @return string HTML "<a>" link to Special:Revisiondelete, wrapped in a
2210 * span to allow for customization of appearance with CSS
2212 public static function revDeleteLink( $query = array(), $restricted = false, $delete = true ) {
2213 $sp = SpecialPage
::getTitleFor( 'Revisiondelete' );
2214 $msgKey = $delete ?
'rev-delundel' : 'rev-showdeleted';
2215 $html = wfMessage( $msgKey )->escaped();
2216 $tag = $restricted ?
'strong' : 'span';
2217 $link = self
::link( $sp, $html, array(), $query, array( 'known', 'noclasses' ) );
2218 return Xml
::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), wfMessage( 'parentheses' )->rawParams( $link )->escaped() );
2222 * Creates a dead (show/hide) link for deleting revisions/log entries
2224 * @param bool $delete Set to true to use (show/hide) rather than (show)
2226 * @return string HTML text wrapped in a span to allow for customization
2227 * of appearance with CSS
2229 public static function revDeleteLinkDisabled( $delete = true ) {
2230 $msgKey = $delete ?
'rev-delundel' : 'rev-showdeleted';
2231 $html = wfMessage( $msgKey )->escaped();
2232 $htmlParentheses = wfMessage( 'parentheses' )->rawParams( $html )->escaped();
2233 return Xml
::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), $htmlParentheses );
2236 /* Deprecated methods */
2239 * @deprecated since 1.16 Use link(); warnings since 1.21
2241 * Make a link for a title which may or may not be in the database. If you need to
2242 * call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
2243 * call to this will result in a DB query.
2245 * @param Title $nt The title object to make the link from, e.g. from Title::newFromText.
2246 * @param string $text Link text
2247 * @param string $query optional query part
2248 * @param string $trail optional trail. Alphabetic characters at the start of this string will
2249 * be included in the link text. Other characters will be appended after
2250 * the end of the link.
2251 * @param string $prefix optional prefix. As trail, only before instead of after.
2254 static function makeLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
2255 wfDeprecated( __METHOD__
, '1.21' );
2257 wfProfileIn( __METHOD__
);
2258 $query = wfCgiToArray( $query );
2259 list( $inside, $trail ) = self
::splitTrail( $trail );
2260 if ( $text === '' ) {
2261 $text = self
::linkText( $nt );
2264 $ret = self
::link( $nt, "$prefix$text$inside", array(), $query ) . $trail;
2266 wfProfileOut( __METHOD__
);
2271 * @deprecated since 1.16 Use link(); warnings since 1.21
2273 * Make a link for a title which definitely exists. This is faster than makeLinkObj because
2274 * it doesn't have to do a database query. It's also valid for interwiki titles and special
2277 * @param Title $title Title object of target page
2278 * @param string $text Text to replace the title
2279 * @param string $query Link target
2280 * @param string $trail Text after link
2281 * @param string $prefix Text before link text
2282 * @param string $aprops Extra attributes to the a-element
2283 * @param string $style Style to apply - if empty, use getInternalLinkAttributesObj instead
2284 * @return string The a-element
2286 static function makeKnownLinkObj(
2287 $title, $text = '', $query = '', $trail = '', $prefix = '', $aprops = '', $style = ''
2289 wfDeprecated( __METHOD__
, '1.21' );
2291 wfProfileIn( __METHOD__
);
2293 if ( $text == '' ) {
2294 $text = self
::linkText( $title );
2296 $attribs = Sanitizer
::mergeAttributes(
2297 Sanitizer
::decodeTagAttributes( $aprops ),
2298 Sanitizer
::decodeTagAttributes( $style )
2300 $query = wfCgiToArray( $query );
2301 list( $inside, $trail ) = self
::splitTrail( $trail );
2303 $ret = self
::link( $title, "$prefix$text$inside", $attribs, $query,
2304 array( 'known', 'noclasses' ) ) . $trail;
2306 wfProfileOut( __METHOD__
);
2311 * Returns the attributes for the tooltip and access key.
2314 public static function tooltipAndAccesskeyAttribs( $name ) {
2315 # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
2316 # no attribute" instead of "output '' as value for attribute", this
2317 # would be three lines.
2319 'title' => self
::titleAttrib( $name, 'withaccess' ),
2320 'accesskey' => self
::accesskey( $name )
2322 if ( $attribs['title'] === false ) {
2323 unset( $attribs['title'] );
2325 if ( $attribs['accesskey'] === false ) {
2326 unset( $attribs['accesskey'] );
2332 * Returns raw bits of HTML, use titleAttrib()
2333 * @return null|string
2335 public static function tooltip( $name, $options = null ) {
2336 # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
2337 # no attribute" instead of "output '' as value for attribute", this
2338 # would be two lines.
2339 $tooltip = self
::titleAttrib( $name, $options );
2340 if ( $tooltip === false ) {
2343 return Xml
::expandAttributes( array(
2355 * Use PHP's magic __call handler to transform instance calls to a dummy instance
2356 * into static calls to the new Linker for backwards compatibility.
2358 * @param string $fname Name of called method
2359 * @param array $args Arguments to the method
2362 public function __call( $fname, $args ) {
2363 return call_user_func_array( array( 'Linker', $fname ), $args );