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 &&
128 $t->exists() && $t->getLength() < $threshold &&
129 MWNamespace
::isContent( $t->getNamespace() ) ) {
137 * This function returns an HTML link to the given target. It serves a few
139 * 1) If $target is a Title, the correct URL to link to will be figured
141 * 2) It automatically adds the usual classes for various types of link
142 * targets: "new" for red links, "stub" for short articles, etc.
143 * 3) It escapes all attribute values safely so there's no risk of XSS.
144 * 4) It provides a default tooltip if the target is a Title (the page
145 * name of the target).
146 * link() replaces the old functions in the makeLink() family.
148 * @param $target Title Can currently only be a Title, but this may
149 * change to support Images, literal URLs, etc.
150 * @param $text string The HTML contents of the <a> element, i.e.,
151 * the link text. This is raw HTML and will not be escaped. If null,
152 * defaults to the prefixed text of the Title; or if the Title is just a
153 * fragment, the contents of the fragment.
154 * @param $customAttribs array A key => value array of extra HTML attri-
155 * butes, such as title and class. (href is ignored.) Classes will be
156 * merged with the default classes, while other attributes will replace
157 * default attributes. All passed attribute values will be HTML-escaped.
158 * A false attribute value means to suppress that attribute.
159 * @param $query array The query string to append to the URL
160 * you're linking to, in key => value array form. Query keys and values
161 * will be URL-encoded.
162 * @param $options mixed String or array of strings:
163 * 'known': Page is known to exist, so don't check if it does.
164 * 'broken': Page is known not to exist, so don't check if it does.
165 * 'noclasses': Don't add any classes automatically (includes "new",
166 * "stub", "mw-redirect", "extiw"). Only use the class attribute
167 * provided, if any, so you get a simple blue link with no funny i-
169 * @return string HTML <a> attribute
171 public function link( $target, $text = null, $customAttribs = array(), $query = array(), $options = array() ) {
172 wfProfileIn( __METHOD__
);
173 if( !$target instanceof Title
) {
174 return "<!-- ERROR -->$text";
176 $options = (array)$options;
179 if( !wfRunHooks( 'LinkBegin', array( $this, $target, &$text,
180 &$customAttribs, &$query, &$options, &$ret ) ) ) {
181 wfProfileOut( __METHOD__
);
185 # Normalize the Title if it's a special page
186 $target = $this->normaliseSpecialPage( $target );
188 # If we don't know whether the page exists, let's find out.
189 wfProfileIn( __METHOD__
. '-checkPageExistence' );
190 if( !in_array( 'known', $options ) and !in_array( 'broken', $options ) ) {
191 if( $target->getNamespace() == NS_SPECIAL
) {
192 if( SpecialPage
::exists( $target->getDbKey() ) ) {
193 $options []= 'known';
195 $options []= 'broken';
197 } elseif( $target->isAlwaysKnown() or
198 ($target->getPrefixedText() == '' and $target->getFragment() != '')
199 or $target->exists() ) {
200 $options []= 'known';
202 $options []= 'broken';
205 wfProfileOut( __METHOD__
. '-checkPageExistence' );
208 if( in_array( "forcearticlepath", $options ) && $query ){
213 # Note: we want the href attribute first, for prettiness.
214 $attribs = array( 'href' => $this->linkUrl( $target, $query, $options ) );
215 if( in_array( 'forcearticlepath', $options ) && $oldquery ){
216 $attribs['href'] = wfAppendQuery( $attribs['href'], wfArrayToCgi( $oldquery ) );
218 $attribs = array_merge(
220 $this->linkAttribs( $target, $customAttribs, $options )
222 if( is_null( $text ) ) {
223 $text = $this->linkText( $target );
227 if( wfRunHooks( 'LinkEnd', array( $this, $target, $options, &$text,
228 &$attribs, &$ret ) ) ) {
229 $ret = Xml
::openElement( 'a', $attribs )
231 . Xml
::closeElement( 'a' );
234 wfProfileOut( __METHOD__
);
238 private function linkUrl( $target, $query, $options ) {
239 wfProfileIn( __METHOD__
);
240 # We don't want to include fragments for broken links, because they
241 # generally make no sense.
242 if( in_array( 'broken', $options ) and $target->mFragment
!== '' ) {
243 $target = clone $target;
244 $target->mFragment
= '';
247 # If it's a broken link, add the appropriate query pieces, unless
248 # there's already an action specified, or unless 'edit' makes no sense
249 # (i.e., for a nonexistent special page).
250 if( in_array( 'broken', $options ) and empty( $query['action'] )
251 and $target->getNamespace() != NS_SPECIAL
) {
252 $query['action'] = 'edit';
253 $query['redlink'] = '1';
255 $ret = $target->getLinkUrl( $query );
256 wfProfileOut( __METHOD__
);
260 private function linkAttribs( $target, $attribs, $options ) {
261 wfProfileIn( __METHOD__
);
265 if( !in_array( 'noclasses', $options ) ) {
266 wfProfileIn( __METHOD__
. '-getClasses' );
267 # Now build the classes.
270 if( in_array( 'broken', $options ) ) {
274 if( $target->isExternal() ) {
275 $classes[] = 'extiw';
278 # Note that redirects never count as stubs here.
279 if ( $target->isRedirect() ) {
280 $classes[] = 'mw-redirect';
281 } elseif( $target->isContentPage() ) {
283 $threshold = $wgUser->getOption( 'stubthreshold' );
284 if( $threshold > 0 and $target->exists() and $target->getLength() < $threshold ) {
288 if( $classes != array() ) {
289 $defaults['class'] = implode( ' ', $classes );
291 wfProfileOut( __METHOD__
. '-getClasses' );
294 # Get a default title attribute.
295 if( in_array( 'known', $options ) ) {
296 $defaults['title'] = $target->getPrefixedText();
298 $defaults['title'] = wfMsg( 'red-link-title', $target->getPrefixedText() );
301 # Finally, merge the custom attribs with the default ones, and iterate
302 # over that, deleting all "false" attributes.
304 $merged = Sanitizer
::mergeAttributes( $defaults, $attribs );
305 foreach( $merged as $key => $val ) {
306 # A false value suppresses the attribute, and we don't want the
307 # href attribute to be overridden.
308 if( $key != 'href' and $val !== false ) {
312 wfProfileOut( __METHOD__
);
316 private function linkText( $target ) {
317 # We might be passed a non-Title by make*LinkObj(). Fail gracefully.
318 if( !$target instanceof Title
) {
322 # If the target is just a fragment, with no title, we return the frag-
323 # ment text. Otherwise, we return the title text itself.
324 if( $target->getPrefixedText() === '' and $target->getFragment() !== '' ) {
325 return htmlspecialchars( $target->getFragment() );
327 return htmlspecialchars( $target->getPrefixedText() );
331 * @deprecated Use link()
333 * This function is a shortcut to makeLinkObj(Title::newFromText($title),...). Do not call
334 * it if you already have a title object handy. See makeLinkObj for further documentation.
336 * @param $title String: the text of the title
337 * @param $text String: link text
338 * @param $query String: optional query part
339 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
340 * be included in the link text. Other characters will be appended after
341 * the end of the link.
343 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
344 wfProfileIn( __METHOD__
);
345 $nt = Title
::newFromText( $title );
346 if ( $nt instanceof Title
) {
347 $result = $this->makeLinkObj( $nt, $text, $query, $trail );
349 wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" );
350 $result = $text == "" ?
$title : $text;
353 wfProfileOut( __METHOD__
);
358 * @deprecated Use link()
360 * This function is a shortcut to makeKnownLinkObj(Title::newFromText($title),...). Do not call
361 * it if you already have a title object handy. See makeKnownLinkObj for further documentation.
363 * @param $title String: the text of the title
364 * @param $text String: link text
365 * @param $query String: optional query part
366 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
367 * be included in the link text. Other characters will be appended after
368 * the end of the link.
370 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
371 $nt = Title
::newFromText( $title );
372 if ( $nt instanceof Title
) {
373 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix , $aprops );
375 wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" );
376 return $text == '' ?
$title : $text;
381 * @deprecated Use link()
383 * This function is a shortcut to makeBrokenLinkObj(Title::newFromText($title),...). Do not call
384 * it if you already have a title object handy. See makeBrokenLinkObj for further documentation.
386 * @param string $title The text of the title
387 * @param string $text Link text
388 * @param string $query Optional query part
389 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
390 * be included in the link text. Other characters will be appended after
391 * the end of the link.
393 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
394 $nt = Title
::newFromText( $title );
395 if ( $nt instanceof Title
) {
396 return $this->makeBrokenLinkObj( $nt, $text, $query, $trail );
398 wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" );
399 return $text == '' ?
$title : $text;
404 * @deprecated Use link()
406 * This function is a shortcut to makeStubLinkObj(Title::newFromText($title),...). Do not call
407 * it if you already have a title object handy. See makeStubLinkObj for further documentation.
409 * @param $title String: the text of the title
410 * @param $text String: link text
411 * @param $query String: optional query part
412 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
413 * be included in the link text. Other characters will be appended after
414 * the end of the link.
416 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
417 wfDeprecated( __METHOD__
);
418 $nt = Title
::newFromText( $title );
419 if ( $nt instanceof Title
) {
420 return $this->makeStubLinkObj( $nt, $text, $query, $trail );
422 wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" );
423 return $text == '' ?
$title : $text;
428 * @deprecated Use link()
430 * Make a link for a title which may or may not be in the database. If you need to
431 * call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
432 * call to this will result in a DB query.
434 * @param $nt Title: the title object to make the link from, e.g. from
435 * Title::newFromText.
436 * @param $text String: link text
437 * @param $query String: optional query part
438 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
439 * be included in the link text. Other characters will be appended after
440 * the end of the link.
441 * @param $prefix String: optional prefix. As trail, only before instead of after.
443 function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
445 wfProfileIn( __METHOD__
);
447 $query = wfCgiToArray( $query );
448 list( $inside, $trail ) = Linker
::splitTrail( $trail );
450 $text = $this->linkText( $nt );
453 $ret = $this->link( $nt, "$prefix$text$inside", array(), $query ) . $trail;
455 wfProfileOut( __METHOD__
);
460 * @deprecated Use link()
462 * Make a link for a title which definitely exists. This is faster than makeLinkObj because
463 * it doesn't have to do a database query. It's also valid for interwiki titles and special
466 * @param $nt Title object of target page
467 * @param $text String: text to replace the title
468 * @param $query String: link target
469 * @param $trail String: text after link
470 * @param $prefix String: text before link text
471 * @param $aprops String: extra attributes to the a-element
472 * @param $style String: style to apply - if empty, use getInternalLinkAttributesObj instead
473 * @return the a-element
475 function makeKnownLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
476 wfProfileIn( __METHOD__
);
479 $text = $this->linkText( $title );
481 $attribs = Sanitizer
::mergeAttributes(
482 Sanitizer
::decodeTagAttributes( $aprops ),
483 Sanitizer
::decodeTagAttributes( $style )
485 $query = wfCgiToArray( $query );
486 list( $inside, $trail ) = Linker
::splitTrail( $trail );
488 $ret = $this->link( $title, "$prefix$text$inside", $attribs, $query,
489 array( 'known', 'noclasses' ) ) . $trail;
491 wfProfileOut( __METHOD__
);
496 * @deprecated Use link()
498 * Make a red link to the edit page of a given title.
500 * @param $nt Title object of the target page
501 * @param $text String: Link text
502 * @param $query String: Optional query part
503 * @param $trail String: Optional trail. Alphabetic characters at the start of this string will
504 * be included in the link text. Other characters will be appended after
505 * the end of the link.
507 function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
508 wfProfileIn( __METHOD__
);
510 list( $inside, $trail ) = Linker
::splitTrail( $trail );
512 $text = $this->linkText( $title );
514 $nt = $this->normaliseSpecialPage( $title );
516 $ret = $this->link( $title, "$prefix$text$inside", array(),
517 wfCgiToArray( $query ), 'broken' ) . $trail;
519 wfProfileOut( __METHOD__
);
524 * @deprecated Use link()
526 * Make a brown link to a short article.
528 * @param $nt Title object of the target page
529 * @param $text String: link text
530 * @param $query String: optional query part
531 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
532 * be included in the link text. Other characters will be appended after
533 * the end of the link.
535 function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
536 wfDeprecated( __METHOD__
);
537 return $this->makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix );
541 * @deprecated Use link()
543 * Make a coloured link.
545 * @param $nt Title object of the target page
546 * @param $colour Integer: colour of the link
547 * @param $text String: link text
548 * @param $query String: optional query part
549 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
550 * be included in the link text. Other characters will be appended after
551 * the end of the link.
553 function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
555 $style = $this->getInternalLinkAttributesObj( $nt, $text, $colour );
557 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style );
561 * Generate either a normal exists-style link or a stub link, depending
562 * on the given page size.
564 * @param $size Integer
565 * @param $nt Title object.
566 * @param $text String
567 * @param $query String
568 * @param $trail String
569 * @param $prefix String
570 * @return string HTML of link
572 function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
574 $threshold = intval( $wgUser->getOption( 'stubthreshold' ) );
575 $colour = ( $size < $threshold ) ?
'stub' : '';
576 return $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
580 * Make appropriate markup for a link to the current article. This is currently rendered
581 * as the bold link text. The calling sequence is the same as the other make*LinkObj functions,
582 * despite $query not being used.
584 function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
586 $text = htmlspecialchars( $nt->getPrefixedText() );
588 list( $inside, $trail ) = Linker
::splitTrail( $trail );
589 return "<strong class=\"selflink\">{$prefix}{$text}{$inside}</strong>{$trail}";
592 function normaliseSpecialPage( Title
$title ) {
593 if ( $title->getNamespace() == NS_SPECIAL
) {
594 list( $name, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $title->getDBkey() );
595 if ( !$name ) return $title;
596 $ret = SpecialPage
::getTitleFor( $name, $subpage );
597 $ret->mFragment
= $title->getFragment();
604 /** @todo document */
605 function fnamePart( $url ) {
606 $basename = strrchr( $url, '/' );
607 if ( false === $basename ) {
610 $basename = substr( $basename, 1 );
615 /** Obsolete alias */
616 function makeImage( $url, $alt = '' ) {
617 wfDeprecated( __METHOD__
);
618 return $this->makeExternalImage( $url, $alt );
621 /** @todo document */
622 function makeExternalImage( $url, $alt = '' ) {
624 $alt = $this->fnamePart( $url );
627 $success = wfRunHooks('LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
629 wfDebug("Hook LinkerMakeExternalImage changed the output of external image with url {$url} and alt text {$alt} to {$img}", true);
632 return Xml
::element( 'img',
639 * Creates the HTML source for images
640 * @deprecated use makeImageLink2
642 * @param object $title
643 * @param string $label label text
644 * @param string $alt alt text
645 * @param string $align horizontal alignment: none, left, center, right)
646 * @param array $handlerParams Parameters to be passed to the media handler
647 * @param boolean $framed shows image in original size in a frame
648 * @param boolean $thumb shows image as thumbnail in a frame
649 * @param string $manualthumb image name for the manual thumbnail
650 * @param string $valign vertical alignment: baseline, sub, super, top, text-top, middle, bottom, text-bottom
651 * @param string $time, timestamp of the file, set as false for current
654 function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(), $framed = false,
655 $thumb = false, $manualthumb = '', $valign = '', $time = false )
657 $frameParams = array( 'alt' => $alt, 'caption' => $label );
659 $frameParams['align'] = $align;
662 $frameParams['framed'] = true;
665 $frameParams['thumbnail'] = true;
667 if ( $manualthumb ) {
668 $frameParams['manualthumb'] = $manualthumb;
671 $frameParams['valign'] = $valign;
673 $file = wfFindFile( $title, $time );
674 return $this->makeImageLink2( $title, $file, $frameParams, $handlerParams, $time );
678 * Given parameters derived from [[Image:Foo|options...]], generate the
679 * HTML that that syntax inserts in the page.
681 * @param Title $title Title object
682 * @param File $file File object, or false if it doesn't exist
684 * @param array $frameParams Associative array of parameters external to the media handler.
685 * Boolean parameters are indicated by presence or absence, the value is arbitrary and
686 * will often be false.
687 * thumbnail If present, downscale and frame
688 * manualthumb Image name to use as a thumbnail, instead of automatic scaling
689 * framed Shows image in original size in a frame
690 * frameless Downscale but don't frame
691 * upright If present, tweak default sizes for portrait orientation
692 * upright_factor Fudge factor for "upright" tweak (default 0.75)
693 * border If present, show a border around the image
694 * align Horizontal alignment (left, right, center, none)
695 * valign Vertical alignment (baseline, sub, super, top, text-top, middle,
696 * bottom, text-bottom)
697 * alt Alternate text for image (i.e. alt attribute). Plain text.
698 * caption HTML for image caption.
700 * @param array $handlerParams Associative array of media handler parameters, to be passed
701 * to transform(). Typical keys are "width" and "page".
702 * @param string $time, timestamp of the file, set as false for current
703 * @param string $query, query params for desc url
704 * @return string HTML for an image, with links, wrappers, etc.
706 function makeImageLink2( Title
$title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
708 if( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$this, &$title,
709 &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
713 global $wgContLang, $wgUser, $wgThumbLimits, $wgThumbUpright;
714 if ( $file && !$file->allowInlineDisplay() ) {
715 wfDebug( __METHOD__
.': '.$title->getPrefixedDBkey()." does not allow inline display\n" );
716 return $this->link( $title );
721 $hp =& $handlerParams;
723 // Clean up parameters
724 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
725 if ( !isset( $fp['align'] ) ) $fp['align'] = '';
726 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
728 $prefix = $postfix = '';
730 if ( 'center' == $fp['align'] )
732 $prefix = '<div class="center">';
734 $fp['align'] = 'none';
736 if ( $file && !isset( $hp['width'] ) ) {
737 $hp['width'] = $file->getWidth( $page );
739 if( isset( $fp['thumbnail'] ) ||
isset( $fp['framed'] ) ||
isset( $fp['frameless'] ) ||
!$hp['width'] ) {
740 $wopt = $wgUser->getOption( 'thumbsize' );
742 if( !isset( $wgThumbLimits[$wopt] ) ) {
743 $wopt = User
::getDefaultOption( 'thumbsize' );
746 // Reduce width for upright images when parameter 'upright' is used
747 if ( isset( $fp['upright'] ) && $fp['upright'] == 0 ) {
748 $fp['upright'] = $wgThumbUpright;
750 // Use width which is smaller: real image width or user preference width
751 // 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
752 $prefWidth = isset( $fp['upright'] ) ?
753 round( $wgThumbLimits[$wopt] * $fp['upright'], -1 ) :
754 $wgThumbLimits[$wopt];
755 if ( $hp['width'] <= 0 ||
$prefWidth < $hp['width'] ) {
756 $hp['width'] = $prefWidth;
761 if ( isset( $fp['thumbnail'] ) ||
isset( $fp['manualthumb'] ) ||
isset( $fp['framed'] ) ) {
763 # Create a thumbnail. Alignment depends on language
764 # writing direction, # right aligned for left-to-right-
765 # languages ("Western languages"), left-aligned
766 # for right-to-left-languages ("Semitic languages")
768 # If thumbnail width has not been provided, it is set
769 # to the default user option as specified in Language*.php
770 if ( $fp['align'] == '' ) {
771 $fp['align'] = $wgContLang->isRTL() ?
'left' : 'right';
773 return $prefix.$this->makeThumbLink2( $title, $file, $fp, $hp, $time, $query ).$postfix;
776 if ( $file && isset( $fp['frameless'] ) ) {
777 $srcWidth = $file->getWidth( $page );
778 # For "frameless" option: do not present an image bigger than the source (for bitmap-style images)
779 # This is the same behaviour as the "thumb" option does it already.
780 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
781 $hp['width'] = $srcWidth;
785 if ( $file && $hp['width'] ) {
786 # Create a resized image, without the additional thumbnail features
787 $thumb = $file->transform( $hp );
793 $s = $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
795 $s = $thumb->toHtml( array(
797 'desc-query' => $query,
799 'valign' => isset( $fp['valign'] ) ?
$fp['valign'] : false ,
800 'img-class' => isset( $fp['border'] ) ?
'thumbborder' : false ) );
802 if ( '' != $fp['align'] ) {
803 $s = "<div class=\"float{$fp['align']}\"><span>{$s}</span></div>";
805 return str_replace("\n", ' ',$prefix.$s.$postfix);
809 * Make HTML for a thumbnail including image, border and caption
810 * @param Title $title
811 * @param File $file File object or false if it doesn't exist
813 function makeThumbLinkObj( Title
$title, $file, $label = '', $alt, $align = 'right', $params = array(), $framed=false , $manualthumb = "" ) {
814 $frameParams = array(
819 if ( $framed ) $frameParams['framed'] = true;
820 if ( $manualthumb ) $frameParams['manualthumb'] = $manualthumb;
821 return $this->makeThumbLink2( $title, $file, $frameParams, $params );
824 function makeThumbLink2( Title
$title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
825 global $wgStylePath, $wgContLang;
826 $exists = $file && $file->exists();
830 $hp =& $handlerParams;
832 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
833 if ( !isset( $fp['align'] ) ) $fp['align'] = 'right';
834 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
835 if ( !isset( $fp['caption'] ) ) $fp['caption'] = '';
837 if ( empty( $hp['width'] ) ) {
838 // Reduce width for upright images when parameter 'upright' is used
839 $hp['width'] = isset( $fp['upright'] ) ?
130 : 180;
844 $outerWidth = $hp['width'] +
2;
846 if ( isset( $fp['manualthumb'] ) ) {
847 # Use manually specified thumbnail
848 $manual_title = Title
::makeTitleSafe( NS_IMAGE
, $fp['manualthumb'] );
849 if( $manual_title ) {
850 $manual_img = wfFindFile( $manual_title );
852 $thumb = $manual_img->getUnscaledThumb();
857 } elseif ( isset( $fp['framed'] ) ) {
858 // Use image dimensions, don't scale
859 $thumb = $file->getUnscaledThumb( $page );
861 # Do not present an image bigger than the source, for bitmap-style images
862 # This is a hack to maintain compatibility with arbitrary pre-1.10 behaviour
863 $srcWidth = $file->getWidth( $page );
864 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
865 $hp['width'] = $srcWidth;
867 $thumb = $file->transform( $hp );
871 $outerWidth = $thumb->getWidth() +
2;
873 $outerWidth = $hp['width'] +
2;
878 $query = $query ?
'&page=' . urlencode( $page ) : 'page=' . urlencode( $page );
880 $url = $title->getLocalURL( $query );
882 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
884 $s = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
886 $s .= $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
888 } elseif ( !$thumb ) {
889 $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
892 $s .= $thumb->toHtml( array(
894 'img-class' => 'thumbimage',
896 'desc-query' => $query ) );
897 if ( isset( $fp['framed'] ) ) {
900 $zoomicon = '<div class="magnify">'.
901 '<a href="'.$url.'" class="internal" title="'.$more.'">'.
902 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
903 'width="15" height="11" alt="" /></a></div>';
906 $s .= ' <div class="thumbcaption">'.$zoomicon.$fp['caption']."</div></div></div>";
907 return str_replace("\n", ' ', $s);
911 * Make a "broken" link to an image
913 * @param Title $title Image title
914 * @param string $text Link label
915 * @param string $query Query string
916 * @param string $trail Link trail
917 * @param string $prefix Link prefix
918 * @param bool $time, a file of a certain timestamp was requested
921 public function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '', $time = false ) {
922 global $wgEnableUploads;
923 if( $title instanceof Title
) {
924 wfProfileIn( __METHOD__
);
925 $currentExists = $time ?
( wfFindFile( $title ) != false ) : false;
926 if( $wgEnableUploads && !$currentExists ) {
927 $upload = SpecialPage
::getTitleFor( 'Upload' );
929 $text = htmlspecialchars( $title->getPrefixedText() );
930 $redir = RepoGroup
::singleton()->getLocalRepo()->checkRedirect( $title );
932 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
934 $q = 'wpDestFile=' . $title->getPartialUrl();
937 list( $inside, $trail ) = self
::splitTrail( $trail );
938 $style = $this->getInternalLinkAttributesObj( $title, $text, 'new' );
939 wfProfileOut( __METHOD__
);
940 return '<a href="' . $upload->escapeLocalUrl( $q ) . '"'
941 . $style . '>' . $prefix . $text . $inside . '</a>' . $trail;
943 wfProfileOut( __METHOD__
);
944 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
947 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
951 /** @deprecated use Linker::makeMediaLinkObj() */
952 function makeMediaLink( $name, $unused = '', $text = '', $time = false ) {
953 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
954 return $this->makeMediaLinkObj( $nt, $text, $time );
958 * Create a direct link to a given uploaded file.
960 * @param $title Title object.
961 * @param $text String: pre-sanitized HTML
962 * @param $time string: time image was created
963 * @return string HTML
966 * @todo Handle invalid or missing images better.
968 function makeMediaLinkObj( $title, $text = '', $time = false ) {
969 if( is_null( $title ) ) {
970 ### HOTFIX. Instead of breaking, return empty string.
973 $img = wfFindFile( $title, $time );
975 $url = $img->getURL();
978 $upload = SpecialPage
::getTitleFor( 'Upload' );
979 $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $title->getDBkey() ) );
982 $alt = htmlspecialchars( $title->getText() );
986 $u = htmlspecialchars( $url );
987 return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\">{$text}</a>";
991 /** @todo document */
992 function specialLink( $name, $key = '' ) {
995 if ( '' == $key ) { $key = strtolower( $name ); }
996 $pn = $wgContLang->ucfirst( $name );
997 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1001 /** @todo document */
1002 function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) {
1003 $attribsText = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
1005 $attribsText .= Xml
::expandAttributes( $attribs );
1007 $url = htmlspecialchars( $url );
1009 $text = htmlspecialchars( $text );
1012 $success = wfRunHooks('LinkerMakeExternalLink', array( &$url, &$text, &$link ) );
1014 wfDebug("Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}", true);
1017 return '<a href="'.$url.'"'.$attribsText.'>'.$text.'</a>';
1021 * Make user link (or user contributions for unregistered users)
1022 * @param $userId Integer: user id in database.
1023 * @param $userText String: user name in database
1024 * @return string HTML fragment
1027 function userLink( $userId, $userText ) {
1028 if( $userId == 0 ) {
1029 $page = SpecialPage
::getTitleFor( 'Contributions', $userText );
1031 $page = Title
::makeTitle( NS_USER
, $userText );
1033 return $this->link( $page, htmlspecialchars( $userText ) );
1037 * Generate standard user tool links (talk, contributions, block link, etc.)
1039 * @param int $userId User identifier
1040 * @param string $userText User name or IP address
1041 * @param bool $redContribsWhenNoEdits Should the contributions link be red if the user has no edits?
1042 * @param int $flags Customisation flags (e.g. self::TOOL_LINKS_NOBLOCK)
1043 * @param int $edits, user edit count (optional, for performance)
1046 public function userToolLinks( $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits=null ) {
1047 global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans;
1048 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
1049 $blockable = ( $wgSysopUserBans ||
0 == $userId ) && !$flags & self
::TOOL_LINKS_NOBLOCK
;
1053 $items[] = $this->userTalkLink( $userId, $userText );
1056 // check if the user has an edit
1058 if( $redContribsWhenNoEdits ) {
1059 $count = !is_null($edits) ?
$edits : User
::edits( $userId );
1061 $attribs['class'] = 'new';
1064 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $userText );
1066 $items[] = $this->link( $contribsPage, wfMsgHtml( 'contribslink' ), $attribs );
1068 if( $blockable && $wgUser->isAllowed( 'block' ) ) {
1069 $items[] = $this->blockLink( $userId, $userText );
1073 return ' (' . implode( ' | ', $items ) . ')';
1080 * Alias for userToolLinks( $userId, $userText, true );
1081 * @param int $userId User identifier
1082 * @param string $userText User name or IP address
1083 * @param int $edits, user edit count (optional, for performance)
1085 public function userToolLinksRedContribs( $userId, $userText, $edits=null ) {
1086 return $this->userToolLinks( $userId, $userText, true, 0, $edits );
1091 * @param $userId Integer: user id in database.
1092 * @param $userText String: user name in database.
1093 * @return string HTML fragment with user talk link
1096 function userTalkLink( $userId, $userText ) {
1097 $userTalkPage = Title
::makeTitle( NS_USER_TALK
, $userText );
1098 $userTalkLink = $this->link( $userTalkPage, wfMsgHtml( 'talkpagelinktext' ) );
1099 return $userTalkLink;
1103 * @param $userId Integer: userid
1104 * @param $userText String: user name in database.
1105 * @return string HTML fragment with block link
1108 function blockLink( $userId, $userText ) {
1109 $blockPage = SpecialPage
::getTitleFor( 'Blockip', $userText );
1110 $blockLink = $this->link( $blockPage, wfMsgHtml( 'blocklink' ) );
1115 * Generate a user link if the current user is allowed to view it
1116 * @param $rev Revision object.
1117 * @param $isPublic, bool, show only if all users can see it
1118 * @return string HTML
1120 function revUserLink( $rev, $isPublic = false ) {
1121 if( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1122 $link = wfMsgHtml( 'rev-deleted-user' );
1123 } else if( $rev->userCan( Revision
::DELETED_USER
) ) {
1124 $link = $this->userLink( $rev->getUser( Revision
::FOR_THIS_USER
),
1125 $rev->getUserText( Revision
::FOR_THIS_USER
) );
1127 $link = wfMsgHtml( 'rev-deleted-user' );
1129 if( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1130 return '<span class="history-deleted">' . $link . '</span>';
1136 * Generate a user tool link cluster if the current user is allowed to view it
1137 * @param $rev Revision object.
1138 * @param $isPublic, bool, show only if all users can see it
1139 * @return string HTML
1141 function revUserTools( $rev, $isPublic = false ) {
1142 if( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1143 $link = wfMsgHtml( 'rev-deleted-user' );
1144 } else if( $rev->userCan( Revision
::DELETED_USER
) ) {
1145 $userId = $rev->getUser( Revision
::FOR_THIS_USER
);
1146 $userText = $rev->getUserText( Revision
::FOR_THIS_USER
);
1147 $link = $this->userLink( $userId, $userText ) .
1148 ' ' . $this->userToolLinks( $userId, $userText );
1150 $link = wfMsgHtml( 'rev-deleted-user' );
1152 if( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1153 return ' <span class="history-deleted">' . $link . '</span>';
1159 * This function is called by all recent changes variants, by the page history,
1160 * and by the user contributions list. It is responsible for formatting edit
1161 * comments. It escapes any HTML in the comment, but adds some CSS to format
1162 * auto-generated comments (from section editing) and formats [[wikilinks]].
1164 * @author Erik Moeller <moeller@scireview.de>
1166 * Note: there's not always a title to pass to this function.
1167 * Since you can't set a default parameter for a reference, I've turned it
1168 * temporarily to a value pass. Should be adjusted further. --brion
1170 * @param string $comment
1171 * @param mixed $title Title object (to generate link to the section in autocomment) or null
1172 * @param bool $local Whether section links should refer to local page
1174 function formatComment($comment, $title = NULL, $local = false) {
1175 wfProfileIn( __METHOD__
);
1177 # Sanitize text a bit:
1178 $comment = str_replace( "\n", " ", $comment );
1179 # Allow HTML entities (for bug 13815)
1180 $comment = Sanitizer
::escapeHtmlAllowEntities( $comment );
1182 # Render autocomments and make links:
1183 $comment = $this->formatAutoComments( $comment, $title, $local );
1184 $comment = $this->formatLinksInComment( $comment );
1186 wfProfileOut( __METHOD__
);
1191 * The pattern for autogen comments is / * foo * /, which makes for
1193 * We look for all comments, match any text before and after the comment,
1194 * add a separator where needed and format the comment itself with CSS
1195 * Called by Linker::formatComment.
1197 * @param string $comment Comment text
1198 * @param object $title An optional title object used to links to sections
1199 * @return string $comment formatted comment
1201 * @todo Document the $local parameter.
1203 private function formatAutocomments( $comment, $title = null, $local = false ) {
1205 $this->autocommentTitle
= $title;
1206 $this->autocommentLocal
= $local;
1207 $comment = preg_replace_callback(
1208 '!(.*)/\*\s*(.*?)\s*\*/(.*)!',
1209 array( $this, 'formatAutocommentsCallback' ),
1211 unset( $this->autocommentTitle
);
1212 unset( $this->autocommentLocal
);
1216 private function formatAutocommentsCallback( $match ) {
1217 $title = $this->autocommentTitle
;
1218 $local = $this->autocommentLocal
;
1227 # Generate a valid anchor name from the section title.
1228 # Hackish, but should generally work - we strip wiki
1229 # syntax, including the magic [[: that is used to
1230 # "link rather than show" in case of images and
1231 # interlanguage links.
1232 $section = str_replace( '[[:', '', $section );
1233 $section = str_replace( '[[', '', $section );
1234 $section = str_replace( ']]', '', $section );
1236 $sectionTitle = Title
::newFromText( '#' . $section );
1238 $sectionTitle = Title
::makeTitleSafe( $title->getNamespace(),
1239 $title->getDBkey(), $section );
1241 if ( $sectionTitle ) {
1242 $link = $this->link( $sectionTitle,
1243 wfMsgForContent( 'sectionlink' ), array(), array(),
1249 $auto = "$link$auto";
1251 # written summary $presep autocomment (summary /* section */)
1252 $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
1255 # autocomment $postsep written summary (/* section */ summary)
1256 $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
1258 $auto = '<span class="autocomment">' . $auto . '</span>';
1259 $comment = $pre . $auto . $post;
1264 * Formats wiki links and media links in text; all other wiki formatting
1267 * @fixme doesn't handle sub-links as in image thumb texts like the main parser
1268 * @param string $comment Text to format links in
1271 public function formatLinksInComment( $comment ) {
1272 return preg_replace_callback(
1273 '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
1274 array( $this, 'formatLinksInCommentCallback' ),
1278 protected function formatLinksInCommentCallback( $match ) {
1281 $medians = '(?:' . preg_quote( MWNamespace
::getCanonicalName( NS_MEDIA
), '/' ) . '|';
1282 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA
), '/' ) . '):';
1284 $comment = $match[0];
1286 # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
1287 if( strpos( $match[1], '%' ) !== false ) {
1288 $match[1] = str_replace( array('<', '>'), array('<', '>'), urldecode($match[1]) );
1291 # Handle link renaming [[foo|text]] will show link as "text"
1292 if( "" != $match[3] ) {
1297 $submatch = array();
1298 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1299 # Media link; trail not supported.
1300 $linkRegexp = '/\[\[(.*?)\]\]/';
1301 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
1303 # Other kind of link
1304 if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
1305 $trail = $submatch[1];
1309 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1310 if (isset($match[1][0]) && $match[1][0] == ':')
1311 $match[1] = substr($match[1], 1);
1312 $thelink = $this->makeLink( $match[1], $text, "", $trail );
1314 $comment = preg_replace( $linkRegexp, StringUtils
::escapeRegexReplacement( $thelink ), $comment, 1 );
1320 * Wrap a comment in standard punctuation and formatting if
1321 * it's non-empty, otherwise return empty string.
1323 * @param string $comment
1324 * @param mixed $title Title object (to generate link to section in autocomment) or null
1325 * @param bool $local Whether section links should refer to local page
1329 function commentBlock( $comment, $title = NULL, $local = false ) {
1330 // '*' used to be the comment inserted by the software way back
1331 // in antiquity in case none was provided, here for backwards
1332 // compatability, acc. to brion -ævar
1333 if( $comment == '' ||
$comment == '*' ) {
1336 $formatted = $this->formatComment( $comment, $title, $local );
1337 return " <span class=\"comment\">($formatted)</span>";
1342 * Wrap and format the given revision's comment block, if the current
1343 * user is allowed to view it.
1345 * @param Revision $rev
1346 * @param bool $local Whether section links should refer to local page
1347 * @param $isPublic, show only if all users can see it
1348 * @return string HTML
1350 function revComment( Revision
$rev, $local = false, $isPublic = false ) {
1351 if( $rev->isDeleted( Revision
::DELETED_COMMENT
) && $isPublic ) {
1352 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1353 } else if( $rev->userCan( Revision
::DELETED_COMMENT
) ) {
1354 $block = $this->commentBlock( $rev->getComment( Revision
::FOR_THIS_USER
),
1355 $rev->getTitle(), $local );
1357 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1359 if( $rev->isDeleted( Revision
::DELETED_COMMENT
) ) {
1360 return " <span class=\"history-deleted\">$block</span>";
1365 public function formatRevisionSize( $size ) {
1367 $stxt = wfMsgExt( 'historyempty', 'parsemag' );
1370 $stxt = wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $size ) );
1373 $stxt = htmlspecialchars( $stxt );
1374 return "<span class=\"history-size\">$stxt</span>";
1377 /** @todo document */
1378 function tocIndent() {
1382 /** @todo document */
1383 function tocUnindent($level) {
1384 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ?
$level : 0 );
1388 * parameter level defines if we are on an indentation level
1390 function tocLine( $anchor, $tocline, $tocnumber, $level ) {
1391 return "\n<li class=\"toclevel-$level\"><a href=\"#" .
1392 $anchor . '"><span class="tocnumber">' .
1393 $tocnumber . '</span> <span class="toctext">' .
1394 $tocline . '</span></a>';
1397 /** @todo document */
1398 function tocLineEnd() {
1402 /** @todo document */
1403 function tocList($toc) {
1404 global $wgJsMimeType;
1405 $title = wfMsgHtml('toc') ;
1407 '<table id="toc" class="toc" summary="' . $title .'"><tr><td>'
1408 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
1410 # no trailing newline, script should not be wrapped in a
1412 . "</ul>\n</td></tr></table>"
1413 . '<script type="' . $wgJsMimeType . '">'
1414 . ' if (window.showTocToggle) {'
1415 . ' var tocShowText = "' . wfEscapeJsString( wfMsg('showtoc') ) . '";'
1416 . ' var tocHideText = "' . wfEscapeJsString( wfMsg('hidetoc') ) . '";'
1417 . ' showTocToggle();'
1423 * Used to generate section edit links that point to "other" pages
1424 * (sections that are really part of included pages).
1426 * @param $title Title string.
1427 * @param $section Integer: section number.
1429 public function editSectionLinkForOther( $title, $section ) {
1430 wfDeprecated( __METHOD__
);
1431 $title = Title
::newFromText( $title );
1432 return $this->doEditSectionLink( $title, $section );
1436 * @param $nt Title object.
1437 * @param $section Integer: section number.
1438 * @param $hint Link String: title, or default if omitted or empty
1440 public function editSectionLink( Title
$nt, $section, $hint = '' ) {
1441 wfDeprecated( __METHOD__
);
1442 if( $hint === '' ) {
1443 # No way to pass an actual empty $hint here! The new interface al-
1444 # lows this, so we have to do this for compatibility.
1447 return $this->doEditSectionLink( $nt, $section, $hint );
1451 * Create a section edit link. This supersedes editSectionLink() and
1452 * editSectionLinkForOther().
1454 * @param $nt Title The title being linked to (may not be the same as
1455 * $wgTitle, if the section is included from a template)
1456 * @param $section string The designation of the section being pointed to,
1457 * to be included in the link, like "§ion=$section"
1458 * @param $tooltip string The tooltip to use for the link: will be escaped
1459 * and wrapped in the 'editsectionhint' message
1460 * @return string HTML to use for edit link
1462 public function doEditSectionLink( Title
$nt, $section, $tooltip = null ) {
1464 if( !is_null( $tooltip ) ) {
1465 $attribs['title'] = wfMsg( 'editsectionhint', $tooltip );
1467 $link = $this->link( $nt, wfMsg('editsection'),
1469 array( 'action' => 'edit', 'section' => $section ),
1470 array( 'noclasses', 'known' )
1473 # Run the old hook. This takes up half of the function . . . hopefully
1474 # we can rid of it someday.
1477 $attribs = wfMsgHtml( 'editsectionhint', htmlspecialchars( $tooltip ) );
1478 $attribs = " title=\"$attribs\"";
1481 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result ) );
1482 if( !is_null( $result ) ) {
1483 # For reverse compatibility, add the brackets *after* the hook is
1484 # run, and even add them to hook-provided text. (This is the main
1485 # reason that the EditSectionLink hook is deprecated in favor of
1486 # DoEditSectionLink: it can't change the brackets or the span.)
1487 $result = wfMsgHtml( 'editsection-brackets', $result );
1488 return "<span class=\"editsection\">$result</span>";
1491 # Add the brackets and the span, and *then* run the nice new hook, with
1492 # clean and non-redundant arguments.
1493 $result = wfMsgHtml( 'editsection-brackets', $link );
1494 $result = "<span class=\"editsection\">$result</span>";
1496 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result ) );
1501 * Create a headline for content
1503 * @param int $level The level of the headline (1-6)
1504 * @param string $attribs Any attributes for the headline, starting with a space and ending with '>'
1505 * This *must* be at least '>' for no attribs
1506 * @param string $anchor The anchor to give the headline (the bit after the #)
1507 * @param string $text The text of the header
1508 * @param string $link HTML to add for the section edit link
1510 * @return string HTML headline
1512 public function makeHeadline( $level, $attribs, $anchor, $text, $link ) {
1513 return "<a name=\"$anchor\"></a><h$level$attribs$link <span class=\"mw-headline\">$text</span></h$level>";
1517 * Split a link trail, return the "inside" portion and the remainder of the trail
1518 * as a two-element array
1522 static function splitTrail( $trail ) {
1523 static $regex = false;
1524 if ( $regex === false ) {
1526 $regex = $wgContLang->linkTrail();
1529 if ( '' != $trail ) {
1531 if ( preg_match( $regex, $trail, $m ) ) {
1536 return array( $inside, $trail );
1540 * Generate a rollback link for a given revision. Currently it's the
1541 * caller's responsibility to ensure that the revision is the top one. If
1542 * it's not, of course, the user will get an error message.
1544 * If the calling page is called with the parameter &bot=1, all rollback
1545 * links also get that parameter. It causes the edit itself and the rollback
1546 * to be marked as "bot" edits. Bot edits are hidden by default from recent
1547 * changes, so this allows sysops to combat a busy vandal without bothering
1550 * @param Revision $rev
1552 function generateRollback( $rev ) {
1553 return '<span class="mw-rollback-link">['
1554 . $this->buildRollbackLink( $rev )
1559 * Build a raw rollback link, useful for collections of "tool" links
1561 * @param Revision $rev
1564 public function buildRollbackLink( $rev ) {
1565 global $wgRequest, $wgUser;
1566 $title = $rev->getTitle();
1568 'action' => 'rollback',
1569 'from' => $rev->getUserText()
1571 if( $wgRequest->getBool( 'bot' ) ) {
1572 $query['bot'] = '1';
1574 $query['token'] = $wgUser->editToken( array( $title->getPrefixedText(),
1575 $rev->getUserText() ) );
1576 return $this->link( $title, wfMsgHtml( 'rollbacklink' ),
1577 array( 'title' => wfMsg( 'tooltip-rollback' ) ),
1578 $query, array( 'known', 'noclasses' ) );
1582 * Returns HTML for the "templates used on this page" list.
1584 * @param array $templates Array of templates from Article::getUsedTemplate
1586 * @param bool $preview Whether this is for a preview
1587 * @param bool $section Whether this is for a section edit
1588 * @return string HTML output
1590 public function formatTemplates( $templates, $preview = false, $section = false) {
1592 wfProfileIn( __METHOD__
);
1594 $sk = $wgUser->getSkin();
1597 if ( count( $templates ) > 0 ) {
1598 # Do a batch existence check
1599 $batch = new LinkBatch
;
1600 foreach( $templates as $title ) {
1601 $batch->addObj( $title );
1605 # Construct the HTML
1606 $outText = '<div class="mw-templatesUsedExplanation">';
1608 $outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ) );
1609 } elseif ( $section ) {
1610 $outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ) );
1612 $outText .= wfMsgExt( 'templatesused', array( 'parse' ) );
1614 $outText .= '</div><ul>';
1616 usort( $templates, array( 'Title', 'compare' ) );
1617 foreach ( $templates as $titleObj ) {
1618 $r = $titleObj->getRestrictions( 'edit' );
1619 if ( in_array( 'sysop', $r ) ) {
1620 $protected = wfMsgExt( 'template-protected', array( 'parseinline' ) );
1621 } elseif ( in_array( 'autoconfirmed', $r ) ) {
1622 $protected = wfMsgExt( 'template-semiprotected', array( 'parseinline' ) );
1626 $outText .= '<li>' . $sk->link( $titleObj ) . ' ' . $protected . '</li>';
1628 $outText .= '</ul>';
1630 wfProfileOut( __METHOD__
);
1635 * Returns HTML for the "hidden categories on this page" list.
1637 * @param array $hiddencats Array of hidden categories from Article::getHiddenCategories
1639 * @return string HTML output
1641 public function formatHiddenCategories( $hiddencats) {
1642 global $wgUser, $wgLang;
1643 wfProfileIn( __METHOD__
);
1645 $sk = $wgUser->getSkin();
1648 if ( count( $hiddencats ) > 0 ) {
1649 # Construct the HTML
1650 $outText = '<div class="mw-hiddenCategoriesExplanation">';
1651 $outText .= wfMsgExt( 'hiddencategories', array( 'parse' ), $wgLang->formatnum( count( $hiddencats ) ) );
1652 $outText .= '</div><ul>';
1654 foreach ( $hiddencats as $titleObj ) {
1655 $outText .= '<li>' . $sk->link( $titleObj, null, array(), array(), 'known' ) . '</li>'; # If it's hidden, it must exist - no need to check with a LinkBatch
1657 $outText .= '</ul>';
1659 wfProfileOut( __METHOD__
);
1664 * Format a size in bytes for output, using an appropriate
1665 * unit (B, KB, MB or GB) according to the magnitude in question
1667 * @param $size Size to format
1670 public function formatSize( $size ) {
1672 return htmlspecialchars( $wgLang->formatSize( $size ) );
1676 * Given the id of an interface element, constructs the appropriate title
1677 * and accesskey attributes from the system messages. (Note, this is usu-
1678 * ally the id but isn't always, because sometimes the accesskey needs to
1679 * go on a different element than the id, for reverse-compatibility, etc.)
1681 * @param string $name Id of the element, minus prefixes.
1682 * @return string title and accesskey attributes, ready to drop in an
1683 * element (e.g., ' title="This does something [x]" accesskey="x"').
1685 public function tooltipAndAccesskey( $name ) {
1686 wfProfileIn( __METHOD__
);
1689 $tooltip = wfMsg( "tooltip-$name" );
1690 if( !wfEmptyMsg( "tooltip-$name", $tooltip ) && $tooltip != '-' ) {
1691 // Compatibility: formerly some tooltips had [alt-.] hardcoded
1692 $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
1693 $attribs['title'] = $tooltip;
1696 $accesskey = wfMsg( "accesskey-$name" );
1697 if( $accesskey && $accesskey != '-' &&
1698 !wfEmptyMsg( "accesskey-$name", $accesskey ) ) {
1699 if( isset( $attribs['title'] ) ) {
1700 $attribs['title'] .= " [$accesskey]";
1702 $attribs['accesskey'] = $accesskey;
1705 $ret = Xml
::expandAttributes( $attribs );
1706 wfProfileOut( __METHOD__
);
1711 * Given the id of an interface element, constructs the appropriate title
1712 * attribute from the system messages. (Note, this is usually the id but
1713 * isn't always, because sometimes the accesskey needs to go on a different
1714 * element than the id, for reverse-compatibility, etc.)
1716 * @param string $name Id of the element, minus prefixes.
1717 * @param mixed $options null or the string 'withaccess' to add an access-
1719 * @return string title attribute, ready to drop in an element
1720 * (e.g., ' title="This does something"').
1722 public function tooltip( $name, $options = null ) {
1723 wfProfileIn( __METHOD__
);
1727 $tooltip = wfMsg( "tooltip-$name" );
1728 if( !wfEmptyMsg( "tooltip-$name", $tooltip ) && $tooltip != '-' ) {
1729 $attribs['title'] = $tooltip;
1732 if( isset( $attribs['title'] ) && $options == 'withaccess' ) {
1733 $accesskey = wfMsg( "accesskey-$name" );
1734 if( $accesskey && $accesskey != '-' &&
1735 !wfEmptyMsg( "accesskey-$name", $accesskey ) ) {
1736 $attribs['title'] .= " [$accesskey]";
1740 $ret = Xml
::expandAttributes( $attribs );
1741 wfProfileOut( __METHOD__
);