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}\"";
73 * @param $nt Title object.
74 * @param $text String: FIXME
75 * @param $broken Boolean: FIXME, default 'false'.
77 function getInternalLinkAttributesObj( &$nt, $text, $broken = false ) {
78 if( $broken == 'stub' ) {
80 } else if ( $broken == 'yes' ) {
86 $r .= ' title="' . $nt->getEscapedText() . '"';
91 * This function is a shortcut to makeLinkObj(Title::newFromText($title),...). Do not call
92 * it if you already have a title object handy. See makeLinkObj for further documentation.
94 * @param $title String: the text of the title
95 * @param $text String: link text
96 * @param $query String: optional query part
97 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
98 * be included in the link text. Other characters will be appended after
99 * the end of the link.
101 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
102 wfProfileIn( 'Linker::makeLink' );
103 $nt = Title
::newFromText( $title );
105 $result = $this->makeLinkObj( Title
::newFromText( $title ), $text, $query, $trail );
107 wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" );
108 $result = $text == "" ?
$title : $text;
111 wfProfileOut( 'Linker::makeLink' );
116 * This function is a shortcut to makeKnownLinkObj(Title::newFromText($title),...). Do not call
117 * it if you already have a title object handy. See makeKnownLinkObj for further documentation.
119 * @param $title String: the text of the title
120 * @param $text String: link text
121 * @param $query String: optional query part
122 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
123 * be included in the link text. Other characters will be appended after
124 * the end of the link.
126 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
127 $nt = Title
::newFromText( $title );
129 return $this->makeKnownLinkObj( Title
::newFromText( $title ), $text, $query, $trail, $prefix , $aprops );
131 wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" );
132 return $text == '' ?
$title : $text;
137 * This function is a shortcut to makeBrokenLinkObj(Title::newFromText($title),...). Do not call
138 * it if you already have a title object handy. See makeBrokenLinkObj for further documentation.
140 * @param string $title The text of the title
141 * @param string $text Link text
142 * @param string $query Optional query part
143 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
144 * be included in the link text. Other characters will be appended after
145 * the end of the link.
147 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
148 $nt = Title
::newFromText( $title );
150 return $this->makeBrokenLinkObj( Title
::newFromText( $title ), $text, $query, $trail );
152 wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" );
153 return $text == '' ?
$title : $text;
158 * This function is a shortcut to makeStubLinkObj(Title::newFromText($title),...). Do not call
159 * it if you already have a title object handy. See makeStubLinkObj for further documentation.
161 * @param $title String: the text of the title
162 * @param $text String: link text
163 * @param $query String: optional query part
164 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
165 * be included in the link text. Other characters will be appended after
166 * the end of the link.
168 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
169 $nt = Title
::newFromText( $title );
171 return $this->makeStubLinkObj( Title
::newFromText( $title ), $text, $query, $trail );
173 wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" );
174 return $text == '' ?
$title : $text;
179 * Make a link for a title which may or may not be in the database. If you need to
180 * call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
181 * call to this will result in a DB query.
183 * @param $title String: the text of the title
184 * @param $text String: link text
185 * @param $query String: optional query part
186 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
187 * be included in the link text. Other characters will be appended after
188 * the end of the link.
190 function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
192 $fname = 'Linker::makeLinkObj';
193 wfProfileIn( $fname );
196 if ( ! is_object($nt) ) {
197 # wfDebugDieBacktrace();
198 wfProfileOut( $fname );
199 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
202 $ns = $nt->getNamespace();
203 $dbkey = $nt->getDBkey();
204 if ( $nt->isExternal() ) {
205 $u = $nt->getFullURL();
206 $link = $nt->getPrefixedURL();
207 if ( '' == $text ) { $text = $nt->getPrefixedText(); }
208 $style = $this->getInterwikiLinkAttributes( $link, $text, 'extiw' );
211 if ( '' != $trail ) {
212 if ( preg_match( '/^([a-z]+)(.*)$$/sD', $trail, $m ) ) {
218 # Check for anchors, normalize the anchor
220 $parts = explode( '#', $u, 2 );
221 if ( count( $parts ) == 2 ) {
222 $anchor = urlencode( Sanitizer
::decodeCharReferences( str_replace(' ', '_', $parts[1] ) ) );
223 $replacearray = array(
227 $u = $parts[0] . '#' .
228 str_replace( array_keys( $replacearray ),
229 array_values( $replacearray ),
233 $t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
235 wfProfileOut( $fname );
237 } elseif ( $nt->isAlwaysKnown() ) {
238 # Image links, special page links and self-links with fragements are always known.
239 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
241 wfProfileIn( $fname.'-immediate' );
242 # Work out link colour immediately
243 $aid = $nt->getArticleID() ;
245 $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
247 $threshold = $wgUser->getOption('stubthreshold') ;
248 if ( $threshold > 0 ) {
249 $dbr =& wfGetDB( DB_SLAVE
);
250 $s = $dbr->selectRow(
254 'page_is_redirect' ),
255 array( 'page_id' => $aid ), $fname ) ;
256 if ( $s !== false ) {
257 $size = $s->page_len
;
258 if ( $s->page_is_redirect
OR $s->page_namespace
!= NS_MAIN
) {
259 $size = $threshold*2 ; # Really big
262 $size = $threshold*2 ; # Really big
267 if ( $size < $threshold ) {
268 $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
270 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
273 wfProfileOut( $fname.'-immediate' );
275 wfProfileOut( $fname );
280 * Make a link for a title which definitely exists. This is faster than makeLinkObj because
281 * it doesn't have to do a database query. It's also valid for interwiki titles and special
284 * @param $nt Title object of target page
285 * @param $text String: text to replace the title
286 * @param $query String: link target
287 * @param $trail String: text after link
288 * @param $prefix String: text before link text
289 * @param $aprops String: extra attributes to the a-element
290 * @param $style String: style to apply - if empty, use getInternalLinkAttributesObj instead
291 * @return the a-element
293 function makeKnownLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
295 $fname = 'Linker::makeKnownLinkObj';
296 wfProfileIn( $fname );
298 if ( !is_object( $nt ) ) {
299 wfProfileOut( $fname );
303 $u = $nt->escapeLocalURL( $query );
304 if ( $nt->getFragment() != '' ) {
305 if( $nt->getPrefixedDbkey() == '' ) {
308 $text = htmlspecialchars( $nt->getFragment() );
311 $anchor = urlencode( Sanitizer
::decodeCharReferences( str_replace( ' ', '_', $nt->getFragment() ) ) );
312 $replacearray = array(
316 $u .= '#' . str_replace(array_keys($replacearray),array_values($replacearray),$anchor);
319 $text = htmlspecialchars( $nt->getPrefixedText() );
321 if ( $style == '' ) {
322 $style = $this->getInternalLinkAttributesObj( $nt, $text );
325 if ( $aprops !== '' ) $aprops = ' ' . $aprops;
327 list( $inside, $trail ) = Linker
::splitTrail( $trail );
328 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
329 wfProfileOut( $fname );
334 * Make a red link to the edit page of a given title.
336 * @param $title String: The text of the title
337 * @param $text String: Link text
338 * @param $query String: Optional query part
339 * @param $trail String: Optional trail. Alphabetic characters at the start of this string will
340 * be included in the link text. Other characters will be appended after
341 * the end of the link.
343 function makeBrokenLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
345 if ( ! isset($nt) ) {
346 # wfDebugDieBacktrace();
347 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
350 $fname = 'Linker::makeBrokenLinkObj';
351 wfProfileIn( $fname );
353 if ( '' == $query ) {
356 $q = 'action=edit&'.$query;
358 $u = $nt->escapeLocalURL( $q );
361 $text = htmlspecialchars( $nt->getPrefixedText() );
363 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
365 list( $inside, $trail ) = Linker
::splitTrail( $trail );
366 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
368 wfProfileOut( $fname );
373 * Make a brown link to a short article.
375 * @param $title String: the text of the title
376 * @param $text String: link text
377 * @param $query String: optional query part
378 * @param $trail String: optional trail. Alphabetic characters at the start of this string will
379 * be included in the link text. Other characters will be appended after
380 * the end of the link.
382 function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
383 $link = $nt->getPrefixedURL();
385 $u = $nt->escapeLocalURL( $query );
388 $text = htmlspecialchars( $nt->getPrefixedText() );
390 $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' );
392 list( $inside, $trail ) = Linker
::splitTrail( $trail );
393 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
398 * Generate either a normal exists-style link or a stub link, depending
399 * on the given page size.
401 * @param $size Integer
402 * @param $nt Title object.
403 * @param $text String
404 * @param $query String
405 * @param $trail String
406 * @param $prefix String
407 * @return string HTML of link
409 function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
411 $threshold = intval( $wgUser->getOption( 'stubthreshold' ) );
412 if( $size < $threshold ) {
413 return $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
415 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
420 * Make appropriate markup for a link to the current article. This is currently rendered
421 * as the bold link text. The calling sequence is the same as the other make*LinkObj functions,
422 * despite $query not being used.
424 function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
426 $text = htmlspecialchars( $nt->getPrefixedText() );
428 list( $inside, $trail ) = Linker
::splitTrail( $trail );
429 return "<strong class=\"selflink\">{$prefix}{$text}{$inside}</strong>{$trail}";
432 /** @todo document */
433 function fnamePart( $url ) {
434 $basename = strrchr( $url, '/' );
435 if ( false === $basename ) {
438 $basename = substr( $basename, 1 );
440 return htmlspecialchars( $basename );
443 /** Obsolete alias */
444 function makeImage( $url, $alt = '' ) {
445 return $this->makeExternalImage( $url, $alt );
448 /** @todo document */
449 function makeExternalImage( $url, $alt = '' ) {
451 $alt = $this->fnamePart( $url );
453 $s = '<img src="'.$url.'" alt="'.$alt.'" />';
457 /** @todo document */
458 function makeImageLinkObj( $nt, $label, $alt, $align = '', $width = false, $height = false, $framed = false,
459 $thumb = false, $manual_thumb = '' )
461 global $wgContLang, $wgUser, $wgThumbLimits;
463 $img = new Image( $nt );
464 if ( !$img->allowInlineDisplay() && $img->exists() ) {
465 return $this->makeKnownLinkObj( $nt );
468 $url = $img->getViewURL();
469 $error = $prefix = $postfix = '';
471 wfDebug( "makeImageLinkObj: '$width'x'$height'\n" );
473 if ( 'center' == $align )
475 $prefix = '<div class="center">';
480 if ( $thumb ||
$framed ) {
482 # Create a thumbnail. Alignment depends on language
483 # writing direction, # right aligned for left-to-right-
484 # languages ("Western languages"), left-aligned
485 # for right-to-left-languages ("Semitic languages")
487 # If thumbnail width has not been provided, it is set
488 # to the default user option as specified in Language*.php
489 if ( $align == '' ) {
490 $align = $wgContLang->isRTL() ?
'left' : 'right';
494 if ( $width === false ) {
495 $wopt = $wgUser->getOption( 'thumbsize' );
497 if( !isset( $wgThumbLimits[$wopt] ) ) {
498 $wopt = User
::getDefaultOption( 'thumbsize' );
501 $width = min( $img->getWidth(), $wgThumbLimits[$wopt] );
504 return $prefix.$this->makeThumbLinkObj( $img, $label, $alt, $align, $width, $height, $framed, $manual_thumb ).$postfix;
507 if ( $width && $img->exists() ) {
509 # Create a resized image, without the additional thumbnail
512 if ( $height == false )
514 if ( $manual_thumb == '') {
515 $thumb = $img->getThumbnail( $width, $height );
517 // In most cases, $width = $thumb->width or $height = $thumb->height.
518 // If not, we're scaling the image larger than it can be scaled,
519 // so we send to the browser a smaller thumbnail, and let the client do the scaling.
521 if ($height != -1 && $width > $thumb->width
* $height / $thumb->height
) {
522 // $height is the limiting factor, not $width
523 // set $width to the largest it can be, such that the resulting
524 // scaled height is at most $height
525 $width = floor($thumb->width
* $height / $thumb->height
);
527 $height = round($thumb->height
* $width / $thumb->width
);
529 wfDebug( "makeImageLinkObj: client-size set to '$width x $height'\n" );
530 $url = $thumb->getUrl();
532 $error = htmlspecialchars( $img->getLastError() );
536 $width = $img->width
;
537 $height = $img->height
;
540 wfDebug( "makeImageLinkObj2: '$width'x'$height'\n" );
541 $u = $nt->escapeLocalURL();
544 } elseif ( $url == '' ) {
545 $s = $this->makeBrokenImageLinkObj( $img->getTitle() );
546 //$s .= "<br />{$alt}<br />{$url}<br />\n";
548 $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
549 '<img src="'.$url.'" alt="'.$alt.'" ' .
551 ?
( 'width="'.$width.'" height="'.$height.'" ' )
553 'longdesc="'.$u.'" /></a>';
555 if ( '' != $align ) {
556 $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
558 return str_replace("\n", ' ',$prefix.$s.$postfix);
562 * Make HTML for a thumbnail including image, border and caption
563 * $img is an Image object
565 function makeThumbLinkObj( $img, $label = '', $alt, $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
566 global $wgStylePath, $wgContLang;
567 $url = $img->getViewURL();
571 $width = $height = 0;
572 if ( $img->exists() ) {
573 $width = $img->getWidth();
574 $height = $img->getHeight();
576 if ( 0 == $width ||
0 == $height ) {
577 $width = $height = 180;
579 if ( $boxwidth == 0 ) {
583 // Use image dimensions, don't scale
585 $boxheight = $height;
588 if ( $boxheight === false )
590 if ( '' == $manual_thumb ) {
591 $thumb = $img->getThumbnail( $boxwidth, $boxheight );
593 $thumbUrl = $thumb->getUrl();
594 $boxwidth = $thumb->width
;
595 $boxheight = $thumb->height
;
597 $error = $img->getLastError();
601 $oboxwidth = $boxwidth +
2;
603 if ( $manual_thumb != '' ) # Use manually specified thumbnail
605 $manual_title = Title
::makeTitleSafe( NS_IMAGE
, $manual_thumb ); #new Title ( $manual_thumb ) ;
606 $manual_img = new Image( $manual_title );
607 $thumbUrl = $manual_img->getViewURL();
608 if ( $manual_img->exists() )
610 $width = $manual_img->getWidth();
611 $height = $manual_img->getHeight();
613 $boxheight = $height ;
614 $oboxwidth = $boxwidth +
2 ;
618 $u = $img->getEscapeLocalURL();
620 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
621 $magnifyalign = $wgContLang->isRTL() ?
'left' : 'right';
622 $textalign = $wgContLang->isRTL() ?
' style="text-align:right"' : '';
624 $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
625 if( $thumbUrl == '' ) {
626 // Couldn't generate thumbnail? Scale the image client-side.
630 $s .= htmlspecialchars( $error );
632 } elseif( !$img->exists() ) {
633 $s .= $this->makeBrokenImageLinkObj( $img->getTitle() );
636 $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
637 '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
638 'width="'.$boxwidth.'" height="'.$boxheight.'" ' .
639 'longdesc="'.$u.'" /></a>';
643 $zoomicon = '<div class="magnify" style="float:'.$magnifyalign.'">'.
644 '<a href="'.$u.'" class="internal" title="'.$more.'">'.
645 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
646 'width="15" height="11" alt="'.$more.'" /></a></div>';
649 $s .= ' <div class="thumbcaption" '.$textalign.'>'.$zoomicon.$label."</div></div></div>";
650 return str_replace("\n", ' ', $s);
654 * Pass a title object, not a title string
656 function makeBrokenImageLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
658 if ( ! isset($nt) ) {
659 # wfDebugDieBacktrace();
660 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
663 $fname = 'Linker::makeBrokenImageLinkObj';
664 wfProfileIn( $fname );
666 $q = 'wpDestFile=' . urlencode( $nt->getDBkey() );
667 if ( '' != $query ) {
670 $uploadTitle = Title
::makeTitle( NS_SPECIAL
, 'Upload' );
671 $url = $uploadTitle->escapeLocalURL( $q );
674 $text = htmlspecialchars( $nt->getPrefixedText() );
676 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
677 list( $inside, $trail ) = Linker
::splitTrail( $trail );
678 $s = "<a href=\"{$url}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
680 wfProfileOut( $fname );
684 /** @todo document */
685 function makeMediaLink( $name, /* wtf?! */ $url, $alt = '' ) {
686 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
687 return $this->makeMediaLinkObj( $nt, $alt );
691 * Create a direct link to a given uploaded file.
693 * @param $title Title object.
694 * @param $text String: pre-sanitized HTML
695 * @param $nourl Boolean: Mask absolute URLs, so the parser doesn't
696 * linkify them (it is currently not context-aware)
697 * @return string HTML
700 * @todo Handle invalid or missing images better.
702 function makeMediaLinkObj( $title, $text = '' ) {
703 if( is_null( $title ) ) {
704 ### HOTFIX. Instead of breaking, return empty string.
707 $name = $title->getDBKey();
708 $img = new Image( $title );
709 if( $img->exists() ) {
710 $url = $img->getURL();
713 $upload = Title
::makeTitle( NS_SPECIAL
, 'Upload' );
714 $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $img->getName() ) );
717 $alt = htmlspecialchars( $title->getText() );
721 $u = htmlspecialchars( $url );
722 return "<a href=\"{$u}\" class='$class' title=\"{$alt}\">{$text}</a>";
726 /** @todo document */
727 function specialLink( $name, $key = '' ) {
730 if ( '' == $key ) { $key = strtolower( $name ); }
731 $pn = $wgContLang->ucfirst( $name );
732 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
736 /** @todo document */
737 function makeExternalLink( $url, $text, $escape = true, $linktype = '', $ns = null ) {
738 $style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
739 global $wgNoFollowLinks, $wgNoFollowNsExceptions;
740 if( $wgNoFollowLinks && !(isset($ns) && in_array($ns, $wgNoFollowNsExceptions)) ) {
741 $style .= ' rel="nofollow"';
743 $url = htmlspecialchars( $url );
745 $text = htmlspecialchars( $text );
747 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
751 * Make user link (or user contributions for unregistered users)
752 * @param $userId Integer: user id in database.
753 * @param $userText String: user name in database
754 * @return string HTML fragment
757 function userLink( $userId, $userText ) {
758 $encName = htmlspecialchars( $userText );
760 $contribsPage = Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
761 return $this->makeKnownLinkObj( $contribsPage,
762 $encName, 'target=' . urlencode( $userText ) );
764 $userPage = Title
::makeTitle( NS_USER
, $userText );
765 return $this->makeLinkObj( $userPage, $encName );
770 * @param $userId Integer: user id in database.
771 * @param $userText String: user name in database.
772 * @return string HTML fragment with talk and/or block links
775 function userToolLinks( $userId, $userText ) {
776 global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans;
777 $talkable = !( $wgDisableAnonTalk && 0 == $userId );
778 $blockable = ( $wgSysopUserBans ||
0 == $userId );
782 $items[] = $this->userTalkLink( $userId, $userText );
785 $contribsPage = Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
786 $items[] = $this->makeKnownLinkObj( $contribsPage,
787 wfMsgHtml( 'contribslink' ), 'target=' . urlencode( $userText ) );
789 if( $blockable && $wgUser->isAllowed( 'block' ) ) {
790 $items[] = $this->blockLink( $userId, $userText );
794 return ' (' . implode( ' | ', $items ) . ')';
801 * @param $userId Integer: user id in database.
802 * @param $userText String: user name in database.
803 * @return string HTML fragment with user talk link
806 function userTalkLink( $userId, $userText ) {
808 $talkname = $wgLang->getNsText( NS_TALK
); # use the shorter name
810 $userTalkPage = Title
::makeTitle( NS_USER_TALK
, $userText );
811 $userTalkLink = $this->makeLinkObj( $userTalkPage, $talkname );
812 return $userTalkLink;
816 * @param $userId Integer: userid
817 * @param $userText String: user name in database.
818 * @return string HTML fragment with block link
821 function blockLink( $userId, $userText ) {
822 $blockPage = Title
::makeTitle( NS_SPECIAL
, 'Blockip' );
823 $blockLink = $this->makeKnownLinkObj( $blockPage,
824 wfMsgHtml( 'blocklink' ), 'ip=' . urlencode( $userText ) );
829 * Generate a user link if the current user is allowed to view it
830 * @param $rev Revision object.
831 * @return string HTML
833 function revUserLink( $rev ) {
834 if( $rev->userCan( MW_REV_DELETED_USER
) ) {
835 $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() );
837 $link = wfMsgHtml( 'rev-deleted-user' );
839 if( $rev->isDeleted( MW_REV_DELETED_USER
) ) {
840 return '<span class="history-deleted">' . $link . '</span>';
846 * Generate a user tool link cluster if the current user is allowed to view it
847 * @param $rev Revision object.
848 * @return string HTML
850 function revUserTools( $rev ) {
851 if( $rev->userCan( MW_REV_DELETED_USER
) ) {
852 $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() ) .
854 $this->userToolLinks( $rev->getRawUser(), $rev->getRawUserText() );
856 $link = wfMsgHtml( 'rev-deleted-user' );
858 if( $rev->isDeleted( MW_REV_DELETED_USER
) ) {
859 return '<span class="history-deleted">' . $link . '</span>';
865 * This function is called by all recent changes variants, by the page history,
866 * and by the user contributions list. It is responsible for formatting edit
867 * comments. It escapes any HTML in the comment, but adds some CSS to format
868 * auto-generated comments (from section editing) and formats [[wikilinks]].
870 * The $title parameter must be a title OBJECT. It is used to generate a
871 * direct link to the section in the autocomment.
872 * @author Erik Moeller <moeller@scireview.de>
874 * Note: there's not always a title to pass to this function.
875 * Since you can't set a default parameter for a reference, I've turned it
876 * temporarily to a value pass. Should be adjusted further. --brion
878 function formatComment($comment, $title = NULL) {
879 $fname = 'Linker::formatComment';
880 wfProfileIn( $fname );
883 $comment = str_replace( "\n", " ", $comment );
884 $comment = htmlspecialchars( $comment );
886 # The pattern for autogen comments is / * foo * /, which makes for
888 # We look for all comments, match any text before and after the comment,
889 # add a separator where needed and format the comment itself with CSS
890 while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
898 # This is hackish but should work in most cases.
899 $section = str_replace( '[[', '', $section );
900 $section = str_replace( ']]', '', $section );
901 $sectionTitle = wfClone( $title );
902 $sectionTitle->mFragment
= $section;
903 $link = $this->makeKnownLinkObj( $sectionTitle, wfMsg( 'sectionlink' ) );
907 if($pre) { $auto = $sep.' '.$auto; }
908 if($post) { $auto .= ' '.$sep; }
909 $auto='<span class="autocomment">'.$auto.'</span>';
910 $comment=$pre.$auto.$post;
913 # format regular and media links - all other wiki formatting
915 $medians = $wgContLang->getNsText( NS_MEDIA
) . ':';
916 while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
917 # Handle link renaming [[foo|text]] will show link as "text"
918 if( "" != $match[3] ) {
923 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
924 # Media link; trail not supported.
925 $linkRegexp = '/\[\[(.*?)\]\]/';
926 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
929 if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
930 $trail = $submatch[1];
934 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
935 if ($match[1][0] == ':')
936 $match[1] = substr($match[1], 1);
937 $thelink = $this->makeLink( $match[1], $text, "", $trail );
939 $comment = preg_replace( $linkRegexp, wfRegexReplacement( $thelink ), $comment, 1 );
941 wfProfileOut( $fname );
946 * Wrap a comment in standard punctuation and formatting if
947 * it's non-empty, otherwise return empty string.
949 * @param $comment String: the comment.
950 * @param $title Title object.
954 function commentBlock( $comment, $title = NULL ) {
955 // '*' used to be the comment inserted by the software way back
956 // in antiquity in case none was provided, here for backwards
957 // compatability, acc. to brion -ævar
958 if( $comment == '' ||
$comment == '*' ) {
961 $formatted = $this->formatComment( $comment, $title );
962 return " <span class='comment'>($formatted)</span>";
967 * Wrap and format the given revision's comment block, if the current
968 * user is allowed to view it.
969 * @param $rev Revision object.
970 * @return string HTML
972 function revComment( $rev ) {
973 if( $rev->userCan( MW_REV_DELETED_COMMENT
) ) {
974 $block = $this->commentBlock( $rev->getRawComment(), $rev->getTitle() );
976 $block = " <span class='comment'>" .
977 wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
979 if( $rev->isDeleted( MW_REV_DELETED_COMMENT
) ) {
980 return " <span class='history-deleted'>$block</span>";
985 /** @todo document */
986 function tocIndent() {
990 /** @todo document */
991 function tocUnindent($level) {
992 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ?
$level : 0 );
996 * parameter level defines if we are on an indentation level
998 function tocLine( $anchor, $tocline, $tocnumber, $level ) {
999 return "\n<li class='toclevel-$level'><a href=\"#" .
1000 $anchor . '"><span class="tocnumber">' .
1001 $tocnumber . '</span> <span class="toctext">' .
1002 $tocline . '</span></a>';
1005 /** @todo document */
1006 function tocLineEnd() {
1010 /** @todo document */
1011 function tocList($toc) {
1012 global $wgJsMimeType;
1013 $title = wfMsgForContent('toc') ;
1015 '<table id="toc" class="toc" summary="' . $title .'"><tr><td>'
1016 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
1018 # no trailing newline, script should not be wrapped in a
1020 . "</ul>\n</td></tr></table>"
1021 . '<script type="' . $wgJsMimeType . '">'
1022 . ' if (window.showTocToggle) {'
1023 . ' var tocShowText = "' . wfEscapeJsString( wfMsgForContent('showtoc') ) . '";'
1024 . ' var tocHideText = "' . wfEscapeJsString( wfMsgForContent('hidetoc') ) . '";'
1025 . ' showTocToggle();'
1030 /** @todo document */
1031 function editSectionLinkForOther( $title, $section ) {
1034 $title = Title
::newFromText( $title );
1035 $editurl = '§ion='.$section;
1036 $url = $this->makeKnownLinkObj( $title, wfMsg('editsection'), 'action=edit'.$editurl );
1038 if( $wgContLang->isRTL() ) {
1040 $nearside = 'right';
1045 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
1050 * @param $title Title object.
1051 * @param $section Integer: section number.
1052 * @param $hint Link String: title, or default if omitted or empty
1054 function editSectionLink( $nt, $section, $hint='' ) {
1057 $editurl = '§ion='.$section;
1058 $hint = ( $hint=='' ) ?
'' : ' title="' . wfMsgHtml( 'editsectionhint', htmlspecialchars( $hint ) ) . '"';
1059 $url = $this->makeKnownLinkObj( $nt, wfMsg('editsection'), 'action=edit'.$editurl, '', '', '', $hint );
1061 if( $wgContLang->isRTL() ) {
1063 $nearside = 'right';
1068 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
1072 * Split a link trail, return the "inside" portion and the remainder of the trail
1073 * as a two-element array
1077 function splitTrail( $trail ) {
1078 static $regex = false;
1079 if ( $regex === false ) {
1081 $regex = $wgContLang->linkTrail();
1084 if ( '' != $trail ) {
1085 if ( preg_match( $regex, $trail, $m ) ) {
1090 return array( $inside, $trail );