Jump to content

Live hacks/internalParse

From Wikitech
This page contains historical information. It may be outdated or unreliable.
Index: includes/Parser.php
===================================================================
--- includes/Parser.php (revision 30164)
+++ includes/Parser.php (working copy)
@@ -328,8 +328,10 @@
 
                global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang;
                $fname = 'Parser::parse-' . wfGetCaller();
-               wfProfileIn( __METHOD__ );
-               wfProfileIn( $fname );
+               if ( $clearState ) {
+                       wfProfileIn( __METHOD__ );
+                       wfProfileIn( $fname );
+               }
 
                if ( $clearState ) {
                        $this->clearState();
@@ -347,7 +349,7 @@
                wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
                # No more strip!
                wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
-               $text = $this->internalParse( $text );
+               $text = $this->internalParse( $text, $clearState );
                $text = $this->mStripState->unstripGeneral( $text );
 
                # Clean up special characters, only run once, next-to-last before doBlockLevels
@@ -443,9 +445,12 @@
                $this->mOutput->setText( $text );
                $this->mRevisionId = $oldRevisionId;
                $this->mRevisionTimestamp = $oldRevisionTimestamp;
-               wfProfileOut( $fname );
-               wfProfileOut( __METHOD__ );
 
+               if ( $clearState ) {
+                       wfProfileOut( $fname );
+                       wfProfileOut( __METHOD__ );
+               }
+
                return $this->mOutput;
        }
 
@@ -967,7 +972,7 @@
         *
         * @private
         */
-       function internalParse( $text ) {
+       function internalParse( $text, $clearState ) {
                $isMain = true;
                $fname = 'Parser::internalParse';
                wfProfileIn( $fname );
@@ -978,7 +983,13 @@
                        return $text ;
                }
 
+               if ( $clearState ) {
+                       wfProfileIn( __METHOD__.'-rv' );
+               }
                $text = $this->replaceVariables( $text );
+               if ( $clearState ) {
+                       wfProfileOut( __METHOD__.'-rv' );
+               }
                $text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ), false, array_keys( $this->mTransparentTagHooks ) );
                wfRunHooks( 'InternalParseBeforeLinks', array( &$this, &$text, &$this->mStripState ) );