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 * 'forcearticlepath': Use the article path always, even with a querystring.
170 * Has compatibility issues on some setups, so avoid wherever possible.
171 * @return string HTML <a> attribute
173 public function link( $target, $text = null, $customAttribs = array(), $query = array(), $options = array() ) {
174 wfProfileIn( __METHOD__
);
175 if( !$target instanceof Title
) {
176 return "<!-- ERROR -->$text";
178 $options = (array)$options;
181 if( !wfRunHooks( 'LinkBegin', array( $this, $target, &$text,
182 &$customAttribs, &$query, &$options, &$ret ) ) ) {
183 wfProfileOut( __METHOD__
);
187 # Normalize the Title if it's a special page
188 $target = $this->normaliseSpecialPage( $target );
190 # If we don't know whether the page exists, let's find out.
191 wfProfileIn( __METHOD__
. '-checkPageExistence' );
192 if( !in_array( 'known', $options ) and !in_array( 'broken', $options ) ) {
193 if( $target->getNamespace() == NS_SPECIAL
) {
194 if( SpecialPage
::exists( $target->getDbKey() ) ) {
195 $options []= 'known';
197 $options []= 'broken';
199 } elseif( $target->isAlwaysKnown() or
200 ($target->getPrefixedText() == '' and $target->getFragment() != '')
201 or $target->exists() ) {
202 $options []= 'known';
204 $options []= 'broken';
207 wfProfileOut( __METHOD__
. '-checkPageExistence' );
210 if( in_array( "forcearticlepath", $options ) && $query ){
215 # Note: we want the href attribute first, for prettiness.
216 $attribs = array( 'href' => $this->linkUrl( $target, $query, $options ) );
217 if( in_array( 'forcearticlepath', $options ) && $oldquery ){
218 $attribs['href'] = wfAppendQuery( $attribs['href'], wfArrayToCgi( $oldquery ) );
221 $attribs = array_merge(
223 $this->linkAttribs( $target, $customAttribs, $options )
225 if( is_null( $text ) ) {
226 $text = $this->linkText( $target );
230 if( wfRunHooks( 'LinkEnd', array( $this, $target, $options, &$text,
231 &$attribs, &$ret ) ) ) {
232 $ret = Xml
::openElement( 'a', $attribs )
234 . Xml
::closeElement( 'a' );
237 wfProfileOut( __METHOD__
);
241 private function linkUrl( $target, $query, $options ) {
242 wfProfileIn( __METHOD__
);
243 # We don't want to include fragments for broken links, because they
244 # generally make no sense.
245 if( in_array( 'broken', $options ) and $target->mFragment
!== '' ) {
246 $target = clone $target;
247 $target->mFragment
= '';
250 # If it's a broken link, add the appropriate query pieces, unless
251 # there's already an action specified, or unless 'edit' makes no sense
252 # (i.e., for a nonexistent special page).
253 if( in_array( 'broken', $options ) and empty( $query['action'] )
254 and $target->getNamespace() != NS_SPECIAL
) {
255 $query['action'] = 'edit';
256 $query['redlink'] = '1';
258 $ret = $target->getLinkUrl( $query );
259 wfProfileOut( __METHOD__
);
263 private function linkAttribs( $target, $attribs, $options ) {
264 wfProfileIn( __METHOD__
);
268 if( !in_array( 'noclasses', $options ) ) {
269 wfProfileIn( __METHOD__
. '-getClasses' );
270 # Now build the classes.
273 if( in_array( 'broken', $options ) ) {
277 if( $target->isExternal() ) {
278 $classes[] = 'extiw';
281 # Note that redirects never count as stubs here.
282 if ( $target->isRedirect() ) {
283 $classes[] = 'mw-redirect';
284 } elseif( $target->isContentPage() ) {
286 $threshold = $wgUser->getOption( 'stubthreshold' );
287 if( $threshold > 0 and $target->exists() and $target->getLength() < $threshold ) {
291 if( $classes != array() ) {
292 $defaults['class'] = implode( ' ', $classes );
294 wfProfileOut( __METHOD__
. '-getClasses' );
297 # Get a default title attribute.
298 if( in_array( 'known', $options ) ) {
299 $defaults['title'] = $target->getPrefixedText();
301 $defaults['title'] = wfMsg( 'red-link-title', $target->getPrefixedText() );
304 # Finally, merge the custom attribs with the default ones, and iterate
305 # over that, deleting all "false" attributes.
307 $merged = Sanitizer
::mergeAttributes( $defaults, $attribs );
308 foreach( $merged as $key => $val ) {
309 # A false value suppresses the attribute, and we don't want the
310 # href attribute to be overridden.
311 if( $key != 'href' and $val !== false ) {
315 wfProfileOut( __METHOD__
);
319 private function linkText( $target ) {
320 # We might be passed a non-Title by make*LinkObj(). Fail gracefully.
321 if( !$target instanceof Title
) {
325 # If the target is just a fragment, with no title, we return the frag-
326 # ment text. Otherwise, we return the title text itself.
327 if( $target->getPrefixedText() === '' and $target->getFragment() !== '' ) {
328 return htmlspecialchars( $target->getFragment() );
330 return htmlspecialchars( $target->getPrefixedText() );
334 * @deprecated Use link()
336 * This function is a shortcut to makeLinkObj(Title::newFromText($title),...). Do not call
337 * it if you already have a title object handy. See makeLinkObj for further documentation.
339 * @param $title String: the text of the title
340 * @param $text String: link text
341 * @param $query String: optional query part
342 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
343 * be included in the link text. Other characters will be appended after
344 * the end of the link.
346 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
347 wfProfileIn( __METHOD__
);
348 $nt = Title
::newFromText( $title );
349 if ( $nt instanceof Title
) {
350 $result = $this->makeLinkObj( $nt, $text, $query, $trail );
352 wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" );
353 $result = $text == "" ?
$title : $text;
356 wfProfileOut( __METHOD__
);
361 * @deprecated Use link()
363 * This function is a shortcut to makeKnownLinkObj(Title::newFromText($title),...). Do not call
364 * it if you already have a title object handy. See makeKnownLinkObj for further documentation.
366 * @param $title String: the text of the title
367 * @param $text String: link text
368 * @param $query String: optional query part
369 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
370 * be included in the link text. Other characters will be appended after
371 * the end of the link.
373 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
374 $nt = Title
::newFromText( $title );
375 if ( $nt instanceof Title
) {
376 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix , $aprops );
378 wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" );
379 return $text == '' ?
$title : $text;
384 * @deprecated Use link()
386 * This function is a shortcut to makeBrokenLinkObj(Title::newFromText($title),...). Do not call
387 * it if you already have a title object handy. See makeBrokenLinkObj for further documentation.
389 * @param string $title The text of the title
390 * @param string $text Link text
391 * @param string $query Optional query part
392 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
393 * be included in the link text. Other characters will be appended after
394 * the end of the link.
396 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
397 $nt = Title
::newFromText( $title );
398 if ( $nt instanceof Title
) {
399 return $this->makeBrokenLinkObj( $nt, $text, $query, $trail );
401 wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" );
402 return $text == '' ?
$title : $text;
407 * @deprecated Use link()
409 * This function is a shortcut to makeStubLinkObj(Title::newFromText($title),...). Do not call
410 * it if you already have a title object handy. See makeStubLinkObj for further documentation.
412 * @param $title String: the text of the title
413 * @param $text String: link text
414 * @param $query String: optional query part
415 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
416 * be included in the link text. Other characters will be appended after
417 * the end of the link.
419 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
420 wfDeprecated( __METHOD__
);
421 $nt = Title
::newFromText( $title );
422 if ( $nt instanceof Title
) {
423 return $this->makeStubLinkObj( $nt, $text, $query, $trail );
425 wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" );
426 return $text == '' ?
$title : $text;
431 * @deprecated Use link()
433 * Make a link for a title which may or may not be in the database. If you need to
434 * call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
435 * call to this will result in a DB query.
437 * @param $nt Title: the title object to make the link from, e.g. from
438 * Title::newFromText.
439 * @param $text String: link text
440 * @param $query String: optional query part
441 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
442 * be included in the link text. Other characters will be appended after
443 * the end of the link.
444 * @param $prefix String: optional prefix. As trail, only before instead of after.
446 function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
448 wfProfileIn( __METHOD__
);
450 $query = wfCgiToArray( $query );
451 list( $inside, $trail ) = Linker
::splitTrail( $trail );
453 $text = $this->linkText( $nt );
456 $ret = $this->link( $nt, "$prefix$text$inside", array(), $query ) . $trail;
458 wfProfileOut( __METHOD__
);
463 * @deprecated Use link()
465 * Make a link for a title which definitely exists. This is faster than makeLinkObj because
466 * it doesn't have to do a database query. It's also valid for interwiki titles and special
469 * @param $nt Title object of target page
470 * @param $text String: text to replace the title
471 * @param $query String: link target
472 * @param $trail String: text after link
473 * @param $prefix String: text before link text
474 * @param $aprops String: extra attributes to the a-element
475 * @param $style String: style to apply - if empty, use getInternalLinkAttributesObj instead
476 * @return the a-element
478 function makeKnownLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
479 wfProfileIn( __METHOD__
);
482 $text = $this->linkText( $title );
484 $attribs = Sanitizer
::mergeAttributes(
485 Sanitizer
::decodeTagAttributes( $aprops ),
486 Sanitizer
::decodeTagAttributes( $style )
488 $query = wfCgiToArray( $query );
489 list( $inside, $trail ) = Linker
::splitTrail( $trail );
491 $ret = $this->link( $title, "$prefix$text$inside", $attribs, $query,
492 array( 'known', 'noclasses' ) ) . $trail;
494 wfProfileOut( __METHOD__
);
499 * @deprecated Use link()
501 * Make a red link to the edit page of a given title.
503 * @param $nt Title object of the target page
504 * @param $text String: Link text
505 * @param $query String: Optional query part
506 * @param $trail String: Optional trail. Alphabetic characters at the start of this string will
507 * be included in the link text. Other characters will be appended after
508 * the end of the link.
510 function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
511 wfProfileIn( __METHOD__
);
513 list( $inside, $trail ) = Linker
::splitTrail( $trail );
515 $text = $this->linkText( $title );
517 $nt = $this->normaliseSpecialPage( $title );
519 $ret = $this->link( $title, "$prefix$text$inside", array(),
520 wfCgiToArray( $query ), 'broken' ) . $trail;
522 wfProfileOut( __METHOD__
);
527 * @deprecated Use link()
529 * Make a brown link to a short article.
531 * @param $nt Title object of the target page
532 * @param $text String: link text
533 * @param $query String: optional query part
534 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
535 * be included in the link text. Other characters will be appended after
536 * the end of the link.
538 function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
539 wfDeprecated( __METHOD__
);
540 return $this->makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix );
544 * @deprecated Use link()
546 * Make a coloured link.
548 * @param $nt Title object of the target page
549 * @param $colour Integer: colour of the link
550 * @param $text String: link text
551 * @param $query String: optional query part
552 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
553 * be included in the link text. Other characters will be appended after
554 * the end of the link.
556 function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
558 $style = $this->getInternalLinkAttributesObj( $nt, $text, $colour );
560 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style );
564 * Generate either a normal exists-style link or a stub link, depending
565 * on the given page size.
567 * @param $size Integer
568 * @param $nt Title object.
569 * @param $text String
570 * @param $query String
571 * @param $trail String
572 * @param $prefix String
573 * @return string HTML of link
575 function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
577 $threshold = intval( $wgUser->getOption( 'stubthreshold' ) );
578 $colour = ( $size < $threshold ) ?
'stub' : '';
579 return $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
583 * Make appropriate markup for a link to the current article. This is currently rendered
584 * as the bold link text. The calling sequence is the same as the other make*LinkObj functions,
585 * despite $query not being used.
587 function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
589 $text = htmlspecialchars( $nt->getPrefixedText() );
591 list( $inside, $trail ) = Linker
::splitTrail( $trail );
592 return "<strong class=\"selflink\">{$prefix}{$text}{$inside}</strong>{$trail}";
595 function normaliseSpecialPage( Title
$title ) {
596 if ( $title->getNamespace() == NS_SPECIAL
) {
597 list( $name, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $title->getDBkey() );
598 if ( !$name ) return $title;
599 $ret = SpecialPage
::getTitleFor( $name, $subpage );
600 $ret->mFragment
= $title->getFragment();
607 /** @todo document */
608 function fnamePart( $url ) {
609 $basename = strrchr( $url, '/' );
610 if ( false === $basename ) {
613 $basename = substr( $basename, 1 );
618 /** Obsolete alias */
619 function makeImage( $url, $alt = '' ) {
620 wfDeprecated( __METHOD__
);
621 return $this->makeExternalImage( $url, $alt );
624 /** @todo document */
625 function makeExternalImage( $url, $alt = '' ) {
627 $alt = $this->fnamePart( $url );
630 $success = wfRunHooks('LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
632 wfDebug("Hook LinkerMakeExternalImage changed the output of external image with url {$url} and alt text {$alt} to {$img}", true);
635 return Xml
::element( 'img',
642 * Creates the HTML source for images
643 * @deprecated use makeImageLink2
645 * @param object $title
646 * @param string $label label text
647 * @param string $alt alt text
648 * @param string $align horizontal alignment: none, left, center, right)
649 * @param array $handlerParams Parameters to be passed to the media handler
650 * @param boolean $framed shows image in original size in a frame
651 * @param boolean $thumb shows image as thumbnail in a frame
652 * @param string $manualthumb image name for the manual thumbnail
653 * @param string $valign vertical alignment: baseline, sub, super, top, text-top, middle, bottom, text-bottom
654 * @param string $time, timestamp of the file, set as false for current
657 function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(), $framed = false,
658 $thumb = false, $manualthumb = '', $valign = '', $time = false )
660 $frameParams = array( 'alt' => $alt, 'caption' => $label );
662 $frameParams['align'] = $align;
665 $frameParams['framed'] = true;
668 $frameParams['thumbnail'] = true;
670 if ( $manualthumb ) {
671 $frameParams['manualthumb'] = $manualthumb;
674 $frameParams['valign'] = $valign;
676 $file = wfFindFile( $title, $time );
677 return $this->makeImageLink2( $title, $file, $frameParams, $handlerParams, $time );
681 * Given parameters derived from [[Image:Foo|options...]], generate the
682 * HTML that that syntax inserts in the page.
684 * @param Title $title Title object
685 * @param File $file File object, or false if it doesn't exist
687 * @param array $frameParams Associative array of parameters external to the media handler.
688 * Boolean parameters are indicated by presence or absence, the value is arbitrary and
689 * will often be false.
690 * thumbnail If present, downscale and frame
691 * manualthumb Image name to use as a thumbnail, instead of automatic scaling
692 * framed Shows image in original size in a frame
693 * frameless Downscale but don't frame
694 * upright If present, tweak default sizes for portrait orientation
695 * upright_factor Fudge factor for "upright" tweak (default 0.75)
696 * border If present, show a border around the image
697 * align Horizontal alignment (left, right, center, none)
698 * valign Vertical alignment (baseline, sub, super, top, text-top, middle,
699 * bottom, text-bottom)
700 * alt Alternate text for image (i.e. alt attribute). Plain text.
701 * caption HTML for image caption.
703 * @param array $handlerParams Associative array of media handler parameters, to be passed
704 * to transform(). Typical keys are "width" and "page".
705 * @param string $time, timestamp of the file, set as false for current
706 * @param string $query, query params for desc url
707 * @return string HTML for an image, with links, wrappers, etc.
709 function makeImageLink2( Title
$title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
711 if( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$this, &$title,
712 &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
716 global $wgContLang, $wgUser, $wgThumbLimits, $wgThumbUpright;
717 if ( $file && !$file->allowInlineDisplay() ) {
718 wfDebug( __METHOD__
.': '.$title->getPrefixedDBkey()." does not allow inline display\n" );
719 return $this->link( $title );
724 $hp =& $handlerParams;
726 // Clean up parameters
727 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
728 if ( !isset( $fp['align'] ) ) $fp['align'] = '';
729 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
731 $prefix = $postfix = '';
733 if ( 'center' == $fp['align'] )
735 $prefix = '<div class="center">';
737 $fp['align'] = 'none';
739 if ( $file && !isset( $hp['width'] ) ) {
740 $hp['width'] = $file->getWidth( $page );
742 if( isset( $fp['thumbnail'] ) ||
isset( $fp['framed'] ) ||
isset( $fp['frameless'] ) ||
!$hp['width'] ) {
743 $wopt = $wgUser->getOption( 'thumbsize' );
745 if( !isset( $wgThumbLimits[$wopt] ) ) {
746 $wopt = User
::getDefaultOption( 'thumbsize' );
749 // Reduce width for upright images when parameter 'upright' is used
750 if ( isset( $fp['upright'] ) && $fp['upright'] == 0 ) {
751 $fp['upright'] = $wgThumbUpright;
753 // Use width which is smaller: real image width or user preference width
754 // 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
755 $prefWidth = isset( $fp['upright'] ) ?
756 round( $wgThumbLimits[$wopt] * $fp['upright'], -1 ) :
757 $wgThumbLimits[$wopt];
758 if ( $hp['width'] <= 0 ||
$prefWidth < $hp['width'] ) {
759 $hp['width'] = $prefWidth;
764 if ( isset( $fp['thumbnail'] ) ||
isset( $fp['manualthumb'] ) ||
isset( $fp['framed'] ) ) {
766 # Create a thumbnail. Alignment depends on language
767 # writing direction, # right aligned for left-to-right-
768 # languages ("Western languages"), left-aligned
769 # for right-to-left-languages ("Semitic languages")
771 # If thumbnail width has not been provided, it is set
772 # to the default user option as specified in Language*.php
773 if ( $fp['align'] == '' ) {
774 $fp['align'] = $wgContLang->isRTL() ?
'left' : 'right';
776 return $prefix.$this->makeThumbLink2( $title, $file, $fp, $hp, $time, $query ).$postfix;
779 if ( $file && isset( $fp['frameless'] ) ) {
780 $srcWidth = $file->getWidth( $page );
781 # For "frameless" option: do not present an image bigger than the source (for bitmap-style images)
782 # This is the same behaviour as the "thumb" option does it already.
783 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
784 $hp['width'] = $srcWidth;
788 if ( $file && $hp['width'] ) {
789 # Create a resized image, without the additional thumbnail features
790 $thumb = $file->transform( $hp );
796 $s = $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
798 $s = $thumb->toHtml( array(
800 'desc-query' => $query,
802 'valign' => isset( $fp['valign'] ) ?
$fp['valign'] : false ,
803 'img-class' => isset( $fp['border'] ) ?
'thumbborder' : false ) );
805 if ( '' != $fp['align'] ) {
806 $s = "<div class=\"float{$fp['align']}\"><span>{$s}</span></div>";
808 return str_replace("\n", ' ',$prefix.$s.$postfix);
812 * Make HTML for a thumbnail including image, border and caption
813 * @param Title $title
814 * @param File $file File object or false if it doesn't exist
816 function makeThumbLinkObj( Title
$title, $file, $label = '', $alt, $align = 'right', $params = array(), $framed=false , $manualthumb = "" ) {
817 $frameParams = array(
822 if ( $framed ) $frameParams['framed'] = true;
823 if ( $manualthumb ) $frameParams['manualthumb'] = $manualthumb;
824 return $this->makeThumbLink2( $title, $file, $frameParams, $params );
827 function makeThumbLink2( Title
$title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
828 global $wgStylePath, $wgContLang;
829 $exists = $file && $file->exists();
833 $hp =& $handlerParams;
835 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
836 if ( !isset( $fp['align'] ) ) $fp['align'] = 'right';
837 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
838 if ( !isset( $fp['caption'] ) ) $fp['caption'] = '';
840 if ( empty( $hp['width'] ) ) {
841 // Reduce width for upright images when parameter 'upright' is used
842 $hp['width'] = isset( $fp['upright'] ) ?
130 : 180;
847 $outerWidth = $hp['width'] +
2;
849 if ( isset( $fp['manualthumb'] ) ) {
850 # Use manually specified thumbnail
851 $manual_title = Title
::makeTitleSafe( NS_IMAGE
, $fp['manualthumb'] );
852 if( $manual_title ) {
853 $manual_img = wfFindFile( $manual_title );
855 $thumb = $manual_img->getUnscaledThumb();
860 } elseif ( isset( $fp['framed'] ) ) {
861 // Use image dimensions, don't scale
862 $thumb = $file->getUnscaledThumb( $page );
864 # Do not present an image bigger than the source, for bitmap-style images
865 # This is a hack to maintain compatibility with arbitrary pre-1.10 behaviour
866 $srcWidth = $file->getWidth( $page );
867 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
868 $hp['width'] = $srcWidth;
870 $thumb = $file->transform( $hp );
874 $outerWidth = $thumb->getWidth() +
2;
876 $outerWidth = $hp['width'] +
2;
881 $query = $query ?
'&page=' . urlencode( $page ) : 'page=' . urlencode( $page );
883 $url = $title->getLocalURL( $query );
885 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
887 $s = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
889 $s .= $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
891 } elseif ( !$thumb ) {
892 $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
895 $s .= $thumb->toHtml( array(
897 'img-class' => 'thumbimage',
899 'desc-query' => $query ) );
900 if ( isset( $fp['framed'] ) ) {
903 $zoomicon = '<div class="magnify">'.
904 '<a href="'.$url.'" class="internal" title="'.$more.'">'.
905 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
906 'width="15" height="11" alt="" /></a></div>';
909 $s .= ' <div class="thumbcaption">'.$zoomicon.$fp['caption']."</div></div></div>";
910 return str_replace("\n", ' ', $s);
914 * Make a "broken" link to an image
916 * @param Title $title Image title
917 * @param string $text Link label
918 * @param string $query Query string
919 * @param string $trail Link trail
920 * @param string $prefix Link prefix
921 * @param bool $time, a file of a certain timestamp was requested
924 public function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '', $time = false ) {
925 global $wgEnableUploads;
926 if( $title instanceof Title
) {
927 wfProfileIn( __METHOD__
);
928 $currentExists = $time ?
( wfFindFile( $title ) != false ) : false;
929 if( $wgEnableUploads && !$currentExists ) {
930 $upload = SpecialPage
::getTitleFor( 'Upload' );
932 $text = htmlspecialchars( $title->getPrefixedText() );
933 $redir = RepoGroup
::singleton()->getLocalRepo()->checkRedirect( $title );
935 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
937 $q = 'wpDestFile=' . $title->getPartialUrl();
940 list( $inside, $trail ) = self
::splitTrail( $trail );
941 $style = $this->getInternalLinkAttributesObj( $title, $text, 'new' );
942 wfProfileOut( __METHOD__
);
943 return '<a href="' . $upload->escapeLocalUrl( $q ) . '"'
944 . $style . '>' . $prefix . $text . $inside . '</a>' . $trail;
946 wfProfileOut( __METHOD__
);
947 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
950 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
954 /** @deprecated use Linker::makeMediaLinkObj() */
955 function makeMediaLink( $name, $unused = '', $text = '', $time = false ) {
956 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
957 return $this->makeMediaLinkObj( $nt, $text, $time );
961 * Create a direct link to a given uploaded file.
963 * @param $title Title object.
964 * @param $text String: pre-sanitized HTML
965 * @param $time string: time image was created
966 * @return string HTML
969 * @todo Handle invalid or missing images better.
971 function makeMediaLinkObj( $title, $text = '', $time = false ) {
972 if( is_null( $title ) ) {
973 ### HOTFIX. Instead of breaking, return empty string.
976 $img = wfFindFile( $title, $time );
978 $url = $img->getURL();
981 $upload = SpecialPage
::getTitleFor( 'Upload' );
982 $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $title->getDBkey() ) );
985 $alt = htmlspecialchars( $title->getText() );
989 $u = htmlspecialchars( $url );
990 return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\">{$text}</a>";
994 /** @todo document */
995 function specialLink( $name, $key = '' ) {
998 if ( '' == $key ) { $key = strtolower( $name ); }
999 $pn = $wgContLang->ucfirst( $name );
1000 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1004 /** @todo document */
1005 function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) {
1006 $attribsText = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
1008 $attribsText .= Xml
::expandAttributes( $attribs );
1010 $url = htmlspecialchars( $url );
1012 $text = htmlspecialchars( $text );
1015 $success = wfRunHooks('LinkerMakeExternalLink', array( &$url, &$text, &$link ) );
1017 wfDebug("Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}", true);
1020 return '<a href="'.$url.'"'.$attribsText.'>'.$text.'</a>';
1024 * Make user link (or user contributions for unregistered users)
1025 * @param $userId Integer: user id in database.
1026 * @param $userText String: user name in database
1027 * @return string HTML fragment
1030 function userLink( $userId, $userText ) {
1031 if( $userId == 0 ) {
1032 $page = SpecialPage
::getTitleFor( 'Contributions', $userText );
1034 $page = Title
::makeTitle( NS_USER
, $userText );
1036 return $this->link( $page, htmlspecialchars( $userText ) );
1040 * Generate standard user tool links (talk, contributions, block link, etc.)
1042 * @param int $userId User identifier
1043 * @param string $userText User name or IP address
1044 * @param bool $redContribsWhenNoEdits Should the contributions link be red if the user has no edits?
1045 * @param int $flags Customisation flags (e.g. self::TOOL_LINKS_NOBLOCK)
1046 * @param int $edits, user edit count (optional, for performance)
1049 public function userToolLinks( $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits=null ) {
1050 global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans;
1051 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
1052 $blockable = ( $wgSysopUserBans ||
0 == $userId ) && !$flags & self
::TOOL_LINKS_NOBLOCK
;
1056 $items[] = $this->userTalkLink( $userId, $userText );
1059 // check if the user has an edit
1061 if( $redContribsWhenNoEdits ) {
1062 $count = !is_null($edits) ?
$edits : User
::edits( $userId );
1064 $attribs['class'] = 'new';
1067 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $userText );
1069 $items[] = $this->link( $contribsPage, wfMsgHtml( 'contribslink' ), $attribs );
1071 if( $blockable && $wgUser->isAllowed( 'block' ) ) {
1072 $items[] = $this->blockLink( $userId, $userText );
1076 return ' (' . implode( ' | ', $items ) . ')';
1083 * Alias for userToolLinks( $userId, $userText, true );
1084 * @param int $userId User identifier
1085 * @param string $userText User name or IP address
1086 * @param int $edits, user edit count (optional, for performance)
1088 public function userToolLinksRedContribs( $userId, $userText, $edits=null ) {
1089 return $this->userToolLinks( $userId, $userText, true, 0, $edits );
1094 * @param $userId Integer: user id in database.
1095 * @param $userText String: user name in database.
1096 * @return string HTML fragment with user talk link
1099 function userTalkLink( $userId, $userText ) {
1100 $userTalkPage = Title
::makeTitle( NS_USER_TALK
, $userText );
1101 $userTalkLink = $this->link( $userTalkPage, wfMsgHtml( 'talkpagelinktext' ) );
1102 return $userTalkLink;
1106 * @param $userId Integer: userid
1107 * @param $userText String: user name in database.
1108 * @return string HTML fragment with block link
1111 function blockLink( $userId, $userText ) {
1112 $blockPage = SpecialPage
::getTitleFor( 'Blockip', $userText );
1113 $blockLink = $this->link( $blockPage, wfMsgHtml( 'blocklink' ) );
1118 * Generate a user link if the current user is allowed to view it
1119 * @param $rev Revision object.
1120 * @param $isPublic, bool, show only if all users can see it
1121 * @return string HTML
1123 function revUserLink( $rev, $isPublic = false ) {
1124 if( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1125 $link = wfMsgHtml( 'rev-deleted-user' );
1126 } else if( $rev->userCan( Revision
::DELETED_USER
) ) {
1127 $link = $this->userLink( $rev->getUser( Revision
::FOR_THIS_USER
),
1128 $rev->getUserText( Revision
::FOR_THIS_USER
) );
1130 $link = wfMsgHtml( 'rev-deleted-user' );
1132 if( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1133 return '<span class="history-deleted">' . $link . '</span>';
1139 * Generate a user tool link cluster if the current user is allowed to view it
1140 * @param $rev Revision object.
1141 * @param $isPublic, bool, show only if all users can see it
1142 * @return string HTML
1144 function revUserTools( $rev, $isPublic = false ) {
1145 if( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1146 $link = wfMsgHtml( 'rev-deleted-user' );
1147 } else if( $rev->userCan( Revision
::DELETED_USER
) ) {
1148 $userId = $rev->getUser( Revision
::FOR_THIS_USER
);
1149 $userText = $rev->getUserText( Revision
::FOR_THIS_USER
);
1150 $link = $this->userLink( $userId, $userText ) .
1151 ' ' . $this->userToolLinks( $userId, $userText );
1153 $link = wfMsgHtml( 'rev-deleted-user' );
1155 if( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1156 return ' <span class="history-deleted">' . $link . '</span>';
1162 * This function is called by all recent changes variants, by the page history,
1163 * and by the user contributions list. It is responsible for formatting edit
1164 * comments. It escapes any HTML in the comment, but adds some CSS to format
1165 * auto-generated comments (from section editing) and formats [[wikilinks]].
1167 * @author Erik Moeller <moeller@scireview.de>
1169 * Note: there's not always a title to pass to this function.
1170 * Since you can't set a default parameter for a reference, I've turned it
1171 * temporarily to a value pass. Should be adjusted further. --brion
1173 * @param string $comment
1174 * @param mixed $title Title object (to generate link to the section in autocomment) or null
1175 * @param bool $local Whether section links should refer to local page
1177 function formatComment($comment, $title = NULL, $local = false) {
1178 wfProfileIn( __METHOD__
);
1180 # Sanitize text a bit:
1181 $comment = str_replace( "\n", " ", $comment );
1182 # Allow HTML entities (for bug 13815)
1183 $comment = Sanitizer
::escapeHtmlAllowEntities( $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 $this->autocommentTitle
= $title;
1209 $this->autocommentLocal
= $local;
1210 $comment = preg_replace_callback(
1211 '!(.*)/\*\s*(.*?)\s*\*/(.*)!',
1212 array( $this, 'formatAutocommentsCallback' ),
1214 unset( $this->autocommentTitle
);
1215 unset( $this->autocommentLocal
);
1219 private function formatAutocommentsCallback( $match ) {
1220 $title = $this->autocommentTitle
;
1221 $local = $this->autocommentLocal
;
1230 # Generate a valid anchor name from the section title.
1231 # Hackish, but should generally work - we strip wiki
1232 # syntax, including the magic [[: that is used to
1233 # "link rather than show" in case of images and
1234 # interlanguage links.
1235 $section = str_replace( '[[:', '', $section );
1236 $section = str_replace( '[[', '', $section );
1237 $section = str_replace( ']]', '', $section );
1239 $sectionTitle = Title
::newFromText( '#' . $section );
1241 $sectionTitle = Title
::makeTitleSafe( $title->getNamespace(),
1242 $title->getDBkey(), $section );
1244 if ( $sectionTitle ) {
1245 $link = $this->link( $sectionTitle,
1246 wfMsgForContent( 'sectionlink' ), array(), array(),
1252 $auto = "$link$auto";
1254 # written summary $presep autocomment (summary /* section */)
1255 $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
1258 # autocomment $postsep written summary (/* section */ summary)
1259 $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
1261 $auto = '<span class="autocomment">' . $auto . '</span>';
1262 $comment = $pre . $auto . $post;
1267 * Formats wiki links and media links in text; all other wiki formatting
1270 * @fixme doesn't handle sub-links as in image thumb texts like the main parser
1271 * @param string $comment Text to format links in
1274 public function formatLinksInComment( $comment ) {
1275 return preg_replace_callback(
1276 '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
1277 array( $this, 'formatLinksInCommentCallback' ),
1281 protected function formatLinksInCommentCallback( $match ) {
1284 $medians = '(?:' . preg_quote( MWNamespace
::getCanonicalName( NS_MEDIA
), '/' ) . '|';
1285 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA
), '/' ) . '):';
1287 $comment = $match[0];
1289 # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
1290 if( strpos( $match[1], '%' ) !== false ) {
1291 $match[1] = str_replace( array('<', '>'), array('<', '>'), urldecode($match[1]) );
1294 # Handle link renaming [[foo|text]] will show link as "text"
1295 if( "" != $match[3] ) {
1300 $submatch = array();
1301 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1302 # Media link; trail not supported.
1303 $linkRegexp = '/\[\[(.*?)\]\]/';
1304 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
1306 # Other kind of link
1307 if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
1308 $trail = $submatch[1];
1312 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1313 if (isset($match[1][0]) && $match[1][0] == ':')
1314 $match[1] = substr($match[1], 1);
1315 $thelink = $this->makeLink( $match[1], $text, "", $trail );
1317 $comment = preg_replace( $linkRegexp, StringUtils
::escapeRegexReplacement( $thelink ), $comment, 1 );
1323 * Wrap a comment in standard punctuation and formatting if
1324 * it's non-empty, otherwise return empty string.
1326 * @param string $comment
1327 * @param mixed $title Title object (to generate link to section in autocomment) or null
1328 * @param bool $local Whether section links should refer to local page
1332 function commentBlock( $comment, $title = NULL, $local = false ) {
1333 // '*' used to be the comment inserted by the software way back
1334 // in antiquity in case none was provided, here for backwards
1335 // compatability, acc. to brion -ævar
1336 if( $comment == '' ||
$comment == '*' ) {
1339 $formatted = $this->formatComment( $comment, $title, $local );
1340 return " <span class=\"comment\">($formatted)</span>";
1345 * Wrap and format the given revision's comment block, if the current
1346 * user is allowed to view it.
1348 * @param Revision $rev
1349 * @param bool $local Whether section links should refer to local page
1350 * @param $isPublic, show only if all users can see it
1351 * @return string HTML
1353 function revComment( Revision
$rev, $local = false, $isPublic = false ) {
1354 if( $rev->isDeleted( Revision
::DELETED_COMMENT
) && $isPublic ) {
1355 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1356 } else if( $rev->userCan( Revision
::DELETED_COMMENT
) ) {
1357 $block = $this->commentBlock( $rev->getComment( Revision
::FOR_THIS_USER
),
1358 $rev->getTitle(), $local );
1360 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1362 if( $rev->isDeleted( Revision
::DELETED_COMMENT
) ) {
1363 return " <span class=\"history-deleted\">$block</span>";
1368 public function formatRevisionSize( $size ) {
1370 $stxt = wfMsgExt( 'historyempty', 'parsemag' );
1373 $stxt = wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $size ) );
1376 $stxt = htmlspecialchars( $stxt );
1377 return "<span class=\"history-size\">$stxt</span>";
1380 /** @todo document */
1381 function tocIndent() {
1385 /** @todo document */
1386 function tocUnindent($level) {
1387 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ?
$level : 0 );
1391 * parameter level defines if we are on an indentation level
1393 function tocLine( $anchor, $tocline, $tocnumber, $level ) {
1394 return "\n<li class=\"toclevel-$level\"><a href=\"#" .
1395 $anchor . '"><span class="tocnumber">' .
1396 $tocnumber . '</span> <span class="toctext">' .
1397 $tocline . '</span></a>';
1400 /** @todo document */
1401 function tocLineEnd() {
1405 /** @todo document */
1406 function tocList($toc) {
1407 global $wgJsMimeType;
1408 $title = wfMsgHtml('toc') ;
1410 '<table id="toc" class="toc" summary="' . $title .'"><tr><td>'
1411 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
1413 # no trailing newline, script should not be wrapped in a
1415 . "</ul>\n</td></tr></table>"
1416 . '<script type="' . $wgJsMimeType . '">'
1417 . ' if (window.showTocToggle) {'
1418 . ' var tocShowText = "' . wfEscapeJsString( wfMsg('showtoc') ) . '";'
1419 . ' var tocHideText = "' . wfEscapeJsString( wfMsg('hidetoc') ) . '";'
1420 . ' showTocToggle();'
1426 * Used to generate section edit links that point to "other" pages
1427 * (sections that are really part of included pages).
1429 * @param $title Title string.
1430 * @param $section Integer: section number.
1432 public function editSectionLinkForOther( $title, $section ) {
1433 wfDeprecated( __METHOD__
);
1434 $title = Title
::newFromText( $title );
1435 return $this->doEditSectionLink( $title, $section );
1439 * @param $nt Title object.
1440 * @param $section Integer: section number.
1441 * @param $hint Link String: title, or default if omitted or empty
1443 public function editSectionLink( Title
$nt, $section, $hint = '' ) {
1444 wfDeprecated( __METHOD__
);
1445 if( $hint === '' ) {
1446 # No way to pass an actual empty $hint here! The new interface al-
1447 # lows this, so we have to do this for compatibility.
1450 return $this->doEditSectionLink( $nt, $section, $hint );
1454 * Create a section edit link. This supersedes editSectionLink() and
1455 * editSectionLinkForOther().
1457 * @param $nt Title The title being linked to (may not be the same as
1458 * $wgTitle, if the section is included from a template)
1459 * @param $section string The designation of the section being pointed to,
1460 * to be included in the link, like "§ion=$section"
1461 * @param $tooltip string The tooltip to use for the link: will be escaped
1462 * and wrapped in the 'editsectionhint' message
1463 * @return string HTML to use for edit link
1465 public function doEditSectionLink( Title
$nt, $section, $tooltip = null ) {
1467 if( !is_null( $tooltip ) ) {
1468 $attribs['title'] = wfMsg( 'editsectionhint', $tooltip );
1470 $link = $this->link( $nt, wfMsg('editsection'),
1472 array( 'action' => 'edit', 'section' => $section ),
1473 array( 'noclasses', 'known' )
1476 # Run the old hook. This takes up half of the function . . . hopefully
1477 # we can rid of it someday.
1480 $attribs = wfMsgHtml( 'editsectionhint', htmlspecialchars( $tooltip ) );
1481 $attribs = " title=\"$attribs\"";
1484 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result ) );
1485 if( !is_null( $result ) ) {
1486 # For reverse compatibility, add the brackets *after* the hook is
1487 # run, and even add them to hook-provided text. (This is the main
1488 # reason that the EditSectionLink hook is deprecated in favor of
1489 # DoEditSectionLink: it can't change the brackets or the span.)
1490 $result = wfMsgHtml( 'editsection-brackets', $result );
1491 return "<span class=\"editsection\">$result</span>";
1494 # Add the brackets and the span, and *then* run the nice new hook, with
1495 # clean and non-redundant arguments.
1496 $result = wfMsgHtml( 'editsection-brackets', $link );
1497 $result = "<span class=\"editsection\">$result</span>";
1499 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result ) );
1504 * Create a headline for content
1506 * @param int $level The level of the headline (1-6)
1507 * @param string $attribs Any attributes for the headline, starting with a space and ending with '>'
1508 * This *must* be at least '>' for no attribs
1509 * @param string $anchor The anchor to give the headline (the bit after the #)
1510 * @param string $text The text of the header
1511 * @param string $link HTML to add for the section edit link
1513 * @return string HTML headline
1515 public function makeHeadline( $level, $attribs, $anchor, $text, $link ) {
1516 return "<a name=\"$anchor\"></a><h$level$attribs$link <span class=\"mw-headline\">$text</span></h$level>";
1520 * Split a link trail, return the "inside" portion and the remainder of the trail
1521 * as a two-element array
1525 static function splitTrail( $trail ) {
1526 static $regex = false;
1527 if ( $regex === false ) {
1529 $regex = $wgContLang->linkTrail();
1532 if ( '' != $trail ) {
1534 if ( preg_match( $regex, $trail, $m ) ) {
1539 return array( $inside, $trail );
1543 * Generate a rollback link for a given revision. Currently it's the
1544 * caller's responsibility to ensure that the revision is the top one. If
1545 * it's not, of course, the user will get an error message.
1547 * If the calling page is called with the parameter &bot=1, all rollback
1548 * links also get that parameter. It causes the edit itself and the rollback
1549 * to be marked as "bot" edits. Bot edits are hidden by default from recent
1550 * changes, so this allows sysops to combat a busy vandal without bothering
1553 * @param Revision $rev
1555 function generateRollback( $rev ) {
1556 return '<span class="mw-rollback-link">['
1557 . $this->buildRollbackLink( $rev )
1562 * Build a raw rollback link, useful for collections of "tool" links
1564 * @param Revision $rev
1567 public function buildRollbackLink( $rev ) {
1568 global $wgRequest, $wgUser;
1569 $title = $rev->getTitle();
1571 'action' => 'rollback',
1572 'from' => $rev->getUserText()
1574 if( $wgRequest->getBool( 'bot' ) ) {
1575 $query['bot'] = '1';
1577 $query['token'] = $wgUser->editToken( array( $title->getPrefixedText(),
1578 $rev->getUserText() ) );
1579 return $this->link( $title, wfMsgHtml( 'rollbacklink' ),
1580 array( 'title' => wfMsg( 'tooltip-rollback' ) ),
1581 $query, array( 'known', 'noclasses' ) );
1585 * Returns HTML for the "templates used on this page" list.
1587 * @param array $templates Array of templates from Article::getUsedTemplate
1589 * @param bool $preview Whether this is for a preview
1590 * @param bool $section Whether this is for a section edit
1591 * @return string HTML output
1593 public function formatTemplates( $templates, $preview = false, $section = false) {
1595 wfProfileIn( __METHOD__
);
1597 $sk = $wgUser->getSkin();
1600 if ( count( $templates ) > 0 ) {
1601 # Do a batch existence check
1602 $batch = new LinkBatch
;
1603 foreach( $templates as $title ) {
1604 $batch->addObj( $title );
1608 # Construct the HTML
1609 $outText = '<div class="mw-templatesUsedExplanation">';
1611 $outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ) );
1612 } elseif ( $section ) {
1613 $outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ) );
1615 $outText .= wfMsgExt( 'templatesused', array( 'parse' ) );
1617 $outText .= '</div><ul>';
1619 usort( $templates, array( 'Title', 'compare' ) );
1620 foreach ( $templates as $titleObj ) {
1621 $r = $titleObj->getRestrictions( 'edit' );
1622 if ( in_array( 'sysop', $r ) ) {
1623 $protected = wfMsgExt( 'template-protected', array( 'parseinline' ) );
1624 } elseif ( in_array( 'autoconfirmed', $r ) ) {
1625 $protected = wfMsgExt( 'template-semiprotected', array( 'parseinline' ) );
1629 $outText .= '<li>' . $sk->link( $titleObj ) . ' ' . $protected . '</li>';
1631 $outText .= '</ul>';
1633 wfProfileOut( __METHOD__
);
1638 * Returns HTML for the "hidden categories on this page" list.
1640 * @param array $hiddencats Array of hidden categories from Article::getHiddenCategories
1642 * @return string HTML output
1644 public function formatHiddenCategories( $hiddencats) {
1645 global $wgUser, $wgLang;
1646 wfProfileIn( __METHOD__
);
1648 $sk = $wgUser->getSkin();
1651 if ( count( $hiddencats ) > 0 ) {
1652 # Construct the HTML
1653 $outText = '<div class="mw-hiddenCategoriesExplanation">';
1654 $outText .= wfMsgExt( 'hiddencategories', array( 'parse' ), $wgLang->formatnum( count( $hiddencats ) ) );
1655 $outText .= '</div><ul>';
1657 foreach ( $hiddencats as $titleObj ) {
1658 $outText .= '<li>' . $sk->link( $titleObj, null, array(), array(), 'known' ) . '</li>'; # If it's hidden, it must exist - no need to check with a LinkBatch
1660 $outText .= '</ul>';
1662 wfProfileOut( __METHOD__
);
1667 * Format a size in bytes for output, using an appropriate
1668 * unit (B, KB, MB or GB) according to the magnitude in question
1670 * @param $size Size to format
1673 public function formatSize( $size ) {
1675 return htmlspecialchars( $wgLang->formatSize( $size ) );
1679 * Given the id of an interface element, constructs the appropriate title
1680 * and accesskey attributes from the system messages. (Note, this is usu-
1681 * ally the id but isn't always, because sometimes the accesskey needs to
1682 * go on a different element than the id, for reverse-compatibility, etc.)
1684 * @param string $name Id of the element, minus prefixes.
1685 * @return string title and accesskey attributes, ready to drop in an
1686 * element (e.g., ' title="This does something [x]" accesskey="x"').
1688 public function tooltipAndAccesskey( $name ) {
1689 wfProfileIn( __METHOD__
);
1692 $tooltip = wfMsg( "tooltip-$name" );
1693 if( !wfEmptyMsg( "tooltip-$name", $tooltip ) && $tooltip != '-' ) {
1694 // Compatibility: formerly some tooltips had [alt-.] hardcoded
1695 $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
1696 $attribs['title'] = $tooltip;
1699 $accesskey = wfMsg( "accesskey-$name" );
1700 if( $accesskey && $accesskey != '-' &&
1701 !wfEmptyMsg( "accesskey-$name", $accesskey ) ) {
1702 if( isset( $attribs['title'] ) ) {
1703 $attribs['title'] .= " [$accesskey]";
1705 $attribs['accesskey'] = $accesskey;
1708 $ret = Xml
::expandAttributes( $attribs );
1709 wfProfileOut( __METHOD__
);
1714 * Given the id of an interface element, constructs the appropriate title
1715 * attribute from the system messages. (Note, this is usually the id but
1716 * isn't always, because sometimes the accesskey needs to go on a different
1717 * element than the id, for reverse-compatibility, etc.)
1719 * @param string $name Id of the element, minus prefixes.
1720 * @param mixed $options null or the string 'withaccess' to add an access-
1722 * @return string title attribute, ready to drop in an element
1723 * (e.g., ' title="This does something"').
1725 public function tooltip( $name, $options = null ) {
1726 wfProfileIn( __METHOD__
);
1730 $tooltip = wfMsg( "tooltip-$name" );
1731 if( !wfEmptyMsg( "tooltip-$name", $tooltip ) && $tooltip != '-' ) {
1732 $attribs['title'] = $tooltip;
1735 if( isset( $attribs['title'] ) && $options == 'withaccess' ) {
1736 $accesskey = wfMsg( "accesskey-$name" );
1737 if( $accesskey && $accesskey != '-' &&
1738 !wfEmptyMsg( "accesskey-$name", $accesskey ) ) {
1739 $attribs['title'] .= " [$accesskey]";
1743 $ret = Xml
::expandAttributes( $attribs );
1744 wfProfileOut( __METHOD__
);