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(
230 array( 'page', 'text' ),
231 array( 'LENGTH(old_text) AS x',
233 'page_is_redirect' ),
234 array( 'page_id' => $aid,
235 'old_id = page_latest' ), $fname ) ;
236 if ( $s !== false ) {
238 if ( $s->page_is_redirect
OR $s->page_namespace
!= NS_MAIN
) {
239 $size = $threshold*2 ; # Really big
242 $size = $threshold*2 ; # Really big
247 if ( $size < $threshold ) {
248 $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
250 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
253 wfProfileOut( $fname.'-immediate' );
255 wfProfileOut( $fname );
260 * Pass a title object, not a title string
262 function makeKnownLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '' ) {
263 global $wgOut, $wgTitle, $wgInputEncoding;
265 $fname = 'Skin::makeKnownLinkObj';
266 wfProfileIn( $fname );
268 if ( !is_object( $nt ) ) {
269 wfProfileIn( $fname );
273 $u = $nt->escapeLocalURL( $query );
274 if ( '' != $nt->getFragment() ) {
275 if( $nt->getPrefixedDbkey() == '' ) {
278 $text = htmlspecialchars( $nt->getFragment() );
281 $anchor = urlencode( do_html_entity_decode( str_replace(' ', '_', $nt->getFragment()), ENT_COMPAT
, $wgInputEncoding ) );
282 $replacearray = array(
286 $u .= '#' . str_replace(array_keys($replacearray),array_values($replacearray),$anchor);
289 $text = htmlspecialchars( $nt->getPrefixedText() );
291 $style = $this->getInternalLinkAttributesObj( $nt, $text );
294 if ( '' != $trail ) {
295 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
300 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
301 wfProfileOut( $fname );
306 * Pass a title object, not a title string
308 function makeBrokenLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
310 if ( ! isset($nt) ) {
311 # wfDebugDieBacktrace();
312 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
315 $fname = 'Skin::makeBrokenLinkObj';
316 wfProfileIn( $fname );
318 if ( '' == $query ) {
321 $q = 'action=edit&'.$query;
323 $u = $nt->escapeLocalURL( $q );
326 $text = htmlspecialchars( $nt->getPrefixedText() );
328 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
331 if ( '' != $trail ) {
332 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
337 if ( $this->mOptions
['highlightbroken'] ) {
338 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
340 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>?</a>{$trail}";
343 wfProfileOut( $fname );
348 * Pass a title object, not a title string
350 function makeStubLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
351 $link = $nt->getPrefixedURL();
353 $u = $nt->escapeLocalURL( $query );
356 $text = htmlspecialchars( $nt->getPrefixedText() );
358 $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' );
361 if ( '' != $trail ) {
362 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
367 if ( $this->mOptions
['highlightbroken'] ) {
368 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
370 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>!</a>{$trail}";
375 /** @todo document */
376 function makeSelfLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
377 $u = $nt->escapeLocalURL( $query );
379 $text = htmlspecialchars( $nt->getPrefixedText() );
382 if ( '' != $trail ) {
383 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
388 return "<strong>{$prefix}{$text}{$inside}</strong>{$trail}";
391 /** @todo document */
392 function fnamePart( $url ) {
393 $basename = strrchr( $url, '/' );
394 if ( false === $basename ) {
397 $basename = substr( $basename, 1 );
399 return htmlspecialchars( $basename );
402 /** @todo document */
403 function makeImage( $url, $alt = '' ) {
406 $alt = $this->fnamePart( $url );
408 $s = '<img src="'.$url.'" alt="'.$alt.'" />';
412 /** @todo document */
413 function makeImageLink( $name, $url, $alt = '' ) {
414 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
415 return $this->makeImageLinkObj( $nt, $alt );
418 /** @todo document */
419 function makeImageLinkObj( $nt, $alt = '' ) {
420 global $wgContLang, $wgUseImageResize;
421 $img = Image
::newFromTitle( $nt );
422 $url = $img->getViewURL();
425 $prefix = $postfix = '';
427 # Check if the alt text is of the form "options|alt text"
429 # * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
430 # * left no resizing, just left align. label is used for alt= only
431 # * right same, but right aligned
432 # * none same, but not aligned
433 # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
434 # * center center the image
435 # * framed Keep original image size, no magnify-button.
437 $part = explode( '|', $alt);
439 $mwThumb =& MagicWord
::get( MAG_IMG_THUMBNAIL
);
440 $mwLeft =& MagicWord
::get( MAG_IMG_LEFT
);
441 $mwRight =& MagicWord
::get( MAG_IMG_RIGHT
);
442 $mwNone =& MagicWord
::get( MAG_IMG_NONE
);
443 $mwWidth =& MagicWord
::get( MAG_IMG_WIDTH
);
444 $mwCenter =& MagicWord
::get( MAG_IMG_CENTER
);
445 $mwFramed =& MagicWord
::get( MAG_IMG_FRAMED
);
448 $height = $framed = $thumb = false;
451 foreach( $part as $key => $val ) {
452 $val_parts = explode ( "=" , $val , 2 ) ;
453 $left_part = array_shift ( $val_parts ) ;
454 if ( $wgUseImageResize && ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
456 } elseif ( $wgUseImageResize && count ( $val_parts ) == 1 && ! is_null( $mwThumb->matchVariableStartToEnd($left_part) ) ) {
457 # use manually specified thumbnail
459 $manual_thumb = array_shift ( $val_parts ) ;
460 } elseif ( ! is_null( $mwRight->matchVariableStartToEnd($val) ) ) {
461 # remember to set an alignment, don't render immediately
463 } elseif ( ! is_null( $mwLeft->matchVariableStartToEnd($val) ) ) {
464 # remember to set an alignment, don't render immediately
466 } elseif ( ! is_null( $mwCenter->matchVariableStartToEnd($val) ) ) {
467 # remember to set an alignment, don't render immediately
469 } elseif ( ! is_null( $mwNone->matchVariableStartToEnd($val) ) ) {
470 # remember to set an alignment, don't render immediately
472 } elseif ( $wgUseImageResize && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
473 # $match is the image width in pixels
474 if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) {
475 $width = intval( $m[1] );
476 $height = intval( $m[2] );
478 $width = intval($match);
480 } elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) {
486 if ( 'center' == $align )
488 $prefix = '<div class="center">';
493 if ( $thumb ||
$framed ) {
495 # Create a thumbnail. Alignment depends on language
496 # writing direction, # right aligned for left-to-right-
497 # languages ("Western languages"), left-aligned
498 # for right-to-left-languages ("Semitic languages")
500 # If thumbnail width has not been provided, it is set
502 if ( $align == '' ) {
503 $align = $wgContLang->isRTL() ?
'left' : 'right';
505 if ( ! isset($width) ) {
508 return $prefix.$this->makeThumbLinkObj( $img, $alt, $align, $width, $height, $framed, $manual_thumb ).$postfix;
510 } elseif ( isset($width) ) {
512 # Create a resized image, without the additional thumbnail
515 if ( ( ! $height === false )
516 && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) {
517 $width = $img->getWidth() * $height / $img->getHeight();
519 if ( '' == $manual_thumb ) $url = $img->createThumb( $width );
522 # FIXME: This is a gross hack using a global.
523 # Replace link color holders in the caption text so the
524 # text portion can be placed int the alt/title attributes.
526 $wgParser->replaceLinkHolders( $alt );
528 $alt = Sanitizer
::stripAllTags( $alt );
530 $u = $nt->escapeLocalURL();
532 $s = wfMsg( 'missingimage', $img->getName() );
533 $s .= "<br />{$alt}<br />{$url}<br />\n";
535 $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
536 '<img src="'.$url.'" alt="'.$alt.'" longdesc="'.$u.'" /></a>';
538 if ( '' != $align ) {
539 $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
541 return str_replace("\n", ' ',$prefix.$s.$postfix);
545 * Make HTML for a thumbnail including image, border and caption
546 * $img is an Image object
548 function makeThumbLinkObj( $img, $label = '', $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
549 global $wgStylePath, $wgContLang;
550 # $image = Title::makeTitleSafe( NS_IMAGE, $name );
551 $url = $img->getViewURL();
553 #$label = htmlspecialchars( $label );
554 $alt = Sanitizer
::stripAllTags( $label );
556 $width = $height = 0;
557 if ( $img->exists() )
559 $width = $img->getWidth();
560 $height = $img->getHeight();
562 if ( 0 == $width ||
0 == $height )
564 $width = $height = 200;
566 if ( $boxwidth == 0 )
572 // Use image dimensions, don't scale
574 $oboxwidth = $boxwidth +
2;
575 $boxheight = $height;
578 $h = intval( $height/($width/$boxwidth) );
579 $oboxwidth = $boxwidth +
2;
580 if ( ( ! $boxheight === false ) && ( $h > $boxheight ) )
582 $boxwidth *= $boxheight/$h;
586 if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth );
589 if ( $manual_thumb != '' ) # Use manually specified thumbnail
591 $manual_title = Title
::makeTitleSafe( NS_IMAGE
, $manual_thumb ); #new Title ( $manual_thumb ) ;
592 $manual_img = Image
::newFromTitle( $manual_title );
593 $thumbUrl = $manual_img->getViewURL();
594 if ( $manual_img->exists() )
596 $width = $manual_img->getWidth();
597 $height = $manual_img->getHeight();
599 $boxheight = $height ;
600 $oboxwidth = $boxwidth +
2 ;
604 $u = $img->getEscapeLocalURL();
606 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
607 $magnifyalign = $wgContLang->isRTL() ?
'left' : 'right';
608 $textalign = $wgContLang->isRTL() ?
' style="text-align:right"' : '';
610 $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
611 if ( $thumbUrl == '' ) {
612 $s .= wfMsg( 'missingimage', $img->getName() );
615 $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
616 '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
617 'width="'.$boxwidth.'" height="'.$boxheight.'" ' .
618 'longdesc="'.$u.'" /></a>';
622 $zoomicon = '<div class="magnify" style="float:'.$magnifyalign.'">'.
623 '<a href="'.$u.'" class="internal" title="'.$more.'">'.
624 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
625 'width="15" height="11" alt="'.$more.'" /></a></div>';
628 $s .= ' <div class="thumbcaption" '.$textalign.'>'.$zoomicon.$label."</div></div></div>";
629 return str_replace("\n", ' ', $s);
632 /** @todo document */
633 function makeMediaLink( $name, $url, $alt = '' ) {
634 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
635 return $this->makeMediaLinkObj( $nt, $alt );
639 * Create a direct link to a given uploaded file.
641 * @param Title $title
642 * @param string $text pre-sanitized HTML
643 * @param bool $nourl Mask absolute URLs, so the parser doesn't
644 * linkify them (it is currently not context-aware)
645 * @return string HTML
648 * @todo Handle invalid or missing images better.
650 function makeMediaLinkObj( $title, $text = '', $nourl=false ) {
651 if( is_null( $title ) ) {
652 ### HOTFIX. Instead of breaking, return empty string.
655 $name = $title->getDBKey();
656 $img = Image
::newFromTitle( $title );
657 $url = $img->getURL();
659 $url = str_replace( "http://", "http-noparse://", $url );
661 $alt = htmlspecialchars( $title->getText() );
665 $u = htmlspecialchars( $url );
666 return "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$text}</a>";
670 /** @todo document */
671 function specialLink( $name, $key = '' ) {
674 if ( '' == $key ) { $key = strtolower( $name ); }
675 $pn = $wgContLang->ucfirst( $name );
676 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
680 /** @todo document */
681 function makeExternalLink( $url, $text, $escape = true, $linktype = '' ) {
682 $style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
683 global $wgNoFollowLinks;
684 if( $wgNoFollowLinks ) {
685 $style .= ' rel="nofollow"';
687 $url = htmlspecialchars( $url );
689 $text = htmlspecialchars( $text );
691 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
695 * This function is called by all recent changes variants, by the page history,
696 * and by the user contributions list. It is responsible for formatting edit
697 * comments. It escapes any HTML in the comment, but adds some CSS to format
698 * auto-generated comments (from section editing) and formats [[wikilinks]].
700 * The &$title parameter must be a title OBJECT. It is used to generate a
701 * direct link to the section in the autocomment.
702 * @author Erik Moeller <moeller@scireview.de>
704 * Note: there's not always a title to pass to this function.
705 * Since you can't set a default parameter for a reference, I've turned it
706 * temporarily to a value pass. Should be adjusted further. --brion
708 function formatComment($comment, $title = NULL) {
709 $fname = 'Skin::formatComment';
710 wfProfileIn( $fname );
713 $comment = htmlspecialchars( $comment );
715 # The pattern for autogen comments is / * foo * /, which makes for
717 # We look for all comments, match any text before and after the comment,
718 # add a separator where needed and format the comment itself with CSS
719 while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
727 # This is hackish but should work in most cases.
728 $section=str_replace('[[','',$section);
729 $section=str_replace(']]','',$section);
730 $title->mFragment
=$section;
731 $link=$this->makeKnownLinkObj($title,wfMsg('sectionlink'));
735 if($pre) { $auto = $sep.' '.$auto; }
736 if($post) { $auto .= ' '.$sep; }
737 $auto='<span class="autocomment">'.$auto.'</span>';
738 $comment=$pre.$auto.$post;
741 # format regular and media links - all other wiki formatting
743 $medians = $wgContLang->getNsText( NS_MEDIA
) . ':';
744 while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
745 # Handle link renaming [[foo|text]] will show link as "text"
746 if( "" != $match[3] ) {
751 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
752 # Media link; trail not supported.
753 $linkRegexp = '/\[\[(.*?)\]\]/';
754 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
757 if( preg_match( wfMsgForContent( "linktrail" ), $match[4], $submatch ) ) {
758 $trail = $submatch[1];
762 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
763 if ($match[1][0] == ':')
764 $match[1] = substr($match[1], 1);
765 $thelink = $this->makeLink( $match[1], $text, "", $trail );
767 $comment = preg_replace( $linkRegexp, $thelink, $comment, 1 );
769 wfProfileOut( $fname );
774 * Wrap a comment in standard punctuation and formatting if
775 * it's non-empty, otherwise return empty string.
777 * @param string $comment
778 * @param Title $title
782 function commentBlock( $comment, $title = NULL ) {
783 if( $comment == '' ||
$comment == '*' ) {
786 $formatted = $this->formatComment( $comment, $title );
787 return " <span class='comment'>($formatted)</span>";
791 /** @todo document */
792 function tocIndent() {
796 /** @todo document */
797 function tocUnindent($level) {
798 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ?
$level : 0 );
802 * parameter level defines if we are on an indentation level
804 function tocLine( $anchor, $tocline, $tocnumber, $level ) {
805 return "\n<li class='toclevel-$level'><a href=\"#" .
806 $anchor . '"><span class="tocnumber">' .
807 $tocnumber . '</span> <span class="toctext">' .
808 $tocline . '</span></a>';
811 /** @todo document */
812 function tocLineEnd() {
816 /** @todo document */
817 function tocList($toc) {
818 return "<div id='toc'>\n"
819 . "<div id='toctitle'><h2>" . wfMsg('toc') . "</h2></div>\n"
822 . '<script type="text/javascript">'
823 . ' if (window.showTocToggle) {'
824 . ' var tocShowText = "' . addslashes( wfMsg('showtoc') ) . '";'
825 . ' var tocHideText = "' . addslashes( wfMsg('hidetoc') ) . '"; '
826 . ' showTocToggle();'
829 . "<div class='visualClear'></div>\n";
833 * These two do not check for permissions: check $wgTitle->userCanEdit
834 * before calling them
836 function editSectionScriptForOther( $title, $section, $head ) {
837 $ttl = Title
::newFromText( $title );
838 $url = $ttl->escapeLocalURL( 'action=edit§ion='.$section );
839 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
842 /** @todo document */
843 function editSectionScript( $nt, $section, $head ) {
845 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
848 $url = $nt->escapeLocalURL( 'action=edit§ion='.$section );
849 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
852 /** @todo document */
853 function editSectionLinkForOther( $title, $section ) {
857 $title = Title
::newFromText($title);
858 $editurl = '§ion='.$section;
859 $url = $this->makeKnownLink($title->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
861 if( $wgContLang->isRTL() ) {
868 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
872 /** @todo document */
873 function editSectionLink( $nt, $section ) {
877 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
878 # Section edit links would be out of sync on an old page.
879 # But, if we're diffing to the current page, they'll be
884 $editurl = '§ion='.$section;
885 $url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
887 if( $wgContLang->isRTL() ) {
894 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";