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.
19 var $linktrail ; # linktrail regexp
20 var $postParseLinkColour = false;
25 $this->linktrail
= $wgContLang->linkTrail();
27 # Cache option lookups done very frequently
28 $options = array( 'highlightbroken', 'hover' );
29 foreach( $options as $opt ) {
31 $this->mOptions
[$opt] = $wgUser->getOption( $opt );
36 * Get/set accessor for delayed link colouring
38 function postParseLinkColour( $setting = NULL ) {
39 return wfSetVar( $this->postParseLinkColour
, $setting );
43 function getExternalLinkAttributes( $link, $text, $class='' ) {
46 $same = ($link == $text);
47 $link = urldecode( $link );
48 $link = $wgContLang->checkTitleEncoding( $link );
49 $link = preg_replace( '/[\\x00-\\x1f_]/', ' ', $link );
50 $link = htmlspecialchars( $link );
52 $r = ($class != '') ?
" class='$class'" : " class='external'";
54 if( !$same && $this->mOptions
['hover'] ) {
55 $r .= " title=\"{$link}\"";
61 function getInternalLinkAttributes( $link, $text, $broken = false ) {
62 $link = urldecode( $link );
63 $link = str_replace( '_', ' ', $link );
64 $link = htmlspecialchars( $link );
66 if( $broken == 'stub' ) {
68 } else if ( $broken == 'yes' ) {
74 if( $this->mOptions
['hover'] ) {
75 $r .= " title=\"{$link}\"";
83 function getInternalLinkAttributesObj( &$nt, $text, $broken = false ) {
84 if( $broken == 'stub' ) {
86 } else if ( $broken == 'yes' ) {
92 if( $this->mOptions
['hover'] ) {
93 $r .= ' title="' . $nt->getEscapedText() . '"';
99 * Note: This function MUST call getArticleID() on the link,
100 * otherwise the cache won't get updated properly. See LINKCACHE.DOC.
102 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
103 wfProfileIn( 'Skin::makeLink' );
104 $nt = Title
::newFromText( $title );
106 $result = $this->makeLinkObj( Title
::newFromText( $title ), $text, $query, $trail );
108 wfDebug( 'Invalid title passed to Skin::makeLink(): "'.$title."\"\n" );
109 $result = $text == "" ?
$title : $text;
112 wfProfileOut( 'Skin::makeLink' );
116 /** @todo document */
117 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
118 $nt = Title
::newFromText( $title );
120 return $this->makeKnownLinkObj( Title
::newFromText( $title ), $text, $query, $trail, $prefix , $aprops );
122 wfDebug( 'Invalid title passed to Skin::makeKnownLink(): "'.$title."\"\n" );
123 return $text == '' ?
$title : $text;
127 /** @todo document */
128 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
129 $nt = Title
::newFromText( $title );
131 return $this->makeBrokenLinkObj( Title
::newFromText( $title ), $text, $query, $trail );
133 wfDebug( 'Invalid title passed to Skin::makeBrokenLink(): "'.$title."\"\n" );
134 return $text == '' ?
$title : $text;
138 /** @todo document */
139 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
140 $nt = Title
::newFromText( $title );
142 return $this->makeStubLinkObj( Title
::newFromText( $title ), $text, $query, $trail );
144 wfDebug( 'Invalid title passed to Skin::makeStubLink(): "'.$title."\"\n" );
145 return $text == '' ?
$title : $text;
150 * Pass a title object, not a title string
152 function makeLinkObj( &$nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
153 global $wgOut, $wgUser, $wgLinkHolders;
154 $fname = 'Skin::makeLinkObj';
155 wfProfileIn( $fname );
158 if ( ! isset($nt) ) {
159 # wfDebugDieBacktrace();
160 wfProfileOut( $fname );
161 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
164 $ns = $nt->getNamespace();
165 $dbkey = $nt->getDBkey();
166 if ( $nt->isExternal() ) {
167 $u = $nt->getFullURL();
168 $link = $nt->getPrefixedURL();
169 if ( '' == $text ) { $text = $nt->getPrefixedText(); }
170 $style = $this->getExternalLinkAttributes( $link, $text, 'extiw' );
173 if ( '' != $trail ) {
174 if ( preg_match( '/^([a-z]+)(.*)$$/sD', $trail, $m ) ) {
179 $t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
180 if( $this->postParseLinkColour
) {
181 # There's no existence check, but this will prevent
182 # interwiki links from being parsed as external links.
183 global $wgInterwikiLinkHolders;
184 $nr = array_push($wgInterwikiLinkHolders, $t);
185 $retVal = '<!--IWLINK '. ($nr-1) ."-->{$trail}";
189 } elseif ( 0 == $ns && "" == $dbkey ) {
190 # A self-link with a fragment; skip existence check.
191 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
192 } elseif ( ( NS_SPECIAL
== $ns ) ||
( NS_IMAGE
== $ns ) ) {
193 # These are always shown as existing, currently.
194 # Special pages don't exist in the database; images may
195 # occasionally be present when there is no description
196 # page per se, so we always shown them.
197 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
198 } elseif ( $this->postParseLinkColour
) {
199 wfProfileIn( $fname.'-postparse' );
200 # Insert a placeholder, and we'll work out the existence checks
201 # in a big lump later.
203 if ( '' != $trail ) {
204 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
210 # These get picked up by Parser::replaceLinkHolders()
211 $nr = array_push( $wgLinkHolders['namespaces'], $nt->getNamespace() );
212 $wgLinkHolders['dbkeys'][] = $dbkey;
213 $wgLinkHolders['queries'][] = $query;
214 $wgLinkHolders['texts'][] = $prefix.$text.$inside;
215 $wgLinkHolders['titles'][] =& $nt;
217 $retVal = '<!--LINK '. ($nr-1) ."-->{$trail}";
218 wfProfileOut( $fname.'-postparse' );
220 wfProfileIn( $fname.'-immediate' );
221 # Work out link colour immediately
222 $aid = $nt->getArticleID() ;
224 $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
226 $threshold = $wgUser->getOption('stubthreshold') ;
227 if ( $threshold > 0 ) {
228 $dbr =& wfGetDB( DB_SLAVE
);
229 $s = $dbr->selectRow(
233 'page_is_redirect' ),
234 array( 'page_id' => $aid ), $fname ) ;
235 if ( $s !== false ) {
236 $size = $s->page_len
;
237 if ( $s->page_is_redirect
OR $s->page_namespace
!= NS_MAIN
) {
238 $size = $threshold*2 ; # Really big
241 $size = $threshold*2 ; # Really big
246 if ( $size < $threshold ) {
247 $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
249 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
252 wfProfileOut( $fname.'-immediate' );
254 wfProfileOut( $fname );
259 * Pass a title object, not a title string
261 function makeKnownLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '' ) {
262 global $wgOut, $wgTitle, $wgInputEncoding;
264 $fname = 'Skin::makeKnownLinkObj';
265 wfProfileIn( $fname );
267 if ( !is_object( $nt ) ) {
268 wfProfileIn( $fname );
272 $u = $nt->escapeLocalURL( $query );
273 if ( '' != $nt->getFragment() ) {
274 if( $nt->getPrefixedDbkey() == '' ) {
277 $text = htmlspecialchars( $nt->getFragment() );
280 $anchor = urlencode( do_html_entity_decode( str_replace(' ', '_', $nt->getFragment()), ENT_COMPAT
, $wgInputEncoding ) );
281 $replacearray = array(
285 $u .= '#' . str_replace(array_keys($replacearray),array_values($replacearray),$anchor);
288 $text = htmlspecialchars( $nt->getPrefixedText() );
290 $style = $this->getInternalLinkAttributesObj( $nt, $text );
293 if ( '' != $trail ) {
294 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
299 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
300 wfProfileOut( $fname );
305 * Pass a title object, not a title string
307 function makeBrokenLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
309 if ( ! isset($nt) ) {
310 # wfDebugDieBacktrace();
311 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
314 $fname = 'Skin::makeBrokenLinkObj';
315 wfProfileIn( $fname );
317 if ( '' == $query ) {
320 $q = 'action=edit&'.$query;
322 $u = $nt->escapeLocalURL( $q );
325 $text = htmlspecialchars( $nt->getPrefixedText() );
327 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
330 if ( '' != $trail ) {
331 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
336 if ( $this->mOptions
['highlightbroken'] ) {
337 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
339 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>?</a>{$trail}";
342 wfProfileOut( $fname );
347 * Pass a title object, not a title string
349 function makeStubLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
350 $link = $nt->getPrefixedURL();
352 $u = $nt->escapeLocalURL( $query );
355 $text = htmlspecialchars( $nt->getPrefixedText() );
357 $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' );
360 if ( '' != $trail ) {
361 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
366 if ( $this->mOptions
['highlightbroken'] ) {
367 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
369 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>!</a>{$trail}";
374 /** @todo document */
375 function makeSelfLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
376 $u = $nt->escapeLocalURL( $query );
378 $text = htmlspecialchars( $nt->getPrefixedText() );
381 if ( '' != $trail ) {
382 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
387 return "<strong>{$prefix}{$text}{$inside}</strong>{$trail}";
390 /** @todo document */
391 function fnamePart( $url ) {
392 $basename = strrchr( $url, '/' );
393 if ( false === $basename ) {
396 $basename = substr( $basename, 1 );
398 return htmlspecialchars( $basename );
401 /** @todo document */
402 function makeImage( $url, $alt = '' ) {
405 $alt = $this->fnamePart( $url );
407 $s = '<img src="'.$url.'" alt="'.$alt.'" />';
411 /** @todo document */
412 function makeImageLink( $name, $url, $alt = '' ) {
413 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
414 return $this->makeImageLinkObj( $nt, $alt );
417 /** @todo document */
418 function makeImageLinkObj( $nt, $alt = '' ) {
419 global $wgContLang, $wgUseImageResize;
420 $img = Image
::newFromTitle( $nt );
421 $url = $img->getViewURL();
424 $prefix = $postfix = '';
426 # Check if the alt text is of the form "options|alt text"
428 # * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
429 # * left no resizing, just left align. label is used for alt= only
430 # * right same, but right aligned
431 # * none same, but not aligned
432 # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
433 # * center center the image
434 # * framed Keep original image size, no magnify-button.
436 $part = explode( '|', $alt);
438 $mwThumb =& MagicWord
::get( MAG_IMG_THUMBNAIL
);
439 $mwLeft =& MagicWord
::get( MAG_IMG_LEFT
);
440 $mwRight =& MagicWord
::get( MAG_IMG_RIGHT
);
441 $mwNone =& MagicWord
::get( MAG_IMG_NONE
);
442 $mwWidth =& MagicWord
::get( MAG_IMG_WIDTH
);
443 $mwCenter =& MagicWord
::get( MAG_IMG_CENTER
);
444 $mwFramed =& MagicWord
::get( MAG_IMG_FRAMED
);
447 $height = $framed = $thumb = false;
450 foreach( $part as $key => $val ) {
451 $val_parts = explode ( "=" , $val , 2 ) ;
452 $left_part = array_shift ( $val_parts ) ;
453 if ( $wgUseImageResize && ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
455 } elseif ( $wgUseImageResize && count ( $val_parts ) == 1 && ! is_null( $mwThumb->matchVariableStartToEnd($left_part) ) ) {
456 # use manually specified thumbnail
458 $manual_thumb = array_shift ( $val_parts ) ;
459 } elseif ( ! is_null( $mwRight->matchVariableStartToEnd($val) ) ) {
460 # remember to set an alignment, don't render immediately
462 } elseif ( ! is_null( $mwLeft->matchVariableStartToEnd($val) ) ) {
463 # remember to set an alignment, don't render immediately
465 } elseif ( ! is_null( $mwCenter->matchVariableStartToEnd($val) ) ) {
466 # remember to set an alignment, don't render immediately
468 } elseif ( ! is_null( $mwNone->matchVariableStartToEnd($val) ) ) {
469 # remember to set an alignment, don't render immediately
471 } elseif ( $wgUseImageResize && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
472 # $match is the image width in pixels
473 if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) {
474 $width = intval( $m[1] );
475 $height = intval( $m[2] );
477 $width = intval($match);
479 } elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) {
485 if ( 'center' == $align )
487 $prefix = '<div class="center">';
492 if ( $thumb ||
$framed ) {
494 # Create a thumbnail. Alignment depends on language
495 # writing direction, # right aligned for left-to-right-
496 # languages ("Western languages"), left-aligned
497 # for right-to-left-languages ("Semitic languages")
499 # If thumbnail width has not been provided, it is set
501 if ( $align == '' ) {
502 $align = $wgContLang->isRTL() ?
'left' : 'right';
504 if ( ! isset($width) ) {
507 return $prefix.$this->makeThumbLinkObj( $img, $alt, $align, $width, $height, $framed, $manual_thumb ).$postfix;
509 } elseif ( isset($width) ) {
511 # Create a resized image, without the additional thumbnail
514 if ( ( ! $height === false )
515 && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) {
516 $width = $img->getWidth() * $height / $img->getHeight();
518 if ( '' == $manual_thumb ) $url = $img->createThumb( $width );
521 # FIXME: This is a gross hack using a global.
522 # Replace link color holders in the caption text so the
523 # text portion can be placed int the alt/title attributes.
525 $wgParser->replaceLinkHolders( $alt );
527 $alt = Sanitizer
::stripAllTags( $alt );
529 $u = $nt->escapeLocalURL();
531 $s = wfMsg( 'missingimage', $img->getName() );
532 $s .= "<br />{$alt}<br />{$url}<br />\n";
534 $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
535 '<img src="'.$url.'" alt="'.$alt.'" longdesc="'.$u.'" /></a>';
537 if ( '' != $align ) {
538 $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
540 return str_replace("\n", ' ',$prefix.$s.$postfix);
544 * Make HTML for a thumbnail including image, border and caption
545 * $img is an Image object
547 function makeThumbLinkObj( $img, $label = '', $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
548 global $wgStylePath, $wgContLang;
549 # $image = Title::makeTitleSafe( NS_IMAGE, $name );
550 $url = $img->getViewURL();
552 #$label = htmlspecialchars( $label );
553 $alt = Sanitizer
::stripAllTags( $label );
555 $width = $height = 0;
556 if ( $img->exists() )
558 $width = $img->getWidth();
559 $height = $img->getHeight();
561 if ( 0 == $width ||
0 == $height )
563 $width = $height = 200;
565 if ( $boxwidth == 0 )
571 // Use image dimensions, don't scale
573 $oboxwidth = $boxwidth +
2;
574 $boxheight = $height;
577 $h = intval( $height/($width/$boxwidth) );
578 $oboxwidth = $boxwidth +
2;
579 if ( ( ! $boxheight === false ) && ( $h > $boxheight ) )
581 $boxwidth *= $boxheight/$h;
585 if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth );
588 if ( $manual_thumb != '' ) # Use manually specified thumbnail
590 $manual_title = Title
::makeTitleSafe( NS_IMAGE
, $manual_thumb ); #new Title ( $manual_thumb ) ;
591 $manual_img = Image
::newFromTitle( $manual_title );
592 $thumbUrl = $manual_img->getViewURL();
593 if ( $manual_img->exists() )
595 $width = $manual_img->getWidth();
596 $height = $manual_img->getHeight();
598 $boxheight = $height ;
599 $oboxwidth = $boxwidth +
2 ;
603 $u = $img->getEscapeLocalURL();
605 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
606 $magnifyalign = $wgContLang->isRTL() ?
'left' : 'right';
607 $textalign = $wgContLang->isRTL() ?
' style="text-align:right"' : '';
609 $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
610 if ( $thumbUrl == '' ) {
611 $s .= wfMsg( 'missingimage', $img->getName() );
614 $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
615 '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
616 'width="'.$boxwidth.'" height="'.$boxheight.'" ' .
617 'longdesc="'.$u.'" /></a>';
621 $zoomicon = '<div class="magnify" style="float:'.$magnifyalign.'">'.
622 '<a href="'.$u.'" class="internal" title="'.$more.'">'.
623 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
624 'width="15" height="11" alt="'.$more.'" /></a></div>';
627 $s .= ' <div class="thumbcaption" '.$textalign.'>'.$zoomicon.$label."</div></div></div>";
628 return str_replace("\n", ' ', $s);
631 /** @todo document */
632 function makeMediaLink( $name, $url, $alt = '' ) {
633 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
634 return $this->makeMediaLinkObj( $nt, $alt );
638 * Create a direct link to a given uploaded file.
640 * @param Title $title
641 * @param string $text pre-sanitized HTML
642 * @param bool $nourl Mask absolute URLs, so the parser doesn't
643 * linkify them (it is currently not context-aware)
644 * @return string HTML
647 * @todo Handle invalid or missing images better.
649 function makeMediaLinkObj( $title, $text = '', $nourl=false ) {
650 if( is_null( $title ) ) {
651 ### HOTFIX. Instead of breaking, return empty string.
654 $name = $title->getDBKey();
655 $img = Image
::newFromTitle( $title );
656 $url = $img->getURL();
658 $url = str_replace( "http://", "http-noparse://", $url );
660 $alt = htmlspecialchars( $title->getText() );
664 $u = htmlspecialchars( $url );
665 return "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$text}</a>";
669 /** @todo document */
670 function specialLink( $name, $key = '' ) {
673 if ( '' == $key ) { $key = strtolower( $name ); }
674 $pn = $wgContLang->ucfirst( $name );
675 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
679 /** @todo document */
680 function makeExternalLink( $url, $text, $escape = true, $linktype = '' ) {
681 $style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
682 global $wgNoFollowLinks;
683 if( $wgNoFollowLinks ) {
684 $style .= ' rel="nofollow"';
686 $url = htmlspecialchars( $url );
688 $text = htmlspecialchars( $text );
690 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
694 * This function is called by all recent changes variants, by the page history,
695 * and by the user contributions list. It is responsible for formatting edit
696 * comments. It escapes any HTML in the comment, but adds some CSS to format
697 * auto-generated comments (from section editing) and formats [[wikilinks]].
699 * The &$title parameter must be a title OBJECT. It is used to generate a
700 * direct link to the section in the autocomment.
701 * @author Erik Moeller <moeller@scireview.de>
703 * Note: there's not always a title to pass to this function.
704 * Since you can't set a default parameter for a reference, I've turned it
705 * temporarily to a value pass. Should be adjusted further. --brion
707 function formatComment($comment, $title = NULL) {
708 $fname = 'Skin::formatComment';
709 wfProfileIn( $fname );
712 $comment = htmlspecialchars( $comment );
714 # The pattern for autogen comments is / * foo * /, which makes for
716 # We look for all comments, match any text before and after the comment,
717 # add a separator where needed and format the comment itself with CSS
718 while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
726 # This is hackish but should work in most cases.
727 $section=str_replace('[[','',$section);
728 $section=str_replace(']]','',$section);
729 $title->mFragment
=$section;
730 $link=$this->makeKnownLinkObj($title,wfMsg('sectionlink'));
734 if($pre) { $auto = $sep.' '.$auto; }
735 if($post) { $auto .= ' '.$sep; }
736 $auto='<span class="autocomment">'.$auto.'</span>';
737 $comment=$pre.$auto.$post;
740 # format regular and media links - all other wiki formatting
742 $medians = $wgContLang->getNsText( NS_MEDIA
) . ':';
743 while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
744 # Handle link renaming [[foo|text]] will show link as "text"
745 if( "" != $match[3] ) {
750 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
751 # Media link; trail not supported.
752 $linkRegexp = '/\[\[(.*?)\]\]/';
753 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
756 if( preg_match( wfMsgForContent( "linktrail" ), $match[4], $submatch ) ) {
757 $trail = $submatch[1];
761 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
762 if ($match[1][0] == ':')
763 $match[1] = substr($match[1], 1);
764 $thelink = $this->makeLink( $match[1], $text, "", $trail );
766 $comment = preg_replace( $linkRegexp, $thelink, $comment, 1 );
768 wfProfileOut( $fname );
773 * Wrap a comment in standard punctuation and formatting if
774 * it's non-empty, otherwise return empty string.
776 * @param string $comment
777 * @param Title $title
781 function commentBlock( $comment, $title = NULL ) {
782 if( $comment == '' ||
$comment == '*' ) {
785 $formatted = $this->formatComment( $comment, $title );
786 return " <span class='comment'>($formatted)</span>";
790 /** @todo document */
791 function tocIndent() {
795 /** @todo document */
796 function tocUnindent($level) {
797 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ?
$level : 0 );
801 * parameter level defines if we are on an indentation level
803 function tocLine( $anchor, $tocline, $tocnumber, $level ) {
804 return "\n<li class='toclevel-$level'><a href=\"#" .
805 $anchor . '"><span class="tocnumber">' .
806 $tocnumber . '</span> <span class="toctext">' .
807 $tocline . '</span></a>';
810 /** @todo document */
811 function tocLineEnd() {
815 /** @todo document */
816 function tocList($toc) {
817 return "<div id='toc'>\n"
818 . "<div id='toctitle'><h2>" . wfMsg('toc') . "</h2></div>\n"
821 . '<script type="text/javascript">'
822 . ' if (window.showTocToggle) {'
823 . ' var tocShowText = "' . addslashes( wfMsg('showtoc') ) . '";'
824 . ' var tocHideText = "' . addslashes( wfMsg('hidetoc') ) . '"; '
825 . ' showTocToggle();'
828 . "<div class='visualClear'></div>\n";
832 * These two do not check for permissions: check $wgTitle->userCanEdit
833 * before calling them
835 function editSectionScriptForOther( $title, $section, $head ) {
836 $ttl = Title
::newFromText( $title );
837 $url = $ttl->escapeLocalURL( 'action=edit§ion='.$section );
838 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
841 /** @todo document */
842 function editSectionScript( $nt, $section, $head ) {
844 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
847 $url = $nt->escapeLocalURL( 'action=edit§ion='.$section );
848 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
851 /** @todo document */
852 function editSectionLinkForOther( $title, $section ) {
856 $title = Title
::newFromText($title);
857 $editurl = '§ion='.$section;
858 $url = $this->makeKnownLink($title->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
860 if( $wgContLang->isRTL() ) {
867 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
871 /** @todo document */
872 function editSectionLink( $nt, $section ) {
876 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
877 # Section edit links would be out of sync on an old page.
878 # But, if we're diffing to the current page, they'll be
883 $editurl = '§ion='.$section;
884 $url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
886 if( $wgContLang->isRTL() ) {
893 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";