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 $alt = preg_replace( '/<[^>]*>/', '', $alt );
523 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&', $alt);
524 $alt = str_replace( array('<', '>', '"'), array('<', '>', '"'), $alt );
526 $u = $nt->escapeLocalURL();
528 $s = wfMsg( 'missingimage', $img->getName() );
529 $s .= "<br />{$alt}<br />{$url}<br />\n";
531 $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
532 '<img src="'.$url.'" alt="'.$alt.'" longdesc="'.$u.'" /></a>';
534 if ( '' != $align ) {
535 $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
537 return str_replace("\n", ' ',$prefix.$s.$postfix);
541 * Make HTML for a thumbnail including image, border and caption
542 * $img is an Image object
544 function makeThumbLinkObj( $img, $label = '', $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
545 global $wgStylePath, $wgContLang;
546 # $image = Title::makeTitleSafe( NS_IMAGE, $name );
547 $url = $img->getViewURL();
549 #$label = htmlspecialchars( $label );
550 $alt = preg_replace( '/<[^>]*>/', '', $label);
551 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&', $alt);
552 $alt = str_replace( array('<', '>', '"'), array('<', '>', '"'), $alt );
554 $width = $height = 0;
555 if ( $img->exists() )
557 $width = $img->getWidth();
558 $height = $img->getHeight();
560 if ( 0 == $width ||
0 == $height )
562 $width = $height = 200;
564 if ( $boxwidth == 0 )
570 // Use image dimensions, don't scale
572 $oboxwidth = $boxwidth +
2;
573 $boxheight = $height;
576 $h = intval( $height/($width/$boxwidth) );
577 $oboxwidth = $boxwidth +
2;
578 if ( ( ! $boxheight === false ) && ( $h > $boxheight ) )
580 $boxwidth *= $boxheight/$h;
584 if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth );
587 if ( $manual_thumb != '' ) # Use manually specified thumbnail
589 $manual_title = Title
::makeTitleSafe( NS_IMAGE
, $manual_thumb ); #new Title ( $manual_thumb ) ;
590 $manual_img = Image
::newFromTitle( $manual_title );
591 $thumbUrl = $manual_img->getViewURL();
592 if ( $manual_img->exists() )
594 $width = $manual_img->getWidth();
595 $height = $manual_img->getHeight();
597 $boxheight = $height ;
598 $oboxwidth = $boxwidth +
2 ;
602 $u = $img->getEscapeLocalURL();
604 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
605 $magnifyalign = $wgContLang->isRTL() ?
'left' : 'right';
606 $textalign = $wgContLang->isRTL() ?
' style="text-align:right"' : '';
608 $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
609 if ( $thumbUrl == '' ) {
610 $s .= wfMsg( 'missingimage', $img->getName() );
613 $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
614 '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
615 'width="'.$boxwidth.'" height="'.$boxheight.'" ' .
616 'longdesc="'.$u.'" /></a>';
620 $zoomicon = '<div class="magnify" style="float:'.$magnifyalign.'">'.
621 '<a href="'.$u.'" class="internal" title="'.$more.'">'.
622 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
623 'width="15" height="11" alt="'.$more.'" /></a></div>';
626 $s .= ' <div class="thumbcaption" '.$textalign.'>'.$zoomicon.$label."</div></div></div>";
627 return str_replace("\n", ' ', $s);
630 /** @todo document */
631 function makeMediaLink( $name, $url, $alt = '' ) {
632 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
633 return $this->makeMediaLinkObj( $nt, $alt );
636 /** @todo document */
637 function makeMediaLinkObj( $nt, $alt = '', $nourl=false ) {
638 if ( ! isset( $nt ) )
640 ### HOTFIX. Instead of breaking, return empty string.
643 $name = $nt->getDBKey();
644 $img = Image
::newFromTitle( $nt );
645 $url = $img->getURL();
646 # $nourl can be set by the parser
647 # this is a hack to mask absolute URLs, so the parser doesn't
648 # linkify them (it is currently not context-aware)
650 if ($nourl) { $url=str_replace("http://","http-noparse://",$url) ; }
651 if ( empty( $alt ) ) {
652 $alt = preg_replace( '/\.(.+?)^/', '', $name );
654 $u = htmlspecialchars( $url );
655 $s = "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$alt}</a>";
660 /** @todo document */
661 function specialLink( $name, $key = '' ) {
664 if ( '' == $key ) { $key = strtolower( $name ); }
665 $pn = $wgContLang->ucfirst( $name );
666 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
670 /** @todo document */
671 function makeExternalLink( $url, $text, $escape = true, $linktype = '' ) {
672 $style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
673 global $wgNoFollowLinks;
674 if( $wgNoFollowLinks ) {
675 $style .= ' rel="nofollow"';
677 $url = htmlspecialchars( $url );
679 $text = htmlspecialchars( $text );
681 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
685 * This function is called by all recent changes variants, by the page history,
686 * and by the user contributions list. It is responsible for formatting edit
687 * comments. It escapes any HTML in the comment, but adds some CSS to format
688 * auto-generated comments (from section editing) and formats [[wikilinks]].
690 * The &$title parameter must be a title OBJECT. It is used to generate a
691 * direct link to the section in the autocomment.
692 * @author Erik Moeller <moeller@scireview.de>
694 * Note: there's not always a title to pass to this function.
695 * Since you can't set a default parameter for a reference, I've turned it
696 * temporarily to a value pass. Should be adjusted further. --brion
698 function formatComment($comment, $title = NULL) {
699 $fname = 'Skin::formatComment';
700 wfProfileIn( $fname );
703 $comment = htmlspecialchars( $comment );
705 # The pattern for autogen comments is / * foo * /, which makes for
707 # We look for all comments, match any text before and after the comment,
708 # add a separator where needed and format the comment itself with CSS
709 while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
717 # This is hackish but should work in most cases.
718 $section=str_replace('[[','',$section);
719 $section=str_replace(']]','',$section);
720 $title->mFragment
=$section;
721 $link=$this->makeKnownLinkObj($title,wfMsg('sectionlink'));
725 if($pre) { $auto = $sep.' '.$auto; }
726 if($post) { $auto .= ' '.$sep; }
727 $auto='<span class="autocomment">'.$auto.'</span>';
728 $comment=$pre.$auto.$post;
731 # format regular and media links - all other wiki formatting
733 $medians = $wgContLang->getNsText(Namespace::getMedia()).':';
734 while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
735 # Handle link renaming [[foo|text]] will show link as "text"
736 if( "" != $match[3] ) {
741 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
742 # Media link; trail not supported.
743 $linkRegexp = '/\[\[(.*?)\]\]/';
744 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
747 if( preg_match( wfMsgForContent( "linktrail" ), $match[4], $submatch ) ) {
748 $trail = $submatch[1];
752 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
753 if ($match[1][0] == ':')
754 $match[1] = substr($match[1], 1);
755 $thelink = $this->makeLink( $match[1], $text, "", $trail );
757 $comment = preg_replace( $linkRegexp, $thelink, $comment, 1 );
759 wfProfileOut( $fname );
763 /** @todo document */
764 function tocIndent() {
768 /** @todo document */
769 function tocUnindent($level) {
770 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ?
$level : 0 );
774 * parameter level defines if we are on an indentation level
776 function tocLine( $anchor, $tocline, $tocnumber, $level ) {
777 return "\n<li class='toclevel-$level'><a href=\"#" . $anchor . '"><span class="tocnumber">' . $tocnumber . '</span> <span class="toctext">' . $tocline . '</span></a>';
780 /** @todo document */
781 function tocLineEnd() {
785 /** @todo document */
786 function tocList($toc) {
787 return "<div id='toc'>\n"
788 . "<div id='toctitle'><h2>" . wfMsg('toc') . "</h2></div>\n"
791 . '<script type="text/javascript">'
792 . ' if (window.showTocToggle) {'
793 . ' var tocShowText = "' . addslashes( wfMsg('showtoc') ) . '";'
794 . ' var tocHideText = "' . addslashes( wfMsg('hidetoc') ) . '"; '
795 . ' showTocToggle();'
798 . "<div class='visualClear'></div>\n";
802 * These two do not check for permissions: check $wgTitle->userCanEdit
803 * before calling them
805 function editSectionScriptForOther( $title, $section, $head ) {
806 $ttl = Title
::newFromText( $title );
807 $url = $ttl->escapeLocalURL( 'action=edit§ion='.$section );
808 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
811 /** @todo document */
812 function editSectionScript( $nt, $section, $head ) {
814 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
817 $url = $nt->escapeLocalURL( 'action=edit§ion='.$section );
818 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
821 /** @todo document */
822 function editSectionLinkForOther( $title, $section ) {
826 $title = Title
::newFromText($title);
827 $editurl = '§ion='.$section;
828 $url = $this->makeKnownLink($title->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
830 if( $wgContLang->isRTL() ) {
837 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
841 /** @todo document */
842 function editSectionLink( $nt, $section ) {
846 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
847 # Section edit links would be out of sync on an old page.
848 # But, if we're diffing to the current page, they'll be
853 $editurl = '§ion='.$section;
854 $url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
856 if( $wgContLang->isRTL() ) {
863 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";