98c0d558280deae5c5a495991b52062af10aefd3
3 include_once('Tokenizer.php');
7 # Converts wikitext to HTML.
10 # objects: $wgLang, $wgDateFormatter, $wgLinkCache, $wgCurOut
12 # NOT $wgArticle, $wgUser or $wgTitle. Keep them away!
14 # settings: $wgUseTex*, $wgUseCategoryMagic*, $wgUseDynamicDates*, $wgInterwikiMagic*,
15 # $wgNamespacesWithSubpages, $wgLanguageCode, $wgAllowExternalImages*,
18 # * only within ParserOptions
22 # Cleared with clearState():
23 var $mOutput, $mAutonumber, $mLastSection, $mDTopen, $mStripState;
26 var $mOptions, $mTitle;
35 $this->mOutput
= new ParserOutput
;
36 $this->mAutonumber
= 0;
37 $this->mLastSection
= "";
38 $this->mDTopen
= false;
39 $this->mStripState
= false;
42 # First pass--just handle <nowiki> sections, pass the rest off
43 # to doWikiPass2() which does all the real work.
45 # Returns a ParserOutput
47 function parse( $text, &$title, $options, $linestart = true, $clearState = true )
49 $fname = "Parser::parse";
50 wfProfileIn( $fname );
56 $this->mOptions
= $options;
57 $this->mTitle
=& $title;
60 $text = $this->strip( $text, $this->mStripState
, true );
61 $text = $this->doWikiPass2( $text, $linestart );
62 $text = $this->unstrip( $text, $this->mStripState
);
64 $this->mOutput
->setText( $text );
65 wfProfileOut( $fname );
66 return $this->mOutput
;
69 /* static */ function getRandomString()
71 return dechex(mt_rand(0, 0x7fffffff)) . dechex(mt_rand(0, 0x7fffffff));
74 # Strips <nowiki>, <pre> and <math>
75 # Returns the text, and fills an array with data needed in unstrip()
77 function strip( $text, &$state, $render = true )
82 'nwunq' => Parser
::getRandomString(),
83 'mathlist' => array(),
85 'mathunq' => Parser
::getRandomString(),
88 'preunq' => Parser
::getRandomString()
95 # Replace any instances of the placeholders
96 $text = str_replace( $state['nwunq'], wfHtmlEscapeFirst( $state['nwunq'] ), $text );
97 $text = str_replace( $state['mathunq'], wfHtmlEscapeFirst( $state['mathunq'] ), $text );
98 $text = str_replace( $state['preunq'], wfHtmlEscapeFirst( $state['preunq'] ), $text );
100 while ( "" != $text ) {
101 $p = preg_split( "/<\\s*nowiki\\s*>/i", $text, 2 );
103 if ( ( count( $p ) < 2 ) ||
( "" == $p[1] ) ) {
106 $q = preg_split( "/<\\/\\s*nowiki\\s*>/i", $p[1], 2 );
110 $state['nwlist'][$state['nwsecs']] = wfEscapeHTMLTagsOnly($q[0]);
112 $state['nwlist'][$state['nwsecs']] = "<nowiki>{$q[0]}</nowiki>";
115 $stripped .= $state['nwunq'] . sprintf("%08X", $state['nwsecs']);
120 if( $this->mOptions
->getUseTeX() ) {
121 while ( "" != $stripped ) {
122 $p = preg_split( "/<\\s*math\\s*>/i", $stripped, 2 );
124 if ( ( count( $p ) < 2 ) ||
( "" == $p[1] ) ) {
127 $q = preg_split( "/<\\/\\s*math\\s*>/i", $p[1], 2 );
128 ++
$state['mathsecs'];
131 $state['mathlist'][$state['mathsecs']] = renderMath($q[0]);
133 $state['mathlist'][$state['mathsecs']] = "<math>{$q[0]}</math>";
136 $stripped2 .= $state['mathunq'] . sprintf("%08X", $state['mathsecs']);
141 $stripped2 = $stripped;
144 while ( "" != $stripped2 ) {
145 $p = preg_split( "/<\\s*pre\\s*>/i", $stripped2, 2 );
147 if ( ( count( $p ) < 2 ) ||
( "" == $p[1] ) ) {
150 $q = preg_split( "/<\\/\\s*pre\\s*>/i", $p[1], 2 );
154 $state['prelist'][$state['presecs']] = "<pre>". wfEscapeHTMLTagsOnly($q[0]). "</pre>\n";
156 $state['prelist'][$state['presecs']] = "<pre>{$q[0]}</pre>";
159 $stripped3 .= $state['preunq'] . sprintf("%08X", $state['presecs']);
166 function unstrip( $text, &$state )
168 for ( $i = 1; $i <= $state['presecs']; ++
$i ) {
169 $text = str_replace( $state['preunq'] . sprintf("%08X", $i), $state['prelist'][$i], $text );
172 for ( $i = 1; $i <= $state['mathsecs']; ++
$i ) {
173 $text = str_replace( $state['mathunq'] . sprintf("%08X", $i), $state['mathlist'][$i], $text );
176 for ( $i = 1; $i <= $state['nwsecs']; ++
$i ) {
177 $text = str_replace( $state['nwunq'] . sprintf("%08X", $i), $state['nwlist'][$i], $text );
182 function categoryMagic ()
184 global $wgLang , $wgUser ;
185 if ( !$this->mOptions
->getUseCategoryMagic() ) return ;
186 $id = $this->mTitle
->getArticleID() ;
187 $cat = ucfirst ( wfMsg ( "category" ) ) ;
188 $ti = $this->mTitle
->getText() ;
189 $ti = explode ( ":" , $ti , 2 ) ;
190 if ( $cat != $ti[0] ) return "" ;
191 $r = "<br break=all>\n" ;
193 $articles = array() ;
194 $parents = array () ;
195 $children = array() ;
198 # $sk =& $this->mGetSkin();
199 $sk =& $wgUser->getSkin() ;
203 $sql = "SELECT l_from FROM links WHERE l_to={$id}" ;
205 $sql = "SELECT cur_title,cur_namespace FROM cur,brokenlinks WHERE bl_to={$id} AND bl_from=cur_id" ;
208 $res = wfQuery ( $sql, DB_READ
) ;
209 while ( $x = wfFetchObject ( $res ) )
212 # $t->newFromDBkey ( $x->l_from ) ;
213 # $t = $t->getText() ;
217 $t = $wgLang->getNsText ( $x->cur_namespace
) ;
218 if ( $t != "" ) $t .= ":" ;
219 $t .= $x->cur_title
;
222 $y = explode ( ":" , $t , 2 ) ;
223 if ( count ( $y ) == 2 && $y[0] == $cat ) {
224 array_push ( $children , $sk->makeLink ( $t , $y[1] ) ) ;
226 array_push ( $articles , $sk->makeLink ( $t ) ) ;
229 wfFreeResult ( $res ) ;
232 if ( count ( $children ) > 0 )
234 asort ( $children ) ;
235 $r .= "<h2>".wfMsg("subcategories")."</h2>\n" ;
236 $r .= implode ( ", " , $children ) ;
240 if ( count ( $articles ) > 0 )
242 asort ( $articles ) ;
243 $h = wfMsg( "category_header", $ti[1] );
244 $r .= "<h2>{$h}</h2>\n" ;
245 $r .= implode ( ", " , $articles ) ;
252 function getHTMLattrs ()
254 $htmlattrs = array( # Allowed attributes--no scripting, etc.
255 "title", "align", "lang", "dir", "width", "height",
256 "bgcolor", "clear", /* BR */ "noshade", /* HR */
257 "cite", /* BLOCKQUOTE, Q */ "size", "face", "color",
258 /* FONT */ "type", "start", "value", "compact",
259 /* For various lists, mostly deprecated but safe */
260 "summary", "width", "border", "frame", "rules",
261 "cellspacing", "cellpadding", "valign", "char",
262 "charoff", "colgroup", "col", "span", "abbr", "axis",
263 "headers", "scope", "rowspan", "colspan", /* Tables */
264 "id", "class", "name", "style" /* For CSS */
269 function fixTagAttributes ( $t )
271 if ( trim ( $t ) == "" ) return "" ; # Saves runtime ;-)
272 $htmlattrs = $this->getHTMLattrs() ;
274 # Strip non-approved attributes from the tag
276 "/(\\w+)(\\s*=\\s*([^\\s\">]+|\"[^\">]*\"))?/e",
277 "(in_array(strtolower(\"\$1\"),\$htmlattrs)?(\"\$1\".((\"x\$3\" != \"x\")?\"=\$3\":'')):'')",
279 # Strip javascript "expression" from stylesheets. Brute force approach:
280 # If anythin offensive is found, all attributes of the HTML tag are dropped
283 "/style\\s*=.*(expression|tps*:\/\/|url\\s*\().*/is",
284 wfMungeToUtf8( $t ) ) )
292 function doTableStuff ( $t )
294 $t = explode ( "\n" , $t ) ;
295 $td = array () ; # Is currently a td tag open?
296 $ltd = array () ; # Was it TD or TH?
297 $tr = array () ; # Is currently a tr tag open?
298 $ltr = array () ; # tr attributes
299 foreach ( $t AS $k => $x )
302 $fc = substr ( $x , 0 , 1 ) ;
303 if ( "{|" == substr ( $x , 0 , 2 ) )
305 $t[$k] = "<table " . $this->fixTagAttributes ( substr ( $x , 3 ) ) . ">" ;
306 array_push ( $td , false ) ;
307 array_push ( $ltd , "" ) ;
308 array_push ( $tr , false ) ;
309 array_push ( $ltr , "" ) ;
311 else if ( count ( $td ) == 0 ) { } # Don't do any of the following
312 else if ( "|}" == substr ( $x , 0 , 2 ) )
315 $l = array_pop ( $ltd ) ;
316 if ( array_pop ( $tr ) ) $z = "</tr>" . $z ;
317 if ( array_pop ( $td ) ) $z = "</{$l}>" . $z ;
321 /* else if ( "|_" == substr ( $x , 0 , 2 ) ) # Caption
323 $z = trim ( substr ( $x , 2 ) ) ;
324 $t[$k] = "<caption>{$z}</caption>\n" ;
326 else if ( "|-" == substr ( $x , 0 , 2 ) ) # Allows for |---------------
328 $x = substr ( $x , 1 ) ;
329 while ( $x != "" && substr ( $x , 0 , 1 ) == '-' ) $x = substr ( $x , 1 ) ;
331 $l = array_pop ( $ltd ) ;
332 if ( array_pop ( $tr ) ) $z = "</tr>" . $z ;
333 if ( array_pop ( $td ) ) $z = "</{$l}>" . $z ;
336 array_push ( $tr , false ) ;
337 array_push ( $td , false ) ;
338 array_push ( $ltd , "" ) ;
339 array_push ( $ltr , $this->fixTagAttributes ( $x ) ) ;
341 else if ( "|" == $fc ||
"!" == $fc ||
"|+" == substr ( $x , 0 , 2 ) ) # Caption
343 if ( "|+" == substr ( $x , 0 , 2 ) )
346 $x = substr ( $x , 1 ) ;
348 $after = substr ( $x , 1 ) ;
349 if ( $fc == "!" ) $after = str_replace ( "!!" , "||" , $after ) ;
350 $after = explode ( "||" , $after ) ;
352 foreach ( $after AS $theline )
357 $tra = array_pop ( $ltr ) ;
358 if ( !array_pop ( $tr ) ) $z = "<tr {$tra}>\n" ;
359 array_push ( $tr , true ) ;
360 array_push ( $ltr , "" ) ;
363 $l = array_pop ( $ltd ) ;
364 if ( array_pop ( $td ) ) $z = "</{$l}>" . $z ;
365 if ( $fc == "|" ) $l = "TD" ;
366 else if ( $fc == "!" ) $l = "TH" ;
367 else if ( $fc == "+" ) $l = "CAPTION" ;
369 array_push ( $ltd , $l ) ;
370 $y = explode ( "|" , $theline , 2 ) ;
371 if ( count ( $y ) == 1 ) $y = "{$z}<{$l}>{$y[0]}" ;
372 else $y = $y = "{$z}<{$l} ".$this->fixTagAttributes($y[0]).">{$y[1]}" ;
374 array_push ( $td , true ) ;
379 # Closing open td, tr && table
380 while ( count ( $td ) > 0 )
382 if ( array_pop ( $td ) ) $t[] = "</td>" ;
383 if ( array_pop ( $tr ) ) $t[] = "</tr>" ;
387 $t = implode ( "\n" , $t ) ;
388 # $t = $this->removeHTMLtags( $t );
392 # Well, OK, it's actually about 14 passes. But since all the
393 # hard lifting is done inside PHP's regex code, it probably
394 # wouldn't speed things up much to add a real parser.
396 function doWikiPass2( $text, $linestart )
398 $fname = "OutputPage::doWikiPass2";
399 wfProfileIn( $fname );
401 $text = $this->removeHTMLtags( $text );
402 $text = $this->replaceVariables( $text );
404 # $text = preg_replace( "/(^|\n)-----*/", "\\1<hr>", $text );
405 $text = str_replace ( "<HR>", "<hr>", $text );
407 $text = $this->doHeadings( $text );
408 $text = $this->doBlockLevels( $text, $linestart );
410 if($this->mOptions
->getUseDynamicDates()) {
411 global $wgDateFormatter;
412 $text = $wgDateFormatter->reformat( $this->mOptions
->getDateFormat(), $text );
415 $text = $this->replaceExternalLinks( $text );
416 $text = $this->replaceInternalLinks ( $text );
417 $text = $this->doTableStuff ( $text ) ;
419 $text = $this->formatHeadings( $text );
421 $sk =& $this->mOptions
->getSkin();
422 $text = $sk->transformContent( $text );
423 $text .= $this->categoryMagic () ;
425 wfProfileOut( $fname );
430 /* private */ function doHeadings( $text )
432 for ( $i = 6; $i >= 1; --$i ) {
433 $h = substr( "======", 0, $i );
434 $text = preg_replace( "/^{$h}([^=]+){$h}(\\s|$)/m",
435 "<h{$i}>\\1</h{$i}>\\2", $text );
440 # Note: we have to do external links before the internal ones,
441 # and otherwise take great care in the order of things here, so
442 # that we don't end up interpreting some URLs twice.
444 /* private */ function replaceExternalLinks( $text )
446 $fname = "OutputPage::replaceExternalLinks";
447 wfProfileIn( $fname );
448 $text = $this->subReplaceExternalLinks( $text, "http", true );
449 $text = $this->subReplaceExternalLinks( $text, "https", true );
450 $text = $this->subReplaceExternalLinks( $text, "ftp", false );
451 $text = $this->subReplaceExternalLinks( $text, "irc", false );
452 $text = $this->subReplaceExternalLinks( $text, "gopher", false );
453 $text = $this->subReplaceExternalLinks( $text, "news", false );
454 $text = $this->subReplaceExternalLinks( $text, "mailto", false );
455 wfProfileOut( $fname );
459 /* private */ function subReplaceExternalLinks( $s, $protocol, $autonumber )
461 $unique = "4jzAfzB8hNvf4sqyO9Edd8pSmk9rE2in0Tgw3";
462 $uc = "A-Za-z0-9_\\/~%\\-+&*#?!=()@\\x80-\\xFF";
464 # this is the list of separators that should be ignored if they
465 # are the last character of an URL but that should be included
466 # if they occur within the URL, e.g. "go to www.foo.com, where .."
467 # in this case, the last comma should not become part of the URL,
468 # but in "www.foo.com/123,2342,32.htm" it should.
470 $fnc = "A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF";
471 $images = "gif|png|jpg|jpeg";
473 # PLEASE NOTE: The curly braces { } are not part of the regex,
474 # they are interpreted as part of the string (used to tell PHP
475 # that the content of the string should be inserted there).
476 $e1 = "/(^|[^\\[])({$protocol}:)([{$uc}{$sep}]+)\\/([{$fnc}]+)\\." .
477 "((?i){$images})([^{$uc}]|$)/";
479 $e2 = "/(^|[^\\[])({$protocol}:)(([".$uc."]|[".$sep."][".$uc."])+)([^". $uc . $sep. "]|[".$sep."]|$)/";
480 $sk =& $this->mOptions
->getSkin();
482 if ( $autonumber and $this->mOptions
->getAllowExternalImages() ) { # Use img tags only for HTTP urls
483 $s = preg_replace( $e1, "\\1" . $sk->makeImage( "{$unique}:\\3" .
484 "/\\4.\\5", "\\4.\\5" ) . "\\6", $s );
486 $s = preg_replace( $e2, "\\1" . "<a href=\"{$unique}:\\3\"" .
487 $sk->getExternalLinkAttributes( "{$unique}:\\3", wfEscapeHTML(
488 "{$unique}:\\3" ) ) . ">" . wfEscapeHTML( "{$unique}:\\3" ) .
490 $s = str_replace( $unique, $protocol, $s );
492 $a = explode( "[{$protocol}:", " " . $s );
493 $s = array_shift( $a );
494 $s = substr( $s, 1 );
496 $e1 = "/^([{$uc}"."{$sep}]+)](.*)\$/sD";
497 $e2 = "/^([{$uc}"."{$sep}]+)\\s+([^\\]]+)](.*)\$/sD";
499 foreach ( $a as $line ) {
500 if ( preg_match( $e1, $line, $m ) ) {
501 $link = "{$protocol}:{$m[1]}";
503 if ( $autonumber ) { $text = "[" . ++
$this->mAutonumber
. "]"; }
504 else { $text = wfEscapeHTML( $link ); }
505 } else if ( preg_match( $e2, $line, $m ) ) {
506 $link = "{$protocol}:{$m[1]}";
510 $s .= "[{$protocol}:" . $line;
513 if ( $this->mOptions
->getPrintable() ) $paren = " (<i>" . htmlspecialchars ( $link ) . "</i>)";
515 $la = $sk->getExternalLinkAttributes( $link, $text );
516 $s .= "<a href='{$link}'{$la}>{$text}</a>{$paren}{$trail}";
522 /* private */ function handle3Quotes( &$state, $token )
524 if ( $state["strong"] ) {
525 if ( $state["em"] && $state["em"] > $state["strong"] )
527 # ''' lala ''lala '''
528 $s = "</em></strong><em>";
532 $state["strong"] = FALSE;
535 $state["strong"] = $token["pos"];
540 /* private */ function handle2Quotes( &$state, $token )
542 if ( $state["em"] ) {
543 if ( $state["strong"] && $state["strong"] > $state["em"] )
545 # ''lala'''lala'' ....'''
546 $s = "</strong></em><strong>";
550 $state["em"] = FALSE;
553 $state["em"] = $token["pos"];
558 /* private */ function handle5Quotes( &$state, $token )
560 if ( $state["em"] && $state["strong"] ) {
561 if ( $state["em"] < $state["strong"] ) {
562 $s .= "</strong></em>";
564 $s .= "</em></strong>";
566 $state["strong"] = $state["em"] = FALSE;
567 } elseif ( $state["em"] ) {
568 $s .= "</em><strong>";
569 $state["em"] = FALSE;
570 $state["strong"] = $token["pos"];
571 } elseif ( $state["strong"] ) {
572 $s .= "</strong><em>";
573 $state["strong"] = FALSE;
574 $state["em"] = $token["pos"];
575 } else { # not $em and not $strong
576 $s .= "<strong><em>";
577 $state["strong"] = $state["em"] = $token["pos"];
582 /* private */ function replaceInternalLinks( $str )
584 global $wgLang; # for language specific parser hook
586 $tokenizer=Tokenizer
::newFromString( $str );
587 $tokenStack = array();
590 $state["em"] = FALSE;
591 $state["strong"] = FALSE;
594 # The tokenizer splits the text into tokens and returns them one by one.
595 # Every call to the tokenizer returns a new token.
596 while ( $token = $tokenizer->nextToken() )
598 switch ( $token["type"] )
601 # simple text with no further markup
602 $txt = $token["text"];
606 # FIXME : Treat orphaned open tags (stack not empty when text is over)
608 array_push( $tokenStack, $token );
613 # get text from stack, glue it together, and call the code to handle a
615 if ( count( $tokenStack ) == 0 )
617 # stack empty. Found a ]] without an opening [[
621 $lastToken = array_pop( $tokenStack );
622 while ( $lastToken["type"] != "[[" )
624 $linkText = $lastToken["text"] . $linkText;
625 $lastToken = array_pop( $tokenStack );
627 $txt = $linkText ."]]";
628 $prefix = $lastToken["text"];
629 $nextToken = $tokenizer->previewToken();
630 if ( $nextToken["type"] == "text" )
632 # Preview just looks at it. Now we have to fetch it.
633 $nextToken = $tokenizer->nextToken();
634 $txt .= $nextToken["text"];
636 $txt = $this->handleInternalLink( $txt, $prefix );
638 $tagIsOpen = (count( $tokenStack ) != 0);
644 # This and the three next ones handle quotes
645 $txt = $this->handle3Quotes( $state, $token );
648 $txt = $this->handle2Quotes( $state, $token );
651 $txt = $this->handle5Quotes( $state, $token );
658 $txt = $this->doMagicRFC( $tokenizer );
661 $txt = $this->doMagicISBN( $tokenizer );
664 # Call language specific Hook.
665 $txt = $wgLang->processToken( $token, $tokenStack );
666 if ( NULL == $txt ) {
667 # An unkown token. Highlight.
668 $txt = "<font color=\"#FF0000\"><b>".$token["type"]."</b></font>";
669 $txt .= "<font color=\"#FFFF00\"><b>".$token["text"]."</b></font>";
673 # If we're parsing the interior of a link, don't append the interior to $s,
674 # but push it to the stack so it can be processed when a ]] token is found.
675 if ( $tagIsOpen && $txt != "" ) {
676 $token["type"] = "text";
677 $token["text"] = $txt;
678 array_push( $tokenStack, $token );
683 if ( count( $tokenStack ) != 0 )
685 # still objects on stack. opened [[ tag without closing ]] tag.
687 while ( $lastToken = array_pop( $tokenStack ) )
689 if ( $lastToken["type"] == "text" )
691 $txt = $lastToken["text"] . $txt;
693 $txt = $lastToken["type"] . $txt;
701 /* private */ function handleInternalLink( $line, $prefix )
703 global $wgLang, $wgLinkCache;
704 global $wgNamespacesWithSubpages, $wgLanguageCode;
705 static $fname = "OutputPage::replaceInternalLinks" ;
706 wfProfileIn( $fname );
708 wfProfileIn( "$fname-setup" );
710 if ( !$tc ) { $tc = Title
::legalChars() . "#"; }
711 $sk =& $this->mOptions
->getSkin();
713 # Match a link having the form [[namespace:link|alternate]]trail
715 if ( !$e1 ) { $e1 = "/^([{$tc}]+)(?:\\|([^]]+))?]](.*)\$/sD"; }
716 # Match the end of a line for a word that's not followed by whitespace,
717 # e.g. in the case of 'The Arab al[[Razi]]', 'al' will be matched
718 #$e2 = "/^(.*)\\b(\\w+)\$/suD";
719 #$e2 = "/^(.*\\s)(\\S+)\$/suD";
720 static $e2 = '/^(.*\s)([a-zA-Z\x80-\xff]+)$/sD';
723 # Special and Media are pseudo-namespaces; no pages actually exist in them
724 static $image = FALSE;
725 static $special = FALSE;
726 static $media = FALSE;
727 static $category = FALSE;
728 if ( !$image ) { $image = Namespace::getImage(); }
729 if ( !$special ) { $special = Namespace::getSpecial(); }
730 if ( !$media ) { $media = Namespace::getMedia(); }
731 if ( !$category ) { $category = wfMsg ( "category" ) ; }
733 $nottalk = !Namespace::isTalk( $this->mTitle
->getNamespace() );
735 wfProfileOut( "$fname-setup" );
737 if ( preg_match( $e1, $line, $m ) ) { # page with normal text or alt
740 } else { # Invalid form; output directly
741 $s .= $prefix . "[[" . $line ;
747 :Foobar -- override special treatment of prefix (images, language links)
748 /Foobar -- convert to CurrentPage/Foobar
749 /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text
751 $c = substr($m[1],0,1);
752 $noforce = ($c != ":");
753 if( $c == "/" ) { # subpage
754 if(substr($m[1],-1,1)=="/") { # / at end means we don't want the slash to be shown
755 $m[1]=substr($m[1],1,strlen($m[1])-2);
758 $noslash=substr($m[1],1);
760 if($wgNamespacesWithSubpages[$this->mTitle
->getNamespace()]) { # subpages allowed here
761 $link = $this->mTitle
->getPrefixedText(). "/" . trim($noslash);
764 } # this might be changed for ugliness reasons
766 $link = $noslash; # no subpage allowed, use standard link
768 } elseif( $noforce ) { # no subpage
771 $link = substr( $m[1], 1 );
776 $nt = Title
::newFromText( $link );
778 $s .= $prefix . "[[" . $line;
781 $ns = $nt->getNamespace();
782 $iw = $nt->getInterWiki();
784 if( $iw && $wgInterwikiMagic && $nottalk && $wgLang->getLanguageName( $iw ) ) {
785 array_push( $this->mOutput
->mLanguageLinks
, $nt->getPrefixedText() );
786 $s .= $prefix . $trail;
789 if( $ns == $image ) {
790 $s .= $prefix . $sk->makeImageLinkObj( $nt, $text ) . $trail;
791 $wgLinkCache->addImageLinkObj( $nt );
795 if( ( $nt->getPrefixedText() == $this->mTitle
->getPrefixedText() ) &&
796 ( strpos( $link, "#" ) == FALSE ) ) {
797 $s .= $prefix . "<strong>" . $text . "</strong>" . $trail;
800 if ( $ns == $category && $this->mOptions
->getUseCategoryMagic() ) {
801 $t = explode ( ":" , $nt->getText() ) ;
803 $t = implode ( ":" , $t ) ;
804 $t = $wgLang->ucFirst ( $t ) ;
805 # $t = $sk->makeKnownLink( $category.":".$t, $t, "", $trail , $prefix );
806 $nnt = Title
::newFromText ( $category.":".$t ) ;
807 $t = $sk->makeLinkObj( $nnt, $t, "", $trail , $prefix );
808 $this->mCategoryLinks
[] = $t ;
809 $s .= $prefix . $trail ;
812 if( $ns == $media ) {
813 $s .= $prefix . $sk->makeMediaLinkObj( $nt, $text ) . $trail;
814 $wgLinkCache->addImageLinkObj( $nt );
816 } elseif( $ns == $special ) {
817 $s .= $prefix . $sk->makeKnownLinkObj( $nt, $text, "", $trail );
820 $s .= $sk->makeLinkObj( $nt, $text, "", $trail , $prefix );
822 wfProfileOut( $fname );
826 # Some functions here used by doBlockLevels()
828 /* private */ function closeParagraph()
831 if ( 0 != strcmp( "p", $this->mLastSection
) &&
832 0 != strcmp( "", $this->mLastSection
) ) {
833 $result = "</" . $this->mLastSection
. ">";
835 $this->mLastSection
= "";
838 # getCommon() returns the length of the longest common substring
839 # of both arguments, starting at the beginning of both.
841 /* private */ function getCommon( $st1, $st2 )
843 $fl = strlen( $st1 );
844 $shorter = strlen( $st2 );
845 if ( $fl < $shorter ) { $shorter = $fl; }
847 for ( $i = 0; $i < $shorter; ++
$i ) {
848 if ( $st1{$i} != $st2{$i} ) { break; }
852 # These next three functions open, continue, and close the list
853 # element appropriate to the prefix character passed into them.
855 /* private */ function openList( $char )
857 $result = $this->closeParagraph();
859 if ( "*" == $char ) { $result .= "<ul><li>"; }
860 else if ( "#" == $char ) { $result .= "<ol><li>"; }
861 else if ( ":" == $char ) { $result .= "<dl><dd>"; }
862 else if ( ";" == $char ) {
863 $result .= "<dl><dt>";
864 $this->mDTopen
= true;
866 else { $result = "<!-- ERR 1 -->"; }
871 /* private */ function nextItem( $char )
873 if ( "*" == $char ||
"#" == $char ) { return "</li><li>"; }
874 else if ( ":" == $char ||
";" == $char ) {
876 if ( $this->mDTopen
) { $close = "</dt>"; }
877 if ( ";" == $char ) {
878 $this->mDTopen
= true;
879 return $close . "<dt>";
881 $this->mDTopen
= false;
882 return $close . "<dd>";
885 return "<!-- ERR 2 -->";
888 /* private */function closeList( $char )
890 if ( "*" == $char ) { $text = "</li></ul>"; }
891 else if ( "#" == $char ) { $text = "</li></ol>"; }
892 else if ( ":" == $char ) {
893 if ( $this->mDTopen
) {
894 $this->mDTopen
= false;
895 $text = "</dt></dl>";
897 $text = "</dd></dl>";
900 else { return "<!-- ERR 3 -->"; }
904 /* private */ function doBlockLevels( $text, $linestart )
906 $fname = "OutputPage::doBlockLevels";
907 wfProfileIn( $fname );
908 # Parsing through the text line by line. The main thing
909 # happening here is handling of block-level elements p, pre,
910 # and making lists from lines starting with * # : etc.
912 $a = explode( "\n", $text );
913 $text = $lastPref = "";
914 $this->mDTopen
= $inBlockElem = false;
916 if ( ! $linestart ) { $text .= array_shift( $a ); }
917 foreach ( $a as $t ) {
918 if ( "" != $text ) { $text .= "\n"; }
921 $opl = strlen( $lastPref );
922 $npl = strspn( $t, "*#:;" );
923 $pref = substr( $t, 0, $npl );
924 $pref2 = str_replace( ";", ":", $pref );
925 $t = substr( $t, $npl );
927 if ( 0 != $npl && 0 == strcmp( $lastPref, $pref2 ) ) {
928 $text .= $this->nextItem( substr( $pref, -1 ) );
930 if ( ";" == substr( $pref, -1 ) ) {
931 $cpos = strpos( $t, ":" );
932 if ( ! ( false === $cpos ) ) {
933 $term = substr( $t, 0, $cpos );
934 $text .= $term . $this->nextItem( ":" );
935 $t = substr( $t, $cpos +
1 );
938 } else if (0 != $npl ||
0 != $opl) {
939 $cpl = $this->getCommon( $pref, $lastPref );
941 while ( $cpl < $opl ) {
942 $text .= $this->closeList( $lastPref{$opl-1} );
945 if ( $npl <= $cpl && $cpl > 0 ) {
946 $text .= $this->nextItem( $pref{$cpl-1} );
948 while ( $npl > $cpl ) {
949 $char = substr( $pref, $cpl, 1 );
950 $text .= $this->openList( $char );
952 if ( ";" == $char ) {
953 $cpos = strpos( $t, ":" );
954 if ( ! ( false === $cpos ) ) {
955 $term = substr( $t, 0, $cpos );
956 $text .= $term . $this->nextItem( ":" );
957 $t = substr( $t, $cpos +
1 );
964 if ( 0 == $npl ) { # No prefix--go to paragraph mode
966 "/(<table|<blockquote|<h1|<h2|<h3|<h4|<h5|<h6)/i", $t ) ) {
967 $text .= $this->closeParagraph();
970 if ( ! $inBlockElem ) {
971 if ( " " == $t{0} ) {
973 # $t = wfEscapeHTML( $t );
975 else { $newSection = "p"; }
977 if ( 0 == strcmp( "", trim( $oLine ) ) ) {
978 $text .= $this->closeParagraph();
979 $text .= "<" . $newSection . ">";
980 } else if ( 0 != strcmp( $this->mLastSection
,
982 $text .= $this->closeParagraph();
983 if ( 0 != strcmp( "p", $newSection ) ) {
984 $text .= "<" . $newSection . ">";
987 $this->mLastSection
= $newSection;
990 preg_match( "/(<\\/table|<\\/blockquote|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6)/i", $t ) ) {
991 $inBlockElem = false;
997 $text .= $this->closeList( $pref2{$npl-1} );
1000 if ( "" != $this->mLastSection
) {
1001 if ( "p" != $this->mLastSection
) {
1002 $text .= "</" . $this->mLastSection
. ">";
1004 $this->mLastSection
= "";
1006 wfProfileOut( $fname );
1010 /* private */ function replaceVariables( $text )
1012 global $wgLang, $wgCurOut;
1013 $fname = "OutputPage::replaceVariables";
1014 wfProfileIn( $fname );
1019 # See Language.php for the definition of each magic word
1020 # As with sigs, this uses the server's local time -- ensure
1021 # this is appropriate for your audience!
1023 $magic[MAG_CURRENTMONTH
] = date( "m" );
1024 $magic[MAG_CURRENTMONTHNAME
] = $wgLang->getMonthName( date("n") );
1025 $magic[MAG_CURRENTMONTHNAMEGEN
] = $wgLang->getMonthNameGen( date("n") );
1026 $magic[MAG_CURRENTDAY
] = date("j");
1027 $magic[MAG_CURRENTDAYNAME
] = $wgLang->getWeekdayName( date("w")+
1 );
1028 $magic[MAG_CURRENTYEAR
] = date( "Y" );
1029 $magic[MAG_CURRENTTIME
] = $wgLang->time( wfTimestampNow(), false );
1031 $this->mContainsOldMagic +
= MagicWord
::replaceMultiple($magic, $text, $text);
1033 $mw =& MagicWord
::get( MAG_NUMBEROFARTICLES
);
1034 if ( $mw->match( $text ) ) {
1035 $v = wfNumberOfArticles();
1036 $text = $mw->replace( $v, $text );
1037 if( $mw->getWasModified() ) { $this->mContainsOldMagic++
; }
1040 # "Variables" with an additional parameter e.g. {{MSG:wikipedia}}
1041 # The callbacks are at the bottom of this file
1043 $mw =& MagicWord
::get( MAG_MSG
);
1044 $text = $mw->substituteCallback( $text, "wfReplaceMsgVar" );
1045 if( $mw->getWasModified() ) { $this->mContainsNewMagic++
; }
1047 $mw =& MagicWord
::get( MAG_MSGNW
);
1048 $text = $mw->substituteCallback( $text, "wfReplaceMsgnwVar" );
1049 if( $mw->getWasModified() ) { $this->mContainsNewMagic++
; }
1051 wfProfileOut( $fname );
1055 # Cleans up HTML, removes dangerous tags and attributes
1056 /* private */ function removeHTMLtags( $text )
1058 $fname = "OutputPage::removeHTMLtags";
1059 wfProfileIn( $fname );
1060 $htmlpairs = array( # Tags that must be closed
1061 "b", "i", "u", "font", "big", "small", "sub", "sup", "h1",
1062 "h2", "h3", "h4", "h5", "h6", "cite", "code", "em", "s",
1063 "strike", "strong", "tt", "var", "div", "center",
1064 "blockquote", "ol", "ul", "dl", "table", "caption", "pre",
1065 "ruby", "rt" , "rb" , "rp"
1067 $htmlsingle = array(
1068 "br", "p", "hr", "li", "dt", "dd"
1070 $htmlnest = array( # Tags that can be nested--??
1071 "table", "tr", "td", "th", "div", "blockquote", "ol", "ul",
1072 "dl", "font", "big", "small", "sub", "sup"
1074 $tabletags = array( # Can only appear inside table
1078 $htmlsingle = array_merge( $tabletags, $htmlsingle );
1079 $htmlelements = array_merge( $htmlsingle, $htmlpairs );
1081 $htmlattrs = $this->getHTMLattrs () ;
1083 # Remove HTML comments
1084 $text = preg_replace( "/<!--.*-->/sU", "", $text );
1086 $bits = explode( "<", $text );
1087 $text = array_shift( $bits );
1088 $tagstack = array(); $tablestack = array();
1090 foreach ( $bits as $x ) {
1091 $prev = error_reporting( E_ALL
& ~
( E_NOTICE | E_WARNING
) );
1092 preg_match( "/^(\\/?)(\\w+)([^>]*)(\\/{0,1}>)([^<]*)$/",
1094 list( $qbar, $slash, $t, $params, $brace, $rest ) = $regs;
1095 error_reporting( $prev );
1098 if ( in_array( $t = strtolower( $t ), $htmlelements ) ) {
1102 if ( ! in_array( $t, $htmlsingle ) &&
1103 ( $ot = array_pop( $tagstack ) ) != $t ) {
1104 array_push( $tagstack, $ot );
1107 if ( $t == "table" ) {
1108 $tagstack = array_pop( $tablestack );
1113 # Keep track for later
1114 if ( in_array( $t, $tabletags ) &&
1115 ! in_array( "table", $tagstack ) ) {
1117 } else if ( in_array( $t, $tagstack ) &&
1118 ! in_array ( $t , $htmlnest ) ) {
1120 } else if ( ! in_array( $t, $htmlsingle ) ) {
1121 if ( $t == "table" ) {
1122 array_push( $tablestack, $tagstack );
1123 $tagstack = array();
1125 array_push( $tagstack, $t );
1127 # Strip non-approved attributes from the tag
1128 $newparams = $this->fixTagAttributes($params);
1132 $rest = str_replace( ">", ">", $rest );
1133 $text .= "<$slash$t $newparams$brace$rest";
1137 $text .= "<" . str_replace( ">", ">", $x);
1139 # Close off any remaining tags
1140 while ( $t = array_pop( $tagstack ) ) {
1142 if ( $t == "table" ) { $tagstack = array_pop( $tablestack ); }
1144 wfProfileOut( $fname );
1150 * This function accomplishes several tasks:
1151 * 1) Auto-number headings if that option is enabled
1152 * 2) Add an [edit] link to sections for logged in users who have enabled the option
1153 * 3) Add a Table of contents on the top for users who have enabled the option
1154 * 4) Auto-anchor headings
1156 * It loops through all headlines, collects the necessary data, then splits up the
1157 * string and re-inserts the newly formatted headlines.
1160 /* private */ function formatHeadings( $text )
1162 $nh=$this->mOptions
->getNumberHeadings();
1163 $st=$this->mOptions
->getShowToc();
1164 if(!$this->mTitle
->userCanEdit()) {
1168 $es=$this->mOptions
->getEditSection();
1169 $esr=$this->mOptions
->getEditSectionOnRightClick();
1172 # Inhibit editsection links if requested in the page
1173 $esw =& MagicWord
::get( MAG_NOEDITSECTION
);
1174 if ($esw->matchAndRemove( $text )) {
1177 # if the string __NOTOC__ (not case-sensitive) occurs in the HTML,
1179 $mw =& MagicWord
::get( MAG_NOTOC
);
1180 if ($mw->matchAndRemove( $text ))
1185 # never add the TOC to the Main Page. This is an entry page that should not
1186 # be more than 1-2 screens large anyway
1187 if($this->mTitle
->getPrefixedText()==wfMsg("mainpage")) {$st=0;}
1189 # We need this to perform operations on the HTML
1190 $sk =& $this->mOptions
->getSkin();
1192 # Get all headlines for numbering them and adding funky stuff like [edit]
1194 preg_match_all("/<H([1-6])(.*?>)(.*?)<\/H[1-6]>/i",$text,$matches);
1199 # Ugh .. the TOC should have neat indentation levels which can be
1200 # passed to the skin functions. These are determined here
1201 foreach($matches[3] as $headline) {
1202 if($level) { $prevlevel=$level;}
1203 $level=$matches[1][$c];
1204 if(($nh||
$st) && $prevlevel && $level>$prevlevel) {
1206 $h[$level]=0; // reset when we enter a new level
1207 $toc.=$sk->tocIndent($level-$prevlevel);
1208 $toclevel+
=$level-$prevlevel;
1211 if(($nh||
$st) && $level<$prevlevel) {
1212 $h[$level+
1]=0; // reset when we step back a level
1213 $toc.=$sk->tocUnindent($prevlevel-$level);
1214 $toclevel-=$prevlevel-$level;
1217 $h[$level]++
; // count number of headlines for each level
1220 for($i=1;$i<=$level;$i++
) {
1222 if($dot) {$numbering.=".";}
1229 // The canonized header is a version of the header text safe to use for links
1230 // Avoid insertion of weird stuff like <math> by expanding the relevant sections
1231 $canonized_headline=Parser
::unstrip( $headline, $this->mStripState
);
1232 $canonized_headline=preg_replace("/<.*?>/","",$canonized_headline); // strip out HTML
1233 $tocline = trim( $canonized_headline );
1234 $canonized_headline=str_replace('"',"",$canonized_headline);
1235 $canonized_headline=str_replace(" ","_",trim($canonized_headline));
1236 $refer[$c]=$canonized_headline;
1237 $refers[$canonized_headline]++
; // count how many in assoc. array so we can track dupes in anchors
1238 $refcount[$c]=$refers[$canonized_headline];
1240 // Prepend the number to the heading text
1243 $tocline=$numbering ." ". $tocline;
1245 // Don't number the heading if it is the only one (looks silly)
1246 if($nh && count($matches[3]) > 1) {
1247 $headline=$numbering . " " . $headline; // the two are different if the line contains a link
1251 // Create the anchor for linking from the TOC to the section
1253 $anchor=$canonized_headline;
1254 if($refcount[$c]>1) {$anchor.="_".$refcount[$c];}
1256 $toc.=$sk->tocLine($anchor,$tocline,$toclevel);
1259 $head[$c].=$sk->editSectionLink($c+
1);
1262 // Put it all together
1264 $head[$c].="<h".$level.$matches[2][$c]
1265 ."<a name=\"".$anchor."\">"
1270 // Add the edit section link
1273 $head[$c]=$sk->editSectionScript($c+
1,$head[$c]);
1283 $toc.=$sk->tocUnindent($toclevel);
1284 $toc=$sk->tocTable($toc);
1287 // split up and insert constructed headlines
1289 $blocks=preg_split("/<H[1-6].*?>.*?<\/H[1-6]>/i",$text);
1292 foreach($blocks as $block) {
1293 if(($es) && $c>0 && $i==0) {
1294 # This is the [edit] link that appears for the top block of text when
1295 # section editing is enabled
1296 $full.=$sk->editSectionLink(0);
1299 if($st && $toclines>3 && !$i) {
1300 # Let's add a top anchor just in case we want to link to the top of the page
1301 $full="<a name=\"top\"></a>".$full.$toc;
1311 /* private */ function doMagicISBN( &$tokenizer )
1315 # Check whether next token is a text token
1316 # If yes, fetch it and convert the text into a
1317 # Special::BookSources link
1318 $token = $tokenizer->previewToken();
1319 while ( $token["type"] == "" )
1321 $tokenizer->nextToken();
1322 $token = $tokenizer->previewToken();
1324 if ( $token["type"] == "text" )
1326 $token = $tokenizer->nextToken();
1327 $x = $token["text"];
1328 $valid = "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1330 $isbn = $blank = "" ;
1331 while ( " " == $x{0} ) {
1333 $x = substr( $x, 1 );
1335 while ( strstr( $valid, $x{0} ) != false ) {
1337 $x = substr( $x, 1 );
1339 $num = str_replace( "-", "", $isbn );
1340 $num = str_replace( " ", "", $num );
1343 $text .= "ISBN $blank$x";
1345 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Booksources" );
1346 $text .= "<a href=\"" .
1347 $titleObj->getUrl( "isbn={$num}", false, true ) .
1348 "\" class=\"internal\">ISBN $isbn</a>";
1356 /* private */ function doMagicRFC( &$tokenizer )
1360 # Check whether next token is a text token
1361 # If yes, fetch it and convert the text into a
1362 # link to an RFC source
1363 $token = $tokenizer->previewToken();
1364 while ( $token["type"] == "" )
1366 $tokenizer->nextToken();
1367 $token = $tokenizer->previewToken();
1369 if ( $token["type"] == "text" )
1371 $token = $tokenizer->nextToken();
1372 $x = $token["text"];
1373 $valid = "0123456789";
1375 $rfc = $blank = "" ;
1376 while ( " " == $x{0} ) {
1378 $x = substr( $x, 1 );
1380 while ( strstr( $valid, $x{0} ) != false ) {
1382 $x = substr( $x, 1 );
1386 $text .= "RFC $blank$x";
1388 $url = wfmsg( "rfcurl" );
1389 $url = str_replace( "$1", $rfc, $url);
1390 $sk =& $this->mOptions
->getSkin();
1391 $la = $sk->getExternalLinkAttributes( $url, "RFC {$rfc}" );
1392 $text = "<a href='{$url}'{$la}>RFC {$rfc}</a>{$x}";
1400 function preSaveTransform( $text, &$title, &$user, $options, $clearState = true )
1402 $this->mOptions
= $options;
1403 $this->mTitle
= $title;
1404 if ( $clearState ) {
1408 $stripState = false;
1409 $text = $this->strip( $text, $stripState, false );
1410 $text = $this->pstPass2( $text, $user );
1411 $text = $this->unstrip( $text, $stripState );
1415 /* private */ function pstPass2( $text, &$user )
1417 global $wgLang, $wgLocaltimezone;
1421 $n = $user->getName();
1422 $k = $user->getOption( "nickname" );
1423 if ( "" == $k ) { $k = $n; }
1424 if(isset($wgLocaltimezone)) {
1425 $oldtz = getenv("TZ"); putenv("TZ=$wgLocaltimezone");
1427 /* Note: this is an ugly timezone hack for the European wikis */
1428 $d = $wgLang->timeanddate( date( "YmdHis" ), false ) .
1429 " (" . date( "T" ) . ")";
1430 if(isset($wgLocaltimezone)) putenv("TZ=$oldtz");
1432 $text = preg_replace( "/~~~~/", "[[" . $wgLang->getNsText(
1433 Namespace::getUser() ) . ":$n|$k]] $d", $text );
1434 $text = preg_replace( "/~~~/", "[[" . $wgLang->getNsText(
1435 Namespace::getUser() ) . ":$n|$k]]", $text );
1437 # Context links: [[|name]] and [[name (context)|]]
1439 $tc = "[&;%\\-,.\\(\\)' _0-9A-Za-z\\/:\\x80-\\xff]";
1440 $np = "[&;%\\-,.' _0-9A-Za-z\\/:\\x80-\\xff]"; # No parens
1441 $namespacechar = '[ _0-9A-Za-z\x80-\xff]'; # Namespaces can use non-ascii!
1442 $conpat = "/^({$np}+) \\(({$tc}+)\\)$/";
1444 $p1 = "/\[\[({$np}+) \\(({$np}+)\\)\\|]]/"; # [[page (context)|]]
1445 $p2 = "/\[\[\\|({$tc}+)]]/"; # [[|page]]
1446 $p3 = "/\[\[($namespacechar+):({$np}+)\\|]]/"; # [[namespace:page|]]
1447 $p4 = "/\[\[($namespacechar+):({$np}+) \\(({$np}+)\\)\\|]]/";
1448 # [[ns:page (cont)|]]
1450 $t = $this->mTitle
->getText();
1451 if ( preg_match( $conpat, $t, $m ) ) {
1454 $text = preg_replace( $p4, "[[\\1:\\2 (\\3)|\\2]]", $text );
1455 $text = preg_replace( $p1, "[[\\1 (\\2)|\\1]]", $text );
1456 $text = preg_replace( $p3, "[[\\1:\\2|\\2]]", $text );
1458 if ( "" == $context ) {
1459 $text = preg_replace( $p2, "[[\\1]]", $text );
1461 $text = preg_replace( $p2, "[[\\1 ({$context})|\\1]]", $text );
1464 # {{SUBST:xxx}} variables
1466 $mw =& MagicWord
::get( MAG_SUBST
);
1467 $text = $mw->substituteCallback( $text, "wfReplaceSubstVar" );
1469 # Trim trailing whitespace
1470 # MAG_END (__END__) tag allows for trailing
1471 # whitespace to be deliberately included
1472 $text = rtrim( $text );
1473 $mw =& MagicWord
::get( MAG_END
);
1474 $mw->matchAndRemove( $text );
1484 var $mText, $mLanguageLinks, $mCategoryLinks, $mContainsOldMagic;
1486 function ParserOutput( $text = "", $languageLinks = array(), $categoryLinks = array(),
1487 $containsOldMagic = false )
1489 $this->mText
= $text;
1490 $this->mLanguageLinks
= $languageLinks;
1491 $this->mCategoryLinks
= $categoryLinks;
1492 $this->mContainsOldMagic
= $containsOldMagic;
1495 function getText() { return $this->mText
; }
1496 function getLanguageLinks() { return $this->mLanguageLinks
; }
1497 function getCategoryLinks() { return $this->mCategoryLinks
; }
1498 function containsOldMagic() { return $this->mContainsOldMagic
; }
1499 function setText( $text ) { return wfSetVar( $this->mText
, $text ); }
1500 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks
, $ll ); }
1501 function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategoryLinks
, $cl ); }
1502 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic
, $com ); }
1507 # All variables are private
1508 var $mUseTeX; # Use texvc to expand <math> tags
1509 var $mUseCategoryMagic; # Treat [[Category:xxxx]] tags specially
1510 var $mUseDynamicDates; # Use $wgDateFormatter to format dates
1511 var $mInterwikiMagic; # Interlanguage links are removed and returned in an array
1512 var $mAllowExternalImages; # Allow external images inline
1513 var $mSkin; # Reference to the preferred skin
1514 var $mDateFormat; # Date format index
1515 var $mEditSection; # Create "edit section" links
1516 var $mEditSectionOnRightClick; # Generate JavaScript to edit section on right click
1517 var $mPrintable; # Generate printable output
1518 var $mNumberHeadings; # Automatically number headings
1519 var $mShowToc; # Show table of contents
1521 function getUseTeX() { return $this->mUseTeX
; }
1522 function getUseCategoryMagic() { return $this->mUseCategoryMagic
; }
1523 function getUseDynamicDates() { return $this->mUseDynamicDates
; }
1524 function getInterwikiMagic() { return $this->mInterwikiMagic
; }
1525 function getAllowExternalImages() { return $this->mAllowExternalImages
; }
1526 function getSkin() { return $this->mSkin
; }
1527 function getDateFormat() { return $this->mDateFormat
; }
1528 function getEditSection() { return $this->mEditSection
; }
1529 function getEditSectionOnRightClick() { return $this->mEditSectionOnRightClick
; }
1530 function getPrintable() { return $this->mPrintable
; }
1531 function getNumberHeadings() { return $this->mNumberHeadings
; }
1532 function getShowToc() { return $this->mShowToc
; }
1534 function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX
, $x ); }
1535 function setUseCategoryMagic( $x ) { return wfSetVar( $this->mUseCategoryMagic
, $x ); }
1536 function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates
, $x ); }
1537 function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic
, $x ); }
1538 function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages
, $x ); }
1539 function setSkin( $x ) { return wfSetRef( $this->mSkin
, $x ); }
1540 function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat
, $x ); }
1541 function setEditSection( $x ) { return wfSetVar( $this->mEditSection
, $x ); }
1542 function setEditSectionOnRightClick( $x ) { return wfSetVar( $this->mEditSectionOnRightClick
, $x ); }
1543 function setPrintable( $x ) { return wfSetVar( $this->mPrintable
, $x ); }
1544 function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings
, $x ); }
1545 function setShowToc( $x ) { return wfSetVar( $this->mShowToc
, $x ); }
1547 /* static */ function newFromUser( &$user )
1549 $popts = new ParserOptions
;
1550 $popts->initialiseFromUser( &$user );
1554 function initialiseFromUser( &$userInput )
1556 global $wgUseTeX, $wgUseCategoryMagic, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
1558 if ( !$userInput ) {
1561 $user =& $userInput;
1564 $this->mUseTeX
= $wgUseTeX;
1565 $this->mUseCategoryMagic
= $wgUseCategoryMagic;
1566 $this->mUseDynamicDates
= $wgUseDynamicDates;
1567 $this->mInterwikiMagic
= $wgInterwikiMagic;
1568 $this->mAllowExternalImages
= $wgAllowExternalImages;
1569 $this->mSkin
=& $user->getSkin();
1570 $this->mDateFormat
= $user->getOption( "date" );
1571 $this->mEditSection
= $user->getOption( "editsection" );
1572 $this->mEditSectionOnRightClick
= $user->getOption( "editsectiononrightclick" );
1573 $this->mPrintable
= false;
1574 $this->mNumberHeadings
= $user->getOption( "numberheadings" );
1575 $this->mShowToc
= $user->getOption( "showtoc" );
1581 # Regex callbacks, used in OutputPage::replaceVariables
1583 # Just get rid of the dangerous stuff
1584 # Necessary because replaceVariables is called after removeHTMLtags,
1585 # and message text can come from any user
1586 function wfReplaceMsgVar( $matches ) {
1587 global $wgCurOut, $wgLinkCache;
1588 $text = $wgCurOut->removeHTMLtags( wfMsg( $matches[1] ) );
1589 $wgLinkCache->suspend();
1590 $text = $wgCurOut->replaceInternalLinks( $text );
1591 $wgLinkCache->resume();
1592 $wgLinkCache->addLinkObj( Title
::makeTitle( NS_MEDIAWIKI
, $matches[1] ) );
1596 # Effective <nowiki></nowiki>
1597 # Not real <nowiki> because this is called after nowiki sections are processed
1598 function wfReplaceMsgnwVar( $matches ) {
1599 global $wgCurOut, $wgLinkCache;
1600 $text = wfEscapeWikiText( wfMsg( $matches[1] ) );
1601 $wgLinkCache->addLinkObj( Title
::makeTitle( NS_MEDIAWIKI
, $matches[1] ) );