From 100316948f02f37d94aa8320dda9652f70d9707f Mon Sep 17 00:00:00 2001 From: Jens Frank Date: Mon, 20 Sep 2004 23:02:08 +0000 Subject: [PATCH] Instead of storing entire link attributes in wikitext for deleayed link colouring, store pointer to an entry in array wgLinkHolders. Fixes BUG#493 and should be faster. --- includes/OutputPage.php | 45 ++++++++++++++++++----------------------- includes/Parser.php | 9 ++++++--- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index a7af0442ff..9c98a56782 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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( "//", $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 = ''; + $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( - '/()/', + '/()/', "outputReplaceMatches", $text); wfProfileOut( $fname.'-replace' ); diff --git a/includes/Parser.php b/includes/Parser.php index 36d7f01692..e4679421b1 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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. - # + # # turns into # link text with suffix - $canonized_headline = preg_replace( '//','$1', $canonized_headline ); + $canonized_headline = preg_replace( '//e', + "\$wgLinkHolders['texts'][\$1]", + $canonized_headline ); + # strip out HTML $canonized_headline = preg_replace( '/<.*?' . '>/','',$canonized_headline ); $tocline = trim( $canonized_headline ); -- 2.20.1