r17066 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17065‎ | r17066 | r17067 >
Date:08:49, 17 October 2006
Author:nickj
Status:old
Tags:
Comment:
* Make ParserOptions private variables private.
* Remove two unused globals.
* Remove pass-by-ref usage when arg is never modified (objects automatically passed-by-ref in PHP5)
* Removed some unused local variables.
* Mark a possibly dubious pass-by-ref on an uninitialized var as "FIXME: Please check that this initialization is correct", and added what I presume is the correct initialization.
* Declare preg_match arg 3 (output matches argument) as an array() before using it. Nothing wrong with not doing this, just feels slightly more explicit to me than a function call that also implictly creates and populates an array.
* My editor has automatically removed trailing spaces at the end of lines (which is not inherently a bad thing, but I have turned this option off now to help minimize diff sizes in future).
* Have confirmed that "php maintenance/parserTests.php --quiet --quick --color=no" shows no regressions, and that "php maintenance/fuzz-tester.php --specific-test=editPageTest --max-runtime=5" still shows no errors.
Modified paths:
  • /trunk/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -78,7 +78,7 @@
7979 * settings:
8080 * $wgUseTex*, $wgUseDynamicDates*, $wgInterwikiMagic*,
8181 * $wgNamespacesWithSubpages, $wgAllowExternalImages*,
82 - * $wgLocaltimezone, $wgAllowSpecialInclusion*,
 82+ * $wgLocaltimezone, $wgAllowSpecialInclusion*,
8383 * $wgMaxArticleSize*
8484 *
8585 * * only within ParserOptions
@@ -169,12 +169,12 @@
170170 if ( $wgAllowSlowParserFunctions ) {
171171 $this->setFunctionHook( 'pagesinnamespace', array( 'CoreParserFunctions', 'pagesinnamespace' ), SFH_NO_HASH );
172172 }
173 -
 173+
174174 $this->initialiseVariables();
175175
176176 $this->mFirstCall = false;
177177 wfProfileOut( __METHOD__ );
178 - }
 178+ }
