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 ) {
28 * Get the appropriate HTML attributes to add to the "a" element of an ex-
29 * ternal link, as created by [wikisyntax].
31 * @param string $title The (unescaped) title text for the link
32 * @param string $unused Unused
33 * @param string $class The contents of the class attribute; if an empty
34 * string is passed, which is the default value, defaults to 'external'.
36 function getExternalLinkAttributes( $title, $unused = null, $class='' ) {
37 return $this->getLinkAttributesInternal( $title, $class, 'external' );
41 * Get the appropriate HTML attributes to add to the "a" element of an in-
44 * @param string $title The title text for the link, URL-encoded (???) but
46 * @param string $unused Unused
47 * @param string $class The contents of the class attribute; if an empty
48 * string is passed, which is the default value, defaults to 'external'.
50 function getInterwikiLinkAttributes( $title, $unused = null, $class='' ) {
53 # FIXME: We have a whole bunch of handling here that doesn't happen in
54 # getExternalLinkAttributes, why?
55 $title = urldecode( $title );
56 $title = $wgContLang->checkTitleEncoding( $title );
57 $title = preg_replace( '/[\\x00-\\x1f]/', ' ', $title );
59 return $this->getLinkAttributesInternal( $title, $class, 'external' );
63 * Get the appropriate HTML attributes to add to the "a" element of an in-
66 * @param string $title The title text for the link, URL-encoded (???) but
68 * @param string $unused Unused
69 * @param string $class The contents of the class attribute, default none
71 function getInternalLinkAttributes( $title, $unused = null, $class='' ) {
72 $title = urldecode( $title );
73 $title = str_replace( '_', ' ', $title );
74 return $this->getLinkAttributesInternal( $title, $class );
78 * Get the appropriate HTML attributes to add to the "a" element of an in-
79 * ternal link, given the Title object for the page we want to link to.
81 * @param Title $nt The Title object
82 * @param string $unused Unused
83 * @param string $class The contents of the class attribute, default none
84 * @param mixed $title Optional (unescaped) string to use in the title
85 * attribute; if false, default to the name of the page we're linking to
87 function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) {
88 if( $title === false ) {
89 $title = $nt->getPrefixedText();
91 return $this->getLinkAttributesInternal( $title, $class );
95 * Common code for getLinkAttributesX functions
97 private function getLinkAttributesInternal( $title, $class, $classDefault = false ) {
98 $title = htmlspecialchars( $title );
99 if( $class === '' and $classDefault !== false ) {
100 # FIXME: Parameter defaults the hard way! We should just have
101 # $class = 'external' or whatever as the default in the externally-
102 # exposed functions, not $class = ''.
103 $class = $classDefault;
105 $class = htmlspecialchars( $class );
107 if( $class !== '' ) {
108 $r .= " class=\"$class\"";
110 $r .= " title=\"$title\"";
115 * Return the CSS colour of a known link
118 * @param integer $threshold user defined threshold
119 * @return string CSS class
121 function getLinkColour( $t, $threshold ) {
123 if ( $t->isRedirect() ) {
125 $colour = 'mw-redirect';
126 } elseif ( $threshold > 0 && $t->getLength() < $threshold && MWNamespace
::isContent( $t->getNamespace() ) ) {
134 * This function is a shortcut to makeLinkObj(Title::newFromText($title),...). Do not call
135 * it if you already have a title object handy. See makeLinkObj for further documentation.
137 * @param $title String: the text of the title
138 * @param $text String: link text
139 * @param $query String: optional query part
140 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
141 * be included in the link text. Other characters will be appended after
142 * the end of the link.
144 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
145 wfProfileIn( __METHOD__
);
146 $nt = Title
::newFromText( $title );
147 if ( $nt instanceof Title
) {
148 $result = $this->makeLinkObj( $nt, $text, $query, $trail );
150 wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" );
151 $result = $text == "" ?
$title : $text;
154 wfProfileOut( __METHOD__
);
159 * This function is a shortcut to makeKnownLinkObj(Title::newFromText($title),...). Do not call
160 * it if you already have a title object handy. See makeKnownLinkObj for further documentation.
162 * @param $title String: the text of the title
163 * @param $text String: link text
164 * @param $query String: optional query part
165 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
166 * be included in the link text. Other characters will be appended after
167 * the end of the link.
169 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
170 $nt = Title
::newFromText( $title );
171 if ( $nt instanceof Title
) {
172 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix , $aprops );
174 wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" );
175 return $text == '' ?
$title : $text;
180 * This function is a shortcut to makeBrokenLinkObj(Title::newFromText($title),...). Do not call
181 * it if you already have a title object handy. See makeBrokenLinkObj for further documentation.
183 * @param string $title The text of the title
184 * @param string $text Link text
185 * @param string $query Optional query part
186 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
187 * be included in the link text. Other characters will be appended after
188 * the end of the link.
190 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
191 $nt = Title
::newFromText( $title );
192 if ( $nt instanceof Title
) {
193 return $this->makeBrokenLinkObj( $nt, $text, $query, $trail );
195 wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" );
196 return $text == '' ?
$title : $text;
201 * @deprecated use makeColouredLinkObj
203 * This function is a shortcut to makeStubLinkObj(Title::newFromText($title),...). Do not call
204 * it if you already have a title object handy. See makeStubLinkObj for further documentation.
206 * @param $title String: the text of the title
207 * @param $text String: link text
208 * @param $query String: optional query part
209 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
210 * be included in the link text. Other characters will be appended after
211 * the end of the link.
213 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
214 $nt = Title
::newFromText( $title );
215 if ( $nt instanceof Title
) {
216 return $this->makeStubLinkObj( $nt, $text, $query, $trail );
218 wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" );
219 return $text == '' ?
$title : $text;
224 * Make a link for a title which may or may not be in the database. If you need to
225 * call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
226 * call to this will result in a DB query.
228 * @param $nt Title: the title object to make the link from, e.g. from
229 * Title::newFromText.
230 * @param $text String: link text
231 * @param $query String: optional query part
232 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
233 * be included in the link text. Other characters will be appended after
234 * the end of the link.
235 * @param $prefix String: optional prefix. As trail, only before instead of after.
237 function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
239 wfProfileIn( __METHOD__
);
241 if ( !$nt instanceof Title
) {
243 wfProfileOut( __METHOD__
);
244 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
247 if ( $nt->isExternal() ) {
248 $u = $nt->getFullURL();
249 $link = $nt->getPrefixedURL();
250 if ( '' == $text ) { $text = $nt->getPrefixedText(); }
251 $style = $this->getInterwikiLinkAttributes( $link, $text, 'extiw' );
254 if ( '' != $trail ) {
256 if ( preg_match( '/^([a-z]+)(.*)$$/sD', $trail, $m ) ) {
261 $t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
263 wfProfileOut( __METHOD__
);
265 } elseif ( $nt->isAlwaysKnown() ) {
266 # Image links, special page links and self-links with fragments are always known.
267 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
269 wfProfileIn( __METHOD__
.'-immediate' );
271 # Handles links to special pages which do not exist in the database:
272 if( $nt->getNamespace() == NS_SPECIAL
) {
273 if( SpecialPage
::exists( $nt->getDBkey() ) ) {
274 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
276 $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
278 wfProfileOut( __METHOD__
.'-immediate' );
279 wfProfileOut( __METHOD__
);
283 # Work out link colour immediately
284 $aid = $nt->getArticleID() ;
286 $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
289 if ( $nt->isContentPage() ) {
290 $threshold = $wgUser->getOption('stubthreshold');
291 $colour = $this->getLinkColour( $nt, $threshold );
293 $retVal = $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
295 wfProfileOut( __METHOD__
.'-immediate' );
297 wfProfileOut( __METHOD__
);
302 * Make a link for a title which definitely exists. This is faster than makeLinkObj because
303 * it doesn't have to do a database query. It's also valid for interwiki titles and special
306 * @param $nt Title object of target page
307 * @param $text String: text to replace the title
308 * @param $query String: link target
309 * @param $trail String: text after link
310 * @param $prefix String: text before link text
311 * @param $aprops String: extra attributes to the a-element
312 * @param $style String: style to apply - if empty, use getInternalLinkAttributesObj instead
313 * @return the a-element
315 function makeKnownLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
316 wfProfileIn( __METHOD__
);
318 if ( !$title instanceof Title
) {
320 wfProfileOut( __METHOD__
);
321 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
324 $nt = $this->normaliseSpecialPage( $title );
326 $u = $nt->escapeLocalURL( $query );
327 if ( $nt->getFragment() != '' ) {
328 if( $nt->getPrefixedDbkey() == '' ) {
331 $text = htmlspecialchars( $nt->getFragment() );
334 $u .= $nt->getFragmentForURL();
337 $text = htmlspecialchars( $nt->getPrefixedText() );
339 if ( $style == '' ) {
340 $style = $this->getInternalLinkAttributesObj( $nt, $text );
343 if ( $aprops !== '' ) $aprops = ' ' . $aprops;
345 list( $inside, $trail ) = Linker
::splitTrail( $trail );
346 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
347 wfProfileOut( __METHOD__
);
352 * Make a red link to the edit page of a given title.
354 * @param $nt Title object of the target page
355 * @param $text String: Link text
356 * @param $query String: Optional query part
357 * @param $trail String: Optional trail. Alphabetic characters at the start of this string will
358 * be included in the link text. Other characters will be appended after
359 * the end of the link.
361 function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
362 wfProfileIn( __METHOD__
);
364 if ( !$title instanceof Title
) {
366 wfProfileOut( __METHOD__
);
367 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
370 $nt = $this->normaliseSpecialPage( $title );
372 if( $nt->getNamespace() == NS_SPECIAL
) {
374 } else if ( '' == $query ) {
375 $q = 'action=edit&redlink=1';
377 $q = 'action=edit&redlink=1&'.$query;
379 $u = $nt->escapeLocalURL( $q );
381 $titleText = $nt->getPrefixedText();
383 $text = htmlspecialchars( $titleText );
385 $titleAttr = wfMsg( 'red-link-title', $titleText );
386 $style = $this->getInternalLinkAttributesObj( $nt, $text, 'new', $titleAttr );
387 list( $inside, $trail ) = Linker
::splitTrail( $trail );
389 wfRunHooks( 'BrokenLink', array( &$this, $nt, $query, &$u, &$style, &$prefix, &$text, &$inside, &$trail ) );
390 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
392 wfProfileOut( __METHOD__
);
397 * @deprecated use makeColouredLinkObj
399 * Make a brown link to a short article.
401 * @param $nt Title object of the target page
402 * @param $text String: link text
403 * @param $query String: optional query part
404 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
405 * be included in the link text. Other characters will be appended after
406 * the end of the link.
408 function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
409 return $this->makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix );
413 * Make a coloured link.
415 * @param $nt Title object of the target page
416 * @param $colour Integer: colour of the link
417 * @param $text String: link text
418 * @param $query String: optional query part
419 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
420 * be included in the link text. Other characters will be appended after
421 * the end of the link.
423 function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
426 $style = $this->getInternalLinkAttributesObj( $nt, $text, $colour );
428 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style );
432 * Generate either a normal exists-style link or a stub link, depending
433 * on the given page size.
435 * @param $size Integer
436 * @param $nt Title object.
437 * @param $text String
438 * @param $query String
439 * @param $trail String
440 * @param $prefix String
441 * @return string HTML of link
443 function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
445 $threshold = intval( $wgUser->getOption( 'stubthreshold' ) );
446 $colour = ( $size < $threshold ) ?
'stub' : '';
447 return $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
451 * Make appropriate markup for a link to the current article. This is currently rendered
452 * as the bold link text. The calling sequence is the same as the other make*LinkObj functions,
453 * despite $query not being used.
455 function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
457 $text = htmlspecialchars( $nt->getPrefixedText() );
459 list( $inside, $trail ) = Linker
::splitTrail( $trail );
460 return "<strong class=\"selflink\">{$prefix}{$text}{$inside}</strong>{$trail}";
463 function normaliseSpecialPage( Title
$title ) {
464 if ( $title->getNamespace() == NS_SPECIAL
) {
465 list( $name, $subpage ) = SpecialPage
::resolveAliasWithSubpage( $title->getDBkey() );
466 if ( !$name ) return $title;
467 return SpecialPage
::getTitleFor( $name, $subpage );
473 /** @todo document */
474 function fnamePart( $url ) {
475 $basename = strrchr( $url, '/' );
476 if ( false === $basename ) {
479 $basename = substr( $basename, 1 );
484 /** Obsolete alias */
485 function makeImage( $url, $alt = '' ) {
486 return $this->makeExternalImage( $url, $alt );
489 /** @todo document */
490 function makeExternalImage( $url, $alt = '' ) {
492 $alt = $this->fnamePart( $url );
495 $success = wfRunHooks('LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
497 wfDebug("Hook LinkerMakeExternalImage changed the output of external image with url {$url} and alt text {$alt} to {$img}", true);
500 return Xml
::element( 'img',
507 * Creates the HTML source for images
508 * @deprecated use makeImageLink2
510 * @param object $title
511 * @param string $label label text
512 * @param string $alt alt text
513 * @param string $align horizontal alignment: none, left, center, right)
514 * @param array $handlerParams Parameters to be passed to the media handler
515 * @param boolean $framed shows image in original size in a frame
516 * @param boolean $thumb shows image as thumbnail in a frame
517 * @param string $manualthumb image name for the manual thumbnail
518 * @param string $valign vertical alignment: baseline, sub, super, top, text-top, middle, bottom, text-bottom
519 * @param string $time, timestamp of the file, set as false for current
522 function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(), $framed = false,
523 $thumb = false, $manualthumb = '', $valign = '', $time = false )
525 $frameParams = array( 'alt' => $alt, 'caption' => $label );
527 $frameParams['align'] = $align;
530 $frameParams['framed'] = true;
533 $frameParams['thumbnail'] = true;
535 if ( $manualthumb ) {
536 $frameParams['manualthumb'] = $manualthumb;
539 $frameParams['valign'] = $valign;
541 $file = wfFindFile( $title, $time );
542 return $this->makeImageLink2( $title, $file, $frameParams, $handlerParams, $time );
546 * Given parameters derived from [[Image:Foo|options...]], generate the
547 * HTML that that syntax inserts in the page.
549 * @param Title $title Title object
550 * @param File $file File object, or false if it doesn't exist
552 * @param array $frameParams Associative array of parameters external to the media handler.
553 * Boolean parameters are indicated by presence or absence, the value is arbitrary and
554 * will often be false.
555 * thumbnail If present, downscale and frame
556 * manualthumb Image name to use as a thumbnail, instead of automatic scaling
557 * framed Shows image in original size in a frame
558 * frameless Downscale but don't frame
559 * upright If present, tweak default sizes for portrait orientation
560 * upright_factor Fudge factor for "upright" tweak (default 0.75)
561 * border If present, show a border around the image
562 * align Horizontal alignment (left, right, center, none)
563 * valign Vertical alignment (baseline, sub, super, top, text-top, middle,
564 * bottom, text-bottom)
565 * alt Alternate text for image (i.e. alt attribute). Plain text.
566 * caption HTML for image caption.
568 * @param array $handlerParams Associative array of media handler parameters, to be passed
569 * to transform(). Typical keys are "width" and "page".
570 * @param string $time, timestamp of the file, set as false for current
571 * @param string $query, query params for desc url
572 * @return string HTML for an image, with links, wrappers, etc.
574 function makeImageLink2( Title
$title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
576 if( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$this, &$title,
577 &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
581 global $wgContLang, $wgUser, $wgThumbLimits, $wgThumbUpright;
582 if ( $file && !$file->allowInlineDisplay() ) {
583 wfDebug( __METHOD__
.': '.$title->getPrefixedDBkey()." does not allow inline display\n" );
584 return $this->makeKnownLinkObj( $title );
589 $hp =& $handlerParams;
591 // Clean up parameters
592 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
593 if ( !isset( $fp['align'] ) ) $fp['align'] = '';
594 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
596 $prefix = $postfix = '';
598 if ( 'center' == $fp['align'] )
600 $prefix = '<div class="center">';
602 $fp['align'] = 'none';
604 if ( $file && !isset( $hp['width'] ) ) {
605 $hp['width'] = $file->getWidth( $page );
607 if( isset( $fp['thumbnail'] ) ||
isset( $fp['framed'] ) ||
isset( $fp['frameless'] ) ||
!$hp['width'] ) {
608 $wopt = $wgUser->getOption( 'thumbsize' );
610 if( !isset( $wgThumbLimits[$wopt] ) ) {
611 $wopt = User
::getDefaultOption( 'thumbsize' );
614 // Reduce width for upright images when parameter 'upright' is used
615 if ( isset( $fp['upright'] ) && $fp['upright'] == 0 ) {
616 $fp['upright'] = $wgThumbUpright;
618 // Use width which is smaller: real image width or user preference width
619 // 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
620 $prefWidth = isset( $fp['upright'] ) ?
621 round( $wgThumbLimits[$wopt] * $fp['upright'], -1 ) :
622 $wgThumbLimits[$wopt];
623 if ( $hp['width'] <= 0 ||
$prefWidth < $hp['width'] ) {
624 $hp['width'] = $prefWidth;
629 if ( isset( $fp['thumbnail'] ) ||
isset( $fp['manualthumb'] ) ||
isset( $fp['framed'] ) ) {
631 # Create a thumbnail. Alignment depends on language
632 # writing direction, # right aligned for left-to-right-
633 # languages ("Western languages"), left-aligned
634 # for right-to-left-languages ("Semitic languages")
636 # If thumbnail width has not been provided, it is set
637 # to the default user option as specified in Language*.php
638 if ( $fp['align'] == '' ) {
639 $fp['align'] = $wgContLang->isRTL() ?
'left' : 'right';
641 return $prefix.$this->makeThumbLink2( $title, $file, $fp, $hp, $time, $query ).$postfix;
644 if ( $file && isset( $fp['frameless'] ) ) {
645 $srcWidth = $file->getWidth( $page );
646 # For "frameless" option: do not present an image bigger than the source (for bitmap-style images)
647 # This is the same behaviour as the "thumb" option does it already.
648 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
649 $hp['width'] = $srcWidth;
653 if ( $file && $hp['width'] ) {
654 # Create a resized image, without the additional thumbnail features
655 $thumb = $file->transform( $hp );
661 $s = $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
663 $s = $thumb->toHtml( array(
665 'desc-query' => $query,
667 'valign' => isset( $fp['valign'] ) ?
$fp['valign'] : false ,
668 'img-class' => isset( $fp['border'] ) ?
'thumbborder' : false ) );
670 if ( '' != $fp['align'] ) {
671 $s = "<div class=\"float{$fp['align']}\"><span>{$s}</span></div>";
673 return str_replace("\n", ' ',$prefix.$s.$postfix);
677 * Make HTML for a thumbnail including image, border and caption
678 * @param Title $title
679 * @param File $file File object or false if it doesn't exist
681 function makeThumbLinkObj( Title
$title, $file, $label = '', $alt, $align = 'right', $params = array(), $framed=false , $manualthumb = "" ) {
682 $frameParams = array(
687 if ( $framed ) $frameParams['framed'] = true;
688 if ( $manualthumb ) $frameParams['manualthumb'] = $manualthumb;
689 return $this->makeThumbLink2( $title, $file, $frameParams, $params );
692 function makeThumbLink2( Title
$title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
693 global $wgStylePath, $wgContLang;
694 $exists = $file && $file->exists();
698 $hp =& $handlerParams;
700 $page = isset( $hp['page'] ) ?
$hp['page'] : false;
701 if ( !isset( $fp['align'] ) ) $fp['align'] = 'right';
702 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
703 if ( !isset( $fp['caption'] ) ) $fp['caption'] = '';
705 if ( empty( $hp['width'] ) ) {
706 // Reduce width for upright images when parameter 'upright' is used
707 $hp['width'] = isset( $fp['upright'] ) ?
130 : 180;
712 $outerWidth = $hp['width'] +
2;
714 if ( isset( $fp['manualthumb'] ) ) {
715 # Use manually specified thumbnail
716 $manual_title = Title
::makeTitleSafe( NS_IMAGE
, $fp['manualthumb'] );
717 if( $manual_title ) {
718 $manual_img = wfFindFile( $manual_title );
720 $thumb = $manual_img->getUnscaledThumb();
725 } elseif ( isset( $fp['framed'] ) ) {
726 // Use image dimensions, don't scale
727 $thumb = $file->getUnscaledThumb( $page );
729 # Do not present an image bigger than the source, for bitmap-style images
730 # This is a hack to maintain compatibility with arbitrary pre-1.10 behaviour
731 $srcWidth = $file->getWidth( $page );
732 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
733 $hp['width'] = $srcWidth;
735 $thumb = $file->transform( $hp );
739 $outerWidth = $thumb->getWidth() +
2;
741 $outerWidth = $hp['width'] +
2;
746 $query = $query ?
'&page=' . urlencode( $page ) : 'page=' . urlencode( $page );
748 $url = $title->getLocalURL( $query );
750 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
752 $s = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
754 $s .= $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
756 } elseif ( !$thumb ) {
757 $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
760 $s .= $thumb->toHtml( array(
762 'img-class' => 'thumbimage',
764 'desc-query' => $query ) );
765 if ( isset( $fp['framed'] ) ) {
768 $zoomicon = '<div class="magnify">'.
769 '<a href="'.$url.'" class="internal" title="'.$more.'">'.
770 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
771 'width="15" height="11" alt="" /></a></div>';
774 $s .= ' <div class="thumbcaption">'.$zoomicon.$fp['caption']."</div></div></div>";
775 return str_replace("\n", ' ', $s);
779 * Make a "broken" link to an image
781 * @param Title $title Image title
782 * @param string $text Link label
783 * @param string $query Query string
784 * @param string $trail Link trail
785 * @param string $prefix Link prefix
786 * @param bool $time, a file of a certain timestamp was requested
789 public function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '', $time = false ) {
790 global $wgEnableUploads;
791 if( $title instanceof Title
) {
792 wfProfileIn( __METHOD__
);
793 $currentExists = $time ?
( wfFindFile( $title ) != false ) : false;
794 if( $wgEnableUploads && !$currentExists ) {
795 $upload = SpecialPage
::getTitleFor( 'Upload' );
797 $text = htmlspecialchars( $title->getPrefixedText() );
798 $redir = RepoGroup
::singleton()->getLocalRepo()->checkRedirect( $title );
800 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
802 $q = 'wpDestFile=' . $title->getPartialUrl();
805 list( $inside, $trail ) = self
::splitTrail( $trail );
806 $style = $this->getInternalLinkAttributesObj( $title, $text, 'new' );
807 wfProfileOut( __METHOD__
);
808 return '<a href="' . $upload->escapeLocalUrl( $q ) . '"'
809 . $style . '>' . $prefix . $text . $inside . '</a>' . $trail;
811 wfProfileOut( __METHOD__
);
812 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
815 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
819 /** @deprecated use Linker::makeMediaLinkObj() */
820 function makeMediaLink( $name, $unused = '', $text = '', $time = false ) {
821 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
822 return $this->makeMediaLinkObj( $nt, $text, $time );
826 * Create a direct link to a given uploaded file.
828 * @param $title Title object.
829 * @param $text String: pre-sanitized HTML
830 * @param $time string: time image was created
831 * @return string HTML
834 * @todo Handle invalid or missing images better.
836 function makeMediaLinkObj( $title, $text = '', $time = false ) {
837 if( is_null( $title ) ) {
838 ### HOTFIX. Instead of breaking, return empty string.
841 $img = wfFindFile( $title, $time );
843 $url = $img->getURL();
846 $upload = SpecialPage
::getTitleFor( 'Upload' );
847 $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $title->getDBkey() ) );
850 $alt = htmlspecialchars( $title->getText() );
854 $u = htmlspecialchars( $url );
855 return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\">{$text}</a>";
859 /** @todo document */
860 function specialLink( $name, $key = '' ) {
863 if ( '' == $key ) { $key = strtolower( $name ); }
864 $pn = $wgContLang->ucfirst( $name );
865 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
869 /** @todo document */
870 function makeExternalLink( $url, $text, $escape = true, $linktype = '', $ns = null ) {
871 $style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
872 global $wgNoFollowLinks, $wgNoFollowNsExceptions;
873 if( $wgNoFollowLinks && !(isset($ns) && in_array($ns, $wgNoFollowNsExceptions)) ) {
874 $style .= ' rel="nofollow"';
876 $url = htmlspecialchars( $url );
878 $text = htmlspecialchars( $text );
881 $success = wfRunHooks('LinkerMakeExternalLink', array( &$url, &$text, &$link ) );
883 wfDebug("Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}", true);
886 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
890 * Make user link (or user contributions for unregistered users)
891 * @param $userId Integer: user id in database.
892 * @param $userText String: user name in database
893 * @return string HTML fragment
896 function userLink( $userId, $userText ) {
897 $encName = htmlspecialchars( $userText );
899 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $userText );
900 return $this->makeKnownLinkObj( $contribsPage,
903 $userPage = Title
::makeTitle( NS_USER
, $userText );
904 return $this->makeLinkObj( $userPage, $encName );
909 * Generate standard user tool links (talk, contributions, block link, etc.)
911 * @param int $userId User identifier
912 * @param string $userText User name or IP address
913 * @param bool $redContribsWhenNoEdits Should the contributions link be red if the user has no edits?
914 * @param int $flags Customisation flags (e.g. self::TOOL_LINKS_NOBLOCK)
915 * @param int $edits, user edit count (optional, for performance)
918 public function userToolLinks( $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits=null ) {
919 global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans;
920 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
921 $blockable = ( $wgSysopUserBans ||
0 == $userId ) && !$flags & self
::TOOL_LINKS_NOBLOCK
;
925 $items[] = $this->userTalkLink( $userId, $userText );
928 // check if the user has an edit
929 if( $redContribsWhenNoEdits ) {
930 $count = !is_null($edits) ?
$edits : User
::edits( $userId );
931 $style = ($count == 0) ?
" class='new'" : '';
935 $contribsPage = SpecialPage
::getTitleFor( 'Contributions', $userText );
937 $items[] = $this->makeKnownLinkObj( $contribsPage, wfMsgHtml( 'contribslink' ), '', '', '', '', $style );
939 if( $blockable && $wgUser->isAllowed( 'block' ) ) {
940 $items[] = $this->blockLink( $userId, $userText );
944 return ' (' . implode( ' | ', $items ) . ')';
951 * Alias for userToolLinks( $userId, $userText, true );
952 * @param int $userId User identifier
953 * @param string $userText User name or IP address
954 * @param int $edits, user edit count (optional, for performance)
956 public function userToolLinksRedContribs( $userId, $userText, $edits=null ) {
957 return $this->userToolLinks( $userId, $userText, true, 0, $edits );
962 * @param $userId Integer: user id in database.
963 * @param $userText String: user name in database.
964 * @return string HTML fragment with user talk link
967 function userTalkLink( $userId, $userText ) {
968 $userTalkPage = Title
::makeTitle( NS_USER_TALK
, $userText );
969 $userTalkLink = $this->makeLinkObj( $userTalkPage, wfMsgHtml( 'talkpagelinktext' ) );
970 return $userTalkLink;
974 * @param $userId Integer: userid
975 * @param $userText String: user name in database.
976 * @return string HTML fragment with block link
979 function blockLink( $userId, $userText ) {
980 $blockPage = SpecialPage
::getTitleFor( 'Blockip', $userText );
981 $blockLink = $this->makeKnownLinkObj( $blockPage,
982 wfMsgHtml( 'blocklink' ) );
987 * Generate a user link if the current user is allowed to view it
988 * @param $rev Revision object.
989 * @param $isPublic, bool, show only if all users can see it
990 * @return string HTML
992 function revUserLink( $rev, $isPublic = false ) {
993 if( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
994 $link = wfMsgHtml( 'rev-deleted-user' );
995 } else if( $rev->userCan( Revision
::DELETED_USER
) ) {
996 $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() );
998 $link = wfMsgHtml( 'rev-deleted-user' );
1000 if( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1001 return '<span class="history-deleted">' . $link . '</span>';
1007 * Generate a user tool link cluster if the current user is allowed to view it
1008 * @param $rev Revision object.
1009 * @param $isPublic, bool, show only if all users can see it
1010 * @return string HTML
1012 function revUserTools( $rev, $isPublic = false ) {
1013 if( $rev->isDeleted( Revision
::DELETED_USER
) && $isPublic ) {
1014 $link = wfMsgHtml( 'rev-deleted-user' );
1015 } else if( $rev->userCan( Revision
::DELETED_USER
) ) {
1016 $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() ) .
1017 ' ' . $this->userToolLinks( $rev->getRawUser(), $rev->getRawUserText() );
1019 $link = wfMsgHtml( 'rev-deleted-user' );
1021 if( $rev->isDeleted( Revision
::DELETED_USER
) ) {
1022 return ' <span class="history-deleted">' . $link . '</span>';
1028 * This function is called by all recent changes variants, by the page history,
1029 * and by the user contributions list. It is responsible for formatting edit
1030 * comments. It escapes any HTML in the comment, but adds some CSS to format
1031 * auto-generated comments (from section editing) and formats [[wikilinks]].
1033 * @author Erik Moeller <moeller@scireview.de>
1035 * Note: there's not always a title to pass to this function.
1036 * Since you can't set a default parameter for a reference, I've turned it
1037 * temporarily to a value pass. Should be adjusted further. --brion
1039 * @param string $comment
1040 * @param mixed $title Title object (to generate link to the section in autocomment) or null
1041 * @param bool $local Whether section links should refer to local page
1043 function formatComment($comment, $title = NULL, $local = false) {
1044 wfProfileIn( __METHOD__
);
1046 # Sanitize text a bit:
1047 $comment = str_replace( "\n", " ", $comment );
1048 $comment = htmlspecialchars( $comment );
1050 # Render autocomments and make links:
1051 $comment = $this->formatAutoComments( $comment, $title, $local );
1052 $comment = $this->formatLinksInComment( $comment );
1054 wfProfileOut( __METHOD__
);
1059 * The pattern for autogen comments is / * foo * /, which makes for
1061 * We look for all comments, match any text before and after the comment,
1062 * add a separator where needed and format the comment itself with CSS
1063 * Called by Linker::formatComment.
1065 * @param string $comment Comment text
1066 * @param object $title An optional title object used to links to sections
1067 * @return string $comment formatted comment
1069 * @todo Document the $local parameter.
1071 private function formatAutocomments( $comment, $title = NULL, $local = false ) {
1073 while (preg_match('!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment,$match)) {
1081 # Generate a valid anchor name from the section title.
1082 # Hackish, but should generally work - we strip wiki
1083 # syntax, including the magic [[: that is used to
1084 # "link rather than show" in case of images and
1085 # interlanguage links.
1086 $section = str_replace( '[[:', '', $section );
1087 $section = str_replace( '[[', '', $section );
1088 $section = str_replace( ']]', '', $section );
1090 $sectionTitle = Title
::newFromText( '#' . $section);
1092 $sectionTitle = wfClone( $title );
1093 $sectionTitle->mFragment
= $section;
1095 $link = $this->makeKnownLinkObj( $sectionTitle, wfMsgForContent( 'sectionlink' ) );
1097 $auto = $link . $auto;
1099 # written summary $presep autocomment (summary /* section */)
1100 $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
1103 # autocomment $postsep written summary (/* section */ summary)
1104 $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
1106 $auto = '<span class="autocomment">' . $auto . '</span>';
1107 $comment = $pre . $auto . $post;
1114 * Formats wiki links and media links in text; all other wiki formatting
1117 * @fixme doesn't handle sub-links as in image thumb texts like the main parser
1118 * @param string $comment Text to format links in
1121 public function formatLinksInComment( $comment ) {
1122 return preg_replace_callback(
1123 '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
1124 array( $this, 'formatLinksInCommentCallback' ),
1128 protected function formatLinksInCommentCallback( $match ) {
1131 $medians = '(?:' . preg_quote( MWNamespace
::getCanonicalName( NS_MEDIA
), '/' ) . '|';
1132 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA
), '/' ) . '):';
1134 $comment = $match[0];
1136 # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
1137 if( strpos( $match[1], '%' ) !== false ) {
1138 $match[1] = str_replace( array('<', '>'), array('<', '>'), urldecode($match[1]) );
1141 # Handle link renaming [[foo|text]] will show link as "text"
1142 if( "" != $match[3] ) {
1147 $submatch = array();
1148 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1149 # Media link; trail not supported.
1150 $linkRegexp = '/\[\[(.*?)\]\]/';
1151 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
1153 # Other kind of link
1154 if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
1155 $trail = $submatch[1];
1159 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
1160 if (isset($match[1][0]) && $match[1][0] == ':')
1161 $match[1] = substr($match[1], 1);
1162 $thelink = $this->makeLink( $match[1], $text, "", $trail );
1164 $comment = preg_replace( $linkRegexp, StringUtils
::escapeRegexReplacement( $thelink ), $comment, 1 );
1170 * Wrap a comment in standard punctuation and formatting if
1171 * it's non-empty, otherwise return empty string.
1173 * @param string $comment
1174 * @param mixed $title Title object (to generate link to section in autocomment) or null
1175 * @param bool $local Whether section links should refer to local page
1179 function commentBlock( $comment, $title = NULL, $local = false ) {
1180 // '*' used to be the comment inserted by the software way back
1181 // in antiquity in case none was provided, here for backwards
1182 // compatability, acc. to brion -ævar
1183 if( $comment == '' ||
$comment == '*' ) {
1186 $formatted = $this->formatComment( $comment, $title, $local );
1187 return " <span class=\"comment\">($formatted)</span>";
1192 * Wrap and format the given revision's comment block, if the current
1193 * user is allowed to view it.
1195 * @param Revision $rev
1196 * @param bool $local Whether section links should refer to local page
1197 * @param $isPublic, show only if all users can see it
1198 * @return string HTML
1200 function revComment( Revision
$rev, $local = false, $isPublic = false ) {
1201 if( $rev->isDeleted( Revision
::DELETED_COMMENT
) && $isPublic ) {
1202 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1203 } else if( $rev->userCan( Revision
::DELETED_COMMENT
) ) {
1204 $block = $this->commentBlock( $rev->getRawComment(), $rev->getTitle(), $local );
1206 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
1208 if( $rev->isDeleted( Revision
::DELETED_COMMENT
) ) {
1209 return " <span class=\"history-deleted\">$block</span>";
1214 /** @todo document */
1215 function tocIndent() {
1219 /** @todo document */
1220 function tocUnindent($level) {
1221 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ?
$level : 0 );
1225 * parameter level defines if we are on an indentation level
1227 function tocLine( $anchor, $tocline, $tocnumber, $level ) {
1228 return "\n<li class=\"toclevel-$level\"><a href=\"#" .
1229 $anchor . '"><span class="tocnumber">' .
1230 $tocnumber . '</span> <span class="toctext">' .
1231 $tocline . '</span></a>';
1234 /** @todo document */
1235 function tocLineEnd() {
1239 /** @todo document */
1240 function tocList($toc) {
1241 global $wgJsMimeType;
1242 $title = wfMsgHtml('toc') ;
1244 '<table id="toc" class="toc" summary="' . $title .'"><tr><td>'
1245 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
1247 # no trailing newline, script should not be wrapped in a
1249 . "</ul>\n</td></tr></table>"
1250 . '<script type="' . $wgJsMimeType . '">'
1251 . ' if (window.showTocToggle) {'
1252 . ' var tocShowText = "' . wfEscapeJsString( wfMsg('showtoc') ) . '";'
1253 . ' var tocHideText = "' . wfEscapeJsString( wfMsg('hidetoc') ) . '";'
1254 . ' showTocToggle();'
1260 * Used to generate section edit links that point to "other" pages
1261 * (sections that are really part of included pages).
1263 * @param $title Title string.
1264 * @param $section Integer: section number.
1266 public function editSectionLinkForOther( $title, $section ) {
1267 $title = Title
::newFromText( $title );
1268 return $this->doEditSectionLink( $title, $section, '', 'EditSectionLinkForOther' );
1272 * @param $nt Title object.
1273 * @param $section Integer: section number.
1274 * @param $hint Link String: title, or default if omitted or empty
1276 public function editSectionLink( Title
$nt, $section, $hint='' ) {
1278 $hint = wfMsgHtml( 'editsectionhint', htmlspecialchars( $hint ) );
1279 $hint = " title=\"$hint\"";
1281 return $this->doEditSectionLink( $nt, $section, $hint, 'EditSectionLink' );
1285 * Implement editSectionLink and editSectionLinkForOther.
1287 * @param $nt Title object
1288 * @param $section Integer, section number
1289 * @param $hint String, for HTML title attribute
1290 * @param $hook String, name of hook to run
1291 * @return String, HTML to use for edit link
1293 protected function doEditSectionLink( Title
$nt, $section, $hint, $hook ) {
1295 $editurl = '§ion='.$section;
1296 $url = $this->makeKnownLinkObj(
1298 htmlspecialchars(wfMsg('editsection')),
1299 'action=edit'.$editurl,
1304 // The two hooks have slightly different interfaces . . .
1305 if( $hook == 'EditSectionLink' ) {
1306 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $hint, $url, &$result ) );
1307 } elseif( $hook == 'EditSectionLinkForOther' ) {
1308 wfRunHooks( 'EditSectionLinkForOther', array( &$this, $nt, $section, $url, &$result ) );
1311 // For reverse compatibility, add the brackets *after* the hook is run,
1312 // and even add them to hook-provided text.
1313 if( is_null( $result ) ) {
1314 $result = wfMsgHtml( 'editsection-brackets', $url );
1316 $result = wfMsgHtml( 'editsection-brackets', $result );
1318 return "<span class=\"editsection\">$result</span>";
1322 * Create a headline for content
1324 * @param int $level The level of the headline (1-6)
1325 * @param string $attribs Any attributes for the headline, starting with a space and ending with '>'
1326 * This *must* be at least '>' for no attribs
1327 * @param string $anchor The anchor to give the headline (the bit after the #)
1328 * @param string $text The text of the header
1329 * @param string $link HTML to add for the section edit link
1331 * @return string HTML headline
1333 public function makeHeadline( $level, $attribs, $anchor, $text, $link ) {
1334 return "<a name=\"$anchor\"></a><h$level$attribs$link <span class=\"mw-headline\">$text</span></h$level>";
1338 * Split a link trail, return the "inside" portion and the remainder of the trail
1339 * as a two-element array
1343 static function splitTrail( $trail ) {
1344 static $regex = false;
1345 if ( $regex === false ) {
1347 $regex = $wgContLang->linkTrail();
1350 if ( '' != $trail ) {
1352 if ( preg_match( $regex, $trail, $m ) ) {
1357 return array( $inside, $trail );
1361 * Generate a rollback link for a given revision. Currently it's the
1362 * caller's responsibility to ensure that the revision is the top one. If
1363 * it's not, of course, the user will get an error message.
1365 * If the calling page is called with the parameter &bot=1, all rollback
1366 * links also get that parameter. It causes the edit itself and the rollback
1367 * to be marked as "bot" edits. Bot edits are hidden by default from recent
1368 * changes, so this allows sysops to combat a busy vandal without bothering
1371 * @param Revision $rev
1373 function generateRollback( $rev ) {
1374 return '<span class="mw-rollback-link">['
1375 . $this->buildRollbackLink( $rev )
1380 * Build a raw rollback link, useful for collections of "tool" links
1382 * @param Revision $rev
1385 public function buildRollbackLink( $rev ) {
1386 global $wgRequest, $wgUser;
1387 $title = $rev->getTitle();
1388 $extra = $wgRequest->getBool( 'bot' ) ?
'&bot=1' : '';
1389 $extra .= '&token=' . urlencode( $wgUser->editToken( array( $title->getPrefixedText(),
1390 $rev->getUserText() ) ) );
1391 return $this->makeKnownLinkObj(
1393 wfMsgHtml( 'rollbacklink' ),
1394 'action=rollback&from=' . urlencode( $rev->getUserText() ) . $extra
1399 * Returns HTML for the "templates used on this page" list.
1401 * @param array $templates Array of templates from Article::getUsedTemplate
1403 * @param bool $preview Whether this is for a preview
1404 * @param bool $section Whether this is for a section edit
1405 * @return string HTML output
1407 public function formatTemplates( $templates, $preview = false, $section = false) {
1409 wfProfileIn( __METHOD__
);
1411 $sk = $wgUser->getSkin();
1414 if ( count( $templates ) > 0 ) {
1415 # Do a batch existence check
1416 $batch = new LinkBatch
;
1417 foreach( $templates as $title ) {
1418 $batch->addObj( $title );
1422 # Construct the HTML
1423 $outText = '<div class="mw-templatesUsedExplanation">';
1425 $outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ) );
1426 } elseif ( $section ) {
1427 $outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ) );
1429 $outText .= wfMsgExt( 'templatesused', array( 'parse' ) );
1431 $outText .= '</div><ul>';
1433 usort( $templates, array( 'Title', 'compare' ) );
1434 foreach ( $templates as $titleObj ) {
1435 $r = $titleObj->getRestrictions( 'edit' );
1436 if ( in_array( 'sysop', $r ) ) {
1437 $protected = wfMsgExt( 'template-protected', array( 'parseinline' ) );
1438 } elseif ( in_array( 'autoconfirmed', $r ) ) {
1439 $protected = wfMsgExt( 'template-semiprotected', array( 'parseinline' ) );
1443 $outText .= '<li>' . $sk->makeLinkObj( $titleObj ) . ' ' . $protected . '</li>';
1445 $outText .= '</ul>';
1447 wfProfileOut( __METHOD__
);
1452 * Returns HTML for the "hidden categories on this page" list.
1454 * @param array $hiddencats Array of hidden categories from Article::getHiddenCategories
1456 * @return string HTML output
1458 public function formatHiddenCategories( $hiddencats) {
1459 global $wgUser, $wgLang;
1460 wfProfileIn( __METHOD__
);
1462 $sk = $wgUser->getSkin();
1465 if ( count( $hiddencats ) > 0 ) {
1466 # Construct the HTML
1467 $outText = '<div class="mw-hiddenCategoriesExplanation">';
1468 $outText .= wfMsgExt( 'hiddencategories', array( 'parse' ), $wgLang->formatnum( count( $hiddencats ) ) );
1469 $outText .= '</div><ul>';
1471 foreach ( $hiddencats as $titleObj ) {
1472 $outText .= '<li>' . $sk->makeKnownLinkObj( $titleObj ) . '</li>'; # If it's hidden, it must exist - no need to check with a LinkBatch
1474 $outText .= '</ul>';
1476 wfProfileOut( __METHOD__
);
1481 * Format a size in bytes for output, using an appropriate
1482 * unit (B, KB, MB or GB) according to the magnitude in question
1484 * @param $size Size to format
1487 public function formatSize( $size ) {
1489 return htmlspecialchars( $wgLang->formatSize( $size ) );
1493 * Given the id of an interface element, constructs the appropriate title
1494 * and accesskey attributes from the system messages. (Note, this is usu-
1495 * ally the id but isn't always, because sometimes the accesskey needs to
1496 * go on a different element than the id, for reverse-compatibility, etc.)
1498 * @param string $name Id of the element, minus prefixes.
1499 * @return string title and accesskey attributes, ready to drop in an
1500 * element (e.g., ' title="This does something [x]" accesskey="x"').
1502 public function tooltipAndAccesskey($name) {
1503 $fname="Linker::tooltipAndAccesskey";
1504 wfProfileIn($fname);
1507 $tooltip = wfMsg('tooltip-'.$name);
1508 if (!wfEmptyMsg('tooltip-'.$name, $tooltip) && $tooltip != '-') {
1509 // Compatibility: formerly some tooltips had [alt-.] hardcoded
1510 $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
1511 $out .= ' title="'.htmlspecialchars($tooltip);
1513 $accesskey = wfMsg('accesskey-'.$name);
1514 if ($accesskey && $accesskey != '-' && !wfEmptyMsg('accesskey-'.$name, $accesskey)) {
1515 if ($out) $out .= " [$accesskey]\" accesskey=\"$accesskey\"";
1516 else $out .= " title=\"[$accesskey]\" accesskey=\"$accesskey\"";
1520 wfProfileOut($fname);
1525 * Given the id of an interface element, constructs the appropriate title
1526 * attribute from the system messages. (Note, this is usually the id but
1527 * isn't always, because sometimes the accesskey needs to go on a different
1528 * element than the id, for reverse-compatibility, etc.)
1530 * @param string $name Id of the element, minus prefixes.
1531 * @return string title attribute, ready to drop in an element
1532 * (e.g., ' title="This does something"').
1534 public function tooltip($name) {
1537 $tooltip = wfMsg('tooltip-'.$name);
1538 if (!wfEmptyMsg('tooltip-'.$name, $tooltip) && $tooltip != '-') {
1539 $out = ' title="'.htmlspecialchars($tooltip).'"';