Prevent OutputPage::addWikiText and friends from causing UNIQ fails
authorBrian Wolff <bawolff+wn@gmail.com>
Fri, 20 Jun 2014 20:38:10 +0000 (17:38 -0300)
committerBrian Wolff <bawolff+wn@gmail.com>
Wed, 25 Jun 2014 18:16:14 +0000 (15:16 -0300)
If you transclude a special page, OutputPage::addWikiText can cause
problems. This prevents that from happening, by using a new object
if currently in a parsing operation.

Bug: 14562
Bug: 65826
Change-Id: I7c38fa9e2fbd270e45f73f522612451e77ab8cbb

includes/OutputPage.php
includes/parser/Parser.php

index 8fd7812..815ac12 100644 (file)
@@ -1608,7 +1608,7 @@ class OutputPage extends ContextSource {
                $oldTidy = $popts->setTidy( $tidy );
                $popts->setInterfaceMessage( (bool)$interface );
 
-               $parserOutput = $wgParser->parse(
+               $parserOutput = $wgParser->getFreshParser()->parse(
                        $text, $title, $popts,
                        $linestart, true, $this->mRevisionId
                );
@@ -1726,7 +1726,7 @@ class OutputPage extends ContextSource {
                        $oldLang = $popts->setTargetLanguage( $language );
                }
 
-               $parserOutput = $wgParser->parse(
+               $parserOutput = $wgParser->getFreshParser()->parse(
                        $text, $this->getTitle(), $popts,
                        $linestart, true, $this->mRevisionId
                );
index c1fce12..a9e2a3b 100644 (file)
@@ -6333,4 +6333,23 @@ class Parser {
 
                return $html;
        }
+
+       /**
+        * Return this parser if it is not doing anything, otherwise
+        * get a fresh parser. You can use this method by doing
+        * $myParser = $wgParser->getFreshParser(), or more simply
+        * $wgParser->getFreshParser()->parse( ... );
+        * if you're unsure if $wgParser is safe to use.
+        *
+        * @since 1.24
+        * @return Parser A parser object that is not parsing anything
+        */
+       public function getFreshParser() {
+               global $wgParserConf;
+               if ( $this->mInParse ) {
+                       return new $wgParserConf['class']( $wgParserConf );
+               } else {
+                       return $this;
+               }
+       }
 }