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( 'cur', array( 'LENGTH(cur_text) AS x', 'cur_namespace',
230 'cur_is_redirect' ), array( 'cur_id' => $aid ), $fname ) ;
231 if ( $s !== false ) {
233 if ( $s->cur_is_redirect
OR $s->cur_namespace
!= NS_MAIN
) {
234 $size = $threshold*2 ; # Really big
237 $size = $threshold*2 ; # Really big
242 if ( $size < $threshold ) {
243 $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
245 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
248 wfProfileOut( $fname.'-immediate' );
250 wfProfileOut( $fname );
255 * Pass a title object, not a title string
257 function makeKnownLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '' ) {
258 global $wgOut, $wgTitle, $wgInputEncoding;
260 $fname = 'Skin::makeKnownLinkObj';
261 wfProfileIn( $fname );
263 if ( !is_object( $nt ) ) {
264 wfProfileIn( $fname );
268 $u = $nt->escapeLocalURL( $query );
269 if ( '' != $nt->getFragment() ) {
270 if( $nt->getPrefixedDbkey() == '' ) {
273 $text = htmlspecialchars( $nt->getFragment() );
276 $anchor = urlencode( do_html_entity_decode( str_replace(' ', '_', $nt->getFragment()), ENT_COMPAT
, $wgInputEncoding ) );
277 $replacearray = array(
281 $u .= '#' . str_replace(array_keys($replacearray),array_values($replacearray),$anchor);
284 $text = htmlspecialchars( $nt->getPrefixedText() );
286 $style = $this->getInternalLinkAttributesObj( $nt, $text );
289 if ( '' != $trail ) {
290 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
295 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
296 wfProfileOut( $fname );
301 * Pass a title object, not a title string
303 function makeBrokenLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
305 if ( ! isset($nt) ) {
306 # wfDebugDieBacktrace();
307 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
310 $fname = 'Skin::makeBrokenLinkObj';
311 wfProfileIn( $fname );
313 if ( '' == $query ) {
316 $q = 'action=edit&'.$query;
318 $u = $nt->escapeLocalURL( $q );
321 $text = htmlspecialchars( $nt->getPrefixedText() );
323 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
326 if ( '' != $trail ) {
327 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
332 if ( $this->mOptions
['highlightbroken'] ) {
333 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
335 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>?</a>{$trail}";
338 wfProfileOut( $fname );
343 * Pass a title object, not a title string
345 function makeStubLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
346 $link = $nt->getPrefixedURL();
348 $u = $nt->escapeLocalURL( $query );
351 $text = htmlspecialchars( $nt->getPrefixedText() );
353 $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' );
356 if ( '' != $trail ) {
357 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
362 if ( $this->mOptions
['highlightbroken'] ) {
363 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
365 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>!</a>{$trail}";
370 /** @todo document */
371 function makeSelfLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
372 $u = $nt->escapeLocalURL( $query );
374 $text = htmlspecialchars( $nt->getPrefixedText() );
377 if ( '' != $trail ) {
378 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
383 return "<strong>{$prefix}{$text}{$inside}</strong>{$trail}";
386 /** @todo document */
387 function fnamePart( $url ) {
388 $basename = strrchr( $url, '/' );
389 if ( false === $basename ) {
392 $basename = substr( $basename, 1 );
394 return htmlspecialchars( $basename );
397 /** @todo document */
398 function makeImage( $url, $alt = '' ) {
401 $alt = $this->fnamePart( $url );
403 $s = '<img src="'.$url.'" alt="'.$alt.'" />';
407 /** @todo document */
408 function makeImageLink( $name, $url, $alt = '' ) {
409 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
410 return $this->makeImageLinkObj( $nt, $alt );
413 /** @todo document */
414 function makeImageLinkObj( $nt, $alt = '' ) {
415 global $wgContLang, $wgUseImageResize;
416 $img = Image
::newFromTitle( $nt );
417 $url = $img->getViewURL();
420 $prefix = $postfix = '';
422 # Check if the alt text is of the form "options|alt text"
424 # * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
425 # * left no resizing, just left align. label is used for alt= only
426 # * right same, but right aligned
427 # * none same, but not aligned
428 # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
429 # * center center the image
430 # * framed Keep original image size, no magnify-button.
432 $part = explode( '|', $alt);
434 $mwThumb =& MagicWord
::get( MAG_IMG_THUMBNAIL
);
435 $mwLeft =& MagicWord
::get( MAG_IMG_LEFT
);
436 $mwRight =& MagicWord
::get( MAG_IMG_RIGHT
);
437 $mwNone =& MagicWord
::get( MAG_IMG_NONE
);
438 $mwWidth =& MagicWord
::get( MAG_IMG_WIDTH
);
439 $mwCenter =& MagicWord
::get( MAG_IMG_CENTER
);
440 $mwFramed =& MagicWord
::get( MAG_IMG_FRAMED
);
443 $height = $framed = $thumb = false;
446 foreach( $part as $key => $val ) {
447 $val_parts = explode ( "=" , $val , 2 ) ;
448 $left_part = array_shift ( $val_parts ) ;
449 if ( $wgUseImageResize && ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
451 } elseif ( $wgUseImageResize && count ( $val_parts ) == 1 && ! is_null( $mwThumb->matchVariableStartToEnd($left_part) ) ) {
452 # use manually specified thumbnail
454 $manual_thumb = array_shift ( $val_parts ) ;
455 } elseif ( ! is_null( $mwRight->matchVariableStartToEnd($val) ) ) {
456 # remember to set an alignment, don't render immediately
458 } elseif ( ! is_null( $mwLeft->matchVariableStartToEnd($val) ) ) {
459 # remember to set an alignment, don't render immediately
461 } elseif ( ! is_null( $mwCenter->matchVariableStartToEnd($val) ) ) {
462 # remember to set an alignment, don't render immediately
464 } elseif ( ! is_null( $mwNone->matchVariableStartToEnd($val) ) ) {
465 # remember to set an alignment, don't render immediately
467 } elseif ( $wgUseImageResize && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
468 # $match is the image width in pixels
469 if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) {
470 $width = intval( $m[1] );
471 $height = intval( $m[2] );
473 $width = intval($match);
475 } elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) {
481 if ( 'center' == $align )
483 $prefix = '<div class="center">';
488 if ( $thumb ||
$framed ) {
490 # Create a thumbnail. Alignment depends on language
491 # writing direction, # right aligned for left-to-right-
492 # languages ("Western languages"), left-aligned
493 # for right-to-left-languages ("Semitic languages")
495 # If thumbnail width has not been provided, it is set
497 if ( $align == '' ) {
498 $align = $wgContLang->isRTL() ?
'left' : 'right';
500 if ( ! isset($width) ) {
503 return $prefix.$this->makeThumbLinkObj( $img, $alt, $align, $width, $height, $framed, $manual_thumb ).$postfix;
505 } elseif ( isset($width) ) {
507 # Create a resized image, without the additional thumbnail
510 if ( ( ! $height === false )
511 && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) {
512 $width = $img->getWidth() * $height / $img->getHeight();
514 if ( '' == $manual_thumb ) $url = $img->createThumb( $width );
517 $alt = preg_replace( '/<[^>]*>/', '', $alt );
518 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&', $alt);
519 $alt = str_replace( array('<', '>', '"'), array('<', '>', '"'), $alt );
521 $u = $nt->escapeLocalURL();
523 $s = wfMsg( 'missingimage', $img->getName() );
524 $s .= "<br />{$alt}<br />{$url}<br />\n";
526 $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
527 '<img src="'.$url.'" alt="'.$alt.'" longdesc="'.$u.'" /></a>';
529 if ( '' != $align ) {
530 $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
532 return str_replace("\n", ' ',$prefix.$s.$postfix);
536 * Make HTML for a thumbnail including image, border and caption
537 * $img is an Image object
539 function makeThumbLinkObj( $img, $label = '', $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
540 global $wgStylePath, $wgContLang;
541 # $image = Title::makeTitleSafe( NS_IMAGE, $name );
542 $url = $img->getViewURL();
544 #$label = htmlspecialchars( $label );
545 $alt = preg_replace( '/<[^>]*>/', '', $label);
546 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&', $alt);
547 $alt = str_replace( array('<', '>', '"'), array('<', '>', '"'), $alt );
549 $width = $height = 0;
550 if ( $img->exists() )
552 $width = $img->getWidth();
553 $height = $img->getHeight();
555 if ( 0 == $width ||
0 == $height )
557 $width = $height = 200;
559 if ( $boxwidth == 0 )
565 // Use image dimensions, don't scale
567 $oboxwidth = $boxwidth +
2;
568 $boxheight = $height;
571 $h = intval( $height/($width/$boxwidth) );
572 $oboxwidth = $boxwidth +
2;
573 if ( ( ! $boxheight === false ) && ( $h > $boxheight ) )
575 $boxwidth *= $boxheight/$h;
579 if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth );
582 if ( $manual_thumb != '' ) # Use manually specified thumbnail
584 $manual_title = Title
::makeTitleSafe( NS_IMAGE
, $manual_thumb ); #new Title ( $manual_thumb ) ;
585 $manual_img = Image
::newFromTitle( $manual_title );
586 $thumbUrl = $manual_img->getViewURL();
587 if ( $manual_img->exists() )
589 $width = $manual_img->getWidth();
590 $height = $manual_img->getHeight();
592 $boxheight = $height ;
593 $oboxwidth = $boxwidth +
2 ;
597 $u = $img->getEscapeLocalURL();
599 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
600 $magnifyalign = $wgContLang->isRTL() ?
'left' : 'right';
601 $textalign = $wgContLang->isRTL() ?
' style="text-align:right"' : '';
603 $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
604 if ( $thumbUrl == '' ) {
605 $s .= wfMsg( 'missingimage', $img->getName() );
608 $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
609 '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
610 'width="'.$boxwidth.'" height="'.$boxheight.'" ' .
611 'longdesc="'.$u.'" /></a>';
615 $zoomicon = '<div class="magnify" style="float:'.$magnifyalign.'">'.
616 '<a href="'.$u.'" class="internal" title="'.$more.'">'.
617 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
618 'width="15" height="11" alt="'.$more.'" /></a></div>';
621 $s .= ' <div class="thumbcaption" '.$textalign.'>'.$zoomicon.$label."</div></div></div>";
622 return str_replace("\n", ' ', $s);
625 /** @todo document */
626 function makeMediaLink( $name, $url, $alt = '' ) {
627 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
628 return $this->makeMediaLinkObj( $nt, $alt );
631 /** @todo document */
632 function makeMediaLinkObj( $nt, $alt = '', $nourl=false ) {
633 if ( ! isset( $nt ) )
635 ### HOTFIX. Instead of breaking, return empty string.
638 $name = $nt->getDBKey();
639 $img = Image
::newFromTitle( $nt );
640 $url = $img->getURL();
641 # $nourl can be set by the parser
642 # this is a hack to mask absolute URLs, so the parser doesn't
643 # linkify them (it is currently not context-aware)
645 if ($nourl) { $url=str_replace("http://","http-noparse://",$url) ; }
646 if ( empty( $alt ) ) {
647 $alt = preg_replace( '/\.(.+?)^/', '', $name );
649 $u = htmlspecialchars( $url );
650 $s = "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$alt}</a>";
655 /** @todo document */
656 function specialLink( $name, $key = '' ) {
659 if ( '' == $key ) { $key = strtolower( $name ); }
660 $pn = $wgContLang->ucfirst( $name );
661 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
665 /** @todo document */
666 function makeExternalLink( $url, $text, $escape = true, $linktype = '' ) {
667 $style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
668 global $wgNoFollowLinks;
669 if( $wgNoFollowLinks ) {
670 $style .= ' rel="nofollow"';
672 $url = htmlspecialchars( $url );
674 $text = htmlspecialchars( $text );
676 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
680 * This function is called by all recent changes variants, by the page history,
681 * and by the user contributions list. It is responsible for formatting edit
682 * comments. It escapes any HTML in the comment, but adds some CSS to format
683 * auto-generated comments (from section editing) and formats [[wikilinks]].
685 * The &$title parameter must be a title OBJECT. It is used to generate a
686 * direct link to the section in the autocomment.
687 * @author Erik Moeller <moeller@scireview.de>
689 * Note: there's not always a title to pass to this function.
690 * Since you can't set a default parameter for a reference, I've turned it
691 * temporarily to a value pass. Should be adjusted further. --brion
693 function formatComment($comment, $title = NULL) {
694 $fname = 'Skin::formatComment';
695 wfProfileIn( $fname );
698 $comment = htmlspecialchars( $comment );
700 # The pattern for autogen comments is / * foo * /, which makes for
702 # We look for all comments, match any text before and after the comment,
703 # add a separator where needed and format the comment itself with CSS
704 while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
712 # This is hackish but should work in most cases.
713 $section=str_replace('[[','',$section);
714 $section=str_replace(']]','',$section);
715 $title->mFragment
=$section;
716 $link=$this->makeKnownLinkObj($title,wfMsg('sectionlink'));
720 if($pre) { $auto = $sep.' '.$auto; }
721 if($post) { $auto .= ' '.$sep; }
722 $auto='<span class="autocomment">'.$auto.'</span>';
723 $comment=$pre.$auto.$post;
726 # format regular and media links - all other wiki formatting
728 $medians = $wgContLang->getNsText(Namespace::getMedia()).':';
729 while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
730 # Handle link renaming [[foo|text]] will show link as "text"
731 if( "" != $match[3] ) {
736 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
737 # Media link; trail not supported.
738 $linkRegexp = '/\[\[(.*?)\]\]/';
739 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
742 if( preg_match( wfMsgForContent( "linktrail" ), $match[4], $submatch ) ) {
743 $trail = $submatch[1];
747 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
748 if ($match[1][0] == ':')
749 $match[1] = substr($match[1], 1);
750 $thelink = $this->makeLink( $match[1], $text, "", $trail );
752 $comment = preg_replace( $linkRegexp, $thelink, $comment, 1 );
754 wfProfileOut( $fname );
758 /** @todo document */
759 function tocIndent() {
763 /** @todo document */
764 function tocUnindent($level) {
765 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ?
$level : 0 );
769 * parameter level defines if we are on an indentation level
771 function tocLine( $anchor, $tocline, $tocnumber, $level ) {
772 return "\n<li class='toclevel-$level'><a href=\"#" . $anchor . '"><span class="tocnumber">' . $tocnumber . '</span> <span class="toctext">' . $tocline . '</span></a>';
775 /** @todo document */
776 function tocLineEnd() {
780 /** @todo document */
781 function tocList($toc) {
782 return "<div id='toc'>\n"
783 . "<div id='toctitle'><h2>" . wfMsg('toc') . "</h2></div>\n"
786 . '<script type="text/javascript">'
787 . ' if (window.showTocToggle) {'
788 . ' var tocShowText = "' . addslashes( wfMsg('showtoc') ) . '";'
789 . ' var tocHideText = "' . addslashes( wfMsg('hidetoc') ) . '"; '
790 . ' showTocToggle();'
793 . "<div class='visualClear'></div>\n";
797 * These two do not check for permissions: check $wgTitle->userCanEdit
798 * before calling them
800 function editSectionScriptForOther( $title, $section, $head ) {
801 $ttl = Title
::newFromText( $title );
802 $url = $ttl->escapeLocalURL( 'action=edit§ion='.$section );
803 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
806 /** @todo document */
807 function editSectionScript( $nt, $section, $head ) {
809 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
812 $url = $nt->escapeLocalURL( 'action=edit§ion='.$section );
813 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
816 /** @todo document */
817 function editSectionLinkForOther( $title, $section ) {
821 $title = Title
::newFromText($title);
822 $editurl = '§ion='.$section;
823 $url = $this->makeKnownLink($title->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
825 if( $wgContLang->isRTL() ) {
832 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
836 /** @todo document */
837 function editSectionLink( $nt, $section ) {
841 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
842 # Section edit links would be out of sync on an old page.
843 # But, if we're diffing to the current page, they'll be
848 $editurl = '§ion='.$section;
849 $url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
851 if( $wgContLang->isRTL() ) {
858 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";