179179
180180 /**
181181 * Clear Parser state
@@ -206,7 +206,7 @@
207207 'titles' => array()
208208 );
209209 $this->mRevisionId = null;
210 -
 210+
211211 /**
212212 * Prefix for temporary replacement strings for the multipass parser.
213213 * \x07 should never appear in input as it's disallowed in XML.
@@ -503,7 +503,7 @@
504504 $text = $q[2];
505505 }
506506 }
507 -
 507+
508508 $matches[$marker] = array( $element,
509509 $content,
510510 Sanitizer::decodeTagAttributes( $attributes ),
@@ -522,7 +522,7 @@
523523 * will be stripped in addition to other tags. This is important
524524 * for section editing, where these comments cause confusion when
525525 * counting the sections in the wikisource
526 - *
 526+ *
527527 * @param array dontstrip contains tags which should not be stripped;
528528 * used to prevent stipping of <gallery> when saving (fixes bug 2700)
529529 *
@@ -534,7 +534,7 @@
535535
536536 $uniq_prefix = $this->mUniqPrefix;
537537 $commentState = array();
538 -
 538+
539539 $elements = array_merge(
540540 array( 'nowiki', 'gallery' ),
541541 array_keys( $this->mTagHooks ) );
@@ -545,13 +545,13 @@
546546 if( $this->mOptions->getUseTeX() ) {
547547 $elements[] = 'math';
548548 }
549 -
 549+
550550 # Removing $dontstrip tags from $elements list (currently only 'gallery', fixing bug 2700)
551551 foreach ( $elements AS $k => $v ) {
552552 if ( !in_array ( $v , $dontstrip ) ) continue;
553553 unset ( $elements[$k] );
554554 }
555 -
 555+
556556 $matches = array();
557557 $text = Parser::extractTagsAndParams( $elements, $text, $matches, $uniq_prefix );
558558
@@ -600,7 +600,7 @@
601601 $output = $tag;
602602 }
603603
604 - // Unstrip the output, because unstrip() is no longer recursive so
 604+ // Unstrip the output, because unstrip() is no longer recursive so
605605 // it won't do it itself
606606 $output = $this->unstrip( $output, $state );
607607
@@ -632,7 +632,7 @@
633633 * always call unstripNoWiki() after this one
634634 * @private
635635 */
636 - function unstrip( $text, &$state ) {
 636+ function unstrip( $text, $state ) {
637637 if ( !isset( $state['general'] ) ) {
638638 return $text;
639639 }
@@ -649,7 +649,7 @@
650650 *
651651 * @private
652652 */
653 - function unstripNoWiki( $text, &$state ) {
 653+ function unstripNoWiki( $text, $state ) {
654654 if ( !isset( $state['nowiki'] ) ) {
655655 return $text;
656656 }
@@ -658,7 +658,7 @@
659659 # TODO: good candidate for FSS
660660 $text = strtr( $text, $state['nowiki'] );
661661 wfProfileOut( __METHOD__ );
662 -
 662+
663663 return $text;
664664 }
665665
@@ -806,6 +806,7 @@
807807 {
808808 $x = trim ( $x ) ;
809809 $fc = substr ( $x , 0 , 1 ) ;
 810+ $matches = array();
810811 if ( preg_match( '/^(:*)\{\|(.*)$/', $x, $matches ) ) {
811812 $indent_level = strlen( $matches[1] );
812813
@@ -879,10 +880,15 @@
880881
881882 $l = array_pop ( $ltd ) ;
882883 if ( array_pop ( $td ) ) $z = '</'.$l.'>' . $z ;
883 - if ( $fc == '|' ) $l = 'td' ;
884 - else if ( $fc == '!' ) $l = 'th' ;
885 - else if ( $fc == '+' ) $l = 'caption' ;
886 - else $l = '' ;
 884+ if ( $fc == '|' ) {
 885+ $l = 'td' ;
 886+ } else if ( $fc == '!' ) {
 887+ $l = 'th' ;
 888+ } else if ( $fc == '+' ) {
 889+ $l = 'caption' ;
 890+ } else {
 891+ $l = '' ;
 892+ }
887893 array_push ( $ltd , $l ) ;
888894
889895 # Cell parameters
@@ -935,6 +941,7 @@
936942 wfProfileIn( $fname );
937943
938944 # Hook to suspend the parser in this state
 945+ $x =& $this->mStripState; // FIXME: Please check that this initialization is correct.
939946 if ( !wfRunHooks( 'ParserBeforeInternalParse', array( &$this, &$text, &$x ) ) ) {
940947 wfProfileOut( $fname );
941948 return $text ;
@@ -987,7 +994,7 @@
988995 */
989996 function &doMagicLinks( &$text ) {
990997 wfProfileIn( __METHOD__ );
991 - $text = preg_replace_callback(
 998+ $text = preg_replace_callback(
992999 '!(?: # Start cases
9931000 <a.*?</a> | # Skip link text
9941001 <.*?> | # Skip stuff inside HTML elements
@@ -995,7 +1002,7 @@
9961003 ISBN\s+([0-9Xx-]+) # ISBN, capture number as m[2]
9971004 )!x', array( &$this, 'magicLinkCallback' ), $text );
9981005 wfProfileOut( __METHOD__ );
999 - return $text;
 1006+ return $text;
10001007 }
10011008
10021009 function magicLinkCallback( $m ) {
@@ -1004,7 +1011,7 @@
10051012 return $m[0];
10061013 } elseif ( substr( $m[0], 0, 4 ) == 'ISBN' ) {
10071014 $isbn = $m[2];
1008 - $num = strtr( $isbn, array(
 1015+ $num = strtr( $isbn, array(
10091016 '-' => '',
10101017 ' ' => '',
10111018 'x' => 'X',
@@ -1023,10 +1030,10 @@
10241031 $urlmsg = 'pubmedurl';
10251032 $id = $m[1];
10261033 } else {
1027 - throw new MWException( __METHOD__.': unrecognised match type "' .
 1034+ throw new MWException( __METHOD__.': unrecognised match type "' .
10281035 substr($m[0], 0, 20 ) . '"' );
10291036 }
1030 -
 1037+
10311038 $url = wfMsg( $urlmsg, $id);
10321039 $sk =& $this->mOptions->getSkin();
10331040 $la = $sk->getExternalLinkAttributes( $url, $keyword.$id );
@@ -1106,9 +1113,9 @@
11071114 }
11081115 # Count the number of occurrences of bold and italics mark-ups.
11091116 # We are not counting sequences of five apostrophes.
1110 - if ( strlen( $arr[$i] ) == 2 ) $numitalics++; else
1111 - if ( strlen( $arr[$i] ) == 3 ) $numbold++; else
1112 - if ( strlen( $arr[$i] ) == 5 ) { $numitalics++; $numbold++; }
 1117+ if ( strlen( $arr[$i] ) == 2 ) { $numitalics++; }
 1118+ else if ( strlen( $arr[$i] ) == 3 ) { $numbold++; }
 1119+ else if ( strlen( $arr[$i] ) == 5 ) { $numitalics++; $numbold++; }
11131120 }
11141121 $i++;
11151122 }
@@ -1264,6 +1271,7 @@
12651272 # The characters '<' and '>' (which were escaped by
12661273 # removeHTMLtags()) should not be included in
12671274 # URLs, per RFC 2396.
 1275+ $m2 = array();
12681276 if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) {
12691277 $text = substr($url, $m2[0][1]) . ' ' . $text;
12701278 $url = substr($url, 0, $m2[0][1]);
@@ -1299,7 +1307,7 @@
13001308 }
13011309
13021310 $text = $wgContLang->markNoConversion($text);
1303 -
 1311+
13041312 $url = Sanitizer::cleanUrl( $url );
13051313
13061314 # Process the trail (i.e. everything after this link up until start of the next link),
@@ -1342,6 +1350,7 @@
13431351 $protocol = $bits[$i++];
13441352 $remainder = $bits[$i++];
13451353
 1354+ $m = array();
13461355 if ( preg_match( '/^('.EXT_LINK_URL_CLASS.'+)(.*)$/s', $remainder, $m ) ) {
13471356 # Found some characters after the protocol that look promising
13481357 $url = $protocol . $m[1];
@@ -1349,10 +1358,10 @@
13501359
13511360 # special case: handle urls as url args:
13521361 # http://www.example.com/foo?=http://www.example.com/bar
1353 - if(strlen($trail) == 0 &&
 1362+ if(strlen($trail) == 0 &&
13541363 isset($bits[$i]) &&
13551364 preg_match('/^'. wfUrlProtocols() . '$/S', $bits[$i]) &&
1356 - preg_match( '/^('.EXT_LINK_URL_CLASS.'+)(.*)$/s', $bits[$i + 1], $m ))
 1365+ preg_match( '/^('.EXT_LINK_URL_CLASS.'+)(.*)$/s', $bits[$i + 1], $m ))
13571366 {
13581367 # add protocol, arg
13591368 $url .= $bits[$i] . $m[1]; # protocol, url as arg to previous link
@@ -1363,6 +1372,7 @@
13641373 # The characters '<' and '>' (which were escaped by
13651374 # removeHTMLtags()) should not be included in
13661375 # URLs, per RFC 2396.
 1376+ $m2 = array();
13671377 if (preg_match('/&(lt|gt);/', $url, $m2, PREG_OFFSET_CAPTURE)) {
13681378 $trail = substr($url, $m2[0][1]) . $trail;
13691379 $url = substr($url, 0, $m2[0][1]);
@@ -1498,6 +1508,7 @@
14991509 $nottalk = !$this->mTitle->isTalkPage();
15001510
15011511 if ( $useLinkPrefixExtension ) {
 1512+ $m = array();
15021513 if ( preg_match( $e2, $s, $m ) ) {
15031514 $first_prefix = $m[2];
15041515 } else {
@@ -1543,10 +1554,10 @@
15441555 # Still some problems for cases where the ] is meant to be outside punctuation,
15451556 # and no image is in sight. See bug 2095.
15461557 #
1547 - if( $text !== '' &&
1548 - substr( $m[3], 0, 1 ) === ']' &&
1549 - strpos($text, '[') !== false
1550 - )
 1558+ if( $text !== '' &&
 1559+ substr( $m[3], 0, 1 ) === ']' &&
 1560+ strpos($text, '[') !== false
 1561+ )
15511562 {
15521563 $text .= ']'; # so that replaceExternalLinks($text) works later
15531564 $m[3] = substr( $m[3], 1 );
@@ -1605,7 +1616,7 @@
16061617 $ns = $nt->getNamespace();
16071618 $iw = $nt->getInterWiki();
16081619 wfProfileOut( "$fname-title" );
1609 -
 1620+
16101621 if ($might_be_img) { # if this is actually an invalid link
16111622 wfProfileIn( "$fname-might_be_img" );
16121623 if ($ns == NS_IMAGE && $noforce) { #but might be an image
@@ -2326,9 +2337,11 @@
23272338 * expensive to check many times.
23282339 */
23292340 static $varCache = array();
2330 - if ( wfRunHooks( 'ParserGetVariableValueVarCache', array( &$this, &$varCache ) ) )
2331 - if ( isset( $varCache[$index] ) )
 2341+ if ( wfRunHooks( 'ParserGetVariableValueVarCache', array( &$this, &$varCache ) ) ) {
 2342+ if ( isset( $varCache[$index] ) ) {
23322343 return $varCache[$index];
 2344+ }
 2345+ }
23332346
23342347 $ts = time();
23352348 wfRunHooks( 'ParserGetVariableValueTs', array( &$this, &$ts ) );
@@ -2543,7 +2556,7 @@
25442557 $lastOpeningBrace = -1; # last not closed parentheses
25452558
25462559 $validOpeningBraces = implode( '', array_keys( $callbacks ) );
2547 -
 2560+
25482561 $i = 0;
25492562 while ( $i < strlen( $text ) ) {
25502563 # Find next opening brace, closing brace or pipe
@@ -2597,13 +2610,13 @@
25982611 $maxCount = $openingBraceStack[$lastOpeningBrace]['count'];
25992612 $count = strspn( $text, $text[$i], $i, $maxCount );
26002613
2601 - # check for maximum matching characters (if there are 5 closing
 2614+ # check for maximum matching characters (if there are 5 closing
26022615 # characters, we will probably need only 3 - depending on the rules)
26032616 $matchingCount = 0;
26042617 $matchingCallback = null;
26052618 $cbType = $callbacks[$openingBraceStack[$lastOpeningBrace]['brace']];
26062619 if ( $count > $cbType['max'] ) {
2607 - # The specified maximum exists in the callback array, unless the caller
 2620+ # The specified maximum exists in the callback array, unless the caller
26082621 # has made an error
26092622 $matchingCount = $cbType['max'];
26102623 } else {
@@ -2624,12 +2637,12 @@
26252638
26262639 # let's set a title or last part (if '|' was found)
26272640 if (null === $openingBraceStack[$lastOpeningBrace]['parts']) {
2628 - $openingBraceStack[$lastOpeningBrace]['title'] =
2629 - substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
 2641+ $openingBraceStack[$lastOpeningBrace]['title'] =
 2642+ substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
26302643 $i - $openingBraceStack[$lastOpeningBrace]['partStart']);
26312644 } else {
2632 - $openingBraceStack[$lastOpeningBrace]['parts'][] =
2633 - substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
 2645+ $openingBraceStack[$lastOpeningBrace]['parts'][] =
 2646+ substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
26342647 $i - $openingBraceStack[$lastOpeningBrace]['partStart']);
26352648 }
26362649
@@ -2679,13 +2692,13 @@
26802693 } elseif ( $found == 'pipe' ) {
26812694 # lets set a title if it is a first separator, or next part otherwise
26822695 if (null === $openingBraceStack[$lastOpeningBrace]['parts']) {
2683 - $openingBraceStack[$lastOpeningBrace]['title'] =
2684 - substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
 2696+ $openingBraceStack[$lastOpeningBrace]['title'] =
 2697+ substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
26852698 $i - $openingBraceStack[$lastOpeningBrace]['partStart']);
26862699 $openingBraceStack[$lastOpeningBrace]['parts'] = array();
26872700 } else {
2688 - $openingBraceStack[$lastOpeningBrace]['parts'][] =
2689 - substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
 2701+ $openingBraceStack[$lastOpeningBrace]['parts'][] =
 2702+ substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'],
26902703 $i - $openingBraceStack[$lastOpeningBrace]['partStart']);
26912704 }
26922705 $openingBraceStack[$lastOpeningBrace]['partStart'] = ++$i;
@@ -2731,15 +2744,15 @@
27322745 $braceCallbacks[3] = array( &$this, 'argSubstitution' );
27332746 }
27342747 if ( $braceCallbacks ) {
2735 - $callbacks = array(
 2748+ $callbacks = array(
27362749 '{' => array(
27372750 'end' => '}',
27382751 'cb' => $braceCallbacks,
27392752 'min' => $argsOnly ? 3 : 2,
27402753 'max' => isset( $braceCallbacks[3] ) ? 3 : 2,
27412754 ),
2742 - '[' => array(
2743 - 'end' => ']',
 2755+ '[' => array(
 2756+ 'end' => ']',
27442757 'cb' => array(2=>null),
27452758 'min' => 2,
27462759 'max' => 2,
@@ -2801,7 +2814,7 @@
28022815 * @private
28032816 */
28042817 function braceSubstitution( $piece ) {
2805 - global $wgContLang, $wgLang, $wgAllowDisplayTitle, $action;
 2818+ global $wgContLang, $wgLang, $wgAllowDisplayTitle;
28062819 $fname = __METHOD__ /*. '-L' . count( $this->mArgStack )*/;
28072820 wfProfileIn( $fname );
28082821 wfProfileIn( __METHOD__.'-setup' );
@@ -2820,7 +2833,7 @@
28212834
28222835 $linestart = '';
28232836
2824 -
 2837+
28252838 # $part1 is the bit before the first |, and must contain only title characters
28262839 # $args is a list of arguments, starting from index 0, not including $part1
28272840
@@ -2838,7 +2851,6 @@
28392852 }
28402853
28412854 $args = (null == $piece['parts']) ? array() : $piece['parts'];
2842 - $argc = count( $args );
28432855 wfProfileOut( __METHOD__.'-setup' );
28442856
28452857 # SUBST
@@ -2868,7 +2880,7 @@
28692881 $mwMsg =& MagicWord::get( 'msg' );
28702882 $mwMsg->matchStartAndRemove( $part1 );
28712883 }
2872 -
 2884+
28732885 # Check for RAW:
28742886 $mwRaw =& MagicWord::get( 'raw' );
28752887 if ( $mwRaw->matchStartAndRemove( $part1 ) ) {
@@ -2880,7 +2892,7 @@
28812893 # Parser functions
28822894 if ( !$found ) {
28832895 wfProfileIn( __METHOD__ . '-pfunc' );
2884 -
 2896+
28852897 $colonPos = strpos( $part1, ':' );
28862898 if ( $colonPos !== false ) {
28872899 # Case sensitive functions
@@ -3062,6 +3074,7 @@
30633075 if ( !$noparse ) {
30643076 # If there are any <onlyinclude> tags, only include them
30653077 if ( in_string( '<onlyinclude>', $text ) && in_string( '</onlyinclude>', $text ) ) {
 3078+ $m = array();
30663079 preg_match_all( '/<onlyinclude>(.*?)\n?<\/onlyinclude>/s', $text, $m );
30673080 $text = '';
30683081 foreach ($m[1] as $piece)
@@ -3084,7 +3097,7 @@
30853098
30863099 # If the template begins with a table or block-level
30873100 # element, it should be treated as beginning a new line.
3088 - if (!$piece['lineStart'] && preg_match('/^({\\||:|;|#|\*)/', $text)) /*}*/{
 3101+ if (!$piece['lineStart'] && preg_match('/^({\\||:|;|#|\*)/', $text)) /*}*/{
30893102 $text = "\n" . $text;
30903103 }
30913104 } elseif ( !$noargs ) {
@@ -3135,6 +3148,7 @@
31363149 $text .= $hl;
31373150 continue;
31383151 }
 3152+ $m2 = array();
31393153 preg_match('/^(={1,6})(.*?)(={1,6})\s*?$/m', $hl, $m2);
31403154 $text .= $m2[1] . $m2[2] . "<!--MWTEMPLATESECTION="
31413155 . $encodedname . "&" . base64_encode("$nsec") . "-->" . $m2[3];
@@ -3242,7 +3256,7 @@
32433257
32443258 if ( array_key_exists( $arg, $inputArgs ) ) {
32453259 $text = $inputArgs[$arg];
3246 - } else if (($this->mOutputType == OT_HTML || $this->mOutputType == OT_PREPROCESS ) &&
 3260+ } else if (($this->mOutputType == OT_HTML || $this->mOutputType == OT_PREPROCESS ) &&
32473261 null != $matches['parts'] && count($matches['parts']) > 0) {
32483262 $text = $matches['parts'][0];
32493263 }
@@ -3337,6 +3351,7 @@
33383352
33393353 # Get all headlines for numbering them and adding funky stuff like [edit]
33403354 # links - this is for later, but we need the number of headlines right now
 3355+ $matches = array();
33413356 $numMatches = preg_match_all( '/<H([1-6])(.*?'.'>)(.*?)<\/H[1-6] *>/i', $text, $matches );
33423357
33433358 # if there are fewer than 4 headlines in the article, do not show TOC
@@ -3388,7 +3403,7 @@
33893404 $templatetitle = '';
33903405 $templatesection = 0;
33913406 $numbering = '';
3392 -
 3407+ $mat = array();
33933408 if (preg_match("/<!--MWTEMPLATESECTION=([^&]+)&([^_]+)-->/", $headline, $mat)) {
33943409 $istemplate = 1;
33953410 $templatetitle = base64_decode($mat[1]);
@@ -3570,7 +3585,7 @@
35713586 * @return string the altered wiki markup
35723587 * @public
35733588 */
3574 - function preSaveTransform( $text, &$title, &$user, $options, $clearState = true ) {
 3589+ function preSaveTransform( $text, &$title, $user, $options, $clearState = true ) {
35753590 $this->mOptions = $options;
35763591 $this->mTitle =& $title;
35773592 $this->setOutputType( OT_WIKI );
@@ -3595,7 +3610,7 @@
35963611 * Pre-save transform helper function
35973612 * @private
35983613 */
3599 - function pstPass2( $text, &$stripState, &$user ) {
 3614+ function pstPass2( $text, &$stripState, $user ) {
36003615 global $wgContLang, $wgLocaltimezone;
36013616
36023617 /* Note: This is the timestamp saved as hardcoded wikitext to
@@ -3643,6 +3658,7 @@
36443659 $text = preg_replace( $p3, '[[\\1\\2\\3\\4|\\2]]', $text );
36453660
36463661 $t = $this->mTitle->getText();
 3662+ $m = array();
36473663 if ( preg_match( "/^($nc+:|)$tc+?( \\($tc+\\))$/", $t, $m ) ) {
36483664 $text = preg_replace( $p2, "[[$m[1]\\1$m[2]|\\1]]", $text );
36493665 } elseif ( preg_match( "/^($nc+:|)$tc+?(, $tc+|)$/", $t, $m ) && '' != "$m[1]$m[2]" ) {
@@ -3820,10 +3836,10 @@
38213837 * The callback function should have the form:
38223838 * function myParserFunction( &$parser, $arg1, $arg2, $arg3 ) { ... }
38233839 *
3824 - * The callback may either return the text result of the function, or an array with the text
3825 - * in element 0, and a number of flags in the other elements. The names of the flags are
 3840+ * The callback may either return the text result of the function, or an array with the text
 3841+ * in element 0, and a number of flags in the other elements. The names of the flags are
38263842 * specified in the keys. Valid flags are:
3827 - * found The text returned is valid, stop processing the template. This
 3843+ * found The text returned is valid, stop processing the template. This
38283844 * is on by default.
38293845 * nowiki Wiki markup in the return value should be escaped
38303846 * noparse Unsafe HTML tags should not be stripped, etc.
@@ -3834,7 +3850,7 @@
38353851 *
38363852 * @param string $id The magic word ID
38373853 * @param mixed $callback The callback function (and object) to use
3838 - * @param integer $flags a combination of the following flags:
 3854+ * @param integer $flags a combination of the following flags:
38393855 * SFH_NO_HASH No leading hash, i.e. {{plural:...}} instead of {{#if:...}}
38403856 *
38413857 * @return The old callback function for this name, if any
@@ -3890,7 +3906,7 @@
38913907 function replaceLinkHolders( &$text, $options = 0 ) {
38923908 global $wgUser;
38933909 global $wgOutputReplace;
3894 - global $wgContLang, $wgLanguageCode;
 3910+ global $wgContLang;
38953911
38963912 $fname = 'Parser::replaceLinkHolders';
38973913 wfProfileIn( $fname );
@@ -3911,6 +3927,7 @@
39123928
39133929 # Generate query
39143930 $query = false;
 3931+ $current = null;
39153932 foreach ( $this->mLinkHolders['namespaces'] as $key => $ns ) {
39163933 # Make title object
39173934 $title = $this->mLinkHolders['titles'][$key];
@@ -3983,7 +4000,7 @@
39844001
39854002 # Do a second query for different language variants of links (if needed)
39864003 if($wgContLang->hasVariants()){
3987 - $linkBatch = new LinkBatch();
 4004+ $linkBatch = new LinkBatch();
39884005 $variantMap = array(); // maps $pdbkey_Variant => $pdbkey_original
39894006
39904007 // Add variants of links to link batch
@@ -4007,8 +4024,8 @@
40084025 }
40094026 }
40104027 }
4011 -
40124028
 4029+
40134030 if(!$linkBatch->isEmpty()){
40144031 // construct query
40154032 $titleClause = $linkBatch->constructSet('page', $dbr);
@@ -4036,7 +4053,7 @@
40374054 $holderKeys = $variantMap[$varPdbk];
40384055
40394056 // loop over link holders
4040 - foreach($holderKeys as $key){
 4057+ foreach($holderKeys as $key){
40414058 $title = $this->mLinkHolders['titles'][$key];
40424059 if ( is_null( $title ) ) continue;
40434060
@@ -4046,7 +4063,7 @@
40474064 // found link in some of the variants, replace the link holder data
40484065 $this->mLinkHolders['titles'][$key] = $variantTitle;
40494066 $this->mLinkHolders['dbkeys'][$key] = $variantTitle->getDBkey();
4050 -
 4067+
40514068 // set pdbk and colour
40524069 $pdbks[$key] = $varPdbk;
40534070 if ( $threshold > 0 ) {
@@ -4056,10 +4073,10 @@
40574074 } else {
40584075 $colours[$varPdbk] = 2;
40594076 }
4060 - }
 4077+ }
40614078 else {
40624079 $colours[$varPdbk] = 1;
4063 - }
 4080+ }
40644081 }
40654082 }
40664083 }
@@ -4167,7 +4184,7 @@
41684185 /**
41694186 * Tag hook handler for 'pre'.
41704187 */
4171 - function renderPreTag( $text, $attribs, $parser ) {
 4188+ function renderPreTag( $text, $attribs ) {
41724189 // Backwards-compatibility hack
41734190 $content = preg_replace( '!<nowiki>(.*?)</nowiki>!is', '\\1', $text );
41744191
@@ -4200,6 +4217,7 @@
42014218 foreach ( $lines as $line ) {
42024219 # match lines like these:
42034220 # Image:someimage.jpg|This is some image
 4221+ $matches = array();
42044222 preg_match( "/^([^|]+)(\\|(.*))?$/", $line, $matches );
42054223 # Skip empty lines
42064224 if ( count( $matches ) == 0 ) {
@@ -4238,7 +4256,7 @@
42394257 /**
42404258 * Parse image options text and use it to make an image
42414259 */
4242 - function makeImage( &$nt, $options ) {
 4260+ function makeImage( $nt, $options ) {
42434261 global $wgUseImageResize, $wgDjvuRenderer;
42444262
42454263 $align = '';
@@ -4270,7 +4288,7 @@
42714289 $page = null;
42724290 $manual_thumb = '' ;
42734291
4274 - foreach( $part as $key => $val ) {
 4292+ foreach( $part as $val ) {
42754293 if ( $wgUseImageResize && ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
42764294 $thumb=true;
42774295 } elseif ( ! is_null( $match = $mwManualThumb->matchVariableStartToEnd($val) ) ) {
@@ -4296,6 +4314,7 @@
42974315 } elseif ( $wgUseImageResize && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
42984316 wfDebug( "img_width match: $match\n" );
42994317 # $match is the image width in pixels
 4318+ $m = array();
43004319 if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) {
43014320 $width = intval( $m[1] );
43024321 $height = intval( $m[2] );
@@ -4314,7 +4333,7 @@
43154334 # make sure there are no placeholders in thumbnail attributes
43164335 # that are later expanded to html- so expand them now and
43174336 # remove the tags
4318 - $alt = $this->unstrip($alt, $this->mStripState);
 4337+ $alt = $this->unstrip($alt, $this->mStripState);
43194338 $alt = Sanitizer::stripAllTags( $alt );
43204339
43214340 # Linker does the rest
@@ -4594,7 +4613,7 @@
45954614 function addImage( $name ) { $this->mImages[$name] = 1; }
45964615 function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
45974616 function addExternalLink( $url ) { $this->mExternalLinks[$url] = 1; }
4598 -
 4617+
45994618 function setNewSection( $value ) {
46004619 $this->mNewSection = (bool)$value;
46014620 }
@@ -4650,22 +4669,22 @@
46514670 class ParserOptions
46524671 {
46534672 # All variables are private
4654 - var $mUseTeX; # Use texvc to expand <math> tags
4655 - var $mUseDynamicDates; # Use DateFormatter to format dates
4656 - var $mInterwikiMagic; # Interlanguage links are removed and returned in an array
4657 - var $mAllowExternalImages; # Allow external images inline
4658 - var $mAllowExternalImagesFrom; # If not, any exception?
4659 - var $mSkin; # Reference to the preferred skin
4660 - var $mDateFormat; # Date format index
4661 - var $mEditSection; # Create "edit section" links
4662 - var $mNumberHeadings; # Automatically number headings
4663 - var $mAllowSpecialInclusion; # Allow inclusion of special pages
4664 - var $mTidy; # Ask for tidy cleanup
4665 - var $mInterfaceMessage; # Which lang to call for PLURAL and GRAMMAR
4666 - var $mMaxIncludeSize; # Maximum size of template expansions, in bytes
4667 - var $mRemoveComments; # Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
 4673+ private $mUseTeX; # Use texvc to expand <math> tags
 4674+ private $mUseDynamicDates; # Use DateFormatter to format dates
 4675+ private $mInterwikiMagic; # Interlanguage links are removed and returned in an array
 4676+ private $mAllowExternalImages; # Allow external images inline
 4677+ private $mAllowExternalImagesFrom; # If not, any exception?
 4678+ private $mSkin; # Reference to the preferred skin
 4679+ private $mDateFormat; # Date format index
 4680+ private $mEditSection; # Create "edit section" links
 4681+ private $mNumberHeadings; # Automatically number headings
 4682+ private $mAllowSpecialInclusion; # Allow inclusion of special pages
 4683+ private $mTidy; # Ask for tidy cleanup
 4684+ private $mInterfaceMessage; # Which lang to call for PLURAL and GRAMMAR
 4685+ private $mMaxIncludeSize; # Maximum size of template expansions, in bytes
 4686+ private $mRemoveComments; # Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
46684687
4669 - var $mUser; # Stored user object, just used to initialise the skin
 4688+ private $mUser; # Stored user object, just used to initialise the skin
46704689
46714690 function getUseTeX() { return $this->mUseTeX; }
46724691 function getUseDynamicDates() { return $this->mUseDynamicDates; }
@@ -4687,7 +4706,7 @@
46884707 return $this->mSkin;
46894708 }
46904709
4691 - function getDateFormat() {
 4710+ function getDateFormat() {
46924711 if ( !isset( $this->mDateFormat ) ) {
46934712 $this->mDateFormat = $this->mUser->getDatePreference();
46944713 }
@@ -4704,7 +4723,7 @@
47054724 function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); }
47064725 function setAllowSpecialInclusion( $x ) { return wfSetVar( $this->mAllowSpecialInclusion, $x ); }
47074726 function setTidy( $x ) { return wfSetVar( $this->mTidy, $x); }
4708 - function setSkin( &$x ) { $this->mSkin =& $x; }
 4727+ function setSkin( $x ) { $this->mSkin = $x; }
47094728 function setInterfaceMessage( $x ) { return wfSetVar( $this->mInterfaceMessage, $x); }
47104729 function setMaxIncludeSize( $x ) { return wfSetVar( $this->mMaxIncludeSize, $x ); }
47114730 function setRemoveComments( $x ) { return wfSetVar( $this->mRemoveComments, $x ); }
@@ -4881,7 +4900,7 @@
48824901 function wfRevisionTimestamp( $id ) {
48834902 global $wgContLang;
48844903 $fname = 'wfRevisionTimestamp';
4885 -
 4904+
48864905 wfProfileIn( $fname );
48874906 $dbr =& wfGetDB( DB_SLAVE );
48884907 $timestamp = $dbr->selectField( 'revision', 'rev_timestamp',

Follow-up revisions

RevisionCommit summaryAuthorDate
r17075Revert part of r17066 - ParserOptions private variables not being treated as ...nickj05:29, 18 October 2006