3 require_once('Tokenizer.php');
5 if( $GLOBALS['wgUseWikiHiero'] ){
6 require_once('extensions/wikihiero/wikihiero.php');
8 if( $GLOBALS['wgUseTimeline'] ){
9 require_once('extensions/timeline/Timeline.php');
14 # Processes wiki markup
16 # There are two main entry points into the Parser class: parse() and preSaveTransform().
17 # The parse() function produces HTML output, preSaveTransform() produces altered wiki markup.
20 # objects: $wgLang, $wgDateFormatter, $wgLinkCache, $wgCurParser
22 # NOT $wgArticle, $wgUser or $wgTitle. Keep them away!
24 # settings: $wgUseTex*, $wgUseCategoryMagic*, $wgUseDynamicDates*, $wgInterwikiMagic*,
25 # $wgNamespacesWithSubpages, $wgLanguageCode, $wgAllowExternalImages*,
28 # * only within ParserOptions
31 #----------------------------------------
32 # Variable substitution O(N^2) attack
33 #-----------------------------------------
34 # Without countermeasures, it would be possible to attack the parser by saving a page
35 # filled with a large number of inclusions of large pages. The size of the generated
36 # page would be proportional to the square of the input size. Hence, we limit the number
37 # of inclusions of any given page, thus bringing any attack back to O(N).
40 define( "MAX_INCLUDE_REPEAT", 5 );
42 # Allowed values for $mOutputType
43 define( "OT_HTML", 1 );
44 define( "OT_WIKI", 2 );
45 define( "OT_MSG", 3 );
47 # string parameter for extractTags which will cause it
48 # to strip HTML comments in addition to regular
49 # <XML>-style tags. This should not be anything we
50 # may want to use in wikisyntax
51 define( "STRIP_COMMENTS", "HTMLCommentStrip" );
53 # prefix for escaping, used in two functions at least
54 define( "UNIQ_PREFIX", "NaodW29");
58 # Cleared with clearState():
59 var $mOutput, $mAutonumber, $mDTopen, $mStripState = array();
60 var $mVariables, $mIncludeCount, $mArgStack, $mLastSection, $mInPre;
63 var $mOptions, $mTitle, $mOutputType;
72 $this->mOutput
= new ParserOutput
;
73 $this->mAutonumber
= 0;
74 $this->mLastSection
= "";
75 $this->mDTopen
= false;
76 $this->mVariables
= false;
77 $this->mIncludeCount
= array();
78 $this->mStripState
= array();
79 $this->mArgStack
= array();
82 # First pass--just handle <nowiki> sections, pass the rest off
83 # to internalParse() which does all the real work.
85 # Returns a ParserOutput
87 function parse( $text, &$title, $options, $linestart = true, $clearState = true )
90 $fname = "Parser::parse";
91 wfProfileIn( $fname );
97 $this->mOptions
= $options;
98 $this->mTitle
=& $title;
99 $this->mOutputType
= OT_HTML
;
102 $text = $this->strip( $text, $this->mStripState
);
103 $text = $this->internalParse( $text, $linestart );
104 $text = $this->unstrip( $text, $this->mStripState
);
105 # Clean up special characters, only run once, next-to-last before doBlockLevels
108 "/<hr *>/i" => '<hr/>',
109 "/<br *>/i" => '<br/>',
110 "/<center *>/i"=>'<div class="center">',
111 "/<\\/center *>/i" => '</div>',
112 # Clean up spare ampersands; note that we probably ought to be
113 # more careful about named entities.
114 '/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/' => '&'
116 $text = preg_replace( array_keys($fixtags), array_values($fixtags), $text );
119 "/<center *>/i"=>'<div class="center">',
120 "/<\\/center *>/i" => '</div>'
122 $text = preg_replace( array_keys($fixtags), array_values($fixtags), $text );
125 $text = $this->doBlockLevels( $text, $linestart );
127 $text = $this->tidy($text);
129 $this->mOutput
->setText( $text );
130 wfProfileOut( $fname );
131 return $this->mOutput
;
134 /* static */ function getRandomString()
136 return dechex(mt_rand(0, 0x7fffffff)) . dechex(mt_rand(0, 0x7fffffff));
139 # Replaces all occurrences of <$tag>content</$tag> in the text
140 # with a random marker and returns the new text. the output parameter
141 # $content will be an associative array filled with data on the form
142 # $unique_marker => content.
144 # If $content is already set, the additional entries will be appended
146 # If $tag is set to STRIP_COMMENTS, the function will extract
147 # <!-- HTML comments -->
149 /* static */ function extractTags($tag, $text, &$content, $uniq_prefix = ""){
150 $rnd = $uniq_prefix . '-' . $tag . Parser
::getRandomString();
157 while ( "" != $text ) {
158 if($tag==STRIP_COMMENTS
) {
159 $p = preg_split( "/<!--/i", $text, 2 );
161 $p = preg_split( "/<\\s*$tag\\s*>/i", $text, 2 );
164 if ( ( count( $p ) < 2 ) ||
( "" == $p[1] ) ) {
167 if($tag==STRIP_COMMENTS
) {
168 $q = preg_split( "/-->/i", $p[1], 2 );
170 $q = preg_split( "/<\\/\\s*$tag\\s*>/i", $p[1], 2 );
172 $marker = $rnd . sprintf("%08X", $n++
);
173 $content[$marker] = $q[0];
174 $stripped .= $marker;
181 # Strips and renders <nowiki>, <pre>, <math>, <hiero>
182 # If $render is set, performs necessary rendering operations on plugins
183 # Returns the text, and fills an array with data needed in unstrip()
184 # If the $state is already a valid strip state, it adds to the state
186 # When $stripcomments is set, HTML comments <!-- like this -->
187 # will be stripped in addition to other tags. This is important
188 # for section editing, where these comments cause confusion when
189 # counting the sections in the wikisource
190 function strip( $text, &$state, $stripcomments = false )
192 $render = ($this->mOutputType
== OT_HTML
);
193 $nowiki_content = array();
194 $hiero_content = array();
195 $math_content = array();
196 $pre_content = array();
197 $comment_content = array();
199 # Replace any instances of the placeholders
200 $uniq_prefix = UNIQ_PREFIX
;
201 #$text = str_replace( $uniq_prefix, wfHtmlEscapeFirst( $uniq_prefix ), $text );
203 $text = Parser
::extractTags("nowiki", $text, $nowiki_content, $uniq_prefix);
204 foreach( $nowiki_content as $marker => $content ){
206 $nowiki_content[$marker] = wfEscapeHTMLTagsOnly( $content );
208 $nowiki_content[$marker] = "<nowiki>$content</nowiki>";
212 $text = Parser
::extractTags("hiero", $text, $hiero_content, $uniq_prefix);
213 foreach( $hiero_content as $marker => $content ){
214 if( $render && $GLOBALS['wgUseWikiHiero']){
215 $hiero_content[$marker] = WikiHiero( $content, WH_MODE_HTML
);
217 $hiero_content[$marker] = "<hiero>$content</hiero>";
221 $text = Parser
::extractTags("math", $text, $math_content, $uniq_prefix);
222 foreach( $math_content as $marker => $content ){
224 if( $this->mOptions
->getUseTeX() ) {
225 $math_content[$marker] = renderMath( $content );
227 $math_content[$marker] = "<math>$content<math>";
230 $math_content[$marker] = "<math>$content</math>";
234 $text = Parser
::extractTags("pre", $text, $pre_content, $uniq_prefix);
235 foreach( $pre_content as $marker => $content ){
237 $pre_content[$marker] = "<pre>" . wfEscapeHTMLTagsOnly( $content ) . "</pre>";
239 $pre_content[$marker] = "<pre>$content</pre>";
243 $text = Parser
::extractTags(STRIP_COMMENTS
, $text, $comment_content, $uniq_prefix);
244 foreach( $comment_content as $marker => $content ){
245 $comment_content[$marker] = "<!--$content-->";
249 # Merge state with the pre-existing state, if there is one
251 $state['nowiki'] = $state['nowiki'] +
$nowiki_content;
252 $state['hiero'] = $state['hiero'] +
$hiero_content;
253 $state['math'] = $state['math'] +
$math_content;
254 $state['pre'] = $state['pre'] +
$pre_content;
255 $state['comment'] = $state['comment'] +
$comment_content;
258 'nowiki' => $nowiki_content,
259 'hiero' => $hiero_content,
260 'math' => $math_content,
261 'pre' => $pre_content,
262 'comment' => $comment_content
268 function unstrip( $text, &$state )
270 # Must expand in reverse order, otherwise nested tags will be corrupted
271 $contentDict = end( $state );
272 for ( $contentDict = end( $state ); $contentDict !== false; $contentDict = prev( $state ) ) {
273 for ( $content = end( $contentDict ); $content !== false; $content = prev( $contentDict ) ) {
274 $text = str_replace( key( $contentDict ), $content, $text );
281 # Add an item to the strip state
282 # Returns the unique tag which must be inserted into the stripped text
283 # The tag will be replaced with the original text in unstrip()
285 function insertStripItem( $text, &$state )
287 $rnd = UNIQ_PREFIX
. '-item' . Parser
::getRandomString();
296 $state['item'][$rnd] = $text;
300 # This method generates the list of subcategories and pages for a category
301 function categoryMagic ()
303 global $wgLang , $wgUser ;
304 if ( !$this->mOptions
->getUseCategoryMagic() ) return ; # Doesn't use categories at all
306 $cns = Namespace::getCategory() ;
307 if ( $this->mTitle
->getNamespace() != $cns ) return "" ; # This ain't a category page
309 $r = "<br style=\"clear:both;\"/>\n";
312 $sk =& $wgUser->getSkin() ;
314 $articles = array() ;
315 $children = array() ;
317 $id = $this->mTitle
->getArticleID() ;
320 $t = wfStrencode( $this->mTitle
->getDBKey() );
321 $sql = "SELECT DISTINCT cur_title,cur_namespace FROM cur,categorylinks WHERE cl_to='$t' AND cl_from=cur_id ORDER BY cl_sortkey" ;
322 $res = wfQuery ( $sql, DB_READ
) ;
323 while ( $x = wfFetchObject ( $res ) ) $data[] = $x ;
325 # For all pages that link to this category
326 foreach ( $data AS $x )
328 $t = $wgLang->getNsText ( $x->cur_namespace
) ;
329 if ( $t != "" ) $t .= ":" ;
330 $t .= $x->cur_title
;
332 if ( $x->cur_namespace
== $cns ) {
333 array_push ( $children , $sk->makeLink ( $t ) ) ; # Subcategory
335 array_push ( $articles , $sk->makeLink ( $t ) ) ; # Page in this category
338 wfFreeResult ( $res ) ;
340 # Showing subcategories
341 if ( count ( $children ) > 0 ) {
342 $r .= "<h2>".wfMsg("subcategories")."</h2>\n" ;
343 $r .= implode ( ", " , $children ) ;
346 # Showing pages in this category
347 if ( count ( $articles ) > 0 ) {
348 $ti = $this->mTitle
->getText() ;
349 $h = wfMsg( "category_header", $ti );
350 $r .= "<h2>{$h}</h2>\n" ;
351 $r .= implode ( ", " , $articles ) ;
358 function getHTMLattrs ()
360 $htmlattrs = array( # Allowed attributes--no scripting, etc.
361 "title", "align", "lang", "dir", "width", "height",
362 "bgcolor", "clear", /* BR */ "noshade", /* HR */
363 "cite", /* BLOCKQUOTE, Q */ "size", "face", "color",
364 /* FONT */ "type", "start", "value", "compact",
365 /* For various lists, mostly deprecated but safe */
366 "summary", "width", "border", "frame", "rules",
367 "cellspacing", "cellpadding", "valign", "char",
368 "charoff", "colgroup", "col", "span", "abbr", "axis",
369 "headers", "scope", "rowspan", "colspan", /* Tables */
370 "id", "class", "name", "style" /* For CSS */
375 function fixTagAttributes ( $t )
377 if ( trim ( $t ) == "" ) return "" ; # Saves runtime ;-)
378 $htmlattrs = $this->getHTMLattrs() ;
380 # Strip non-approved attributes from the tag
382 "/(\\w+)(\\s*=\\s*([^\\s\">]+|\"[^\">]*\"))?/e",
383 "(in_array(strtolower(\"\$1\"),\$htmlattrs)?(\"\$1\".((\"x\$3\" != \"x\")?\"=\$3\":'')):'')",
385 # Strip javascript "expression" from stylesheets. Brute force approach:
386 # If anythin offensive is found, all attributes of the HTML tag are dropped
389 "/style\\s*=.*(expression|tps*:\/\/|url\\s*\().*/is",
390 wfMungeToUtf8( $t ) ) )
398 /* interface with html tidy, used if $wgUseTidy = true */
399 function tidy ( $text ) {
400 global $wgTidyConf, $wgTidyBin, $wgTidyOpts;
401 global $wgInputEncoding, $wgOutputEncoding;
403 switch(strtoupper($wgOutputEncoding)) {
405 $wgTidyOpts .= ($wgInputEncoding == $wgOutputEncoding)?
' -latin1':' -raw';
408 $wgTidyOpts .= ($wgInputEncoding == $wgOutputEncoding)?
' -utf8':' -raw';
411 $wgTidyOpts .= ' -raw';
414 $text = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'.
415 ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>'.
416 '<head><title>test</title></head><body>'.$text.'</body></html>';
417 $descriptorspec = array(
418 0 => array("pipe", "r"),
419 1 => array("pipe", "w"),
420 2 => array("file", "/dev/null", "a")
422 $process = proc_open("$wgTidyBin -config $wgTidyConf $wgTidyOpts", $descriptorspec, $pipes);
423 if (is_resource($process)) {
424 fwrite($pipes[0], $text);
426 while (!feof($pipes[1])) {
427 $cleansource .= fgets($pipes[1], 1024);
430 $return_value = proc_close($process);
432 if( $cleansource == '' && $text != '') {
433 return '<h2>'.wfMsg('seriousxhtmlerrors').'</h2><pre>'.htmlspecialchars($text).'</pre>';
439 function doTableStuff ( $t )
441 $t = explode ( "\n" , $t ) ;
442 $td = array () ; # Is currently a td tag open?
443 $ltd = array () ; # Was it TD or TH?
444 $tr = array () ; # Is currently a tr tag open?
445 $ltr = array () ; # tr attributes
446 foreach ( $t AS $k => $x )
449 $fc = substr ( $x , 0 , 1 ) ;
450 if ( "{|" == substr ( $x , 0 , 2 ) )
452 $t[$k] = "\n<table " . $this->fixTagAttributes ( substr ( $x , 3 ) ) . ">" ;
453 array_push ( $td , false ) ;
454 array_push ( $ltd , "" ) ;
455 array_push ( $tr , false ) ;
456 array_push ( $ltr , "" ) ;
458 else if ( count ( $td ) == 0 ) { } # Don't do any of the following
459 else if ( "|}" == substr ( $x , 0 , 2 ) )
462 $l = array_pop ( $ltd ) ;
463 if ( array_pop ( $tr ) ) $z = "</tr>" . $z ;
464 if ( array_pop ( $td ) ) $z = "</{$l}>" . $z ;
468 /* else if ( "|_" == substr ( $x , 0 , 2 ) ) # Caption
470 $z = trim ( substr ( $x , 2 ) ) ;
471 $t[$k] = "<caption>{$z}</caption>\n" ;
473 else if ( "|-" == substr ( $x , 0 , 2 ) ) # Allows for |---------------
475 $x = substr ( $x , 1 ) ;
476 while ( $x != "" && substr ( $x , 0 , 1 ) == '-' ) $x = substr ( $x , 1 ) ;
478 $l = array_pop ( $ltd ) ;
479 if ( array_pop ( $tr ) ) $z = "</tr>" . $z ;
480 if ( array_pop ( $td ) ) $z = "</{$l}>" . $z ;
483 array_push ( $tr , false ) ;
484 array_push ( $td , false ) ;
485 array_push ( $ltd , "" ) ;
486 array_push ( $ltr , $this->fixTagAttributes ( $x ) ) ;
488 else if ( "|" == $fc ||
"!" == $fc ||
"|+" == substr ( $x , 0 , 2 ) ) # Caption
490 if ( "|+" == substr ( $x , 0 , 2 ) )
493 $x = substr ( $x , 1 ) ;
495 $after = substr ( $x , 1 ) ;
496 if ( $fc == "!" ) $after = str_replace ( "!!" , "||" , $after ) ;
497 $after = explode ( "||" , $after ) ;
499 foreach ( $after AS $theline )
504 $tra = array_pop ( $ltr ) ;
505 if ( !array_pop ( $tr ) ) $z = "<tr {$tra}>\n" ;
506 array_push ( $tr , true ) ;
507 array_push ( $ltr , "" ) ;
510 $l = array_pop ( $ltd ) ;
511 if ( array_pop ( $td ) ) $z = "</{$l}>" . $z ;
512 if ( $fc == "|" ) $l = "td" ;
513 else if ( $fc == "!" ) $l = "th" ;
514 else if ( $fc == "+" ) $l = "caption" ;
516 array_push ( $ltd , $l ) ;
517 $y = explode ( "|" , $theline , 2 ) ;
518 if ( count ( $y ) == 1 ) $y = "{$z}<{$l}>{$y[0]}" ;
519 else $y = $y = "{$z}<{$l} ".$this->fixTagAttributes($y[0]).">{$y[1]}" ;
521 array_push ( $td , true ) ;
526 # Closing open td, tr && table
527 while ( count ( $td ) > 0 )
529 if ( array_pop ( $td ) ) $t[] = "</td>" ;
530 if ( array_pop ( $tr ) ) $t[] = "</tr>" ;
534 $t = implode ( "\n" , $t ) ;
535 # $t = $this->removeHTMLtags( $t );
539 # Parses the text and adds the result to the strip state
540 # Returns the strip tag
541 function stripParse( $text, $linestart, $args )
543 $text = $this->strip( $text, $this->mStripState
);
544 $text = $this->internalParse( $text, $linestart, $args, false );
546 $text = "\n" . $text;
548 return $this->insertStripItem( $text, $this->mStripState
);
551 function internalParse( $text, $linestart, $args = array(), $isMain=true )
553 $fname = "Parser::internalParse";
554 wfProfileIn( $fname );
556 $text = $this->removeHTMLtags( $text );
557 $text = $this->replaceVariables( $text, $args );
559 # $text = preg_replace( "/(^|\n)-----*/", "\\1<hr>", $text );
561 $text = $this->doHeadings( $text );
562 if($this->mOptions
->getUseDynamicDates()) {
563 global $wgDateFormatter;
564 $text = $wgDateFormatter->reformat( $this->mOptions
->getDateFormat(), $text );
566 $text = $this->replaceExternalLinks( $text );
567 $text = $this->doTokenizedParser ( $text );
568 $text = $this->doTableStuff ( $text ) ;
569 $text = $this->formatHeadings( $text, $isMain );
570 $sk =& $this->mOptions
->getSkin();
571 $text = $sk->transformContent( $text );
573 if ( !isset ( $this->categoryMagicDone
) ) {
574 $text .= $this->categoryMagic () ;
575 $this->categoryMagicDone
= true ;
578 wfProfileOut( $fname );
583 /* private */ function doHeadings( $text )
585 for ( $i = 6; $i >= 1; --$i ) {
586 $h = substr( "======", 0, $i );
587 $text = preg_replace( "/^{$h}(.+){$h}(\\s|$)/m",
588 "<h{$i}>\\1</h{$i}>\\2", $text );
593 # Note: we have to do external links before the internal ones,
594 # and otherwise take great care in the order of things here, so
595 # that we don't end up interpreting some URLs twice.
597 /* private */ function replaceExternalLinks( $text )
599 $fname = "Parser::replaceExternalLinks";
600 wfProfileIn( $fname );
601 $text = $this->subReplaceExternalLinks( $text, "http", true );
602 $text = $this->subReplaceExternalLinks( $text, "https", true );
603 $text = $this->subReplaceExternalLinks( $text, "ftp", false );
604 $text = $this->subReplaceExternalLinks( $text, "irc", false );
605 $text = $this->subReplaceExternalLinks( $text, "gopher", false );
606 $text = $this->subReplaceExternalLinks( $text, "news", false );
607 $text = $this->subReplaceExternalLinks( $text, "mailto", false );
608 wfProfileOut( $fname );
612 /* private */ function subReplaceExternalLinks( $s, $protocol, $autonumber )
614 $unique = "4jzAfzB8hNvf4sqyO9Edd8pSmk9rE2in0Tgw3";
615 $uc = "A-Za-z0-9_\\/~%\\-+&*#?!=()@\\x80-\\xFF";
617 # this is the list of separators that should be ignored if they
618 # are the last character of an URL but that should be included
619 # if they occur within the URL, e.g. "go to www.foo.com, where .."
620 # in this case, the last comma should not become part of the URL,
621 # but in "www.foo.com/123,2342,32.htm" it should.
623 $fnc = "A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF";
624 $images = "gif|png|jpg|jpeg";
626 # PLEASE NOTE: The curly braces { } are not part of the regex,
627 # they are interpreted as part of the string (used to tell PHP
628 # that the content of the string should be inserted there).
629 $e1 = "/(^|[^\\[])({$protocol}:)([{$uc}{$sep}]+)\\/([{$fnc}]+)\\." .
630 "((?i){$images})([^{$uc}]|$)/";
632 $e2 = "/(^|[^\\[])({$protocol}:)(([".$uc."]|[".$sep."][".$uc."])+)([^". $uc . $sep. "]|[".$sep."]|$)/";
633 $sk =& $this->mOptions
->getSkin();
635 if ( $autonumber and $this->mOptions
->getAllowExternalImages() ) { # Use img tags only for HTTP urls
636 $s = preg_replace( $e1, "\\1" . $sk->makeImage( "{$unique}:\\3" .
637 "/\\4.\\5", "\\4.\\5" ) . "\\6", $s );
639 $s = preg_replace( $e2, "\\1" . "<a href=\"{$unique}:\\3\"" .
640 $sk->getExternalLinkAttributes( "{$unique}:\\3", wfEscapeHTML(
641 "{$unique}:\\3" ) ) . ">" . wfEscapeHTML( "{$unique}:\\3" ) .
643 $s = str_replace( $unique, $protocol, $s );
645 $a = explode( "[{$protocol}:", " " . $s );
646 $s = array_shift( $a );
647 $s = substr( $s, 1 );
649 $e1 = "/^([{$uc}"."{$sep}]+)](.*)\$/sD";
650 $e2 = "/^([{$uc}"."{$sep}]+)\\s+([^\\]]+)](.*)\$/sD";
652 foreach ( $a as $line ) {
653 if ( preg_match( $e1, $line, $m ) ) {
654 $link = "{$protocol}:{$m[1]}";
656 if ( $autonumber ) { $text = "[" . ++
$this->mAutonumber
. "]"; }
657 else { $text = wfEscapeHTML( $link ); }
658 } else if ( preg_match( $e2, $line, $m ) ) {
659 $link = "{$protocol}:{$m[1]}";
663 $s .= "[{$protocol}:" . $line;
666 if( $link == $text ||
preg_match( "!$protocol://" . preg_quote( $text, "/" ) . "/?$!", $link ) ) {
669 # Expand the URL for printable version
670 $paren = "<span class='urlexpansion'> (<i>" . htmlspecialchars ( $link ) . "</i>)</span>";
672 $la = $sk->getExternalLinkAttributes( $link, $text );
673 $s .= "<a href='{$link}'{$la}>{$text}</a>{$paren}{$trail}";
679 /* private */ function handle4Quotes( &$state, $token )
681 /* This one makes some assumptions.
682 * '''Caesar''''s army => <strong>Caesar</strong>'s army
683 * ''''Caesar'''' was a roman emperor => '<strong>Caesar</strong>' was a roman emperor
684 * These assumptions might be wrong, but any other assumption might be wrong, too.
686 if ( $state["strong"] !== false ) {
687 return $this->handle3Quotes( $state, $token ) . "'";
689 return "'" . $this->handle3Quotes( $state, $token );
694 /* private */ function handle3Quotes( &$state, $token )
696 if ( $state["strong"] !== false ) {
697 if ( $state["em"] !== false && $state["em"] > $state["strong"] )
699 # ''' lala ''lala '''
700 $s = "</em></strong><em>";
704 $state["strong"] = FALSE;
707 $state["strong"] = $token["pos"];
712 /* private */ function handle2Quotes( &$state, $token )
714 if ( $state["em"] !== false ) {
715 if ( $state["strong"] !== false && $state["strong"] > $state["em"] )
717 # ''lala'''lala'' ....'''
718 $s = "</strong></em><strong>";
722 $state["em"] = FALSE;
725 $state["em"] = $token["pos"];
731 /* private */ function handle5Quotes( &$state, $token )
734 if ( $state["em"] !== false && $state["strong"] !== false ) {
735 if ( $state["em"] < $state["strong"] ) {
736 $s .= "</strong></em>";
738 $s .= "</em></strong>";
740 $state["strong"] = $state["em"] = FALSE;
741 } elseif ( $state["em"] !== false ) {
742 $s .= "</em><strong>";
743 $state["em"] = FALSE;
744 $state["strong"] = $token["pos"];
745 } elseif ( $state["strong"] !== false ) {
746 $s .= "</strong><em>";
747 $state["strong"] = FALSE;
748 $state["em"] = $token["pos"];
749 } else { # not $em and not $strong
750 $s .= "<strong><em>";
751 $state["strong"] = $state["em"] = $token["pos"];
756 /* private */ function doTokenizedParser( $str )
758 global $wgLang; # for language specific parser hook
759 global $wgUploadDirectory, $wgUseTimeline;
761 $tokenizer=Tokenizer
::newFromString( $str );
762 $tokenStack = array();
765 $state["em"] = FALSE;
766 $state["strong"] = FALSE;
770 # The tokenizer splits the text into tokens and returns them one by one.
771 # Every call to the tokenizer returns a new token.
772 while ( $token = $tokenizer->nextToken() )
774 switch ( $token["type"] )
777 # simple text with no further markup
778 $txt = $token["text"];
781 # Text that contains blanks that have to be converted to
782 # non-breakable spaces for French.
783 # U+202F NARROW NO-BREAK SPACE might be a better choice, but
784 # browser support for Unicode spacing is poor.
785 $txt = str_replace( " ", " ", $token["text"] );
788 # remember the tag opened with 3 [
792 # FIXME : Treat orphaned open tags (stack not empty when text is over)
794 array_push( $tokenStack, $token );
801 # get text from stack, glue it together, and call the code to handle a
804 if ( count( $tokenStack ) == 0 )
806 # stack empty. Found a ]] without an opening [[
810 $lastToken = array_pop( $tokenStack );
811 while ( !(($lastToken["type"] == "[[[") or ($lastToken["type"] == "[[")) )
813 if( !empty( $lastToken["text"] ) ) {
814 $linkText = $lastToken["text"] . $linkText;
816 $lastToken = array_pop( $tokenStack );
819 $txt = $linkText ."]]";
821 if( isset( $lastToken["text"] ) ) {
822 $prefix = $lastToken["text"];
826 $nextToken = $tokenizer->previewToken();
827 if ( $nextToken["type"] == "text" )
829 # Preview just looks at it. Now we have to fetch it.
830 $nextToken = $tokenizer->nextToken();
831 $txt .= $nextToken["text"];
833 $txt = $this->handleInternalLink( $this->unstrip($txt,$this->mStripState
), $prefix );
835 # did the tag start with 3 [ ?
837 # show the first as text
843 $tagIsOpen = (count( $tokenStack ) != 0);
849 # This and the four next ones handle quotes
850 $txt = $this->handle3Quotes( $state, $token );
853 $txt = $this->handle2Quotes( $state, $token );
856 $txt = $this->handle5Quotes( $state, $token );
859 $txt = $this->handle4Quotes( $state, $token );
866 #heading- used to close all unbalanced bold or em tags in this section
868 if( $state['em'] !== false and
869 ( $state['strong'] === false or $state['em'] > $state['strong'] ) )
872 $state['em'] = false;
874 if ( $state['strong'] !== false ) $txt .= '</strong>';
875 if ( $state['em'] !== false ) $txt .= '</em>';
876 $state['strong'] = $state['em'] = false;
882 $txt = $this->doMagicRFC( $tokenizer );
889 $txt = $this->doMagicISBN( $tokenizer );
893 if ( $wgUseTimeline &&
894 "" != ( $timelinesrc = $tokenizer->readAllUntil("</timeline>") ) )
896 $txt = renderTimeline( $timelinesrc );
902 # Call language specific Hook.
903 $txt = $wgLang->processToken( $token, $tokenStack );
904 if ( NULL == $txt ) {
905 # An unkown token. Highlight.
906 $txt = "<font color=\"#FF0000\"><b>".$token["type"]."</b></font>";
907 $txt .= "<font color=\"#FFFF00\"><b>".$token["text"]."</b></font>";
911 # If we're parsing the interior of a link, don't append the interior to $s,
912 # but push it to the stack so it can be processed when a ]] token is found.
913 if ( $tagIsOpen && $txt != "" ) {
914 $token["type"] = "text";
915 $token["text"] = $txt;
916 array_push( $tokenStack, $token );
922 # make 100% sure all strong and em tags are closed
923 # doBlockLevels often messes the last bit up though, but invalid nesting is better than unclosed tags
924 # tidy solves this though
925 if( $state['em'] !== false and
926 ( $state['strong'] === false or $state['em'] > $state['strong'] ) )
929 $state['em'] = false;
931 if ( $state['strong'] !== false ) $s .= '</strong>';
932 if ( $state['em'] !== false ) $s .= '</em>';
934 if ( count( $tokenStack ) != 0 )
936 # still objects on stack. opened [[ tag without closing ]] tag.
938 while ( $lastToken = array_pop( $tokenStack ) )
940 if ( $lastToken["type"] == "text" )
942 $txt = $lastToken["text"] . $txt;
944 $txt = $lastToken["type"] . $txt;
952 /* private */ function handleInternalLink( $line, $prefix )
954 global $wgLang, $wgLinkCache;
955 global $wgNamespacesWithSubpages, $wgLanguageCode;
956 static $fname = "Parser::handleInternalLink" ;
957 wfProfileIn( $fname );
959 wfProfileIn( "$fname-setup" );
961 # the % is needed to support urlencoded titles as well
962 if ( !$tc ) { $tc = Title
::legalChars() . "#%"; }
963 $sk =& $this->mOptions
->getSkin();
965 # Match a link having the form [[namespace:link|alternate]]trail
967 if ( !$e1 ) { $e1 = "/^([{$tc}]+)(?:\\|([^]]+))?]](.*)\$/sD"; }
968 # Match the end of a line for a word that's not followed by whitespace,
969 # e.g. in the case of 'The Arab al[[Razi]]', 'al' will be matched
970 #$e2 = "/^(.*)\\b(\\w+)\$/suD";
971 #$e2 = "/^(.*\\s)(\\S+)\$/suD";
972 static $e2 = '/^(.*\s)([a-zA-Z\x80-\xff]+)$/sD';
975 # Special and Media are pseudo-namespaces; no pages actually exist in them
976 static $image = FALSE;
977 static $special = FALSE;
978 static $media = FALSE;
979 static $category = FALSE;
980 if ( !$image ) { $image = Namespace::getImage(); }
981 if ( !$special ) { $special = Namespace::getSpecial(); }
982 if ( !$media ) { $media = Namespace::getMedia(); }
983 if ( !$category ) { $category = Namespace::getCategory(); }
985 $nottalk = !Namespace::isTalk( $this->mTitle
->getNamespace() );
987 wfProfileOut( "$fname-setup" );
990 if ( preg_match( $e1, $line, $m ) ) { # page with normal text or alt
992 # fix up urlencoded title texts
993 if(preg_match("/%/", $m[1] )) $m[1] = urldecode($m[1]);
995 } else { # Invalid form; output directly
996 $s .= $prefix . "[[" . $line ;
1000 /* Valid link forms:
1002 :Foobar -- override special treatment of prefix (images, language links)
1003 /Foobar -- convert to CurrentPage/Foobar
1004 /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text
1006 $c = substr($m[1],0,1);
1007 $noforce = ($c != ":");
1008 if( $c == "/" ) { # subpage
1009 if(substr($m[1],-1,1)=="/") { # / at end means we don't want the slash to be shown
1010 $m[1]=substr($m[1],1,strlen($m[1])-2);
1013 $noslash=substr($m[1],1);
1015 if(!empty($wgNamespacesWithSubpages[$this->mTitle
->getNamespace()])) { # subpages allowed here
1016 $link = $this->mTitle
->getPrefixedText(). "/" . trim($noslash);
1019 } # this might be changed for ugliness reasons
1021 $link = $noslash; # no subpage allowed, use standard link
1023 } elseif( $noforce ) { # no subpage
1026 $link = substr( $m[1], 1 );
1028 $wasblank = ( "" == $text );
1032 $nt = Title
::newFromText( $link );
1034 $s .= $prefix . "[[" . $line;
1037 $ns = $nt->getNamespace();
1038 $iw = $nt->getInterWiki();
1040 if( $iw && $this->mOptions
->getInterwikiMagic() && $nottalk && $wgLang->getLanguageName( $iw ) ) {
1041 array_push( $this->mOutput
->mLanguageLinks
, $nt->getPrefixedText() );
1042 $s .= $prefix . $trail ;
1043 return (trim($s) == '')?
'': $s;
1045 if( $ns == $image ) {
1046 $s .= $prefix . $sk->makeImageLinkObj( $nt, $text ) . $trail;
1047 $wgLinkCache->addImageLinkObj( $nt );
1050 if ( $ns == $category ) {
1051 $t = $nt->getText() ;
1052 $nnt = Title
::newFromText ( Namespace::getCanonicalName($category).":".$t ) ;
1054 $wgLinkCache->suspend(); # Don't save in links/brokenlinks
1055 $t = $sk->makeLinkObj( $nnt, $t, "", "" , $prefix );
1056 $wgLinkCache->resume();
1058 $sortkey = $wasblank ?
$this->mTitle
->getPrefixedText() : $text;
1059 $wgLinkCache->addCategoryLinkObj( $nt, $sortkey );
1060 $this->mOutput
->mCategoryLinks
[] = $t ;
1061 $s .= $prefix . $trail ;
1065 if( ( $nt->getPrefixedText() == $this->mTitle
->getPrefixedText() ) &&
1066 ( strpos( $link, "#" ) == FALSE ) ) {
1067 # Self-links are handled specially; generally de-link and change to bold.
1068 $s .= $prefix . $sk->makeSelfLinkObj( $nt, $text, "", $trail );
1072 if( $ns == $media ) {
1073 $s .= $prefix . $sk->makeMediaLinkObj( $nt, $text ) . $trail;
1074 $wgLinkCache->addImageLinkObj( $nt );
1076 } elseif( $ns == $special ) {
1077 $s .= $prefix . $sk->makeKnownLinkObj( $nt, $text, "", $trail );
1080 $s .= $sk->makeLinkObj( $nt, $text, "", $trail , $prefix );
1082 wfProfileOut( $fname );
1086 # Some functions here used by doBlockLevels()
1088 /* private */ function closeParagraph()
1091 if ( '' != $this->mLastSection
) {
1092 $result = "</" . $this->mLastSection
. ">\n";
1094 $this->mInPre
= false;
1095 $this->mLastSection
= "";
1098 # getCommon() returns the length of the longest common substring
1099 # of both arguments, starting at the beginning of both.
1101 /* private */ function getCommon( $st1, $st2 )
1103 $fl = strlen( $st1 );
1104 $shorter = strlen( $st2 );
1105 if ( $fl < $shorter ) { $shorter = $fl; }
1107 for ( $i = 0; $i < $shorter; ++
$i ) {
1108 if ( $st1{$i} != $st2{$i} ) { break; }
1112 # These next three functions open, continue, and close the list
1113 # element appropriate to the prefix character passed into them.
1115 /* private */ function openList( $char )
1117 $result = $this->closeParagraph();
1119 if ( "*" == $char ) { $result .= "<ul><li>"; }
1120 else if ( "#" == $char ) { $result .= "<ol><li>"; }
1121 else if ( ":" == $char ) { $result .= "<dl><dd>"; }
1122 else if ( ";" == $char ) {
1123 $result .= "<dl><dt>";
1124 $this->mDTopen
= true;
1126 else { $result = "<!-- ERR 1 -->"; }
1131 /* private */ function nextItem( $char )
1133 if ( "*" == $char ||
"#" == $char ) { return "</li><li>"; }
1134 else if ( ":" == $char ||
";" == $char ) {
1136 if ( $this->mDTopen
) { $close = "</dt>"; }
1137 if ( ";" == $char ) {
1138 $this->mDTopen
= true;
1139 return $close . "<dt>";
1141 $this->mDTopen
= false;
1142 return $close . "<dd>";
1145 return "<!-- ERR 2 -->";
1148 /* private */function closeList( $char )
1150 if ( "*" == $char ) { $text = "</li></ul>"; }
1151 else if ( "#" == $char ) { $text = "</li></ol>"; }
1152 else if ( ":" == $char ) {
1153 if ( $this->mDTopen
) {
1154 $this->mDTopen
= false;
1155 $text = "</dt></dl>";
1157 $text = "</dd></dl>";
1160 else { return "<!-- ERR 3 -->"; }
1164 /* private */ function doBlockLevels( $text, $linestart ) {
1165 $fname = "Parser::doBlockLevels";
1166 wfProfileIn( $fname );
1168 # Parsing through the text line by line. The main thing
1169 # happening here is handling of block-level elements p, pre,
1170 # and making lists from lines starting with * # : etc.
1172 $textLines = explode( "\n", $text );
1174 $lastPrefix = $output = $lastLine = '';
1175 $this->mDTopen
= $inBlockElem = false;
1177 $paragraphStack = false;
1179 if ( !$linestart ) {
1180 $output .= array_shift( $textLines );
1182 foreach ( $textLines as $oLine ) {
1183 $lastPrefixLength = strlen( $lastPrefix );
1184 $preCloseMatch = preg_match("/<\\/pre/i", $oLine );
1185 $preOpenMatch = preg_match("/<pre/i", $oLine );
1186 if (!$this->mInPre
) {
1187 $this->mInPre
= !empty($preOpenMatch);
1189 if ( !$this->mInPre
) {
1190 # Multiple prefixes may abut each other for nested lists.
1191 $prefixLength = strspn( $oLine, "*#:;" );
1192 $pref = substr( $oLine, 0, $prefixLength );
1195 $pref2 = str_replace( ";", ":", $pref );
1196 $t = substr( $oLine, $prefixLength );
1198 # Don't interpret any other prefixes in preformatted text
1200 $pref = $pref2 = '';
1205 if( $prefixLength && 0 == strcmp( $lastPrefix, $pref2 ) ) {
1206 # Same as the last item, so no need to deal with nesting or opening stuff
1207 $output .= $this->nextItem( substr( $pref, -1 ) );
1208 $paragraphStack = false;
1210 if ( ";" == substr( $pref, -1 ) ) {
1211 # The one nasty exception: definition lists work like this:
1212 # ; title : definition text
1213 # So we check for : in the remainder text to split up the
1214 # title and definition, without b0rking links.
1215 # FIXME: This is not foolproof. Something better in Tokenizer might help.
1216 if( preg_match( '/^(.*?(?:\s| )):(.*)$/', $t, $match ) ) {
1218 $output .= $term . $this->nextItem( ":" );
1222 } elseif( $prefixLength ||
$lastPrefixLength ) {
1223 # Either open or close a level...
1224 $commonPrefixLength = $this->getCommon( $pref, $lastPrefix );
1225 $paragraphStack = false;
1227 while( $commonPrefixLength < $lastPrefixLength ) {
1228 $output .= $this->closeList( $lastPrefix{$lastPrefixLength-1} );
1229 --$lastPrefixLength;
1231 if ( $prefixLength <= $commonPrefixLength && $commonPrefixLength > 0 ) {
1232 $output .= $this->nextItem( $pref{$commonPrefixLength-1} );
1234 while ( $prefixLength > $commonPrefixLength ) {
1235 $char = substr( $pref, $commonPrefixLength, 1 );
1236 $output .= $this->openList( $char );
1238 if ( ";" == $char ) {
1239 # FIXME: This is dupe of code above
1240 if( preg_match( '/^(.*?(?:\s| )):(.*)$/', $t, $match ) ) {
1242 $output .= $term . $this->nextItem( ":" );
1246 ++
$commonPrefixLength;
1248 $lastPrefix = $pref2;
1250 if( 0 == $prefixLength ) {
1251 # No prefix (not in list)--go to paragraph mode
1252 $uniq_prefix = UNIQ_PREFIX
;
1253 // XXX: use a stack for nestable elements like span, table and div
1254 $openmatch = preg_match("/(<table|<blockquote|<h1|<h2|<h3|<h4|<h5|<h6|<pre|<tr|<td|<p|<ul|<li)/i", $t );
1255 $closematch = preg_match(
1256 "/(<\\/table|<\\/blockquote|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|".
1257 "<div|<\\/div|<hr|<\\/td|<\\/pre|<\\/p|".$uniq_prefix."-pre|<\\/li|<\\/ul)/i", $t );
1258 if ( $openmatch or $closematch ) {
1259 $paragraphStack = false;
1260 $output .= $this->closeParagraph();
1261 if($preOpenMatch and !$preCloseMatch) {
1262 $this->mInPre
= true;
1264 if ( $closematch ) {
1265 $inBlockElem = false;
1267 $inBlockElem = true;
1269 } else if ( !$inBlockElem && !$this->mInPre
) {
1270 if ( " " == $t{0} and trim($t) != '' ) {
1272 if ($this->mLastSection
!= 'pre') {
1273 $paragraphStack = false;
1274 $output .= $this->closeParagraph().'<pre>';
1275 $this->mLastSection
= 'pre';
1279 if ( '' == trim($t) ) {
1280 if ( $paragraphStack ) {
1281 $output .= $paragraphStack.'<br/>';
1282 $paragraphStack = false;
1283 $this->mLastSection
= 'p';
1285 if ($this->mLastSection
!= 'p' ) {
1286 $output .= $this->closeParagraph();
1287 $this->mLastSection
= '';
1288 $paragraphStack = "<p>";
1290 $paragraphStack = '</p><p>';
1294 if ( $paragraphStack ) {
1295 $output .= $paragraphStack;
1296 $paragraphStack = false;
1297 $this->mLastSection
= 'p';
1298 } else if ($this->mLastSection
!= 'p') {
1299 $output .= $this->closeParagraph().'<p>';
1300 $this->mLastSection
= 'p';
1306 if ($paragraphStack === false) {
1310 while ( $prefixLength ) {
1311 $output .= $this->closeList( $pref2{$prefixLength-1} );
1314 if ( "" != $this->mLastSection
) {
1315 $output .= "</" . $this->mLastSection
. ">";
1316 $this->mLastSection
= "";
1319 wfProfileOut( $fname );
1323 function getVariableValue( $index ) {
1324 global $wgLang, $wgSitename, $wgServer;
1327 case MAG_CURRENTMONTH
:
1329 case MAG_CURRENTMONTHNAME
:
1330 return $wgLang->getMonthName( date("n") );
1331 case MAG_CURRENTMONTHNAMEGEN
:
1332 return $wgLang->getMonthNameGen( date("n") );
1333 case MAG_CURRENTDAY
:
1336 return $this->mTitle
->getText();
1338 # return Namespace::getCanonicalName($this->mTitle->getNamespace());
1339 return $wgLang->getNsText($this->mTitle
->getNamespace()); // Patch by Dori
1340 case MAG_CURRENTDAYNAME
:
1341 return $wgLang->getWeekdayName( date("w")+
1 );
1342 case MAG_CURRENTYEAR
:
1344 case MAG_CURRENTTIME
:
1345 return $wgLang->time( wfTimestampNow(), false );
1346 case MAG_NUMBEROFARTICLES
:
1347 return wfNumberOfArticles();
1357 function initialiseVariables()
1359 global $wgVariableIDs;
1360 $this->mVariables
= array();
1361 foreach ( $wgVariableIDs as $id ) {
1362 $mw =& MagicWord
::get( $id );
1363 $mw->addToArray( $this->mVariables
, $this->getVariableValue( $id ) );
1367 /* private */ function replaceVariables( $text, $args = array() )
1369 global $wgLang, $wgScript, $wgArticlePath;
1371 $fname = "Parser::replaceVariables";
1372 wfProfileIn( $fname );
1375 if ( !$this->mVariables
) {
1376 $this->initialiseVariables();
1378 $titleChars = Title
::legalChars();
1380 # This function is called recursively. To keep track of arguments we need a stack:
1381 array_push( $this->mArgStack
, $args );
1383 # PHP global rebinding syntax is a bit weird, need to use the GLOBALS array
1384 $GLOBALS['wgCurParser'] =& $this;
1386 # Argument substitution
1387 if ( $this->mOutputType
== OT_HTML
) {
1388 $text = preg_replace_callback( "/(\\n?){{{([$titleChars]*?)}}}/", "wfArgSubstitution", $text );
1391 # Double brace substitution
1392 $regex = "/(\\n?){{([$titleChars]*?)(\\|.*?|)}}/s";
1393 $text = preg_replace_callback( $regex, "wfBraceSubstitution", $text );
1395 array_pop( $this->mArgStack
);
1400 function braceSubstitution( $matches )
1402 global $wgLinkCache, $wgLang;
1403 $fname = "Parser::braceSubstitution";
1410 # $newline is an optional newline character before the braces
1411 # $part1 is the bit before the first |, and must contain only title characters
1412 # $args is a list of arguments, starting from index 0, not including $part1
1414 $newline = $matches[1];
1415 $part1 = $matches[2];
1416 # If the third subpattern matched anything, it will start with |
1417 if ( $matches[3] !== "" ) {
1418 $args = explode( "|", substr( $matches[3], 1 ) );
1422 $argc = count( $args );
1425 if ( strpos( $matches[0], "{{{" ) !== false ) {
1426 $text = $matches[0];
1433 $mwSubst =& MagicWord
::get( MAG_SUBST
);
1434 if ( $mwSubst->matchStartAndRemove( $part1 ) ) {
1435 if ( $this->mOutputType
!= OT_WIKI
) {
1436 # Invalid SUBST not replaced at PST time
1437 # Return without further processing
1438 $text = $matches[0];
1442 } elseif ( $this->mOutputType
== OT_WIKI
) {
1443 # SUBST not found in PST pass, do nothing
1444 $text = $matches[0];
1449 # MSG, MSGNW and INT
1452 $mwMsgnw =& MagicWord
::get( MAG_MSGNW
);
1453 if ( $mwMsgnw->matchStartAndRemove( $part1 ) ) {
1456 # Remove obsolete MSG:
1457 $mwMsg =& MagicWord
::get( MAG_MSG
);
1458 $mwMsg->matchStartAndRemove( $part1 );
1461 # Check if it is an internal message
1462 $mwInt =& MagicWord
::get( MAG_INT
);
1463 if ( $mwInt->matchStartAndRemove( $part1 ) ) {
1464 if ( $this->incrementIncludeCount( "int:$part1" ) ) {
1465 $text = wfMsgReal( $part1, $args, true );
1473 # Check for NS: (namespace expansion)
1474 $mwNs = MagicWord
::get( MAG_NS
);
1475 if ( $mwNs->matchStartAndRemove( $part1 ) ) {
1476 if ( intval( $part1 ) ) {
1477 $text = $wgLang->getNsText( intval( $part1 ) );
1480 $index = Namespace::getCanonicalIndex( strtolower( $part1 ) );
1481 if ( !is_null( $index ) ) {
1482 $text = $wgLang->getNsText( $index );
1489 # LOCALURL and LOCALURLE
1491 $mwLocal = MagicWord
::get( MAG_LOCALURL
);
1492 $mwLocalE = MagicWord
::get( MAG_LOCALURLE
);
1494 if ( $mwLocal->matchStartAndRemove( $part1 ) ) {
1495 $func = 'getLocalURL';
1496 } elseif ( $mwLocalE->matchStartAndRemove( $part1 ) ) {
1497 $func = 'escapeLocalURL';
1502 if ( $func !== '' ) {
1503 $title = Title
::newFromText( $part1 );
1504 if ( !is_null( $title ) ) {
1506 $text = $title->$func( $args[0] );
1508 $text = $title->$func();
1515 # Internal variables
1516 if ( !$found && array_key_exists( $part1, $this->mVariables
) ) {
1517 $text = $this->mVariables
[$part1];
1519 $this->mOutput
->mContainsOldMagic
= true;
1522 # Arguments input from the caller
1523 $inputArgs = end( $this->mArgStack );
1524 if ( !$found && array_key_exists( $part1, $inputArgs ) ) {
1525 $text = $inputArgs[$part1];
1529 # Load from database
1531 $title = Title
::newFromText( $part1, NS_TEMPLATE
);
1532 if ( !is_null( $title ) && !$title->isExternal() ) {
1533 # Check for excessive inclusion
1534 $dbk = $title->getPrefixedDBkey();
1535 if ( $this->incrementIncludeCount( $dbk ) ) {
1536 $article = new Article( $title );
1537 $articleContent = $article->getContentWithoutUsingSoManyDamnGlobals();
1538 if ( $articleContent !== false ) {
1540 $text = $articleContent;
1545 # If the title is valid but undisplayable, make a link to it
1546 if ( $this->mOutputType
== OT_HTML
&& !$found ) {
1547 $text = "[[" . $title->getPrefixedText() . "]]";
1553 # Recursive parsing, escaping and link table handling
1554 # Only for HTML output
1555 if ( $nowiki && $found && $this->mOutputType
== OT_HTML
) {
1556 $text = wfEscapeWikiText( $text );
1557 } elseif ( $this->mOutputType
== OT_HTML
&& $found && !$noparse) {
1558 # Clean up argument array
1559 $assocArgs = array();
1561 foreach( $args as $arg ) {
1562 $eqpos = strpos( $arg, "=" );
1563 if ( $eqpos === false ) {
1564 $assocArgs[$index++
] = $arg;
1566 $name = trim( substr( $arg, 0, $eqpos ) );
1567 $value = trim( substr( $arg, $eqpos+
1 ) );
1568 if ( $value === false ) {
1571 if ( $name !== false ) {
1572 $assocArgs[$name] = $value;
1577 # Do not enter included links in link table
1578 if ( !is_null( $title ) ) {
1579 $wgLinkCache->suspend();
1582 # Run full parser on the included text
1583 $text = $this->stripParse( $text, (bool)$newline, $assocArgs );
1585 # Resume the link cache and register the inclusion as a link
1586 if ( !is_null( $title ) ) {
1587 $wgLinkCache->resume();
1588 $wgLinkCache->addLinkObj( $title );
1599 # Triple brace replacement -- used for template arguments
1600 function argSubstitution( $matches )
1602 $newline = $matches[1];
1603 $arg = trim( $matches[2] );
1604 $text = $matches[0];
1605 $inputArgs = end( $this->mArgStack
);
1607 if ( array_key_exists( $arg, $inputArgs ) ) {
1608 $text = $this->stripParse( $inputArgs[$arg], (bool)$newline, array() );
1614 # Returns true if the function is allowed to include this entity
1615 function incrementIncludeCount( $dbk )
1617 if ( !array_key_exists( $dbk, $this->mIncludeCount
) ) {
1618 $this->mIncludeCount
[$dbk] = 0;
1620 if ( ++
$this->mIncludeCount
[$dbk] <= MAX_INCLUDE_REPEAT
) {
1628 # Cleans up HTML, removes dangerous tags and attributes
1629 /* private */ function removeHTMLtags( $text )
1631 global $wgUseTidy, $wgUserHtml;
1632 $fname = "Parser::removeHTMLtags";
1633 wfProfileIn( $fname );
1636 $htmlpairs = array( # Tags that must be closed
1637 "b", "del", "i", "ins", "u", "font", "big", "small", "sub", "sup", "h1",
1638 "h2", "h3", "h4", "h5", "h6", "cite", "code", "em", "s",
1639 "strike", "strong", "tt", "var", "div", "center",
1640 "blockquote", "ol", "ul", "dl", "table", "caption", "pre",
1641 "ruby", "rt" , "rb" , "rp", "p"
1643 $htmlsingle = array(
1644 "br", "hr", "li", "dt", "dd"
1646 $htmlnest = array( # Tags that can be nested--??
1647 "table", "tr", "td", "th", "div", "blockquote", "ol", "ul",
1648 "dl", "font", "big", "small", "sub", "sup"
1650 $tabletags = array( # Can only appear inside table
1654 $htmlpairs = array();
1655 $htmlsingle = array();
1656 $htmlnest = array();
1657 $tabletags = array();
1660 $htmlsingle = array_merge( $tabletags, $htmlsingle );
1661 $htmlelements = array_merge( $htmlsingle, $htmlpairs );
1663 $htmlattrs = $this->getHTMLattrs () ;
1665 # Remove HTML comments
1666 $text = preg_replace( "/(\\n *<!--.*--> *(?=\\n)|<!--.*-->)/sU", "$2", $text );
1668 $bits = explode( "<", $text );
1669 $text = array_shift( $bits );
1671 $tagstack = array(); $tablestack = array();
1672 foreach ( $bits as $x ) {
1673 $prev = error_reporting( E_ALL
& ~
( E_NOTICE | E_WARNING
) );
1674 preg_match( "/^(\\/?)(\\w+)([^>]*)(\\/{0,1}>)([^<]*)$/",
1676 list( $qbar, $slash, $t, $params, $brace, $rest ) = $regs;
1677 error_reporting( $prev );
1680 if ( in_array( $t = strtolower( $t ), $htmlelements ) ) {
1684 if ( ! in_array( $t, $htmlsingle ) &&
1685 ( count($tagstack) && $ot = array_pop( $tagstack ) ) != $t ) {
1686 if(!empty($ot)) array_push( $tagstack, $ot );
1689 if ( $t == "table" ) {
1690 $tagstack = array_pop( $tablestack );
1695 # Keep track for later
1696 if ( in_array( $t, $tabletags ) &&
1697 ! in_array( "table", $tagstack ) ) {
1699 } else if ( in_array( $t, $tagstack ) &&
1700 ! in_array ( $t , $htmlnest ) ) {
1702 } else if ( ! in_array( $t, $htmlsingle ) ) {
1703 if ( $t == "table" ) {
1704 array_push( $tablestack, $tagstack );
1705 $tagstack = array();
1707 array_push( $tagstack, $t );
1709 # Strip non-approved attributes from the tag
1710 $newparams = $this->fixTagAttributes($params);
1714 $rest = str_replace( ">", ">", $rest );
1715 $text .= "<$slash$t $newparams$brace$rest";
1719 $text .= "<" . str_replace( ">", ">", $x);
1721 # Close off any remaining tags
1722 while ( $t = array_pop( $tagstack ) ) {
1724 if ( $t == "table" ) { $tagstack = array_pop( $tablestack ); }
1727 # this might be possible using tidy itself
1728 foreach ( $bits as $x ) {
1729 preg_match( "/^(\\/?)(\\w+)([^>]*)(\\/{0,1}>)([^<]*)$/",
1731 @list
( $qbar, $slash, $t, $params, $brace, $rest ) = $regs;
1732 if ( in_array( $t = strtolower( $t ), $htmlelements ) ) {
1733 $newparams = $this->fixTagAttributes($params);
1734 $rest = str_replace( ">", ">", $rest );
1735 $text .= "<$slash$t $newparams$brace$rest";
1737 $text .= "<" . str_replace( ">", ">", $x);
1741 wfProfileOut( $fname );
1748 * This function accomplishes several tasks:
1749 * 1) Auto-number headings if that option is enabled
1750 * 2) Add an [edit] link to sections for logged in users who have enabled the option
1751 * 3) Add a Table of contents on the top for users who have enabled the option
1752 * 4) Auto-anchor headings
1754 * It loops through all headlines, collects the necessary data, then splits up the
1755 * string and re-inserts the newly formatted headlines.
1759 /* private */ function formatHeadings( $text, $isMain=true )
1761 global $wgInputEncoding;
1763 $doNumberHeadings = $this->mOptions
->getNumberHeadings();
1764 $doShowToc = $this->mOptions
->getShowToc();
1765 if( !$this->mTitle
->userCanEdit() ) {
1767 $rightClickHack = 0;
1769 $showEditLink = $this->mOptions
->getEditSection();
1770 $rightClickHack = $this->mOptions
->getEditSectionOnRightClick();
1773 # Inhibit editsection links if requested in the page
1774 $esw =& MagicWord
::get( MAG_NOEDITSECTION
);
1775 if( $esw->matchAndRemove( $text ) ) {
1778 # if the string __NOTOC__ (not case-sensitive) occurs in the HTML,
1780 $mw =& MagicWord
::get( MAG_NOTOC
);
1781 if( $mw->matchAndRemove( $text ) ) {
1785 # never add the TOC to the Main Page. This is an entry page that should not
1786 # be more than 1-2 screens large anyway
1787 if( $this->mTitle
->getPrefixedText() == wfMsg("mainpage") ) {
1791 # Get all headlines for numbering them and adding funky stuff like [edit]
1792 # links - this is for later, but we need the number of headlines right now
1793 $numMatches = preg_match_all( "/<H([1-6])(.*?" . ">)(.*?)<\/H[1-6]>/i", $text, $matches );
1795 # if there are fewer than 4 headlines in the article, do not show TOC
1796 if( $numMatches < 4 ) {
1800 # if the string __FORCETOC__ (not case-sensitive) occurs in the HTML,
1801 # override above conditions and always show TOC
1802 $mw =& MagicWord
::get( MAG_FORCETOC
);
1803 if ($mw->matchAndRemove( $text ) ) {
1808 # We need this to perform operations on the HTML
1809 $sk =& $this->mOptions
->getSkin();
1814 # Ugh .. the TOC should have neat indentation levels which can be
1815 # passed to the skin functions. These are determined here
1820 $sublevelCount = array();
1823 foreach( $matches[3] as $headline ) {
1826 $prevlevel = $level;
1828 $level = $matches[1][$headlineCount];
1829 if( ( $doNumberHeadings ||
$doShowToc ) && $prevlevel && $level > $prevlevel ) {
1830 # reset when we enter a new level
1831 $sublevelCount[$level] = 0;
1832 $toc .= $sk->tocIndent( $level - $prevlevel );
1833 $toclevel +
= $level - $prevlevel;
1835 if( ( $doNumberHeadings ||
$doShowToc ) && $level < $prevlevel ) {
1836 # reset when we step back a level
1837 $sublevelCount[$level+
1]=0;
1838 $toc .= $sk->tocUnindent( $prevlevel - $level );
1839 $toclevel -= $prevlevel - $level;
1841 # count number of headlines for each level
1842 @$sublevelCount[$level]++
;
1843 if( $doNumberHeadings ||
$doShowToc ) {
1845 for( $i = 1; $i <= $level; $i++
) {
1846 if( !empty( $sublevelCount[$i] ) ) {
1850 $numbering .= $sublevelCount[$i];
1856 # The canonized header is a version of the header text safe to use for links
1857 # Avoid insertion of weird stuff like <math> by expanding the relevant sections
1858 $canonized_headline = $this->unstrip( $headline, $this->mStripState
);
1861 $canonized_headline = preg_replace( "/<.*?" . ">/","",$canonized_headline );
1862 $tocline = trim( $canonized_headline );
1863 $canonized_headline = preg_replace("/[ \\?&\\/<>\\(\\)\\[\\]=,+']+/", '_', urlencode( do_html_entity_decode( $tocline, ENT_COMPAT
, $wgInputEncoding ) ) );
1864 # strip out urlencoded (inserted for french spaces, e.g. first space in 'something : something')
1865 $canonized_headline = str_replace('%C2%A0','_', $canonized_headline);
1866 $refer[$headlineCount] = $canonized_headline;
1868 # count how many in assoc. array so we can track dupes in anchors
1869 @$refers[$canonized_headline]++
;
1870 $refcount[$headlineCount]=$refers[$canonized_headline];
1872 # Prepend the number to the heading text
1874 if( $doNumberHeadings ||
$doShowToc ) {
1875 $tocline = $numbering . " " . $tocline;
1877 # Don't number the heading if it is the only one (looks silly)
1878 if( $doNumberHeadings && count( $matches[3] ) > 1) {
1879 # the two are different if the line contains a link
1880 $headline=$numbering . " " . $headline;
1884 # Create the anchor for linking from the TOC to the section
1885 $anchor = $canonized_headline;
1886 if($refcount[$headlineCount] > 1 ) {
1887 $anchor .= "_" . $refcount[$headlineCount];
1890 $toc .= $sk->tocLine($anchor,$tocline,$toclevel);
1892 if( $showEditLink ) {
1893 if ( empty( $head[$headlineCount] ) ) {
1894 $head[$headlineCount] = "";
1896 $head[$headlineCount] .= $sk->editSectionLink($headlineCount+
1);
1899 # Add the edit section span
1900 if( $rightClickHack ) {
1901 $headline = $sk->editSectionScript($headlineCount+
1,$headline);
1904 # give headline the correct <h#> tag
1905 @$head[$headlineCount] .= "<a name=\"$anchor\"></a><h".$level.$matches[2][$headlineCount] .$headline."</h".$level.">";
1911 $toclines = $headlineCount;
1912 $toc .= $sk->tocUnindent( $toclevel );
1913 $toc = $sk->tocTable( $toc );
1916 # split up and insert constructed headlines
1918 $blocks = preg_split( "/<H[1-6].*?" . ">.*?<\/H[1-6]>/i", $text );
1921 foreach( $blocks as $block ) {
1922 if( $showEditLink && $headlineCount > 0 && $i == 0 && $block != "\n" ) {
1923 # This is the [edit] link that appears for the top block of text when
1924 # section editing is enabled
1926 # Disabled because it broke block formatting
1927 # For example, a bullet point in the top line
1928 # $full .= $sk->editSectionLink(0);
1931 if( $doShowToc && !$i && $isMain) {
1932 # Top anchor now in skin
1936 if( !empty( $head[$i] ) ) {
1945 /* private */ function doMagicISBN( &$tokenizer )
1949 # Check whether next token is a text token
1950 # If yes, fetch it and convert the text into a
1951 # Special::BookSources link
1952 $token = $tokenizer->previewToken();
1953 while ( $token["type"] == "" )
1955 $tokenizer->nextToken();
1956 $token = $tokenizer->previewToken();
1958 if ( $token["type"] == "text" )
1960 $token = $tokenizer->nextToken();
1961 $x = $token["text"];
1962 $valid = "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1964 $isbn = $blank = "" ;
1965 while ( " " == $x{0} ) {
1967 $x = substr( $x, 1 );
1969 while ( strstr( $valid, $x{0} ) != false ) {
1971 $x = substr( $x, 1 );
1973 $num = str_replace( "-", "", $isbn );
1974 $num = str_replace( " ", "", $num );
1977 $text = "ISBN $blank$x";
1979 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Booksources" );
1980 $text = "<a href=\"" .
1981 $titleObj->escapeLocalUrl( "isbn={$num}" ) .
1982 "\" class=\"internal\">ISBN $isbn</a>";
1990 /* private */ function doMagicRFC( &$tokenizer )
1994 # Check whether next token is a text token
1995 # If yes, fetch it and convert the text into a
1996 # link to an RFC source
1997 $token = $tokenizer->previewToken();
1998 while ( $token["type"] == "" )
2000 $tokenizer->nextToken();
2001 $token = $tokenizer->previewToken();
2003 if ( $token["type"] == "text" )
2005 $token = $tokenizer->nextToken();
2006 $x = $token["text"];
2007 $valid = "0123456789";
2009 $rfc = $blank = "" ;
2010 while ( " " == $x{0} ) {
2012 $x = substr( $x, 1 );
2014 while ( strstr( $valid, $x{0} ) != false ) {
2016 $x = substr( $x, 1 );
2020 $text .= "RFC $blank$x";
2022 $url = wfmsg( "rfcurl" );
2023 $url = str_replace( "$1", $rfc, $url);
2024 $sk =& $this->mOptions
->getSkin();
2025 $la = $sk->getExternalLinkAttributes( $url, "RFC {$rfc}" );
2026 $text = "<a href='{$url}'{$la}>RFC {$rfc}</a>{$x}";
2034 function preSaveTransform( $text, &$title, &$user, $options, $clearState = true )
2036 $this->mOptions
= $options;
2037 $this->mTitle
=& $title;
2038 $this->mOutputType
= OT_WIKI
;
2040 if ( $clearState ) {
2041 $this->clearState();
2044 $stripState = false;
2048 $text = str_replace(array_keys($pairs), array_values($pairs), $text);
2051 "/<br.+(clear|break)=[\"']?(all|both)[\"']?\\/?>/i" => '<br style="clear:both;"/>',
2052 "/<br *?>/i" => "<br/>",
2054 $text = preg_replace(array_keys($pairs), array_values($pairs), $text);
2055 $text = $this->strip( $text, $stripState, false );
2056 $text = $this->pstPass2( $text, $user );
2057 $text = $this->unstrip( $text, $stripState );
2061 /* private */ function pstPass2( $text, &$user )
2063 global $wgLang, $wgLocaltimezone, $wgCurParser;
2065 # Variable replacement
2066 # Because mOutputType is OT_WIKI, this will only process {{subst:xxx}} type tags
2067 $text = $this->replaceVariables( $text );
2071 $n = $user->getName();
2072 $k = $user->getOption( "nickname" );
2073 if ( "" == $k ) { $k = $n; }
2074 if(isset($wgLocaltimezone)) {
2075 $oldtz = getenv("TZ"); putenv("TZ=$wgLocaltimezone");
2077 /* Note: this is an ugly timezone hack for the European wikis */
2078 $d = $wgLang->timeanddate( date( "YmdHis" ), false ) .
2079 " (" . date( "T" ) . ")";
2080 if(isset($wgLocaltimezone)) putenv("TZ=$oldtz");
2082 $text = preg_replace( "/~~~~~/", $d, $text );
2083 $text = preg_replace( "/~~~~/", "[[" . $wgLang->getNsText(
2084 Namespace::getUser() ) . ":$n|$k]] $d", $text );
2085 $text = preg_replace( "/~~~/", "[[" . $wgLang->getNsText(
2086 Namespace::getUser() ) . ":$n|$k]]", $text );
2088 # Context links: [[|name]] and [[name (context)|]]
2090 $tc = "[&;%\\-,.\\(\\)' _0-9A-Za-z\\/:\\x80-\\xff]";
2091 $np = "[&;%\\-,.' _0-9A-Za-z\\/:\\x80-\\xff]"; # No parens
2092 $namespacechar = '[ _0-9A-Za-z\x80-\xff]'; # Namespaces can use non-ascii!
2093 $conpat = "/^({$np}+) \\(({$tc}+)\\)$/";
2095 $p1 = "/\[\[({$np}+) \\(({$np}+)\\)\\|]]/"; # [[page (context)|]]
2096 $p2 = "/\[\[\\|({$tc}+)]]/"; # [[|page]]
2097 $p3 = "/\[\[($namespacechar+):({$np}+)\\|]]/"; # [[namespace:page|]]
2098 $p4 = "/\[\[($namespacechar+):({$np}+) \\(({$np}+)\\)\\|]]/";
2099 # [[ns:page (cont)|]]
2101 $t = $this->mTitle
->getText();
2102 if ( preg_match( $conpat, $t, $m ) ) {
2105 $text = preg_replace( $p4, "[[\\1:\\2 (\\3)|\\2]]", $text );
2106 $text = preg_replace( $p1, "[[\\1 (\\2)|\\1]]", $text );
2107 $text = preg_replace( $p3, "[[\\1:\\2|\\2]]", $text );
2109 if ( "" == $context ) {
2110 $text = preg_replace( $p2, "[[\\1]]", $text );
2112 $text = preg_replace( $p2, "[[\\1 ({$context})|\\1]]", $text );
2116 $mw =& MagicWord::get( MAG_SUBST );
2117 $wgCurParser = $this->fork();
2118 $text = $mw->substituteCallback( $text, "wfBraceSubstitution" );
2119 $this->merge( $wgCurParser );
2122 # Trim trailing whitespace
2123 # MAG_END (__END__) tag allows for trailing
2124 # whitespace to be deliberately included
2125 $text = rtrim( $text );
2126 $mw =& MagicWord
::get( MAG_END
);
2127 $mw->matchAndRemove( $text );
2132 # Set up some variables which are usually set up in parse()
2133 # so that an external function can call some class members with confidence
2134 function startExternalParse( &$title, $options, $outputType, $clearState = true )
2136 $this->mTitle
=& $title;
2137 $this->mOptions
= $options;
2138 $this->mOutputType
= $outputType;
2139 if ( $clearState ) {
2140 $this->clearState();
2144 function transformMsg( $text, $options ) {
2146 static $executing = false;
2148 # Guard against infinite recursion
2154 $this->mTitle
= $wgTitle;
2155 $this->mOptions
= $options;
2156 $this->mOutputType
= OT_MSG
;
2157 $this->clearState();
2158 $text = $this->replaceVariables( $text );
2167 var $mText, $mLanguageLinks, $mCategoryLinks, $mContainsOldMagic;
2169 function ParserOutput( $text = "", $languageLinks = array(), $categoryLinks = array(),
2170 $containsOldMagic = false )
2172 $this->mText
= $text;
2173 $this->mLanguageLinks
= $languageLinks;
2174 $this->mCategoryLinks
= $categoryLinks;
2175 $this->mContainsOldMagic
= $containsOldMagic;
2178 function getText() { return $this->mText
; }
2179 function getLanguageLinks() { return $this->mLanguageLinks
; }
2180 function getCategoryLinks() { return $this->mCategoryLinks
; }
2181 function containsOldMagic() { return $this->mContainsOldMagic
; }
2182 function setText( $text ) { return wfSetVar( $this->mText
, $text ); }
2183 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks
, $ll ); }
2184 function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategoryLinks
, $cl ); }
2185 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic
, $com ); }
2187 function merge( $other ) {
2188 $this->mLanguageLinks
= array_merge( $this->mLanguageLinks
, $other->mLanguageLinks
);
2189 $this->mCategoryLinks
= array_merge( $this->mCategoryLinks
, $this->mLanguageLinks
);
2190 $this->mContainsOldMagic
= $this->mContainsOldMagic ||
$other->mContainsOldMagic
;
2197 # All variables are private
2198 var $mUseTeX; # Use texvc to expand <math> tags
2199 var $mUseCategoryMagic; # Treat [[Category:xxxx]] tags specially
2200 var $mUseDynamicDates; # Use $wgDateFormatter to format dates
2201 var $mInterwikiMagic; # Interlanguage links are removed and returned in an array
2202 var $mAllowExternalImages; # Allow external images inline
2203 var $mSkin; # Reference to the preferred skin
2204 var $mDateFormat; # Date format index
2205 var $mEditSection; # Create "edit section" links
2206 var $mEditSectionOnRightClick; # Generate JavaScript to edit section on right click
2207 var $mNumberHeadings; # Automatically number headings
2208 var $mShowToc; # Show table of contents
2210 function getUseTeX() { return $this->mUseTeX
; }
2211 function getUseCategoryMagic() { return $this->mUseCategoryMagic
; }
2212 function getUseDynamicDates() { return $this->mUseDynamicDates
; }
2213 function getInterwikiMagic() { return $this->mInterwikiMagic
; }
2214 function getAllowExternalImages() { return $this->mAllowExternalImages
; }
2215 function getSkin() { return $this->mSkin
; }
2216 function getDateFormat() { return $this->mDateFormat
; }
2217 function getEditSection() { return $this->mEditSection
; }
2218 function getEditSectionOnRightClick() { return $this->mEditSectionOnRightClick
; }
2219 function getNumberHeadings() { return $this->mNumberHeadings
; }
2220 function getShowToc() { return $this->mShowToc
; }
2222 function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX
, $x ); }
2223 function setUseCategoryMagic( $x ) { return wfSetVar( $this->mUseCategoryMagic
, $x ); }
2224 function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates
, $x ); }
2225 function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic
, $x ); }
2226 function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages
, $x ); }
2227 function setSkin( $x ) { return wfSetRef( $this->mSkin
, $x ); }
2228 function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat
, $x ); }
2229 function setEditSection( $x ) { return wfSetVar( $this->mEditSection
, $x ); }
2230 function setEditSectionOnRightClick( $x ) { return wfSetVar( $this->mEditSectionOnRightClick
, $x ); }
2231 function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings
, $x ); }
2232 function setShowToc( $x ) { return wfSetVar( $this->mShowToc
, $x ); }
2234 /* static */ function newFromUser( &$user )
2236 $popts = new ParserOptions
;
2237 $popts->initialiseFromUser( $user );
2241 function initialiseFromUser( &$userInput )
2243 global $wgUseTeX, $wgUseCategoryMagic, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
2245 if ( !$userInput ) {
2247 $user->setLoaded( true );
2249 $user =& $userInput;
2252 $this->mUseTeX
= $wgUseTeX;
2253 $this->mUseCategoryMagic
= $wgUseCategoryMagic;
2254 $this->mUseDynamicDates
= $wgUseDynamicDates;
2255 $this->mInterwikiMagic
= $wgInterwikiMagic;
2256 $this->mAllowExternalImages
= $wgAllowExternalImages;
2257 $this->mSkin
=& $user->getSkin();
2258 $this->mDateFormat
= $user->getOption( "date" );
2259 $this->mEditSection
= $user->getOption( "editsection" );
2260 $this->mEditSectionOnRightClick
= $user->getOption( "editsectiononrightclick" );
2261 $this->mNumberHeadings
= $user->getOption( "numberheadings" );
2262 $this->mShowToc
= $user->getOption( "showtoc" );
2268 # Regex callbacks, used in Parser::replaceVariables
2269 function wfBraceSubstitution( $matches )
2271 global $wgCurParser;
2272 return $wgCurParser->braceSubstitution( $matches );
2275 function wfArgSubstitution( $matches )
2277 global $wgCurParser;
2278 return $wgCurParser->argSubstitution( $matches );