r5337 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r5336‎ | r5337 | r5338 >
Date:23:02, 20 September 2004
Author:jeluf
Status:old
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -1911,7 +1911,7 @@
19121912 # It loops through all headlines, collects the necessary data, then splits up the
19131913 # string and re-inserts the newly formatted headlines.
19141914 /* private */ function formatHeadings( $text, $isMain=true ) {
1915 - global $wgInputEncoding, $wgMaxTocLevel, $wgLang;
 1915+ global $wgInputEncoding, $wgMaxTocLevel, $wgLang, $wgLinkHolders;
19161916
19171917 $doNumberHeadings = $this->mOptions->getNumberHeadings();
19181918 $doShowToc = $this->mOptions->getShowToc();
@@ -2022,10 +2022,13 @@
20232023 $canonized_headline = $this->unstripNoWiki( $headline, $this->mStripState );
20242024
20252025 # Remove link placeholders by the link text.
2026 - # <!--LINK namespace page_title link text with suffix-->
 2026+ # <!--LINK number-->
20272027 # turns into
20282028 # link text with suffix
2029 - $canonized_headline = preg_replace( '/<!--LINK [0-9]* [^ ]* *(.*?)-->/','$1', $canonized_headline );
 2029+ $canonized_headline = preg_replace( '/<!--LINK ([0-9]*)-->/e',
 2030+ "\$wgLinkHolders['texts'][\$1]",
 2031+ $canonized_headline );
 2032+
20302033 # strip out HTML
20312034 $canonized_headline = preg_replace( '/<.*?' . '>/','',$canonized_headline );
20322035 $tocline = trim( $canonized_headline );
Index: trunk/phase3/includes/OutputPage.php
@@ -810,7 +810,7 @@
811811 * $options is a bit field, RLH_FOR_UPDATE to select for update
812812 */
813813 function replaceLinkHolders( &$text, $options = 0 ) {
814 - global $wgUser, $wgLinkCache, $wgUseOldExistenceCheck;
 814+ global $wgUser, $wgLinkCache, $wgUseOldExistenceCheck, $wgLinkHolders;
815815
816816 if ( $wgUseOldExistenceCheck ) {
817817 return array();
@@ -819,36 +819,25 @@
820820 $fname = 'OutputPage::replaceLinkHolders';
821821 wfProfileIn( $fname );
822822
823 - $titles = array();
824823 $pdbks = array();
825824 $colours = array();
826825
827 - # Get placeholders from body
828 - wfProfileIn( $fname.'-match' );
829 - preg_match_all( "/<!--LINK (.*?) (.*?) (.*?) (.*?)-->/", $text, $tmpLinks );
830 - wfProfileOut( $fname.'-match' );
831 -
832 - if ( !empty( $tmpLinks[0] ) ) {
 826+ #if ( !empty( $tmpLinks[0] ) ) { #TODO
 827+ if ( !empty( $wgLinkHolders['namespaces'] ) ) {
833828 wfProfileIn( $fname.'-check' );
834829 $dbr =& wfGetDB( DB_SLAVE );
835830 $cur = $dbr->tableName( 'cur' );
836831 $sk = $wgUser->getSkin();
837832 $threshold = $wgUser->getOption('stubthreshold');
838833
839 - $namespaces =& $tmpLinks[1];
840 - $dbkeys =& $tmpLinks[2];
841 - $queries =& $tmpLinks[3];
842 - $texts =& $tmpLinks[4];
843 -
844834 # Sort by namespace
845 - asort( $namespaces );
 835+ asort( $wgLinkHolders['namespaces'] );
846836
847837 # Generate query
848838 $query = false;
849 - foreach ( $namespaces as $key => $val ) {
 839+ foreach ( $wgLinkHolders['namespaces'] as $key => $val ) {
850840 # Make title object
851 - $dbk = $dbkeys[$key];
852 - $title = $titles[$key] = Title::makeTitleSafe( $val, $dbk );
 841+ $title = $wgLinkHolders['titles'][$key];
853842
854843 # Skip invalid entries.
855844 # Result will be ugly, but prevents crash.
@@ -878,7 +867,7 @@
879868 $query .= ', ';
880869 }
881870
882 - $query .= $dbr->addQuotes( $dbkeys[$key] );
 871+ $query .= $dbr->addQuotes( $wgLinkHolders['dbkeys'][$key] );
883872 }
884873 }
885874 if ( $query ) {
@@ -916,18 +905,24 @@
917906 wfProfileIn( $fname.'-construct' );
918907 global $outputReplace;
919908 $outputReplace = array();
920 - foreach ( $namespaces as $key => $ns ) {
 909+ foreach ( $wgLinkHolders['namespaces'] as $key => $ns ) {
921910 $pdbk = $pdbks[$key];
922 - $searchkey = $tmpLinks[0][$key];
923 - $title = $titles[$key];
 911+ $searchkey = '<!--LINK '.$key.'-->';
 912+ $title = $wgLinkHolders['titles'][$key];
924913 if ( empty( $colours[$pdbk] ) ) {
925914 $wgLinkCache->addBadLink( $pdbk );
926915 $colours[$pdbk] = 0;
927 - $outputReplace[$searchkey] = $sk->makeBrokenLinkObj( $title, $texts[$key], $queries[$key] );
 916+ $outputReplace[$searchkey] = $sk->makeBrokenLinkObj( $title,
 917+ $wgLinkHolders['texts'][$key],
 918+ $wgLinkHolders['queries'][$key] );
928919 } elseif ( $colours[$pdbk] == 1 ) {
929 - $outputReplace[$searchkey] = $sk->makeKnownLinkObj( $title, $texts[$key], $queries[$key] );
 920+ $outputReplace[$searchkey] = $sk->makeKnownLinkObj( $title,
 921+ $wgLinkHolders['texts'][$key],
 922+ $wgLinkHolders['queries'][$key] );
930923 } elseif ( $colours[$pdbk] == 2 ) {
931 - $outputReplace[$searchkey] = $sk->makeStubLinkObj( $title, $texts[$key], $queries[$key] );
 924+ $outputReplace[$searchkey] = $sk->makeStubLinkObj( $title,
 925+ $wgLinkHolders['texts'][$key],
 926+ $wgLinkHolders['queries'][$key] );
932927 }
933928 }
934929 wfProfileOut( $fname.'-construct' );
@@ -936,7 +931,7 @@
937932 wfProfileIn( $fname.'-replace' );
938933
939934 $text = preg_replace_callback(
940 - '/(<!--LINK .*? .*? .*? .*?-->)/',
 935+ '/(<!--LINK .*?-->)/',
941936 "outputReplaceMatches",
942937 $text);
943938 wfProfileOut( $fname.'-replace' );

Follow-up revisions

RevisionCommit summaryAuthorDate
r5361Instead of storing entire link attributes in wikitext for...jeluf17:57, 21 September 2004

Status & tagging log