Replaced link holders with actual links before saving into the cache, thereby speedin...
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 21 Aug 2004 14:56:07 +0000 (14:56 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 21 Aug 2004 14:56:07 +0000 (14:56 +0000)
includes/Article.php
includes/OutputPage.php

index fb2b94e..ec07e3d 100644 (file)
@@ -741,7 +741,7 @@ class Article {
                                  "<span class=\"redirectText\">$link</span>" );
                        } else if ( $pcache ) {
                                # Display content and save to parser cache
-                               $wgOut->addWikiText( $text, true, $this );
+                               $wgOut->addPrimaryWikiText( $text, $this );
                        } else {
                                # Display content, don't attempt to save to parser cache
                                $wgOut->addWikiText( $text );
@@ -760,7 +760,7 @@ class Article {
                }
 
                # Put link titles into the link cache
-               $wgOut->replaceLinkHolders();
+               $wgOut->transformBuffer();
 
                # Add link titles as META keywords
                $wgOut->addMetaTags() ;
index bd1a012..948fc41 100644 (file)
@@ -218,25 +218,40 @@ class OutputPage {
                return wfSetVar( $this->mParserOptions, $options );
        }
 
-       # First pass--just handle <nowiki> sections, pass the rest off
-       # to doWikiPass2() which does all the real work.
+       # Convert wikitext to HTML and add it to the buffer
        #
-       # $cacheArticle - assume this text is the main text for the given article
-       #
-       function addWikiText( $text, $linestart = true, $cacheArticle = NULL )
+       function addWikiText( $text, $linestart = true )
        {
-               global $wgParser, $wgParserCache, $wgUser, $wgTitle;
+               global $wgParser, $wgTitle;
 
                $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart );
+               $this->mLanguageLinks += $parserOutput->getLanguageLinks();
+               $this->mCategoryLinks += $parserOutput->getCategoryLinks();
+               $this->addHTML( $parserOutput->getText() );
+       }
+
+       # Add wikitext to the buffer, assuming that this is the primary text for a page view
+       # Saves the text into the parser cache if possible
+       #
+       function addPrimaryWikiText( $text, $cacheArticle ) {
+               global $wgParser, $wgParserCache, $wgUser, $wgTitle;
+
+               $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, true );
+
+               # Replace link holders
+               $text = $parserOutput->getText();
+               $this->replaceLinkHolders( $text );
+               $parserOutput->setText( $text );
+               
                if ( $cacheArticle ) {
                        $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
                }
 
                $this->mLanguageLinks += $parserOutput->getLanguageLinks();
                $this->mCategoryLinks += $parserOutput->getCategoryLinks();
-               $this->addHTML( $parserOutput->getText() );
+               $this->addHTML( $text );
        }
-
+       
        function tryParserCache( $article, $user ) {
                global $wgParserCache;
                $parserOutput = $wgParserCache->get( $article, $user );
@@ -352,7 +367,7 @@ class OutputPage {
 
                $this->sendCacheControl();
                # Perform link colouring
-               $this->replaceLinkHolders();
+               $this->transformBuffer();
                
                # Disable temporary placeholders, so that the skin produces HTML
                $sk->postParseLinkColour( false );
@@ -762,6 +777,12 @@ class OutputPage {
                return $ret;
        }
        
+       # Run any necessary pre-output transformations on the buffer text
+       function transformBuffer( $options = 0 )
+       {
+               $this->replaceLinkHolders( $this->mBodytext, $options );
+       }
+
        # Replace <!--LINK--> link placeholders with actual links, in the buffer
        # Placeholders created in Skin::makeLinkObj()
        # Returns an array of links found, indexed by PDBK:
@@ -769,8 +790,7 @@ class OutputPage {
        #   1 - normal link
        #   2 - stub
        # $options is a bit field, RLH_FOR_UPDATE to select for update
-       function replaceLinkHolders( $options = 0 )
-       {
+       function replaceLinkHolders( &$text, $options = 0 ) {
                global $wgUser, $wgLinkCache, $wgUseOldExistenceCheck;
                
                if ( $wgUseOldExistenceCheck ) {
@@ -786,7 +806,7 @@ class OutputPage {
                
                # Get placeholders from body
                wfProfileIn( "$fname-match" );
-               preg_match_all( "/<!--LINK (.*?) (.*?) (.*?) (.*?)-->/", $this->mBodytext, $tmpLinks );
+               preg_match_all( "/<!--LINK (.*?) (.*?) (.*?) (.*?)-->/", $text, $tmpLinks );
                wfProfileOut( "$fname-match" );
                
                if ( !empty( $tmpLinks[0] ) ) {
@@ -896,10 +916,10 @@ class OutputPage {
                        # Do the thing
                        wfProfileIn( "$fname-replace" );
                        
-                       $this->mBodytext = preg_replace_callback(
+                       $text = preg_replace_callback(
                                '/(<!--LINK .*? .*? .*? .*?-->)/',
                                "outputReplaceMatches",
-                               $this->mBodytext);
+                               $text);
                        wfProfileOut( "$fname-replace" );
                }
                wfProfileOut( $fname );