fb3deefb4c3751c2feda757c4fba32a3f5e7a4f5
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.
25 function postParseLinkColour( $s = NULL ) {
30 function getExternalLinkAttributes( $link, $text, $class='' ) {
33 $same = ($link == $text);
34 $link = urldecode( $link );
35 $link = $wgContLang->checkTitleEncoding( $link );
36 $link = preg_replace( '/[\\x00-\\x1f_]/', ' ', $link );
37 $link = htmlspecialchars( $link );
39 $r = ($class != '') ?
" class='$class'" : " class='external'";
41 $r .= " title=\"{$link}\"";
46 function getInternalLinkAttributes( $link, $text, $broken = false ) {
47 $link = urldecode( $link );
48 $link = str_replace( '_', ' ', $link );
49 $link = htmlspecialchars( $link );
51 if( $broken == 'stub' ) {
53 } else if ( $broken == 'yes' ) {
59 $r .= " title=\"{$link}\"";
66 function getInternalLinkAttributesObj( &$nt, $text, $broken = false ) {
67 if( $broken == 'stub' ) {
69 } else if ( $broken == 'yes' ) {
75 $r .= ' title="' . $nt->getEscapedText() . '"';
80 * This function is a shortcut to makeLinkObj(Title::newFromText($title),...). Do not call
81 * it if you already have a title object handy. See makeLinkObj for further documentation.
83 * @param string $title The text of the title
84 * @param string $text Link text
85 * @param string $query Optional query part
86 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
87 * be included in the link text. Other characters will be appended after
88 * the end of the link.
90 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
91 wfProfileIn( 'Linker::makeLink' );
92 $nt = Title
::newFromText( $title );
94 $result = $this->makeLinkObj( Title
::newFromText( $title ), $text, $query, $trail );
96 wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" );
97 $result = $text == "" ?
$title : $text;
100 wfProfileOut( 'Linker::makeLink' );
105 * This function is a shortcut to makeKnownLinkObj(Title::newFromText($title),...). Do not call
106 * it if you already have a title object handy. See makeKnownLinkObj for further documentation.
108 * @param string $title The text of the title
109 * @param string $text Link text
110 * @param string $query Optional query part
111 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
112 * be included in the link text. Other characters will be appended after
113 * the end of the link.
115 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
116 $nt = Title
::newFromText( $title );
118 return $this->makeKnownLinkObj( Title
::newFromText( $title ), $text, $query, $trail, $prefix , $aprops );
120 wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" );
121 return $text == '' ?
$title : $text;
126 * This function is a shortcut to makeBrokenLinkObj(Title::newFromText($title),...). Do not call
127 * it if you already have a title object handy. See makeBrokenLinkObj for further documentation.
129 * @param string $title The text of the title
130 * @param string $text Link text
131 * @param string $query Optional query part
132 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
133 * be included in the link text. Other characters will be appended after
134 * the end of the link.
136 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
137 $nt = Title
::newFromText( $title );
139 return $this->makeBrokenLinkObj( Title
::newFromText( $title ), $text, $query, $trail );
141 wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" );
142 return $text == '' ?
$title : $text;
147 * This function is a shortcut to makeStubLinkObj(Title::newFromText($title),...). Do not call
148 * it if you already have a title object handy. See makeStubLinkObj for further documentation.
150 * @param string $title The text of the title
151 * @param string $text Link text
152 * @param string $query Optional query part
153 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
154 * be included in the link text. Other characters will be appended after
155 * the end of the link.
157 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
158 $nt = Title
::newFromText( $title );
160 return $this->makeStubLinkObj( Title
::newFromText( $title ), $text, $query, $trail );
162 wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" );
163 return $text == '' ?
$title : $text;
168 * Make a link for a title which may or may not be in the database. If you need to
169 * call this lots of times, pre-fill the link cache with a LinkBatch, otherwise each
170 * call to this will result in a DB query.
172 * @param string $title The text of the title
173 * @param string $text Link text
174 * @param string $query Optional query part
175 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
176 * be included in the link text. Other characters will be appended after
177 * the end of the link.
179 function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
181 $fname = 'Linker::makeLinkObj';
182 wfProfileIn( $fname );
185 if ( ! is_object($nt) ) {
186 # wfDebugDieBacktrace();
187 wfProfileOut( $fname );
188 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
191 $ns = $nt->getNamespace();
192 $dbkey = $nt->getDBkey();
193 if ( $nt->isExternal() ) {
194 $u = $nt->getFullURL();
195 $link = $nt->getPrefixedURL();
196 if ( '' == $text ) { $text = $nt->getPrefixedText(); }
197 $style = $this->getExternalLinkAttributes( $link, $text, 'extiw' );
200 if ( '' != $trail ) {
201 if ( preg_match( '/^([a-z]+)(.*)$$/sD', $trail, $m ) ) {
207 # Check for anchors, normalize the anchor
209 $parts = explode( '#', $u, 2 );
210 if ( count( $parts ) == 2 ) {
211 $anchor = urlencode( Sanitizer
::decodeCharReferences( str_replace(' ', '_', $parts[1] ) ) );
212 $replacearray = array(
216 $u = $parts[0] . '#' .
217 str_replace( array_keys( $replacearray ),
218 array_values( $replacearray ),
222 $t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
224 wfProfileOut( $fname );
226 } elseif ( $nt->isAlwaysKnown() ) {
227 # Image links, special page links and self-links with fragements are always known.
228 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
230 wfProfileIn( $fname.'-immediate' );
231 # Work out link colour immediately
232 $aid = $nt->getArticleID() ;
234 $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
236 $threshold = $wgUser->getOption('stubthreshold') ;
237 if ( $threshold > 0 ) {
238 $dbr =& wfGetDB( DB_SLAVE
);
239 $s = $dbr->selectRow(
243 'page_is_redirect' ),
244 array( 'page_id' => $aid ), $fname ) ;
245 if ( $s !== false ) {
246 $size = $s->page_len
;
247 if ( $s->page_is_redirect
OR $s->page_namespace
!= NS_MAIN
) {
248 $size = $threshold*2 ; # Really big
251 $size = $threshold*2 ; # Really big
256 if ( $size < $threshold ) {
257 $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
259 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
262 wfProfileOut( $fname.'-immediate' );
264 wfProfileOut( $fname );
269 * Make a link for a title which definitely exists. This is faster than makeLinkObj because
270 * it doesn't have to do a database query. It's also valid for interwiki titles and special
273 * @param object Title of target page
274 * @param string Text to replace the title
275 * @param string Link target
276 * @param string Text after link
277 * @param string Text before link text
278 * @param string Extra attributes to the a-element
279 * @return the a-element
281 function makeKnownLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '' ) {
283 $fname = 'Linker::makeKnownLinkObj';
284 wfProfileIn( $fname );
286 if ( !is_object( $nt ) ) {
287 wfProfileOut( $fname );
291 $u = $nt->escapeLocalURL( $query );
292 if ( '' != $nt->getFragment() ) {
293 if( $nt->getPrefixedDbkey() == '' ) {
296 $text = htmlspecialchars( $nt->getFragment() );
299 $anchor = urlencode( Sanitizer
::decodeCharReferences( str_replace( ' ', '_', $nt->getFragment() ) ) );
300 $replacearray = array(
304 $u .= '#' . str_replace(array_keys($replacearray),array_values($replacearray),$anchor);
307 $text = htmlspecialchars( $nt->getPrefixedText() );
309 $style = $this->getInternalLinkAttributesObj( $nt, $text );
311 if ( $aprops !== '' ) $aprops = ' ' . $aprops;
313 list( $inside, $trail ) = Linker
::splitTrail( $trail );
314 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
315 wfProfileOut( $fname );
320 * Make a red link to the edit page of a given title.
322 * @param string $title The text of the title
323 * @param string $text Link text
324 * @param string $query Optional query part
325 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
326 * be included in the link text. Other characters will be appended after
327 * the end of the link.
329 function makeBrokenLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
331 if ( ! isset($nt) ) {
332 # wfDebugDieBacktrace();
333 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
336 $fname = 'Linker::makeBrokenLinkObj';
337 wfProfileIn( $fname );
339 if ( '' == $query ) {
342 $q = 'action=edit&'.$query;
344 $u = $nt->escapeLocalURL( $q );
347 $text = htmlspecialchars( $nt->getPrefixedText() );
349 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
351 list( $inside, $trail ) = Linker
::splitTrail( $trail );
352 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
354 wfProfileOut( $fname );
359 * Make a brown link to a short article.
361 * @param string $title The text of the title
362 * @param string $text Link text
363 * @param string $query Optional query part
364 * @param string $trail Optional trail. Alphabetic characters at the start of this string will
365 * be included in the link text. Other characters will be appended after
366 * the end of the link.
368 function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
369 $link = $nt->getPrefixedURL();
371 $u = $nt->escapeLocalURL( $query );
374 $text = htmlspecialchars( $nt->getPrefixedText() );
376 $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' );
378 list( $inside, $trail ) = Linker
::splitTrail( $trail );
379 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
384 * Generate either a normal exists-style link or a stub link, depending
385 * on the given page size.
389 * @param string $text
390 * @param string $query
391 * @param string $trail
392 * @param string $prefix
393 * @return string HTML of link
395 function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
397 $threshold = intval( $wgUser->getOption( 'stubthreshold' ) );
398 if( $size < $threshold ) {
399 return $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
401 return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
406 * Make appropriate markup for a link to the current article. This is currently rendered
407 * as the bold link text. The calling sequence is the same as the other make*LinkObj functions,
408 * despite $query not being used.
410 function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
412 $text = htmlspecialchars( $nt->getPrefixedText() );
414 list( $inside, $trail ) = Linker
::splitTrail( $trail );
415 return "<strong>{$prefix}{$text}{$inside}</strong>{$trail}";
418 /** @todo document */
419 function fnamePart( $url ) {
420 $basename = strrchr( $url, '/' );
421 if ( false === $basename ) {
424 $basename = substr( $basename, 1 );
426 return htmlspecialchars( $basename );
429 /** Obsolete alias */
430 function makeImage( $url, $alt = '' ) {
431 return $this->makeExternalImage( $url, $alt );
434 /** @todo document */
435 function makeExternalImage( $url, $alt = '' ) {
437 $alt = $this->fnamePart( $url );
439 $s = '<img src="'.$url.'" alt="'.$alt.'" />';
443 /** @todo document */
444 function makeImageLinkObj( $nt, $label, $alt, $align = '', $width = false, $height = false, $framed = false,
445 $thumb = false, $manual_thumb = '' )
447 global $wgContLang, $wgUser, $wgThumbLimits;
449 $img = new Image( $nt );
450 if ( !$img->allowInlineDisplay() ) {
451 return $this->makeKnownLinkObj( $nt );
454 $url = $img->getViewURL();
455 $error = $prefix = $postfix = '';
457 wfDebug( "makeImageLinkObj: '$width'x'$height'\n" );
459 if ( 'center' == $align )
461 $prefix = '<div class="center">';
466 if ( $thumb ||
$framed ) {
468 # Create a thumbnail. Alignment depends on language
469 # writing direction, # right aligned for left-to-right-
470 # languages ("Western languages"), left-aligned
471 # for right-to-left-languages ("Semitic languages")
473 # If thumbnail width has not been provided, it is set
474 # to the default user option as specified in Language*.php
475 if ( $align == '' ) {
476 $align = $wgContLang->isRTL() ?
'left' : 'right';
480 if ( $width === false ) {
481 $wopt = $wgUser->getOption( 'thumbsize' );
483 if( !isset( $wgThumbLimits[$wopt] ) ) {
484 $wopt = User
::getDefaultOption( 'thumbsize' );
487 $width = min( $img->getWidth(), $wgThumbLimits[$wopt] );
490 return $prefix.$this->makeThumbLinkObj( $img, $label, $alt, $align, $width, $height, $framed, $manual_thumb ).$postfix;
493 if ( $width && $img->exists() ) {
495 # Create a resized image, without the additional thumbnail
498 if ( $height == false )
500 if ( $manual_thumb == '') {
501 $thumb = $img->getThumbnail( $width, $height );
503 // In most cases, $width = $thumb->width or $height = $thumb->height.
504 // If not, we're scaling the image larger than it can be scaled,
505 // so we send to the browser a smaller thumbnail, and let the client do the scaling.
507 if ($height != -1 && $width > $thumb->width
* $height / $thumb->height
) {
508 // $height is the limiting factor, not $width
509 // set $width to the largest it can be, such that the resulting
510 // scaled height is at most $height
511 $width = floor($thumb->width
* $height / $thumb->height
);
513 $height = round($thumb->height
* $width / $thumb->width
);
515 wfDebug( "makeImageLinkObj: client-size set to '$width x $height'\n" );
516 $url = $thumb->getUrl();
518 $error = htmlspecialchars( $img->getLastError() );
522 $width = $img->width
;
523 $height = $img->height
;
526 wfDebug( "makeImageLinkObj2: '$width'x'$height'\n" );
527 $u = $nt->escapeLocalURL();
530 } elseif ( $url == '' ) {
531 $s = $this->makeBrokenImageLinkObj( $img->getTitle() );
532 //$s .= "<br />{$alt}<br />{$url}<br />\n";
534 $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
535 '<img src="'.$url.'" alt="'.$alt.'" ' .
537 ?
( 'width="'.$width.'" height="'.$height.'" ' )
539 'longdesc="'.$u.'" /></a>';
541 if ( '' != $align ) {
542 $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
544 return str_replace("\n", ' ',$prefix.$s.$postfix);
548 * Make HTML for a thumbnail including image, border and caption
549 * $img is an Image object
551 function makeThumbLinkObj( $img, $label = '', $alt, $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
552 global $wgStylePath, $wgContLang;
553 $url = $img->getViewURL();
557 $width = $height = 0;
558 if ( $img->exists() ) {
559 $width = $img->getWidth();
560 $height = $img->getHeight();
562 if ( 0 == $width ||
0 == $height ) {
563 $width = $height = 200;
565 if ( $boxwidth == 0 ) {
569 // Use image dimensions, don't scale
571 $boxheight = $height;
574 if ( $boxheight === false )
576 if ( '' == $manual_thumb ) {
577 $thumb = $img->getThumbnail( $boxwidth, $boxheight );
579 $thumbUrl = $thumb->getUrl();
580 $boxwidth = $thumb->width
;
581 $boxheight = $thumb->height
;
583 $error = $img->getLastError();
587 $oboxwidth = $boxwidth +
2;
589 if ( $manual_thumb != '' ) # Use manually specified thumbnail
591 $manual_title = Title
::makeTitleSafe( NS_IMAGE
, $manual_thumb ); #new Title ( $manual_thumb ) ;
592 $manual_img = new Image( $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 // Couldn't generate thumbnail? Scale the image client-side.
616 $s .= htmlspecialchars( $error );
618 } elseif( !$img->exists() ) {
619 $s .= $this->makeBrokenImageLinkObj( $img->getTitle() );
622 $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
623 '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
624 'width="'.$boxwidth.'" height="'.$boxheight.'" ' .
625 'longdesc="'.$u.'" /></a>';
629 $zoomicon = '<div class="magnify" style="float:'.$magnifyalign.'">'.
630 '<a href="'.$u.'" class="internal" title="'.$more.'">'.
631 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
632 'width="15" height="11" alt="'.$more.'" /></a></div>';
635 $s .= ' <div class="thumbcaption" '.$textalign.'>'.$zoomicon.$label."</div></div></div>";
636 return str_replace("\n", ' ', $s);
640 * Pass a title object, not a title string
642 function makeBrokenImageLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
644 if ( ! isset($nt) ) {
645 # wfDebugDieBacktrace();
646 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
649 $fname = 'Linker::makeBrokenImageLinkObj';
650 wfProfileIn( $fname );
652 $q = 'wpDestFile=' . urlencode( $nt->getDBkey() );
653 if ( '' != $query ) {
656 $uploadTitle = Title
::makeTitle( NS_SPECIAL
, 'Upload' );
657 $url = $uploadTitle->escapeLocalURL( $q );
660 $text = htmlspecialchars( $nt->getPrefixedText() );
662 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
663 list( $inside, $trail ) = Linker
::splitTrail( $trail );
664 $s = "<a href=\"{$url}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
666 wfProfileOut( $fname );
670 /** @todo document */
671 function makeMediaLink( $name, /* wtf?! */ $url, $alt = '' ) {
672 $nt = Title
::makeTitleSafe( NS_IMAGE
, $name );
673 return $this->makeMediaLinkObj( $nt, $alt );
677 * Create a direct link to a given uploaded file.
679 * @param Title $title
680 * @param string $text pre-sanitized HTML
681 * @param bool $nourl Mask absolute URLs, so the parser doesn't
682 * linkify them (it is currently not context-aware)
683 * @return string HTML
686 * @todo Handle invalid or missing images better.
688 function makeMediaLinkObj( $title, $text = '' ) {
689 if( is_null( $title ) ) {
690 ### HOTFIX. Instead of breaking, return empty string.
693 $name = $title->getDBKey();
694 $img = new Image( $title );
695 if( $img->exists() ) {
696 $url = $img->getURL();
699 $upload = Title
::makeTitle( NS_SPECIAL
, 'Upload' );
700 $url = $upload->getLocalUrl( 'wpDestFile=' . urlencode( $img->getName() ) );
703 $alt = htmlspecialchars( $title->getText() );
707 $u = htmlspecialchars( $url );
708 return "<a href=\"{$u}\" class='$class' title=\"{$alt}\">{$text}</a>";
712 /** @todo document */
713 function specialLink( $name, $key = '' ) {
716 if ( '' == $key ) { $key = strtolower( $name ); }
717 $pn = $wgContLang->ucfirst( $name );
718 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
722 /** @todo document */
723 function makeExternalLink( $url, $text, $escape = true, $linktype = '' ) {
724 $style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
725 global $wgNoFollowLinks;
726 if( $wgNoFollowLinks ) {
727 $style .= ' rel="nofollow"';
729 $url = htmlspecialchars( $url );
731 $text = htmlspecialchars( $text );
733 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
737 * This function is called by all recent changes variants, by the page history,
738 * and by the user contributions list. It is responsible for formatting edit
739 * comments. It escapes any HTML in the comment, but adds some CSS to format
740 * auto-generated comments (from section editing) and formats [[wikilinks]].
742 * The $title parameter must be a title OBJECT. It is used to generate a
743 * direct link to the section in the autocomment.
744 * @author Erik Moeller <moeller@scireview.de>
746 * Note: there's not always a title to pass to this function.
747 * Since you can't set a default parameter for a reference, I've turned it
748 * temporarily to a value pass. Should be adjusted further. --brion
750 function formatComment($comment, $title = NULL) {
751 $fname = 'Linker::formatComment';
752 wfProfileIn( $fname );
755 $comment = str_replace( "\n", " ", $comment );
756 $comment = htmlspecialchars( $comment );
758 # The pattern for autogen comments is / * foo * /, which makes for
760 # We look for all comments, match any text before and after the comment,
761 # add a separator where needed and format the comment itself with CSS
762 while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
770 # This is hackish but should work in most cases.
771 $section = str_replace( '[[', '', $section );
772 $section = str_replace( ']]', '', $section );
773 $sectionTitle = wfClone( $title );
774 $sectionTitle->mFragment
= $section;
775 $link = $this->makeKnownLinkObj( $sectionTitle, wfMsg( 'sectionlink' ) );
779 if($pre) { $auto = $sep.' '.$auto; }
780 if($post) { $auto .= ' '.$sep; }
781 $auto='<span class="autocomment">'.$auto.'</span>';
782 $comment=$pre.$auto.$post;
785 # format regular and media links - all other wiki formatting
787 $medians = $wgContLang->getNsText( NS_MEDIA
) . ':';
788 while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
789 # Handle link renaming [[foo|text]] will show link as "text"
790 if( "" != $match[3] ) {
795 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
796 # Media link; trail not supported.
797 $linkRegexp = '/\[\[(.*?)\]\]/';
798 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
801 if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
802 $trail = $submatch[1];
806 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
807 if ($match[1][0] == ':')
808 $match[1] = substr($match[1], 1);
809 $thelink = $this->makeLink( $match[1], $text, "", $trail );
811 $comment = preg_replace( $linkRegexp, wfRegexReplacement( $thelink ), $comment, 1 );
813 wfProfileOut( $fname );
818 * Wrap a comment in standard punctuation and formatting if
819 * it's non-empty, otherwise return empty string.
821 * @param string $comment
822 * @param Title $title
823 * @param bool $deleted
827 function commentBlock( $comment, $title = NULL, $deleted = false ) {
828 // '*' used to be the comment inserted by the software way back
829 // in antiquity in case none was provided, here for backwards
830 // compatability, acc. to brion -ævar
831 if( $comment == '' ||
$comment == '*' ) {
835 return " <span class='comment'>(...)</span>";
837 $formatted = $this->formatComment( $comment, $title );
838 return " <span class='comment'>($formatted)</span>";
843 /** @todo document */
844 function tocIndent() {
848 /** @todo document */
849 function tocUnindent($level) {
850 return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level>0 ?
$level : 0 );
854 * parameter level defines if we are on an indentation level
856 function tocLine( $anchor, $tocline, $tocnumber, $level ) {
857 return "\n<li class='toclevel-$level'><a href=\"#" .
858 $anchor . '"><span class="tocnumber">' .
859 $tocnumber . '</span> <span class="toctext">' .
860 $tocline . '</span></a>';
863 /** @todo document */
864 function tocLineEnd() {
868 /** @todo document */
869 function tocList($toc) {
870 global $wgJsMimeType;
871 $title = wfMsgForContent('toc') ;
873 '<table id="toc" class="toc" summary="' . $title .'"><tr><td>'
874 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
876 . "</ul>\n</td></tr></table>\n"
877 . '<script type="' . $wgJsMimeType . '">'
878 . ' if (window.showTocToggle) {'
879 . ' var tocShowText = "' . wfEscapeJsString( wfMsgForContent('showtoc') ) . '";'
880 . ' var tocHideText = "' . wfEscapeJsString( wfMsgForContent('hidetoc') ) . '";'
881 . ' showTocToggle();'
886 /** @todo document */
887 function editSectionLinkForOther( $title, $section ) {
890 $title = Title
::newFromText( $title );
891 $editurl = '§ion='.$section;
892 $url = $this->makeKnownLinkObj( $title, wfMsg('editsection'), 'action=edit'.$editurl );
894 if( $wgContLang->isRTL() ) {
901 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
905 /** @todo document */
906 function editSectionLink( $nt, $section ) {
909 $editurl = '§ion='.$section;
910 $url = $this->makeKnownLinkObj( $nt, wfMsg('editsection'), 'action=edit'.$editurl );
912 if( $wgContLang->isRTL() ) {
919 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
923 * Split a link trail, return the "inside" portion and the remainder of the trail
924 * as a two-element array
928 function splitTrail( $trail ) {
929 static $regex = false;
930 if ( $regex === false ) {
932 $regex = $wgContLang->linkTrail();
935 if ( '' != $trail ) {
936 if ( preg_match( $regex, $trail, $m ) ) {
941 return array( $inside, $trail );