00001 <?php
00011 class Linker {
00012
00016 const TOOL_LINKS_NOBLOCK = 1;
00017
00018 function __construct() {}
00019
00027 function getExternalLinkAttributes( $class = 'external' ) {
00028 return $this->getLinkAttributesInternal( '', $class );
00029 }
00030
00041 function getInterwikiLinkAttributes( $title, $unused = null, $class = 'external' ) {
00042 global $wgContLang;
00043
00044 # FIXME: We have a whole bunch of handling here that doesn't happen in
00045 # getExternalLinkAttributes, why?
00046 $title = urldecode( $title );
00047 $title = $wgContLang->checkTitleEncoding( $title );
00048 $title = preg_replace( '/[\\x00-\\x1f]/', ' ', $title );
00049
00050 return $this->getLinkAttributesInternal( $title, $class );
00051 }
00052
00062 function getInternalLinkAttributes( $title, $unused = null, $class='' ) {
00063 $title = urldecode( $title );
00064 $title = str_replace( '_', ' ', $title );
00065 return $this->getLinkAttributesInternal( $title, $class );
00066 }
00067
00078 function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) {
00079 if( $title === false ) {
00080 $title = $nt->getPrefixedText();
00081 }
00082 return $this->getLinkAttributesInternal( $title, $class );
00083 }
00084
00088 private function getLinkAttributesInternal( $title, $class ) {
00089 $title = htmlspecialchars( $title );
00090 $class = htmlspecialchars( $class );
00091 $r = '';
00092 if ( $class != '' ) {
00093 $r .= " class=\"$class\"";
00094 }
00095 if ( $title != '') {
00096 $r .= " title=\"$title\"";
00097 }
00098 return $r;
00099 }
00100
00108 function getLinkColour( $t, $threshold ) {
00109 $colour = '';
00110 if ( $t->isRedirect() ) {
00111 # Page is a redirect
00112 $colour = 'mw-redirect';
00113 } elseif ( $threshold > 0 &&
00114 $t->exists() && $t->getLength() < $threshold &&
00115 MWNamespace::isContent( $t->getNamespace() ) ) {
00116 # Page is a stub
00117 $colour = 'stub';
00118 }
00119 return $colour;
00120 }
00121
00159 public function link( $target, $text = null, $customAttribs = array(), $query = array(), $options = array() ) {
00160 wfProfileIn( __METHOD__ );
00161 if( !$target instanceof Title ) {
00162 return "<!-- ERROR -->$text";
00163 }
00164 $options = (array)$options;
00165
00166 $ret = null;
00167 if( !wfRunHooks( 'LinkBegin', array( $this, $target, &$text,
00168 &$customAttribs, &$query, &$options, &$ret ) ) ) {
00169 wfProfileOut( __METHOD__ );
00170 return $ret;
00171 }
00172
00173 # Normalize the Title if it's a special page
00174 $target = $this->normaliseSpecialPage( $target );
00175
00176 # If we don't know whether the page exists, let's find out.
00177 wfProfileIn( __METHOD__ . '-checkPageExistence' );
00178 if( !in_array( 'known', $options ) and !in_array( 'broken', $options ) ) {
00179 if( $target->isKnown() ) {
00180 $options []= 'known';
00181 } else {
00182 $options []= 'broken';
00183 }
00184 }
00185 wfProfileOut( __METHOD__ . '-checkPageExistence' );
00186
00187 $oldquery = array();
00188 if( in_array( "forcearticlepath", $options ) && $query ){
00189 $oldquery = $query;
00190 $query = array();
00191 }
00192
00193 # Note: we want the href attribute first, for prettiness.
00194 $attribs = array( 'href' => $this->linkUrl( $target, $query, $options ) );
00195 if( in_array( 'forcearticlepath', $options ) && $oldquery ){
00196 $attribs['href'] = wfAppendQuery( $attribs['href'], wfArrayToCgi( $oldquery ) );
00197 }
00198
00199 $attribs = array_merge(
00200 $attribs,
00201 $this->linkAttribs( $target, $customAttribs, $options )
00202 );
00203 if( is_null( $text ) ) {
00204 $text = $this->linkText( $target );
00205 }
00206
00207 $ret = null;
00208 if( wfRunHooks( 'LinkEnd', array( $this, $target, $options, &$text, &$attribs, &$ret ) ) ) {
00209 $ret = Html::rawElement( 'a', $attribs, $text );
00210 }
00211
00212 wfProfileOut( __METHOD__ );
00213 return $ret;
00214 }
00215
00219 public function linkKnown( $target, $text = null, $customAttribs = array(), $query = array(), $options = array('known','noclasses') ) {
00220 return $this->link( $target, $text, $customAttribs, $query, $options );
00221 }
00222
00226 private function linkUrl( $target, $query, $options ) {
00227 wfProfileIn( __METHOD__ );
00228 # We don't want to include fragments for broken links, because they
00229 # generally make no sense.
00230 if( in_array( 'broken', $options ) and $target->mFragment !== '' ) {
00231 $target = clone $target;
00232 $target->mFragment = '';
00233 }
00234
00235 # If it's a broken link, add the appropriate query pieces, unless
00236 # there's already an action specified, or unless 'edit' makes no sense
00237 # (i.e., for a nonexistent special page).
00238 if( in_array( 'broken', $options ) and empty( $query['action'] )
00239 and $target->getNamespace() != NS_SPECIAL ) {
00240 $query['action'] = 'edit';
00241 $query['redlink'] = '1';
00242 }
00243 $ret = $target->getLinkUrl( $query );
00244 wfProfileOut( __METHOD__ );
00245 return $ret;
00246 }
00247
00251 private function linkAttribs( $target, $attribs, $options ) {
00252 wfProfileIn( __METHOD__ );
00253 global $wgUser;
00254 $defaults = array();
00255
00256 if( !in_array( 'noclasses', $options ) ) {
00257 wfProfileIn( __METHOD__ . '-getClasses' );
00258 # Now build the classes.
00259 $classes = array();
00260
00261 if( in_array( 'broken', $options ) ) {
00262 $classes[] = 'new';
00263 }
00264
00265 if( $target->isExternal() ) {
00266 $classes[] = 'extiw';
00267 }
00268
00269 # Note that redirects never count as stubs here.
00270 if ( !in_array( 'broken', $options ) && $target->isRedirect() ) {
00271 $classes[] = 'mw-redirect';
00272 } elseif( $target->isContentPage() ) {
00273 # Check for stub.
00274 $threshold = $wgUser->getOption( 'stubthreshold' );
00275 if( $threshold > 0 and $target->exists() and $target->getLength() < $threshold ) {
00276 $classes[] = 'stub';
00277 }
00278 }
00279 if( $classes != array() ) {
00280 $defaults['class'] = implode( ' ', $classes );
00281 }
00282 wfProfileOut( __METHOD__ . '-getClasses' );
00283 }
00284
00285 # Get a default title attribute.
00286 if( $target->getPrefixedText() == '' ) {
00287 # A link like [[#Foo]]. This used to mean an empty title
00288 # attribute, but that's silly. Just don't output a title.
00289 } elseif( in_array( 'known', $options ) ) {
00290 $defaults['title'] = $target->getPrefixedText();
00291 } else {
00292 $defaults['title'] = wfMsg( 'red-link-title', $target->getPrefixedText() );
00293 }
00294
00295 # Finally, merge the custom attribs with the default ones, and iterate
00296 # over that, deleting all "false" attributes.
00297 $ret = array();
00298 $merged = Sanitizer::mergeAttributes( $defaults, $attribs );
00299 foreach( $merged as $key => $val ) {
00300 # A false value suppresses the attribute, and we don't want the
00301 # href attribute to be overridden.
00302 if( $key != 'href' and $val !== false ) {
00303 $ret[$key] = $val;
00304 }
00305 }
00306 wfProfileOut( __METHOD__ );
00307 return $ret;
00308 }
00309
00313 private function linkText( $target ) {
00314 # We might be passed a non-Title by make*LinkObj(). Fail gracefully.
00315 if( !$target instanceof Title ) {
00316 return '';
00317 }
00318
00319 # If the target is just a fragment, with no title, we return the frag-
00320 # ment text. Otherwise, we return the title text itself.
00321 if( $target->getPrefixedText() === '' and $target->getFragment() !== '' ) {
00322 return htmlspecialchars( $target->getFragment() );
00323 }
00324 return htmlspecialchars( $target->getPrefixedText() );
00325 }
00326
00339 function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
00340 global $wgUser;
00341 $threshold = intval( $wgUser->getOption( 'stubthreshold' ) );
00342 $colour = ( $size < $threshold ) ? 'stub' : '';
00343
00344 return $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
00345 }
00346
00352 function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
00353 if ( $text == '' ) {
00354 $text = htmlspecialchars( $nt->getPrefixedText() );
00355 }
00356 list( $inside, $trail ) = Linker::splitTrail( $trail );
00357 return "<strong class=\"selflink\">{$prefix}{$text}{$inside}</strong>{$trail}";
00358 }
00359
00360 function normaliseSpecialPage( Title $title ) {
00361 if ( $title->getNamespace() == NS_SPECIAL ) {
00362 list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $title->getDBkey() );
00363 if ( !$name ) return $title;
00364 $ret = SpecialPage::getTitleFor( $name, $subpage );
00365 $ret->mFragment = $title->getFragment();
00366 return $ret;
00367 } else {
00368 return $title;
00369 }
00370 }
00371
00376 function fnamePart( $url ) {
00377 $basename = strrchr( $url, '/' );
00378 if ( false === $basename ) {
00379 $basename = $url;
00380 } else {
00381 $basename = substr( $basename, 1 );
00382 }
00383 return $basename;
00384 }
00385
00390 function makeExternalImage( $url, $alt = '' ) {
00391 if ( $alt == '' ) {
00392 $alt = $this->fnamePart( $url );
00393 }
00394 $img = '';
00395 $success = wfRunHooks('LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
00396 if(!$success) {
00397 wfDebug("Hook LinkerMakeExternalImage changed the output of external image with url {$url} and alt text {$alt} to {$img}\n", true);
00398 return $img;
00399 }
00400 return Html::element( 'img',
00401 array(
00402 'src' => $url,
00403 'alt' => $alt ) );
00404 }
00405
00438 function makeImageLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
00439 $res = null;
00440 if( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$this, &$title,
00441 &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
00442 return $res;
00443 }
00444
00445 global $wgContLang, $wgUser, $wgThumbLimits, $wgThumbUpright;
00446 if ( $file && !$file->allowInlineDisplay() ) {
00447 wfDebug( __METHOD__.': '.$title->getPrefixedDBkey()." does not allow inline display\n" );
00448 return $this->link( $title );
00449 }
00450
00451
00452 $fp =& $frameParams;
00453 $hp =& $handlerParams;
00454
00455
00456 $page = isset( $hp['page'] ) ? $hp['page'] : false;
00457 if ( !isset( $fp['align'] ) ) $fp['align'] = '';
00458 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
00459 if ( !isset( $fp['title'] ) ) $fp['title'] = '';
00460
00461 $prefix = $postfix = '';
00462
00463 if ( 'center' == $fp['align'] ) {
00464 $prefix = '<div class="center">';
00465 $postfix = '</div>';
00466 $fp['align'] = 'none';
00467 }
00468 if ( $file && !isset( $hp['width'] ) ) {
00469 $hp['width'] = $file->getWidth( $page );
00470
00471 if( isset( $fp['thumbnail'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) || !$hp['width'] ) {
00472 $wopt = $wgUser->getOption( 'thumbsize' );
00473
00474 if( !isset( $wgThumbLimits[$wopt] ) ) {
00475 $wopt = User::getDefaultOption( 'thumbsize' );
00476 }
00477
00478
00479 if ( isset( $fp['upright'] ) && $fp['upright'] == 0 ) {
00480 $fp['upright'] = $wgThumbUpright;
00481 }
00482
00483
00484 $prefWidth = isset( $fp['upright'] ) ?
00485 round( $wgThumbLimits[$wopt] * $fp['upright'], -1 ) :
00486 $wgThumbLimits[$wopt];
00487 if ( $hp['width'] <= 0 || $prefWidth < $hp['width'] ) {
00488 $hp['width'] = $prefWidth;
00489 }
00490 }
00491 }
00492
00493 if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) ) {
00494 # Create a thumbnail. Alignment depends on language
00495 # writing direction, # right aligned for left-to-right-
00496 # languages ("Western languages"), left-aligned
00497 # for right-to-left-languages ("Semitic languages")
00498 #
00499 # If thumbnail width has not been provided, it is set
00500 # to the default user option as specified in Language*.php
00501 if ( $fp['align'] == '' ) {
00502 $fp['align'] = $wgContLang->alignEnd();
00503 }
00504 return $prefix.$this->makeThumbLink2( $title, $file, $fp, $hp, $time, $query ).$postfix;
00505 }
00506
00507 if ( $file && isset( $fp['frameless'] ) ) {
00508 $srcWidth = $file->getWidth( $page );
00509 # For "frameless" option: do not present an image bigger than the source (for bitmap-style images)
00510 # This is the same behaviour as the "thumb" option does it already.
00511 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
00512 $hp['width'] = $srcWidth;
00513 }
00514 }
00515
00516 if ( $file && $hp['width'] ) {
00517 # Create a resized image, without the additional thumbnail features
00518 $thumb = $file->transform( $hp );
00519 } else {
00520 $thumb = false;
00521 }
00522
00523 if ( !$thumb ) {
00524 $s = $this->makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time==true );
00525 } else {
00526 $params = array(
00527 'alt' => $fp['alt'],
00528 'title' => $fp['title'],
00529 'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false ,
00530 'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false );
00531 if ( !empty( $fp['link-url'] ) ) {
00532 $params['custom-url-link'] = $fp['link-url'];
00533 } elseif ( !empty( $fp['link-title'] ) ) {
00534 $params['custom-title-link'] = $fp['link-title'];
00535 } elseif ( !empty( $fp['no-link'] ) ) {
00536
00537 } else {
00538 $params['desc-link'] = true;
00539 $params['desc-query'] = $query;
00540 }
00541
00542 $s = $thumb->toHtml( $params );
00543 }
00544 if ( $fp['align'] != '' ) {
00545 $s = "<div class=\"float{$fp['align']}\">{$s}</div>";
00546 }
00547 return str_replace("\n", ' ',$prefix.$s.$postfix);
00548 }
00549
00555 function makeThumbLinkObj( Title $title, $file, $label = '', $alt, $align = 'right', $params = array(), $framed=false , $manualthumb = "" ) {
00556 $frameParams = array(
00557 'alt' => $alt,
00558 'caption' => $label,
00559 'align' => $align
00560 );
00561 if ( $framed ) $frameParams['framed'] = true;
00562 if ( $manualthumb ) $frameParams['manualthumb'] = $manualthumb;
00563 return $this->makeThumbLink2( $title, $file, $frameParams, $params );
00564 }
00565
00566 function makeThumbLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
00567 global $wgStylePath, $wgContLang;
00568 $exists = $file && $file->exists();
00569
00570 # Shortcuts
00571 $fp =& $frameParams;
00572 $hp =& $handlerParams;
00573
00574 $page = isset( $hp['page'] ) ? $hp['page'] : false;
00575 if ( !isset( $fp['align'] ) ) $fp['align'] = 'right';
00576 if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
00577 if ( !isset( $fp['title'] ) ) $fp['title'] = '';
00578 if ( !isset( $fp['caption'] ) ) $fp['caption'] = '';
00579
00580 if ( empty( $hp['width'] ) ) {
00581
00582 $hp['width'] = isset( $fp['upright'] ) ? 130 : 180;
00583 }
00584 $thumb = false;
00585
00586 if ( !$exists ) {
00587 $outerWidth = $hp['width'] + 2;
00588 } else {
00589 if ( isset( $fp['manualthumb'] ) ) {
00590 # Use manually specified thumbnail
00591 $manual_title = Title::makeTitleSafe( NS_FILE, $fp['manualthumb'] );
00592 if( $manual_title ) {
00593 $manual_img = wfFindFile( $manual_title );
00594 if ( $manual_img ) {
00595 $thumb = $manual_img->getUnscaledThumb();
00596 } else {
00597 $exists = false;
00598 }
00599 }
00600 } elseif ( isset( $fp['framed'] ) ) {
00601
00602 $thumb = $file->getUnscaledThumb( $page );
00603 } else {
00604 # Do not present an image bigger than the source, for bitmap-style images
00605 # This is a hack to maintain compatibility with arbitrary pre-1.10 behaviour
00606 $srcWidth = $file->getWidth( $page );
00607 if ( $srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth ) {
00608 $hp['width'] = $srcWidth;
00609 }
00610 $thumb = $file->transform( $hp );
00611 }
00612
00613 if ( $thumb ) {
00614 $outerWidth = $thumb->getWidth() + 2;
00615 } else {
00616 $outerWidth = $hp['width'] + 2;
00617 }
00618 }
00619
00620 # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
00621 # So we don't need to pass it here in $query. However, the URL for the
00622 # zoom icon still needs it, so we make a unique query for it. See bug 14771
00623 $url = $title->getLocalURL( $query );
00624 if( $page ) {
00625 $url = wfAppendQuery( $url, 'page=' . urlencode( $page ) );
00626 }
00627
00628 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
00629
00630 $s = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
00631 if( !$exists ) {
00632 $s .= $this->makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time==true );
00633 $zoomicon = '';
00634 } elseif ( !$thumb ) {
00635 $s .= htmlspecialchars( wfMsg( 'thumbnail_error', '' ) );
00636 $zoomicon = '';
00637 } else {
00638 $s .= $thumb->toHtml( array(
00639 'alt' => $fp['alt'],
00640 'title' => $fp['title'],
00641 'img-class' => 'thumbimage',
00642 'desc-link' => true,
00643 'desc-query' => $query ) );
00644 if ( isset( $fp['framed'] ) ) {
00645 $zoomicon="";
00646 } else {
00647 $zoomicon = '<div class="magnify">'.
00648 '<a href="'.$url.'" class="internal" title="'.$more.'">'.
00649 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
00650 'width="15" height="11" alt="" /></a></div>';
00651 }
00652 }
00653 $s .= ' <div class="thumbcaption">'.$zoomicon.$fp['caption']."</div></div></div>";
00654 return str_replace("\n", ' ', $s);
00655 }
00656
00668 public function makeBrokenImageLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '', $time = false ) {
00669 global $wgEnableUploads, $wgUploadNavigationUrl;
00670 if( $title instanceof Title ) {
00671 wfProfileIn( __METHOD__ );
00672 $currentExists = $time ? ( wfFindFile( $title ) != false ) : false;
00673 if( ( $wgUploadNavigationUrl || $wgEnableUploads ) && !$currentExists ) {
00674 if( $text == '' )
00675 $text = htmlspecialchars( $title->getPrefixedText() );
00676
00677 $redir = RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title );
00678 if( $redir ) {
00679 wfProfileOut( __METHOD__ );
00680 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
00681 }
00682
00683 $href = $this->getUploadUrl( $title, $query );
00684
00685
00686 list( $inside, $trail ) = self::splitTrail( $trail );
00687
00688 wfProfileOut( __METHOD__ );
00689 return Html::element( 'a', array(
00690 'href' => $href,
00691 'class' => 'new',
00692 'title' => $title->getPrefixedText()
00693 ), $prefix . $text . $inside ) . $trail;
00694 } else {
00695 wfProfileOut( __METHOD__ );
00696 return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
00697 }
00698 } else {
00699 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
00700 }
00701 }
00702
00710 protected function getUploadUrl( $destFile, $query = '' ) {
00711 global $wgUploadNavigationUrl;
00712 $q = 'wpDestFile=' . $destFile->getPartialUrl();
00713 if( $query != '' )
00714 $q .= '&' . $query;
00715
00716 if( $wgUploadNavigationUrl ) {
00717 return wfAppendQuery( $wgUploadNavigationUrl, $q );
00718 } else {
00719 $upload = SpecialPage::getTitleFor( 'Upload' );
00720 return $upload->getLocalUrl( $q );
00721 }
00722 }
00723
00735 function makeMediaLinkObj( $title, $text = '', $time = false ) {
00736 if( is_null( $title ) ) {
00737 ### HOTFIX. Instead of breaking, return empty string.
00738 return $text;
00739 } else {
00740 $img = wfFindFile( $title, array( 'time' => $time ) );
00741 if( $img ) {
00742 $url = $img->getURL();
00743 $class = 'internal';
00744 } else {
00745 $url = $this->getUploadUrl( $title );
00746 $class = 'new';
00747 }
00748 $alt = htmlspecialchars( $title->getText() );
00749 if( $text == '' ) {
00750 $text = $alt;
00751 }
00752 $u = htmlspecialchars( $url );
00753 return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\">{$text}</a>";
00754 }
00755 }
00756
00762 function specialLink( $name, $key = '' ) {
00763 global $wgContLang;
00764
00765 if ( $key == '' ) { $key = strtolower( $name ); }
00766 $pn = $wgContLang->ucfirst( $name );
00767 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
00768 wfMsg( $key ) );
00769 }
00770
00787 function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) {
00788 if ( isset( $attribs[ 'class' ] ) ) $class = $attribs[ 'class' ]; # yet another hack :(
00789 else $class = 'external ' . $linktype;
00790
00791 $attribsText = $this->getExternalLinkAttributes( $class );
00792 $url = htmlspecialchars( $url );
00793 if( $escape ) {
00794 $text = htmlspecialchars( $text );
00795 }
00796 $link = '';
00797 $success = wfRunHooks('LinkerMakeExternalLink', array( &$url, &$text, &$link, &$attribs, $linktype ) );
00798 if(!$success) {
00799 wfDebug("Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}\n", true);
00800 return $link;
00801 }
00802 if ( $attribs ) {
00803 $attribsText .= Html::expandAttributes( $attribs );
00804 }
00805 return '<a href="'.$url.'"'.$attribsText.'>'.$text.'</a>';
00806 }
00807
00815 function userLink( $userId, $userText ) {
00816 if( $userId == 0 ) {
00817 $page = SpecialPage::getTitleFor( 'Contributions', $userText );
00818 } else {
00819 $page = Title::makeTitle( NS_USER, $userText );
00820 }
00821 return $this->link( $page, htmlspecialchars( $userText ), array( 'class' => 'mw-userlink' ) );
00822 }
00823
00834 public function userToolLinks( $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits=null ) {
00835 global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans, $wgLang;
00836 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
00837 $blockable = ( $wgSysopUserBans || 0 == $userId ) && !$flags & self::TOOL_LINKS_NOBLOCK;
00838
00839 $items = array();
00840 if( $talkable ) {
00841 $items[] = $this->userTalkLink( $userId, $userText );
00842 }
00843 if( $userId ) {
00844
00845 $attribs = array();
00846 if( $redContribsWhenNoEdits ) {
00847 $count = !is_null($edits) ? $edits : User::edits( $userId );
00848 if( $count == 0 ) {
00849 $attribs['class'] = 'new';
00850 }
00851 }
00852 $contribsPage = SpecialPage::getTitleFor( 'Contributions', $userText );
00853
00854 $items[] = $this->link( $contribsPage, wfMsgHtml( 'contribslink' ), $attribs );
00855 }
00856 if( $blockable && $wgUser->isAllowed( 'block' ) ) {
00857 $items[] = $this->blockLink( $userId, $userText );
00858 }
00859
00860 if( $items ) {
00861 return ' <span class="mw-usertoollinks">(' . $wgLang->pipeList( $items ) . ')</span>';
00862 } else {
00863 return '';
00864 }
00865 }
00866
00873 public function userToolLinksRedContribs( $userId, $userText, $edits=null ) {
00874 return $this->userToolLinks( $userId, $userText, true, 0, $edits );
00875 }
00876
00877
00884 function userTalkLink( $userId, $userText ) {
00885 $userTalkPage = Title::makeTitle( NS_USER_TALK, $userText );
00886 $userTalkLink = $this->link( $userTalkPage, wfMsgHtml( 'talkpagelinktext' ) );
00887 return $userTalkLink;
00888 }
00889
00896 function blockLink( $userId, $userText ) {
00897 $blockPage = SpecialPage::getTitleFor( 'Blockip', $userText );
00898 $blockLink = $this->link( $blockPage, wfMsgHtml( 'blocklink' ) );
00899 return $blockLink;
00900 }
00901
00908 function revUserLink( $rev, $isPublic = false ) {
00909 if( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
00910 $link = wfMsgHtml( 'rev-deleted-user' );
00911 } else if( $rev->userCan( Revision::DELETED_USER ) ) {
00912 $link = $this->userLink( $rev->getUser( Revision::FOR_THIS_USER ),
00913 $rev->getUserText( Revision::FOR_THIS_USER ) );
00914 } else {
00915 $link = wfMsgHtml( 'rev-deleted-user' );
00916 }
00917 if( $rev->isDeleted( Revision::DELETED_USER ) ) {
00918 return '<span class="history-deleted">' . $link . '</span>';
00919 }
00920 return $link;
00921 }
00922
00929 function revUserTools( $rev, $isPublic = false ) {
00930 if( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
00931 $link = wfMsgHtml( 'rev-deleted-user' );
00932 } else if( $rev->userCan( Revision::DELETED_USER ) ) {
00933 $userId = $rev->getUser( Revision::FOR_THIS_USER );
00934 $userText = $rev->getUserText( Revision::FOR_THIS_USER );
00935 $link = $this->userLink( $userId, $userText ) .
00936 ' ' . $this->userToolLinks( $userId, $userText );
00937 } else {
00938 $link = wfMsgHtml( 'rev-deleted-user' );
00939 }
00940 if( $rev->isDeleted( Revision::DELETED_USER ) ) {
00941 return ' <span class="history-deleted">' . $link . '</span>';
00942 }
00943 return $link;
00944 }
00945
00962 function formatComment($comment, $title = null, $local = false) {
00963 wfProfileIn( __METHOD__ );
00964
00965 # Sanitize text a bit:
00966 $comment = str_replace( "\n", " ", $comment );
00967 # Allow HTML entities (for bug 13815)
00968 $comment = Sanitizer::escapeHtmlAllowEntities( $comment );
00969
00970 # Render autocomments and make links:
00971 $comment = $this->formatAutocomments( $comment, $title, $local );
00972 $comment = $this->formatLinksInComment( $comment, $title, $local );
00973
00974 wfProfileOut( __METHOD__ );
00975 return $comment;
00976 }
00977
00991 private function formatAutocomments( $comment, $title = null, $local = false ) {
00992
00993 $this->autocommentTitle = $title;
00994 $this->autocommentLocal = $local;
00995 $comment = preg_replace_callback(
00996 '!(.*)/\*\s*(.*?)\s*\*/(.*)!',
00997 array( $this, 'formatAutocommentsCallback' ),
00998 $comment );
00999 unset( $this->autocommentTitle );
01000 unset( $this->autocommentLocal );
01001 return $comment;
01002 }
01003
01004 private function formatAutocommentsCallback( $match ) {
01005 $title = $this->autocommentTitle;
01006 $local = $this->autocommentLocal;
01007
01008 $pre = $match[1];
01009 $auto = $match[2];
01010 $post = $match[3];
01011 $link = '';
01012 if ( $title ) {
01013 $section = $auto;
01014
01015 # Generate a valid anchor name from the section title.
01016 # Hackish, but should generally work - we strip wiki
01017 # syntax, including the magic [[: that is used to
01018 # "link rather than show" in case of images and
01019 # interlanguage links.
01020 $section = str_replace( '[[:', '', $section );
01021 $section = str_replace( '[[', '', $section );
01022 $section = str_replace( ']]', '', $section );
01023 if ( $local ) {
01024 $sectionTitle = Title::newFromText( '#' . $section );
01025 } else {
01026 $sectionTitle = Title::makeTitleSafe( $title->getNamespace(),
01027 $title->getDBkey(), $section );
01028 }
01029 if ( $sectionTitle ) {
01030 $link = $this->link( $sectionTitle,
01031 htmlspecialchars( wfMsgForContent( 'sectionlink' ) ), array(), array(),
01032 'noclasses' );
01033 } else {
01034 $link = '';
01035 }
01036 }
01037 $auto = "$link$auto";
01038 if( $pre ) {
01039 # written summary $presep autocomment (summary )
01040 $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
01041 }
01042 if( $post ) {
01043 # autocomment $postsep written summary ( summary)
01044 $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
01045 }
01046 $auto = '<span class="autocomment">' . $auto . '</span>';
01047 $comment = $pre . $auto . $post;
01048 return $comment;
01049 }
01050
01059 public function formatLinksInComment( $comment, $title = null, $local = false ) {
01060 $this->commentContextTitle = $title;
01061 $this->commentLocal = $local;
01062 $html = preg_replace_callback(
01063 '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
01064 array( $this, 'formatLinksInCommentCallback' ),
01065 $comment );
01066 unset( $this->commentContextTitle );
01067 unset( $this->commentLocal );
01068 return $html;
01069 }
01070
01071 protected function formatLinksInCommentCallback( $match ) {
01072 global $wgContLang;
01073
01074 $medians = '(?:' . preg_quote( MWNamespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
01075 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA ), '/' ) . '):';
01076
01077 $comment = $match[0];
01078
01079 # fix up urlencoded title texts (copied from Parser::replaceInternalLinks)
01080 if( strpos( $match[1], '%' ) !== false ) {
01081 $match[1] = str_replace( array('<', '>'), array('<', '>'), urldecode($match[1]) );
01082 }
01083
01084 # Handle link renaming [[foo|text]] will show link as "text"
01085 if( $match[3] != "" ) {
01086 $text = $match[3];
01087 } else {
01088 $text = $match[1];
01089 }
01090 $submatch = array();
01091 $thelink = null;
01092 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
01093 # Media link; trail not supported.
01094 $linkRegexp = '/\[\[(.*?)\]\]/';
01095 $title = Title::makeTitleSafe( NS_FILE, $submatch[1] );
01096 $thelink = $this->makeMediaLinkObj( $title, $text );
01097 } else {
01098 # Other kind of link
01099 if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
01100 $trail = $submatch[1];
01101 } else {
01102 $trail = "";
01103 }
01104 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
01105 if (isset($match[1][0]) && $match[1][0] == ':')
01106 $match[1] = substr($match[1], 1);
01107 list( $inside, $trail ) = Linker::splitTrail( $trail );
01108
01109 $linkText = $text;
01110 $linkTarget = Linker::normalizeSubpageLink( $this->commentContextTitle,
01111 $match[1], $linkText );
01112
01113 $target = Title::newFromText( $linkTarget );
01114 if( $target ) {
01115 if( $target->getText() == '' && !$this->commentLocal && $this->commentContextTitle ) {
01116 $newTarget = clone( $this->commentContextTitle );
01117 $newTarget->setFragment( '#' . $target->getFragment() );
01118 $target = $newTarget;
01119 }
01120 $thelink = $this->link(
01121 $target,
01122 $linkText . $inside
01123 ) . $trail;
01124 }
01125 }
01126 if( $thelink ) {
01127
01128 $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 );
01129 }
01130
01131 return $comment;
01132 }
01133
01134 static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
01135 # Valid link forms:
01136 # Foobar -- normal
01137 # :Foobar -- override special treatment of prefix (images, language links)
01138 # /Foobar -- convert to CurrentPage/Foobar
01139 # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text
01140 # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage
01141 # ../Foobar -- convert to CurrentPage/Foobar, from CurrentPage/CurrentSubPage
01142
01143 wfProfileIn( __METHOD__ );
01144 $ret = $target; # default return value is no change
01145
01146 # Some namespaces don't allow subpages,
01147 # so only perform processing if subpages are allowed
01148 if( $contextTitle && MWNamespace::hasSubpages( $contextTitle->getNamespace() ) ) {
01149 $hash = strpos( $target, '#' );
01150 if( $hash !== false ) {
01151 $suffix = substr( $target, $hash );
01152 $target = substr( $target, 0, $hash );
01153 } else {
01154 $suffix = '';
01155 }
01156 # bug 7425
01157 $target = trim( $target );
01158 # Look at the first character
01159 if( $target != '' && $target{0} === '/' ) {
01160 # / at end means we don't want the slash to be shown
01161 $m = array();
01162 $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
01163 if( $trailingSlashes ) {
01164 $noslash = $target = substr( $target, 1, -strlen($m[0][0]) );
01165 } else {
01166 $noslash = substr( $target, 1 );
01167 }
01168
01169 $ret = $contextTitle->getPrefixedText(). '/' . trim($noslash) . $suffix;
01170 if( $text === '' ) {
01171 $text = $target . $suffix;
01172 } # this might be changed for ugliness reasons
01173 } else {
01174 # check for .. subpage backlinks
01175 $dotdotcount = 0;
01176 $nodotdot = $target;
01177 while( strncmp( $nodotdot, "../", 3 ) == 0 ) {
01178 ++$dotdotcount;
01179 $nodotdot = substr( $nodotdot, 3 );
01180 }
01181 if($dotdotcount > 0) {
01182 $exploded = explode( '/', $contextTitle->GetPrefixedText() );
01183 if( count( $exploded ) > $dotdotcount ) { # not allowed to go below top level page
01184 $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) );
01185 # / at the end means don't show full path
01186 if( substr( $nodotdot, -1, 1 ) === '/' ) {
01187 $nodotdot = substr( $nodotdot, 0, -1 );
01188 if( $text === '' ) {
01189 $text = $nodotdot . $suffix;
01190 }
01191 }
01192 $nodotdot = trim( $nodotdot );
01193 if( $nodotdot != '' ) {
01194 $ret .= '/' . $nodotdot;
01195 }
01196 $ret .= $suffix;
01197 }
01198 }
01199 }
01200 }
01201
01202 wfProfileOut( __METHOD__ );
01203 return $ret;
01204 }
01205
01216 function commentBlock( $comment, $title = null, $local = false ) {
01217
01218
01219
01220 if( $comment == '' || $comment == '*' ) {
01221 return '';
01222 } else {
01223 $formatted = $this->formatComment( $comment, $title, $local );
01224 return " <span class=\"comment\">($formatted)</span>";
01225 }
01226 }
01227
01237 function revComment( Revision $rev, $local = false, $isPublic = false ) {
01238 if( $rev->getRawComment() == "" ) return "";
01239 if( $rev->isDeleted( Revision::DELETED_COMMENT ) && $isPublic ) {
01240 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
01241 } else if( $rev->userCan( Revision::DELETED_COMMENT ) ) {
01242 $block = $this->commentBlock( $rev->getComment( Revision::FOR_THIS_USER ),
01243 $rev->getTitle(), $local );
01244 } else {
01245 $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
01246 }
01247 if( $rev->isDeleted( Revision::DELETED_COMMENT ) ) {
01248 return " <span class=\"history-deleted\">$block</span>";
01249 }
01250 return $block;
01251 }
01252
01253 public function formatRevisionSize( $size ) {
01254 if ( $size == 0 ) {
01255 $stxt = wfMsgExt( 'historyempty', 'parsemag' );
01256 } else {
01257 global $wgLang;
01258 $stxt = wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $size ) );
01259 $stxt = "($stxt)";
01260 }
01261 $stxt = htmlspecialchars( $stxt );
01262 return "<span class=\"history-size\">$stxt</span>";
01263 }
01264
01268 function tocIndent() {
01269 return "\n<ul>";
01270 }
01271
01275 function tocUnindent($level) {
01276 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ? $level : 0 );
01277 }
01278
01282 function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
01283 $classes = "toclevel-$level";
01284 if ( $sectionIndex !== false )
01285 $classes .= " tocsection-$sectionIndex";
01286 return "\n<li class=\"$classes\"><a href=\"#" .
01287 $anchor . '"><span class="tocnumber">' .
01288 $tocnumber . '</span> <span class="toctext">' .
01289 $tocline . '</span></a>';
01290 }
01291
01297 function tocLineEnd() {
01298 return "</li>\n";
01299 }
01300
01306 function tocList($toc) {
01307 $title = wfMsgHtml('toc') ;
01308 return
01309 '<table id="toc" class="toc"><tr><td>'
01310 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
01311 . $toc
01312 # no trailing newline, script should not be wrapped in a
01313 # paragraph
01314 . "</ul>\n</td></tr></table>"
01315 . Html::inlineScript(
01316 'if (window.showTocToggle) {'
01317 . ' var tocShowText = "' . Xml::escapeJsString( wfMsg('showtoc') ) . '";'
01318 . ' var tocHideText = "' . Xml::escapeJsString( wfMsg('hidetoc') ) . '";'
01319 . ' showTocToggle();'
01320 . ' } ' )
01321 . "\n";
01322 }
01323
01330 public function generateTOC( $tree ) {
01331 $toc = '';
01332 $lastLevel = 0;
01333 foreach ( $tree as $section ) {
01334 if ( $section['toclevel'] > $lastLevel )
01335 $toc .= $this->tocIndent();
01336 else if ( $section['toclevel'] < $lastLevel )
01337 $toc .= $this->tocUnindent(
01338 $lastLevel - $section['toclevel'] );
01339 else
01340 $toc .= $this->tocLineEnd();
01341
01342 $toc .= $this->tocLine( $section['anchor'],
01343 $section['line'], $section['number'],
01344 $section['toclevel'], $section['index'] );
01345 $lastLevel = $section['toclevel'];
01346 }
01347 $toc .= $this->tocLineEnd();
01348 return $this->tocList( $toc );
01349 }
01350
01363 public function doEditSectionLink( Title $nt, $section, $tooltip = null ) {
01364
01365
01366 $attribs = array();
01367 if( !is_null( $tooltip ) ) {
01368 $attribs['title'] = wfMsg( 'editsectionhint', $tooltip );
01369 }
01370 $link = $this->link( $nt, wfMsg('editsection'),
01371 $attribs,
01372 array( 'action' => 'edit', 'section' => $section ),
01373 array( 'noclasses', 'known' )
01374 );
01375
01376 # Run the old hook. This takes up half of the function . . . hopefully
01377 # we can rid of it someday.
01378 $attribs = '';
01379 if( $tooltip ) {
01380 $attribs = wfMsgHtml( 'editsectionhint', htmlspecialchars( $tooltip ) );
01381 $attribs = " title=\"$attribs\"";
01382 }
01383 $result = null;
01384 wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result ) );
01385 if( !is_null( $result ) ) {
01386 # For reverse compatibility, add the brackets *after* the hook is
01387 # run, and even add them to hook-provided text. (This is the main
01388 # reason that the EditSectionLink hook is deprecated in favor of
01389 # DoEditSectionLink: it can't change the brackets or the span.)
01390 $result = wfMsgHtml( 'editsection-brackets', $result );
01391 return "<span class=\"editsection\">$result</span>";
01392 }
01393
01394 # Add the brackets and the span, and *then* run the nice new hook, with
01395 # clean and non-redundant arguments.
01396 $result = wfMsgHtml( 'editsection-brackets', $link );
01397 $result = "<span class=\"editsection\">$result</span>";
01398
01399 wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result ) );
01400 return $result;
01401 }
01402
01417 public function makeHeadline( $level, $attribs, $anchor, $text, $link, $legacyAnchor = false ) {
01418 $ret = "<h$level$attribs"
01419 . $link
01420 . " <span class=\"mw-headline\" id=\"$anchor\">$text</span>"
01421 . "</h$level>";
01422 if ( $legacyAnchor !== false ) {
01423 $ret = "<a id=\"$legacyAnchor\"></a>$ret";
01424 }
01425 return $ret;
01426 }
01427
01434 static function splitTrail( $trail ) {
01435 static $regex = false;
01436 if ( $regex === false ) {
01437 global $wgContLang;
01438 $regex = $wgContLang->linkTrail();
01439 }
01440 $inside = '';
01441 if ( $trail != '' ) {
01442 $m = array();
01443 if ( preg_match( $regex, $trail, $m ) ) {
01444 $inside = $m[1];
01445 $trail = $m[2];
01446 }
01447 }
01448 return array( $inside, $trail );
01449 }
01450
01464 function generateRollback( $rev ) {
01465 return '<span class="mw-rollback-link">['
01466 . $this->buildRollbackLink( $rev )
01467 . ']</span>';
01468 }
01469
01476 public function buildRollbackLink( $rev ) {
01477 global $wgRequest, $wgUser;
01478 $title = $rev->getTitle();
01479 $query = array(
01480 'action' => 'rollback',
01481 'from' => $rev->getUserText()
01482 );
01483 if( $wgRequest->getBool( 'bot' ) ) {
01484 $query['bot'] = '1';
01485 $query['hidediff'] = '1';
01486 }
01487 $query['token'] = $wgUser->editToken( array( $title->getPrefixedText(),
01488 $rev->getUserText() ) );
01489 return $this->link( $title, wfMsgHtml( 'rollbacklink' ),
01490 array( 'title' => wfMsg( 'tooltip-rollback' ) ),
01491 $query, array( 'known', 'noclasses' ) );
01492 }
01493
01503 public function formatTemplates( $templates, $preview = false, $section = false ) {
01504 wfProfileIn( __METHOD__ );
01505
01506 $outText = '';
01507 if ( count( $templates ) > 0 ) {
01508 # Do a batch existence check
01509 $batch = new LinkBatch;
01510 foreach( $templates as $title ) {
01511 $batch->addObj( $title );
01512 }
01513 $batch->execute();
01514
01515 # Construct the HTML
01516 $outText = '<div class="mw-templatesUsedExplanation">';
01517 if ( $preview ) {
01518 $outText .= wfMsgExt( 'templatesusedpreview', array( 'parse' ), count( $templates ) );
01519 } elseif ( $section ) {
01520 $outText .= wfMsgExt( 'templatesusedsection', array( 'parse' ), count( $templates ) );
01521 } else {
01522 $outText .= wfMsgExt( 'templatesused', array( 'parse' ), count( $templates ) );
01523 }
01524 $outText .= "</div><ul>\n";
01525
01526 usort( $templates, array( 'Title', 'compare' ) );
01527 foreach ( $templates as $titleObj ) {
01528 $r = $titleObj->getRestrictions( 'edit' );
01529 if ( in_array( 'sysop', $r ) ) {
01530 $protected = wfMsgExt( 'template-protected', array( 'parseinline' ) );
01531 } elseif ( in_array( 'autoconfirmed', $r ) ) {
01532 $protected = wfMsgExt( 'template-semiprotected', array( 'parseinline' ) );
01533 } else {
01534 $protected = '';
01535 }
01536 if( $titleObj->quickUserCan( 'edit' ) ) {
01537 $editLink = $this->link(
01538 $titleObj,
01539 wfMsg( 'editlink' ),
01540 array(),
01541 array( 'action' => 'edit' )
01542 );
01543 } else {
01544 $editLink = $this->link(
01545 $titleObj,
01546 wfMsg( 'viewsourcelink' ),
01547 array(),
01548 array( 'action' => 'edit' )
01549 );
01550 }
01551 $outText .= '<li>' . $this->link( $titleObj ) . ' (' . $editLink . ') ' . $protected . '</li>';
01552 }
01553 $outText .= '</ul>';
01554 }
01555 wfProfileOut( __METHOD__ );
01556 return $outText;
01557 }
01558
01566 public function formatHiddenCategories( $hiddencats ) {
01567 global $wgLang;
01568 wfProfileIn( __METHOD__ );
01569
01570 $outText = '';
01571 if ( count( $hiddencats ) > 0 ) {
01572 # Construct the HTML
01573 $outText = '<div class="mw-hiddenCategoriesExplanation">';
01574 $outText .= wfMsgExt( 'hiddencategories', array( 'parse' ), $wgLang->formatnum( count( $hiddencats ) ) );
01575 $outText .= "</div><ul>\n";
01576
01577 foreach ( $hiddencats as $titleObj ) {
01578 $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
01579 }
01580 $outText .= '</ul>';
01581 }
01582 wfProfileOut( __METHOD__ );
01583 return $outText;
01584 }
01585
01593 public function formatSize( $size ) {
01594 global $wgLang;
01595 return htmlspecialchars( $wgLang->formatSize( $size ) );
01596 }
01597
01610 public function titleAttrib( $name, $options = null ) {
01611 wfProfileIn( __METHOD__ );
01612
01613 $tooltip = wfMsg( "tooltip-$name" );
01614 # Compatibility: formerly some tooltips had [alt-.] hardcoded
01615 $tooltip = preg_replace( "/ ?\[alt-.\]$/", '', $tooltip );
01616
01617 # Message equal to '-' means suppress it.
01618 if ( wfEmptyMsg( "tooltip-$name", $tooltip ) || $tooltip == '-' ) {
01619 $tooltip = false;
01620 }
01621
01622 if ( $options == 'withaccess' ) {
01623 $accesskey = $this->accesskey( $name );
01624 if( $accesskey !== false ) {
01625 if ( $tooltip === false || $tooltip === '' ) {
01626 $tooltip = "[$accesskey]";
01627 } else {
01628 $tooltip .= " [$accesskey]";
01629 }
01630 }
01631 }
01632
01633 wfProfileOut( __METHOD__ );
01634 return $tooltip;
01635 }
01636
01647 public function accesskey( $name ) {
01648 wfProfileIn( __METHOD__ );
01649
01650 $accesskey = wfMsg( "accesskey-$name" );
01651
01652 # FIXME: Per standard MW behavior, a value of '-' means to suppress the
01653 # attribute, but this is broken for accesskey: that might be a useful
01654 # value.
01655 if( $accesskey != '' && $accesskey != '-' && !wfEmptyMsg( "accesskey-$name", $accesskey ) ) {
01656 wfProfileOut( __METHOD__ );
01657 return $accesskey;
01658 }
01659
01660 wfProfileOut( __METHOD__ );
01661 return false;
01662 }
01663
01674 public function revDeleteLink( $query = array(), $restricted = false, $delete = true ) {
01675 $sp = SpecialPage::getTitleFor( 'Revisiondelete' );
01676 $text = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' );
01677 $tag = $restricted ? 'strong' : 'span';
01678 $link = $this->link( $sp, $text, array(), $query, array( 'known', 'noclasses' ) );
01679 return Xml::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), "($link)" );
01680 }
01681
01690 public function revDeleteLinkDisabled( $delete = true ) {
01691 $text = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' );
01692 return Xml::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), "($text)" );
01693 }
01694
01695 /* Deprecated methods */
01696
01700 function postParseLinkColour( $s = null ) {
01701 wfDeprecated( __METHOD__ );
01702 return null;
01703 }
01704
01705
01719 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
01720 wfProfileIn( __METHOD__ );
01721 $nt = Title::newFromText( $title );
01722 if ( $nt instanceof Title ) {
01723 $result = $this->makeLinkObj( $nt, $text, $query, $trail );
01724 } else {
01725 wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" );
01726 $result = $text == "" ? $title : $text;
01727 }
01728
01729 wfProfileOut( __METHOD__ );
01730 return $result;
01731 }
01732
01746 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
01747 $nt = Title::newFromText( $title );
01748 if ( $nt instanceof Title ) {
01749 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix , $aprops );
01750 } else {
01751 wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" );
01752 return $text == '' ? $title : $text;
01753 }
01754 }
01755
01769 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
01770 $nt = Title::newFromText( $title );
01771 if ( $nt instanceof Title ) {
01772 return $this->makeBrokenLinkObj( $nt, $text, $query, $trail );
01773 } else {
01774 wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" );
01775 return $text == '' ? $title : $text;
01776 }
01777 }
01778
01792 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
01793 wfDeprecated( __METHOD__ );
01794 $nt = Title::newFromText( $title );
01795 if ( $nt instanceof Title ) {
01796 return $this->makeStubLinkObj( $nt, $text, $query, $trail );
01797 } else {
01798 wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" );
01799 return $text == '' ? $title : $text;
01800 }
01801 }
01802
01819 function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
01820 wfProfileIn( __METHOD__ );
01821
01822 $query = wfCgiToArray( $query );
01823 list( $inside, $trail ) = Linker::splitTrail( $trail );
01824 if( $text === '' ) {
01825 $text = $this->linkText( $nt );
01826 }
01827
01828 $ret = $this->link( $nt, "$prefix$text$inside", array(), $query ) . $trail;
01829
01830 wfProfileOut( __METHOD__ );
01831 return $ret;
01832 }
01833
01850 function makeKnownLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
01851 wfProfileIn( __METHOD__ );
01852
01853 if ( $text == '' ) {
01854 $text = $this->linkText( $title );
01855 }
01856 $attribs = Sanitizer::mergeAttributes(
01857 Sanitizer::decodeTagAttributes( $aprops ),
01858 Sanitizer::decodeTagAttributes( $style )
01859 );
01860 $query = wfCgiToArray( $query );
01861 list( $inside, $trail ) = Linker::splitTrail( $trail );
01862
01863 $ret = $this->link( $title, "$prefix$text$inside", $attribs, $query,
01864 array( 'known', 'noclasses' ) ) . $trail;
01865
01866 wfProfileOut( __METHOD__ );
01867 return $ret;
01868 }
01869
01882 function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
01883 wfProfileIn( __METHOD__ );
01884
01885 list( $inside, $trail ) = Linker::splitTrail( $trail );
01886 if( $text === '' ) {
01887 $text = $this->linkText( $title );
01888 }
01889 $nt = $this->normaliseSpecialPage( $title );
01890
01891 $ret = $this->link( $title, "$prefix$text$inside", array(),
01892 wfCgiToArray( $query ), 'broken' ) . $trail;
01893
01894 wfProfileOut( __METHOD__ );
01895 return $ret;
01896 }
01897
01910 function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
01911 wfDeprecated( __METHOD__ );
01912 return $this->makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix );
01913 }
01914
01928 function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
01929 if($colour != ''){
01930 $style = $this->getInternalLinkAttributesObj( $nt, $text, $colour );
01931 } else $style = '';
01932 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style );
01933 }
01934
01936 function makeImage( $url, $alt = '' ) {
01937 wfDeprecated( __METHOD__ );
01938 return $this->makeExternalImage( $url, $alt );
01939 }
01940
01957 function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(), $framed = false,
01958 $thumb = false, $manualthumb = '', $valign = '', $time = false )
01959 {
01960 $frameParams = array( 'alt' => $alt, 'caption' => $label );
01961 if ( $align ) {
01962 $frameParams['align'] = $align;
01963 }
01964 if ( $framed ) {
01965 $frameParams['framed'] = true;
01966 }
01967 if ( $thumb ) {
01968 $frameParams['thumbnail'] = true;
01969 }
01970 if ( $manualthumb ) {
01971 $frameParams['manualthumb'] = $manualthumb;
01972 }
01973 if ( $valign ) {
01974 $frameParams['valign'] = $valign;
01975 }
01976 $file = wfFindFile( $title, array( 'time' => $time ) );
01977 return $this->makeImageLink2( $title, $file, $frameParams, $handlerParams, $time );
01978 }
01979
01981 function makeMediaLink( $name, $unused = '', $text = '', $time = false ) {
01982 $nt = Title::makeTitleSafe( NS_FILE, $name );
01983 return $this->makeMediaLinkObj( $nt, $text, $time );
01984 }
01985
01994 public function editSectionLinkForOther( $title, $section ) {
01995 wfDeprecated( __METHOD__ );
01996 $title = Title::newFromText( $title );
01997 return $this->doEditSectionLink( $title, $section );
01998 }
01999
02006 public function editSectionLink( Title $nt, $section, $hint = '' ) {
02007 wfDeprecated( __METHOD__ );
02008 if( $hint === '' ) {
02009 # No way to pass an actual empty $hint here! The new interface al-
02010 # lows this, so we have to do this for compatibility.
02011 $hint = null;
02012 }
02013 return $this->doEditSectionLink( $nt, $section, $hint );
02014 }
02015
02019 public function tooltipAndAccesskeyAttribs( $name ) {
02020 global $wgEnableTooltipsAndAccesskeys;
02021 if ( !$wgEnableTooltipsAndAccesskeys )
02022 return array();
02023 # FIXME: If Sanitizer::expandAttributes() treated "false" as "output
02024 # no attribute" instead of "output '' as value for attribute", this
02025 # would be three lines.
02026 $attribs = array(
02027 'title' => $this->titleAttrib( $name, 'withaccess' ),
02028 'accesskey' => $this->accesskey( $name )
02029 );
02030 if ( $attribs['title'] === false ) {
02031 unset( $attribs['title'] );
02032 }
02033 if ( $attribs['accesskey'] === false ) {
02034 unset( $attribs['accesskey'] );
02035 }
02036 return $attribs;
02037 }
02041 public function tooltipAndAccesskey( $name ) {
02042 return Xml::expandAttributes( $this->tooltipAndAccesskeyAttribs( $name ) );
02043 }
02044
02045
02047 public function tooltip( $name, $options = null ) {
02048 global $wgEnableTooltipsAndAccesskeys;
02049 if ( !$wgEnableTooltipsAndAccesskeys )
02050 return '';
02051 # FIXME: If Sanitizer::expandAttributes() treated "false" as "output
02052 # no attribute" instead of "output '' as value for attribute", this
02053 # would be two lines.
02054 $tooltip = $this->titleAttrib( $name, $options );
02055 if ( $tooltip === false ) {
02056 return '';
02057 }
02058 return Xml::expandAttributes( array(
02059 'title' => $this->titleAttrib( $name, $options )
02060 ) );
02061 }
02062 }