3 * Split off some of the internal bits from Skin.php. These functions are used
4 * for primarily page content: links, embedded images, table of contents. Links
5 * are also used in the skin. For the moment, Skin is a descendent class of
6 * Linker. In the future, it should probably be further split so that every
7 * other bit of the wiki doesn't have to go loading up Skin to get at it.
14 * Flags for userToolLinks()
16 const TOOL_LINKS_NOBLOCK
= 1;
18 function __construct() {}
23 function postParseLinkColour( $s = null ) {
24 wfDeprecated( __METHOD__
);
29 * Get the appropriate HTML attributes to add to the "a" element of an ex-
30 * ternal link, as created by [wikisyntax].
32 * @param string $title The (unescaped) title text for the link
33 * @param string $unused Unused
34 * @param string $class The contents of the class attribute; if an empty
35 * string is passed, which is the default value, defaults to 'external'.
37 function getExternalLinkAttributes( $title, $unused = null, $class='' ) {
38 return $this->getLinkAttributesInternal( $title, $class, 'external' );
42 * Get the appropriate HTML attributes to add to the "a" element of an in-
45 * @param string $title The title text for the link, URL-encoded (???) but
47 * @param string $unused Unused
48 * @param string $class The contents of the class attribute; if an empty
49 * string is passed, which is the default value, defaults to 'external'.
51 function getInterwikiLinkAttributes( $title, $unused = null, $class='' ) {
54 # FIXME: We have a whole bunch of handling here that doesn't happen in
55 # getExternalLinkAttributes, why?
56 $title = urldecode( $title );
57 $title = $wgContLang->checkTitleEncoding( $title );
58 $title = preg_replace( '/[\\x00-\\x1f]/', ' ', $title );
60 return $this->getLinkAttributesInternal( $title, $class, 'external' );
64 * Get the appropriate HTML attributes to add to the "a" element of an in-
67 * @param string $title The title text for the link, URL-encoded (???) but
69 * @param string $unused Unused
70 * @param string $class The contents of the class attribute, default none
72 function getInternalLinkAttributes( $title, $unused = null, $class='' ) {
73 $title = urldecode( $title );
74 $title = str_replace( '_', ' ', $title );
75 return $this->getLinkAttributesInternal( $title, $class );
79 * Get the appropriate HTML attributes to add to the "a" element of an in-
80 * ternal link, given the Title object for the page we want to link to.
82 * @param Title $nt The Title object
83 * @param string $unused Unused
84 * @param string $class The contents of the class attribute, default none
85 * @param mixed $title Optional (unescaped) string to use in the title
86 * attribute; if false, default to the name of the page we're linking to
88 function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) {
89 if( $title === false ) {
90 $title = $nt->getPrefixedText();
92 return $this->getLinkAttributesInternal( $title, $class );
96 * Common code for getLinkAttributesX functions
98 private function getLinkAttributesInternal( $title, $class, $classDefault = false ) {
99 $title = htmlspecialchars( $title );
100 if( $class === '' and $classDefault !== false ) {
101 # FIXME: Parameter defaults the hard way! We should just have
102 # $class = 'external' or whatever as the default in the externally-
103 # exposed functions, not $class = ''.
104 $class = $classDefault;
106 $class = htmlspecialchars( $class );
108 if( $class !== '' ) {
109 $r .= " class=\"$class\"";
111 $r .= " title=\"$title\"";
116 * Return the CSS colour of a known link
119 * @param integer $threshold user defined threshold
120 * @return string CSS class
122 function getLinkColour( $t, $threshold ) {
124 if ( $t->isRedirect() ) {
126 $colour = 'mw-redirect';
127 } elseif ( $threshold > 0 && $t->getLength() < $threshold && MWNamespace
::isContent( $t->getNamespace() ) ) {
135 * This function returns an HTML link to the given target. It serves a few
137 * 1) If $target is a Title, the correct URL to link to will be figured
139 * 2) It automatically adds the usual classes for various types of link
140 * targets: "new" for red links, "stub" for short articles, etc.
141 * 3) It escapes all attribute values safely so there's no risk of XSS.
142 * 4) It provides a default tooltip if the target is a Title (the page
143 * name of the target).
144 * link() replaces the old functions in the makeLink() family.
146 * @param $target Title Can currently only be a Title, but this may
147 * change to support Images, literal URLs, etc.
148 * @param $text string The HTML contents of the <a> element, i.e.,
149 * the link text. This is raw HTML and will not be escaped. If null,
150 * defaults to the prefixed text of the Title; or if the Title is just a
151 * fragment, the contents of the fragment.
152 * @param $query array The query string to append to the URL
153 * you're linking to, in key => value array form. Query keys and values
154 * will be URL-encoded.
155 * @param $customAttribs array A key => value array of extra HTML attri-
156 * butes, such as title and class. (href is ignored.) Classes will be
157 * merged with the default classes, while other attributes will replace
158 * default attributes. All passed attribute values will be HTML-escaped.
159 * A false attribute value means to suppress that attribute.
160 * @param $options mixed String or array of strings:
161 * 'known': Page is known to exist, so don't check if it does.
162 * 'broken': Page is known not to exist, so don't check if it does.
163 * 'noclasses': Don't add any classes automatically (includes "new",
164 * "stub", "mw-redirect"). Only use the class attribute provided, if
166 * @return string HTML <a> attribute
168 public function link( $target, $text = null, $customAttribs = array(), $query = array(), $options = array() ) {
169 wfProfileIn( __METHOD__
);
170 if( !($target instanceof Title
) ) {
171 throw new MWException( 'Linker::link passed invalid target' );
173 $options = (array)$options;
175 # Normalize the Title if it's a special page
176 if( $target->getNamespace() == NS_SPECIAL
) {
177 list( $name, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $target->getDBkey() );
179 $target = SpecialPage
::getTitleFor( $name, $subpage );
183 # If we don't know whether the page exists, let's find out.
184 if( !in_array( 'known', $options ) and !in_array( 'broken', $options ) ) {
185 if( $target->getNamespace() == NS_SPECIAL
) {
186 if( SpecialPage
::exists( $target->getDbKey() ) ) {
187 $options []= 'known';
189 $options []= 'broken';
191 } elseif( $target->isAlwaysKnown() or
192 ($target->getPrefixedText() == '' and $target->getFragment() != '')
193 or $target->exists() ) {
194 $options []= 'known';
197 $options []= 'broken';
201 # Note: we want the href attribute first, for prettiness.
202 $attribs = array( 'href' => $this->linkUrl( $target, $query, $options ) );
203 $attribs = array_merge(
205 $this->linkAttribs( $target, $customAttribs, $options )
207 if( is_null( $text ) ) {
208 $text = $this->linkText( $target, $options );
211 $ret = Xml
::element( 'a', $attribs, $text, false );
213 wfProfileOut( __METHOD__
);
217 private function linkUrl( $target, $query, $options ) {
218 # If it's a broken link, add the appropriate query pieces. This over-
219 # writes the default action!
220 if( in_array( 'broken', $options ) ) {
221 $query['action'] = 'edit';
222 $query['redlink'] = '1';
224 $ret = $target->getLocalURL( $query );
225 if( $target->getFragment() !== '' ) {
226 $ret .= '#'.$target->getFragment();
231 private function linkAttribs( $target, $attribs, $options ) {
235 # First get a default title attribute.
236 if( in_array( 'known', $options ) ) {
237 $defaults['title'] = $target->getPrefixedText();
239 $defaults['title'] = wfMsg( 'red-link-title', $target->getPrefixedText() );
242 if( !in_array( 'noclasses', $options ) ) {
243 # Now build the classes. This is the bulk of what we're doing.
246 if( in_array( 'broken', $options ) ) {
250 # Note that redirects never count as stubs here.
251 if ( $target->isRedirect() ) {
252 $classes []= 'mw-redirect';
253 } elseif( $target->isContentPage() ) {
254 $threshold = $wgUser->getOption( 'stubthreshold' );
255 if( $threshold > 0 and $target->getLength() < $threshold ) {
259 if( $classes != array() ) {
260 $defaults['class'] = implode( ' ', $classes );
264 # Finally, merge the custom attribs with the default ones, and iterate
265 # over that, deleting all "false" attributes.
267 $merged = Sanitizer
::mergeAttributes( $defaults, $attribs );
268 foreach( $merged as $key => $val ) {
269 # A false value suppresses the attribute, and we don't want the
270 # href attribute to be overridden.
271 if( $key != 'href' and $val !== false ) {
278 private function linkText( $target, $options ) {
279 # If the target is just a fragment, with no title, we return the frag-
280 # ment text. Otherwise, we return the title text itself.
281 if( $target->getPrefixedText() === '' and $target->getFragment() !== '' ) {
282 return htmlspecialchars( $target->getFragment() );
284 return htmlspecialchars( $target->getPrefixedText() );
288 * This function is a shortcut to makeLinkObj(Title::newFromText($title),...). Do not call
289 * it if you already have a title object handy. See makeLinkObj for further documentation.
291 * @param $title String: the text of the title
292 * @param $text String: link text
293 * @param $query String: optional query part
294 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
295 * be included in the link text. Other characters will be appended after
296 * the end of the link.
298 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
299 wfProfileIn( __METHOD__
);
300 $nt = Title
::newFromText( $title );
301 if ( $nt instanceof Title
) {
302 $result = $this->makeLinkObj( $nt, $text, $query, $trail );
304 wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" );
305 $result = $text == "" ?
$title : $text;
308 wfProfileOut( __METHOD__
);
313 * This function is a shortcut to makeKnownLinkObj(Title::newFromText($title),...). Do not call
314 * it if you already have a title object handy. See makeKnownLinkObj for further documentation.
316 * @param $title String: the text of the title
317 * @param $text String: link text
318 * @param $query String: optional query part
319 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
320 * be included in the link text. Other characters will be appended after
321 * the end of the link.
323 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
324 $nt = Title
::newFromText( $title );
325 if ( $nt instanceof Title
) {
326 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix , $aprops );
328 wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" );
329 return $text == '' ?
$title : $text;
334 * This function is a shortcut to makeBrokenLinkObj(Title::newFromText($title),...). Do not call
335 * it if you already have a title object handy. See makeBrokenLinkObj for further documentation.
337 * @param string $title The text of the title
338 * @param string $text Link text
339 * @param string $query Optional query part
340 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
341 * be included in the link text. Other characters will be appended after
342 * the end of the link.
344 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
345 $nt = Title
::newFromText( $title );
346 if ( $nt instanceof Title
) {
347 return $this->makeBrokenLinkObj( $nt, $text, $query, $trail );
349 wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" );
350 return $text == '' ?
$title : $text;
355 * @deprecated use makeColouredLinkObj
357 * This function is a shortcut to makeStubLinkObj(Title::newFromText($title),...). Do not call
358 * it if you already have a title object handy. See makeStubLinkObj for further documentation.
360 * @param $title String: the text of the title
361 * @param $text String: link text
362 * @param $query String: optional query part
363 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
364 * be included in the link text. Other characters will be appended after
365 * the end of the link.
367 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
368 $nt = Title
::newFromText( $title );
369 if ( $nt instanceof Title
) {
370 return $this->makeStubLinkObj( $nt, $text, $query, $trail );
372 wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" );
373 return $text == '' ?
$title : $text;
378 * Make a link for a title which may or may not be in the database. If you need to
379 * call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
380 * call to this will result in a DB query.
382 * @param $nt Title: the title object to make the link from, e.g. from
383 * Title::newFromText.
384 * @param $text String: link text
385 * @param $query String: optional query part
386 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
387 * be included in the link text. Other characters will be appended after
388 * the end of the link.
389 * @param $prefix String: optional prefix. As trail, only before instead of after.
391 function makeLinkObj( Title
$nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
393 wfProfileIn( __METHOD__
);
395 if ( $nt->isExternal() ) {
396 $u = $nt->getFullURL();
397 $link = $nt->getPrefixedURL();
398 if ( '' == $text ) { $text = $nt->getPrefixedText(); }
399 $style = $this->getInterwikiLinkAttributes( $link, $text, 'extiw' );
402 if ( '' != $trail ) {
404 if ( preg_match( '/^([a-z]+)(.*)$$/sD', $trail, $m ) ) {
409 $t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
411 wfProfileOut( __METHOD__
);
413 } elseif ( $nt->isAlwaysKnown() ) {
414 # Image links, special page links and self-links with fragments are always known.
415 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
417 wfProfileIn( __METHOD__
.'-immediate' );
419 # Handles links to special pages which do not exist in the database:
420 if( $nt->getNamespace() == NS_SPECIAL
) {
421 if( SpecialPage
::exists( $nt->getDBkey() ) ) {
422 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
424 $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
426 wfProfileOut( __METHOD__
.'-immediate' );
427 wfProfileOut( __METHOD__
);
431 # Work out link colour immediately
432 $aid = $nt->getArticleID() ;
434 $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
437 if ( $nt->isContentPage() ) {
438 $threshold = $wgUser->getOption('stubthreshold');
439 $colour = $this->getLinkColour( $nt, $threshold );
441 $retVal = $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
443 wfProfileOut( __METHOD__
.'-immediate' );
445 wfProfileOut( __METHOD__
);
450 * Make a link for a title which definitely exists. This is faster than makeLinkObj because
451 * it doesn't have to do a database query. It's also valid for interwiki titles and special
454 * @param $nt Title object of target page
455 * @param $text String: text to replace the title
456 * @param $query String: link target
457 * @param $trail String: text after link
458 * @param $prefix String: text before link text
459 * @param $aprops String: extra attributes to the a-element
460 * @param $style String: style to apply - if empty, use getInternalLinkAttributesObj instead
461 * @return the a-element
463 function makeKnownLinkObj( Title
$title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
464 wfProfileIn( __METHOD__
);
466 $nt = $this->normaliseSpecialPage( $title );
468 $u = $nt->escapeLocalURL( $query );
469 if ( $nt->getFragment() != '' ) {
470 if( $nt->getPrefixedDbkey() == '' ) {
473 $text = htmlspecialchars( $nt->getFragment() );
476 $u .= $nt->getFragmentForURL();
479 $text = htmlspecialchars( $nt->getPrefixedText() );
481 if ( $style == '' ) {
482 $style = $this->getInternalLinkAttributesObj( $nt, $text );
485 if ( $aprops !== '' ) $aprops = " $aprops";
487 list( $inside, $trail ) = Linker
::splitTrail( $trail );
488 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
489 wfProfileOut( __METHOD__
);
494 * Make a red link to the edit page of a given title.
496 * @param $nt Title object of the target page
497 * @param $text String: Link text
498 * @param $query String: Optional query part
499 * @param $trail String: Optional trail. Alphabetic characters at the start of this string will
500 * be included in the link text. Other characters will be appended after
501 * the end of the link.
503 function makeBrokenLinkObj( Title
$title, $text = '', $query = '', $trail = '', $prefix = '' ) {
504 wfProfileIn( __METHOD__
);
506 $nt = $this->normaliseSpecialPage( $title );
508 if( $nt->getNamespace() == NS_SPECIAL
) {
510 } else if ( '' == $query ) {
511 $q = 'action=edit&redlink=1';
513 $q = 'action=edit&redlink=1&'.$query;
515 $u = $nt->escapeLocalURL( $q );
517 $titleText = $nt->getPrefixedText();
519 $text = htmlspecialchars( $titleText );
521 $titleAttr = wfMsg( 'red-link-title', $titleText );
522 $style = $this->getInternalLinkAttributesObj( $nt, $text, 'new', $titleAttr );
523 list( $inside, $trail ) = Linker
::splitTrail( $trail );
525 wfRunHooks( 'BrokenLink', array( &$this, $nt, $query, &$u, &$style, &$prefix, &$text, &$inside, &$trail ) );
526 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
528 wfProfileOut( __METHOD__
);
533 * @deprecated use makeColouredLinkObj
535 * Make a brown link to a short article.
537 * @param $nt Title object of the target page
538 * @param $text String: link text
539 * @param $query String: optional query part
540 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
541 * be included in the link text. Other characters will be appended after
542 * the end of the link.
544 function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
545 wfDeprecated( __METHOD__
);
546 return $this->makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix );
550 * Make a coloured link.
552 * @param $nt Title object of the target page
553 * @param $colour Integer: colour of the link
554 * @param $text String: link text
555 * @param $query String: optional query part
556 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
557 * be included in the link text. Other characters will be appended after
558 * the end of the link.
560 function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
562 $style = $this->getInternalLinkAttributesObj( $nt, $text, $colour );
564 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style );
568 * Generate either a normal exists-style link or a stub link, depending
569 * on the given page size.
571 * @param $size Integer
572 * @param $nt Title object.
573 * @param $text String
574 * @param $query String
575 * @param $trail String
576 * @param $prefix String
577 * @return string HTML of link
579 function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
581 $threshold = intval( $wgUser->getOption( 'stubthreshold' ) );
582 $colour = ( $size < $threshold ) ?
'stub' : '';
583 return $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
587 * Make appropriate markup for a link to the current article. This is currently rendered
588 * as the bold link text. The calling sequence is the same as the other make*LinkObj functions,
589 * despite $query not being used.
591 function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
593 $text = htmlspecialchars( $nt->getPrefixedText() );
595 list( $inside, $trail ) = Linker
::splitTrail( $trail );
596 return "<strong class=\"selflink\">{$prefix}{$text}{$inside}</strong>{$trail}";
599 function normaliseSpecialPage( Title
$title ) {
600 if ( $title->getNamespace() == NS_SPECIAL
) {
601 list( $name, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $title->getDBkey() );
602 if ( !$name ) return $title;
603 return SpecialPage
::getTitleFor( $name, $subpage );
609 /** @todo document */
610 function fnamePart( $url ) {
611 $basename = strrchr( $url, '/' );
612 if ( false === $basename ) {
615 $basename = substr( $basename, 1 );
620 /** Obsolete alias */
621 function makeImage( $url, $alt = '' ) {
622 wfDeprecated( __METHOD__
);
623 return $this->makeExternalImage( $url, $alt );
626 /** @todo document */
627 function makeExternalImage( $url, $alt = '' ) {
629 $alt = $this->fnamePart( $url );
632 $success = wfRunHooks('LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
634 wfDebug("Hook LinkerMakeExternalImage changed the output of external image with url {$url} and alt text {$alt} to {$img}", true);
637 return Xml
::element( 'img',
644 * Creates the HTML source for images
645 * @deprecated use makeImageLink2
647 * @param object $title
648 * @param string $label label text
649 * @param string $alt alt text
650 * @param string $align horizontal alignment: none, left, center, right)
651 * @param array $handlerParams Parameters to be passed to the media handler
652 * @param boolean $framed shows image in original size in a frame
653 * @param boolean $thumb shows image as thumbnail in a frame
654 * @param string $manualthumb image name for the manual thumbnail
655 * @param string $valign vertical alignment: baseline, sub, super, top, text-top, middle, bottom, text-bottom
656 * @param string $time, timestamp of the file, set as false for current
659 function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(), $framed = false,
660 $thumb = false, $manualthumb = '', $valign = '', $time = false )
662 $frameParams = array( 'alt' => $alt, 'caption' => $label );
664 $frameParams['align'] = $align;
667 $frameParams['framed'] = true;
670 $frameParams['thumbnail'] = true;
672 if ( $manualthumb ) {
673 $frameParams['manualthumb'] = $manualthumb;
676 $frameParams['valign'] = $valign;
678 $file = wfFindFile( $title, $time );
679 return $this->makeImageLink2( $title, $file, $frameParams, $handlerParams, $time );
683 * Given parameters derived from [[Image:Foo|options...]], generate the
684 * HTML that that syntax inserts in the page.
686 * @param Title $title Title object
687 * @param File $file File object, or false if it doesn't exist
689 * @param array $frameParams Associative array of parameters external to the media handler.
690 * Boolean parameters are indicated by presence or absence, the value is arbitrary and
691 * will often be false.
692 * thumbnail If present, downscale and frame
693 * manualthumb Image name to use as a thumbnail, instead of automatic scaling
694 * framed Shows image in original size in a frame
695 * frameless Downscale but don't frame
696 * upright If present, tweak default sizes for portrait orientation
697 * upright_factor Fudge factor for "upright" tweak (default 0.75)
698 * border If present, show a border around the image
699 * align Horizontal alignment (left, right, center, none)
700 * valign Vertical alignment (baseline, sub, super, top, text-top, middle,
701 * bottom, text-bottom)
702 * alt Alternate text for image (i.e. alt attribute). Plain text.
703 * caption HTML for image caption.
705 * @param array $handlerParams Associative array of media handler parameters, to be passed
706 * to transform(). Typical keys are "width" and "page".
707 * @param string $time, timestamp of the file, set as false for current
708 * @param string $query, query params for desc url
709 * @return string HTML for an image, with links, wrappers, etc.
711 function makeImageLink2( Title
$title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
713 if( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$this, &$title,
714 &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
718 global $wgContLang, $wgUser, $wgThumbLimits, $wgThumbUpright;
719 if ( $file && !$file->allowInlineDisplay() ) {
720 wfDebug( __METHOD__
.': '.$title->getPrefixedDBkey()." does not allow inline display\n" );
721 return $this->link( $title );
726 $hp =& $handlerParams;
728 // Clean up parameters
729 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
730 if ( !isset( $fp['align'] ) ) $fp['align'] = '';
731 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
733 $prefix = $postfix = '';
735 if ( 'center' == $fp['align'] )
737 $prefix = '<div class="center">';
739 $fp['align'] = 'none';
741 if ( $file && !isset( $hp['width'] ) ) {
742 $hp['width'] = $file->getWidth( $page );
744 if( isset( $fp['thumbnail'] ) ||
isset( $fp['framed'] ) ||
isset( $fp['frameless'] ) ||
!$hp['width'] ) {
745 $wopt = $wgUser->getOption( 'thumbsize' );
747 if( !isset( $wgThumbLimits[$wopt] ) ) {
748 $wopt = User
::getDefaultOption( 'thumbsize' );
751 // Reduce width for upright images when parameter 'upright' is used
752 if ( isset( $fp['upright'] ) && $fp['upright'] == 0 ) {
753 $fp['upright'] = $wgThumbUpright;
755 // Use width which is smaller: real image width or user preference width
756 // 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
757 $prefWidth = isset( $fp['upright'] ) ?
758 round( $wgThumbLimits[$wopt] * $fp['upright'], -1 ) :
759 $wgThumbLimits[$wopt];
760 if ( $hp['width'] <= 0 ||
$prefWidth < $hp['width'] ) {
761 $hp['width'] = $prefWidth;
766 if ( isset( $fp['thumbnail'] ) ||
isset( $fp['manualthumb'] ) ||
isset( $fp['framed'] ) ) {
768 # Create a thumbnail. Alignment depends on language
769 # writing direction, # right aligned for left-to-right-
770 # languages ("Western languages"), left-aligned
771 # for right-to-left-languages ("Semitic languages")
773 # If thumbnail width has not been provided, it is set
774 # to the default user option as specified in Language*.php
775 if ( $fp['align'] == '' ) {
776 $fp['align'] = $wgContLang->isRTL() ?
'left' : 'right';
778 return $prefix.$this->makeThumbLink2( $title, $file, $fp, $hp, $time, $query ).$postfix;
781 if ( $file && isset( $fp['frameless'] ) ) {
782 $srcWidth = $file->getWidth( $page );
783 # For "frameless" option: do not present an image bigger than the source (for bitmap-style images)
784 # This is the same behaviour as the "thumb" option does it already.
785 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
786 $hp['width'] = $srcWidth;
790 if ( $file && $hp['width'] ) {
791 # Create a resized image, without the additional thumbnail features
792 $thumb = $file->transform( $hp );
798 $s = $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
800 $s = $thumb->toHtml( array(
802 'desc-query' => $query,
804 'valign' => isset( $fp['valign'] ) ?
$fp['valign'] : false ,
805 'img-class' => isset( $fp['border'] ) ?
'thumbborder' : false ) );
807 if ( '' != $fp['align'] ) {
808 $s = "<div class=\"float{$fp['align']}\"><span>{$s}</span></div>";
810 return str_replace("\n", ' ',$prefix.$s.$postfix);
814 * Make HTML for a thumbnail including image, border and caption
815 * @param Title $title
816 * @param File $file File object or false if it doesn't exist
818 function makeThumbLinkObj( Title
$title, $file, $label = '', $alt, $align = 'right', $params = array(), $framed=false , $manualthumb = "" ) {
819 $frameParams = array(
824 if ( $framed ) $frameParams['framed'] = true;
825 if ( $manualthumb ) $frameParams['manualthumb'] = $manualthumb;
826 return $this->makeThumbLink2( $title, $file, $frameParams, $params );
829 function makeThumbLink2( Title
$title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
830 global $wgStylePath, $wgContLang;
831 $exists = $file && $file->exists();
835 $hp =& $handlerParams;
837 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
838 if ( !isset( $fp['align'] ) ) $fp['align'] = 'right';
839 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
840 if ( !isset( $fp['caption'] ) ) $fp['caption'] = '';
842 if ( empty( $hp['width'] ) ) {
843 // Reduce width for upright images when parameter 'upright' is used
844 $hp['width'] = isset( $fp['upright'] ) ?
130 : 180;
849 $outerWidth = $hp['width'] +
2;
851 if ( isset( $fp['manualthumb'] ) ) {
852 # Use manually specified thumbnail
853 $manual_title = Title
::makeTitleSafe( NS_IMAGE
, $fp['manualthumb'] );
854 if( $manual_title ) {
855 $manual_img = wfFindFile( $manual_title );
857 $thumb = $manual_img->getUnscaledThumb();
862 } elseif ( isset( $fp['framed'] ) ) {
863 // Use image dimensions, don't scale
864 $thumb = $file->getUnscaledThumb( $page );
866 # Do not present an image bigger than the source, for bitmap-style images
867 # This is a hack to maintain compatibility with arbitrary pre-1.10 behaviour
868 $srcWidth = $file->getWidth( $page );
869 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
870 $hp['width'] = $srcWidth;
872 $thumb = $file->transform( $hp );
876 $outerWidth = $thumb->getWidth() +
2;
878 $outerWidth = $hp['width'] +
2;
883 $query = $query ?
'&page=' . urlencode( $page ) : 'page=' . urlencode( $page );
885 $url = $title->getLocalURL( $query );
887 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
889 $s = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
891 $s .= $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
893 } elseif ( !$thumb ) {
894 $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
897 $s .= $thumb->toHtml( array(
899 'img-class' => 'thumbimage',
901 'desc-query' => $query ) );
902 if ( isset( $fp['framed'] ) ) {
905 $zoomicon = '<div class="magnify">'.
906 '<a href="'.$url.'" class="internal" title="'.$more.'">'.
907 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
908 'width="15" height="11" alt="" /></a></div>';
911 $s .= ' <div class="thumbcaption">'.$zoomicon.$fp['caption']."</div></div></div>";
912 return str_replace("\n", ' ', $s);
916 * Make a "broken" link to an image
918 * @param Title $title Image title
919 * @param string $text Link label
920 * @param string $query Query string
921 * @param string $trail Link trail
922 * @param string $prefix Link prefix
923 * @param bool $time, a file of a certain timestamp was requested
926 public function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '', $time = false ) {
927 global $wgEnableUploads;
928 if( $title instanceof Title
) {
929 wfProfileIn( __METHOD__
);
930 $currentExists = $time ?
( wfFindFile( $title ) != false ) : false;
931 if( $wgEnableUploads && !$currentExists ) {
932 $upload = SpecialPage
::getTitleFor( 'Upload' );
934 $text = htmlspecialchars( $title->getPrefixedText() );
935 $redir = RepoGroup
::singleton()->getLocalRepo()->checkRedirect( $title );
937 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
939 $q = 'wpDestFile=' . $title->getPartialUrl();
942 list( $inside, $trail ) = self
::splitTrail( $trail );
943 $style = $this->getInternalLinkAttributesObj( $title, $text, 'new' );
944 wfProfileOut( __METHOD__
);
945 return '<a href="' . $upload->escapeLocalUrl( $q ) . '"'
946 . $style . '>' . $prefix . $text . $inside . '</a>' . $trail;
948 wfProfileOut( __METHOD__
);
949 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
952 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
956 /** @deprecated use Linker::makeMediaLinkObj() */
957 function makeMediaLink( $name, $unused = '', $text = '', $time = false ) {
958 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
959 return $this->makeMediaLinkObj( $nt, $text, $time );
963 * Create a direct link to a given uploaded file.
965 * @param $title Title object.
966 * @param $text String: pre-sanitized HTML
967 * @param $time string: time image was created
968 * @return string HTML
971 * @todo Handle invalid or missing images better.
973 function makeMediaLinkObj( $title, $text = '', $time = false ) {
974 if( is_null( $title ) ) {
975 ### HOTFIX. Instead of breaking, return empty string.
978 $img = wfFindFile( $title, $time );
980 $url = $img->getURL();
983 $upload = SpecialPage
::getTitleFor( 'Upload' );
984 $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $title->getDBkey() ) );
987 $alt = htmlspecialchars( $title->getText() );
991 $u = htmlspecialchars( $url );
992 return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\">{$text}</a>";
996 /** @todo document */
997 function specialLink( $name, $key = '' ) {
1000 if ( '' == $key ) { $key = strtolower( $name ); }
1001 $pn = $wgContLang->ucfirst( $name );
1002 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1006 /** @todo document */
1007 function makeExternalLink( $url, $text, $escape = true, $linktype = '', $ns = null ) {
1008 $style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
1009 global $wgNoFollowLinks, $wgNoFollowNsExceptions;
1010 if( $wgNoFollowLinks && !(isset($ns) && in_array($ns, $wgNoFollowNsExceptions)) ) {
1011 $style .= ' rel="nofollow"';
1013 $url = htmlspecialchars( $url );
1015 $text = htmlspecialchars( $text );
1018 $success = wfRunHooks('LinkerMakeExternalLink', array( &$url, &$text, &$link ) );
1020 wfDebug("Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}", true);
1023 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
1027 * Make user link (or user contributions for unregistered users)
1028 * @param $userId Integer: user id in database.
1029 * @param $userText String: user name in database
1030 * @return string HTML fragment
1033 function userLink( $userId, $userText ) {
1034 $encName = htmlspecialchars( $userText );
1035 if( $userId == 0 ) {
1036 $page = SpecialPage
::getTitleFor( 'Contributions', $userText );
1038 $page = Title
::makeTitle( NS_USER
, $userText );
1040 return $this->link( $page, $encName );
1044 * Generate standard user tool links (talk, contributions, block link, etc.)
1046 * @param int $userId User identifier
1047 * @param string $userText User name or IP address
1048 * @param bool $redContribsWhenNoEdits Should the contributions link be red if the user has no edits?
1049 * @param int $flags Customisation flags (e.g. self::TOOL_LINKS_NOBLOCK)
1050 * @param int $edits, user edit count (optional, for performance)
1053 public function userToolLinks( $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits=null ) {
1054 global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans;
1055 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
1056 $blockable = ( $wgSysopUserBans ||
0 == $userId ) && !$flags & self
::TOOL_LINKS_NOBLOCK
;
1060 $items[] = $this->userTalkLink( $userId, $userText );
1063 // check if the user has an edit
1065 if( $redContribsWhenNoEdits ) {
1066 $count = !is_null($edits) ?
$edits : User
::edits( $userId );
1068 $attribs['class'] = 'new';
1071 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $userText );
1073 $items[] = $this->link( $contribsPage, wfMsgHtml( 'contribslink' ), $attribs );
1075 if( $blockable && $wgUser->isAllowed( 'block' ) ) {
1076 $items[] = $this->blockLink( $userId, $userText );
1080 return ' (' . implode( ' | ', $items ) . ')';
1087 * Alias for userToolLinks( $userId, $userText, true );
1088 * @param int $userId User identifier
1089 * @param string $userText User name or IP address
1090 * @param int $edits, user edit count (optional, for performance)
1092 public function userToolLinksRedContribs( $userId, $userText, $edits=null ) {
1093 return $this->userToolLinks( $userId, $userText, true, 0, $edits );
1098 * @param $userId Integer: user id in database.
1099 * @param $userText String: user name in database.
1100 * @return string HTML fragment with user talk link
1103 function userTalkLink( $userId, $userText ) {
1104 $userTalkPage = Title
::makeTitle( NS_USER_TALK
, $userText );
1105 $userTalkLink = $this->link( $userTalkPage, wfMsgHtml( 'talkpagelinktext' ) );
1106 return $userTalkLink;
1110 * @param $userId Integer: userid
1111 * @param $userText String: user name in database.
1112 * @return string HTML fragment with block link
1115 function blockLink( $userId, $userText ) {
1116 $blockPage = SpecialPage
::getTitleFor( 'Blockip', $userText );
1117 $blockLink = $this->link( $blockPage, wfMsgHtml( 'blocklink' ) );
1122 * Generate a user link if the current user is allowed to view it
1123 * @param $rev Revision object.
1124 * @param $isPublic, bool, show only if all users can see it
1125 * @return string HTML
1127 function revUserLink( $rev, $isPublic = false ) {
1128 if( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1129 $link = wfMsgHtml( 'rev-deleted-user' );
1130 } else if( $rev->userCan( Revision
::DELETED_USER
) ) {
1131 $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() );
1133 $link = wfMsgHtml( 'rev-deleted-user' );
1135 if( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1136 return '<span class="history-deleted">' . $link . '</span>';
1142 * Generate a user tool link cluster if the current user is allowed to view it
1143 * @param $rev Revision object.
1144 * @param $isPublic, bool, show only if all users can see it
1145 * @return string HTML
1147 function revUserTools( $rev, $isPublic = false ) {
1148 if( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1149 $link = wfMsgHtml( 'rev-deleted-user' );
1150 } else if( $rev->userCan( Revision
::DELETED_USER
) ) {
1151 $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() ) .
1152 ' ' . $this->userToolLinks( $rev->getRawUser(), $rev->getRawUserText() );
1154 $link = wfMsgHtml( 'rev-deleted-user' );
1156 if( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1157 return ' <span class="history-deleted">' . $link . '</span>';
1163 * This function is called by all recent changes variants, by the page history,
1164 * and by the user contributions list. It is responsible for formatting edit
1165 * comments. It escapes any HTML in the comment, but adds some CSS to format
1166 * auto-generated comments (from section editing) and formats [[wikilinks]].
1168 * @author Erik Moeller <moeller@scireview.de>
1170 * Note: there's not always a title to pass to this function.
1171 * Since you can't set a default parameter for a reference, I've turned it
1172 * temporarily to a value pass. Should be adjusted further. --brion
1174 * @param string $comment
1175 * @param mixed $title Title object (to generate link to the section in autocomment) or null
1176 * @param bool $local Whether section links should refer to local page
1178 function formatComment($comment, $title = NULL, $local = false) {
1179 wfProfileIn( __METHOD__
);
1181 # Sanitize text a bit:
1182 $comment = str_replace( "\n", " ", $comment );
1183 $comment = htmlspecialchars( $comment );
1185 # Render autocomments and make links:
1186 $comment = $this->formatAutoComments( $comment, $title, $local );
1187 $comment = $this->formatLinksInComment( $comment );
1189 wfProfileOut( __METHOD__
);
1194 * The pattern for autogen comments is / * foo * /, which makes for
1196 * We look for all comments, match any text before and after the comment,
1197 * add a separator where needed and format the comment itself with CSS
1198 * Called by Linker::formatComment.
1200 * @param string $comment Comment text
1201 * @param object $title An optional title object used to links to sections
1202 * @return string $comment formatted comment
1204 * @todo Document the $local parameter.
1206 private function formatAutocomments( $comment, $title = NULL, $local = false ) {
1208 while (preg_match('!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment,$match)) {
1216 # Generate a valid anchor name from the section title.
1217 # Hackish, but should generally work - we strip wiki
1218 # syntax, including the magic [[: that is used to
1219 # "link rather than show" in case of images and
1220 # interlanguage links.
1221 $section = str_replace( '[[:', '', $section );
1222 $section = str_replace( '[[', '', $section );
1223 $section = str_replace( ']]', '', $section );
1225 $sectionTitle = Title
::newFromText( '#' . $section);
1227 $sectionTitle = wfClone( $title );
1228 $sectionTitle->setFragment( $section );
1230 $link = $this->link( $sectionTitle, wfMsgForContent( 'sectionlink' ) );
1232 $auto = $link . $auto;
1234 # written summary $presep autocomment (summary /* section */)
1235 $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
1238 # autocomment $postsep written summary (/* section */ summary)
1239 $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
1241 $auto = '<span class="autocomment">' . $auto . '</span>';
1242 $comment = $pre . $auto . $post;
1249 * Formats wiki links and media links in text; all other wiki formatting
1252 * @fixme doesn't handle sub-links as in image thumb texts like the main parser
1253 * @param string $comment Text to format links in
1256 public function formatLinksInComment( $comment ) {
1257 return preg_replace_callback(
1258 '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
1259 array( $this, 'formatLinksInCommentCallback' ),
1263 protected function formatLinksInCommentCallback( $match ) {
1266 $medians = '(?:' . preg_quote( MWNamespace
::getCanonicalName( NS_MEDIA
), '/' ) . '|';
1267 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA
), '/' ) . '):';
1269 $comment = $match[0];
1271 # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
1272 if( strpos( $match[1], '%' ) !== false ) {
1273 $match[1] = str_replace( array('<', '>'), array('<', '>'), urldecode($match[1]) );
1276 # Handle link renaming [[foo|text]] will show link as "text"
1277 if( "" != $match[3] ) {
1282 $submatch = array();
1283 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1284 # Media link; trail not supported.
1285 $linkRegexp = '/\[\[(.*?)\]\]/';
1286 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
1288 # Other kind of link
1289 if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
1290 $trail = $submatch[1];
1294 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1295 if (isset($match[1][0]) && $match[1][0] == ':')
1296 $match[1] = substr($match[1], 1);
1297 $thelink = $this->makeLink( $match[1], $text, "", $trail );
1299 $comment = preg_replace( $linkRegexp, StringUtils
::escapeRegexReplacement( $thelink ), $comment, 1 );
1305 * Wrap a comment in standard punctuation and formatting if
1306 * it's non-empty, otherwise return empty string.
1308 * @param string $comment
1309 * @param mixed $title Title object (to generate link to section in autocomment) or null
1310 * @param bool $local Whether section links should refer to local page
1314 function commentBlock( $comment, $title = NULL, $local = false ) {
1315 // '*' used to be the comment inserted by the software way back
1316 // in antiquity in case none was provided, here for backwards
1317 // compatability, acc. to brion -ævar
1318 if( $comment == '' ||
$comment == '*' ) {
1321 $formatted = $this->formatComment( $comment, $title, $local );
1322 return " <span class=\"comment\">($formatted)</span>";
1327 * Wrap and format the given revision's comment block, if the current
1328 * user is allowed to view it.
1330 * @param Revision $rev
1331 * @param bool $local Whether section links should refer to local page
1332 * @param $isPublic, show only if all users can see it
1333 * @return string HTML
1335 function revComment( Revision
$rev, $local = false, $isPublic = false ) {
1336 if( $rev->isDeleted( Revision
::DELETED_COMMENT
) && $isPublic ) {
1337 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1338 } else if( $rev->userCan( Revision
::DELETED_COMMENT
) ) {
1339 $block = $this->commentBlock( $rev->getRawComment(), $rev->getTitle(), $local );
1341 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1343 if( $rev->isDeleted( Revision
::DELETED_COMMENT
) ) {
1344 return " <span class=\"history-deleted\">$block</span>";
1349 public function formatRevisionSize( $size ) {
1351 $stxt = wfMsgExt( 'historyempty', 'parsemag' );
1354 $stxt = wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $size ) );
1357 $stxt = htmlspecialchars( $stxt );
1358 return "<span class=\"history-size\">$stxt</span>";
1361 /** @todo document */
1362 function tocIndent() {
1366 /** @todo document */
1367 function tocUnindent($level) {
1368 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ?
$level : 0 );
1372 * parameter level defines if we are on an indentation level
1374 function tocLine( $anchor, $tocline, $tocnumber, $level ) {
1375 return "\n<li class=\"toclevel-$level\"><a href=\"#" .
1376 $anchor . '"><span class="tocnumber">' .
1377 $tocnumber . '</span> <span class="toctext">' .
1378 $tocline . '</span></a>';
1381 /** @todo document */
1382 function tocLineEnd() {
1386 /** @todo document */
1387 function tocList($toc) {
1388 global $wgJsMimeType;
1389 $title = wfMsgHtml('toc') ;
1391 '<table id="toc" class="toc" summary="' . $title .'"><tr><td>'
1392 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
1394 # no trailing newline, script should not be wrapped in a
1396 . "</ul>\n</td></tr></table>"
1397 . '<script type="' . $wgJsMimeType . '">'
1398 . ' if (window.showTocToggle) {'
1399 . ' var tocShowText = "' . wfEscapeJsString( wfMsg('showtoc') ) . '";'
1400 . ' var tocHideText = "' . wfEscapeJsString( wfMsg('hidetoc') ) . '";'
1401 . ' showTocToggle();'
1407 * Used to generate section edit links that point to "other" pages
1408 * (sections that are really part of included pages).
1410 * @param $title Title string.
1411 * @param $section Integer: section number.
1413 public function editSectionLinkForOther( $title, $section ) {
1414 wfDeprecated( __METHOD__
);
1415 $title = Title
::newFromText( $title );
1416 return $this->doEditSectionLink( $title, $section );
1420 * @param $nt Title object.
1421 * @param $section Integer: section number.
1422 * @param $hint Link String: title, or default if omitted or empty
1424 public function editSectionLink( Title
$nt, $section, $hint = '' ) {
1425 wfDeprecated( __METHOD__
);
1426 if( $hint === '' ) {
1427 # No way to pass an actual empty $hint here! The new interface al-
1428 # lows this, so we have to do this for compatibility.
1431 return $this->doEditSectionLink( $nt, $section, $hint );
1435 * Create a section edit link. This supersedes editSectionLink() and
1436 * editSectionLinkForOther().
1438 * @param $nt Title The title being linked to (may not be the same as
1439 * $wgTitle, if the section is included from a template)
1440 * @param $section string The designation of the section being pointed to,
1441 * to be included in the link, like "§ion=$section"
1442 * @param $tooltip string The tooltip to use for the link: will be escaped
1443 * and wrapped in the 'editsectionhint' message
1444 * @return string HTML to use for edit link
1446 public function doEditSectionLink( Title
$nt, $section, $tooltip = null ) {
1448 if( !is_null( $tooltip ) ) {
1449 $attribs['title'] = wfMsg( 'editsectionhint', $tooltip );
1451 $url = $this->link( $nt, wfMsg('editsection'),
1453 array( 'action' => 'edit', 'section' => $section ),
1454 array( 'noclasses', 'known' )
1457 # Run the old hook. This takes up half of the function . . . hopefully
1458 # we can rid of it someday.
1461 $attribs = wfMsgHtml( 'editsectionhint', htmlspecialchars( $tooltip ) );
1462 $attribs = " title=\"$attribs\"";
1465 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $url, &$result ) );
1466 if( !is_null( $result ) ) {
1467 # For reverse compatibility, add the brackets *after* the hook is
1468 # run, and even add them to hook-provided text. (This is the main
1469 # reason that the EditSectionLink hook is deprecated in favor of
1470 # DoEditSectionLink: it can't change the brackets or the span.)
1471 $result = wfMsgHtml( 'editsection-brackets', $url );
1472 return "<span class=\"editsection\">$result</span>";
1475 # Add the brackets and the span, and *then* run the nice new hook, with
1476 # clean and non-redundant arguments.
1477 $result = wfMsgHtml( 'editsection-brackets', $url );
1478 $result = "<span class=\"editsection\">$result</span>";
1480 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result ) );
1485 * Create a headline for content
1487 * @param int $level The level of the headline (1-6)
1488 * @param string $attribs Any attributes for the headline, starting with a space and ending with '>'
1489 * This *must* be at least '>' for no attribs
1490 * @param string $anchor The anchor to give the headline (the bit after the #)
1491 * @param string $text The text of the header
1492 * @param string $link HTML to add for the section edit link
1494 * @return string HTML headline
1496 public function makeHeadline( $level, $attribs, $anchor, $text, $link ) {
1497 return "<a name=\"$anchor\"></a><h$level$attribs$link <span class=\"mw-headline\">$text</span></h$level>";
1501 * Split a link trail, return the "inside" portion and the remainder of the trail
1502 * as a two-element array
1506 static function splitTrail( $trail ) {
1507 static $regex = false;
1508 if ( $regex === false ) {
1510 $regex = $wgContLang->linkTrail();
1513 if ( '' != $trail ) {
1515 if ( preg_match( $regex, $trail, $m ) ) {
1520 return array( $inside, $trail );
1524 * Generate a rollback link for a given revision. Currently it's the
1525 * caller's responsibility to ensure that the revision is the top one. If
1526 * it's not, of course, the user will get an error message.
1528 * If the calling page is called with the parameter &bot=1, all rollback
1529 * links also get that parameter. It causes the edit itself and the rollback
1530 * to be marked as "bot" edits. Bot edits are hidden by default from recent
1531 * changes, so this allows sysops to combat a busy vandal without bothering
1534 * @param Revision $rev
1536 function generateRollback( $rev ) {
1537 return '<span class="mw-rollback-link">['
1538 . $this->buildRollbackLink( $rev )
1543 * Build a raw rollback link, useful for collections of "tool" links
1545 * @param Revision $rev
1548 public function buildRollbackLink( $rev ) {
1549 global $wgRequest, $wgUser;
1550 $title = $rev->getTitle();
1552 'action' => 'rollback',
1553 'from' => $rev->getUserText()
1555 if( $wgRequest->getBool( 'bot' ) ) {
1556 $query['bot'] = '1';
1558 $query['token'] = $wgUser->editToken( array( $title->getPrefixedText(),
1559 $rev->getUserText() ) );
1560 return $this->link( $title, wfMsgHtml( 'rollbacklink' ), array(),
1561 $query, array( 'known', 'noclasses' ) );
1565 * Returns HTML for the "templates used on this page" list.
1567 * @param array $templates Array of templates from Article::getUsedTemplate
1569 * @param bool $preview Whether this is for a preview
1570 * @param bool $section Whether this is for a section edit
1571 * @return string HTML output
1573 public function formatTemplates( $templates, $preview = false, $section = false) {
1575 wfProfileIn( __METHOD__
);
1577 $sk = $wgUser->getSkin();
1580 if ( count( $templates ) > 0 ) {
1581 # Do a batch existence check
1582 $batch = new LinkBatch
;
1583 foreach( $templates as $title ) {
1584 $batch->addObj( $title );
1588 # Construct the HTML
1589 $outText = '<div class="mw-templatesUsedExplanation">';
1591 $outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ) );
1592 } elseif ( $section ) {
1593 $outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ) );
1595 $outText .= wfMsgExt( 'templatesused', array( 'parse' ) );
1597 $outText .= '</div><ul>';
1599 usort( $templates, array( 'Title', 'compare' ) );
1600 foreach ( $templates as $titleObj ) {
1601 $r = $titleObj->getRestrictions( 'edit' );
1602 if ( in_array( 'sysop', $r ) ) {
1603 $protected = wfMsgExt( 'template-protected', array( 'parseinline' ) );
1604 } elseif ( in_array( 'autoconfirmed', $r ) ) {
1605 $protected = wfMsgExt( 'template-semiprotected', array( 'parseinline' ) );
1609 $outText .= '<li>' . $sk->link( $titleObj ) . ' ' . $protected . '</li>';
1611 $outText .= '</ul>';
1613 wfProfileOut( __METHOD__
);
1618 * Returns HTML for the "hidden categories on this page" list.
1620 * @param array $hiddencats Array of hidden categories from Article::getHiddenCategories
1622 * @return string HTML output
1624 public function formatHiddenCategories( $hiddencats) {
1625 global $wgUser, $wgLang;
1626 wfProfileIn( __METHOD__
);
1628 $sk = $wgUser->getSkin();
1631 if ( count( $hiddencats ) > 0 ) {
1632 # Construct the HTML
1633 $outText = '<div class="mw-hiddenCategoriesExplanation">';
1634 $outText .= wfMsgExt( 'hiddencategories', array( 'parse' ), $wgLang->formatnum( count( $hiddencats ) ) );
1635 $outText .= '</div><ul>';
1637 foreach ( $hiddencats as $titleObj ) {
1638 $outText .= '<li>' . $sk->link( $titleObj, null, array(), array(), 'known' ) . '</li>'; # If it's hidden, it must exist - no need to check with a LinkBatch
1640 $outText .= '</ul>';
1642 wfProfileOut( __METHOD__
);
1647 * Format a size in bytes for output, using an appropriate
1648 * unit (B, KB, MB or GB) according to the magnitude in question
1650 * @param $size Size to format
1653 public function formatSize( $size ) {
1655 return htmlspecialchars( $wgLang->formatSize( $size ) );
1659 * Given the id of an interface element, constructs the appropriate title
1660 * and accesskey attributes from the system messages. (Note, this is usu-
1661 * ally the id but isn't always, because sometimes the accesskey needs to
1662 * go on a different element than the id, for reverse-compatibility, etc.)
1664 * @param string $name Id of the element, minus prefixes.
1665 * @return string title and accesskey attributes, ready to drop in an
1666 * element (e.g., ' title="This does something [x]" accesskey="x"').
1668 public function tooltipAndAccesskey($name) {
1669 $fname="Linker::tooltipAndAccesskey";
1670 wfProfileIn($fname);
1673 $tooltip = wfMsg('tooltip-'.$name);
1674 if (!wfEmptyMsg('tooltip-'.$name, $tooltip) && $tooltip != '-') {
1675 // Compatibility: formerly some tooltips had [alt-.] hardcoded
1676 $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
1677 $out .= ' title="'.htmlspecialchars($tooltip);
1679 $accesskey = wfMsg('accesskey-'.$name);
1680 if ($accesskey && $accesskey != '-' && !wfEmptyMsg('accesskey-'.$name, $accesskey)) {
1681 if ($out) $out .= " [$accesskey]\" accesskey=\"$accesskey\"";
1682 else $out .= " title=\"[$accesskey]\" accesskey=\"$accesskey\"";
1686 wfProfileOut($fname);
1691 * Given the id of an interface element, constructs the appropriate title
1692 * attribute from the system messages. (Note, this is usually the id but
1693 * isn't always, because sometimes the accesskey needs to go on a different
1694 * element than the id, for reverse-compatibility, etc.)
1696 * @param string $name Id of the element, minus prefixes.
1697 * @return string title attribute, ready to drop in an element
1698 * (e.g., ' title="This does something"').
1700 public function tooltip($name) {
1703 $tooltip = wfMsg('tooltip-'.$name);
1704 if (!wfEmptyMsg('tooltip-'.$name, $tooltip) && $tooltip != '-') {
1705 $out = ' title="'.htmlspecialchars($tooltip).'"';