From 13adb2866a8461c61a89d110c7be891ac3aa805b Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Tue, 29 Dec 2009 11:44:45 +0000 Subject: [PATCH] Make refreshLinks.php purge orphaned redirect table rows, i.e. rows whose rd_from refers to a page that's not a redirect or doesn't even exist --- RELEASE-NOTES | 1 + maintenance/refreshLinks.php | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a6a54446e7..58304432ca 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/maintenance/refreshLinks.php b/maintenance/refreshLinks.php index 6dccefb335..5820d5bfff 100644 --- a/maintenance/refreshLinks.php +++ b/maintenance/refreshLinks.php @@ -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); + } } /** -- 2.20.1