From 4849760a2004d71a866529bec8dc8c49e116c388 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Robert=20Stojni=C4=87?= Date: Mon, 9 Jul 2007 23:38:54 +0000 Subject: [PATCH] Add --redirects-only switch to refreshLinks.php, which refreshes the redirect table, maybe this should be done by default as well. --- maintenance/refreshLinks.inc | 38 ++++++++++++++++++++++++++++++------ maintenance/refreshLinks.php | 2 +- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/maintenance/refreshLinks.inc b/maintenance/refreshLinks.inc index 7a560e973c..9e4eea8d6b 100644 --- a/maintenance/refreshLinks.inc +++ b/maintenance/refreshLinks.inc @@ -8,7 +8,7 @@ define( "REPORTING_INTERVAL", 100 ); #define( "REPORTING_INTERVAL", 1 ); -function refreshLinks( $start, $newOnly = false, $maxLag = false, $end = 0 ) { +function refreshLinks( $start, $newOnly = false, $maxLag = false, $end = 0, $redirectsOnly = false ) { global $wgUser, $wgParser, $wgUseImageResize, $wgUseTidy; $fname = 'refreshLinks'; @@ -25,8 +25,10 @@ function refreshLinks( $start, $newOnly = false, $maxLag = false, $end = 0 ) { $wgUseImageResize = false; $wgUseTidy = false; + $what = ($redirectsOnly)? "redirects" : "links"; + if ( $newOnly ) { - print "Refreshing links from "; + print "Refreshing $what from "; $res = $dbr->select( 'page', array( 'page_id' ), array( @@ -43,11 +45,13 @@ function refreshLinks( $start, $newOnly = false, $maxLag = false, $end = 0 ) { print "$i\n"; wfWaitForSlaves( $maxLag ); } - - fixLinksFromArticle( $row->page_id ); + if($redirectsOnly) + fixRedirect( $row->page_id ); + else + fixLinksFromArticle( $row->page_id ); } } else { - print "Refreshing link table.\n"; + print "Refreshing $what table.\n"; if ( !$end ) { $end = $dbr->selectField( 'page', 'max(page_id)', false ); } @@ -59,11 +63,33 @@ function refreshLinks( $start, $newOnly = false, $maxLag = false, $end = 0 ) { print "$id\n"; wfWaitForSlaves( $maxLag ); } - fixLinksFromArticle( $id ); + if($redirectsOnly) + fixRedirect( $id ); + else + fixLinksFromArticle( $id ); } } } +function fixRedirect( $id ){ + global $wgTitle, $wgArticle; + + $wgTitle = Title::newFromID( $id ); + $dbw = wfGetDB( DB_MASTER ); + + if ( is_null( $wgTitle ) ) { + return; + } + $wgArticle = new Article($wgTitle); + + $rt = $wgArticle->followRedirect(); + + if($rt == false || !is_object($rt)) + return; + + $wgArticle->updateRedirectOn($dbw,$rt); +} + function fixLinksFromArticle( $id ) { global $wgTitle, $wgParser; diff --git a/maintenance/refreshLinks.php b/maintenance/refreshLinks.php index 5c1e00404c..34ca53c510 100644 --- a/maintenance/refreshLinks.php +++ b/maintenance/refreshLinks.php @@ -18,7 +18,7 @@ if ( !$options['dfn-only'] ) { $start = 1; } - refreshLinks( $start, $options['new-only'], $options['m'], $options['e'] ); + refreshLinks( $start, $options['new-only'], $options['m'], $options['e'], $options['redirects-only'] ); } // this bit's bad for replication: disabling temporarily // --brion 2005-07-16 -- 2.20.1