00001 <?php
00011 class Linker {
00012
00016 const TOOL_LINKS_NOBLOCK = 1;
00017
00018 function __construct() {}
00019
00023 function postParseLinkColour( $s = null ) {
00024 wfDeprecated( __METHOD__ );
00025 return null;
00026 }
00027
00037 function getExternalLinkAttributes( $title, $unused = null, $class='' ) {
00038 return $this->getLinkAttributesInternal( $title, $class, 'external' );
00039 }
00040
00051 function getInterwikiLinkAttributes( $title, $unused = null, $class='' ) {
00052 global $wgContLang;
00053
00054 # FIXME: We have a whole bunch of handling here that doesn't happen in
00055 # getExternalLinkAttributes, why?
00056 $title = urldecode( $title );
00057 $title = $wgContLang->checkTitleEncoding( $title );
00058 $title = preg_replace( '/[\\x00-\\x1f]/', ' ', $title );
00059
00060 return $this->getLinkAttributesInternal( $title, $class, 'external' );
00061 }
00062
00072 function getInternalLinkAttributes( $title, $unused = null, $class='' ) {
00073 $title = urldecode( $title );
00074 $title = str_replace( '_', ' ', $title );
00075 return $this->getLinkAttributesInternal( $title, $class );
00076 }
00077
00088 function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) {
00089 if( $title === false ) {
00090 $title = $nt->getPrefixedText();
00091 }
00092 return $this->getLinkAttributesInternal( $title, $class );
00093 }
00094
00098 private function getLinkAttributesInternal( $title, $class, $classDefault = false ) {
00099 $title = htmlspecialchars( $title );
00100 if( $class === '' and $classDefault !== false ) {
00101 # FIXME: Parameter defaults the hard way! We should just have
00102 # $class = 'external' or whatever as the default in the externally-
00103 # exposed functions, not $class = ''.
00104 $class = $classDefault;
00105 }
00106 $class = htmlspecialchars( $class );
00107 $r = '';
00108 if( $class !== '' ) {
00109 $r .= " class=\"$class\"";
00110 }
00111 $r .= " title=\"$title\"";
00112 return $r;
00113 }
00114
00122 function getLinkColour( $t, $threshold ) {
00123 $colour = '';
00124 if ( $t->isRedirect() ) {
00125 # Page is a redirect
00126 $colour = 'mw-redirect';
00127 } elseif ( $threshold > 0 &&
00128 $t->exists() && $t->getLength() < $threshold &&
00129 MWNamespace::isContent( $t->getNamespace() ) ) {
00130 # Page is a stub
00131 $colour = 'stub';
00132 }
00133 return $colour;
00134 }
00135
00173 public function link( $target, $text = null, $customAttribs = array(), $query = array(), $options = array() ) {
00174 wfProfileIn( __METHOD__ );
00175 if( !$target instanceof Title ) {
00176 return "<!-- ERROR -->$text";
00177 }
00178 $options = (array)$options;
00179
00180 $ret = null;
00181 if( !wfRunHooks( 'LinkBegin', array( $this, $target, &$text,
00182 &$customAttribs, &$query, &$options, &$ret ) ) ) {
00183 wfProfileOut( __METHOD__ );
00184 return $ret;
00185 }
00186
00187 # Normalize the Title if it's a special page
00188 $target = $this->normaliseSpecialPage( $target );
00189
00190 # If we don't know whether the page exists, let's find out.
00191 wfProfileIn( __METHOD__ . '-checkPageExistence' );
00192 if( !in_array( 'known', $options ) and !in_array( 'broken', $options ) ) {
00193 if( $target->isKnown() ) {
00194 $options []= 'known';
00195 } else {
00196 $options []= 'broken';
00197 }
00198 }
00199 wfProfileOut( __METHOD__ . '-checkPageExistence' );
00200
00201 $oldquery = array();
00202 if( in_array( "forcearticlepath", $options ) && $query ){
00203 $oldquery = $query;
00204 $query = array();
00205 }
00206
00207 # Note: we want the href attribute first, for prettiness.
00208 $attribs = array( 'href' => $this->linkUrl( $target, $query, $options ) );
00209 if( in_array( 'forcearticlepath', $options ) && $oldquery ){
00210 $attribs['href'] = wfAppendQuery( $attribs['href'], wfArrayToCgi( $oldquery ) );
00211 }
00212
00213 $attribs = array_merge(
00214 $attribs,
00215 $this->linkAttribs( $target, $customAttribs, $options )
00216 );
00217 if( is_null( $text ) ) {
00218 $text = $this->linkText( $target );
00219 }
00220
00221 $ret = null;
00222 if( wfRunHooks( 'LinkEnd', array( $this, $target, $options, &$text, &$attribs, &$ret ) ) ) {
00223 $ret = Xml::openElement( 'a', $attribs ) . $text . Xml::closeElement( 'a' );
00224 }
00225
00226 wfProfileOut( __METHOD__ );
00227 return $ret;
00228 }
00229
00230 private function linkUrl( $target, $query, $options ) {
00231 wfProfileIn( __METHOD__ );
00232 # We don't want to include fragments for broken links, because they
00233 # generally make no sense.
00234 if( in_array( 'broken', $options ) and $target->mFragment !== '' ) {
00235 $target = clone $target;
00236 $target->mFragment = '';
00237 }
00238
00239 # If it's a broken link, add the appropriate query pieces, unless
00240 # there's already an action specified, or unless 'edit' makes no sense
00241 # (i.e., for a nonexistent special page).
00242 if( in_array( 'broken', $options ) and empty( $query['action'] )
00243 and $target->getNamespace() != NS_SPECIAL ) {
00244 $query['action'] = 'edit';
00245 $query['redlink'] = '1';
00246 }
00247 $ret = $target->getLinkUrl( $query );
00248 wfProfileOut( __METHOD__ );
00249 return $ret;
00250 }
00251
00252 private function linkAttribs( $target, $attribs, $options ) {
00253 wfProfileIn( __METHOD__ );
00254 global $wgUser;
00255 $defaults = array();
00256
00257 if( !in_array( 'noclasses', $options ) ) {
00258 wfProfileIn( __METHOD__ . '-getClasses' );
00259 # Now build the classes.
00260 $classes = array();
00261
00262 if( in_array( 'broken', $options ) ) {
00263 $classes[] = 'new';
00264 }
00265
00266 if( $target->isExternal() ) {
00267 $classes[] = 'extiw';
00268 }
00269
00270 # Note that redirects never count as stubs here.
00271 if ( $target->isRedirect() ) {
00272 $classes[] = 'mw-redirect';
00273 } elseif( $target->isContentPage() ) {
00274 # Check for stub.
00275 $threshold = $wgUser->getOption( 'stubthreshold' );
00276 if( $threshold > 0 and $target->exists() and $target->getLength() < $threshold ) {
00277 $classes[] = 'stub';
00278 }
00279 }
00280 if( $classes != array() ) {
00281 $defaults['class'] = implode( ' ', $classes );
00282 }
00283 wfProfileOut( __METHOD__ . '-getClasses' );
00284 }
00285
00286 # Get a default title attribute.
00287 if( in_array( 'known', $options ) ) {
00288 $defaults['title'] = $target->getPrefixedText();
00289 } else {
00290 $defaults['title'] = wfMsg( 'red-link-title', $target->getPrefixedText() );
00291 }
00292
00293 # Finally, merge the custom attribs with the default ones, and iterate
00294 # over that, deleting all "false" attributes.
00295 $ret = array();
00296 $merged = Sanitizer::mergeAttributes( $defaults, $attribs );
00297 foreach( $merged as $key => $val ) {
00298 # A false value suppresses the attribute, and we don't want the
00299 # href attribute to be overridden.
00300 if( $key != 'href' and $val !== false ) {
00301 $ret[$key] = $val;
00302 }
00303 }
00304 wfProfileOut( __METHOD__ );
00305 return $ret;
00306 }
00307
00308 private function linkText( $target ) {
00309 # We might be passed a non-Title by make*LinkObj(). Fail gracefully.
00310 if( !$target instanceof Title ) {
00311 return '';
00312 }
00313
00314 # If the target is just a fragment, with no title, we return the frag-
00315 # ment text. Otherwise, we return the title text itself.
00316 if( $target->getPrefixedText() === '' and $target->getFragment() !== '' ) {
00317 return htmlspecialchars( $target->getFragment() );
00318 }
00319 return htmlspecialchars( $target->getPrefixedText() );
00320 }
00321
00335 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
00336 wfProfileIn( __METHOD__ );
00337 $nt = Title::newFromText( $title );
00338 if ( $nt instanceof Title ) {
00339 $result = $this->makeLinkObj( $nt, $text, $query, $trail );
00340 } else {
00341 wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" );
00342 $result = $text == "" ? $title : $text;
00343 }
00344
00345 wfProfileOut( __METHOD__ );
00346 return $result;
00347 }
00348
00362 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
00363 $nt = Title::newFromText( $title );
00364 if ( $nt instanceof Title ) {
00365 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix , $aprops );
00366 } else {
00367 wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" );
00368 return $text == '' ? $title : $text;
00369 }
00370 }
00371
00385 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
00386 $nt = Title::newFromText( $title );
00387 if ( $nt instanceof Title ) {
00388 return $this->makeBrokenLinkObj( $nt, $text, $query, $trail );
00389 } else {
00390 wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" );
00391 return $text == '' ? $title : $text;
00392 }
00393 }
00394
00408 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
00409 wfDeprecated( __METHOD__ );
00410 $nt = Title::newFromText( $title );
00411 if ( $nt instanceof Title ) {
00412 return $this->makeStubLinkObj( $nt, $text, $query, $trail );
00413 } else {
00414 wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" );
00415 return $text == '' ? $title : $text;
00416 }
00417 }
00418
00435 function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
00436 global $wgUser;
00437 wfProfileIn( __METHOD__ );
00438
00439 $query = wfCgiToArray( $query );
00440 list( $inside, $trail ) = Linker::splitTrail( $trail );
00441 if( $text === '' ) {
00442 $text = $this->linkText( $nt );
00443 }
00444
00445 $ret = $this->link( $nt, "$prefix$text$inside", array(), $query ) . $trail;
00446
00447 wfProfileOut( __METHOD__ );
00448 return $ret;
00449 }
00450
00467 function makeKnownLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
00468 wfProfileIn( __METHOD__ );
00469
00470 if ( $text == '' ) {
00471 $text = $this->linkText( $title );
00472 }
00473 $attribs = Sanitizer::mergeAttributes(
00474 Sanitizer::decodeTagAttributes( $aprops ),
00475 Sanitizer::decodeTagAttributes( $style )
00476 );
00477 $query = wfCgiToArray( $query );
00478 list( $inside, $trail ) = Linker::splitTrail( $trail );
00479
00480 $ret = $this->link( $title, "$prefix$text$inside", $attribs, $query,
00481 array( 'known', 'noclasses' ) ) . $trail;
00482
00483 wfProfileOut( __METHOD__ );
00484 return $ret;
00485 }
00486
00499 function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
00500 wfProfileIn( __METHOD__ );
00501
00502 list( $inside, $trail ) = Linker::splitTrail( $trail );
00503 if( $text === '' ) {
00504 $text = $this->linkText( $title );
00505 }
00506 $nt = $this->normaliseSpecialPage( $title );
00507
00508 $ret = $this->link( $title, "$prefix$text$inside", array(),
00509 wfCgiToArray( $query ), 'broken' ) . $trail;
00510
00511 wfProfileOut( __METHOD__ );
00512 return $ret;
00513 }
00514
00527 function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
00528 wfDeprecated( __METHOD__ );
00529 return $this->makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix );
00530 }
00531
00545 function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
00546 if($colour != ''){
00547 $style = $this->getInternalLinkAttributesObj( $nt, $text, $colour );
00548 } else $style = '';
00549 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style );
00550 }
00551
00564 function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
00565 global $wgUser;
00566 $threshold = intval( $wgUser->getOption( 'stubthreshold' ) );
00567 $colour = ( $size < $threshold ) ? 'stub' : '';
00568 return $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
00569 }
00570
00576 function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
00577 if ( '' == $text ) {
00578 $text = htmlspecialchars( $nt->getPrefixedText() );
00579 }
00580 list( $inside, $trail ) = Linker::splitTrail( $trail );
00581 return "<strong class=\"selflink\">{$prefix}{$text}{$inside}</strong>{$trail}";
00582 }
00583
00584 function normaliseSpecialPage( Title $title ) {
00585 if ( $title->getNamespace() == NS_SPECIAL ) {
00586 list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $title->getDBkey() );
00587 if ( !$name ) return $title;
00588 $ret = SpecialPage::getTitleFor( $name, $subpage );
00589 $ret->mFragment = $title->getFragment();
00590 return $ret;
00591 } else {
00592 return $title;
00593 }
00594 }
00595
00597 function fnamePart( $url ) {
00598 $basename = strrchr( $url, '/' );
00599 if ( false === $basename ) {
00600 $basename = $url;
00601 } else {
00602 $basename = substr( $basename, 1 );
00603 }
00604 return $basename;
00605 }
00606
00608 function makeImage( $url, $alt = '' ) {
00609 wfDeprecated( __METHOD__ );
00610 return $this->makeExternalImage( $url, $alt );
00611 }
00612
00614 function makeExternalImage( $url, $alt = '' ) {
00615 if ( '' == $alt ) {
00616 $alt = $this->fnamePart( $url );
00617 }
00618 $img = '';
00619 $success = wfRunHooks('LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
00620 if(!$success) {
00621 wfDebug("Hook LinkerMakeExternalImage changed the output of external image with url {$url} and alt text {$alt} to {$img}\n", true);
00622 return $img;
00623 }
00624 return Xml::element( 'img',
00625 array(
00626 'src' => $url,
00627 'alt' => $alt ) );
00628 }
00629
00646 function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(), $framed = false,
00647 $thumb = false, $manualthumb = '', $valign = '', $time = false )
00648 {
00649 $frameParams = array( 'alt' => $alt, 'caption' => $label );
00650 if ( $align ) {
00651 $frameParams['align'] = $align;
00652 }
00653 if ( $framed ) {
00654 $frameParams['framed'] = true;
00655 }
00656 if ( $thumb ) {
00657 $frameParams['thumbnail'] = true;
00658 }
00659 if ( $manualthumb ) {
00660 $frameParams['manualthumb'] = $manualthumb;
00661 }
00662 if ( $valign ) {
00663 $frameParams['valign'] = $valign;
00664 }
00665 $file = wfFindFile( $title, $time );
00666 return $this->makeImageLink2( $title, $file, $frameParams, $handlerParams, $time );
00667 }
00668
00701 function makeImageLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
00702 $res = null;
00703 if( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$this, &$title,
00704 &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
00705 return $res;
00706 }
00707
00708 global $wgContLang, $wgUser, $wgThumbLimits, $wgThumbUpright;
00709 if ( $file && !$file->allowInlineDisplay() ) {
00710 wfDebug( __METHOD__.': '.$title->getPrefixedDBkey()." does not allow inline display\n" );
00711 return $this->link( $title );
00712 }
00713
00714
00715 $fp =& $frameParams;
00716 $hp =& $handlerParams;
00717
00718
00719 $page = isset( $hp['page'] ) ? $hp['page'] : false;
00720 if ( !isset( $fp['align'] ) ) $fp['align'] = '';
00721 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
00722 # Backward compatibility, title used to always be equal to alt text
00723 if ( !isset( $fp['title'] ) ) $fp['title'] = $fp['alt'];
00724
00725 $prefix = $postfix = '';
00726
00727 if ( 'center' == $fp['align'] ) {
00728 $prefix = '<div class="center">';
00729 $postfix = '</div>';
00730 $fp['align'] = 'none';
00731 }
00732 if ( $file && !isset( $hp['width'] ) ) {
00733 $hp['width'] = $file->getWidth( $page );
00734
00735 if( isset( $fp['thumbnail'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) || !$hp['width'] ) {
00736 $wopt = $wgUser->getOption( 'thumbsize' );
00737
00738 if( !isset( $wgThumbLimits[$wopt] ) ) {
00739 $wopt = User::getDefaultOption( 'thumbsize' );
00740 }
00741
00742
00743 if ( isset( $fp['upright'] ) && $fp['upright'] == 0 ) {
00744 $fp['upright'] = $wgThumbUpright;
00745 }
00746
00747
00748 $prefWidth = isset( $fp['upright'] ) ?
00749 round( $wgThumbLimits[$wopt] * $fp['upright'], -1 ) :
00750 $wgThumbLimits[$wopt];
00751 if ( $hp['width'] <= 0 || $prefWidth < $hp['width'] ) {
00752 $hp['width'] = $prefWidth;
00753 }
00754 }
00755 }
00756
00757 if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) ) {
00758 # Create a thumbnail. Alignment depends on language
00759 # writing direction, # right aligned for left-to-right-
00760 # languages ("Western languages"), left-aligned
00761 # for right-to-left-languages ("Semitic languages")
00762 #
00763 # If thumbnail width has not been provided, it is set
00764 # to the default user option as specified in Language*.php
00765 if ( $fp['align'] == '' ) {
00766 $fp['align'] = $wgContLang->isRTL() ? 'left' : 'right';
00767 }
00768 return $prefix.$this->makeThumbLink2( $title, $file, $fp, $hp, $time, $query ).$postfix;
00769 }
00770
00771 if ( $file && isset( $fp['frameless'] ) ) {
00772 $srcWidth = $file->getWidth( $page );
00773 # For "frameless" option: do not present an image bigger than the source (for bitmap-style images)
00774 # This is the same behaviour as the "thumb" option does it already.
00775 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
00776 $hp['width'] = $srcWidth;
00777 }
00778 }
00779
00780 if ( $file && $hp['width'] ) {
00781 # Create a resized image, without the additional thumbnail features
00782 $thumb = $file->transform( $hp );
00783 } else {
00784 $thumb = false;
00785 }
00786
00787 if ( !$thumb ) {
00788 $s = $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
00789 } else {
00790 $params = array(
00791 'alt' => $fp['alt'],
00792 'title' => $fp['title'],
00793 'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false ,
00794 'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false );
00795 if ( !empty( $fp['link-url'] ) ) {
00796 $params['custom-url-link'] = $fp['link-url'];
00797 } elseif ( !empty( $fp['link-title'] ) ) {
00798 $params['custom-title-link'] = $fp['link-title'];
00799 } elseif ( !empty( $fp['no-link'] ) ) {
00800
00801 } else {
00802 $params['desc-link'] = true;
00803 $params['desc-query'] = $query;
00804 }
00805
00806 $s = $thumb->toHtml( $params );
00807 }
00808 if ( '' != $fp['align'] ) {
00809 $s = "<div class=\"float{$fp['align']}\">{$s}</div>";
00810 }
00811 return str_replace("\n", ' ',$prefix.$s.$postfix);
00812 }
00813
00819 function makeThumbLinkObj( Title $title, $file, $label = '', $alt, $align = 'right', $params = array(), $framed=false , $manualthumb = "" ) {
00820 $frameParams = array(
00821 'alt' => $alt,
00822 'caption' => $label,
00823 'align' => $align
00824 );
00825 if ( $framed ) $frameParams['framed'] = true;
00826 if ( $manualthumb ) $frameParams['manualthumb'] = $manualthumb;
00827 return $this->makeThumbLink2( $title, $file, $frameParams, $params );
00828 }
00829
00830 function makeThumbLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
00831 global $wgStylePath, $wgContLang;
00832 $exists = $file && $file->exists();
00833
00834 # Shortcuts
00835 $fp =& $frameParams;
00836 $hp =& $handlerParams;
00837
00838 $page = isset( $hp['page'] ) ? $hp['page'] : false;
00839 if ( !isset( $fp['align'] ) ) $fp['align'] = 'right';
00840 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
00841 # Backward compatibility, title used to always be equal to alt text
00842 if ( !isset( $fp['title'] ) ) $fp['title'] = $fp['alt'];
00843 if ( !isset( $fp['caption'] ) ) $fp['caption'] = '';
00844
00845 if ( empty( $hp['width'] ) ) {
00846
00847 $hp['width'] = isset( $fp['upright'] ) ? 130 : 180;
00848 }
00849 $thumb = false;
00850
00851 if ( !$exists ) {
00852 $outerWidth = $hp['width'] + 2;
00853 } else {
00854 if ( isset( $fp['manualthumb'] ) ) {
00855 # Use manually specified thumbnail
00856 $manual_title = Title::makeTitleSafe( NS_FILE, $fp['manualthumb'] );
00857 if( $manual_title ) {
00858 $manual_img = wfFindFile( $manual_title );
00859 if ( $manual_img ) {
00860 $thumb = $manual_img->getUnscaledThumb();
00861 } else {
00862 $exists = false;
00863 }
00864 }
00865 } elseif ( isset( $fp['framed'] ) ) {
00866
00867 $thumb = $file->getUnscaledThumb( $page );
00868 } else {
00869 # Do not present an image bigger than the source, for bitmap-style images
00870 # This is a hack to maintain compatibility with arbitrary pre-1.10 behaviour
00871 $srcWidth = $file->getWidth( $page );
00872 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
00873 $hp['width'] = $srcWidth;
00874 }
00875 $thumb = $file->transform( $hp );
00876 }
00877
00878 if ( $thumb ) {
00879 $outerWidth = $thumb->getWidth() + 2;
00880 } else {
00881 $outerWidth = $hp['width'] + 2;
00882 }
00883 }
00884
00885 # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
00886 # So we don't need to pass it here in $query. However, the URL for the
00887 # zoom icon still needs it, so we make a unique query for it. See bug 14771
00888 $url = $title->getLocalURL( $query );
00889 if( $page ) {
00890 $url = wfAppendQuery( $url, 'page=' . urlencode( $page ) );
00891 }
00892
00893 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
00894
00895 $s = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
00896 if( !$exists ) {
00897 $s .= $this->makeBrokenImageLinkObj( $title, '', '', '', '', $time==true );
00898 $zoomicon = '';
00899 } elseif ( !$thumb ) {
00900 $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
00901 $zoomicon = '';
00902 } else {
00903 $s .= $thumb->toHtml( array(
00904 'alt' => $fp['alt'],
00905 'title' => $fp['title'],
00906 'img-class' => 'thumbimage',
00907 'desc-link' => true,
00908 'desc-query' => $query ) );
00909 if ( isset( $fp['framed'] ) ) {
00910 $zoomicon="";
00911 } else {
00912 $zoomicon = '<div class="magnify">'.
00913 '<a href="'.$url.'" class="internal" title="'.$more.'">'.
00914 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
00915 'width="15" height="11" alt="" /></a></div>';
00916 }
00917 }
00918 $s .= ' <div class="thumbcaption">'.$zoomicon.$fp['caption']."</div></div></div>";
00919 return str_replace("\n", ' ', $s);
00920 }
00921
00933 public function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '', $time = false ) {
00934 global $wgEnableUploads;
00935 if( $title instanceof Title ) {
00936 wfProfileIn( __METHOD__ );
00937 $currentExists = $time ? ( wfFindFile( $title ) != false ) : false;
00938 if( $wgEnableUploads && !$currentExists ) {
00939 $upload = SpecialPage::getTitleFor( 'Upload' );
00940 if( $text == '' )
00941 $text = htmlspecialchars( $title->getPrefixedText() );
00942 $redir = RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title );
00943 if( $redir ) {
00944 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
00945 }
00946 $q = 'wpDestFile=' . $title->getPartialUrl();
00947 if( $query != '' )
00948 $q .= '&' . $query;
00949 list( $inside, $trail ) = self::splitTrail( $trail );
00950 $style = $this->getInternalLinkAttributesObj( $title, $text, 'new' );
00951 wfProfileOut( __METHOD__ );
00952 return '<a href="' . $upload->escapeLocalUrl( $q ) . '"'
00953 . $style . '>' . $prefix . $text . $inside . '</a>' . $trail;
00954 } else {
00955 wfProfileOut( __METHOD__ );
00956 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
00957 }
00958 } else {
00959 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
00960 }
00961 }
00962
00964 function makeMediaLink( $name, $unused = '', $text = '', $time = false ) {
00965 $nt = Title::makeTitleSafe( NS_FILE, $name );
00966 return $this->makeMediaLinkObj( $nt, $text, $time );
00967 }
00968
00980 function makeMediaLinkObj( $title, $text = '', $time = false ) {
00981 if( is_null( $title ) ) {
00982 ### HOTFIX. Instead of breaking, return empty string.
00983 return $text;
00984 } else {
00985 $img = wfFindFile( $title, $time );
00986 if( $img ) {
00987 $url = $img->getURL();
00988 $class = 'internal';
00989 } else {
00990 $upload = SpecialPage::getTitleFor( 'Upload' );
00991 $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $title->getDBkey() ) );
00992 $class = 'new';
00993 }
00994 $alt = htmlspecialchars( $title->getText() );
00995 if( $text == '' ) {
00996 $text = $alt;
00997 }
00998 $u = htmlspecialchars( $url );
00999 return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\">{$text}</a>";
01000 }
01001 }
01002
01004 function specialLink( $name, $key = '' ) {
01005 global $wgContLang;
01006
01007 if ( '' == $key ) { $key = strtolower( $name ); }
01008 $pn = $wgContLang->ucfirst( $name );
01009 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
01010 wfMsg( $key ) );
01011 }
01012
01029 function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) {
01030 $attribsText = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
01031 $url = htmlspecialchars( $url );
01032 if( $escape ) {
01033 $text = htmlspecialchars( $text );
01034 }
01035 $link = '';
01036 $success = wfRunHooks('LinkerMakeExternalLink', array( &$url, &$text, &$link, &$attribs, $linktype ) );
01037 if(!$success) {
01038 wfDebug("Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}\n", true);
01039 return $link;
01040 }
01041 if ( $attribs ) {
01042 $attribsText .= Xml::expandAttributes( $attribs );
01043 }
01044 return '<a href="'.$url.'"'.$attribsText.'>'.$text.'</a>';
01045 }
01046
01054 function userLink( $userId, $userText ) {
01055 if( $userId == 0 ) {
01056 $page = SpecialPage::getTitleFor( 'Contributions', $userText );
01057 } else {
01058 $page = Title::makeTitle( NS_USER, $userText );
01059 }
01060 return $this->link( $page, htmlspecialchars( $userText ), array( 'class' => 'mw-userlink' ) );
01061 }
01062
01073 public function userToolLinks( $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits=null ) {
01074 global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans, $wgLang;
01075 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
01076 $blockable = ( $wgSysopUserBans || 0 == $userId ) && !$flags & self::TOOL_LINKS_NOBLOCK;
01077
01078 $items = array();
01079 if( $talkable ) {
01080 $items[] = $this->userTalkLink( $userId, $userText );
01081 }
01082 if( $userId ) {
01083
01084 $attribs = array();
01085 if( $redContribsWhenNoEdits ) {
01086 $count = !is_null($edits) ? $edits : User::edits( $userId );
01087 if( $count == 0 ) {
01088 $attribs['class'] = 'new';
01089 }
01090 }
01091 $contribsPage = SpecialPage::getTitleFor( 'Contributions', $userText );
01092
01093 $items[] = $this->link( $contribsPage, wfMsgHtml( 'contribslink' ), $attribs );
01094 }
01095 if( $blockable && $wgUser->isAllowed( 'block' ) ) {
01096 $items[] = $this->blockLink( $userId, $userText );
01097 }
01098
01099 if( $items ) {
01100 return ' <span class="mw-usertoollinks">(' . $wgLang->pipeList( $items ) . ')</span>';
01101 } else {
01102 return '';
01103 }
01104 }
01105
01112 public function userToolLinksRedContribs( $userId, $userText, $edits=null ) {
01113 return $this->userToolLinks( $userId, $userText, true, 0, $edits );
01114 }
01115
01116
01123 function userTalkLink( $userId, $userText ) {
01124 $userTalkPage = Title::makeTitle( NS_USER_TALK, $userText );
01125 $userTalkLink = $this->link( $userTalkPage, wfMsgHtml( 'talkpagelinktext' ) );
01126 return $userTalkLink;
01127 }
01128
01135 function blockLink( $userId, $userText ) {
01136 $blockPage = SpecialPage::getTitleFor( 'Blockip', $userText );
01137 $blockLink = $this->link( $blockPage, wfMsgHtml( 'blocklink' ) );
01138 return $blockLink;
01139 }
01140
01147 function revUserLink( $rev, $isPublic = false ) {
01148 if( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
01149 $link = wfMsgHtml( 'rev-deleted-user' );
01150 } else if( $rev->userCan( Revision::DELETED_USER ) ) {
01151 $link = $this->userLink( $rev->getUser( Revision::FOR_THIS_USER ),
01152 $rev->getUserText( Revision::FOR_THIS_USER ) );
01153 } else {
01154 $link = wfMsgHtml( 'rev-deleted-user' );
01155 }
01156 if( $rev->isDeleted( Revision::DELETED_USER ) ) {
01157 return '<span class="history-deleted">' . $link . '</span>';
01158 }
01159 return $link;
01160 }
01161
01168 function revUserTools( $rev, $isPublic = false ) {
01169 if( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
01170 $link = wfMsgHtml( 'rev-deleted-user' );
01171 } else if( $rev->userCan( Revision::DELETED_USER ) ) {
01172 $userId = $rev->getUser( Revision::FOR_THIS_USER );
01173 $userText = $rev->getUserText( Revision::FOR_THIS_USER );
01174 $link = $this->userLink( $userId, $userText ) .
01175 ' ' . $this->userToolLinks( $userId, $userText );
01176 } else {
01177 $link = wfMsgHtml( 'rev-deleted-user' );
01178 }
01179 if( $rev->isDeleted( Revision::DELETED_USER ) ) {
01180 return ' <span class="history-deleted">' . $link . '</span>';
01181 }
01182 return $link;
01183 }
01184
01201 function formatComment($comment, $title = NULL, $local = false) {
01202 wfProfileIn( __METHOD__ );
01203
01204 # Sanitize text a bit:
01205 $comment = str_replace( "\n", " ", $comment );
01206 # Allow HTML entities (for bug 13815)
01207 $comment = Sanitizer::escapeHtmlAllowEntities( $comment );
01208
01209 # Render autocomments and make links:
01210 $comment = $this->formatAutoComments( $comment, $title, $local );
01211 $comment = $this->formatLinksInComment( $comment );
01212
01213 wfProfileOut( __METHOD__ );
01214 return $comment;
01215 }
01216
01230 private function formatAutocomments( $comment, $title = null, $local = false ) {
01231
01232 $this->autocommentTitle = $title;
01233 $this->autocommentLocal = $local;
01234 $comment = preg_replace_callback(
01235 '!(.*)/\*\s*(.*?)\s*\*/(.*)!',
01236 array( $this, 'formatAutocommentsCallback' ),
01237 $comment );
01238 unset( $this->autocommentTitle );
01239 unset( $this->autocommentLocal );
01240 return $comment;
01241 }
01242
01243 private function formatAutocommentsCallback( $match ) {
01244 $title = $this->autocommentTitle;
01245 $local = $this->autocommentLocal;
01246
01247 $pre=$match[1];
01248 $auto=$match[2];
01249 $post=$match[3];
01250 $link='';
01251 if( $title ) {
01252 $section = $auto;
01253
01254 # Generate a valid anchor name from the section title.
01255 # Hackish, but should generally work - we strip wiki
01256 # syntax, including the magic [[: that is used to
01257 # "link rather than show" in case of images and
01258 # interlanguage links.
01259 $section = str_replace( '[[:', '', $section );
01260 $section = str_replace( '[[', '', $section );
01261 $section = str_replace( ']]', '', $section );
01262 if ( $local ) {
01263 $sectionTitle = Title::newFromText( '#' . $section );
01264 } else {
01265 $sectionTitle = Title::makeTitleSafe( $title->getNamespace(),
01266 $title->getDBkey(), $section );
01267 }
01268 if ( $sectionTitle ) {
01269 $link = $this->link( $sectionTitle,
01270 wfMsgForContent( 'sectionlink' ), array(), array(),
01271 'noclasses' );
01272 } else {
01273 $link = '';
01274 }
01275 }
01276 $auto = "$link$auto";
01277 if( $pre ) {
01278 # written summary $presep autocomment (summary )
01279 $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
01280 }
01281 if( $post ) {
01282 # autocomment $postsep written summary ( summary)
01283 $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
01284 }
01285 $auto = '<span class="autocomment">' . $auto . '</span>';
01286 $comment = $pre . $auto . $post;
01287 return $comment;
01288 }
01289
01298 public function formatLinksInComment( $comment ) {
01299 return preg_replace_callback(
01300 '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
01301 array( $this, 'formatLinksInCommentCallback' ),
01302 $comment );
01303 }
01304
01305 protected function formatLinksInCommentCallback( $match ) {
01306 global $wgContLang;
01307
01308 $medians = '(?:' . preg_quote( MWNamespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
01309 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA ), '/' ) . '):';
01310
01311 $comment = $match[0];
01312
01313 # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
01314 if( strpos( $match[1], '%' ) !== false ) {
01315 $match[1] = str_replace( array('<', '>'), array('<', '>'), urldecode($match[1]) );
01316 }
01317
01318 # Handle link renaming [[foo|text]] will show link as "text"
01319 if( "" != $match[3] ) {
01320 $text = $match[3];
01321 } else {
01322 $text = $match[1];
01323 }
01324 $submatch = array();
01325 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
01326 # Media link; trail not supported.
01327 $linkRegexp = '/\[\[(.*?)\]\]/';
01328 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
01329 } else {
01330 # Other kind of link
01331 if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
01332 $trail = $submatch[1];
01333 } else {
01334 $trail = "";
01335 }
01336 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
01337 if (isset($match[1][0]) && $match[1][0] == ':')
01338 $match[1] = substr($match[1], 1);
01339 $thelink = $this->makeLink( $match[1], $text, "", $trail );
01340 }
01341 $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 );
01342
01343 return $comment;
01344 }
01345
01356 function commentBlock( $comment, $title = NULL, $local = false ) {
01357
01358
01359
01360 if( $comment == '' || $comment == '*' ) {
01361 return '';
01362 } else {
01363 $formatted = $this->formatComment( $comment, $title, $local );
01364 return " <span class=\"comment\">($formatted)</span>";
01365 }
01366 }
01367
01377 function revComment( Revision $rev, $local = false, $isPublic = false ) {
01378 if( $rev->isDeleted( Revision::DELETED_COMMENT ) && $isPublic ) {
01379 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
01380 } else if( $rev->userCan( Revision::DELETED_COMMENT ) ) {
01381 $block = $this->commentBlock( $rev->getComment( Revision::FOR_THIS_USER ),
01382 $rev->getTitle(), $local );
01383 } else {
01384 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
01385 }
01386 if( $rev->isDeleted( Revision::DELETED_COMMENT ) ) {
01387 return " <span class=\"history-deleted\">$block</span>";
01388 }
01389 return $block;
01390 }
01391
01392 public function formatRevisionSize( $size ) {
01393 if ( $size == 0 ) {
01394 $stxt = wfMsgExt( 'historyempty', 'parsemag' );
01395 } else {
01396 global $wgLang;
01397 $stxt = wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $size ) );
01398 $stxt = "($stxt)";
01399 }
01400 $stxt = htmlspecialchars( $stxt );
01401 return "<span class=\"history-size\">$stxt</span>";
01402 }
01403
01405 function tocIndent() {
01406 return "\n<ul>";
01407 }
01408
01410 function tocUnindent($level) {
01411 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ? $level : 0 );
01412 }
01413
01417 function tocLine( $anchor, $tocline, $tocnumber, $level ) {
01418 return "\n<li class=\"toclevel-$level\"><a href=\"#" .
01419 $anchor . '"><span class="tocnumber">' .
01420 $tocnumber . '</span> <span class="toctext">' .
01421 $tocline . '</span></a>';
01422 }
01423
01425 function tocLineEnd() {
01426 return "</li>\n";
01427 }
01428
01430 function tocList($toc) {
01431 global $wgJsMimeType;
01432 $title = wfMsgHtml('toc') ;
01433 return
01434 '<table id="toc" class="toc" summary="' . $title .'"><tr><td>'
01435 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
01436 . $toc
01437 # no trailing newline, script should not be wrapped in a
01438 # paragraph
01439 . "</ul>\n</td></tr></table>"
01440 . '<script type="' . $wgJsMimeType . '">'
01441 . ' if (window.showTocToggle) {'
01442 . ' var tocShowText = "' . Xml::escapeJsString( wfMsg('showtoc') ) . '";'
01443 . ' var tocHideText = "' . Xml::escapeJsString( wfMsg('hidetoc') ) . '";'
01444 . ' showTocToggle();'
01445 . ' } '
01446 . "</script>\n";
01447 }
01448
01456 public function editSectionLinkForOther( $title, $section ) {
01457 wfDeprecated( __METHOD__ );
01458 $title = Title::newFromText( $title );
01459 return $this->doEditSectionLink( $title, $section );
01460 }
01461
01467 public function editSectionLink( Title $nt, $section, $hint = '' ) {
01468 wfDeprecated( __METHOD__ );
01469 if( $hint === '' ) {
01470 # No way to pass an actual empty $hint here! The new interface al-
01471 # lows this, so we have to do this for compatibility.
01472 $hint = null;
01473 }
01474 return $this->doEditSectionLink( $nt, $section, $hint );
01475 }
01476
01489 public function doEditSectionLink( Title $nt, $section, $tooltip = null ) {
01490 $attribs = array();
01491 if( !is_null( $tooltip ) ) {
01492 $attribs['title'] = wfMsg( 'editsectionhint', $tooltip );
01493 }
01494 $link = $this->link( $nt, wfMsg('editsection'),
01495 $attribs,
01496 array( 'action' => 'edit', 'section' => $section ),
01497 array( 'noclasses', 'known' )
01498 );
01499
01500 # Run the old hook. This takes up half of the function . . . hopefully
01501 # we can rid of it someday.
01502 $attribs = '';
01503 if( $tooltip ) {
01504 $attribs = wfMsgHtml( 'editsectionhint', htmlspecialchars( $tooltip ) );
01505 $attribs = " title=\"$attribs\"";
01506 }
01507 $result = null;
01508 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result ) );
01509 if( !is_null( $result ) ) {
01510 # For reverse compatibility, add the brackets *after* the hook is
01511 # run, and even add them to hook-provided text. (This is the main
01512 # reason that the EditSectionLink hook is deprecated in favor of
01513 # DoEditSectionLink: it can't change the brackets or the span.)
01514 $result = wfMsgHtml( 'editsection-brackets', $result );
01515 return "<span class=\"editsection\">$result</span>";
01516 }
01517
01518 # Add the brackets and the span, and *then* run the nice new hook, with
01519 # clean and non-redundant arguments.
01520 $result = wfMsgHtml( 'editsection-brackets', $link );
01521 $result = "<span class=\"editsection\">$result</span>";
01522
01523 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result ) );
01524 return $result;
01525 }
01526
01541 public function makeHeadline( $level, $attribs, $anchor, $text, $link, $legacyAnchor = false ) {
01542 $ret = "<a name=\"$anchor\" id=\"$anchor\"></a>"
01543 . "<h$level$attribs"
01544 . $link
01545 . " <span class=\"mw-headline\">$text</span>"
01546 . "</h$level>";
01547 if ( $legacyAnchor !== false ) {
01548 $ret = "<a name=\"$legacyAnchor\" id=\"$legacyAnchor\"></a>$ret";
01549 }
01550 return $ret;
01551 }
01552
01559 static function splitTrail( $trail ) {
01560 static $regex = false;
01561 if ( $regex === false ) {
01562 global $wgContLang;
01563 $regex = $wgContLang->linkTrail();
01564 }
01565 $inside = '';
01566 if ( '' != $trail ) {
01567 $m = array();
01568 if ( preg_match( $regex, $trail, $m ) ) {
01569 $inside = $m[1];
01570 $trail = $m[2];
01571 }
01572 }
01573 return array( $inside, $trail );
01574 }
01575
01589 function generateRollback( $rev ) {
01590 return '<span class="mw-rollback-link">['
01591 . $this->buildRollbackLink( $rev )
01592 . ']</span>';
01593 }
01594
01601 public function buildRollbackLink( $rev ) {
01602 global $wgRequest, $wgUser;
01603 $title = $rev->getTitle();
01604 $query = array(
01605 'action' => 'rollback',
01606 'from' => $rev->getUserText()
01607 );
01608 if( $wgRequest->getBool( 'bot' ) ) {
01609 $query['bot'] = '1';
01610 $query['hidediff'] = '1';
01611 }
01612 $query['token'] = $wgUser->editToken( array( $title->getPrefixedText(),
01613 $rev->getUserText() ) );
01614 return $this->link( $title, wfMsgHtml( 'rollbacklink' ),
01615 array( 'title' => wfMsg( 'tooltip-rollback' ) ),
01616 $query, array( 'known', 'noclasses' ) );
01617 }
01618
01628 public function formatTemplates( $templates, $preview = false, $section = false ) {
01629 wfProfileIn( __METHOD__ );
01630
01631 $outText = '';
01632 if ( count( $templates ) > 0 ) {
01633 # Do a batch existence check
01634 $batch = new LinkBatch;
01635 foreach( $templates as $title ) {
01636 $batch->addObj( $title );
01637 }
01638 $batch->execute();
01639
01640 # Construct the HTML
01641 $outText = '<div class="mw-templatesUsedExplanation">';
01642 if ( $preview ) {
01643 $outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ) );
01644 } elseif ( $section ) {
01645 $outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ) );
01646 } else {
01647 $outText .= wfMsgExt( 'templatesused', array( 'parse' ) );
01648 }
01649 $outText .= "</div><ul>\n";
01650
01651 usort( $templates, array( 'Title', 'compare' ) );
01652 foreach ( $templates as $titleObj ) {
01653 $r = $titleObj->getRestrictions( 'edit' );
01654 if ( in_array( 'sysop', $r ) ) {
01655 $protected = wfMsgExt( 'template-protected', array( 'parseinline' ) );
01656 } elseif ( in_array( 'autoconfirmed', $r ) ) {
01657 $protected = wfMsgExt( 'template-semiprotected', array( 'parseinline' ) );
01658 } else {
01659 $protected = '';
01660 }
01661 if( $titleObj->quickUserCan( 'edit' ) ) {
01662 $editLink = $this->makeLinkObj( $titleObj, wfMsg('editlink'), 'action=edit' );
01663 } else {
01664 $editLink = $this->makeLinkObj( $titleObj, wfMsg('viewsourcelink'), 'action=edit' );
01665 }
01666 $outText .= '<li>' . $this->link( $titleObj ) . ' (' . $editLink . ') ' . $protected . '</li>';
01667 }
01668 $outText .= '</ul>';
01669 }
01670 wfProfileOut( __METHOD__ );
01671 return $outText;
01672 }
01673
01681 public function formatHiddenCategories( $hiddencats ) {
01682 global $wgLang;
01683 wfProfileIn( __METHOD__ );
01684
01685 $outText = '';
01686 if ( count( $hiddencats ) > 0 ) {
01687 # Construct the HTML
01688 $outText = '<div class="mw-hiddenCategoriesExplanation">';
01689 $outText .= wfMsgExt( 'hiddencategories', array( 'parse' ), $wgLang->formatnum( count( $hiddencats ) ) );
01690 $outText .= "</div><ul>\n";
01691
01692 foreach ( $hiddencats as $titleObj ) {
01693 $outText .= '<li>' . $this->link( $titleObj, null, array(), array(), 'known' ) . "</li>\n"; # If it's hidden, it must exist - no need to check with a LinkBatch
01694 }
01695 $outText .= '</ul>';
01696 }
01697 wfProfileOut( __METHOD__ );
01698 return $outText;
01699 }
01700
01708 public function formatSize( $size ) {
01709 global $wgLang;
01710 return htmlspecialchars( $wgLang->formatSize( $size ) );
01711 }
01712
01716 public function tooltipAndAccesskey( $name ) {
01717 # FIXME: If Sanitizer::expandAttributes() treated "false" as "output
01718 # no attribute" instead of "output '' as value for attribute", this
01719 # would be three lines.
01720 $attribs = array(
01721 'title' => $this->titleAttrib( $name, 'withaccess' ),
01722 'accesskey' => $this->accesskey( $name )
01723 );
01724 if ( $attribs['title'] === false ) {
01725 unset( $attribs['title'] );
01726 }
01727 if ( $attribs['accesskey'] === false ) {
01728 unset( $attribs['accesskey'] );
01729 }
01730 return Xml::expandAttributes( $attribs );
01731 }
01732
01734 public function tooltip( $name, $options = null ) {
01735 # FIXME: If Sanitizer::expandAttributes() treated "false" as "output
01736 # no attribute" instead of "output '' as value for attribute", this
01737 # would be two lines.
01738 $tooltip = $this->titleAttrib( $name, $options );
01739 if ( $tooltip === false ) {
01740 return '';
01741 }
01742 return Xml::expandAttributes( array(
01743 'title' => $this->titleAttrib( $name, $options )
01744 ) );
01745 }
01746
01759 public function titleAttrib( $name, $options = null ) {
01760 wfProfileIn( __METHOD__ );
01761
01762 $tooltip = wfMsg( "tooltip-$name" );
01763 # Compatibility: formerly some tooltips had [alt-.] hardcoded
01764 $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
01765
01766 # Message equal to '-' means suppress it.
01767 if ( wfEmptyMsg( "tooltip-$name", $tooltip ) || $tooltip == '-' ) {
01768 $tooltip = false;
01769 }
01770
01771 if ( $options == 'withaccess' ) {
01772 $accesskey = $this->accesskey( $name );
01773 if( $accesskey !== false ) {
01774 if ( $tooltip === false || $tooltip === '' ) {
01775 $tooltip = "[$accesskey]";
01776 } else {
01777 $tooltip .= " [$accesskey]";
01778 }
01779 }
01780 }
01781
01782 wfProfileOut( __METHOD__ );
01783 return $tooltip;
01784 }
01785
01796 public function accesskey( $name ) {
01797 wfProfileIn( __METHOD__ );
01798
01799 $accesskey = wfMsg( "accesskey-$name" );
01800
01801 # FIXME: Per standard MW behavior, a value of '-' means to suppress the
01802 # attribute, but this is broken for accesskey: that might be a useful
01803 # value.
01804 if( $accesskey != '' && $accesskey != '-' && !wfEmptyMsg( "accesskey-$name", $accesskey ) ) {
01805 wfProfileOut( __METHOD__ );
01806 return $accesskey;
01807 }
01808
01809 wfProfileOut( __METHOD__ );
01810 return false;
01811 }
01812
01822 public function revDeleteLink( $query = array(), $restricted = false ) {
01823 $sp = SpecialPage::getTitleFor( 'Revisiondelete' );
01824 $text = wfMsgHtml( 'rev-delundel' );
01825 $tag = $restricted ? 'strong' : 'span';
01826 $link = $this->link( $sp, $text, array(), $query, array( 'known', 'noclasses' ) );
01827 return Xml::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), "($link)" );
01828 }
01829 }