From: Brian Wolff Date: Fri, 20 Jun 2014 20:38:10 +0000 (-0300) Subject: Prevent OutputPage::addWikiText and friends from causing UNIQ fails X-Git-Tag: 1.31.0-rc.0~15235^2 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=4e6b0e4f4dcd9cffe1d695d2f5f809409ef7b1fc;p=lhc%2Fweb%2Fwiklou.git Prevent OutputPage::addWikiText and friends from causing UNIQ fails 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 --- diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 8fd78121db..815ac12443 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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 ); diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index c1fce121af..a9e2a3b6a7 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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; + } + } }