Instead of storing entire link attributes in wikitext for
authorJens Frank <jeluf@users.mediawiki.org>
Mon, 20 Sep 2004 23:02:08 +0000 (23:02 +0000)
committerJens Frank <jeluf@users.mediawiki.org>
Mon, 20 Sep 2004 23:02:08 +0000 (23:02 +0000)
deleayed link colouring, store pointer to an entry in array wgLinkHolders. Fixes BUG#493 and should
be faster.

includes/OutputPage.php
includes/Parser.php

index a7af044..9c98a56 100644 (file)
@@ -810,7 +810,7 @@ class OutputPage {
         * $options is a bit field, RLH_FOR_UPDATE to select for update
         */
        function replaceLinkHolders( &$text, $options = 0 ) {
-               global $wgUser, $wgLinkCache, $wgUseOldExistenceCheck;
+               global $wgUser, $wgLinkCache, $wgUseOldExistenceCheck, $wgLinkHolders;
                
                if ( $wgUseOldExistenceCheck ) {
                        return array();
@@ -819,36 +819,25 @@ class OutputPage {
                $fname = 'OutputPage::replaceLinkHolders';
                wfProfileIn( $fname );
 
-               $titles = array();
                $pdbks = array();
                $colours = array();
                
-               # Get placeholders from body
-               wfProfileIn( $fname.'-match' );
-               preg_match_all( "/<!--LINK (.*?) (.*?) (.*?) (.*?)-->/", $text, $tmpLinks );
-               wfProfileOut( $fname.'-match' );
-               
-               if ( !empty( $tmpLinks[0] ) ) {
+               #if ( !empty( $tmpLinks[0] ) ) { #TODO
+               if ( !empty( $wgLinkHolders['namespaces'] ) ) {
                        wfProfileIn( $fname.'-check' );
                        $dbr =& wfGetDB( DB_SLAVE );
                        $cur = $dbr->tableName( 'cur' );
                        $sk = $wgUser->getSkin();
                        $threshold = $wgUser->getOption('stubthreshold');
                        
-                       $namespaces =& $tmpLinks[1];
-                       $dbkeys =& $tmpLinks[2];
-                       $queries =& $tmpLinks[3];
-                       $texts =& $tmpLinks[4];
-
                        # Sort by namespace
-                       asort( $namespaces );
+                       asort( $wgLinkHolders['namespaces'] );
        
                        # Generate query
                        $query = false;
-                       foreach ( $namespaces as $key => $val ) {
+                       foreach ( $wgLinkHolders['namespaces'] as $key => $val ) {
                                # Make title object
-                               $dbk = $dbkeys[$key];
-                               $title = $titles[$key] = Title::makeTitleSafe( $val, $dbk );
+                               $title = $wgLinkHolders['titles'][$key];
 
                                # Skip invalid entries.
                                # Result will be ugly, but prevents crash.
@@ -878,7 +867,7 @@ class OutputPage {
                                                $query .= ', ';
                                        }
                                
-                                       $query .= $dbr->addQuotes( $dbkeys[$key] );
+                                       $query .= $dbr->addQuotes( $wgLinkHolders['dbkeys'][$key] );
                                }
                        }
                        if ( $query ) {
@@ -916,18 +905,24 @@ class OutputPage {
                        wfProfileIn( $fname.'-construct' );
                        global $outputReplace;
                        $outputReplace = array();
-                       foreach ( $namespaces as $key => $ns ) {
+                       foreach ( $wgLinkHolders['namespaces'] as $key => $ns ) {
                                $pdbk = $pdbks[$key];
-                               $searchkey = $tmpLinks[0][$key];
-                               $title = $titles[$key];
+                               $searchkey = '<!--LINK '.$key.'-->';
+                               $title = $wgLinkHolders['titles'][$key];
                                if ( empty( $colours[$pdbk] ) ) {
                                        $wgLinkCache->addBadLink( $pdbk );
                                        $colours[$pdbk] = 0;
-                                       $outputReplace[$searchkey] = $sk->makeBrokenLinkObj( $title, $texts[$key], $queries[$key] );
+                                       $outputReplace[$searchkey] = $sk->makeBrokenLinkObj( $title,
+                                                                       $wgLinkHolders['texts'][$key],
+                                                                       $wgLinkHolders['queries'][$key] );
                                } elseif ( $colours[$pdbk] == 1 ) {
-                                       $outputReplace[$searchkey] = $sk->makeKnownLinkObj( $title, $texts[$key], $queries[$key] );
+                                       $outputReplace[$searchkey] = $sk->makeKnownLinkObj( $title,
+                                                                       $wgLinkHolders['texts'][$key],
+                                                                       $wgLinkHolders['queries'][$key] );
                                } elseif ( $colours[$pdbk] == 2 ) {
-                                       $outputReplace[$searchkey] = $sk->makeStubLinkObj( $title, $texts[$key], $queries[$key] );
+                                       $outputReplace[$searchkey] = $sk->makeStubLinkObj( $title,
+                                                                       $wgLinkHolders['texts'][$key],
+                                                                       $wgLinkHolders['queries'][$key] );
                                }
                        }
                        wfProfileOut( $fname.'-construct' );
@@ -936,7 +931,7 @@ class OutputPage {
                        wfProfileIn( $fname.'-replace' );
                        
                        $text = preg_replace_callback(
-                               '/(<!--LINK .*? .*? .*? .*?-->)/',
+                               '/(<!--LINK .*?-->)/',
                                "outputReplaceMatches",
                                $text);
                        wfProfileOut( $fname.'-replace' );
index 36d7f01..e467942 100644 (file)
@@ -1911,7 +1911,7 @@ class Parser
        # It loops through all headlines, collects the necessary data, then splits up the
        # string and re-inserts the newly formatted headlines.
        /* private */ function formatHeadings( $text, $isMain=true ) {
-               global $wgInputEncoding, $wgMaxTocLevel, $wgLang;
+               global $wgInputEncoding, $wgMaxTocLevel, $wgLang, $wgLinkHolders;
 
                $doNumberHeadings = $this->mOptions->getNumberHeadings();
                $doShowToc = $this->mOptions->getShowToc();
@@ -2022,10 +2022,13 @@ class Parser
                        $canonized_headline = $this->unstripNoWiki( $headline, $this->mStripState );
 
                        # Remove link placeholders by the link text.
-                       #     <!--LINK namespace page_title link text with suffix-->
+                       #     <!--LINK number-->
                        # turns into 
                        #     link text with suffix
-                       $canonized_headline = preg_replace( '/<!--LINK [0-9]* [^ ]* *(.*?)-->/','$1', $canonized_headline );
+                       $canonized_headline = preg_replace( '/<!--LINK ([0-9]*)-->/e',
+                                                           "\$wgLinkHolders['texts'][\$1]",
+                                                           $canonized_headline );
+
                        # strip out HTML
                        $canonized_headline = preg_replace( '/<.*?' . '>/','',$canonized_headline );
                        $tocline = trim( $canonized_headline );