Add --old-redirects-only option to maintenance/refreshLinks.php, to add old redirects...
authorAryeh Gregor <simetrical@users.mediawiki.org>
Wed, 5 Mar 2008 03:50:12 +0000 (03:50 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Wed, 5 Mar 2008 03:50:12 +0000 (03:50 +0000)
RELEASE-NOTES
maintenance/refreshLinks.inc
maintenance/refreshLinks.php

index 7aa01ce..ed8418d 100644 (file)
@@ -36,7 +36,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 13112) Added Special:RelatedChanges alias to Special:Recentchangeslinked
 * (bug 13130) Moved edit token and autosummary fields above edit tools to
   reduce broken form submissions
-
+* Add --old-redirects-only option to maintenance/refreshLinks.php, to add old
+  redirects to the redirect table
 
 === Bug fixes in 1.13 ===
 
index e89db8a..c471d0e 100644 (file)
@@ -8,7 +8,7 @@
 define( "REPORTING_INTERVAL", 100 );
 #define( "REPORTING_INTERVAL", 1 );
 
-function refreshLinks( $start, $newOnly = false, $maxLag = false, $end = 0, $redirectsOnly = false ) {
+function refreshLinks( $start, $newOnly = false, $maxLag = false, $end = 0, $redirectsOnly = false, $oldRedirectsOnly = false ) {
        global $wgUser, $wgParser, $wgUseImageResize, $wgUseTidy;
 
        $fname = 'refreshLinks';
@@ -25,15 +25,36 @@ function refreshLinks( $start, $newOnly = false, $maxLag = false, $end = 0, $red
        $wgUseImageResize = false;
        $wgUseTidy = false;
 
-       $what = ($redirectsOnly)? "redirects" : "links";
+       $what = $redirectsOnly ? "redirects" : "links";
+
+       if( $oldRedirectsOnly ) {
+               # This entire code path is cut-and-pasted from below.  Hurrah.
+               $res = $dbr->query(
+                       "SELECT page_id ".
+                       "FROM page ".
+                       "LEFT JOIN redirect ON page_id=rd_from ".
+                       "WHERE page_is_redirect=1 AND rd_from IS NULL AND ".
+                       ($end == 0 ? "page_id >= $start"
+                                  : "page_id BETWEEN $start AND $end"),
+                       $fname
+               );
+               $num = $dbr->numRows( $res );
+               print "Refreshing $num old redirects from $start...\n";
 
-       if ( $newOnly ) {
+               while( $row = $dbr->fetchObject( $res ) ) {
+                       if ( !( ++$i % REPORTING_INTERVAL ) ) {
+                               print "$i\n";
+                               wfWaitForSlaves( $maxLag );
+                       }
+                       fixRedirect( $row->page_id );
+               }
+       } elseif( $newOnly ) {
                print "Refreshing $what from ";
                $res = $dbr->select( 'page',
                        array( 'page_id' ),
                        array(
                                'page_is_new' => 1,
-                               "page_id > $start" ),
+                               "page_id >= $start" ),
                        $fname
                );
                $num = $dbr->numRows( $res );
index 67fb77a..3b4780e 100644 (file)
@@ -11,13 +11,20 @@ require_once( "refreshLinks.inc" );
 
 if( isset( $options['help'] ) ) {
        echo <<<TEXT
-Usage: php refreshLinks.php [<start>] [-e <end>] [-m <maxlag>] [--help] 
-
-    --help      : This help message
-    --dfn-only  : Delete links from nonexistent articles only
-    -m <number> : Maximum replication lag
-    <start>     : First page id to refresh
-    -e <number> : Last page id to refresh
+Usage:
+    php refreshLinks.php --help
+    php refreshLinks.php [<start>] [-e <end>] [-m <maxlag>] [--dfn-only]
+                         [--new-only] [--redirects-only]
+    php refreshLinks.php [<start>] [-e <end>] [-m <maxlag>] --old-redirects-only
+
+    --help               : This help message
+    --dfn-only           : Delete links from nonexistent articles only
+    --new-only           : Only affect articles with just a single edit
+    --redirects-only     : Only fix redirects, not all links
+    --old-redirects-only : Only fix redirects with no redirect table entry
+    -m <number>          : Maximum replication lag
+    <start>              : First page id to refresh
+    -e <number>          : Last page id to refresh
 
 TEXT;
        exit(0);
@@ -32,7 +39,7 @@ if ( !$options['dfn-only'] ) {
                $start = 1;
        }
 
-       refreshLinks( $start, $options['new-only'], $options['m'], $options['e'], $options['redirects-only'] );
+       refreshLinks( $start, $options['new-only'], $options['m'], $options['e'], $options['redirects-only'], $options['old-redirects-only'] );
 }
 // this bit's bad for replication: disabling temporarily
 // --brion 2005-07-16