From ca5836a83eec78f92a7165f9e2d61361244a39ae Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 12 Aug 2019 16:10:22 +1000 Subject: [PATCH] Add Parser::resetOutput() and getStripState() For Parsoid's convenience, add to Parser resetOutput(), getStripState() and a $revId parameter to startExternalParse(). Parser::resetOutput() allows Parsoid to get the ParserOutput of each template without resetting the DOM cache. Change-Id: I084676acdc8db185b8efd9b97b7d5326afd2a997 --- includes/parser/Parser.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index e5bf94a602..9887917c58 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -468,8 +468,7 @@ class Parser { */ public function clearState() { $this->firstCallInit(); - $this->mOutput = new ParserOutput; - $this->mOptions->registerWatcher( [ $this->mOutput, 'recordOption' ] ); + $this->resetOutput(); $this->mAutonumber = 0; $this->mIncludeCount = []; $this->mLinkHolders = new LinkHolderArray( $this ); @@ -512,6 +511,14 @@ class Parser { Hooks::run( 'ParserClearState', [ &$parser ] ); } + /** + * Reset the ParserOutput + */ + public function resetOutput() { + $this->mOutput = new ParserOutput; + $this->mOptions->registerWatcher( [ $this->mOutput, 'recordOption' ] ); + } + /** * Convert wikitext to HTML * Do not call this function recursively. @@ -1177,6 +1184,15 @@ class Parser { return $this->mStripList; } + /** + * Get the StripState + * + * @return StripState + */ + public function getStripState() { + return $this->mStripState; + } + /** * Add an item to the strip state * Returns the unique tag which must be inserted into the stripped text @@ -4857,11 +4873,15 @@ class Parser { * @param ParserOptions $options * @param int $outputType * @param bool $clearState + * @param int|null $revId */ public function startExternalParse( Title $title = null, ParserOptions $options, - $outputType, $clearState = true + $outputType, $clearState = true, $revId = null ) { $this->startParse( $title, $options, $outputType, $clearState ); + if ( $revId !== null ) { + $this->mRevisionId = $revId; + } } /** -- 2.20.1