3 * Split off some of the internal bits from Skin.php.
4 * These functions are used for primarily page content:
5 * links, embedded images, table of contents. Links are
6 * also used in the skin.
11 * For the moment, Skin is a descendent class of Linker.
12 * In the future, it should probably be further split
13 * so that ever other bit of the wiki doesn't have to
14 * go loading up Skin to get at it.
25 function postParseLinkColour( $s = NULL ) {
30 function getExternalLinkAttributes( $link, $text, $class='' ) {
31 $link = htmlspecialchars( $link );
33 $r = ($class != '') ?
" class='$class'" : " class='external'";
35 $r .= " title=\"{$link}\"";
39 function getInterwikiLinkAttributes( $link, $text, $class='' ) {
42 $same = ($link == $text);
43 $link = urldecode( $link );
44 $link = $wgContLang->checkTitleEncoding( $link );
45 $link = preg_replace( '/[\\x00-\\x1f]/', ' ', $link );
46 $link = htmlspecialchars( $link );
48 $r = ($class != '') ?
" class='$class'" : " class='external'";
50 $r .= " title=\"{$link}\"";
55 function getInternalLinkAttributes( $link, $text, $broken = false ) {
56 $link = urldecode( $link );
57 $link = str_replace( '_', ' ', $link );
58 $link = htmlspecialchars( $link );
60 if( $broken == 'stub' ) {
62 } else if ( $broken == 'yes' ) {
68 $r .= " title=\"{$link}\"";
75 function getInternalLinkAttributesObj( &$nt, $text, $broken = false ) {
76 if( $broken == 'stub' ) {
78 } else if ( $broken == 'yes' ) {
84 $r .= ' title="' . $nt->getEscapedText() . '"';
89 * This function is a shortcut to makeLinkObj(Title::newFromText($title),...). Do not call
90 * it if you already have a title object handy. See makeLinkObj for further documentation.
92 * @param string $title The text of the title
93 * @param string $text Link text
94 * @param string $query Optional query part
95 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
96 * be included in the link text. Other characters will be appended after
97 * the end of the link.
99 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
100 wfProfileIn( 'Linker::makeLink' );
101 $nt = Title
::newFromText( $title );
103 $result = $this->makeLinkObj( Title
::newFromText( $title ), $text, $query, $trail );
105 wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" );
106 $result = $text == "" ?
$title : $text;
109 wfProfileOut( 'Linker::makeLink' );
114 * This function is a shortcut to makeKnownLinkObj(Title::newFromText($title),...). Do not call
115 * it if you already have a title object handy. See makeKnownLinkObj for further documentation.
117 * @param string $title The text of the title
118 * @param string $text Link text
119 * @param string $query Optional query part
120 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
121 * be included in the link text. Other characters will be appended after
122 * the end of the link.
124 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
125 $nt = Title
::newFromText( $title );
127 return $this->makeKnownLinkObj( Title
::newFromText( $title ), $text, $query, $trail, $prefix , $aprops );
129 wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" );
130 return $text == '' ?
$title : $text;
135 * This function is a shortcut to makeBrokenLinkObj(Title::newFromText($title),...). Do not call
136 * it if you already have a title object handy. See makeBrokenLinkObj for further documentation.
138 * @param string $title The text of the title
139 * @param string $text Link text
140 * @param string $query Optional query part
141 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
142 * be included in the link text. Other characters will be appended after
143 * the end of the link.
145 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
146 $nt = Title
::newFromText( $title );
148 return $this->makeBrokenLinkObj( Title
::newFromText( $title ), $text, $query, $trail );
150 wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" );
151 return $text == '' ?
$title : $text;
156 * This function is a shortcut to makeStubLinkObj(Title::newFromText($title),...). Do not call
157 * it if you already have a title object handy. See makeStubLinkObj for further documentation.
159 * @param string $title The text of the title
160 * @param string $text Link text
161 * @param string $query Optional query part
162 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
163 * be included in the link text. Other characters will be appended after
164 * the end of the link.
166 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
167 $nt = Title
::newFromText( $title );
169 return $this->makeStubLinkObj( Title
::newFromText( $title ), $text, $query, $trail );
171 wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" );
172 return $text == '' ?
$title : $text;
177 * Make a link for a title which may or may not be in the database. If you need to
178 * call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
179 * call to this will result in a DB query.
181 * @param string $title The text of the title
182 * @param string $text Link text
183 * @param string $query Optional query part
184 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
185 * be included in the link text. Other characters will be appended after
186 * the end of the link.
188 function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
190 $fname = 'Linker::makeLinkObj';
191 wfProfileIn( $fname );
194 if ( ! is_object($nt) ) {
195 # wfDebugDieBacktrace();
196 wfProfileOut( $fname );
197 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
200 $ns = $nt->getNamespace();
201 $dbkey = $nt->getDBkey();
202 if ( $nt->isExternal() ) {
203 $u = $nt->getFullURL();
204 $link = $nt->getPrefixedURL();
205 if ( '' == $text ) { $text = $nt->getPrefixedText(); }
206 $style = $this->getInterwikiLinkAttributes( $link, $text, 'extiw' );
209 if ( '' != $trail ) {
210 if ( preg_match( '/^([a-z]+)(.*)$$/sD', $trail, $m ) ) {
216 # Check for anchors, normalize the anchor
218 $parts = explode( '#', $u, 2 );
219 if ( count( $parts ) == 2 ) {
220 $anchor = urlencode( Sanitizer
::decodeCharReferences( str_replace(' ', '_', $parts[1] ) ) );
221 $replacearray = array(
225 $u = $parts[0] . '#' .
226 str_replace( array_keys( $replacearray ),
227 array_values( $replacearray ),
231 $t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
233 wfProfileOut( $fname );
235 } elseif ( $nt->isAlwaysKnown() ) {
236 # Image links, special page links and self-links with fragements are always known.
237 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
239 wfProfileIn( $fname.'-immediate' );
240 # Work out link colour immediately
241 $aid = $nt->getArticleID() ;
243 $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
245 $threshold = $wgUser->getOption('stubthreshold') ;
246 if ( $threshold > 0 ) {
247 $dbr =& wfGetDB( DB_SLAVE
);
248 $s = $dbr->selectRow(
252 'page_is_redirect' ),
253 array( 'page_id' => $aid ), $fname ) ;
254 if ( $s !== false ) {
255 $size = $s->page_len
;
256 if ( $s->page_is_redirect
OR $s->page_namespace
!= NS_MAIN
) {
257 $size = $threshold*2 ; # Really big
260 $size = $threshold*2 ; # Really big
265 if ( $size < $threshold ) {
266 $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
268 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
271 wfProfileOut( $fname.'-immediate' );
273 wfProfileOut( $fname );
278 * Make a link for a title which definitely exists. This is faster than makeLinkObj because
279 * it doesn't have to do a database query. It's also valid for interwiki titles and special
282 * @param object $nt Title of target page
283 * @param string $text Text to replace the title
284 * @param string $query Link target
285 * @param string $trail Text after link
286 * @param string $prefix Text before link text
287 * @param string $aprops Extra attributes to the a-element
288 * @param string $style Style to apply - if empty, use getInternalLinkAttributesObj instead
289 * @return the a-element
291 function makeKnownLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
293 $fname = 'Linker::makeKnownLinkObj';
294 wfProfileIn( $fname );
296 if ( !is_object( $nt ) ) {
297 wfProfileOut( $fname );
301 $u = $nt->escapeLocalURL( $query );
302 if ( $nt->getFragment() != '' ) {
303 if( $nt->getPrefixedDbkey() == '' ) {
306 $text = htmlspecialchars( $nt->getFragment() );
309 $anchor = urlencode( Sanitizer
::decodeCharReferences( str_replace( ' ', '_', $nt->getFragment() ) ) );
310 $replacearray = array(
314 $u .= '#' . str_replace(array_keys($replacearray),array_values($replacearray),$anchor);
317 $text = htmlspecialchars( $nt->getPrefixedText() );
319 if ( $style == '' ) {
320 $style = $this->getInternalLinkAttributesObj( $nt, $text );
323 if ( $aprops !== '' ) $aprops = ' ' . $aprops;
325 list( $inside, $trail ) = Linker
::splitTrail( $trail );
326 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
327 wfProfileOut( $fname );
332 * Make a red link to the edit page of a given title.
334 * @param string $title The text of the title
335 * @param string $text Link text
336 * @param string $query Optional query part
337 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
338 * be included in the link text. Other characters will be appended after
339 * the end of the link.
341 function makeBrokenLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
343 if ( ! isset($nt) ) {
344 # wfDebugDieBacktrace();
345 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
348 $fname = 'Linker::makeBrokenLinkObj';
349 wfProfileIn( $fname );
351 if ( '' == $query ) {
354 $q = 'action=edit&'.$query;
356 $u = $nt->escapeLocalURL( $q );
359 $text = htmlspecialchars( $nt->getPrefixedText() );
361 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
363 list( $inside, $trail ) = Linker
::splitTrail( $trail );
364 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
366 wfProfileOut( $fname );
371 * Make a brown link to a short article.
373 * @param string $title The text of the title
374 * @param string $text Link text
375 * @param string $query Optional query part
376 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
377 * be included in the link text. Other characters will be appended after
378 * the end of the link.
380 function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
381 $link = $nt->getPrefixedURL();
383 $u = $nt->escapeLocalURL( $query );
386 $text = htmlspecialchars( $nt->getPrefixedText() );
388 $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' );
390 list( $inside, $trail ) = Linker
::splitTrail( $trail );
391 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
396 * Generate either a normal exists-style link or a stub link, depending
397 * on the given page size.
401 * @param string $text
402 * @param string $query
403 * @param string $trail
404 * @param string $prefix
405 * @return string HTML of link
407 function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
409 $threshold = intval( $wgUser->getOption( 'stubthreshold' ) );
410 if( $size < $threshold ) {
411 return $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
413 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
418 * Make appropriate markup for a link to the current article. This is currently rendered
419 * as the bold link text. The calling sequence is the same as the other make*LinkObj functions,
420 * despite $query not being used.
422 function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
424 $text = htmlspecialchars( $nt->getPrefixedText() );
426 list( $inside, $trail ) = Linker
::splitTrail( $trail );
427 return "<strong>{$prefix}{$text}{$inside}</strong>{$trail}";
430 /** @todo document */
431 function fnamePart( $url ) {
432 $basename = strrchr( $url, '/' );
433 if ( false === $basename ) {
436 $basename = substr( $basename, 1 );
438 return htmlspecialchars( $basename );
441 /** Obsolete alias */
442 function makeImage( $url, $alt = '' ) {
443 return $this->makeExternalImage( $url, $alt );
446 /** @todo document */
447 function makeExternalImage( $url, $alt = '' ) {
449 $alt = $this->fnamePart( $url );
451 $s = '<img src="'.$url.'" alt="'.$alt.'" />';
455 /** @todo document */
456 function makeImageLinkObj( $nt, $label, $alt, $align = '', $width = false, $height = false, $framed = false,
457 $thumb = false, $manual_thumb = '' )
459 global $wgContLang, $wgUser, $wgThumbLimits;
461 $img = new Image( $nt );
462 if ( !$img->allowInlineDisplay() && $img->exists() ) {
463 return $this->makeKnownLinkObj( $nt );
466 $url = $img->getViewURL();
467 $error = $prefix = $postfix = '';
469 wfDebug( "makeImageLinkObj: '$width'x'$height'\n" );
471 if ( 'center' == $align )
473 $prefix = '<div class="center">';
478 if ( $thumb ||
$framed ) {
480 # Create a thumbnail. Alignment depends on language
481 # writing direction, # right aligned for left-to-right-
482 # languages ("Western languages"), left-aligned
483 # for right-to-left-languages ("Semitic languages")
485 # If thumbnail width has not been provided, it is set
486 # to the default user option as specified in Language*.php
487 if ( $align == '' ) {
488 $align = $wgContLang->isRTL() ?
'left' : 'right';
492 if ( $width === false ) {
493 $wopt = $wgUser->getOption( 'thumbsize' );
495 if( !isset( $wgThumbLimits[$wopt] ) ) {
496 $wopt = User
::getDefaultOption( 'thumbsize' );
499 $width = min( $img->getWidth(), $wgThumbLimits[$wopt] );
502 return $prefix.$this->makeThumbLinkObj( $img, $label, $alt, $align, $width, $height, $framed, $manual_thumb ).$postfix;
505 if ( $width && $img->exists() ) {
507 # Create a resized image, without the additional thumbnail
510 if ( $height == false )
512 if ( $manual_thumb == '') {
513 $thumb = $img->getThumbnail( $width, $height );
515 // In most cases, $width = $thumb->width or $height = $thumb->height.
516 // If not, we're scaling the image larger than it can be scaled,
517 // so we send to the browser a smaller thumbnail, and let the client do the scaling.
519 if ($height != -1 && $width > $thumb->width
* $height / $thumb->height
) {
520 // $height is the limiting factor, not $width
521 // set $width to the largest it can be, such that the resulting
522 // scaled height is at most $height
523 $width = floor($thumb->width
* $height / $thumb->height
);
525 $height = round($thumb->height
* $width / $thumb->width
);
527 wfDebug( "makeImageLinkObj: client-size set to '$width x $height'\n" );
528 $url = $thumb->getUrl();
530 $error = htmlspecialchars( $img->getLastError() );
534 $width = $img->width
;
535 $height = $img->height
;
538 wfDebug( "makeImageLinkObj2: '$width'x'$height'\n" );
539 $u = $nt->escapeLocalURL();
542 } elseif ( $url == '' ) {
543 $s = $this->makeBrokenImageLinkObj( $img->getTitle() );
544 //$s .= "<br />{$alt}<br />{$url}<br />\n";
546 $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
547 '<img src="'.$url.'" alt="'.$alt.'" ' .
549 ?
( 'width="'.$width.'" height="'.$height.'" ' )
551 'longdesc="'.$u.'" /></a>';
553 if ( '' != $align ) {
554 $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
556 return str_replace("\n", ' ',$prefix.$s.$postfix);
560 * Make HTML for a thumbnail including image, border and caption
561 * $img is an Image object
563 function makeThumbLinkObj( $img, $label = '', $alt, $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
564 global $wgStylePath, $wgContLang;
565 $url = $img->getViewURL();
569 $width = $height = 0;
570 if ( $img->exists() ) {
571 $width = $img->getWidth();
572 $height = $img->getHeight();
574 if ( 0 == $width ||
0 == $height ) {
575 $width = $height = 180;
577 if ( $boxwidth == 0 ) {
581 // Use image dimensions, don't scale
583 $boxheight = $height;
586 if ( $boxheight === false )
588 if ( '' == $manual_thumb ) {
589 $thumb = $img->getThumbnail( $boxwidth, $boxheight );
591 $thumbUrl = $thumb->getUrl();
592 $boxwidth = $thumb->width
;
593 $boxheight = $thumb->height
;
595 $error = $img->getLastError();
599 $oboxwidth = $boxwidth +
2;
601 if ( $manual_thumb != '' ) # Use manually specified thumbnail
603 $manual_title = Title
::makeTitleSafe( NS_IMAGE
, $manual_thumb ); #new Title ( $manual_thumb ) ;
604 $manual_img = new Image( $manual_title );
605 $thumbUrl = $manual_img->getViewURL();
606 if ( $manual_img->exists() )
608 $width = $manual_img->getWidth();
609 $height = $manual_img->getHeight();
611 $boxheight = $height ;
612 $oboxwidth = $boxwidth +
2 ;
616 $u = $img->getEscapeLocalURL();
618 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
619 $magnifyalign = $wgContLang->isRTL() ?
'left' : 'right';
620 $textalign = $wgContLang->isRTL() ?
' style="text-align:right"' : '';
622 $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
623 if( $thumbUrl == '' ) {
624 // Couldn't generate thumbnail? Scale the image client-side.
628 $s .= htmlspecialchars( $error );
630 } elseif( !$img->exists() ) {
631 $s .= $this->makeBrokenImageLinkObj( $img->getTitle() );
634 $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
635 '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
636 'width="'.$boxwidth.'" height="'.$boxheight.'" ' .
637 'longdesc="'.$u.'" /></a>';
641 $zoomicon = '<div class="magnify" style="float:'.$magnifyalign.'">'.
642 '<a href="'.$u.'" class="internal" title="'.$more.'">'.
643 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
644 'width="15" height="11" alt="'.$more.'" /></a></div>';
647 $s .= ' <div class="thumbcaption" '.$textalign.'>'.$zoomicon.$label."</div></div></div>";
648 return str_replace("\n", ' ', $s);
652 * Pass a title object, not a title string
654 function makeBrokenImageLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
656 if ( ! isset($nt) ) {
657 # wfDebugDieBacktrace();
658 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
661 $fname = 'Linker::makeBrokenImageLinkObj';
662 wfProfileIn( $fname );
664 $q = 'wpDestFile=' . urlencode( $nt->getDBkey() );
665 if ( '' != $query ) {
668 $uploadTitle = Title
::makeTitle( NS_SPECIAL
, 'Upload' );
669 $url = $uploadTitle->escapeLocalURL( $q );
672 $text = htmlspecialchars( $nt->getPrefixedText() );
674 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
675 list( $inside, $trail ) = Linker
::splitTrail( $trail );
676 $s = "<a href=\"{$url}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
678 wfProfileOut( $fname );
682 /** @todo document */
683 function makeMediaLink( $name, /* wtf?! */ $url, $alt = '' ) {
684 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
685 return $this->makeMediaLinkObj( $nt, $alt );
689 * Create a direct link to a given uploaded file.
691 * @param Title $title
692 * @param string $text pre-sanitized HTML
693 * @param bool $nourl Mask absolute URLs, so the parser doesn't
694 * linkify them (it is currently not context-aware)
695 * @return string HTML
698 * @todo Handle invalid or missing images better.
700 function makeMediaLinkObj( $title, $text = '' ) {
701 if( is_null( $title ) ) {
702 ### HOTFIX. Instead of breaking, return empty string.
705 $name = $title->getDBKey();
706 $img = new Image( $title );
707 if( $img->exists() ) {
708 $url = $img->getURL();
711 $upload = Title
::makeTitle( NS_SPECIAL
, 'Upload' );
712 $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $img->getName() ) );
715 $alt = htmlspecialchars( $title->getText() );
719 $u = htmlspecialchars( $url );
720 return "<a href=\"{$u}\" class='$class' title=\"{$alt}\">{$text}</a>";
724 /** @todo document */
725 function specialLink( $name, $key = '' ) {
728 if ( '' == $key ) { $key = strtolower( $name ); }
729 $pn = $wgContLang->ucfirst( $name );
730 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
734 /** @todo document */
735 function makeExternalLink( $url, $text, $escape = true, $linktype = '' ) {
736 $style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
737 global $wgNoFollowLinks;
738 if( $wgNoFollowLinks ) {
739 $style .= ' rel="nofollow"';
741 $url = htmlspecialchars( $url );
743 $text = htmlspecialchars( $text );
745 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
749 * Make user link (or user contributions for unregistered users)
751 * @param string $userText
752 * @return string HTML fragment
755 function userLink( $userId, $userText ) {
756 $encName = htmlspecialchars( $userText );
758 $contribsPage = Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
759 return $this->makeKnownLinkObj( $contribsPage,
760 $encName, 'target=' . urlencode( $userText ) );
762 $userPage = Title
::makeTitle( NS_USER
, $userText );
763 return $this->makeLinkObj( $userPage, $encName );
769 * @param string $userText
770 * @return string HTML fragment with talk and/or block links
773 function userToolLinks( $userId, $userText ) {
774 global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans;
775 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
776 $blockable = ( $wgSysopUserBans ||
0 == $userId );
780 $items[] = $this->userTalkLink( $userId, $userText );
783 $contribsPage = Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
784 $items[] = $this->makeKnownLinkObj( $contribsPage,
785 wfMsgHtml( 'contribslink' ), 'target=' . urlencode( $userText ) );
787 if( $blockable && $wgUser->isAllowed( 'block' ) ) {
788 $items[] = $this->blockLink( $userId, $userText );
792 return ' (' . implode( ' | ', $items ) . ')';
800 * @param string $userText
801 * @return string HTML fragment with user talk link
804 function userTalkLink( $userId, $userText ) {
806 $talkname = $wgContLang->getNsText( NS_TALK
); # use the shorter name
808 $userTalkPage = Title
::makeTitle( NS_USER_TALK
, $userText );
809 $userTalkLink = $this->makeLinkObj( $userTalkPage, $talkname );
810 return $userTalkLink;
815 * @param string $userText
816 * @return string HTML fragment with block link
819 function blockLink( $userId, $userText ) {
820 $blockPage = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
821 $blockLink = $this->makeKnownLinkObj( $blockPage,
822 wfMsgHtml( 'blocklink' ), 'ip=' . urlencode( $userText ) );
827 * Generate a user link if the current user is allowed to view it
828 * @param Revision $rev
829 * @return string HTML
831 function revUserLink( $rev ) {
832 if( $rev->userCan( MW_REV_DELETED_USER
) ) {
833 $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() );
835 $link = wfMsgHtml( 'rev-deleted-user' );
837 if( $rev->isDeleted( MW_REV_DELETED_USER
) ) {
838 return '<span class="history-deleted">' . $link . '</span>';
844 * Generate a user tool link cluster if the current user is allowed to view it
845 * @param Revision $rev
846 * @return string HTML
848 function revUserTools( $rev ) {
849 if( $rev->userCan( MW_REV_DELETED_USER
) ) {
850 $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() ) .
852 $this->userToolLinks( $rev->getRawUser(), $rev->getRawUserText() );
854 $link = wfMsgHtml( 'rev-deleted-user' );
856 if( $rev->isDeleted( MW_REV_DELETED_USER
) ) {
857 return '<span class="history-deleted">' . $link . '</span>';
863 * This function is called by all recent changes variants, by the page history,
864 * and by the user contributions list. It is responsible for formatting edit
865 * comments. It escapes any HTML in the comment, but adds some CSS to format
866 * auto-generated comments (from section editing) and formats [[wikilinks]].
868 * The $title parameter must be a title OBJECT. It is used to generate a
869 * direct link to the section in the autocomment.
870 * @author Erik Moeller <moeller@scireview.de>
872 * Note: there's not always a title to pass to this function.
873 * Since you can't set a default parameter for a reference, I've turned it
874 * temporarily to a value pass. Should be adjusted further. --brion
876 function formatComment($comment, $title = NULL) {
877 $fname = 'Linker::formatComment';
878 wfProfileIn( $fname );
881 $comment = str_replace( "\n", " ", $comment );
882 $comment = htmlspecialchars( $comment );
884 # The pattern for autogen comments is / * foo * /, which makes for
886 # We look for all comments, match any text before and after the comment,
887 # add a separator where needed and format the comment itself with CSS
888 while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
896 # This is hackish but should work in most cases.
897 $section = str_replace( '[[', '', $section );
898 $section = str_replace( ']]', '', $section );
899 $sectionTitle = wfClone( $title );
900 $sectionTitle->mFragment
= $section;
901 $link = $this->makeKnownLinkObj( $sectionTitle, wfMsg( 'sectionlink' ) );
905 if($pre) { $auto = $sep.' '.$auto; }
906 if($post) { $auto .= ' '.$sep; }
907 $auto='<span class="autocomment">'.$auto.'</span>';
908 $comment=$pre.$auto.$post;
911 # format regular and media links - all other wiki formatting
913 $medians = $wgContLang->getNsText( NS_MEDIA
) . ':';
914 while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
915 # Handle link renaming [[foo|text]] will show link as "text"
916 if( "" != $match[3] ) {
921 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
922 # Media link; trail not supported.
923 $linkRegexp = '/\[\[(.*?)\]\]/';
924 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
927 if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
928 $trail = $submatch[1];
932 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
933 if ($match[1][0] == ':')
934 $match[1] = substr($match[1], 1);
935 $thelink = $this->makeLink( $match[1], $text, "", $trail );
937 $comment = preg_replace( $linkRegexp, wfRegexReplacement( $thelink ), $comment, 1 );
939 wfProfileOut( $fname );
944 * Wrap a comment in standard punctuation and formatting if
945 * it's non-empty, otherwise return empty string.
947 * @param string $comment
948 * @param Title $title
952 function commentBlock( $comment, $title = NULL ) {
953 // '*' used to be the comment inserted by the software way back
954 // in antiquity in case none was provided, here for backwards
955 // compatability, acc. to brion -ævar
956 if( $comment == '' ||
$comment == '*' ) {
959 $formatted = $this->formatComment( $comment, $title );
960 return " <span class='comment'>($formatted)</span>";
965 * Wrap and format the given revision's comment block, if the current
966 * user is allowed to view it.
967 * @param Revision $rev
968 * @return string HTML
970 function revComment( $rev ) {
971 if( $rev->userCan( MW_REV_DELETED_COMMENT
) ) {
972 $block = $this->commentBlock( $rev->getRawComment(), $rev->getTitle() );
974 $block = " <span class='comment'>" .
975 wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
977 if( $rev->isDeleted( MW_REV_DELETED_COMMENT
) ) {
978 return " <span class='history-deleted'>$block</span>";
983 /** @todo document */
984 function tocIndent() {
988 /** @todo document */
989 function tocUnindent($level) {
990 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ?
$level : 0 );
994 * parameter level defines if we are on an indentation level
996 function tocLine( $anchor, $tocline, $tocnumber, $level ) {
997 return "\n<li class='toclevel-$level'><a href=\"#" .
998 $anchor . '"><span class="tocnumber">' .
999 $tocnumber . '</span> <span class="toctext">' .
1000 $tocline . '</span></a>';
1003 /** @todo document */
1004 function tocLineEnd() {
1008 /** @todo document */
1009 function tocList($toc) {
1010 global $wgJsMimeType;
1011 $title = wfMsgForContent('toc') ;
1013 '<table id="toc" class="toc" summary="' . $title .'"><tr><td>'
1014 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
1016 # no trailing newline, script should not be wrapped in a
1018 . "</ul>\n</td></tr></table>"
1019 . '<script type="' . $wgJsMimeType . '">'
1020 . ' if (window.showTocToggle) {'
1021 . ' var tocShowText = "' . wfEscapeJsString( wfMsgForContent('showtoc') ) . '";'
1022 . ' var tocHideText = "' . wfEscapeJsString( wfMsgForContent('hidetoc') ) . '";'
1023 . ' showTocToggle();'
1028 /** @todo document */
1029 function editSectionLinkForOther( $title, $section ) {
1032 $title = Title
::newFromText( $title );
1033 $editurl = '§ion='.$section;
1034 $url = $this->makeKnownLinkObj( $title, wfMsg('editsection'), 'action=edit'.$editurl );
1036 if( $wgContLang->isRTL() ) {
1038 $nearside = 'right';
1043 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
1048 * @param Title $title
1049 * @param integer $section
1050 * @param string $hint Link title, or default if omitted or empty
1052 function editSectionLink( $nt, $section, $hint='' ) {
1055 $editurl = '§ion='.$section;
1056 $hint = ( $hint=='' ) ?
'' : ' title="' . wfMsgHtml( 'editsectionhint', htmlspecialchars( $hint ) ) . '"';
1057 $url = $this->makeKnownLinkObj( $nt, wfMsg('editsection'), 'action=edit'.$editurl, '', '', '', $hint );
1059 if( $wgContLang->isRTL() ) {
1061 $nearside = 'right';
1066 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
1070 * Split a link trail, return the "inside" portion and the remainder of the trail
1071 * as a two-element array
1075 function splitTrail( $trail ) {
1076 static $regex = false;
1077 if ( $regex === false ) {
1079 $regex = $wgContLang->linkTrail();
1082 if ( '' != $trail ) {
1083 if ( preg_match( $regex, $trail, $m ) ) {
1088 return array( $inside, $trail );