3 * Methods to make links and related items.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Some internal bits split of from Skin.php. These functions are used
25 * for primarily page content: links, embedded images, table of contents. Links
26 * are also used in the skin.
28 * @todo turn this into a legacy interface for HtmlPageLinkRenderer and similar services.
34 * Flags for userToolLinks()
36 const TOOL_LINKS_NOBLOCK
= 1;
37 const TOOL_LINKS_EMAIL
= 2;
40 * Get the appropriate HTML attributes to add to the "a" element of an interwiki link.
42 * @deprecated since 1.25
44 * @param string $title The title text for the link, URL-encoded (???) but
46 * @param string $unused Unused
47 * @param string $class The contents of the class attribute; if an empty
48 * string is passed, which is the default value, defaults to 'external'.
51 static function getInterwikiLinkAttributes( $title, $unused = null, $class = 'external' ) {
54 wfDeprecated( __METHOD__
, '1.25' );
56 # @todo FIXME: We have a whole bunch of handling here that doesn't happen in
57 # getExternalLinkAttributes, why?
58 $title = urldecode( $title );
59 $title = $wgContLang->checkTitleEncoding( $title );
60 $title = preg_replace( '/[\\x00-\\x1f]/', ' ', $title );
62 return self
::getLinkAttributesInternal( $title, $class );
66 * Get the appropriate HTML attributes to add to the "a" element of an internal link.
68 * @deprecated since 1.25
70 * @param string $title The title text for the link, URL-encoded (???) but
72 * @param string $unused Unused
73 * @param string $class The contents of the class attribute, default none
76 static function getInternalLinkAttributes( $title, $unused = null, $class = '' ) {
77 wfDeprecated( __METHOD__
, '1.25' );
79 $title = urldecode( $title );
80 $title = strtr( $title, '_', ' ' );
81 return self
::getLinkAttributesInternal( $title, $class );
85 * Get the appropriate HTML attributes to add to the "a" element of an internal
86 * link, given the Title object for the page we want to link to.
88 * @deprecated since 1.25
91 * @param string $unused Unused
92 * @param string $class The contents of the class attribute, default none
93 * @param string|bool $title Optional (unescaped) string to use in the title
94 * attribute; if false, default to the name of the page we're linking to
97 static function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) {
98 wfDeprecated( __METHOD__
, '1.25' );
100 if ( $title === false ) {
101 $title = $nt->getPrefixedText();
103 return self
::getLinkAttributesInternal( $title, $class );
107 * Common code for getLinkAttributesX functions
109 * @deprecated since 1.25
111 * @param string $title
112 * @param string $class
116 private static function getLinkAttributesInternal( $title, $class ) {
117 wfDeprecated( __METHOD__
, '1.25' );
119 $title = htmlspecialchars( $title );
120 $class = htmlspecialchars( $class );
122 if ( $class != '' ) {
123 $r .= " class=\"$class\"";
125 if ( $title != '' ) {
126 $r .= " title=\"$title\"";
132 * Return the CSS colour of a known link
135 * @param int $threshold User defined threshold
136 * @return string CSS class
138 public static function getLinkColour( $t, $threshold ) {
140 if ( $t->isRedirect() ) {
142 $colour = 'mw-redirect';
143 } elseif ( $threshold > 0 && $t->isContentPage() &&
144 $t->exists() && $t->getLength() < $threshold
153 * This function returns an HTML link to the given target. It serves a few
155 * 1) If $target is a Title, the correct URL to link to will be figured
157 * 2) It automatically adds the usual classes for various types of link
158 * targets: "new" for red links, "stub" for short articles, etc.
159 * 3) It escapes all attribute values safely so there's no risk of XSS.
160 * 4) It provides a default tooltip if the target is a Title (the page
161 * name of the target).
162 * link() replaces the old functions in the makeLink() family.
164 * @since 1.18 Method exists since 1.16 as non-static, made static in 1.18.
166 * @param Title $target Can currently only be a Title, but this may
167 * change to support Images, literal URLs, etc.
168 * @param string $html The HTML contents of the <a> element, i.e.,
169 * the link text. This is raw HTML and will not be escaped. If null,
170 * defaults to the prefixed text of the Title; or if the Title is just a
171 * fragment, the contents of the fragment.
172 * @param array $customAttribs A key => value array of extra HTML attributes,
173 * such as title and class. (href is ignored.) Classes will be
174 * merged with the default classes, while other attributes will replace
175 * default attributes. All passed attribute values will be HTML-escaped.
176 * A false attribute value means to suppress that attribute.
177 * @param array $query The query string to append to the URL
178 * you're linking to, in key => value array form. Query keys and values
179 * will be URL-encoded.
180 * @param string|array $options String or array of strings:
181 * 'known': Page is known to exist, so don't check if it does.
182 * 'broken': Page is known not to exist, so don't check if it does.
183 * 'noclasses': Don't add any classes automatically (includes "new",
184 * "stub", "mw-redirect", "extiw"). Only use the class attribute
185 * provided, if any, so you get a simple blue link with no funny i-
187 * 'forcearticlepath': Use the article path always, even with a querystring.
188 * Has compatibility issues on some setups, so avoid wherever possible.
189 * 'http': Force a full URL with http:// as the scheme.
190 * 'https': Force a full URL with https:// as the scheme.
191 * 'stubThreshold' => (int): Stub threshold to use when determining link classes.
192 * @return string HTML <a> attribute
194 public static function link(
195 $target, $html = null, $customAttribs = array(), $query = array(), $options = array()
197 if ( !$target instanceof Title
) {
198 wfWarn( __METHOD__
. ': Requires $target to be a Title object.', 2 );
199 return "<!-- ERROR -->$html";
202 if ( is_string( $query ) ) {
203 // some functions withing core using this still hand over query strings
204 wfDeprecated( __METHOD__
. ' with parameter $query as string (should be array)', '1.20' );
205 $query = wfCgiToArray( $query );
207 $options = (array)$options;
209 $dummy = new DummyLinker
; // dummy linker instance for bc on the hooks
212 if ( !Hooks
::run( 'LinkBegin',
213 array( $dummy, $target, &$html, &$customAttribs, &$query, &$options, &$ret ) )
218 # Normalize the Title if it's a special page
219 $target = self
::normaliseSpecialPage( $target );
221 # If we don't know whether the page exists, let's find out.
222 if ( !in_array( 'known', $options, true ) && !in_array( 'broken', $options, true ) ) {
223 if ( $target->isKnown() ) {
224 $options[] = 'known';
226 $options[] = 'broken';
231 if ( in_array( "forcearticlepath", $options, true ) && $query ) {
236 # Note: we want the href attribute first, for prettiness.
237 $attribs = array( 'href' => self
::linkUrl( $target, $query, $options ) );
238 if ( in_array( 'forcearticlepath', $options, true ) && $oldquery ) {
239 $attribs['href'] = wfAppendQuery( $attribs['href'], $oldquery );
242 $attribs = array_merge(
244 self
::linkAttribs( $target, $customAttribs, $options )
246 if ( is_null( $html ) ) {
247 $html = self
::linkText( $target );
251 if ( Hooks
::run( 'LinkEnd', array( $dummy, $target, $options, &$html, &$attribs, &$ret ) ) ) {
252 $ret = Html
::rawElement( 'a', $attribs, $html );
259 * Identical to link(), except $options defaults to 'known'.
263 public static function linkKnown(
264 $target, $html = null, $customAttribs = array(),
265 $query = array(), $options = array( 'known', 'noclasses' )
267 return self
::link( $target, $html, $customAttribs, $query, $options );
271 * Returns the Url used to link to a Title
273 * @param Title $target
274 * @param array $query Query parameters
275 * @param array $options
278 private static function linkUrl( $target, $query, $options ) {
279 # We don't want to include fragments for broken links, because they
280 # generally make no sense.
281 if ( in_array( 'broken', $options, true ) && $target->hasFragment() ) {
282 $target = clone $target;
283 $target->setFragment( '' );
286 # If it's a broken link, add the appropriate query pieces, unless
287 # there's already an action specified, or unless 'edit' makes no sense
288 # (i.e., for a nonexistent special page).
289 if ( in_array( 'broken', $options, true ) && empty( $query['action'] )
290 && !$target->isSpecialPage() ) {
291 $query['action'] = 'edit';
292 $query['redlink'] = '1';
295 if ( in_array( 'http', $options, true ) ) {
297 } elseif ( in_array( 'https', $options, true ) ) {
298 $proto = PROTO_HTTPS
;
300 $proto = PROTO_RELATIVE
;
303 $ret = $target->getLinkURL( $query, false, $proto );
308 * Returns the array of attributes used when linking to the Title $target
310 * @param Title $target
311 * @param array $attribs
312 * @param array $options
316 private static function linkAttribs( $target, $attribs, $options ) {
320 if ( !in_array( 'noclasses', $options, true ) ) {
321 # Now build the classes.
324 if ( in_array( 'broken', $options, true ) ) {
328 if ( $target->isExternal() ) {
329 $classes[] = 'extiw';
332 if ( !in_array( 'broken', $options, true ) ) { # Avoid useless calls to LinkCache (see r50387)
333 $colour = self
::getLinkColour(
335 isset( $options['stubThreshold'] ) ?
$options['stubThreshold'] : $wgUser->getStubThreshold()
337 if ( $colour !== '' ) {
338 $classes[] = $colour; # mw-redirect or stub
341 if ( $classes != array() ) {
342 $defaults['class'] = implode( ' ', $classes );
346 # Get a default title attribute.
347 if ( $target->getPrefixedText() == '' ) {
348 # A link like [[#Foo]]. This used to mean an empty title
349 # attribute, but that's silly. Just don't output a title.
350 } elseif ( in_array( 'known', $options, true ) ) {
351 $defaults['title'] = $target->getPrefixedText();
353 // This ends up in parser cache!
354 $defaults['title'] = wfMessage( 'red-link-title', $target->getPrefixedText() )
355 ->inContentLanguage()
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' && $val !== false ) {
374 * Default text of the links to the Title $target
376 * @param Title $target
380 private static function linkText( $target ) {
381 if ( !$target instanceof Title
) {
382 wfWarn( __METHOD__
. ': Requires $target to be a Title object.' );
385 // If the target is just a fragment, with no title, we return the fragment
386 // text. Otherwise, we return the title text itself.
387 if ( $target->getPrefixedText() === '' && $target->hasFragment() ) {
388 return htmlspecialchars( $target->getFragment() );
391 return htmlspecialchars( $target->getPrefixedText() );
395 * Make appropriate markup for a link to the current article. This is
396 * currently rendered as the bold link text. The calling sequence is the
397 * same as the other make*LinkObj static functions, despite $query not
401 * @param string $html [optional]
402 * @param string $query [optional]
403 * @param string $trail [optional]
404 * @param string $prefix [optional]
408 public static function makeSelfLinkObj( $nt, $html = '', $query = '', $trail = '', $prefix = '' ) {
409 $ret = "<strong class=\"selflink\">{$prefix}{$html}</strong>{$trail}";
410 if ( !Hooks
::run( 'SelfLinkBegin', array( $nt, &$html, &$trail, &$prefix, &$ret ) ) ) {
415 $html = htmlspecialchars( $nt->getPrefixedText() );
417 list( $inside, $trail ) = self
::splitTrail( $trail );
418 return "<strong class=\"selflink\">{$prefix}{$html}{$inside}</strong>{$trail}";
422 * Get a message saying that an invalid title was encountered.
423 * This should be called after a method like Title::makeTitleSafe() returned
424 * a value indicating that the title object is invalid.
426 * @param IContextSource $context Context to use to get the messages
427 * @param int $namespace Namespace number
428 * @param string $title Text of the title, without the namespace part
431 public static function getInvalidTitleDescription( IContextSource
$context, $namespace, $title ) {
434 // First we check whether the namespace exists or not.
435 if ( MWNamespace
::exists( $namespace ) ) {
436 if ( $namespace == NS_MAIN
) {
437 $name = $context->msg( 'blanknamespace' )->text();
439 $name = $wgContLang->getFormattedNsText( $namespace );
441 return $context->msg( 'invalidtitle-knownnamespace', $namespace, $name, $title )->text();
443 return $context->msg( 'invalidtitle-unknownnamespace', $namespace, $title )->text();
448 * @param Title $title
451 static function normaliseSpecialPage( Title
$title ) {
452 if ( $title->isSpecialPage() ) {
453 list( $name, $subpage ) = SpecialPageFactory
::resolveAlias( $title->getDBkey() );
457 $ret = SpecialPage
::getTitleFor( $name, $subpage, $title->getFragment() );
465 * Returns the filename part of an url.
466 * Used as alternative text for external images.
472 private static function fnamePart( $url ) {
473 $basename = strrchr( $url, '/' );
474 if ( false === $basename ) {
477 $basename = substr( $basename, 1 );
483 * Return the code for images which were added via external links,
484 * via Parser::maybeMakeExternalImage().
491 public static function makeExternalImage( $url, $alt = '' ) {
493 $alt = self
::fnamePart( $url );
496 $success = Hooks
::run( 'LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
498 wfDebug( "Hook LinkerMakeExternalImage changed the output of external image "
499 . "with url {$url} and alt text {$alt} to {$img}\n", true );
502 return Html
::element( 'img',
509 * Given parameters derived from [[Image:Foo|options...]], generate the
510 * HTML that that syntax inserts in the page.
512 * @param Parser $parser
513 * @param Title $title Title object of the file (not the currently viewed page)
514 * @param File $file File object, or false if it doesn't exist
515 * @param array $frameParams Associative array of parameters external to the media handler.
516 * Boolean parameters are indicated by presence or absence, the value is arbitrary and
517 * will often be false.
518 * thumbnail If present, downscale and frame
519 * manualthumb Image name to use as a thumbnail, instead of automatic scaling
520 * framed Shows image in original size in a frame
521 * frameless Downscale but don't frame
522 * upright If present, tweak default sizes for portrait orientation
523 * upright_factor Fudge factor for "upright" tweak (default 0.75)
524 * border If present, show a border around the image
525 * align Horizontal alignment (left, right, center, none)
526 * valign Vertical alignment (baseline, sub, super, top, text-top, middle,
527 * bottom, text-bottom)
528 * alt Alternate text for image (i.e. alt attribute). Plain text.
529 * class HTML for image classes. Plain text.
530 * caption HTML for image caption.
531 * link-url URL to link to
532 * link-title Title object to link to
533 * link-target Value for the target attribute, only with link-url
534 * no-link Boolean, suppress description link
536 * @param array $handlerParams Associative array of media handler parameters, to be passed
537 * to transform(). Typical keys are "width" and "page".
538 * @param string|bool $time Timestamp of the file, set as false for current
539 * @param string $query Query params for desc url
540 * @param int|null $widthOption Used by the parser to remember the user preference thumbnailsize
542 * @return string HTML for an image, with links, wrappers, etc.
544 public static function makeImageLink( Parser
$parser, Title
$title,
545 $file, $frameParams = array(), $handlerParams = array(), $time = false,
546 $query = "", $widthOption = null
549 $dummy = new DummyLinker
;
550 if ( !Hooks
::run( 'ImageBeforeProduceHTML', array( &$dummy, &$title,
551 &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
555 if ( $file && !$file->allowInlineDisplay() ) {
556 wfDebug( __METHOD__
. ': ' . $title->getPrefixedDBkey() . " does not allow inline display\n" );
557 return self
::link( $title );
562 $hp =& $handlerParams;
564 // Clean up parameters
565 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
566 if ( !isset( $fp['align'] ) ) {
569 if ( !isset( $fp['alt'] ) ) {
572 if ( !isset( $fp['title'] ) ) {
575 if ( !isset( $fp['class'] ) ) {
579 $prefix = $postfix = '';
581 if ( 'center' == $fp['align'] ) {
582 $prefix = '<div class="center">';
584 $fp['align'] = 'none';
586 if ( $file && !isset( $hp['width'] ) ) {
587 if ( isset( $hp['height'] ) && $file->isVectorized() ) {
588 // If its a vector image, and user only specifies height
589 // we don't want it to be limited by its "normal" width.
590 global $wgSVGMaxSize;
591 $hp['width'] = $wgSVGMaxSize;
593 $hp['width'] = $file->getWidth( $page );
596 if ( isset( $fp['thumbnail'] )
597 ||
isset( $fp['manualthumb'] )
598 ||
isset( $fp['framed'] )
599 ||
isset( $fp['frameless'] )
602 global $wgThumbLimits, $wgThumbUpright;
604 if ( $widthOption === null ||
!isset( $wgThumbLimits[$widthOption] ) ) {
605 $widthOption = User
::getDefaultOption( 'thumbsize' );
608 // Reduce width for upright images when parameter 'upright' is used
609 if ( isset( $fp['upright'] ) && $fp['upright'] == 0 ) {
610 $fp['upright'] = $wgThumbUpright;
613 // For caching health: If width scaled down due to upright
614 // parameter, round to full __0 pixel to avoid the creation of a
615 // lot of odd thumbs.
616 $prefWidth = isset( $fp['upright'] ) ?
617 round( $wgThumbLimits[$widthOption] * $fp['upright'], -1 ) :
618 $wgThumbLimits[$widthOption];
620 // Use width which is smaller: real image width or user preference width
621 // Unless image is scalable vector.
622 if ( !isset( $hp['height'] ) && ( $hp['width'] <= 0 ||
623 $prefWidth < $hp['width'] ||
$file->isVectorized() ) ) {
624 $hp['width'] = $prefWidth;
629 if ( isset( $fp['thumbnail'] ) ||
isset( $fp['manualthumb'] ) ||
isset( $fp['framed'] ) ) {
630 # Create a thumbnail. Alignment depends on the writing direction of
631 # the page content language (right-aligned for LTR languages,
632 # left-aligned for RTL languages)
633 # If a thumbnail width has not been provided, it is set
634 # to the default user option as specified in Language*.php
635 if ( $fp['align'] == '' ) {
636 $fp['align'] = $parser->getTargetLanguage()->alignEnd();
638 return $prefix . self
::makeThumbLink2( $title, $file, $fp, $hp, $time, $query ) . $postfix;
641 if ( $file && isset( $fp['frameless'] ) ) {
642 $srcWidth = $file->getWidth( $page );
643 # For "frameless" option: do not present an image bigger than the
644 # source (for bitmap-style images). This is the same behavior as the
645 # "thumb" option does it already.
646 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
647 $hp['width'] = $srcWidth;
651 if ( $file && isset( $hp['width'] ) ) {
652 # Create a resized image, without the additional thumbnail features
653 $thumb = $file->transform( $hp );
659 $s = self
::makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time == true );
661 self
::processResponsiveImages( $file, $thumb, $hp );
664 'title' => $fp['title'],
665 'valign' => isset( $fp['valign'] ) ?
$fp['valign'] : false,
666 'img-class' => $fp['class'] );
667 if ( isset( $fp['border'] ) ) {
668 $params['img-class'] .= ( $params['img-class'] !== '' ?
' ' : '' ) . 'thumbborder';
670 $params = self
::getImageLinkMTOParams( $fp, $query, $parser ) +
$params;
672 $s = $thumb->toHtml( $params );
674 if ( $fp['align'] != '' ) {
675 $s = "<div class=\"float{$fp['align']}\">{$s}</div>";
677 return str_replace( "\n", ' ', $prefix . $s . $postfix );
681 * Get the link parameters for MediaTransformOutput::toHtml() from given
682 * frame parameters supplied by the Parser.
683 * @param array $frameParams The frame parameters
684 * @param string $query An optional query string to add to description page links
685 * @param Parser|null $parser
688 private static function getImageLinkMTOParams( $frameParams, $query = '', $parser = null ) {
689 $mtoParams = array();
690 if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) {
691 $mtoParams['custom-url-link'] = $frameParams['link-url'];
692 if ( isset( $frameParams['link-target'] ) ) {
693 $mtoParams['custom-target-link'] = $frameParams['link-target'];
696 $extLinkAttrs = $parser->getExternalLinkAttribs( $frameParams['link-url'] );
697 foreach ( $extLinkAttrs as $name => $val ) {
698 // Currently could include 'rel' and 'target'
699 $mtoParams['parser-extlink-' . $name] = $val;
702 } elseif ( isset( $frameParams['link-title'] ) && $frameParams['link-title'] !== '' ) {
703 $mtoParams['custom-title-link'] = self
::normaliseSpecialPage( $frameParams['link-title'] );
704 } elseif ( !empty( $frameParams['no-link'] ) ) {
707 $mtoParams['desc-link'] = true;
708 $mtoParams['desc-query'] = $query;
714 * Make HTML for a thumbnail including image, border and caption
715 * @param Title $title
716 * @param File|bool $file File object or false if it doesn't exist
717 * @param string $label
719 * @param string $align
720 * @param array $params
721 * @param bool $framed
722 * @param string $manualthumb
725 public static function makeThumbLinkObj( Title
$title, $file, $label = '', $alt,
726 $align = 'right', $params = array(), $framed = false, $manualthumb = ""
728 $frameParams = array(
734 $frameParams['framed'] = true;
736 if ( $manualthumb ) {
737 $frameParams['manualthumb'] = $manualthumb;
739 return self
::makeThumbLink2( $title, $file, $frameParams, $params );
743 * @param Title $title
745 * @param array $frameParams
746 * @param array $handlerParams
748 * @param string $query
751 public static function makeThumbLink2( Title
$title, $file, $frameParams = array(),
752 $handlerParams = array(), $time = false, $query = ""
754 $exists = $file && $file->exists();
758 $hp =& $handlerParams;
760 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
761 if ( !isset( $fp['align'] ) ) {
762 $fp['align'] = 'right';
764 if ( !isset( $fp['alt'] ) ) {
767 if ( !isset( $fp['title'] ) ) {
770 if ( !isset( $fp['caption'] ) ) {
774 if ( empty( $hp['width'] ) ) {
775 // Reduce width for upright images when parameter 'upright' is used
776 $hp['width'] = isset( $fp['upright'] ) ?
130 : 180;
780 $manualthumb = false;
783 $outerWidth = $hp['width'] +
2;
785 if ( isset( $fp['manualthumb'] ) ) {
786 # Use manually specified thumbnail
787 $manual_title = Title
::makeTitleSafe( NS_FILE
, $fp['manualthumb'] );
788 if ( $manual_title ) {
789 $manual_img = wfFindFile( $manual_title );
791 $thumb = $manual_img->getUnscaledThumb( $hp );
797 } elseif ( isset( $fp['framed'] ) ) {
798 // Use image dimensions, don't scale
799 $thumb = $file->getUnscaledThumb( $hp );
802 # Do not present an image bigger than the source, for bitmap-style images
803 # This is a hack to maintain compatibility with arbitrary pre-1.10 behavior
804 $srcWidth = $file->getWidth( $page );
805 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
806 $hp['width'] = $srcWidth;
808 $thumb = $file->transform( $hp );
812 $outerWidth = $thumb->getWidth() +
2;
814 $outerWidth = $hp['width'] +
2;
818 # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
819 # So we don't need to pass it here in $query. However, the URL for the
820 # zoom icon still needs it, so we make a unique query for it. See bug 14771
821 $url = $title->getLocalURL( $query );
823 $url = wfAppendQuery( $url, array( 'page' => $page ) );
826 && !isset( $fp['link-title'] )
827 && !isset( $fp['link-url'] )
828 && !isset( $fp['no-link'] ) ) {
829 $fp['link-url'] = $url;
832 $s = "<div class=\"thumb t{$fp['align']}\">"
833 . "<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'] !== ''
850 : '' ) . 'thumbimage'
852 $params = self
::getImageLinkMTOParams( $fp, $query ) +
$params;
853 $s .= $thumb->toHtml( $params );
854 if ( isset( $fp['framed'] ) ) {
857 $zoomIcon = Html
::rawElement( 'div', array( 'class' => 'magnify' ),
858 Html
::rawElement( 'a', array(
860 'class' => 'internal',
861 'title' => wfMessage( 'thumbnail-more' )->text() ),
865 $s .= ' <div class="thumbcaption">' . $zoomIcon . $fp['caption'] . "</div></div></div>";
866 return str_replace( "\n", ' ', $s );
870 * Process responsive images: add 1.5x and 2x subimages to the thumbnail, where
874 * @param MediaTransformOutput $thumb
875 * @param array $hp Image parameters
877 public static function processResponsiveImages( $file, $thumb, $hp ) {
878 global $wgResponsiveImages;
879 if ( $wgResponsiveImages && $thumb && !$thumb->isError() ) {
881 $hp15['width'] = round( $hp['width'] * 1.5 );
883 $hp20['width'] = $hp['width'] * 2;
884 if ( isset( $hp['height'] ) ) {
885 $hp15['height'] = round( $hp['height'] * 1.5 );
886 $hp20['height'] = $hp['height'] * 2;
889 $thumb15 = $file->transform( $hp15 );
890 $thumb20 = $file->transform( $hp20 );
891 if ( $thumb15 && !$thumb15->isError() && $thumb15->getUrl() !== $thumb->getUrl() ) {
892 $thumb->responsiveUrls
['1.5'] = $thumb15->getUrl();
894 if ( $thumb20 && !$thumb20->isError() && $thumb20->getUrl() !== $thumb->getUrl() ) {
895 $thumb->responsiveUrls
['2'] = $thumb20->getUrl();
901 * Make a "broken" link to an image
903 * @param Title $title
904 * @param string $label Link label (plain text)
905 * @param string $query Query string
906 * @param string $unused1 Unused parameter kept for b/c
907 * @param string $unused2 Unused parameter kept for b/c
908 * @param bool $time A file of a certain timestamp was requested
911 public static function makeBrokenImageLinkObj( $title, $label = '',
912 $query = '', $unused1 = '', $unused2 = '', $time = false
914 if ( !$title instanceof Title
) {
915 wfWarn( __METHOD__
. ': Requires $title to be a Title object.' );
916 return "<!-- ERROR -->" . htmlspecialchars( $label );
919 global $wgEnableUploads, $wgUploadMissingFileUrl, $wgUploadNavigationUrl;
920 if ( $label == '' ) {
921 $label = $title->getPrefixedText();
923 $encLabel = htmlspecialchars( $label );
924 $currentExists = $time ?
( wfFindFile( $title ) != false ) : false;
926 if ( ( $wgUploadMissingFileUrl ||
$wgUploadNavigationUrl ||
$wgEnableUploads )
929 $redir = RepoGroup
::singleton()->getLocalRepo()->checkRedirect( $title );
932 return self
::linkKnown( $title, $encLabel, array(), wfCgiToArray( $query ) );
935 $href = self
::getUploadUrl( $title, $query );
937 return '<a href="' . htmlspecialchars( $href ) . '" class="new" title="' .
938 htmlspecialchars( $title->getPrefixedText(), ENT_QUOTES
) . '">' .
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 ( !Hooks
::run( 'LinkerMakeMediaLinkFile',
1015 array( $title, $file, &$html, &$attribs, &$ret ) ) ) {
1016 wfDebug( "Hook LinkerMakeMediaLinkFile changed the output of link "
1017 . "with url {$url} and text {$html} to {$ret}\n", true );
1021 return Html
::rawElement( 'a', $attribs, $html );
1025 * Make a link to a special page given its name and, optionally,
1026 * a message key from the link text.
1027 * Usage example: Linker::specialLink( 'Recentchanges' )
1029 * @param string $name
1030 * @param string $key
1033 public static function specialLink( $name, $key = '' ) {
1035 $key = strtolower( $name );
1038 return self
::linkKnown( SpecialPage
::getTitleFor( $name ), wfMessage( $key )->text() );
1042 * Make an external link
1043 * @param string $url URL to link to
1044 * @param string $text Text of link
1045 * @param bool $escape Do we escape the link text?
1046 * @param string $linktype Type of external link. Gets added to the classes
1047 * @param array $attribs Array of extra attributes to <a>
1048 * @param Title|null $title Title object used for title specific link attributes
1051 public static function makeExternalLink( $url, $text, $escape = true,
1052 $linktype = '', $attribs = array(), $title = null
1055 $class = "external";
1057 $class .= " $linktype";
1059 if ( isset( $attribs['class'] ) && $attribs['class'] ) {
1060 $class .= " {$attribs['class']}";
1062 $attribs['class'] = $class;
1065 $text = htmlspecialchars( $text );
1071 $attribs['rel'] = Parser
::getExternalLinkRel( $url, $title );
1073 $success = Hooks
::run( 'LinkerMakeExternalLink',
1074 array( &$url, &$text, &$link, &$attribs, $linktype ) );
1076 wfDebug( "Hook LinkerMakeExternalLink changed the output of link "
1077 . "with url {$url} and text {$text} to {$link}\n", true );
1080 $attribs['href'] = $url;
1081 return Html
::rawElement( 'a', $attribs, $text );
1085 * Make user link (or user contributions for unregistered users)
1086 * @param int $userId User id in database.
1087 * @param string $userName User name in database.
1088 * @param string $altUserName Text to display instead of the user name (optional)
1089 * @return string HTML fragment
1090 * @since 1.19 Method exists for a long time. $altUserName was added in 1.19.
1092 public static function userLink( $userId, $userName, $altUserName = false ) {
1093 $classes = 'mw-userlink';
1094 if ( $userId == 0 ) {
1095 $page = SpecialPage
::getTitleFor( 'Contributions', $userName );
1096 if ( $altUserName === false ) {
1097 $altUserName = IP
::prettifyIP( $userName );
1099 $classes .= ' mw-anonuserlink'; // Separate link class for anons (bug 43179)
1101 $page = Title
::makeTitle( NS_USER
, $userName );
1106 htmlspecialchars( $altUserName !== false ?
$altUserName : $userName ),
1107 array( 'class' => $classes )
1112 * Generate standard user tool links (talk, contributions, block link, etc.)
1114 * @param int $userId User identifier
1115 * @param string $userText User name or IP address
1116 * @param bool $redContribsWhenNoEdits Should the contributions link be
1117 * red if the user has no edits?
1118 * @param int $flags Customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK
1119 * and Linker::TOOL_LINKS_EMAIL).
1120 * @param int $edits User edit count (optional, for performance)
1121 * @return string HTML fragment
1123 public static function userToolLinks(
1124 $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits = null
1126 global $wgUser, $wgDisableAnonTalk, $wgLang;
1127 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
1128 $blockable = !( $flags & self
::TOOL_LINKS_NOBLOCK
);
1129 $addEmailLink = $flags & self
::TOOL_LINKS_EMAIL
&& $userId;
1133 $items[] = self
::userTalkLink( $userId, $userText );
1136 // check if the user has an edit
1138 if ( $redContribsWhenNoEdits ) {
1139 if ( intval( $edits ) === 0 && $edits !== 0 ) {
1140 $user = User
::newFromId( $userId );
1141 $edits = $user->getEditCount();
1143 if ( $edits === 0 ) {
1144 $attribs['class'] = 'new';
1147 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $userText );
1149 $items[] = self
::link( $contribsPage, wfMessage( 'contribslink' )->escaped(), $attribs );
1151 if ( $blockable && $wgUser->isAllowed( 'block' ) ) {
1152 $items[] = self
::blockLink( $userId, $userText );
1155 if ( $addEmailLink && $wgUser->canSendEmail() ) {
1156 $items[] = self
::emailLink( $userId, $userText );
1159 Hooks
::run( 'UserToolLinksEdit', array( $userId, $userText, &$items ) );
1162 return wfMessage( 'word-separator' )->escaped()
1163 . '<span class="mw-usertoollinks">'
1164 . wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped()
1172 * Alias for userToolLinks( $userId, $userText, true );
1173 * @param int $userId User identifier
1174 * @param string $userText User name or IP address
1175 * @param int $edits User edit count (optional, for performance)
1178 public static function userToolLinksRedContribs( $userId, $userText, $edits = null ) {
1179 return self
::userToolLinks( $userId, $userText, true, 0, $edits );
1183 * @param int $userId User id in database.
1184 * @param string $userText User name in database.
1185 * @return string HTML fragment with user talk link
1187 public static function userTalkLink( $userId, $userText ) {
1188 $userTalkPage = Title
::makeTitle( NS_USER_TALK
, $userText );
1189 $userTalkLink = self
::link( $userTalkPage, wfMessage( 'talkpagelinktext' )->escaped() );
1190 return $userTalkLink;
1194 * @param int $userId Userid
1195 * @param string $userText User name in database.
1196 * @return string HTML fragment with block link
1198 public static function blockLink( $userId, $userText ) {
1199 $blockPage = SpecialPage
::getTitleFor( 'Block', $userText );
1200 $blockLink = self
::link( $blockPage, wfMessage( 'blocklink' )->escaped() );
1205 * @param int $userId Userid
1206 * @param string $userText User name in database.
1207 * @return string HTML fragment with e-mail user link
1209 public static function emailLink( $userId, $userText ) {
1210 $emailPage = SpecialPage
::getTitleFor( 'Emailuser', $userText );
1211 $emailLink = self
::link( $emailPage, wfMessage( 'emaillink' )->escaped() );
1216 * Generate a user link if the current user is allowed to view it
1217 * @param Revision $rev
1218 * @param bool $isPublic Show only if all users can see it
1219 * @return string HTML fragment
1221 public static function revUserLink( $rev, $isPublic = false ) {
1222 if ( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1223 $link = wfMessage( 'rev-deleted-user' )->escaped();
1224 } elseif ( $rev->userCan( Revision
::DELETED_USER
) ) {
1225 $link = self
::userLink( $rev->getUser( Revision
::FOR_THIS_USER
),
1226 $rev->getUserText( Revision
::FOR_THIS_USER
) );
1228 $link = wfMessage( 'rev-deleted-user' )->escaped();
1230 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1231 return '<span class="history-deleted">' . $link . '</span>';
1237 * Generate a user tool link cluster if the current user is allowed to view it
1238 * @param Revision $rev
1239 * @param bool $isPublic Show only if all users can see it
1240 * @return string HTML
1242 public static function revUserTools( $rev, $isPublic = false ) {
1243 if ( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1244 $link = wfMessage( 'rev-deleted-user' )->escaped();
1245 } elseif ( $rev->userCan( Revision
::DELETED_USER
) ) {
1246 $userId = $rev->getUser( Revision
::FOR_THIS_USER
);
1247 $userText = $rev->getUserText( Revision
::FOR_THIS_USER
);
1248 $link = self
::userLink( $userId, $userText )
1249 . self
::userToolLinks( $userId, $userText );
1251 $link = wfMessage( 'rev-deleted-user' )->escaped();
1253 if ( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1254 return ' <span class="history-deleted">' . $link . '</span>';
1260 * This function is called by all recent changes variants, by the page history,
1261 * and by the user contributions list. It is responsible for formatting edit
1262 * summaries. It escapes any HTML in the summary, but adds some CSS to format
1263 * auto-generated comments (from section editing) and formats [[wikilinks]].
1265 * @author Erik Moeller <moeller@scireview.de>
1267 * Note: there's not always a title to pass to this function.
1268 * Since you can't set a default parameter for a reference, I've turned it
1269 * temporarily to a value pass. Should be adjusted further. --brion
1271 * @param string $comment
1272 * @param Title|null $title Title object (to generate link to the section in autocomment)
1274 * @param bool $local Whether section links should refer to local page
1275 * @param string|null $wikiId Id (as used by WikiMap) of the wiki to generate links to.
1276 * For use with external changes.
1278 * @return mixed|string
1280 public static function formatComment(
1281 $comment, $title = null, $local = false, $wikiId = null
1283 # Sanitize text a bit:
1284 $comment = str_replace( "\n", " ", $comment );
1285 # Allow HTML entities (for bug 13815)
1286 $comment = Sanitizer
::escapeHtmlAllowEntities( $comment );
1288 # Render autocomments and make links:
1289 $comment = self
::formatAutocomments( $comment, $title, $local, $wikiId );
1290 $comment = self
::formatLinksInComment( $comment, $title, $local, $wikiId );
1296 * Converts autogenerated comments in edit summaries into section links.
1298 * The pattern for autogen comments is / * foo * /, which makes for
1300 * We look for all comments, match any text before and after the comment,
1301 * add a separator where needed and format the comment itself with CSS
1302 * Called by Linker::formatComment.
1304 * @param string $comment Comment text
1305 * @param Title|null $title An optional title object used to links to sections
1306 * @param bool $local Whether section links should refer to local page
1307 * @param string|null $wikiId Id of the wiki to link to (if not the local wiki),
1308 * as used by WikiMap.
1310 * @return string Formatted comment (wikitext)
1312 private static function formatAutocomments(
1313 $comment, $title = null, $local = false, $wikiId = null
1315 // @todo $append here is something of a hack to preserve the status
1316 // quo. Someone who knows more about bidi and such should decide
1317 // (1) what sane rendering even *is* for an LTR edit summary on an RTL
1318 // wiki, both when autocomments exist and when they don't, and
1319 // (2) what markup will make that actually happen.
1321 $comment = preg_replace_callback(
1322 // To detect the presence of content before or after the
1323 // auto-comment, we use capturing groups inside optional zero-width
1324 // assertions. But older versions of PCRE can't directly make
1325 // zero-width assertions optional, so wrap them in a non-capturing
1327 '!(?:(?<=(.)))?/\*\s*(.*?)\s*\*/(?:(?=(.)))?!',
1328 function ( $match ) use ( $title, $local, $wikiId, &$append ) {
1331 // Ensure all match positions are defined
1332 $match +
= array( '', '', '', '' );
1334 $pre = $match[1] !== '';
1336 $post = $match[3] !== '';
1340 'FormatAutocomments',
1341 array( &$comment, $pre, $auto, $post, $title, $local, $wikiId )
1344 if ( $comment === null ) {
1348 # Remove links that a user may have manually put in the autosummary
1349 # This could be improved by copying as much of Parser::stripSectionName as desired.
1350 $section = str_replace( '[[:', '', $section );
1351 $section = str_replace( '[[', '', $section );
1352 $section = str_replace( ']]', '', $section );
1354 $section = Sanitizer
::normalizeSectionNameWhitespace( $section ); # bug 22784
1356 $sectionTitle = Title
::newFromText( '#' . $section );
1358 $sectionTitle = Title
::makeTitleSafe( $title->getNamespace(),
1359 $title->getDBkey(), $section );
1361 if ( $sectionTitle ) {
1362 $link = Linker
::makeCommentLink( $sectionTitle, $wgLang->getArrow(), $wikiId, 'noclasses' );
1368 # written summary $presep autocomment (summary /* section */)
1369 $pre = wfMessage( 'autocomment-prefix' )->inContentLanguage()->escaped();
1372 # autocomment $postsep written summary (/* section */ summary)
1373 $auto .= wfMessage( 'colon-separator' )->inContentLanguage()->escaped();
1375 $auto = '<span class="autocomment">' . $auto . '</span>';
1376 $comment = $pre . $link . $wgLang->getDirMark()
1377 . '<span dir="auto">' . $auto;
1378 $append .= '</span>';
1384 return $comment . $append;
1388 * Formats wiki links and media links in text; all other wiki formatting
1391 * @todo FIXME: Doesn't handle sub-links as in image thumb texts like the main parser
1392 * @param string $comment Text to format links in. WARNING! Since the output of this
1393 * function is html, $comment must be sanitized for use as html. You probably want
1394 * to pass $comment through Sanitizer::escapeHtmlAllowEntities() before calling
1396 * @param Title|null $title An optional title object used to links to sections
1397 * @param bool $local Whether section links should refer to local page
1398 * @param string|null $wikiId Id of the wiki to link to (if not the local wiki),
1399 * as used by WikiMap.
1403 public static function formatLinksInComment(
1404 $comment, $title = null, $local = false, $wikiId = null
1406 return preg_replace_callback(
1409 :? # ignore optional leading colon
1410 ([^\]|]+) # 1. link target; page names cannot include ] or |
1412 # 2. a pipe-separated substring; only the last is captured
1413 # Stop matching at | and ]] without relying on backtracking.
1417 ([^[]*) # 3. link trail (the text up until the next link)
1419 function ( $match ) use ( $title, $local, $wikiId ) {
1422 $medians = '(?:' . preg_quote( MWNamespace
::getCanonicalName( NS_MEDIA
), '/' ) . '|';
1423 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA
), '/' ) . '):';
1425 $comment = $match[0];
1427 # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
1428 if ( strpos( $match[1], '%' ) !== false ) {
1430 rawurldecode( $match[1] ),
1431 array( '<' => '<', '>' => '>' )
1435 # Handle link renaming [[foo|text]] will show link as "text"
1436 if ( $match[2] != "" ) {
1441 $submatch = array();
1443 if ( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1444 # Media link; trail not supported.
1445 $linkRegexp = '/\[\[(.*?)\]\]/';
1446 $title = Title
::makeTitleSafe( NS_FILE
, $submatch[1] );
1448 $thelink = Linker
::makeMediaLinkObj( $title, $text );
1451 # Other kind of link
1452 if ( preg_match( $wgContLang->linkTrail(), $match[3], $submatch ) ) {
1453 $trail = $submatch[1];
1457 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1458 if ( isset( $match[1][0] ) && $match[1][0] == ':' ) {
1459 $match[1] = substr( $match[1], 1 );
1461 list( $inside, $trail ) = Linker
::splitTrail( $trail );
1464 $linkTarget = Linker
::normalizeSubpageLink( $title, $match[1], $linkText );
1466 $target = Title
::newFromText( $linkTarget );
1468 if ( $target->getText() == '' && !$target->isExternal()
1469 && !$local && $title
1471 $newTarget = clone $title;
1472 $newTarget->setFragment( '#' . $target->getFragment() );
1473 $target = $newTarget;
1476 $thelink = Linker
::makeCommentLink( $target, $linkText . $inside, $wikiId ) . $trail;
1480 // If the link is still valid, go ahead and replace it in!
1481 $comment = preg_replace(
1483 StringUtils
::escapeRegexReplacement( $thelink ),
1496 * Generates a link to the given Title
1498 * @note This is only public for technical reasons. It's not intended for use outside Linker.
1500 * @param Title $title
1501 * @param string $text
1502 * @param string|null $wikiId Id of the wiki to link to (if not the local wiki),
1503 * as used by WikiMap.
1504 * @param string|string[] $options See the $options parameter in Linker::link.
1506 * @return string HTML link
1508 public static function makeCommentLink(
1509 Title
$title, $text, $wikiId = null, $options = array()
1511 if ( $wikiId !== null && !$title->isExternal() ) {
1512 $link = Linker
::makeExternalLink(
1513 WikiMap
::getForeignURL(
1515 $title->getPrefixedText(),
1516 $title->getFragment()
1519 /* escape = */ false // Already escaped
1522 $link = Linker
::link( $title, $text, array(), array(), $options );
1529 * @param Title $contextTitle
1530 * @param string $target
1531 * @param string $text
1534 public static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
1537 # :Foobar -- override special treatment of prefix (images, language links)
1538 # /Foobar -- convert to CurrentPage/Foobar
1539 # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial and final / from text
1540 # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
1541 # ../Foobar -- convert to CurrentPage/Foobar,
1542 # (from CurrentPage/CurrentSubPage)
1543 # ../Foobar/ -- convert to CurrentPage/Foobar, use 'Foobar' as text
1544 # (from CurrentPage/CurrentSubPage)
1546 $ret = $target; # default return value is no change
1548 # Some namespaces don't allow subpages,
1549 # so only perform processing if subpages are allowed
1550 if ( $contextTitle && MWNamespace
::hasSubpages( $contextTitle->getNamespace() ) ) {
1551 $hash = strpos( $target, '#' );
1552 if ( $hash !== false ) {
1553 $suffix = substr( $target, $hash );
1554 $target = substr( $target, 0, $hash );
1559 $target = trim( $target );
1560 # Look at the first character
1561 if ( $target != '' && $target[0] === '/' ) {
1562 # / at end means we don't want the slash to be shown
1564 $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
1565 if ( $trailingSlashes ) {
1566 $noslash = $target = substr( $target, 1, -strlen( $m[0][0] ) );
1568 $noslash = substr( $target, 1 );
1571 $ret = $contextTitle->getPrefixedText() . '/' . trim( $noslash ) . $suffix;
1572 if ( $text === '' ) {
1573 $text = $target . $suffix;
1574 } # this might be changed for ugliness reasons
1576 # check for .. subpage backlinks
1578 $nodotdot = $target;
1579 while ( strncmp( $nodotdot, "../", 3 ) == 0 ) {
1581 $nodotdot = substr( $nodotdot, 3 );
1583 if ( $dotdotcount > 0 ) {
1584 $exploded = explode( '/', $contextTitle->getPrefixedText() );
1585 if ( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
1586 $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
1587 # / at the end means don't show full path
1588 if ( substr( $nodotdot, -1, 1 ) === '/' ) {
1589 $nodotdot = rtrim( $nodotdot, '/' );
1590 if ( $text === '' ) {
1591 $text = $nodotdot . $suffix;
1594 $nodotdot = trim( $nodotdot );
1595 if ( $nodotdot != '' ) {
1596 $ret .= '/' . $nodotdot;
1608 * Wrap a comment in standard punctuation and formatting if
1609 * it's non-empty, otherwise return empty string.
1611 * @param string $comment
1612 * @param Title|null $title Title object (to generate link to section in autocomment) or null
1613 * @param bool $local Whether section links should refer to local page
1614 * @param string|null $wikiId Id (as used by WikiMap) of the wiki to generate links to.
1615 * For use with external changes.
1619 public static function commentBlock(
1620 $comment, $title = null, $local = false, $wikiId = null
1622 // '*' used to be the comment inserted by the software way back
1623 // in antiquity in case none was provided, here for backwards
1624 // compatibility, acc. to brion -ævar
1625 if ( $comment == '' ||
$comment == '*' ) {
1628 $formatted = self
::formatComment( $comment, $title, $local, $wikiId );
1629 $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped();
1630 return " <span class=\"comment\">$formatted</span>";
1635 * Wrap and format the given revision's comment block, if the current
1636 * user is allowed to view it.
1638 * @param Revision $rev
1639 * @param bool $local Whether section links should refer to local page
1640 * @param bool $isPublic Show only if all users can see it
1641 * @return string HTML fragment
1643 public static function revComment( Revision
$rev, $local = false, $isPublic = false ) {
1644 if ( $rev->getComment( Revision
::RAW
) == "" ) {
1647 if ( $rev->isDeleted( Revision
::DELETED_COMMENT
) && $isPublic ) {
1648 $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>";
1649 } elseif ( $rev->userCan( Revision
::DELETED_COMMENT
) ) {
1650 $block = self
::commentBlock( $rev->getComment( Revision
::FOR_THIS_USER
),
1651 $rev->getTitle(), $local );
1653 $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>";
1655 if ( $rev->isDeleted( Revision
::DELETED_COMMENT
) ) {
1656 return " <span class=\"history-deleted\">$block</span>";
1665 public static function formatRevisionSize( $size ) {
1667 $stxt = wfMessage( 'historyempty' )->escaped();
1669 $stxt = wfMessage( 'nbytes' )->numParams( $size )->escaped();
1670 $stxt = wfMessage( 'parentheses' )->rawParams( $stxt )->escaped();
1672 return "<span class=\"history-size\">$stxt</span>";
1676 * Add another level to the Table of Contents
1680 public static function tocIndent() {
1685 * Finish one or more sublevels on the Table of Contents
1690 public static function tocUnindent( $level ) {
1691 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level > 0 ?
$level : 0 );
1695 * parameter level defines if we are on an indentation level
1697 * @param string $anchor
1698 * @param string $tocline
1699 * @param string $tocnumber
1700 * @param string $level
1701 * @param string|bool $sectionIndex
1704 public static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
1705 $classes = "toclevel-$level";
1706 if ( $sectionIndex !== false ) {
1707 $classes .= " tocsection-$sectionIndex";
1709 return "\n<li class=\"$classes\"><a href=\"#" .
1710 $anchor . '"><span class="tocnumber">' .
1711 $tocnumber . '</span> <span class="toctext">' .
1712 $tocline . '</span></a>';
1716 * End a Table Of Contents line.
1717 * tocUnindent() will be used instead if we're ending a line below
1721 public static function tocLineEnd() {
1726 * Wraps the TOC in a table and provides the hide/collapse javascript.
1728 * @param string $toc Html of the Table Of Contents
1729 * @param string|Language|bool $lang Language for the toc title, defaults to user language
1730 * @return string Full html of the TOC
1732 public static function tocList( $toc, $lang = false ) {
1733 $lang = wfGetLangObj( $lang );
1734 $title = wfMessage( 'toc' )->inLanguage( $lang )->escaped();
1736 return '<div id="toc" class="toc">'
1737 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
1739 . "</ul>\n</div>\n";
1743 * Generate a table of contents from a section tree.
1745 * @param array $tree Return value of ParserOutput::getSections()
1746 * @param string|Language|bool $lang Language for the toc title, defaults to user language
1747 * @return string HTML fragment
1749 public static function generateTOC( $tree, $lang = false ) {
1752 foreach ( $tree as $section ) {
1753 if ( $section['toclevel'] > $lastLevel ) {
1754 $toc .= self
::tocIndent();
1755 } elseif ( $section['toclevel'] < $lastLevel ) {
1756 $toc .= self
::tocUnindent(
1757 $lastLevel - $section['toclevel'] );
1759 $toc .= self
::tocLineEnd();
1762 $toc .= self
::tocLine( $section['anchor'],
1763 $section['line'], $section['number'],
1764 $section['toclevel'], $section['index'] );
1765 $lastLevel = $section['toclevel'];
1767 $toc .= self
::tocLineEnd();
1768 return self
::tocList( $toc, $lang );
1772 * Create a headline for content
1774 * @param int $level The level of the headline (1-6)
1775 * @param string $attribs Any attributes for the headline, starting with
1776 * a space and ending with '>'
1777 * This *must* be at least '>' for no attribs
1778 * @param string $anchor The anchor to give the headline (the bit after the #)
1779 * @param string $html Html for the text of the header
1780 * @param string $link HTML to add for the section edit link
1781 * @param bool|string $legacyAnchor A second, optional anchor to give for
1782 * backward compatibility (false to omit)
1784 * @return string HTML headline
1786 public static function makeHeadline( $level, $attribs, $anchor, $html,
1787 $link, $legacyAnchor = false
1789 $ret = "<h$level$attribs"
1790 . "<span class=\"mw-headline\" id=\"$anchor\">$html</span>"
1793 if ( $legacyAnchor !== false ) {
1794 $ret = "<div id=\"$legacyAnchor\"></div>$ret";
1800 * Split a link trail, return the "inside" portion and the remainder of the trail
1801 * as a two-element array
1802 * @param string $trail
1805 static function splitTrail( $trail ) {
1807 $regex = $wgContLang->linkTrail();
1809 if ( $trail !== '' ) {
1811 if ( preg_match( $regex, $trail, $m ) ) {
1816 return array( $inside, $trail );
1820 * Generate a rollback link for a given revision. Currently it's the
1821 * caller's responsibility to ensure that the revision is the top one. If
1822 * it's not, of course, the user will get an error message.
1824 * If the calling page is called with the parameter &bot=1, all rollback
1825 * links also get that parameter. It causes the edit itself and the rollback
1826 * to be marked as "bot" edits. Bot edits are hidden by default from recent
1827 * changes, so this allows sysops to combat a busy vandal without bothering
1830 * If the option verify is set this function will return the link only in case the
1831 * revision can be reverted. Please note that due to performance limitations
1832 * it might be assumed that a user isn't the only contributor of a page while
1833 * (s)he is, which will lead to useless rollback links. Furthermore this wont
1834 * work if $wgShowRollbackEditCount is disabled, so this can only function
1835 * as an additional check.
1837 * If the option noBrackets is set the rollback link wont be enclosed in []
1839 * @param Revision $rev
1840 * @param IContextSource $context Context to use or null for the main context.
1841 * @param array $options
1844 public static function generateRollback( $rev, IContextSource
$context = null,
1845 $options = array( 'verify' )
1847 if ( $context === null ) {
1848 $context = RequestContext
::getMain();
1852 if ( in_array( 'verify', $options, true ) ) {
1853 $editCount = self
::getRollbackEditCount( $rev, true );
1854 if ( $editCount === false ) {
1859 $inner = self
::buildRollbackLink( $rev, $context, $editCount );
1861 if ( !in_array( 'noBrackets', $options, true ) ) {
1862 $inner = $context->msg( 'brackets' )->rawParams( $inner )->escaped();
1865 return '<span class="mw-rollback-link">' . $inner . '</span>';
1869 * This function will return the number of revisions which a rollback
1870 * would revert and, if $verify is set it will verify that a revision
1871 * can be reverted (that the user isn't the only contributor and the
1872 * revision we might rollback to isn't deleted). These checks can only
1873 * function as an additional check as this function only checks against
1874 * the last $wgShowRollbackEditCount edits.
1876 * Returns null if $wgShowRollbackEditCount is disabled or false if $verify
1877 * is set and the user is the only contributor of the page.
1879 * @param Revision $rev
1880 * @param bool $verify Try to verify that this revision can really be rolled back
1881 * @return int|bool|null
1883 public static function getRollbackEditCount( $rev, $verify ) {
1884 global $wgShowRollbackEditCount;
1885 if ( !is_int( $wgShowRollbackEditCount ) ||
!$wgShowRollbackEditCount > 0 ) {
1886 // Nothing has happened, indicate this by returning 'null'
1890 $dbr = wfGetDB( DB_SLAVE
);
1892 // Up to the value of $wgShowRollbackEditCount revisions are counted
1893 $res = $dbr->select(
1895 array( 'rev_user_text', 'rev_deleted' ),
1896 // $rev->getPage() returns null sometimes
1897 array( 'rev_page' => $rev->getTitle()->getArticleID() ),
1900 'USE INDEX' => array( 'revision' => 'page_timestamp' ),
1901 'ORDER BY' => 'rev_timestamp DESC',
1902 'LIMIT' => $wgShowRollbackEditCount +
1
1908 foreach ( $res as $row ) {
1909 if ( $rev->getUserText( Revision
::RAW
) != $row->rev_user_text
) {
1911 ( $row->rev_deleted
& Revision
::DELETED_TEXT
1912 ||
$row->rev_deleted
& Revision
::DELETED_USER
1914 // If the user or the text of the revision we might rollback
1915 // to is deleted in some way we can't rollback. Similar to
1916 // the sanity checks in WikiPage::commitRollback.
1925 if ( $verify && $editCount <= $wgShowRollbackEditCount && !$moreRevs ) {
1926 // We didn't find at least $wgShowRollbackEditCount revisions made by the current user
1927 // and there weren't any other revisions. That means that the current user is the only
1928 // editor, so we can't rollback
1935 * Build a raw rollback link, useful for collections of "tool" links
1937 * @param Revision $rev
1938 * @param IContextSource|null $context Context to use or null for the main context.
1939 * @param int $editCount Number of edits that would be reverted
1940 * @return string HTML fragment
1942 public static function buildRollbackLink( $rev, IContextSource
$context = null,
1945 global $wgShowRollbackEditCount, $wgMiserMode;
1947 // To config which pages are affected by miser mode
1948 $disableRollbackEditCountSpecialPage = array( 'Recentchanges', 'Watchlist' );
1950 if ( $context === null ) {
1951 $context = RequestContext
::getMain();
1954 $title = $rev->getTitle();
1956 'action' => 'rollback',
1957 'from' => $rev->getUserText(),
1958 'token' => $context->getUser()->getEditToken( array(
1959 $title->getPrefixedText(),
1963 if ( $context->getRequest()->getBool( 'bot' ) ) {
1964 $query['bot'] = '1';
1965 $query['hidediff'] = '1'; // bug 15999
1968 $disableRollbackEditCount = false;
1969 if ( $wgMiserMode ) {
1970 foreach ( $disableRollbackEditCountSpecialPage as $specialPage ) {
1971 if ( $context->getTitle()->isSpecial( $specialPage ) ) {
1972 $disableRollbackEditCount = true;
1978 if ( !$disableRollbackEditCount
1979 && is_int( $wgShowRollbackEditCount )
1980 && $wgShowRollbackEditCount > 0
1982 if ( !is_numeric( $editCount ) ) {
1983 $editCount = self
::getRollbackEditCount( $rev, false );
1986 if ( $editCount > $wgShowRollbackEditCount ) {
1987 $editCount_output = $context->msg( 'rollbacklinkcount-morethan' )
1988 ->numParams( $wgShowRollbackEditCount )->parse();
1990 $editCount_output = $context->msg( 'rollbacklinkcount' )->numParams( $editCount )->parse();
1996 array( 'title' => $context->msg( 'tooltip-rollback' )->text() ),
1998 array( 'known', 'noclasses' )
2003 $context->msg( 'rollbacklink' )->escaped(),
2004 array( 'title' => $context->msg( 'tooltip-rollback' )->text() ),
2006 array( 'known', 'noclasses' )
2012 * Returns HTML for the "templates used on this page" list.
2014 * Make an HTML list of templates, and then add a "More..." link at
2015 * the bottom. If $more is null, do not add a "More..." link. If $more
2016 * is a Title, make a link to that title and use it. If $more is a string,
2017 * directly paste it in as the link (escaping needs to be done manually).
2018 * Finally, if $more is a Message, call toString().
2020 * @param Title[] $templates Array of templates
2021 * @param bool $preview Whether this is for a preview
2022 * @param bool $section Whether this is for a section edit
2023 * @param Title|Message|string|null $more An escaped link for "More..." of the templates
2024 * @return string HTML output
2026 public static function formatTemplates( $templates, $preview = false,
2027 $section = false, $more = null
2032 if ( count( $templates ) > 0 ) {
2033 # Do a batch existence check
2034 $batch = new LinkBatch
;
2035 foreach ( $templates as $title ) {
2036 $batch->addObj( $title );
2040 # Construct the HTML
2041 $outText = '<div class="mw-templatesUsedExplanation">';
2043 $outText .= wfMessage( 'templatesusedpreview' )->numParams( count( $templates ) )
2045 } elseif ( $section ) {
2046 $outText .= wfMessage( 'templatesusedsection' )->numParams( count( $templates ) )
2049 $outText .= wfMessage( 'templatesused' )->numParams( count( $templates ) )
2052 $outText .= "</div><ul>\n";
2054 usort( $templates, 'Title::compare' );
2055 foreach ( $templates as $titleObj ) {
2057 $restrictions = $titleObj->getRestrictions( 'edit' );
2058 if ( $restrictions ) {
2059 // Check backwards-compatible messages
2061 if ( $restrictions === array( 'sysop' ) ) {
2062 $msg = wfMessage( 'template-protected' );
2063 } elseif ( $restrictions === array( 'autoconfirmed' ) ) {
2064 $msg = wfMessage( 'template-semiprotected' );
2066 if ( $msg && !$msg->isDisabled() ) {
2067 $protected = $msg->parse();
2069 // Construct the message from restriction-level-*
2070 // e.g. restriction-level-sysop, restriction-level-autoconfirmed
2072 foreach ( $restrictions as $r ) {
2073 $msgs[] = wfMessage( "restriction-level-$r" )->parse();
2075 $protected = wfMessage( 'parentheses' )
2076 ->rawParams( $wgLang->commaList( $msgs ) )->escaped();
2079 if ( $titleObj->quickUserCan( 'edit' ) ) {
2080 $editLink = self
::link(
2082 wfMessage( 'editlink' )->escaped(),
2084 array( 'action' => 'edit' )
2087 $editLink = self
::link(
2089 wfMessage( 'viewsourcelink' )->escaped(),
2091 array( 'action' => 'edit' )
2094 $outText .= '<li>' . self
::link( $titleObj )
2095 . wfMessage( 'word-separator' )->escaped()
2096 . wfMessage( 'parentheses' )->rawParams( $editLink )->escaped()
2097 . wfMessage( 'word-separator' )->escaped()
2098 . $protected . '</li>';
2101 if ( $more instanceof Title
) {
2102 $outText .= '<li>' . self
::link( $more, wfMessage( 'moredotdotdot' ) ) . '</li>';
2103 } elseif ( $more ) {
2104 $outText .= "<li>$more</li>";
2107 $outText .= '</ul>';
2113 * Returns HTML for the "hidden categories on this page" list.
2115 * @param array $hiddencats Array of hidden categories from Article::getHiddenCategories
2117 * @return string HTML output
2119 public static function formatHiddenCategories( $hiddencats ) {
2122 if ( count( $hiddencats ) > 0 ) {
2123 # Construct the HTML
2124 $outText = '<div class="mw-hiddenCategoriesExplanation">';
2125 $outText .= wfMessage( 'hiddencategories' )->numParams( count( $hiddencats ) )->parseAsBlock();
2126 $outText .= "</div><ul>\n";
2128 foreach ( $hiddencats as $titleObj ) {
2129 # If it's hidden, it must exist - no need to check with a LinkBatch
2131 . self
::link( $titleObj, null, array(), array(), 'known' )
2134 $outText .= '</ul>';
2140 * Format a size in bytes for output, using an appropriate
2141 * unit (B, KB, MB or GB) according to the magnitude in question
2143 * @param int $size Size to format
2146 public static function formatSize( $size ) {
2148 return htmlspecialchars( $wgLang->formatSize( $size ) );
2152 * Given the id of an interface element, constructs the appropriate title
2153 * attribute from the system messages. (Note, this is usually the id but
2154 * isn't always, because sometimes the accesskey needs to go on a different
2155 * element than the id, for reverse-compatibility, etc.)
2157 * @param string $name Id of the element, minus prefixes.
2158 * @param string|null $options Null or the string 'withaccess' to add an access-
2160 * @param array $msgParams Parameters to pass to the message
2162 * @return string Contents of the title attribute (which you must HTML-
2163 * escape), or false for no title attribute
2165 public static function titleAttrib( $name, $options = null, array $msgParams = array() ) {
2166 $message = wfMessage( "tooltip-$name", $msgParams );
2167 if ( !$message->exists() ) {
2170 $tooltip = $message->text();
2171 # Compatibility: formerly some tooltips had [alt-.] hardcoded
2172 $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
2173 # Message equal to '-' means suppress it.
2174 if ( $tooltip == '-' ) {
2179 if ( $options == 'withaccess' ) {
2180 $accesskey = self
::accesskey( $name );
2181 if ( $accesskey !== false ) {
2182 // Should be build the same as in jquery.accessKeyLabel.js
2183 if ( $tooltip === false ||
$tooltip === '' ) {
2184 $tooltip = wfMessage( 'brackets', $accesskey )->text();
2186 $tooltip .= wfMessage( 'word-separator' )->text();
2187 $tooltip .= wfMessage( 'brackets', $accesskey )->text();
2195 public static $accesskeycache;
2198 * Given the id of an interface element, constructs the appropriate
2199 * accesskey attribute from the system messages. (Note, this is usually
2200 * the id but isn't always, because sometimes the accesskey needs to go on
2201 * a different element than the id, for reverse-compatibility, etc.)
2203 * @param string $name Id of the element, minus prefixes.
2204 * @return string Contents of the accesskey attribute (which you must HTML-
2205 * escape), or false for no accesskey attribute
2207 public static function accesskey( $name ) {
2208 if ( isset( self
::$accesskeycache[$name] ) ) {
2209 return self
::$accesskeycache[$name];
2212 $message = wfMessage( "accesskey-$name" );
2214 if ( !$message->exists() ) {
2217 $accesskey = $message->plain();
2218 if ( $accesskey === '' ||
$accesskey === '-' ) {
2219 # @todo FIXME: Per standard MW behavior, a value of '-' means to suppress the
2220 # attribute, but this is broken for accesskey: that might be a useful
2226 self
::$accesskeycache[$name] = $accesskey;
2227 return self
::$accesskeycache[$name];
2231 * Get a revision-deletion link, or disabled link, or nothing, depending
2232 * on user permissions & the settings on the revision.
2234 * Will use forward-compatible revision ID in the Special:RevDelete link
2235 * if possible, otherwise the timestamp-based ID which may break after
2239 * @param Revision $rev
2240 * @param Title $title
2241 * @return string HTML fragment
2243 public static function getRevDeleteLink( User
$user, Revision
$rev, Title
$title ) {
2244 $canHide = $user->isAllowed( 'deleterevision' );
2245 if ( !$canHide && !( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) ) {
2249 if ( !$rev->userCan( Revision
::DELETED_RESTRICTED
, $user ) ) {
2250 return Linker
::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
2252 if ( $rev->getId() ) {
2253 // RevDelete links using revision ID are stable across
2254 // page deletion and undeletion; use when possible.
2256 'type' => 'revision',
2257 'target' => $title->getPrefixedDBkey(),
2258 'ids' => $rev->getId()
2261 // Older deleted entries didn't save a revision ID.
2262 // We have to refer to these by timestamp, ick!
2264 'type' => 'archive',
2265 'target' => $title->getPrefixedDBkey(),
2266 'ids' => $rev->getTimestamp()
2269 return Linker
::revDeleteLink( $query,
2270 $rev->isDeleted( Revision
::DELETED_RESTRICTED
), $canHide );
2275 * Creates a (show/hide) link for deleting revisions/log entries
2277 * @param array $query Query parameters to be passed to link()
2278 * @param bool $restricted Set to true to use a "<strong>" instead of a "<span>"
2279 * @param bool $delete Set to true to use (show/hide) rather than (show)
2281 * @return string HTML "<a>" link to Special:Revisiondelete, wrapped in a
2282 * span to allow for customization of appearance with CSS
2284 public static function revDeleteLink( $query = array(), $restricted = false, $delete = true ) {
2285 $sp = SpecialPage
::getTitleFor( 'Revisiondelete' );
2286 $msgKey = $delete ?
'rev-delundel' : 'rev-showdeleted';
2287 $html = wfMessage( $msgKey )->escaped();
2288 $tag = $restricted ?
'strong' : 'span';
2289 $link = self
::link( $sp, $html, array(), $query, array( 'known', 'noclasses' ) );
2292 array( 'class' => 'mw-revdelundel-link' ),
2293 wfMessage( 'parentheses' )->rawParams( $link )->escaped()
2298 * Creates a dead (show/hide) link for deleting revisions/log entries
2300 * @param bool $delete Set to true to use (show/hide) rather than (show)
2302 * @return string HTML text wrapped in a span to allow for customization
2303 * of appearance with CSS
2305 public static function revDeleteLinkDisabled( $delete = true ) {
2306 $msgKey = $delete ?
'rev-delundel' : 'rev-showdeleted';
2307 $html = wfMessage( $msgKey )->escaped();
2308 $htmlParentheses = wfMessage( 'parentheses' )->rawParams( $html )->escaped();
2309 return Xml
::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), $htmlParentheses );
2312 /* Deprecated methods */
2315 * Returns the attributes for the tooltip and access key.
2317 * @param string $name
2318 * @param array $msgParams Params for constructing the message
2322 public static function tooltipAndAccesskeyAttribs( $name, array $msgParams = array() ) {
2323 # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
2324 # no attribute" instead of "output '' as value for attribute", this
2325 # would be three lines.
2327 'title' => self
::titleAttrib( $name, 'withaccess', $msgParams ),
2328 'accesskey' => self
::accesskey( $name )
2330 if ( $attribs['title'] === false ) {
2331 unset( $attribs['title'] );
2333 if ( $attribs['accesskey'] === false ) {
2334 unset( $attribs['accesskey'] );
2340 * Returns raw bits of HTML, use titleAttrib()
2341 * @param string $name
2342 * @param array|null $options
2343 * @return null|string
2345 public static function tooltip( $name, $options = null ) {
2346 # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
2347 # no attribute" instead of "output '' as value for attribute", this
2348 # would be two lines.
2349 $tooltip = self
::titleAttrib( $name, $options );
2350 if ( $tooltip === false ) {
2353 return Xml
::expandAttributes( array(
2366 * Use PHP's magic __call handler to transform instance calls to a dummy instance
2367 * into static calls to the new Linker for backwards compatibility.
2369 * @param string $fname Name of called method
2370 * @param array $args Arguments to the method
2373 public function __call( $fname, $args ) {
2374 return call_user_func_array( array( 'Linker', $fname ), $args );