Add Parser::resetOutput() and getStripState()
authorTim Starling <tstarling@wikimedia.org>
Mon, 12 Aug 2019 06:10:22 +0000 (16:10 +1000)
committerTim Starling <tstarling@wikimedia.org>
Tue, 13 Aug 2019 03:40:07 +0000 (13:40 +1000)
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

index e5bf94a..9887917 100644 (file)
@@ -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;
+               }
        }
 
        /**