make doBlockLevels last parser stage again, and fix missing paragraphs from
[lhc/web/wiklou.git] / includes / Parser.php
1 <?php
2
3 include_once('Tokenizer.php');
4
5 if( $GLOBALS['wgUseWikiHiero'] ){
6 include_once('wikihiero.php');
7 }
8
9 # PHP Parser
10 #
11 # Processes wiki markup
12 #
13 # There are two main entry points into the Parser class: parse() and preSaveTransform().
14 # The parse() function produces HTML output, preSaveTransform() produces altered wiki markup.
15 #
16 # Globals used:
17 # objects: $wgLang, $wgDateFormatter, $wgLinkCache, $wgCurParser
18 #
19 # NOT $wgArticle, $wgUser or $wgTitle. Keep them away!
20 #
21 # settings: $wgUseTex*, $wgUseCategoryMagic*, $wgUseDynamicDates*, $wgInterwikiMagic*,
22 # $wgNamespacesWithSubpages, $wgLanguageCode, $wgAllowExternalImages*,
23 # $wgLocaltimezone
24 #
25 # * only within ParserOptions
26 #
27 #
28 #----------------------------------------
29 # Variable substitution O(N^2) attack
30 #-----------------------------------------
31 # Without countermeasures, it would be possible to attack the parser by saving a page
32 # filled with a large number of inclusions of large pages. The size of the generated
33 # page would be proportional to the square of the input size. Hence, we limit the number
34 # of inclusions of any given page, thus bringing any attack back to O(N).
35 #
36 define( "MAX_INCLUDE_REPEAT", 5 );
37
38 # Recursion depth of variable/inclusion evaluation
39 define( "MAX_INCLUDE_PASSES", 3 );
40
41 # Allowed values for $mOutputType
42 define( "OT_HTML", 1 );
43 define( "OT_WIKI", 2 );
44 define( "OT_MSG", 3 );
45
46 # prefix for escaping, used in two functions at least
47 define( "UNIQ_PREFIX", "NaodW29");
48
49 class Parser
50 {
51 # Cleared with clearState():
52 var $mOutput, $mAutonumber, $mLastSection, $mDTopen, $mStripState = array();
53 var $mVariables, $mIncludeCount;
54
55 # Temporary:
56 var $mOptions, $mTitle, $mOutputType;
57
58 function Parser()
59 {
60 $this->clearState();
61 }
62
63 function clearState()
64 {
65 $this->mOutput = new ParserOutput;
66 $this->mAutonumber = 0;
67 $this->mLastSection = "";
68 $this->mDTopen = false;
69 $this->mVariables = false;
70 $this->mIncludeCount = array();
71 $this->mStripState = array();
72 }
73
74 # First pass--just handle <nowiki> sections, pass the rest off
75 # to doWikiPass2() which does all the real work.
76 #
77 # Returns a ParserOutput
78 #
79 function parse( $text, &$title, $options, $linestart = true, $clearState = true )
80 {
81 $fname = "Parser::parse";
82 wfProfileIn( $fname );
83
84 if ( $clearState ) {
85 $this->clearState();
86 }
87
88 $this->mOptions = $options;
89 $this->mTitle =& $title;
90 $this->mOutputType = OT_HTML;
91
92 $stripState = NULL;
93 $text = $this->strip( $text, $this->mStripState );
94 $text = $this->doWikiPass2( $text, $linestart );
95 $text = $this->unstrip( $text, $this->mStripState );
96
97 $this->mOutput->setText( $text );
98 wfProfileOut( $fname );
99 return $this->mOutput;
100 }
101
102 /* static */ function getRandomString()
103 {
104 return dechex(mt_rand(0, 0x7fffffff)) . dechex(mt_rand(0, 0x7fffffff));
105 }
106
107 # Replaces all occurences of <$tag>content</$tag> in the text
108 # with a random marker and returns the new text. the output parameter
109 # $content will be an associative array filled with data on the form
110 # $unique_marker => content.
111
112 /* static */ function extractTags($tag, $text, &$content, $uniq_prefix = ""){
113 $result = array();
114 $rnd = $uniq_prefix . '-' . $tag . Parser::getRandomString();
115 $content = array( );
116 $n = 1;
117 $stripped = "";
118
119 while ( "" != $text ) {
120 $p = preg_split( "/<\\s*$tag\\s*>/i", $text, 2 );
121 $stripped .= $p[0];
122 if ( ( count( $p ) < 2 ) || ( "" == $p[1] ) ) {
123 $text = "";
124 } else {
125 $q = preg_split( "/<\\/\\s*$tag\\s*>/i", $p[1], 2 );
126 $marker = $rnd . sprintf("%08X", $n++);
127 $content[$marker] = $q[0];
128 $stripped .= $marker;
129 $text = $q[1];
130 }
131 }
132 return $stripped;
133 }
134
135 # Strips <nowiki>, <pre> and <math>
136 # Returns the text, and fills an array with data needed in unstrip()
137 #
138 function strip( $text, &$state )
139 {
140 $render = ($this->mOutputType == OT_HTML);
141 $nowiki_content = array();
142 $hiero_content = array();
143 $math_content = array();
144 $pre_content = array();
145
146 # Replace any instances of the placeholders
147 $uniq_prefix = UNIQ_PREFIX;
148 $text = str_replace( $uniq_prefix, wfHtmlEscapeFirst( $uniq_prefix ), $text );
149
150 $text = Parser::extractTags("nowiki", $text, $nowiki_content, $uniq_prefix);
151 foreach( $nowiki_content as $marker => $content ){
152 if( $render ){
153 $nowiki_content[$marker] = wfEscapeHTMLTagsOnly( $content );
154 } else {
155 $nowiki_content[$marker] = "<nowiki>$content</nowiki>";
156 }
157 }
158
159 if( $GLOBALS['wgUseWikiHiero'] ){
160 $text = Parser::extractTags("hiero", $text, $hiero_content, $uniq_prefix);
161 foreach( $hiero_content as $marker => $content ){
162 if( $render ){
163 $hiero_content[$marker] = WikiHiero( $content, WH_MODE_HTML);
164 } else {
165 $hiero_content[$marker] = "<hiero>$content</hiero>";
166 }
167 }
168 }
169
170 if( $this->mOptions->getUseTeX() ){
171 $text = Parser::extractTags("math", $text, $math_content, $uniq_prefix);
172 foreach( $math_content as $marker => $content ){
173 if( $render ){
174 $math_content[$marker] = renderMath( $content );
175 } else {
176 $math_content[$marker] = "<math>$content</math>";
177 }
178 }
179 }
180
181 $text = Parser::extractTags("pre", $text, $pre_content, $uniq_prefix);
182 foreach( $pre_content as $marker => $content ){
183 if( $render ){
184 $pre_content[$marker] = "<pre>" . wfEscapeHTMLTagsOnly( $content ) . "</pre>";
185 } else {
186 $pre_content[$marker] = "<pre>$content</pre>";
187 }
188 }
189
190 # Must expand in reverse order, otherwise nested tags will be corrupted
191 $state = array( $pre_content, $math_content, $hiero_content, $nowiki_content );
192 return $text;
193 }
194
195 function unstrip( $text, &$state )
196 {
197 foreach( $state as $content_dict ){
198 foreach( $content_dict as $marker => $content ){
199 $text = str_replace( $marker, $content, $text );
200 }
201 }
202 return $text;
203 }
204
205 function categoryMagic ()
206 {
207 global $wgLang , $wgUser ;
208 if ( !$this->mOptions->getUseCategoryMagic() ) return ;
209 $id = $this->mTitle->getArticleID() ;
210 $cat = $wgLang->ucfirst ( wfMsg ( "category" ) ) ;
211 $ti = $this->mTitle->getText() ;
212 $ti = explode ( ":" , $ti , 2 ) ;
213 if ( $cat != $ti[0] ) return "" ;
214 $r = "<br break='all' />\n" ;
215
216 $articles = array() ;
217 $parents = array () ;
218 $children = array() ;
219
220
221 # $sk =& $this->mGetSkin();
222 $sk =& $wgUser->getSkin() ;
223
224 $data = array () ;
225 $sql1 = "SELECT DISTINCT cur_title,cur_namespace FROM cur,links WHERE l_to={$id} AND l_from=cur_id";
226 $sql2 = "SELECT DISTINCT cur_title,cur_namespace FROM cur,brokenlinks WHERE bl_to={$id} AND bl_from=cur_id" ;
227
228 $res = wfQuery ( $sql1, DB_READ ) ;
229 while ( $x = wfFetchObject ( $res ) ) $data[] = $x ;
230
231 $res = wfQuery ( $sql2, DB_READ ) ;
232 while ( $x = wfFetchObject ( $res ) ) $data[] = $x ;
233
234
235 foreach ( $data AS $x )
236 {
237 $t = $wgLang->getNsText ( $x->cur_namespace ) ;
238 if ( $t != "" ) $t .= ":" ;
239 $t .= $x->cur_title ;
240
241 $y = explode ( ":" , $t , 2 ) ;
242 if ( count ( $y ) == 2 && $y[0] == $cat ) {
243 array_push ( $children , $sk->makeLink ( $t , $y[1] ) ) ;
244 } else {
245 array_push ( $articles , $sk->makeLink ( $t ) ) ;
246 }
247 }
248 wfFreeResult ( $res ) ;
249
250 # Children
251 if ( count ( $children ) > 0 )
252 {
253 asort ( $children ) ;
254 $r .= "<h2>".wfMsg("subcategories")."</h2>\n" ;
255 $r .= implode ( ", " , $children ) ;
256 }
257
258 # Articles
259 if ( count ( $articles ) > 0 )
260 {
261 asort ( $articles ) ;
262 $h = wfMsg( "category_header", $ti[1] );
263 $r .= "<h2>{$h}</h2>\n" ;
264 $r .= implode ( ", " , $articles ) ;
265 }
266
267
268 return $r ;
269 }
270
271 function getHTMLattrs ()
272 {
273 $htmlattrs = array( # Allowed attributes--no scripting, etc.
274 "title", "align", "lang", "dir", "width", "height",
275 "bgcolor", "clear", /* BR */ "noshade", /* HR */
276 "cite", /* BLOCKQUOTE, Q */ "size", "face", "color",
277 /* FONT */ "type", "start", "value", "compact",
278 /* For various lists, mostly deprecated but safe */
279 "summary", "width", "border", "frame", "rules",
280 "cellspacing", "cellpadding", "valign", "char",
281 "charoff", "colgroup", "col", "span", "abbr", "axis",
282 "headers", "scope", "rowspan", "colspan", /* Tables */
283 "id", "class", "name", "style" /* For CSS */
284 );
285 return $htmlattrs ;
286 }
287
288 function fixTagAttributes ( $t )
289 {
290 if ( trim ( $t ) == "" ) return "" ; # Saves runtime ;-)
291 $htmlattrs = $this->getHTMLattrs() ;
292
293 # Strip non-approved attributes from the tag
294 $t = preg_replace(
295 "/(\\w+)(\\s*=\\s*([^\\s\">]+|\"[^\">]*\"))?/e",
296 "(in_array(strtolower(\"\$1\"),\$htmlattrs)?(\"\$1\".((\"x\$3\" != \"x\")?\"=\$3\":'')):'')",
297 $t);
298 # Strip javascript "expression" from stylesheets. Brute force approach:
299 # If anythin offensive is found, all attributes of the HTML tag are dropped
300
301 if( preg_match(
302 "/style\\s*=.*(expression|tps*:\/\/|url\\s*\().*/is",
303 wfMungeToUtf8( $t ) ) )
304 {
305 $t="";
306 }
307
308 return trim ( $t ) ;
309 }
310
311 function doTableStuff ( $t )
312 {
313 $t = explode ( "\n" , $t ) ;
314 $td = array () ; # Is currently a td tag open?
315 $ltd = array () ; # Was it TD or TH?
316 $tr = array () ; # Is currently a tr tag open?
317 $ltr = array () ; # tr attributes
318 foreach ( $t AS $k => $x )
319 {
320 $x = rtrim ( $x ) ;
321 $fc = substr ( $x , 0 , 1 ) ;
322 if ( "{|" == substr ( $x , 0 , 2 ) )
323 {
324 $t[$k] = "\n<table " . $this->fixTagAttributes ( substr ( $x , 3 ) ) . ">" ;
325 array_push ( $td , false ) ;
326 array_push ( $ltd , "" ) ;
327 array_push ( $tr , false ) ;
328 array_push ( $ltr , "" ) ;
329 }
330 else if ( count ( $td ) == 0 ) { } # Don't do any of the following
331 else if ( "|}" == substr ( $x , 0 , 2 ) )
332 {
333 $z = "</table>\n" ;
334 $l = array_pop ( $ltd ) ;
335 if ( array_pop ( $tr ) ) $z = "</tr>" . $z ;
336 if ( array_pop ( $td ) ) $z = "</{$l}>" . $z ;
337 array_pop ( $ltr ) ;
338 $t[$k] = $z ;
339 }
340 /* else if ( "|_" == substr ( $x , 0 , 2 ) ) # Caption
341 {
342 $z = trim ( substr ( $x , 2 ) ) ;
343 $t[$k] = "<caption>{$z}</caption>\n" ;
344 }*/
345 else if ( "|-" == substr ( $x , 0 , 2 ) ) # Allows for |---------------
346 {
347 $x = substr ( $x , 1 ) ;
348 while ( $x != "" && substr ( $x , 0 , 1 ) == '-' ) $x = substr ( $x , 1 ) ;
349 $z = "" ;
350 $l = array_pop ( $ltd ) ;
351 if ( array_pop ( $tr ) ) $z = "</tr>" . $z ;
352 if ( array_pop ( $td ) ) $z = "</{$l}>" . $z ;
353 array_pop ( $ltr ) ;
354 $t[$k] = $z ;
355 array_push ( $tr , false ) ;
356 array_push ( $td , false ) ;
357 array_push ( $ltd , "" ) ;
358 array_push ( $ltr , $this->fixTagAttributes ( $x ) ) ;
359 }
360 else if ( "|" == $fc || "!" == $fc || "|+" == substr ( $x , 0 , 2 ) ) # Caption
361 {
362 if ( "|+" == substr ( $x , 0 , 2 ) )
363 {
364 $fc = "+" ;
365 $x = substr ( $x , 1 ) ;
366 }
367 $after = substr ( $x , 1 ) ;
368 if ( $fc == "!" ) $after = str_replace ( "!!" , "||" , $after ) ;
369 $after = explode ( "||" , $after ) ;
370 $t[$k] = "" ;
371 foreach ( $after AS $theline )
372 {
373 $z = "" ;
374 if ( $fc != "+" )
375 {
376 $tra = array_pop ( $ltr ) ;
377 if ( !array_pop ( $tr ) ) $z = "<tr {$tra}>\n" ;
378 array_push ( $tr , true ) ;
379 array_push ( $ltr , "" ) ;
380 }
381
382 $l = array_pop ( $ltd ) ;
383 if ( array_pop ( $td ) ) $z = "</{$l}>" . $z ;
384 if ( $fc == "|" ) $l = "td" ;
385 else if ( $fc == "!" ) $l = "th" ;
386 else if ( $fc == "+" ) $l = "caption" ;
387 else $l = "" ;
388 array_push ( $ltd , $l ) ;
389 $y = explode ( "|" , $theline , 2 ) ;
390 if ( count ( $y ) == 1 ) $y = "{$z}<{$l}>{$y[0]}" ;
391 else $y = $y = "{$z}<{$l} ".$this->fixTagAttributes($y[0]).">{$y[1]}" ;
392 $t[$k] .= $y ;
393 array_push ( $td , true ) ;
394 }
395 }
396 }
397
398 # Closing open td, tr && table
399 while ( count ( $td ) > 0 )
400 {
401 if ( array_pop ( $td ) ) $t[] = "</td>" ;
402 if ( array_pop ( $tr ) ) $t[] = "</tr>" ;
403 $t[] = "</table>" ;
404 }
405
406 $t = implode ( "\n" , $t ) ;
407 # $t = $this->removeHTMLtags( $t );
408 return $t ;
409 }
410
411 # Well, OK, it's actually about 14 passes. But since all the
412 # hard lifting is done inside PHP's regex code, it probably
413 # wouldn't speed things up much to add a real parser.
414 #
415 function doWikiPass2( $text, $linestart )
416 {
417 $fname = "Parser::doWikiPass2";
418 wfProfileIn( $fname );
419
420 $text = $this->removeHTMLtags( $text );
421 $text = $this->replaceVariables( $text );
422
423 # $text = preg_replace( "/(^|\n)-----*/", "\\1<hr>", $text );
424
425 $text = $this->doHeadings( $text );
426
427 if($this->mOptions->getUseDynamicDates()) {
428 global $wgDateFormatter;
429 $text = $wgDateFormatter->reformat( $this->mOptions->getDateFormat(), $text );
430 }
431
432 $text = $this->replaceExternalLinks( $text );
433 $text = $this->doTokenizedParser ( $text );
434
435 $text = $this->doTableStuff ( $text ) ;
436
437 $text = $this->formatHeadings( $text );
438
439 $sk =& $this->mOptions->getSkin();
440 $text = $sk->transformContent( $text );
441 $fixtags = array(
442 "/<hr *>/i" => '<hr/>',
443 "/<br *>/i" => '<br/>',
444 "/<center *>/i"=>'<span style="text-align:center;">',
445 "/<\\/center *>/i" => '</span>'
446 );
447 $text = preg_replace( array_keys($fixtags), array_values($fixtags), $text );
448
449 # needs to be called last
450 $text = $this->doBlockLevels( $text, $linestart );
451 $text .= $this->categoryMagic () ;
452
453 wfProfileOut( $fname );
454 return $text;
455 }
456
457
458 /* private */ function doHeadings( $text )
459 {
460 for ( $i = 6; $i >= 1; --$i ) {
461 $h = substr( "======", 0, $i );
462 $text = preg_replace( "/^{$h}(.+){$h}(\\s|$)/m",
463 "<h{$i}>\\1</h{$i}>\\2", $text );
464 }
465 return $text;
466 }
467
468 # Note: we have to do external links before the internal ones,
469 # and otherwise take great care in the order of things here, so
470 # that we don't end up interpreting some URLs twice.
471
472 /* private */ function replaceExternalLinks( $text )
473 {
474 $fname = "Parser::replaceExternalLinks";
475 wfProfileIn( $fname );
476 $text = $this->subReplaceExternalLinks( $text, "http", true );
477 $text = $this->subReplaceExternalLinks( $text, "https", true );
478 $text = $this->subReplaceExternalLinks( $text, "ftp", false );
479 $text = $this->subReplaceExternalLinks( $text, "irc", false );
480 $text = $this->subReplaceExternalLinks( $text, "gopher", false );
481 $text = $this->subReplaceExternalLinks( $text, "news", false );
482 $text = $this->subReplaceExternalLinks( $text, "mailto", false );
483 wfProfileOut( $fname );
484 return $text;
485 }
486
487 /* private */ function subReplaceExternalLinks( $s, $protocol, $autonumber )
488 {
489 $unique = "4jzAfzB8hNvf4sqyO9Edd8pSmk9rE2in0Tgw3";
490 $uc = "A-Za-z0-9_\\/~%\\-+&*#?!=()@\\x80-\\xFF";
491
492 # this is the list of separators that should be ignored if they
493 # are the last character of an URL but that should be included
494 # if they occur within the URL, e.g. "go to www.foo.com, where .."
495 # in this case, the last comma should not become part of the URL,
496 # but in "www.foo.com/123,2342,32.htm" it should.
497 $sep = ",;\.:";
498 $fnc = "A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF";
499 $images = "gif|png|jpg|jpeg";
500
501 # PLEASE NOTE: The curly braces { } are not part of the regex,
502 # they are interpreted as part of the string (used to tell PHP
503 # that the content of the string should be inserted there).
504 $e1 = "/(^|[^\\[])({$protocol}:)([{$uc}{$sep}]+)\\/([{$fnc}]+)\\." .
505 "((?i){$images})([^{$uc}]|$)/";
506
507 $e2 = "/(^|[^\\[])({$protocol}:)(([".$uc."]|[".$sep."][".$uc."])+)([^". $uc . $sep. "]|[".$sep."]|$)/";
508 $sk =& $this->mOptions->getSkin();
509
510 if ( $autonumber and $this->mOptions->getAllowExternalImages() ) { # Use img tags only for HTTP urls
511 $s = preg_replace( $e1, "\\1" . $sk->makeImage( "{$unique}:\\3" .
512 "/\\4.\\5", "\\4.\\5" ) . "\\6", $s );
513 }
514 $s = preg_replace( $e2, "\\1" . "<a href=\"{$unique}:\\3\"" .
515 $sk->getExternalLinkAttributes( "{$unique}:\\3", wfEscapeHTML(
516 "{$unique}:\\3" ) ) . ">" . wfEscapeHTML( "{$unique}:\\3" ) .
517 "</a>\\5", $s );
518 $s = str_replace( $unique, $protocol, $s );
519
520 $a = explode( "[{$protocol}:", " " . $s );
521 $s = array_shift( $a );
522 $s = substr( $s, 1 );
523
524 $e1 = "/^([{$uc}"."{$sep}]+)](.*)\$/sD";
525 $e2 = "/^([{$uc}"."{$sep}]+)\\s+([^\\]]+)](.*)\$/sD";
526
527 foreach ( $a as $line ) {
528 if ( preg_match( $e1, $line, $m ) ) {
529 $link = "{$protocol}:{$m[1]}";
530 $trail = $m[2];
531 if ( $autonumber ) { $text = "[" . ++$this->mAutonumber . "]"; }
532 else { $text = wfEscapeHTML( $link ); }
533 } else if ( preg_match( $e2, $line, $m ) ) {
534 $link = "{$protocol}:{$m[1]}";
535 $text = $m[2];
536 $trail = $m[3];
537 } else {
538 $s .= "[{$protocol}:" . $line;
539 continue;
540 }
541 if( $link == $text || preg_match( "!$protocol://" . preg_quote( $text, "/" ) . "/?$!", $link ) ) {
542 $paren = "";
543 } else {
544 # Expand the URL for printable version
545 $paren = "<span class='urlexpansion'> (<i>" . htmlspecialchars ( $link ) . "</i>)</span>";
546 }
547 $la = $sk->getExternalLinkAttributes( $link, $text );
548 $s .= "<a href='{$link}'{$la}>{$text}</a>{$paren}{$trail}";
549
550 }
551 return $s;
552 }
553
554 /* private */ function handle3Quotes( &$state, $token )
555 {
556 if ( $state["strong"] !== false ) {
557 if ( $state["em"] !== false && $state["em"] > $state["strong"] )
558 {
559 # ''' lala ''lala '''
560 $s = "</em></strong><em>";
561 } else {
562 $s = "</strong>";
563 }
564 $state["strong"] = FALSE;
565 } else {
566 $s = "<strong>";
567 $state["strong"] = $token["pos"];
568 }
569 return $s;
570 }
571
572 /* private */ function handle2Quotes( &$state, $token )
573 {
574 if ( $state["em"] !== false ) {
575 if ( $state["strong"] !== false && $state["strong"] > $state["em"] )
576 {
577 # ''lala'''lala'' ....'''
578 $s = "</strong></em><strong>";
579 } else {
580 $s = "</em>";
581 }
582 $state["em"] = FALSE;
583 } else {
584 $s = "<em>";
585 $state["em"] = $token["pos"];
586 }
587 return $s;
588 }
589
590 /* private */ function handle5Quotes( &$state, $token )
591 {
592 $s = "";
593 if ( $state["em"] !== false && $state["strong"] ) {
594 if ( $state["em"] < $state["strong"] ) {
595 $s .= "</strong></em>";
596 } else {
597 $s .= "</em></strong>";
598 }
599 $state["strong"] = $state["em"] = FALSE;
600 } elseif ( $state["em"] !== false ) {
601 $s .= "</em><strong>";
602 $state["em"] = FALSE;
603 $state["strong"] = $token["pos"];
604 } elseif ( $state["strong"] !== false ) {
605 $s .= "</strong><em>";
606 $state["strong"] = FALSE;
607 $state["em"] = $token["pos"];
608 } else { # not $em and not $strong
609 $s .= "<strong><em>";
610 $state["strong"] = $state["em"] = $token["pos"];
611 }
612 return $s;
613 }
614
615 /* private */ function doTokenizedParser( $str )
616 {
617 global $wgLang; # for language specific parser hook
618
619 $tokenizer=Tokenizer::newFromString( $str );
620 $tokenStack = array();
621
622 $s="";
623 $state["em"] = FALSE;
624 $state["strong"] = FALSE;
625 $tagIsOpen = FALSE;
626 $threeopen = false;
627
628 # The tokenizer splits the text into tokens and returns them one by one.
629 # Every call to the tokenizer returns a new token.
630 while ( $token = $tokenizer->nextToken() )
631 {
632 switch ( $token["type"] )
633 {
634 case "text":
635 # simple text with no further markup
636 $txt = $token["text"];
637 break;
638 case "[[[":
639 # remember the tag opened with 3 [
640 $threeopen = true;
641 case "[[":
642 # link opening tag.
643 # FIXME : Treat orphaned open tags (stack not empty when text is over)
644 $tagIsOpen = TRUE;
645 array_push( $tokenStack, $token );
646 $txt="";
647 break;
648
649 case "]]]":
650 case "]]":
651 # link close tag.
652 # get text from stack, glue it together, and call the code to handle a
653 # link
654
655 if ( count( $tokenStack ) == 0 )
656 {
657 # stack empty. Found a ]] without an opening [[
658 $txt = "]]";
659 } else {
660 $linkText = "";
661 $lastToken = array_pop( $tokenStack );
662 while ( !(($lastToken["type"] == "[[[") or ($lastToken["type"] == "[[")) )
663 {
664 if( !empty( $lastToken["text"] ) ) {
665 $linkText = $lastToken["text"] . $linkText;
666 }
667 $lastToken = array_pop( $tokenStack );
668 }
669
670 $txt = $linkText ."]]";
671
672 if( isset( $lastToken["text"] ) ) {
673 $prefix = $lastToken["text"];
674 } else {
675 $prefix = "";
676 }
677 $nextToken = $tokenizer->previewToken();
678 if ( $nextToken["type"] == "text" )
679 {
680 # Preview just looks at it. Now we have to fetch it.
681 $nextToken = $tokenizer->nextToken();
682 $txt .= $nextToken["text"];
683 }
684 $fakestate = $this->mStripState;
685 $txt = $this->handleInternalLink( $this->unstrip($txt,$fakestate), $prefix );
686
687 # did the tag start with 3 [ ?
688 if($threeopen) {
689 # show the first as text
690 $txt = "[".$txt;
691 $threeopen=false;
692 }
693
694 }
695 $tagIsOpen = (count( $tokenStack ) != 0);
696 break;
697 case "----":
698 $txt = "\n<hr />\n";
699 break;
700 case "'''":
701 # This and the three next ones handle quotes
702 $txt = $this->handle3Quotes( $state, $token );
703 break;
704 case "''":
705 $txt = $this->handle2Quotes( $state, $token );
706 break;
707 case "'''''":
708 $txt = $this->handle5Quotes( $state, $token );
709 break;
710 case "":
711 # empty token
712 $txt="";
713 break;
714 case "RFC ":
715 if ( $tagIsOpen ) {
716 $txt = "RFC ";
717 } else {
718 $txt = $this->doMagicRFC( $tokenizer );
719 }
720 break;
721 case "ISBN ":
722 if ( $tagIsOpen ) {
723 $txt = "ISBN ";
724 } else {
725 $txt = $this->doMagicISBN( $tokenizer );
726 }
727 break;
728 default:
729 # Call language specific Hook.
730 $txt = $wgLang->processToken( $token, $tokenStack );
731 if ( NULL == $txt ) {
732 # An unkown token. Highlight.
733 $txt = "<font color=\"#FF0000\"><b>".$token["type"]."</b></font>";
734 $txt .= "<font color=\"#FFFF00\"><b>".$token["text"]."</b></font>";
735 }
736 break;
737 }
738 # If we're parsing the interior of a link, don't append the interior to $s,
739 # but push it to the stack so it can be processed when a ]] token is found.
740 if ( $tagIsOpen && $txt != "" ) {
741 $token["type"] = "text";
742 $token["text"] = $txt;
743 array_push( $tokenStack, $token );
744 } else {
745 $s .= $txt;
746 }
747 } #end while
748 if ( count( $tokenStack ) != 0 )
749 {
750 # still objects on stack. opened [[ tag without closing ]] tag.
751 $txt = "";
752 while ( $lastToken = array_pop( $tokenStack ) )
753 {
754 if ( $lastToken["type"] == "text" )
755 {
756 $txt = $lastToken["text"] . $txt;
757 } else {
758 $txt = $lastToken["type"] . $txt;
759 }
760 }
761 $s .= $txt;
762 }
763 return $s;
764 }
765
766 /* private */ function handleInternalLink( $line, $prefix )
767 {
768 global $wgLang, $wgLinkCache;
769 global $wgNamespacesWithSubpages, $wgLanguageCode;
770 static $fname = "Parser::handleInternalLink" ;
771 wfProfileIn( $fname );
772
773 wfProfileIn( "$fname-setup" );
774 static $tc = FALSE;
775 if ( !$tc ) { $tc = Title::legalChars() . "#"; }
776 $sk =& $this->mOptions->getSkin();
777
778 # Match a link having the form [[namespace:link|alternate]]trail
779 static $e1 = FALSE;
780 if ( !$e1 ) { $e1 = "/^([{$tc}]+)(?:\\|([^]]+))?]](.*)\$/sD"; }
781 # Match the end of a line for a word that's not followed by whitespace,
782 # e.g. in the case of 'The Arab al[[Razi]]', 'al' will be matched
783 #$e2 = "/^(.*)\\b(\\w+)\$/suD";
784 #$e2 = "/^(.*\\s)(\\S+)\$/suD";
785 static $e2 = '/^(.*\s)([a-zA-Z\x80-\xff]+)$/sD';
786
787
788 # Special and Media are pseudo-namespaces; no pages actually exist in them
789 static $image = FALSE;
790 static $special = FALSE;
791 static $media = FALSE;
792 static $category = FALSE;
793 if ( !$image ) { $image = Namespace::getImage(); }
794 if ( !$special ) { $special = Namespace::getSpecial(); }
795 if ( !$media ) { $media = Namespace::getMedia(); }
796 if ( !$category ) { $category = wfMsg ( "category" ) ; }
797
798 $nottalk = !Namespace::isTalk( $this->mTitle->getNamespace() );
799
800 wfProfileOut( "$fname-setup" );
801 $s = "";
802
803 if ( preg_match( $e1, $line, $m ) ) { # page with normal text or alt
804 $text = $m[2];
805 $trail = $m[3];
806 } else { # Invalid form; output directly
807 $s .= $prefix . "[[" . $line ;
808 return $s;
809 }
810
811 /* Valid link forms:
812 Foobar -- normal
813 :Foobar -- override special treatment of prefix (images, language links)
814 /Foobar -- convert to CurrentPage/Foobar
815 /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text
816 */
817 $c = substr($m[1],0,1);
818 $noforce = ($c != ":");
819 if( $c == "/" ) { # subpage
820 if(substr($m[1],-1,1)=="/") { # / at end means we don't want the slash to be shown
821 $m[1]=substr($m[1],1,strlen($m[1])-2);
822 $noslash=$m[1];
823 } else {
824 $noslash=substr($m[1],1);
825 }
826 if($wgNamespacesWithSubpages[$this->mTitle->getNamespace()]) { # subpages allowed here
827 $link = $this->mTitle->getPrefixedText(). "/" . trim($noslash);
828 if( "" == $text ) {
829 $text= $m[1];
830 } # this might be changed for ugliness reasons
831 } else {
832 $link = $noslash; # no subpage allowed, use standard link
833 }
834 } elseif( $noforce ) { # no subpage
835 $link = $m[1];
836 } else {
837 $link = substr( $m[1], 1 );
838 }
839 if( "" == $text )
840 $text = $link;
841
842 $nt = Title::newFromText( $link );
843 if( !$nt ) {
844 $s .= $prefix . "[[" . $line;
845 return $s;
846 }
847 $ns = $nt->getNamespace();
848 $iw = $nt->getInterWiki();
849 if( $noforce ) {
850 if( $iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgLang->getLanguageName( $iw ) ) {
851 array_push( $this->mOutput->mLanguageLinks, $nt->getPrefixedText() );
852 return (trim($s) == '')? '': $s;
853 }
854 if( $ns == $image ) {
855 $s .= $prefix . $sk->makeImageLinkObj( $nt, $text ) . $trail;
856 $wgLinkCache->addImageLinkObj( $nt );
857 return $s;
858 }
859 }
860 if( ( $nt->getPrefixedText() == $this->mTitle->getPrefixedText() ) &&
861 ( strpos( $link, "#" ) == FALSE ) ) {
862 $s .= $prefix . "<strong>" . $text . "</strong>" . $trail;
863 return $s;
864 }
865
866 # Category feature
867 $catns = strtoupper ( $nt->getDBkey () ) ;
868 $catns = explode ( ":" , $catns ) ;
869 if ( count ( $catns ) > 1 ) $catns = array_shift ( $catns ) ;
870 else $catns = "" ;
871 if ( $catns == strtoupper($category) && $this->mOptions->getUseCategoryMagic() ) {
872 $t = explode ( ":" , $nt->getText() ) ;
873 array_shift ( $t ) ;
874 $t = implode ( ":" , $t ) ;
875 $t = $wgLang->ucFirst ( $t ) ;
876 $nnt = Title::newFromText ( $category.":".$t ) ;
877 $t = $sk->makeLinkObj( $nnt, $t, "", $trail , $prefix );
878 $this->mOutput->mCategoryLinks[] = $t ;
879 $s .= $prefix . $trail ;
880 return $s ;
881 }
882
883 if( $ns == $media ) {
884 $s .= $prefix . $sk->makeMediaLinkObj( $nt, $text ) . $trail;
885 $wgLinkCache->addImageLinkObj( $nt );
886 return $s;
887 } elseif( $ns == $special ) {
888 $s .= $prefix . $sk->makeKnownLinkObj( $nt, $text, "", $trail );
889 return $s;
890 }
891 $s .= $sk->makeLinkObj( $nt, $text, "", $trail , $prefix );
892
893 wfProfileOut( $fname );
894 return $s;
895 }
896
897 # Some functions here used by doBlockLevels()
898 #
899 /* private */ function closeParagraph()
900 {
901 $result = "";
902 if ( '' != $this->mLastSection ) {
903 $result = "</" . $this->mLastSection . ">";
904 }
905 $this->mLastSection = "";
906 return $result."\n";
907 }
908 # getCommon() returns the length of the longest common substring
909 # of both arguments, starting at the beginning of both.
910 #
911 /* private */ function getCommon( $st1, $st2 )
912 {
913 $fl = strlen( $st1 );
914 $shorter = strlen( $st2 );
915 if ( $fl < $shorter ) { $shorter = $fl; }
916
917 for ( $i = 0; $i < $shorter; ++$i ) {
918 if ( $st1{$i} != $st2{$i} ) { break; }
919 }
920 return $i;
921 }
922 # These next three functions open, continue, and close the list
923 # element appropriate to the prefix character passed into them.
924 #
925 /* private */ function openList( $char )
926 {
927 $result = $this->closeParagraph();
928
929 if ( "*" == $char ) { $result .= "<ul><li>"; }
930 else if ( "#" == $char ) { $result .= "<ol><li>"; }
931 else if ( ":" == $char ) { $result .= "<dl><dd>"; }
932 else if ( ";" == $char ) {
933 $result .= "<dl><dt>";
934 $this->mDTopen = true;
935 }
936 else { $result = "<!-- ERR 1 -->"; }
937
938 return $result;
939 }
940
941 /* private */ function nextItem( $char )
942 {
943 if ( "*" == $char || "#" == $char ) { return "</li><li>"; }
944 else if ( ":" == $char || ";" == $char ) {
945 $close = "</dd>";
946 if ( $this->mDTopen ) { $close = "</dt>"; }
947 if ( ";" == $char ) {
948 $this->mDTopen = true;
949 return $close . "<dt>";
950 } else {
951 $this->mDTopen = false;
952 return $close . "<dd>";
953 }
954 }
955 return "<!-- ERR 2 -->";
956 }
957
958 /* private */function closeList( $char )
959 {
960 if ( "*" == $char ) { $text = "</li></ul>"; }
961 else if ( "#" == $char ) { $text = "</li></ol>"; }
962 else if ( ":" == $char ) {
963 if ( $this->mDTopen ) {
964 $this->mDTopen = false;
965 $text = "</dt></dl>";
966 } else {
967 $text = "</dd></dl>";
968 }
969 }
970 else { return "<!-- ERR 3 -->"; }
971 return $text."\n";
972 }
973
974 /* private */ function doBlockLevels( $text, $linestart )
975 {
976 $fname = "Parser::doBlockLevels";
977 wfProfileIn( $fname );
978 # Parsing through the text line by line. The main thing
979 # happening here is handling of block-level elements p, pre,
980 # and making lists from lines starting with * # : etc.
981 #
982 $a = explode( "\n", $text );
983 $lastPref = $text = '';
984 $this->mDTopen = $inBlockElem = false;
985
986 if ( ! $linestart ) { $text .= array_shift( $a ); }
987 foreach ( $a as $t ) {
988 if ( "" != $text ) { $text .= "\n"; }
989
990 $oLine = $t;
991 $opl = strlen( $lastPref );
992 $npl = strspn( $t, "*#:;" );
993 $pref = substr( $t, 0, $npl );
994 $pref2 = str_replace( ";", ":", $pref );
995 $t = substr( $t, $npl );
996
997 if ( 0 != $npl && 0 == strcmp( $lastPref, $pref2 ) ) {
998 $text .= $this->nextItem( substr( $pref, -1 ) );
999
1000 if ( ";" == substr( $pref, -1 ) ) {
1001 $cpos = strpos( $t, ":" );
1002 if ( ! ( false === $cpos ) ) {
1003 $term = substr( $t, 0, $cpos );
1004 $text .= $term . $this->nextItem( ":" );
1005 $t = substr( $t, $cpos + 1 );
1006 }
1007 }
1008 } else if (0 != $npl || 0 != $opl) {
1009 $cpl = $this->getCommon( $pref, $lastPref );
1010
1011 while ( $cpl < $opl ) {
1012 $text .= $this->closeList( $lastPref{$opl-1} );
1013 --$opl;
1014 }
1015 if ( $npl <= $cpl && $cpl > 0 ) {
1016 $text .= $this->nextItem( $pref{$cpl-1} );
1017 }
1018 while ( $npl > $cpl ) {
1019 $char = substr( $pref, $cpl, 1 );
1020 $text .= $this->openList( $char );
1021
1022 if ( ";" == $char ) {
1023 $cpos = strpos( $t, ":" );
1024 if ( ! ( false === $cpos ) ) {
1025 $term = substr( $t, 0, $cpos );
1026 $text .= $term . $this->nextItem( ":" );
1027 $t = substr( $t, $cpos + 1 );
1028 }
1029 }
1030 ++$cpl;
1031 }
1032 $lastPref = $pref2;
1033 }
1034 if ( 0 == $npl ) { # No prefix--go to paragraph mode
1035 $uniq_prefix = UNIQ_PREFIX;
1036 $inBlockElem=false;
1037 if ( preg_match(
1038 "/(<table|<blockquote|<h1|<h2|<h3|<h4|<h5|<h6|<div)/i", $t ) ) {
1039 $text .= $this->closeParagraph();
1040 $inBlockElem = true;
1041 } else if ( preg_match("/(<hr|<\\/td|".$uniq_prefix."-pre)/i", $t ) ) {
1042 $text .= $this->closeParagraph();
1043 $inBlockElem = false;
1044 }
1045 if ( !$inBlockElem ) {
1046 if ( " " == $t{0} ) {
1047 $newSection = "pre";
1048 $text .= $this->closeParagraph();
1049 # $t = wfEscapeHTML( $t );
1050 }
1051 else { $newSection = "p"; }
1052
1053 if ( ( '' == trim( $oLine ) ) || ( $this->mLastSection == $newSection and $newSection != 'p' )) {
1054 $text .= $this->closeParagraph();
1055 $text .= "<" . $newSection . ">";
1056 $this->mLastSection = $newSection;
1057 }
1058 }
1059 if ( $inBlockElem &&
1060 preg_match( "/(<\\/table|<\\/blockquote|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|<\\/p<\\/div)/i", $t ) ) {
1061 $inBlockElem = false;
1062 }
1063 }
1064 $text .= $t;
1065 }
1066 while ( $npl ) {
1067 $text .= $this->closeList( $pref2{$npl-1} );
1068 --$npl;
1069 }
1070 if ( "" != $this->mLastSection ) {
1071 $text .= "</" . $this->mLastSection . ">";
1072 $this->mLastSection = "";
1073 }
1074 wfProfileOut( $fname );
1075 return $text;
1076 }
1077
1078 function getVariableValue( $index ) {
1079 global $wgLang, $wgSitename, $wgServer;
1080
1081 switch ( $index ) {
1082 case MAG_CURRENTMONTH:
1083 return date( "m" );
1084 case MAG_CURRENTMONTHNAME:
1085 return $wgLang->getMonthName( date("n") );
1086 case MAG_CURRENTMONTHNAMEGEN:
1087 return $wgLang->getMonthNameGen( date("n") );
1088 case MAG_CURRENTDAY:
1089 return date("j");
1090 case MAG_CURRENTDAYNAME:
1091 return $wgLang->getWeekdayName( date("w")+1 );
1092 case MAG_CURRENTYEAR:
1093 return date( "Y" );
1094 case MAG_CURRENTTIME:
1095 return $wgLang->time( wfTimestampNow(), false );
1096 case MAG_NUMBEROFARTICLES:
1097 return wfNumberOfArticles();
1098 case MAG_SITENAME:
1099 return $wgSitename;
1100 case MAG_SERVER:
1101 return $wgServer;
1102 default:
1103 return NULL;
1104 }
1105 }
1106
1107 function initialiseVariables()
1108 {
1109 global $wgVariableIDs;
1110 $this->mVariables = array();
1111 foreach ( $wgVariableIDs as $id ) {
1112 $mw =& MagicWord::get( $id );
1113 $mw->addToArray( $this->mVariables, $this->getVariableValue( $id ) );
1114 }
1115 }
1116
1117 /* private */ function replaceVariables( $text )
1118 {
1119 global $wgLang, $wgCurParser;
1120 global $wgScript, $wgArticlePath;
1121
1122 $fname = "Parser::replaceVariables";
1123 wfProfileIn( $fname );
1124
1125 $bail = false;
1126 if ( !$this->mVariables ) {
1127 $this->initialiseVariables();
1128 }
1129 $titleChars = Title::legalChars();
1130 $regex = "/{{([$titleChars\\|]*?)}}/s";
1131
1132 # "Recursive" variable expansion: run it through a couple of passes
1133 for ( $i=0; $i<MAX_INCLUDE_REPEAT && !$bail; $i++ ) {
1134 $oldText = $text;
1135
1136 # It's impossible to rebind a global in PHP
1137 # Instead, we run the substitution on a copy, then merge the changed fields back in
1138 $wgCurParser = $this->fork();
1139
1140 $text = preg_replace_callback( $regex, "wfBraceSubstitution", $text );
1141 if ( $oldText == $text ) {
1142 $bail = true;
1143 }
1144 $this->merge( $wgCurParser );
1145 }
1146
1147 return $text;
1148 }
1149
1150 # Returns a copy of this object except with various variables cleared
1151 # This copy can be re-merged with the parent after operations on the copy
1152 function fork()
1153 {
1154 $copy = $this;
1155 $copy->mOutput = new ParserOutput;
1156 return $copy;
1157 }
1158
1159 # Merges a copy split off with fork()
1160 function merge( &$copy )
1161 {
1162 $this->mOutput->merge( $copy->mOutput );
1163
1164 # Merge include throttling arrays
1165 foreach( $copy->mIncludeCount as $dbk => $count ) {
1166 if ( array_key_exists( $dbk, $this->mIncludeCount ) ) {
1167 $this->mIncludeCount[$dbk] += $count;
1168 } else {
1169 $this->mIncludeCount[$dbk] = $count;
1170 }
1171 }
1172 }
1173
1174 function braceSubstitution( $matches )
1175 {
1176 global $wgLinkCache, $wgLang;
1177 $fname = "Parser::braceSubstitution";
1178 $found = false;
1179 $nowiki = false;
1180
1181 $text = $matches[1];
1182
1183 # SUBST
1184 $mwSubst =& MagicWord::get( MAG_SUBST );
1185 if ( $mwSubst->matchStartAndRemove( $text ) ) {
1186 if ( $this->mOutputType != OT_WIKI ) {
1187 # Invalid SUBST not replaced at PST time
1188 # Return without further processing
1189 $text = $matches[0];
1190 $found = true;
1191 }
1192 } elseif ( $this->mOutputType == OT_WIKI ) {
1193 # SUBST not found in PST pass, do nothing
1194 $text = $matches[0];
1195 $found = true;
1196 }
1197
1198 # MSG, MSGNW and INT
1199 if ( !$found ) {
1200 # Check for MSGNW:
1201 $mwMsgnw =& MagicWord::get( MAG_MSGNW );
1202 if ( $mwMsgnw->matchStartAndRemove( $text ) ) {
1203 $nowiki = true;
1204 } else {
1205 # Remove obsolete MSG:
1206 $mwMsg =& MagicWord::get( MAG_MSG );
1207 $mwMsg->matchStartAndRemove( $text );
1208 }
1209
1210 # Check if it is an internal message
1211 $mwInt =& MagicWord::get( MAG_INT );
1212 if ( $mwInt->matchStartAndRemove( $text ) ) {
1213 $text = wfMsg( $text );
1214 $found = true;
1215 }
1216 }
1217
1218 # NS
1219 if ( !$found ) {
1220 # Check for NS: (namespace expansion)
1221 $mwNs = MagicWord::get( MAG_NS );
1222 if ( $mwNs->matchStartAndRemove( $text ) ) {
1223 if ( intval( $text ) ) {
1224 $text = $wgLang->getNsText( intval( $text ) );
1225 $found = true;
1226 } else {
1227 $index = Namespace::getCanonicalIndex( strtolower( $text ) );
1228 if ( !is_null( $index ) ) {
1229 $text = $wgLang->getNsText( $index );
1230 $found = true;
1231 }
1232 }
1233 }
1234 }
1235
1236 # LOCALURL and LOCALURLE
1237 if ( !$found ) {
1238 $mwLocal = MagicWord::get( MAG_LOCALURL );
1239 $mwLocalE = MagicWord::get( MAG_LOCALURLE );
1240
1241 if ( $mwLocal->matchStartAndRemove( $text ) ) {
1242 $func = 'getLocalURL';
1243 } elseif ( $mwLocalE->matchStartAndRemove( $text ) ) {
1244 $func = 'escapeLocalURL';
1245 } else {
1246 $func = '';
1247 }
1248
1249 if ( $func !== '' ) {
1250 $args = explode( "|", $text );
1251 $n = count( $args );
1252 if ( $n > 0 ) {
1253 $title = Title::newFromText( $args[0] );
1254 if ( !is_null( $title ) ) {
1255 if ( $n > 1 ) {
1256 $text = $title->$func( $args[1] );
1257 } else {
1258 $text = $title->$func();
1259 }
1260 $found = true;
1261 }
1262 }
1263 }
1264 }
1265
1266 # Check for a match against internal variables
1267 if ( !$found && array_key_exists( $text, $this->mVariables ) ) {
1268 $text = $this->mVariables[$text];
1269 $found = true;
1270 $this->mOutput->mContainsOldMagic = true;
1271 }
1272
1273 # Load from database
1274 if ( !$found ) {
1275 $title = Title::newFromText( $text, NS_TEMPLATE );
1276 if ( is_object( $title ) && !$title->isExternal() ) {
1277 # Check for excessive inclusion
1278 $dbk = $title->getPrefixedDBkey();
1279 if ( !array_key_exists( $dbk, $this->mIncludeCount ) ) {
1280 $this->mIncludeCount[$dbk] = 0;
1281 }
1282 if ( ++$this->mIncludeCount[$dbk] <= MAX_INCLUDE_REPEAT ) {
1283 $article = new Article( $title );
1284 $articleContent = $article->getContentWithoutUsingSoManyDamnGlobals();
1285 if ( $articleContent !== false ) {
1286 $found = true;
1287 $text = $articleContent;
1288
1289 # Escaping and link table handling
1290 # Not required for preSaveTransform()
1291 if ( $this->mOutputType == OT_HTML ) {
1292 if ( $nowiki ) {
1293 $text = wfEscapeWikiText( $text );
1294 } else {
1295 $text = $this->removeHTMLtags( $text );
1296 }
1297 $wgLinkCache->suspend();
1298 $text = $this->doTokenizedParser( $text );
1299 $wgLinkCache->resume();
1300 $wgLinkCache->addLinkObj( $title );
1301
1302 }
1303 }
1304 }
1305
1306 # If the title is valid but undisplayable, make a link to it
1307 if ( $this->mOutputType == OT_HTML && !$found ) {
1308 $text = "[[" . $title->getPrefixedText() . "]]";
1309 $found = true;
1310 }
1311 }
1312 }
1313
1314 if ( !$found ) {
1315 return $matches[0];
1316 } else {
1317 return $text;
1318 }
1319 }
1320
1321 # Cleans up HTML, removes dangerous tags and attributes
1322 /* private */ function removeHTMLtags( $text )
1323 {
1324 $fname = "Parser::removeHTMLtags";
1325 wfProfileIn( $fname );
1326 $htmlpairs = array( # Tags that must be closed
1327 "b", "i", "u", "font", "big", "small", "sub", "sup", "h1",
1328 "h2", "h3", "h4", "h5", "h6", "cite", "code", "em", "s",
1329 "strike", "strong", "tt", "var", "div", "center",
1330 "blockquote", "ol", "ul", "dl", "table", "caption", "pre",
1331 "ruby", "rt" , "rb" , "rp", "p"
1332 );
1333 $htmlsingle = array(
1334 "br", "hr", "li", "dt", "dd"
1335 );
1336 $htmlnest = array( # Tags that can be nested--??
1337 "table", "tr", "td", "th", "div", "blockquote", "ol", "ul",
1338 "dl", "font", "big", "small", "sub", "sup"
1339 );
1340 $tabletags = array( # Can only appear inside table
1341 "td", "th", "tr"
1342 );
1343
1344 $htmlsingle = array_merge( $tabletags, $htmlsingle );
1345 $htmlelements = array_merge( $htmlsingle, $htmlpairs );
1346
1347 $htmlattrs = $this->getHTMLattrs () ;
1348
1349 # Remove HTML comments
1350 $text = preg_replace( "/<!--.*-->/sU", "", $text );
1351
1352 $bits = explode( "<", $text );
1353 $text = array_shift( $bits );
1354 $tagstack = array(); $tablestack = array();
1355
1356 foreach ( $bits as $x ) {
1357 $prev = error_reporting( E_ALL & ~( E_NOTICE | E_WARNING ) );
1358 preg_match( "/^(\\/?)(\\w+)([^>]*)(\\/{0,1}>)([^<]*)$/",
1359 $x, $regs );
1360 list( $qbar, $slash, $t, $params, $brace, $rest ) = $regs;
1361 error_reporting( $prev );
1362
1363 $badtag = 0 ;
1364 if ( in_array( $t = strtolower( $t ), $htmlelements ) ) {
1365 # Check our stack
1366 if ( $slash ) {
1367 # Closing a tag...
1368 if ( ! in_array( $t, $htmlsingle ) &&
1369 ( $ot = array_pop( $tagstack ) ) != $t ) {
1370 array_push( $tagstack, $ot );
1371 $badtag = 1;
1372 } else {
1373 if ( $t == "table" ) {
1374 $tagstack = array_pop( $tablestack );
1375 }
1376 $newparams = "";
1377 }
1378 } else {
1379 # Keep track for later
1380 if ( in_array( $t, $tabletags ) &&
1381 ! in_array( "table", $tagstack ) ) {
1382 $badtag = 1;
1383 } else if ( in_array( $t, $tagstack ) &&
1384 ! in_array ( $t , $htmlnest ) ) {
1385 $badtag = 1 ;
1386 } else if ( ! in_array( $t, $htmlsingle ) ) {
1387 if ( $t == "table" ) {
1388 array_push( $tablestack, $tagstack );
1389 $tagstack = array();
1390 }
1391 array_push( $tagstack, $t );
1392 }
1393 # Strip non-approved attributes from the tag
1394 $newparams = $this->fixTagAttributes($params);
1395
1396 }
1397 if ( ! $badtag ) {
1398 $rest = str_replace( ">", "&gt;", $rest );
1399 $text .= "<$slash$t $newparams$brace$rest";
1400 continue;
1401 }
1402 }
1403 $text .= "&lt;" . str_replace( ">", "&gt;", $x);
1404 }
1405 # Close off any remaining tags
1406 while ( $t = array_pop( $tagstack ) ) {
1407 $text .= "</$t>\n";
1408 if ( $t == "table" ) { $tagstack = array_pop( $tablestack ); }
1409 }
1410 wfProfileOut( $fname );
1411 return $text;
1412 }
1413
1414 /*
1415 *
1416 * This function accomplishes several tasks:
1417 * 1) Auto-number headings if that option is enabled
1418 * 2) Add an [edit] link to sections for logged in users who have enabled the option
1419 * 3) Add a Table of contents on the top for users who have enabled the option
1420 * 4) Auto-anchor headings
1421 *
1422 * It loops through all headlines, collects the necessary data, then splits up the
1423 * string and re-inserts the newly formatted headlines.
1424 *
1425 */
1426
1427 /* private */ function formatHeadings( $text )
1428 {
1429 return $text;
1430 $doNumberHeadings = $this->mOptions->getNumberHeadings();
1431 $doShowToc = $this->mOptions->getShowToc();
1432 if( !$this->mTitle->userCanEdit() ) {
1433 $showEditLink = 0;
1434 $rightClickHack = 0;
1435 } else {
1436 $showEditLink = $this->mOptions->getEditSection();
1437 $rightClickHack = $this->mOptions->getEditSectionOnRightClick();
1438 }
1439
1440 # Inhibit editsection links if requested in the page
1441 $esw =& MagicWord::get( MAG_NOEDITSECTION );
1442 if( $esw->matchAndRemove( $text ) ) {
1443 $showEditLink = 0;
1444 }
1445 # if the string __NOTOC__ (not case-sensitive) occurs in the HTML,
1446 # do not add TOC
1447 $mw =& MagicWord::get( MAG_NOTOC );
1448 if( $mw->matchAndRemove( $text ) ) {
1449 $doShowToc = 0;
1450 }
1451
1452 # never add the TOC to the Main Page. This is an entry page that should not
1453 # be more than 1-2 screens large anyway
1454 if( $this->mTitle->getPrefixedText() == wfMsg("mainpage") ) {
1455 $doShowToc = 0;
1456 }
1457
1458 # Get all headlines for numbering them and adding funky stuff like [edit]
1459 # links - this is for later, but we need the number of headlines right now
1460 $numMatches = preg_match_all( "/<H([1-6])(.*?" . ">)(.*?)<\/H[1-6]>/i", $text, $matches );
1461
1462 # if there are fewer than 4 headlines in the article, do not show TOC
1463 if( $numMatches < 4 ) {
1464 $doShowToc = 0;
1465 }
1466
1467 # if the string __FORCETOC__ (not case-sensitive) occurs in the HTML,
1468 # override above conditions and always show TOC
1469 $mw =& MagicWord::get( MAG_FORCETOC );
1470 if ($mw->matchAndRemove( $text ) ) {
1471 $doShowToc = 1;
1472 }
1473
1474
1475 # We need this to perform operations on the HTML
1476 $sk =& $this->mOptions->getSkin();
1477
1478 # headline counter
1479 $headlineCount = 0;
1480
1481 # Ugh .. the TOC should have neat indentation levels which can be
1482 # passed to the skin functions. These are determined here
1483 $toclevel = 0;
1484 $toc = "";
1485 $full = "";
1486 $head = array();
1487 $sublevelCount = array();
1488 $level = 0;
1489 $prevlevel = 0;
1490 foreach( $matches[3] as $headline ) {
1491 $numbering = "";
1492 if( $level ) {
1493 $prevlevel = $level;
1494 }
1495 $level = $matches[1][$headlineCount];
1496 if( ( $doNumberHeadings || $doShowToc ) && $prevlevel && $level > $prevlevel ) {
1497 # reset when we enter a new level
1498 $sublevelCount[$level] = 0;
1499 $toc .= $sk->tocIndent( $level - $prevlevel );
1500 $toclevel += $level - $prevlevel;
1501 }
1502 if( ( $doNumberHeadings || $doShowToc ) && $level < $prevlevel ) {
1503 # reset when we step back a level
1504 $sublevelCount[$level+1]=0;
1505 $toc .= $sk->tocUnindent( $prevlevel - $level );
1506 $toclevel -= $prevlevel - $level;
1507 }
1508 # count number of headlines for each level
1509 @$sublevelCount[$level]++;
1510 if( $doNumberHeadings || $doShowToc ) {
1511 $dot = 0;
1512 for( $i = 1; $i <= $level; $i++ ) {
1513 if( !empty( $sublevelCount[$i] ) ) {
1514 if( $dot ) {
1515 $numbering .= ".";
1516 }
1517 $numbering .= $sublevelCount[$i];
1518 $dot = 1;
1519 }
1520 }
1521 }
1522
1523 # The canonized header is a version of the header text safe to use for links
1524 # Avoid insertion of weird stuff like <math> by expanding the relevant sections
1525 $canonized_headline = Parser::unstrip( $headline, $this->mStripState );
1526
1527 # strip out HTML
1528 $canonized_headline = preg_replace( "/<.*?" . ">/","",$canonized_headline );
1529 $tocline = trim( $canonized_headline );
1530 $canonized_headline = preg_replace("/[ &\\/<>\\(\\)\\[\\]=,+']+/", '_', html_entity_decode( $tocline));
1531 $refer[$headlineCount] = $canonized_headline;
1532
1533 # count how many in assoc. array so we can track dupes in anchors
1534 @$refers[$canonized_headline]++;
1535 $refcount[$headlineCount]=$refers[$canonized_headline];
1536
1537 # Prepend the number to the heading text
1538
1539 if( $doNumberHeadings || $doShowToc ) {
1540 $tocline = $numbering . " " . $tocline;
1541
1542 # Don't number the heading if it is the only one (looks silly)
1543 if( $doNumberHeadings && count( $matches[3] ) > 1) {
1544 # the two are different if the line contains a link
1545 $headline=$numbering . " " . $headline;
1546 }
1547 }
1548
1549 # Create the anchor for linking from the TOC to the section
1550 $anchor = $canonized_headline;
1551 if($refcount[$headlineCount] > 1 ) {
1552 $anchor .= "_" . $refcount[$headlineCount];
1553 }
1554 if( $doShowToc ) {
1555 $toc .= $sk->tocLine($anchor,$tocline,$toclevel);
1556 }
1557 if( $showEditLink ) {
1558 if ( empty( $head[$headlineCount] ) ) {
1559 $head[$headlineCount] = "";
1560 }
1561 $head[$headlineCount] .= $sk->editSectionLink($headlineCount+1);
1562 }
1563
1564 # Add the edit section span
1565 if( $rightClickHack ) {
1566 $headline = $sk->editSectionScript($headlineCount+1,$headline);
1567 }
1568
1569 # give headline the correct <h#> tag
1570 @$head[$headlineCount] .= "<a name=\"$anchor\"></a><h".$level.$matches[2][$headlineCount] .$headline."</h".$level.">";
1571
1572 $headlineCount++;
1573 }
1574
1575 if( $doShowToc ) {
1576 $toclines = $headlineCount;
1577 $toc .= $sk->tocUnindent( $toclevel );
1578 $toc = $sk->tocTable( $toc );
1579 }
1580
1581 # split up and insert constructed headlines
1582
1583 $blocks = preg_split( "/<H[1-6].*?" . ">.*?<\/H[1-6]>/i", $text );
1584 $i = 0;
1585
1586 foreach( $blocks as $block ) {
1587 if( $showEditLink && $headlineCount > 0 && $i == 0 && $block != "\n" ) {
1588 # This is the [edit] link that appears for the top block of text when
1589 # section editing is enabled
1590 $full .= $sk->editSectionLink(0);
1591 }
1592 $full .= $block;
1593 if( $doShowToc && !$i) {
1594 # Top anchor now in skin
1595 $full = $full.$toc;
1596 }
1597
1598 if( !empty( $head[$i] ) ) {
1599 $full .= $head[$i];
1600 }
1601 $i++;
1602 }
1603
1604 return $full;
1605 }
1606
1607 /* private */ function doMagicISBN( &$tokenizer )
1608 {
1609 global $wgLang;
1610
1611 # Check whether next token is a text token
1612 # If yes, fetch it and convert the text into a
1613 # Special::BookSources link
1614 $token = $tokenizer->previewToken();
1615 while ( $token["type"] == "" )
1616 {
1617 $tokenizer->nextToken();
1618 $token = $tokenizer->previewToken();
1619 }
1620 if ( $token["type"] == "text" )
1621 {
1622 $token = $tokenizer->nextToken();
1623 $x = $token["text"];
1624 $valid = "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1625
1626 $isbn = $blank = "" ;
1627 while ( " " == $x{0} ) {
1628 $blank .= " ";
1629 $x = substr( $x, 1 );
1630 }
1631 while ( strstr( $valid, $x{0} ) != false ) {
1632 $isbn .= $x{0};
1633 $x = substr( $x, 1 );
1634 }
1635 $num = str_replace( "-", "", $isbn );
1636 $num = str_replace( " ", "", $num );
1637
1638 if ( "" == $num ) {
1639 $text = "ISBN $blank$x";
1640 } else {
1641 $titleObj = Title::makeTitle( NS_SPECIAL, "Booksources" );
1642 $text = "<a href=\"" .
1643 $titleObj->escapeLocalUrl( "isbn={$num}" ) .
1644 "\" class=\"internal\">ISBN $isbn</a>";
1645 $text .= $x;
1646 }
1647 } else {
1648 $text = "ISBN ";
1649 }
1650 return $text;
1651 }
1652 /* private */ function doMagicRFC( &$tokenizer )
1653 {
1654 global $wgLang;
1655
1656 # Check whether next token is a text token
1657 # If yes, fetch it and convert the text into a
1658 # link to an RFC source
1659 $token = $tokenizer->previewToken();
1660 while ( $token["type"] == "" )
1661 {
1662 $tokenizer->nextToken();
1663 $token = $tokenizer->previewToken();
1664 }
1665 if ( $token["type"] == "text" )
1666 {
1667 $token = $tokenizer->nextToken();
1668 $x = $token["text"];
1669 $valid = "0123456789";
1670
1671 $rfc = $blank = "" ;
1672 while ( " " == $x{0} ) {
1673 $blank .= " ";
1674 $x = substr( $x, 1 );
1675 }
1676 while ( strstr( $valid, $x{0} ) != false ) {
1677 $rfc .= $x{0};
1678 $x = substr( $x, 1 );
1679 }
1680
1681 if ( "" == $rfc ) {
1682 $text .= "RFC $blank$x";
1683 } else {
1684 $url = wfmsg( "rfcurl" );
1685 $url = str_replace( "$1", $rfc, $url);
1686 $sk =& $this->mOptions->getSkin();
1687 $la = $sk->getExternalLinkAttributes( $url, "RFC {$rfc}" );
1688 $text = "<a href='{$url}'{$la}>RFC {$rfc}</a>{$x}";
1689 }
1690 } else {
1691 $text = "RFC ";
1692 }
1693 return $text;
1694 }
1695
1696 function preSaveTransform( $text, &$title, &$user, $options, $clearState = true )
1697 {
1698 $this->mOptions = $options;
1699 $this->mTitle =& $title;
1700 $this->mOutputType = OT_WIKI;
1701
1702 if ( $clearState ) {
1703 $this->clearState();
1704 }
1705
1706 $stripState = false;
1707 $text = str_replace("\r\n", "\n", $text);
1708 $text = $this->strip( $text, $stripState, false );
1709 $text = $this->pstPass2( $text, $user );
1710 $text = $this->unstrip( $text, $stripState );
1711 return $text;
1712 }
1713
1714 /* private */ function pstPass2( $text, &$user )
1715 {
1716 global $wgLang, $wgLocaltimezone, $wgCurParser;
1717
1718 # Variable replacement
1719 # Because mOutputType is OT_WIKI, this will only process {{subst:xxx}} type tags
1720 $text = $this->replaceVariables( $text );
1721
1722 # Signatures
1723 #
1724 $n = $user->getName();
1725 $k = $user->getOption( "nickname" );
1726 if ( "" == $k ) { $k = $n; }
1727 if(isset($wgLocaltimezone)) {
1728 $oldtz = getenv("TZ"); putenv("TZ=$wgLocaltimezone");
1729 }
1730 /* Note: this is an ugly timezone hack for the European wikis */
1731 $d = $wgLang->timeanddate( date( "YmdHis" ), false ) .
1732 " (" . date( "T" ) . ")";
1733 if(isset($wgLocaltimezone)) putenv("TZ=$oldtz");
1734
1735 $text = preg_replace( "/~~~~~/", $d, $text );
1736 $text = preg_replace( "/~~~~/", "[[" . $wgLang->getNsText(
1737 Namespace::getUser() ) . ":$n|$k]] $d", $text );
1738 $text = preg_replace( "/~~~/", "[[" . $wgLang->getNsText(
1739 Namespace::getUser() ) . ":$n|$k]]", $text );
1740
1741 # Context links: [[|name]] and [[name (context)|]]
1742 #
1743 $tc = "[&;%\\-,.\\(\\)' _0-9A-Za-z\\/:\\x80-\\xff]";
1744 $np = "[&;%\\-,.' _0-9A-Za-z\\/:\\x80-\\xff]"; # No parens
1745 $namespacechar = '[ _0-9A-Za-z\x80-\xff]'; # Namespaces can use non-ascii!
1746 $conpat = "/^({$np}+) \\(({$tc}+)\\)$/";
1747
1748 $p1 = "/\[\[({$np}+) \\(({$np}+)\\)\\|]]/"; # [[page (context)|]]
1749 $p2 = "/\[\[\\|({$tc}+)]]/"; # [[|page]]
1750 $p3 = "/\[\[($namespacechar+):({$np}+)\\|]]/"; # [[namespace:page|]]
1751 $p4 = "/\[\[($namespacechar+):({$np}+) \\(({$np}+)\\)\\|]]/";
1752 # [[ns:page (cont)|]]
1753 $context = "";
1754 $t = $this->mTitle->getText();
1755 if ( preg_match( $conpat, $t, $m ) ) {
1756 $context = $m[2];
1757 }
1758 $text = preg_replace( $p4, "[[\\1:\\2 (\\3)|\\2]]", $text );
1759 $text = preg_replace( $p1, "[[\\1 (\\2)|\\1]]", $text );
1760 $text = preg_replace( $p3, "[[\\1:\\2|\\2]]", $text );
1761
1762 if ( "" == $context ) {
1763 $text = preg_replace( $p2, "[[\\1]]", $text );
1764 } else {
1765 $text = preg_replace( $p2, "[[\\1 ({$context})|\\1]]", $text );
1766 }
1767
1768 /*
1769 $mw =& MagicWord::get( MAG_SUBST );
1770 $wgCurParser = $this->fork();
1771 $text = $mw->substituteCallback( $text, "wfBraceSubstitution" );
1772 $this->merge( $wgCurParser );
1773 */
1774
1775 # Trim trailing whitespace
1776 # MAG_END (__END__) tag allows for trailing
1777 # whitespace to be deliberately included
1778 $text = rtrim( $text );
1779 $mw =& MagicWord::get( MAG_END );
1780 $mw->matchAndRemove( $text );
1781
1782 return $text;
1783 }
1784
1785 # Set up some variables which are usually set up in parse()
1786 # so that an external function can call some class members with confidence
1787 function startExternalParse( &$title, $options, $outputType, $clearState = true )
1788 {
1789 $this->mTitle =& $title;
1790 $this->mOptions = $options;
1791 $this->mOutputType = $outputType;
1792 if ( $clearState ) {
1793 $this->clearState();
1794 }
1795 }
1796
1797 function transformMsg( $text, $options ) {
1798 global $wgTitle;
1799 static $executing = false;
1800
1801 # Guard against infinite recursion
1802 if ( $executing ) {
1803 return $text;
1804 }
1805 $executing = true;
1806
1807 $this->mTitle = $wgTitle;
1808 $this->mOptions = $options;
1809 $this->mOutputType = OT_MSG;
1810 $this->clearState();
1811 $text = $this->replaceVariables( $text );
1812
1813 $executing = false;
1814 return $text;
1815 }
1816 }
1817
1818 class ParserOutput
1819 {
1820 var $mText, $mLanguageLinks, $mCategoryLinks, $mContainsOldMagic;
1821
1822 function ParserOutput( $text = "", $languageLinks = array(), $categoryLinks = array(),
1823 $containsOldMagic = false )
1824 {
1825 $this->mText = $text;
1826 $this->mLanguageLinks = $languageLinks;
1827 $this->mCategoryLinks = $categoryLinks;
1828 $this->mContainsOldMagic = $containsOldMagic;
1829 }
1830
1831 function getText() { return $this->mText; }
1832 function getLanguageLinks() { return $this->mLanguageLinks; }
1833 function getCategoryLinks() { return $this->mCategoryLinks; }
1834 function containsOldMagic() { return $this->mContainsOldMagic; }
1835 function setText( $text ) { return wfSetVar( $this->mText, $text ); }
1836 function setLanguageLinks( $ll ) { return wfSetVar( $this->mLanguageLinks, $ll ); }
1837 function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategoryLinks, $cl ); }
1838 function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); }
1839
1840 function merge( $other ) {
1841 $this->mLanguageLinks = array_merge( $this->mLanguageLinks, $other->mLanguageLinks );
1842 $this->mCategoryLinks = array_merge( $this->mCategoryLinks, $this->mLanguageLinks );
1843 $this->mContainsOldMagic = $this->mContainsOldMagic || $other->mContainsOldMagic;
1844 }
1845
1846 }
1847
1848 class ParserOptions
1849 {
1850 # All variables are private
1851 var $mUseTeX; # Use texvc to expand <math> tags
1852 var $mUseCategoryMagic; # Treat [[Category:xxxx]] tags specially
1853 var $mUseDynamicDates; # Use $wgDateFormatter to format dates
1854 var $mInterwikiMagic; # Interlanguage links are removed and returned in an array
1855 var $mAllowExternalImages; # Allow external images inline
1856 var $mSkin; # Reference to the preferred skin
1857 var $mDateFormat; # Date format index
1858 var $mEditSection; # Create "edit section" links
1859 var $mEditSectionOnRightClick; # Generate JavaScript to edit section on right click
1860 var $mNumberHeadings; # Automatically number headings
1861 var $mShowToc; # Show table of contents
1862
1863 function getUseTeX() { return $this->mUseTeX; }
1864 function getUseCategoryMagic() { return $this->mUseCategoryMagic; }
1865 function getUseDynamicDates() { return $this->mUseDynamicDates; }
1866 function getInterwikiMagic() { return $this->mInterwikiMagic; }
1867 function getAllowExternalImages() { return $this->mAllowExternalImages; }
1868 function getSkin() { return $this->mSkin; }
1869 function getDateFormat() { return $this->mDateFormat; }
1870 function getEditSection() { return $this->mEditSection; }
1871 function getEditSectionOnRightClick() { return $this->mEditSectionOnRightClick; }
1872 function getNumberHeadings() { return $this->mNumberHeadings; }
1873 function getShowToc() { return $this->mShowToc; }
1874
1875 function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX, $x ); }
1876 function setUseCategoryMagic( $x ) { return wfSetVar( $this->mUseCategoryMagic, $x ); }
1877 function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates, $x ); }
1878 function setInterwikiMagic( $x ) { return wfSetVar( $this->mInterwikiMagic, $x ); }
1879 function setAllowExternalImages( $x ) { return wfSetVar( $this->mAllowExternalImages, $x ); }
1880 function setSkin( $x ) { return wfSetRef( $this->mSkin, $x ); }
1881 function setDateFormat( $x ) { return wfSetVar( $this->mDateFormat, $x ); }
1882 function setEditSection( $x ) { return wfSetVar( $this->mEditSection, $x ); }
1883 function setEditSectionOnRightClick( $x ) { return wfSetVar( $this->mEditSectionOnRightClick, $x ); }
1884 function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); }
1885 function setShowToc( $x ) { return wfSetVar( $this->mShowToc, $x ); }
1886
1887 /* static */ function newFromUser( &$user )
1888 {
1889 $popts = new ParserOptions;
1890 $popts->initialiseFromUser( &$user );
1891 return $popts;
1892 }
1893
1894 function initialiseFromUser( &$userInput )
1895 {
1896 global $wgUseTeX, $wgUseCategoryMagic, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
1897
1898 if ( !$userInput ) {
1899 $user = new User;
1900 $user->setLoaded( true );
1901 } else {
1902 $user =& $userInput;
1903 }
1904
1905 $this->mUseTeX = $wgUseTeX;
1906 $this->mUseCategoryMagic = $wgUseCategoryMagic;
1907 $this->mUseDynamicDates = $wgUseDynamicDates;
1908 $this->mInterwikiMagic = $wgInterwikiMagic;
1909 $this->mAllowExternalImages = $wgAllowExternalImages;
1910 $this->mSkin =& $user->getSkin();
1911 $this->mDateFormat = $user->getOption( "date" );
1912 $this->mEditSection = $user->getOption( "editsection" );
1913 $this->mEditSectionOnRightClick = $user->getOption( "editsectiononrightclick" );
1914 $this->mNumberHeadings = $user->getOption( "numberheadings" );
1915 $this->mShowToc = $user->getOption( "showtoc" );
1916 }
1917
1918
1919 }
1920
1921 # Regex callbacks, used in Parser::replaceVariables
1922 function wfBraceSubstitution( $matches )
1923 {
1924 global $wgCurParser;
1925 return $wgCurParser->braceSubstitution( $matches );
1926 }
1927
1928 ?>