3 * Split off some of the internal bits from Skin.php. These functions are used
4 * for primarily page content: links, embedded images, table of contents. Links
5 * are also used in the skin. For the moment, Skin is a descendent class of
6 * Linker. In the future, it should probably be further split so that every
7 * other bit of the wiki doesn't have to go loading up Skin to get at it.
14 * Flags for userToolLinks()
16 const TOOL_LINKS_NOBLOCK
= 1;
18 function __construct() {}
23 function postParseLinkColour( $s = null ) {
24 wfDeprecated( __METHOD__
);
29 * Get the appropriate HTML attributes to add to the "a" element of an ex-
30 * ternal link, as created by [wikisyntax].
32 * @param string $title The (unescaped) title text for the link
33 * @param string $unused Unused
34 * @param string $class The contents of the class attribute; if an empty
35 * string is passed, which is the default value, defaults to 'external'.
37 function getExternalLinkAttributes( $title, $unused = null, $class='' ) {
38 return $this->getLinkAttributesInternal( $title, $class, 'external' );
42 * Get the appropriate HTML attributes to add to the "a" element of an in-
45 * @param string $title The title text for the link, URL-encoded (???) but
47 * @param string $unused Unused
48 * @param string $class The contents of the class attribute; if an empty
49 * string is passed, which is the default value, defaults to 'external'.
51 function getInterwikiLinkAttributes( $title, $unused = null, $class='' ) {
54 # FIXME: We have a whole bunch of handling here that doesn't happen in
55 # getExternalLinkAttributes, why?
56 $title = urldecode( $title );
57 $title = $wgContLang->checkTitleEncoding( $title );
58 $title = preg_replace( '/[\\x00-\\x1f]/', ' ', $title );
60 return $this->getLinkAttributesInternal( $title, $class, 'external' );
64 * Get the appropriate HTML attributes to add to the "a" element of an in-
67 * @param string $title The title text for the link, URL-encoded (???) but
69 * @param string $unused Unused
70 * @param string $class The contents of the class attribute, default none
72 function getInternalLinkAttributes( $title, $unused = null, $class='' ) {
73 $title = urldecode( $title );
74 $title = str_replace( '_', ' ', $title );
75 return $this->getLinkAttributesInternal( $title, $class );
79 * Get the appropriate HTML attributes to add to the "a" element of an in-
80 * ternal link, given the Title object for the page we want to link to.
82 * @param Title $nt The Title object
83 * @param string $unused Unused
84 * @param string $class The contents of the class attribute, default none
85 * @param mixed $title Optional (unescaped) string to use in the title
86 * attribute; if false, default to the name of the page we're linking to
88 function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) {
89 if( $title === false ) {
90 $title = $nt->getPrefixedText();
92 return $this->getLinkAttributesInternal( $title, $class );
96 * Common code for getLinkAttributesX functions
98 private function getLinkAttributesInternal( $title, $class, $classDefault = false ) {
99 $title = htmlspecialchars( $title );
100 if( $class === '' and $classDefault !== false ) {
101 # FIXME: Parameter defaults the hard way! We should just have
102 # $class = 'external' or whatever as the default in the externally-
103 # exposed functions, not $class = ''.
104 $class = $classDefault;
106 $class = htmlspecialchars( $class );
108 if( $class !== '' ) {
109 $r .= " class=\"$class\"";
111 $r .= " title=\"$title\"";
116 * Return the CSS colour of a known link
119 * @param integer $threshold user defined threshold
120 * @return string CSS class
122 function getLinkColour( $t, $threshold ) {
124 if ( $t->isRedirect() ) {
126 $colour = 'mw-redirect';
127 } elseif ( $threshold > 0 && $t->getLength() < $threshold && MWNamespace
::isContent( $t->getNamespace() ) ) {
135 * This function returns an HTML link to the given target. It serves a few
137 * 1) If $target is a Title, the correct URL to link to will be figured
139 * 2) It automatically adds the usual classes for various types of link
140 * targets: "new" for red links, "stub" for short articles, etc.
141 * 3) It escapes all attribute values safely so there's no risk of XSS.
142 * 4) It provides a default tooltip if the target is a Title (the page
143 * name of the target).
144 * link() replaces the old functions in the makeLink() family.
146 * @param $target Title Can currently only be a Title, but this may
147 * change to support Images, literal URLs, etc.
148 * @param $text string The HTML contents of the <a> element, i.e.,
149 * the link text. This is raw HTML and will not be escaped. If null,
150 * defaults to the prefixed text of the Title; or if the Title is just a
151 * fragment, the contents of the fragment.
152 * @param $query array The query string to append to the URL
153 * you're linking to, in key => value array form. Query keys and values
154 * will be URL-encoded.
155 * @param $customAttribs array A key => value array of extra HTML attri-
156 * butes, such as title and class. (href is ignored.) Classes will be
157 * merged with the default classes, while other attributes will replace
158 * default attributes. All passed attribute values will be HTML-escaped.
159 * A false attribute value means to suppress that attribute.
160 * @param $options mixed String or array of strings:
161 * 'known': Page is known to exist, so don't check if it does.
162 * 'broken': Page is known not to exist, so don't check if it does.
163 * 'noclasses': Don't add any classes automatically (includes "new",
164 * "stub", "mw-redirect", "extiw"). Only use the class attribute
165 * provided, if any, so you get a simple blue link with no funny i-
167 * @return string HTML <a> attribute
169 public function link( $target, $text = null, $customAttribs = array(), $query = array(), $options = array() ) {
170 wfProfileIn( __METHOD__
);
172 if( !wfRunHooks( 'LinkBegin', array( $this, $target, &$text,
173 &$customAttribs, &$query, &$options, &$ret ) ) ) {
174 wfProfileOut( __METHOD__
);
178 if( !$target instanceof Title
) {
179 throw new MWException( 'Linker::link passed invalid target' );
181 $options = (array)$options;
183 # Normalize the Title if it's a special page
184 $target = $this->normaliseSpecialPage( $target );
186 # If we don't know whether the page exists, let's find out.
187 wfProfileIn( __METHOD__
. '-checkPageExistence' );
188 if( !in_array( 'known', $options ) and !in_array( 'broken', $options ) ) {
189 if( $target->getNamespace() == NS_SPECIAL
) {
190 if( SpecialPage
::exists( $target->getDbKey() ) ) {
191 $options []= 'known';
193 $options []= 'broken';
195 } elseif( $target->isAlwaysKnown() or
196 ($target->getPrefixedText() == '' and $target->getFragment() != '')
197 or $target->exists() ) {
198 $options []= 'known';
200 $options []= 'broken';
203 wfProfileOut( __METHOD__
. '-checkPageExistence' );
205 # Note: we want the href attribute first, for prettiness.
206 $attribs = array( 'href' => $this->linkUrl( $target, $query, $options ) );
207 $attribs = array_merge(
209 $this->linkAttribs( $target, $customAttribs, $options )
211 if( is_null( $text ) ) {
212 $text = $this->linkText( $target );
216 if( wfRunHooks( 'LinkEnd', array( $this, $target, $options, &$text,
217 &$attribs, &$ret ) ) ) {
218 $ret = Xml
::openElement( 'a', $attribs )
220 . Xml
::closeElement( 'a' );
223 wfProfileOut( __METHOD__
);
227 private function linkUrl( $target, $query, $options ) {
228 wfProfileIn( __METHOD__
);
229 # We don't want to include fragments for broken links, because they
230 # generally make no sense.
231 if( in_array( 'broken', $options ) and $target->mFragment
!== '' ) {
232 $target = clone $target;
233 $target->mFragment
= '';
236 # If it's a broken link, add the appropriate query pieces, unless
237 # there's already an action specified, or unless 'edit' makes no sense
238 # (i.e., for a nonexistent special page).
239 if( in_array( 'broken', $options ) and empty( $query['action'] )
240 and $target->getNamespace() != NS_SPECIAL
) {
241 $query['action'] = 'edit';
242 $query['redlink'] = '1';
244 $ret = $target->getLinkUrl( $query );
245 wfProfileOut( __METHOD__
);
249 private function linkAttribs( $target, $attribs, $options ) {
250 wfProfileIn( __METHOD__
);
254 if( !in_array( 'noclasses', $options ) ) {
255 wfProfileIn( __METHOD__
. '-getClasses' );
256 # Now build the classes.
259 if( in_array( 'broken', $options ) ) {
263 if( $target->isExternal() ) {
264 $classes[] = 'extiw';
267 # Note that redirects never count as stubs here.
268 if ( $target->isRedirect() ) {
269 $classes[] = 'mw-redirect';
270 } elseif( $target->isContentPage() ) {
272 $threshold = $wgUser->getOption( 'stubthreshold' );
273 if( $threshold > 0 and $target->getLength() < $threshold ) {
277 if( $classes != array() ) {
278 $defaults['class'] = implode( ' ', $classes );
280 wfProfileOut( __METHOD__
. '-getClasses' );
283 # Get a default title attribute.
284 if( in_array( 'known', $options ) ) {
285 $defaults['title'] = $target->getPrefixedText();
287 $defaults['title'] = wfMsg( 'red-link-title', $target->getPrefixedText() );
290 # Finally, merge the custom attribs with the default ones, and iterate
291 # over that, deleting all "false" attributes.
293 $merged = Sanitizer
::mergeAttributes( $defaults, $attribs );
294 foreach( $merged as $key => $val ) {
295 # A false value suppresses the attribute, and we don't want the
296 # href attribute to be overridden.
297 if( $key != 'href' and $val !== false ) {
301 wfProfileOut( __METHOD__
);
305 private function linkText( $target ) {
306 # If the target is just a fragment, with no title, we return the frag-
307 # ment text. Otherwise, we return the title text itself.
308 if( $target->getPrefixedText() === '' and $target->getFragment() !== '' ) {
309 return htmlspecialchars( $target->getFragment() );
311 return htmlspecialchars( $target->getPrefixedText() );
315 * @deprecated Use link()
317 * This function is a shortcut to makeLinkObj(Title::newFromText($title),...). Do not call
318 * it if you already have a title object handy. See makeLinkObj for further documentation.
320 * @param $title String: the text of the title
321 * @param $text String: link text
322 * @param $query String: optional query part
323 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
324 * be included in the link text. Other characters will be appended after
325 * the end of the link.
327 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
328 wfDeprecated( __METHOD__
);
329 wfProfileIn( __METHOD__
);
330 $nt = Title
::newFromText( $title );
331 if ( $nt instanceof Title
) {
332 $result = $this->makeLinkObj( $nt, $text, $query, $trail );
334 wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" );
335 $result = $text == "" ?
$title : $text;
338 wfProfileOut( __METHOD__
);
343 * @deprecated Use link()
345 * This function is a shortcut to makeKnownLinkObj(Title::newFromText($title),...). Do not call
346 * it if you already have a title object handy. See makeKnownLinkObj for further documentation.
348 * @param $title String: the text of the title
349 * @param $text String: link text
350 * @param $query String: optional query part
351 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
352 * be included in the link text. Other characters will be appended after
353 * the end of the link.
355 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
356 wfDeprecated( __METHOD__
);
357 $nt = Title
::newFromText( $title );
358 if ( $nt instanceof Title
) {
359 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix , $aprops );
361 wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" );
362 return $text == '' ?
$title : $text;
367 * @deprecated Use link()
369 * This function is a shortcut to makeBrokenLinkObj(Title::newFromText($title),...). Do not call
370 * it if you already have a title object handy. See makeBrokenLinkObj for further documentation.
372 * @param string $title The text of the title
373 * @param string $text Link text
374 * @param string $query Optional query part
375 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
376 * be included in the link text. Other characters will be appended after
377 * the end of the link.
379 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
380 wfDeprecated( __METHOD__
);
381 $nt = Title
::newFromText( $title );
382 if ( $nt instanceof Title
) {
383 return $this->makeBrokenLinkObj( $nt, $text, $query, $trail );
385 wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" );
386 return $text == '' ?
$title : $text;
391 * @deprecated Use link()
393 * This function is a shortcut to makeStubLinkObj(Title::newFromText($title),...). Do not call
394 * it if you already have a title object handy. See makeStubLinkObj for further documentation.
396 * @param $title String: the text of the title
397 * @param $text String: link text
398 * @param $query String: optional query part
399 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
400 * be included in the link text. Other characters will be appended after
401 * the end of the link.
403 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
404 wfDeprecated( __METHOD__
);
405 $nt = Title
::newFromText( $title );
406 if ( $nt instanceof Title
) {
407 return $this->makeStubLinkObj( $nt, $text, $query, $trail );
409 wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" );
410 return $text == '' ?
$title : $text;
415 * @deprecated Use link()
417 * Make a link for a title which may or may not be in the database. If you need to
418 * call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
419 * call to this will result in a DB query.
421 * @param $nt Title: the title object to make the link from, e.g. from
422 * Title::newFromText.
423 * @param $text String: link text
424 * @param $query String: optional query part
425 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
426 * be included in the link text. Other characters will be appended after
427 * the end of the link.
428 * @param $prefix String: optional prefix. As trail, only before instead of after.
430 function makeLinkObj( Title
$nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
431 wfDeprecated( __METHOD__
);
433 wfProfileIn( __METHOD__
);
435 $query = wfCgiToArray( $query );
436 list( $inside, $trail ) = Linker
::splitTrail( $trail );
438 $text = $this->linkText( $nt );
441 $ret = $this->link( $nt, "$prefix$text$inside", array(), $query,
442 'noclasses' ) . $trail;
444 wfProfileOut( __METHOD__
);
449 * @deprecated Use link()
451 * Make a link for a title which definitely exists. This is faster than makeLinkObj because
452 * it doesn't have to do a database query. It's also valid for interwiki titles and special
455 * @param $nt Title object of target page
456 * @param $text String: text to replace the title
457 * @param $query String: link target
458 * @param $trail String: text after link
459 * @param $prefix String: text before link text
460 * @param $aprops String: extra attributes to the a-element
461 * @param $style String: style to apply - if empty, use getInternalLinkAttributesObj instead
462 * @return the a-element
464 function makeKnownLinkObj( Title
$title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
465 wfDeprecated( __METHOD__
);
466 wfProfileIn( __METHOD__
);
469 $text = $this->linkText( $title );
471 $attribs = Sanitizer
::mergeAttributes(
472 Sanitizer
::decodeTagAttributes( $aprops ),
473 Sanitizer
::decodeTagAttributes( $style )
475 $query = wfCgiToArray( $query );
476 list( $inside, $trail ) = Linker
::splitTrail( $trail );
478 $ret = $this->link( $title, "$prefix$text$inside", $attribs, $query,
479 array( 'known', 'noclasses' ) ) . $trail;
481 wfProfileOut( __METHOD__
);
486 * @deprecated Use link()
488 * Make a red link to the edit page of a given title.
490 * @param $nt Title object of the target page
491 * @param $text String: Link text
492 * @param $query String: Optional query part
493 * @param $trail String: Optional trail. Alphabetic characters at the start of this string will
494 * be included in the link text. Other characters will be appended after
495 * the end of the link.
497 function makeBrokenLinkObj( Title
$title, $text = '', $query = '', $trail = '', $prefix = '' ) {
498 wfDeprecated( __METHOD__
);
499 wfProfileIn( __METHOD__
);
501 list( $inside, $trail ) = Linker
::splitTrail( $trail );
503 $text = $this->linkText( $title );
505 $nt = $this->normaliseSpecialPage( $title );
507 $ret = $this->link( $title, "$prefix$text$inside", array(),
508 wfCgiToArray( $query ), 'broken' ) . $trail;
510 wfProfileOut( __METHOD__
);
515 * @deprecated Use link()
517 * Make a brown link to a short article.
519 * @param $nt Title object of the target page
520 * @param $text String: link text
521 * @param $query String: optional query part
522 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
523 * be included in the link text. Other characters will be appended after
524 * the end of the link.
526 function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
527 wfDeprecated( __METHOD__
);
528 return $this->makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix );
532 * @deprecated Use link()
534 * Make a coloured link.
536 * @param $nt Title object of the target page
537 * @param $colour Integer: colour of the link
538 * @param $text String: link text
539 * @param $query String: optional query part
540 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
541 * be included in the link text. Other characters will be appended after
542 * the end of the link.
544 function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
545 wfDeprecated( __METHOD__
);
547 $style = $this->getInternalLinkAttributesObj( $nt, $text, $colour );
549 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style );
553 * Generate either a normal exists-style link or a stub link, depending
554 * on the given page size.
556 * @param $size Integer
557 * @param $nt Title object.
558 * @param $text String
559 * @param $query String
560 * @param $trail String
561 * @param $prefix String
562 * @return string HTML of link
564 function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
566 $threshold = intval( $wgUser->getOption( 'stubthreshold' ) );
567 $colour = ( $size < $threshold ) ?
'stub' : '';
568 return $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
572 * Make appropriate markup for a link to the current article. This is currently rendered
573 * as the bold link text. The calling sequence is the same as the other make*LinkObj functions,
574 * despite $query not being used.
576 function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
578 $text = htmlspecialchars( $nt->getPrefixedText() );
580 list( $inside, $trail ) = Linker
::splitTrail( $trail );
581 return "<strong class=\"selflink\">{$prefix}{$text}{$inside}</strong>{$trail}";
584 function normaliseSpecialPage( Title
$title ) {
585 if ( $title->getNamespace() == NS_SPECIAL
) {
586 list( $name, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $title->getDBkey() );
587 if ( !$name ) return $title;
588 $ret = SpecialPage
::getTitleFor( $name, $subpage );
589 $ret->mFragment
= $title->getFragment();
596 /** @todo document */
597 function fnamePart( $url ) {
598 $basename = strrchr( $url, '/' );
599 if ( false === $basename ) {
602 $basename = substr( $basename, 1 );
607 /** Obsolete alias */
608 function makeImage( $url, $alt = '' ) {
609 wfDeprecated( __METHOD__
);
610 return $this->makeExternalImage( $url, $alt );
613 /** @todo document */
614 function makeExternalImage( $url, $alt = '' ) {
616 $alt = $this->fnamePart( $url );
619 $success = wfRunHooks('LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
621 wfDebug("Hook LinkerMakeExternalImage changed the output of external image with url {$url} and alt text {$alt} to {$img}", true);
624 return Xml
::element( 'img',
631 * Creates the HTML source for images
632 * @deprecated use makeImageLink2
634 * @param object $title
635 * @param string $label label text
636 * @param string $alt alt text
637 * @param string $align horizontal alignment: none, left, center, right)
638 * @param array $handlerParams Parameters to be passed to the media handler
639 * @param boolean $framed shows image in original size in a frame
640 * @param boolean $thumb shows image as thumbnail in a frame
641 * @param string $manualthumb image name for the manual thumbnail
642 * @param string $valign vertical alignment: baseline, sub, super, top, text-top, middle, bottom, text-bottom
643 * @param string $time, timestamp of the file, set as false for current
646 function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(), $framed = false,
647 $thumb = false, $manualthumb = '', $valign = '', $time = false )
649 $frameParams = array( 'alt' => $alt, 'caption' => $label );
651 $frameParams['align'] = $align;
654 $frameParams['framed'] = true;
657 $frameParams['thumbnail'] = true;
659 if ( $manualthumb ) {
660 $frameParams['manualthumb'] = $manualthumb;
663 $frameParams['valign'] = $valign;
665 $file = wfFindFile( $title, $time );
666 return $this->makeImageLink2( $title, $file, $frameParams, $handlerParams, $time );
670 * Given parameters derived from [[Image:Foo|options...]], generate the
671 * HTML that that syntax inserts in the page.
673 * @param Title $title Title object
674 * @param File $file File object, or false if it doesn't exist
676 * @param array $frameParams Associative array of parameters external to the media handler.
677 * Boolean parameters are indicated by presence or absence, the value is arbitrary and
678 * will often be false.
679 * thumbnail If present, downscale and frame
680 * manualthumb Image name to use as a thumbnail, instead of automatic scaling
681 * framed Shows image in original size in a frame
682 * frameless Downscale but don't frame
683 * upright If present, tweak default sizes for portrait orientation
684 * upright_factor Fudge factor for "upright" tweak (default 0.75)
685 * border If present, show a border around the image
686 * align Horizontal alignment (left, right, center, none)
687 * valign Vertical alignment (baseline, sub, super, top, text-top, middle,
688 * bottom, text-bottom)
689 * alt Alternate text for image (i.e. alt attribute). Plain text.
690 * caption HTML for image caption.
692 * @param array $handlerParams Associative array of media handler parameters, to be passed
693 * to transform(). Typical keys are "width" and "page".
694 * @param string $time, timestamp of the file, set as false for current
695 * @param string $query, query params for desc url
696 * @return string HTML for an image, with links, wrappers, etc.
698 function makeImageLink2( Title
$title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
700 if( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$this, &$title,
701 &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
705 global $wgContLang, $wgUser, $wgThumbLimits, $wgThumbUpright;
706 if ( $file && !$file->allowInlineDisplay() ) {
707 wfDebug( __METHOD__
.': '.$title->getPrefixedDBkey()." does not allow inline display\n" );
708 return $this->link( $title );
713 $hp =& $handlerParams;
715 // Clean up parameters
716 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
717 if ( !isset( $fp['align'] ) ) $fp['align'] = '';
718 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
720 $prefix = $postfix = '';
722 if ( 'center' == $fp['align'] )
724 $prefix = '<div class="center">';
726 $fp['align'] = 'none';
728 if ( $file && !isset( $hp['width'] ) ) {
729 $hp['width'] = $file->getWidth( $page );
731 if( isset( $fp['thumbnail'] ) ||
isset( $fp['framed'] ) ||
isset( $fp['frameless'] ) ||
!$hp['width'] ) {
732 $wopt = $wgUser->getOption( 'thumbsize' );
734 if( !isset( $wgThumbLimits[$wopt] ) ) {
735 $wopt = User
::getDefaultOption( 'thumbsize' );
738 // Reduce width for upright images when parameter 'upright' is used
739 if ( isset( $fp['upright'] ) && $fp['upright'] == 0 ) {
740 $fp['upright'] = $wgThumbUpright;
742 // Use width which is smaller: real image width or user preference width
743 // 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
744 $prefWidth = isset( $fp['upright'] ) ?
745 round( $wgThumbLimits[$wopt] * $fp['upright'], -1 ) :
746 $wgThumbLimits[$wopt];
747 if ( $hp['width'] <= 0 ||
$prefWidth < $hp['width'] ) {
748 $hp['width'] = $prefWidth;
753 if ( isset( $fp['thumbnail'] ) ||
isset( $fp['manualthumb'] ) ||
isset( $fp['framed'] ) ) {
755 # Create a thumbnail. Alignment depends on language
756 # writing direction, # right aligned for left-to-right-
757 # languages ("Western languages"), left-aligned
758 # for right-to-left-languages ("Semitic languages")
760 # If thumbnail width has not been provided, it is set
761 # to the default user option as specified in Language*.php
762 if ( $fp['align'] == '' ) {
763 $fp['align'] = $wgContLang->isRTL() ?
'left' : 'right';
765 return $prefix.$this->makeThumbLink2( $title, $file, $fp, $hp, $time, $query ).$postfix;
768 if ( $file && isset( $fp['frameless'] ) ) {
769 $srcWidth = $file->getWidth( $page );
770 # For "frameless" option: do not present an image bigger than the source (for bitmap-style images)
771 # This is the same behaviour as the "thumb" option does it already.
772 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
773 $hp['width'] = $srcWidth;
777 if ( $file && $hp['width'] ) {
778 # Create a resized image, without the additional thumbnail features
779 $thumb = $file->transform( $hp );
785 $s = $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
787 $s = $thumb->toHtml( array(
789 'desc-query' => $query,
791 'valign' => isset( $fp['valign'] ) ?
$fp['valign'] : false ,
792 'img-class' => isset( $fp['border'] ) ?
'thumbborder' : false ) );
794 if ( '' != $fp['align'] ) {
795 $s = "<div class=\"float{$fp['align']}\"><span>{$s}</span></div>";
797 return str_replace("\n", ' ',$prefix.$s.$postfix);
801 * Make HTML for a thumbnail including image, border and caption
802 * @param Title $title
803 * @param File $file File object or false if it doesn't exist
805 function makeThumbLinkObj( Title
$title, $file, $label = '', $alt, $align = 'right', $params = array(), $framed=false , $manualthumb = "" ) {
806 $frameParams = array(
811 if ( $framed ) $frameParams['framed'] = true;
812 if ( $manualthumb ) $frameParams['manualthumb'] = $manualthumb;
813 return $this->makeThumbLink2( $title, $file, $frameParams, $params );
816 function makeThumbLink2( Title
$title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
817 global $wgStylePath, $wgContLang;
818 $exists = $file && $file->exists();
822 $hp =& $handlerParams;
824 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
825 if ( !isset( $fp['align'] ) ) $fp['align'] = 'right';
826 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
827 if ( !isset( $fp['caption'] ) ) $fp['caption'] = '';
829 if ( empty( $hp['width'] ) ) {
830 // Reduce width for upright images when parameter 'upright' is used
831 $hp['width'] = isset( $fp['upright'] ) ?
130 : 180;
836 $outerWidth = $hp['width'] +
2;
838 if ( isset( $fp['manualthumb'] ) ) {
839 # Use manually specified thumbnail
840 $manual_title = Title
::makeTitleSafe( NS_IMAGE
, $fp['manualthumb'] );
841 if( $manual_title ) {
842 $manual_img = wfFindFile( $manual_title );
844 $thumb = $manual_img->getUnscaledThumb();
849 } elseif ( isset( $fp['framed'] ) ) {
850 // Use image dimensions, don't scale
851 $thumb = $file->getUnscaledThumb( $page );
853 # Do not present an image bigger than the source, for bitmap-style images
854 # This is a hack to maintain compatibility with arbitrary pre-1.10 behaviour
855 $srcWidth = $file->getWidth( $page );
856 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
857 $hp['width'] = $srcWidth;
859 $thumb = $file->transform( $hp );
863 $outerWidth = $thumb->getWidth() +
2;
865 $outerWidth = $hp['width'] +
2;
870 $query = $query ?
'&page=' . urlencode( $page ) : 'page=' . urlencode( $page );
872 $url = $title->getLocalURL( $query );
874 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
876 $s = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
878 $s .= $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
880 } elseif ( !$thumb ) {
881 $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
884 $s .= $thumb->toHtml( array(
886 'img-class' => 'thumbimage',
888 'desc-query' => $query ) );
889 if ( isset( $fp['framed'] ) ) {
892 $zoomicon = '<div class="magnify">'.
893 '<a href="'.$url.'" class="internal" title="'.$more.'">'.
894 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
895 'width="15" height="11" alt="" /></a></div>';
898 $s .= ' <div class="thumbcaption">'.$zoomicon.$fp['caption']."</div></div></div>";
899 return str_replace("\n", ' ', $s);
903 * Make a "broken" link to an image
905 * @param Title $title Image title
906 * @param string $text Link label
907 * @param string $query Query string
908 * @param string $trail Link trail
909 * @param string $prefix Link prefix
910 * @param bool $time, a file of a certain timestamp was requested
913 public function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '', $time = false ) {
914 global $wgEnableUploads;
915 if( $title instanceof Title
) {
916 wfProfileIn( __METHOD__
);
917 $currentExists = $time ?
( wfFindFile( $title ) != false ) : false;
918 if( $wgEnableUploads && !$currentExists ) {
919 $upload = SpecialPage
::getTitleFor( 'Upload' );
921 $text = htmlspecialchars( $title->getPrefixedText() );
922 $redir = RepoGroup
::singleton()->getLocalRepo()->checkRedirect( $title );
924 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
926 $q = 'wpDestFile=' . $title->getPartialUrl();
929 list( $inside, $trail ) = self
::splitTrail( $trail );
930 $style = $this->getInternalLinkAttributesObj( $title, $text, 'new' );
931 wfProfileOut( __METHOD__
);
932 return '<a href="' . $upload->escapeLocalUrl( $q ) . '"'
933 . $style . '>' . $prefix . $text . $inside . '</a>' . $trail;
935 wfProfileOut( __METHOD__
);
936 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
939 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
943 /** @deprecated use Linker::makeMediaLinkObj() */
944 function makeMediaLink( $name, $unused = '', $text = '', $time = false ) {
945 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
946 return $this->makeMediaLinkObj( $nt, $text, $time );
950 * Create a direct link to a given uploaded file.
952 * @param $title Title object.
953 * @param $text String: pre-sanitized HTML
954 * @param $time string: time image was created
955 * @return string HTML
958 * @todo Handle invalid or missing images better.
960 function makeMediaLinkObj( $title, $text = '', $time = false ) {
961 if( is_null( $title ) ) {
962 ### HOTFIX. Instead of breaking, return empty string.
965 $img = wfFindFile( $title, $time );
967 $url = $img->getURL();
970 $upload = SpecialPage
::getTitleFor( 'Upload' );
971 $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $title->getDBkey() ) );
974 $alt = htmlspecialchars( $title->getText() );
978 $u = htmlspecialchars( $url );
979 return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\">{$text}</a>";
983 /** @todo document */
984 function specialLink( $name, $key = '' ) {
987 if ( '' == $key ) { $key = strtolower( $name ); }
988 $pn = $wgContLang->ucfirst( $name );
989 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
993 /** @todo document */
994 function makeExternalLink( $url, $text, $escape = true, $linktype = '', $ns = null ) {
995 $style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
996 global $wgNoFollowLinks, $wgNoFollowNsExceptions;
997 if( $wgNoFollowLinks && !(isset($ns) && in_array($ns, $wgNoFollowNsExceptions)) ) {
998 $style .= ' rel="nofollow"';
1000 $url = htmlspecialchars( $url );
1002 $text = htmlspecialchars( $text );
1005 $success = wfRunHooks('LinkerMakeExternalLink', array( &$url, &$text, &$link ) );
1007 wfDebug("Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}", true);
1010 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
1014 * Make user link (or user contributions for unregistered users)
1015 * @param $userId Integer: user id in database.
1016 * @param $userText String: user name in database
1017 * @return string HTML fragment
1020 function userLink( $userId, $userText ) {
1021 if( $userId == 0 ) {
1022 $page = SpecialPage
::getTitleFor( 'Contributions', $userText );
1024 $page = Title
::makeTitle( NS_USER
, $userText );
1026 return $this->link( $page, htmlspecialchars( $userText ) );
1030 * Generate standard user tool links (talk, contributions, block link, etc.)
1032 * @param int $userId User identifier
1033 * @param string $userText User name or IP address
1034 * @param bool $redContribsWhenNoEdits Should the contributions link be red if the user has no edits?
1035 * @param int $flags Customisation flags (e.g. self::TOOL_LINKS_NOBLOCK)
1036 * @param int $edits, user edit count (optional, for performance)
1039 public function userToolLinks( $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits=null ) {
1040 global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans;
1041 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
1042 $blockable = ( $wgSysopUserBans ||
0 == $userId ) && !$flags & self
::TOOL_LINKS_NOBLOCK
;
1046 $items[] = $this->userTalkLink( $userId, $userText );
1049 // check if the user has an edit
1051 if( $redContribsWhenNoEdits ) {
1052 $count = !is_null($edits) ?
$edits : User
::edits( $userId );
1054 $attribs['class'] = 'new';
1057 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $userText );
1059 $items[] = $this->link( $contribsPage, wfMsgHtml( 'contribslink' ), $attribs );
1061 if( $blockable && $wgUser->isAllowed( 'block' ) ) {
1062 $items[] = $this->blockLink( $userId, $userText );
1066 return ' (' . implode( ' | ', $items ) . ')';
1073 * Alias for userToolLinks( $userId, $userText, true );
1074 * @param int $userId User identifier
1075 * @param string $userText User name or IP address
1076 * @param int $edits, user edit count (optional, for performance)
1078 public function userToolLinksRedContribs( $userId, $userText, $edits=null ) {
1079 return $this->userToolLinks( $userId, $userText, true, 0, $edits );
1084 * @param $userId Integer: user id in database.
1085 * @param $userText String: user name in database.
1086 * @return string HTML fragment with user talk link
1089 function userTalkLink( $userId, $userText ) {
1090 $userTalkPage = Title
::makeTitle( NS_USER_TALK
, $userText );
1091 $userTalkLink = $this->link( $userTalkPage, wfMsgHtml( 'talkpagelinktext' ) );
1092 return $userTalkLink;
1096 * @param $userId Integer: userid
1097 * @param $userText String: user name in database.
1098 * @return string HTML fragment with block link
1101 function blockLink( $userId, $userText ) {
1102 $blockPage = SpecialPage
::getTitleFor( 'Blockip', $userText );
1103 $blockLink = $this->link( $blockPage, wfMsgHtml( 'blocklink' ) );
1108 * Generate a user link if the current user is allowed to view it
1109 * @param $rev Revision object.
1110 * @param $isPublic, bool, show only if all users can see it
1111 * @return string HTML
1113 function revUserLink( $rev, $isPublic = false ) {
1114 if( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1115 $link = wfMsgHtml( 'rev-deleted-user' );
1116 } else if( $rev->userCan( Revision
::DELETED_USER
) ) {
1117 $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() );
1119 $link = wfMsgHtml( 'rev-deleted-user' );
1121 if( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1122 return '<span class="history-deleted">' . $link . '</span>';
1128 * Generate a user tool link cluster if the current user is allowed to view it
1129 * @param $rev Revision object.
1130 * @param $isPublic, bool, show only if all users can see it
1131 * @return string HTML
1133 function revUserTools( $rev, $isPublic = false ) {
1134 if( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1135 $link = wfMsgHtml( 'rev-deleted-user' );
1136 } else if( $rev->userCan( Revision
::DELETED_USER
) ) {
1137 $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() ) .
1138 ' ' . $this->userToolLinks( $rev->getRawUser(), $rev->getRawUserText() );
1140 $link = wfMsgHtml( 'rev-deleted-user' );
1142 if( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1143 return ' <span class="history-deleted">' . $link . '</span>';
1149 * This function is called by all recent changes variants, by the page history,
1150 * and by the user contributions list. It is responsible for formatting edit
1151 * comments. It escapes any HTML in the comment, but adds some CSS to format
1152 * auto-generated comments (from section editing) and formats [[wikilinks]].
1154 * @author Erik Moeller <moeller@scireview.de>
1156 * Note: there's not always a title to pass to this function.
1157 * Since you can't set a default parameter for a reference, I've turned it
1158 * temporarily to a value pass. Should be adjusted further. --brion
1160 * @param string $comment
1161 * @param mixed $title Title object (to generate link to the section in autocomment) or null
1162 * @param bool $local Whether section links should refer to local page
1164 function formatComment($comment, $title = NULL, $local = false) {
1165 wfProfileIn( __METHOD__
);
1167 # Sanitize text a bit:
1168 $comment = str_replace( "\n", " ", $comment );
1169 $comment = htmlspecialchars( $comment );
1171 # Render autocomments and make links:
1172 $comment = $this->formatAutoComments( $comment, $title, $local );
1173 $comment = $this->formatLinksInComment( $comment );
1175 wfProfileOut( __METHOD__
);
1180 * The pattern for autogen comments is / * foo * /, which makes for
1182 * We look for all comments, match any text before and after the comment,
1183 * add a separator where needed and format the comment itself with CSS
1184 * Called by Linker::formatComment.
1186 * @param string $comment Comment text
1187 * @param object $title An optional title object used to links to sections
1188 * @return string $comment formatted comment
1190 * @todo Document the $local parameter.
1192 private function formatAutocomments( $comment, $title = null, $local = false ) {
1194 while (preg_match('!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment,$match)) {
1202 # Generate a valid anchor name from the section title.
1203 # Hackish, but should generally work - we strip wiki
1204 # syntax, including the magic [[: that is used to
1205 # "link rather than show" in case of images and
1206 # interlanguage links.
1207 $section = str_replace( '[[:', '', $section );
1208 $section = str_replace( '[[', '', $section );
1209 $section = str_replace( ']]', '', $section );
1211 $sectionTitle = Title
::newFromText( '#' . $section );
1213 $sectionTitle = clone( $title );
1214 $sectionTitle->mFragment
= $section;
1216 $link = $this->link( $sectionTitle,
1217 wfMsgForContent( 'sectionlink' ), array(), array(),
1220 $auto = $link . $auto;
1222 # written summary $presep autocomment (summary /* section */)
1223 $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
1226 # autocomment $postsep written summary (/* section */ summary)
1227 $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
1229 $auto = '<span class="autocomment">' . $auto . '</span>';
1230 $comment = $pre . $auto . $post;
1237 * Formats wiki links and media links in text; all other wiki formatting
1240 * @fixme doesn't handle sub-links as in image thumb texts like the main parser
1241 * @param string $comment Text to format links in
1244 public function formatLinksInComment( $comment ) {
1245 return preg_replace_callback(
1246 '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
1247 array( $this, 'formatLinksInCommentCallback' ),
1251 protected function formatLinksInCommentCallback( $match ) {
1254 $medians = '(?:' . preg_quote( MWNamespace
::getCanonicalName( NS_MEDIA
), '/' ) . '|';
1255 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA
), '/' ) . '):';
1257 $comment = $match[0];
1259 # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
1260 if( strpos( $match[1], '%' ) !== false ) {
1261 $match[1] = str_replace( array('<', '>'), array('<', '>'), urldecode($match[1]) );
1264 # Handle link renaming [[foo|text]] will show link as "text"
1265 if( "" != $match[3] ) {
1270 $submatch = array();
1271 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1272 # Media link; trail not supported.
1273 $linkRegexp = '/\[\[(.*?)\]\]/';
1274 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
1276 # Other kind of link
1277 if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
1278 $trail = $submatch[1];
1282 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1283 if (isset($match[1][0]) && $match[1][0] == ':')
1284 $match[1] = substr($match[1], 1);
1285 $thelink = $this->makeLink( $match[1], $text, "", $trail );
1287 $comment = preg_replace( $linkRegexp, StringUtils
::escapeRegexReplacement( $thelink ), $comment, 1 );
1293 * Wrap a comment in standard punctuation and formatting if
1294 * it's non-empty, otherwise return empty string.
1296 * @param string $comment
1297 * @param mixed $title Title object (to generate link to section in autocomment) or null
1298 * @param bool $local Whether section links should refer to local page
1302 function commentBlock( $comment, $title = NULL, $local = false ) {
1303 // '*' used to be the comment inserted by the software way back
1304 // in antiquity in case none was provided, here for backwards
1305 // compatability, acc. to brion -ævar
1306 if( $comment == '' ||
$comment == '*' ) {
1309 $formatted = $this->formatComment( $comment, $title, $local );
1310 return " <span class=\"comment\">($formatted)</span>";
1315 * Wrap and format the given revision's comment block, if the current
1316 * user is allowed to view it.
1318 * @param Revision $rev
1319 * @param bool $local Whether section links should refer to local page
1320 * @param $isPublic, show only if all users can see it
1321 * @return string HTML
1323 function revComment( Revision
$rev, $local = false, $isPublic = false ) {
1324 if( $rev->isDeleted( Revision
::DELETED_COMMENT
) && $isPublic ) {
1325 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1326 } else if( $rev->userCan( Revision
::DELETED_COMMENT
) ) {
1327 $block = $this->commentBlock( $rev->getRawComment(), $rev->getTitle(), $local );
1329 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1331 if( $rev->isDeleted( Revision
::DELETED_COMMENT
) ) {
1332 return " <span class=\"history-deleted\">$block</span>";
1337 public function formatRevisionSize( $size ) {
1339 $stxt = wfMsgExt( 'historyempty', 'parsemag' );
1342 $stxt = wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $size ) );
1345 $stxt = htmlspecialchars( $stxt );
1346 return "<span class=\"history-size\">$stxt</span>";
1349 /** @todo document */
1350 function tocIndent() {
1354 /** @todo document */
1355 function tocUnindent($level) {
1356 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ?
$level : 0 );
1360 * parameter level defines if we are on an indentation level
1362 function tocLine( $anchor, $tocline, $tocnumber, $level ) {
1363 return "\n<li class=\"toclevel-$level\"><a href=\"#" .
1364 $anchor . '"><span class="tocnumber">' .
1365 $tocnumber . '</span> <span class="toctext">' .
1366 $tocline . '</span></a>';
1369 /** @todo document */
1370 function tocLineEnd() {
1374 /** @todo document */
1375 function tocList($toc) {
1376 global $wgJsMimeType;
1377 $title = wfMsgHtml('toc') ;
1379 '<table id="toc" class="toc" summary="' . $title .'"><tr><td>'
1380 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
1382 # no trailing newline, script should not be wrapped in a
1384 . "</ul>\n</td></tr></table>"
1385 . '<script type="' . $wgJsMimeType . '">'
1386 . ' if (window.showTocToggle) {'
1387 . ' var tocShowText = "' . wfEscapeJsString( wfMsg('showtoc') ) . '";'
1388 . ' var tocHideText = "' . wfEscapeJsString( wfMsg('hidetoc') ) . '";'
1389 . ' showTocToggle();'
1395 * Used to generate section edit links that point to "other" pages
1396 * (sections that are really part of included pages).
1398 * @param $title Title string.
1399 * @param $section Integer: section number.
1401 public function editSectionLinkForOther( $title, $section ) {
1402 wfDeprecated( __METHOD__
);
1403 $title = Title
::newFromText( $title );
1404 return $this->doEditSectionLink( $title, $section );
1408 * @param $nt Title object.
1409 * @param $section Integer: section number.
1410 * @param $hint Link String: title, or default if omitted or empty
1412 public function editSectionLink( Title
$nt, $section, $hint = '' ) {
1413 wfDeprecated( __METHOD__
);
1414 if( $hint === '' ) {
1415 # No way to pass an actual empty $hint here! The new interface al-
1416 # lows this, so we have to do this for compatibility.
1419 return $this->doEditSectionLink( $nt, $section, $hint );
1423 * Create a section edit link. This supersedes editSectionLink() and
1424 * editSectionLinkForOther().
1426 * @param $nt Title The title being linked to (may not be the same as
1427 * $wgTitle, if the section is included from a template)
1428 * @param $section string The designation of the section being pointed to,
1429 * to be included in the link, like "§ion=$section"
1430 * @param $tooltip string The tooltip to use for the link: will be escaped
1431 * and wrapped in the 'editsectionhint' message
1432 * @return string HTML to use for edit link
1434 public function doEditSectionLink( Title
$nt, $section, $tooltip = null ) {
1436 if( !is_null( $tooltip ) ) {
1437 $attribs['title'] = wfMsg( 'editsectionhint', $tooltip );
1439 $url = $this->link( $nt, wfMsg('editsection'),
1441 array( 'action' => 'edit', 'section' => $section ),
1442 array( 'noclasses', 'known' )
1445 # Run the old hook. This takes up half of the function . . . hopefully
1446 # we can rid of it someday.
1449 $attribs = wfMsgHtml( 'editsectionhint', htmlspecialchars( $tooltip ) );
1450 $attribs = " title=\"$attribs\"";
1453 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $url, &$result ) );
1454 if( !is_null( $result ) ) {
1455 # For reverse compatibility, add the brackets *after* the hook is
1456 # run, and even add them to hook-provided text. (This is the main
1457 # reason that the EditSectionLink hook is deprecated in favor of
1458 # DoEditSectionLink: it can't change the brackets or the span.)
1459 $result = wfMsgHtml( 'editsection-brackets', $url );
1460 return "<span class=\"editsection\">$result</span>";
1463 # Add the brackets and the span, and *then* run the nice new hook, with
1464 # clean and non-redundant arguments.
1465 $result = wfMsgHtml( 'editsection-brackets', $url );
1466 $result = "<span class=\"editsection\">$result</span>";
1468 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result ) );
1473 * Create a headline for content
1475 * @param int $level The level of the headline (1-6)
1476 * @param string $attribs Any attributes for the headline, starting with a space and ending with '>'
1477 * This *must* be at least '>' for no attribs
1478 * @param string $anchor The anchor to give the headline (the bit after the #)
1479 * @param string $text The text of the header
1480 * @param string $link HTML to add for the section edit link
1482 * @return string HTML headline
1484 public function makeHeadline( $level, $attribs, $anchor, $text, $link ) {
1485 return "<a name=\"$anchor\"></a><h$level$attribs$link <span class=\"mw-headline\">$text</span></h$level>";
1489 * Split a link trail, return the "inside" portion and the remainder of the trail
1490 * as a two-element array
1494 static function splitTrail( $trail ) {
1495 static $regex = false;
1496 if ( $regex === false ) {
1498 $regex = $wgContLang->linkTrail();
1501 if ( '' != $trail ) {
1503 if ( preg_match( $regex, $trail, $m ) ) {
1508 return array( $inside, $trail );
1512 * Generate a rollback link for a given revision. Currently it's the
1513 * caller's responsibility to ensure that the revision is the top one. If
1514 * it's not, of course, the user will get an error message.
1516 * If the calling page is called with the parameter &bot=1, all rollback
1517 * links also get that parameter. It causes the edit itself and the rollback
1518 * to be marked as "bot" edits. Bot edits are hidden by default from recent
1519 * changes, so this allows sysops to combat a busy vandal without bothering
1522 * @param Revision $rev
1524 function generateRollback( $rev ) {
1525 return '<span class="mw-rollback-link">['
1526 . $this->buildRollbackLink( $rev )
1531 * Build a raw rollback link, useful for collections of "tool" links
1533 * @param Revision $rev
1536 public function buildRollbackLink( $rev ) {
1537 global $wgRequest, $wgUser;
1538 $title = $rev->getTitle();
1540 'action' => 'rollback',
1541 'from' => $rev->getUserText()
1543 if( $wgRequest->getBool( 'bot' ) ) {
1544 $query['bot'] = '1';
1546 $query['token'] = $wgUser->editToken( array( $title->getPrefixedText(),
1547 $rev->getUserText() ) );
1548 return $this->link( $title, wfMsgHtml( 'rollbacklink' ), array(),
1549 $query, array( 'known', 'noclasses' ) );
1553 * Returns HTML for the "templates used on this page" list.
1555 * @param array $templates Array of templates from Article::getUsedTemplate
1557 * @param bool $preview Whether this is for a preview
1558 * @param bool $section Whether this is for a section edit
1559 * @return string HTML output
1561 public function formatTemplates( $templates, $preview = false, $section = false) {
1563 wfProfileIn( __METHOD__
);
1565 $sk = $wgUser->getSkin();
1568 if ( count( $templates ) > 0 ) {
1569 # Do a batch existence check
1570 $batch = new LinkBatch
;
1571 foreach( $templates as $title ) {
1572 $batch->addObj( $title );
1576 # Construct the HTML
1577 $outText = '<div class="mw-templatesUsedExplanation">';
1579 $outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ) );
1580 } elseif ( $section ) {
1581 $outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ) );
1583 $outText .= wfMsgExt( 'templatesused', array( 'parse' ) );
1585 $outText .= '</div><ul>';
1587 usort( $templates, array( 'Title', 'compare' ) );
1588 foreach ( $templates as $titleObj ) {
1589 $r = $titleObj->getRestrictions( 'edit' );
1590 if ( in_array( 'sysop', $r ) ) {
1591 $protected = wfMsgExt( 'template-protected', array( 'parseinline' ) );
1592 } elseif ( in_array( 'autoconfirmed', $r ) ) {
1593 $protected = wfMsgExt( 'template-semiprotected', array( 'parseinline' ) );
1597 $outText .= '<li>' . $sk->link( $titleObj ) . ' ' . $protected . '</li>';
1599 $outText .= '</ul>';
1601 wfProfileOut( __METHOD__
);
1606 * Returns HTML for the "hidden categories on this page" list.
1608 * @param array $hiddencats Array of hidden categories from Article::getHiddenCategories
1610 * @return string HTML output
1612 public function formatHiddenCategories( $hiddencats) {
1613 global $wgUser, $wgLang;
1614 wfProfileIn( __METHOD__
);
1616 $sk = $wgUser->getSkin();
1619 if ( count( $hiddencats ) > 0 ) {
1620 # Construct the HTML
1621 $outText = '<div class="mw-hiddenCategoriesExplanation">';
1622 $outText .= wfMsgExt( 'hiddencategories', array( 'parse' ), $wgLang->formatnum( count( $hiddencats ) ) );
1623 $outText .= '</div><ul>';
1625 foreach ( $hiddencats as $titleObj ) {
1626 $outText .= '<li>' . $sk->link( $titleObj, null, array(), array(), 'known' ) . '</li>'; # If it's hidden, it must exist - no need to check with a LinkBatch
1628 $outText .= '</ul>';
1630 wfProfileOut( __METHOD__
);
1635 * Format a size in bytes for output, using an appropriate
1636 * unit (B, KB, MB or GB) according to the magnitude in question
1638 * @param $size Size to format
1641 public function formatSize( $size ) {
1643 return htmlspecialchars( $wgLang->formatSize( $size ) );
1647 * Given the id of an interface element, constructs the appropriate title
1648 * and accesskey attributes from the system messages. (Note, this is usu-
1649 * ally the id but isn't always, because sometimes the accesskey needs to
1650 * go on a different element than the id, for reverse-compatibility, etc.)
1652 * @param string $name Id of the element, minus prefixes.
1653 * @return string title and accesskey attributes, ready to drop in an
1654 * element (e.g., ' title="This does something [x]" accesskey="x"').
1656 public function tooltipAndAccesskey($name) {
1657 $fname="Linker::tooltipAndAccesskey";
1658 wfProfileIn($fname);
1661 $tooltip = wfMsg('tooltip-'.$name);
1662 if (!wfEmptyMsg('tooltip-'.$name, $tooltip) && $tooltip != '-') {
1663 // Compatibility: formerly some tooltips had [alt-.] hardcoded
1664 $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
1665 $out .= ' title="'.htmlspecialchars($tooltip);
1667 $accesskey = wfMsg('accesskey-'.$name);
1668 if ($accesskey && $accesskey != '-' && !wfEmptyMsg('accesskey-'.$name, $accesskey)) {
1669 if ($out) $out .= " [$accesskey]\" accesskey=\"$accesskey\"";
1670 else $out .= " title=\"[$accesskey]\" accesskey=\"$accesskey\"";
1674 wfProfileOut($fname);
1679 * Given the id of an interface element, constructs the appropriate title
1680 * attribute from the system messages. (Note, this is usually the id but
1681 * isn't always, because sometimes the accesskey needs to go on a different
1682 * element than the id, for reverse-compatibility, etc.)
1684 * @param string $name Id of the element, minus prefixes.
1685 * @return string title attribute, ready to drop in an element
1686 * (e.g., ' title="This does something"').
1688 public function tooltip($name) {
1691 $tooltip = wfMsg('tooltip-'.$name);
1692 if (!wfEmptyMsg('tooltip-'.$name, $tooltip) && $tooltip != '-') {
1693 $out = ' title="'.htmlspecialchars($tooltip).'"';