Make refreshLinks.php purge orphaned redirect table rows, i.e. rows whose rd_from...
authorRoan Kattouw <catrope@users.mediawiki.org>
Tue, 29 Dec 2009 11:44:45 +0000 (11:44 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Tue, 29 Dec 2009 11:44:45 +0000 (11:44 +0000)
RELEASE-NOTES
maintenance/refreshLinks.php

index a6a5444..5830443 100644 (file)
@@ -665,6 +665,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 21535) RecentChanges RSS feed now always recognises the namespace filter,
   previously it sometimes didn't due to caching.
 * (bug 20388) ProfilerSimpleText no longer outputs comment on action=raw
+* refreshLinks.php now purges orphaned redirect table rows
 
 == API changes in 1.16 ==
 
index 6dccefb..5820d5b 100644 (file)
@@ -123,7 +123,9 @@ class RefreshLinks extends Maintenance {
                        }
                } else {
                        if ( !$end ) {
-                               $end = $dbr->selectField( 'page', 'max(page_id)', false );
+                               $maxPage = $dbr->selectField( 'page', 'max(page_id)', false );
+                               $maxRD = $dbr->selectField( 'redirect', 'max(rd_from)', false );
+                               $end = max( $maxPage, $maxRD );
                        }
                        $this->output( "Refreshing redirects table.\n" );
                        $this->output( "Starting from page_id $start of $end.\n" );
@@ -164,16 +166,24 @@ class RefreshLinks extends Maintenance {
                $dbw = wfGetDB( DB_MASTER );
        
                if ( is_null( $wgTitle ) ) {
+                       // This page doesn't exist (any more)
+                       // Delete any redirect table entry for it
+                       $dbw->delete( 'redirect', array( 'rd_from' => $id ),
+                               __METHOD__ );
                        return;
                }
                $wgArticle = new Article($wgTitle);
        
                $rt = $wgArticle->followRedirect();
        
-               if($rt == false || !is_object($rt))
-                       return;
-       
-               $wgArticle->updateRedirectOn($dbw,$rt);
+               if($rt == false || !is_object($rt)) {
+                       // $wgTitle is not a redirect
+                       // Delete any redirect table entry for it
+                       $dbw->delete( 'redirect', array( 'rd_from' => $id ),
+                               __METHOD__ );
+               } else {
+                       $wgArticle->updateRedirectOn($dbw,$rt);
+               }
        }
 
        /**