From: Aryeh Gregor Date: Wed, 5 Mar 2008 03:50:12 +0000 (+0000) Subject: Add --old-redirects-only option to maintenance/refreshLinks.php, to add old redirects... X-Git-Tag: 1.31.0-rc.0~49249 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/ajouter.php?a=commitdiff_plain;h=6b79f5995a0f6d19460537310621882d89f0902c;p=lhc%2Fweb%2Fwiklou.git Add --old-redirects-only option to maintenance/refreshLinks.php, to add old redirects to the redirect table. This may be worth trying out on at least some of the smaller wikis. It seems to work correctly, and pretty quickly for a couple thousand redirects to fix, although truncating the redirect table and running it inevitably gives a different number (probably due to incorrect redirect table entries to start with). With the limit options, it might be tried on bigger wikis too. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 7aa01ce36e..ed8418d241 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/maintenance/refreshLinks.inc b/maintenance/refreshLinks.inc index e89db8aa03..c471d0eece 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, $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 ); diff --git a/maintenance/refreshLinks.php b/maintenance/refreshLinks.php index 67fb77aebf..3b4780ee02 100644 --- a/maintenance/refreshLinks.php +++ b/maintenance/refreshLinks.php @@ -11,13 +11,20 @@ require_once( "refreshLinks.inc" ); if( isset( $options['help'] ) ) { echo <<] [-e ] [-m ] [--help] - - --help : This help message - --dfn-only : Delete links from nonexistent articles only - -m : Maximum replication lag - : First page id to refresh - -e : Last page id to refresh +Usage: + php refreshLinks.php --help + php refreshLinks.php [] [-e ] [-m ] [--dfn-only] + [--new-only] [--redirects-only] + php refreshLinks.php [] [-e ] [-m ] --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 : Maximum replication lag + : First page id to refresh + -e : 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