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();
29 * Get/set accessor for delayed link colouring
31 function postParseLinkColour( $setting = NULL ) {
32 return wfSetVar( $this->postParseLinkColour
, $setting );
36 function getExternalLinkAttributes( $link, $text, $class='' ) {
39 $same = ($link == $text);
40 $link = urldecode( $link );
41 $link = $wgContLang->checkTitleEncoding( $link );
42 $link = preg_replace( '/[\\x00-\\x1f_]/', ' ', $link );
43 $link = htmlspecialchars( $link );
45 $r = ($class != '') ?
" class='$class'" : " class='external'";
47 $r .= " title=\"{$link}\"";
52 function getInternalLinkAttributes( $link, $text, $broken = false ) {
53 $link = urldecode( $link );
54 $link = str_replace( '_', ' ', $link );
55 $link = htmlspecialchars( $link );
57 if( $broken == 'stub' ) {
59 } else if ( $broken == 'yes' ) {
65 $r .= " title=\"{$link}\"";
72 function getInternalLinkAttributesObj( &$nt, $text, $broken = false ) {
73 if( $broken == 'stub' ) {
75 } else if ( $broken == 'yes' ) {
81 $r .= ' title="' . $nt->getEscapedText() . '"';
86 * Note: This function MUST call getArticleID() on the link,
87 * otherwise the cache won't get updated properly. See LINKCACHE.DOC.
89 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
90 wfProfileIn( 'Skin::makeLink' );
91 $nt = Title
::newFromText( $title );
93 $result = $this->makeLinkObj( Title
::newFromText( $title ), $text, $query, $trail );
95 wfDebug( 'Invalid title passed to Skin::makeLink(): "'.$title."\"\n" );
96 $result = $text == "" ?
$title : $text;
99 wfProfileOut( 'Skin::makeLink' );
103 /** @todo document */
104 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
105 $nt = Title
::newFromText( $title );
107 return $this->makeKnownLinkObj( Title
::newFromText( $title ), $text, $query, $trail, $prefix , $aprops );
109 wfDebug( 'Invalid title passed to Skin::makeKnownLink(): "'.$title."\"\n" );
110 return $text == '' ?
$title : $text;
114 /** @todo document */
115 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
116 $nt = Title
::newFromText( $title );
118 return $this->makeBrokenLinkObj( Title
::newFromText( $title ), $text, $query, $trail );
120 wfDebug( 'Invalid title passed to Skin::makeBrokenLink(): "'.$title."\"\n" );
121 return $text == '' ?
$title : $text;
125 /** @todo document */
126 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
127 $nt = Title
::newFromText( $title );
129 return $this->makeStubLinkObj( Title
::newFromText( $title ), $text, $query, $trail );
131 wfDebug( 'Invalid title passed to Skin::makeStubLink(): "'.$title."\"\n" );
132 return $text == '' ?
$title : $text;
137 * Pass a title object, not a title string
139 function makeLinkObj( &$nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
140 global $wgOut, $wgUser, $wgLinkHolders, $wgInputEncoding;
141 $fname = 'Skin::makeLinkObj';
142 wfProfileIn( $fname );
145 if ( ! isset($nt) ) {
146 # wfDebugDieBacktrace();
147 wfProfileOut( $fname );
148 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
151 $ns = $nt->getNamespace();
152 $dbkey = $nt->getDBkey();
153 if ( $nt->isExternal() ) {
154 $u = $nt->getFullURL();
155 $link = $nt->getPrefixedURL();
156 if ( '' == $text ) { $text = $nt->getPrefixedText(); }
157 $style = $this->getExternalLinkAttributes( $link, $text, 'extiw' );
160 if ( '' != $trail ) {
161 if ( preg_match( '/^([a-z]+)(.*)$$/sD', $trail, $m ) ) {
167 # Check for anchors, normalize the anchor
169 $parts = explode( '#', $u, 2 );
170 if ( count( $parts ) == 2 ) {
171 $anchor = urlencode( do_html_entity_decode( str_replace(' ', '_', $parts[1] ),
173 $wgInputEncoding ) );
174 $replacearray = array(
178 $u = $parts[0] . '#' .
179 str_replace( array_keys( $replacearray ),
180 array_values( $replacearray ),
184 $t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
186 if( $this->postParseLinkColour
) {
187 # There's no existence check, but this will prevent
188 # interwiki links from being parsed as external links.
189 global $wgInterwikiLinkHolders;
190 $nr = array_push($wgInterwikiLinkHolders, $t);
191 $retVal = '<!--IWLINK '. ($nr-1) ."-->{$trail}";
195 } elseif ( 0 == $ns && "" == $dbkey ) {
196 # A self-link with a fragment; skip existence check.
197 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
198 } elseif ( ( NS_SPECIAL
== $ns ) ||
( NS_IMAGE
== $ns ) ) {
199 # These are always shown as existing, currently.
200 # Special pages don't exist in the database; images may
201 # occasionally be present when there is no description
202 # page per se, so we always shown them.
203 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
204 } elseif ( $this->postParseLinkColour
) {
205 wfProfileIn( $fname.'-postparse' );
206 # Insert a placeholder, and we'll work out the existence checks
207 # in a big lump later.
209 if ( '' != $trail ) {
210 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
216 # These get picked up by Parser::replaceLinkHolders()
217 $nr = array_push( $wgLinkHolders['namespaces'], $nt->getNamespace() );
218 $wgLinkHolders['dbkeys'][] = $dbkey;
219 $wgLinkHolders['queries'][] = $query;
220 $wgLinkHolders['texts'][] = $prefix.$text.$inside;
221 $wgLinkHolders['titles'][] =& $nt;
223 $retVal = '<!--LINK '. ($nr-1) ."-->{$trail}";
224 wfProfileOut( $fname.'-postparse' );
226 wfProfileIn( $fname.'-immediate' );
227 # Work out link colour immediately
228 $aid = $nt->getArticleID() ;
230 $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
232 $threshold = $wgUser->getOption('stubthreshold') ;
233 if ( $threshold > 0 ) {
234 $dbr =& wfGetDB( DB_SLAVE
);
235 $s = $dbr->selectRow(
239 'page_is_redirect' ),
240 array( 'page_id' => $aid ), $fname ) ;
241 if ( $s !== false ) {
242 $size = $s->page_len
;
243 if ( $s->page_is_redirect
OR $s->page_namespace
!= NS_MAIN
) {
244 $size = $threshold*2 ; # Really big
247 $size = $threshold*2 ; # Really big
252 if ( $size < $threshold ) {
253 $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
255 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
258 wfProfileOut( $fname.'-immediate' );
260 wfProfileOut( $fname );
265 * Pass a title object, not a title string
267 function makeKnownLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '' ) {
268 global $wgOut, $wgTitle, $wgInputEncoding;
270 $fname = 'Skin::makeKnownLinkObj';
271 wfProfileIn( $fname );
273 if ( !is_object( $nt ) ) {
274 wfProfileIn( $fname );
278 $u = $nt->escapeLocalURL( $query );
279 if ( '' != $nt->getFragment() ) {
280 if( $nt->getPrefixedDbkey() == '' ) {
283 $text = htmlspecialchars( $nt->getFragment() );
286 $anchor = urlencode( do_html_entity_decode( str_replace(' ', '_', $nt->getFragment()), ENT_COMPAT
, $wgInputEncoding ) );
287 $replacearray = array(
291 $u .= '#' . str_replace(array_keys($replacearray),array_values($replacearray),$anchor);
294 $text = htmlspecialchars( $nt->getPrefixedText() );
296 $style = $this->getInternalLinkAttributesObj( $nt, $text );
299 if ( '' != $trail ) {
300 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
305 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
306 wfProfileOut( $fname );
311 * Pass a title object, not a title string
313 function makeBrokenLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
315 if ( ! isset($nt) ) {
316 # wfDebugDieBacktrace();
317 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
320 $fname = 'Skin::makeBrokenLinkObj';
321 wfProfileIn( $fname );
323 if ( '' == $query ) {
326 $q = 'action=edit&'.$query;
328 $u = $nt->escapeLocalURL( $q );
331 $text = htmlspecialchars( $nt->getPrefixedText() );
333 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
336 if ( '' != $trail ) {
337 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
342 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
344 wfProfileOut( $fname );
349 * Pass a title object, not a title string
351 function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
352 $link = $nt->getPrefixedURL();
354 $u = $nt->escapeLocalURL( $query );
357 $text = htmlspecialchars( $nt->getPrefixedText() );
359 $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' );
362 if ( '' != $trail ) {
363 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
368 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
372 /** @todo document */
373 function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
374 $u = $nt->escapeLocalURL( $query );
376 $text = htmlspecialchars( $nt->getPrefixedText() );
379 if ( '' != $trail ) {
380 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
385 return "<strong>{$prefix}{$text}{$inside}</strong>{$trail}";
388 /** @todo document */
389 function fnamePart( $url ) {
390 $basename = strrchr( $url, '/' );
391 if ( false === $basename ) {
394 $basename = substr( $basename, 1 );
396 return htmlspecialchars( $basename );
399 /** @todo document */
400 function makeImage( $url, $alt = '' ) {
403 $alt = $this->fnamePart( $url );
405 $s = '<img src="'.$url.'" alt="'.$alt.'" />';
409 /** @todo document */
410 function makeImageLink( $name, $url, $alt = '' ) {
411 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
412 return $this->makeImageLinkObj( $nt, $alt );
415 /** @todo document */
416 function makeImageLinkObj( $nt, $alt = '' ) {
417 global $wgContLang, $wgUseImageResize;
418 global $wgUser, $wgThumbLimits;
420 $img = new Image( $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
500 # to the default user option as specified in Language*.php
501 if ( $align == '' ) {
502 $align = $wgContLang->isRTL() ?
'left' : 'right';
506 if ( ! isset($width) ) {
507 $wopt = $wgUser->getOption( 'thumbsize' );
509 if( !isset( $wgThumbLimits[$wopt] ) ) {
510 $wopt = User
::getDefaultOption( 'thumbsize' );
513 $width = $wgThumbLimits[$wopt];
516 return $prefix.$this->makeThumbLinkObj( $img, $alt, $align, $width, $height, $framed, $manual_thumb ).$postfix;
518 } elseif ( isset($width) ) {
520 # Create a resized image, without the additional thumbnail
523 if ( ( ! $height === false )
524 && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) {
525 $width = $img->getWidth() * $height / $img->getHeight();
527 if ( '' == $manual_thumb ) $url = $img->createThumb( $width );
530 # FIXME: This is a gross hack using a global.
531 # Replace link color holders in the caption text so the
532 # text portion can be placed int the alt/title attributes.
534 $wgParser->replaceLinkHolders( $alt );
536 $alt = Sanitizer
::stripAllTags( $alt );
538 $u = $nt->escapeLocalURL();
540 $s = $this->makeBrokenImageLinkObj( $img->getTitle() );
541 //$s .= "<br />{$alt}<br />{$url}<br />\n";
543 $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
544 '<img src="'.$url.'" alt="'.$alt.'" longdesc="'.$u.'" /></a>';
546 if ( '' != $align ) {
547 $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
549 return str_replace("\n", ' ',$prefix.$s.$postfix);
553 * Make HTML for a thumbnail including image, border and caption
554 * $img is an Image object
556 function makeThumbLinkObj( $img, $label = '', $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
557 global $wgStylePath, $wgContLang;
558 # $image = Title::makeTitleSafe( NS_IMAGE, $name );
559 $url = $img->getViewURL();
561 #$label = htmlspecialchars( $label );
562 $alt = Sanitizer
::stripAllTags( $label );
564 $width = $height = 0;
565 if ( $img->exists() )
567 $width = $img->getWidth();
568 $height = $img->getHeight();
570 if ( 0 == $width ||
0 == $height )
572 $width = $height = 200;
574 if ( $boxwidth == 0 )
580 // Use image dimensions, don't scale
582 $oboxwidth = $boxwidth +
2;
583 $boxheight = $height;
586 $h = intval( $height/($width/$boxwidth) );
587 $oboxwidth = $boxwidth +
2;
588 if ( ( ! $boxheight === false ) && ( $h > $boxheight ) )
590 $boxwidth *= $boxheight/$h;
594 if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth );
597 if ( $manual_thumb != '' ) # Use manually specified thumbnail
599 $manual_title = Title
::makeTitleSafe( NS_IMAGE
, $manual_thumb ); #new Title ( $manual_thumb ) ;
600 $manual_img = new Image( $manual_title );
601 $thumbUrl = $manual_img->getViewURL();
602 if ( $manual_img->exists() )
604 $width = $manual_img->getWidth();
605 $height = $manual_img->getHeight();
607 $boxheight = $height ;
608 $oboxwidth = $boxwidth +
2 ;
612 $u = $img->getEscapeLocalURL();
614 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
615 $magnifyalign = $wgContLang->isRTL() ?
'left' : 'right';
616 $textalign = $wgContLang->isRTL() ?
' style="text-align:right"' : '';
618 $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
619 if ( $thumbUrl == '' ) {
620 $s .= $this->makeBrokenImageLinkObj( $img->getTitle
);
623 $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
624 '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
625 'width="'.$boxwidth.'" height="'.$boxheight.'" ' .
626 'longdesc="'.$u.'" /></a>';
630 $zoomicon = '<div class="magnify" style="float:'.$magnifyalign.'">'.
631 '<a href="'.$u.'" class="internal" title="'.$more.'">'.
632 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
633 'width="15" height="11" alt="'.$more.'" /></a></div>';
636 $s .= ' <div class="thumbcaption" '.$textalign.'>'.$zoomicon.$label."</div></div></div>";
637 return str_replace("\n", ' ', $s);
641 * Pass a title object, not a title string
643 function makeBrokenImageLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
645 if ( ! isset($nt) ) {
646 # wfDebugDieBacktrace();
647 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
650 $fname = 'Skin::makeBrokenImageLinkObj';
651 wfProfileIn( $fname );
653 $q = 'wpDestFile=' . urlencode( $nt->getDBkey() );
654 if ( '' != $query ) {
657 $uploadTitle = Title
::makeTitle( NS_SPECIAL
, 'Upload' );
658 $url = $uploadTitle->escapeLocalURL( $q );
661 $text = htmlspecialchars( $nt->getPrefixedText() );
663 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
666 if ( '' != $trail ) {
667 if ( preg_match( $this->linktrail
, $trail, $m ) ) {
672 $s = "<a href=\"{$url}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
674 wfProfileOut( $fname );
678 /** @todo document */
679 function makeMediaLink( $name, $url, $alt = '' ) {
680 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
681 return $this->makeMediaLinkObj( $nt, $alt );
685 * Create a direct link to a given uploaded file.
687 * @param Title $title
688 * @param string $text pre-sanitized HTML
689 * @param bool $nourl Mask absolute URLs, so the parser doesn't
690 * linkify them (it is currently not context-aware)
691 * @return string HTML
694 * @todo Handle invalid or missing images better.
696 function makeMediaLinkObj( $title, $text = '', $nourl=false ) {
697 if( is_null( $title ) ) {
698 ### HOTFIX. Instead of breaking, return empty string.
701 $name = $title->getDBKey();
702 $img = new Image( $title );
703 $url = $img->getURL();
705 $url = str_replace( "http://", "http-noparse://", $url );
707 $alt = htmlspecialchars( $title->getText() );
711 $u = htmlspecialchars( $url );
712 return "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$text}</a>";
716 /** @todo document */
717 function specialLink( $name, $key = '' ) {
720 if ( '' == $key ) { $key = strtolower( $name ); }
721 $pn = $wgContLang->ucfirst( $name );
722 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
726 /** @todo document */
727 function makeExternalLink( $url, $text, $escape = true, $linktype = '' ) {
728 $style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
729 global $wgNoFollowLinks;
730 if( $wgNoFollowLinks ) {
731 $style .= ' rel="nofollow"';
733 $url = htmlspecialchars( $url );
735 $text = htmlspecialchars( $text );
737 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
741 * This function is called by all recent changes variants, by the page history,
742 * and by the user contributions list. It is responsible for formatting edit
743 * comments. It escapes any HTML in the comment, but adds some CSS to format
744 * auto-generated comments (from section editing) and formats [[wikilinks]].
746 * The &$title parameter must be a title OBJECT. It is used to generate a
747 * direct link to the section in the autocomment.
748 * @author Erik Moeller <moeller@scireview.de>
750 * Note: there's not always a title to pass to this function.
751 * Since you can't set a default parameter for a reference, I've turned it
752 * temporarily to a value pass. Should be adjusted further. --brion
754 function formatComment($comment, $title = NULL) {
755 $fname = 'Skin::formatComment';
756 wfProfileIn( $fname );
759 $comment = str_replace( "\n", " ", $comment );
760 $comment = htmlspecialchars( $comment );
762 # The pattern for autogen comments is / * foo * /, which makes for
764 # We look for all comments, match any text before and after the comment,
765 # add a separator where needed and format the comment itself with CSS
766 while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
774 # This is hackish but should work in most cases.
775 $section=str_replace('[[','',$section);
776 $section=str_replace(']]','',$section);
777 $title->mFragment
=$section;
778 $link=$this->makeKnownLinkObj($title,wfMsg('sectionlink'));
782 if($pre) { $auto = $sep.' '.$auto; }
783 if($post) { $auto .= ' '.$sep; }
784 $auto='<span class="autocomment">'.$auto.'</span>';
785 $comment=$pre.$auto.$post;
788 # format regular and media links - all other wiki formatting
790 $medians = $wgContLang->getNsText( NS_MEDIA
) . ':';
791 while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
792 # Handle link renaming [[foo|text]] will show link as "text"
793 if( "" != $match[3] ) {
798 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
799 # Media link; trail not supported.
800 $linkRegexp = '/\[\[(.*?)\]\]/';
801 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
804 if( preg_match( wfMsgForContent( "linktrail" ), $match[4], $submatch ) ) {
805 $trail = $submatch[1];
809 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
810 if ($match[1][0] == ':')
811 $match[1] = substr($match[1], 1);
812 $thelink = $this->makeLink( $match[1], $text, "", $trail );
814 $comment = preg_replace( $linkRegexp, $thelink, $comment, 1 );
816 wfProfileOut( $fname );
821 * Wrap a comment in standard punctuation and formatting if
822 * it's non-empty, otherwise return empty string.
824 * @param string $comment
825 * @param Title $title
829 function commentBlock( $comment, $title = NULL ) {
830 if( $comment == '' ||
$comment == '*' ) {
833 $formatted = $this->formatComment( $comment, $title );
834 return " <span class='comment'>($formatted)</span>";
838 /** @todo document */
839 function tocIndent() {
843 /** @todo document */
844 function tocUnindent($level) {
845 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ?
$level : 0 );
849 * parameter level defines if we are on an indentation level
851 function tocLine( $anchor, $tocline, $tocnumber, $level ) {
852 return "\n<li class='toclevel-$level'><a href=\"#" .
853 $anchor . '"><span class="tocnumber">' .
854 $tocnumber . '</span> <span class="toctext">' .
855 $tocline . '</span></a>';
858 /** @todo document */
859 function tocLineEnd() {
863 /** @todo document */
864 function tocList($toc) {
865 return "<div id='toc'>\n"
866 . "<div id='toctitle'><h2>" . wfMsg('toc') . "</h2></div>\n"
869 . '<script type="text/javascript">'
870 . ' if (window.showTocToggle) {'
871 . ' var tocShowText = "' . addslashes( wfMsg('showtoc') ) . '";'
872 . ' var tocHideText = "' . addslashes( wfMsg('hidetoc') ) . '"; '
873 . ' showTocToggle();'
876 . "<div class='visualClear'></div>\n";
879 /** @todo document */
880 function editSectionLinkForOther( $title, $section ) {
884 $title = Title
::newFromText($title);
885 $editurl = '§ion='.$section;
886 $url = $this->makeKnownLink($title->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
888 if( $wgContLang->isRTL() ) {
895 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
899 /** @todo document */
900 function editSectionLink( $nt, $section ) {
904 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
905 # Section edit links would be out of sync on an old page.
906 # But, if we're diffing to the current page, they'll be
911 $editurl = '§ion='.$section;
912 $url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
914 if( $wgContLang->isRTL() ) {
921 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";