r2082 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r2081‎ | r2082 | r2083 >
Date:16:31, 27 November 2003
Author:e23
Status:old
Tags:
Comment:
Fixed bug causing 'what links here' on image pages to break. Fixed bug causing problems on pages with same links with different capitalization.
Modified paths:
  • /trunk/phase3/maintenance/rebuildlinks.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/rebuildlinks.inc
@@ -97,7 +97,7 @@
9898 $numlinks = preg_match_all( "/\\[\\[([{$tc}]+)(]|\\|)/", $text,
9999 $m, PREG_PATTERN_ORDER );
100100
101 - $seen_links = array(); // seen links in this article
 101+ $seen_dbtitles = array(); // seen links (normalized and with ns, see below)
102102 $titles_ready_for_insertion = array();
103103 $titles_needing_curdata = array();
104104 $titles_needing_curdata_pos = array();
@@ -105,12 +105,6 @@
106106
107107 for ( $i = 0 ; $i < $numlinks; ++$i ) {
108108 $link = $m[1][$i];
109 -
110 - // We're only interested in the link once per article
111 - if( isset( $seen_links[$link] ) )
112 - continue;
113 - $seen_links[$link] = 1;
114 -
115109 if( preg_match( '/^(http|https|ftp|mailto|news):/', $m[1][$i] ) ) {
116110 # an URL link; not for us!
117111 continue;
@@ -119,13 +113,26 @@
120114 # FIXME: Handle subpage links
121115 $nt = $titleCache->get( $link );
122116 if( $nt != false ){
123 - $titles_ready_for_insertion[] = $nt;
 117+ // Only process each unique link once per page
 118+ $nt_key = $nt->getDBkey() . $nt->getNamespace();
 119+ if( isset( $seen_dbtitles[$nt_key] ) )
 120+ continue;
 121+ $seen_dbtitles[$nt_key] = 1;
 122+
 123+ $titles_ready_for_insertion[] = $nt;
124124 } else {
125125 $nt = Title::newFromText( $link );
126126 if (! $nt) {
127 - print "\nerror in '$ns:{$from_full_title}': '$link'\n";
 127+ print "\nInvalid link in page '$ns:{$from_full_title}': '$link'\n";
128128 continue;
129129 }
 130+
 131+ // Only process each unique link once per page
 132+ $nt_key = $nt->getDBkey() . $nt->getNamespace();
 133+ if( isset( $seen_dbtitles[$nt_key] ) )
 134+ continue;
 135+ $seen_dbtitles[$nt_key] = 1;
 136+
130137 if( $nt->getInterwiki() != "" ) {
131138 # Interwiki links are not stored in the link tables
132139 continue;
@@ -152,8 +159,7 @@
153160 $parts = array();
154161 foreach ($titles_needing_curdata as $nt ) {
155162 $parts[] = " (cur_namespace = " . $nt->getNamespace() . " AND " .
156 - "cur_title='" . wfStrencode( $nt->getDBkey() ) . "' AND ".
157 - "cur_namespace=" . intval( $nt->getNamespace() ) . ")";
 163+ "cur_title='" . wfStrencode( $nt->getDBkey() ) . "')";
158164 }
159165 $sql = "SELECT cur_title, cur_id FROM cur WHERE " . implode(" OR ", $parts);
160166 $res = wfQuery( $sql, DB_WRITE );
@@ -169,13 +175,15 @@
170176 }
171177
172178 foreach ( $titles_ready_for_insertion as $nt ) {
173 - $dest = addslashes( $nt->getPrefixedDBkey() );
 179+ $dest_noslashes = $nt->getPrefixedDBkey();
 180+ $dest = addslashes( $dest_noslashes );
174181 $dest_id = $nt->getArticleID();
175182 $from = $from_full_title_with_slashes;
176183
177184 # print "\nLINK '$from_full_title' ($from_id) -> '$dest' ($dest_id)\n";
178 - if ( 0 == strncmp( "$ins:", $from_full_title, $inslen ) ) {
179 - $iname = addslashes( substr( $from_full_title, $inslen ) );
 185+
 186+ if ( 0 == strncmp( "$ins:", $dest_noslashes, $inslen ) ) {
 187+ $iname = addslashes( substr( $dest_noslashes, $inslen ) );
180188 $imagelinks_inserter->insert( "('{$from}','{$iname}')" );
181189 } else if ( 0 == $dest_id ) {
182190 $brokenlinks_inserter->insert( "({$from_id},'{$dest}')" );

Status & tagging log