Add --redirects-only switch to refreshLinks.php, which refreshes the redirect table...
authorRobert Stojnić <rainman@users.mediawiki.org>
Mon, 9 Jul 2007 23:38:54 +0000 (23:38 +0000)
committerRobert Stojnić <rainman@users.mediawiki.org>
Mon, 9 Jul 2007 23:38:54 +0000 (23:38 +0000)
maintenance/refreshLinks.inc
maintenance/refreshLinks.php

index 7a560e9..9e4eea8 100644 (file)
@@ -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;
        
index 5c1e004..34ca53c 100644 (file)
@@ -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