Index: trunk/phase3/maintenance/fixDoubleRedirects.php |
— | — | @@ -0,0 +1,120 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Script to fix double redirects. |
| 5 | + * |
| 6 | + * Copyright (C) 2010 Ilmari Karonen <nospam@vyznev.net> |
| 7 | + * http://www.mediawiki.org/ |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU General Public License as published by |
| 11 | + * the Free Software Foundation; either version 2 of the License, or |
| 12 | + * (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License along |
| 20 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 | + * http://www.gnu.org/copyleft/gpl.html |
| 23 | + * |
| 24 | + * @file |
| 25 | + * @author Ilmari Karonen <nospam@vyznev.net> |
| 26 | + * @ingroup Maintenance |
| 27 | + */ |
| 28 | + |
| 29 | +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
| 30 | + |
| 31 | +class FixDoubleRedirects extends Maintenance { |
| 32 | + public function __construct() { |
| 33 | + parent::__construct(); |
| 34 | + $this->mDescription = "Script to fix double redirects"; |
| 35 | + $this->addOption( 'async', 'Don\'t fix anything directly, just add queue the jobs' ); |
| 36 | + $this->addOption( 'title', 'Fix only redirects pointing to this page', false, true ); |
| 37 | + $this->addOption( 'dry-run', 'Perform a dry run, fix nothing' ); |
| 38 | + } |
| 39 | + |
| 40 | + public function execute() { |
| 41 | + $async = $this->getOption( 'async', false ); |
| 42 | + $dryrun = $this->getOption( 'dry-run', false ); |
| 43 | + $title = $this->getOption( 'title' ); |
| 44 | + |
| 45 | + if ( isset( $title ) ) { |
| 46 | + $title = Title::newFromText( $title ); |
| 47 | + if ( !$title || !$title->isRedirect() ) { |
| 48 | + $this->error( $title->getPrefixedText() . " is not a redirect!\n", true ); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + $dbr = wfGetDB( DB_SLAVE ); |
| 53 | + |
| 54 | + $tables = array( 'redirect', 'pa' => 'page', 'pb' => 'page' ); |
| 55 | + $fields = array( |
| 56 | + 'pa.page_namespace AS pa_namespace', |
| 57 | + 'pa.page_title AS pa_title', |
| 58 | + 'pb.page_namespace AS pb_namespace', |
| 59 | + 'pb.page_title AS pb_title', |
| 60 | + ); |
| 61 | + $conds = array( |
| 62 | + 'rd_from = pa.page_id', |
| 63 | + 'rd_namespace = pb.page_namespace', |
| 64 | + 'rd_title = pb.page_title', |
| 65 | + 'pb.page_is_redirect' => 1, |
| 66 | + ); |
| 67 | + |
| 68 | + if ( isset( $title ) ) { |
| 69 | + $conds['pb.page_namespace'] = $title->getNamespace(); |
| 70 | + $conds['pb.page_title'] = $title->getDBkey(); |
| 71 | + } |
| 72 | + // TODO: support batch querying |
| 73 | + |
| 74 | + $res = $dbr->select( $tables, $fields, $conds, __METHOD__ ); |
| 75 | + |
| 76 | + if ( !$res->numRows() ) { |
| 77 | + $this->output( "No double redirects found.\n" ); |
| 78 | + return; |
| 79 | + } |
| 80 | + |
| 81 | + $jobs = array(); |
| 82 | + $n = 0; |
| 83 | + foreach ( $res as $row ) { |
| 84 | + $titleA = Title::makeTitle( $row->pa_namespace, $row->pa_title ); |
| 85 | + $titleB = Title::makeTitle( $row->pb_namespace, $row->pb_title ); |
| 86 | + |
| 87 | + $job = new DoubleRedirectJob( $titleA, array( 'reason' => 'maintenance', 'redirTitle' => $titleB->getPrefixedDBkey() ) ); |
| 88 | + |
| 89 | + if ( !$async ) { |
| 90 | + $success = ( $dryrun ? true : $job->run() ); |
| 91 | + if ( !$success ) { |
| 92 | + $this->error( "Error fixing " . $titleA->getPrefixedText() . ": " . $job->getLastError() . "\n" ); |
| 93 | + } |
| 94 | + } else { |
| 95 | + $jobs[] = $job; |
| 96 | + // FIXME: hardcoded constant 10000 copied from DoubleRedirectFixer class |
| 97 | + if ( count( $jobs ) > 10000 ) { |
| 98 | + $this->queueJobs( $jobs, $dryrun ); |
| 99 | + $jobs = array(); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + if ( ++$n % 100 == 0 ) { |
| 104 | + $this->output( "$n...\n" ); |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + if ( count( $jobs ) ) { |
| 109 | + $this->queueJobs( $jobs, $dryrun ); |
| 110 | + } |
| 111 | + $this->output( "$n double redirects processed.\n" ); |
| 112 | + } |
| 113 | + |
| 114 | + protected function queueJobs( $jobs, $dryrun = false ) { |
| 115 | + $this->output( "Queuing batch of " . count( $jobs ) . " double redirects.\n" ); |
| 116 | + Job::batchInsert( $dryrun ? array() : $jobs ); |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +$maintClass = "FixDoubleRedirects"; |
| 121 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Property changes on: trunk/phase3/maintenance/fixDoubleRedirects.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 122 | + native |
Index: trunk/phase3/languages/messages/MessagesQqq.php |
— | — | @@ -2050,6 +2050,7 @@ |
2051 | 2051 | 'doubleredirects' => 'Name of [[Special:DoubleRedirects]] displayed in [[Special:SpecialPages]]', |
2052 | 2052 | 'doubleredirectstext' => 'Shown on top of [[Special:Doubleredirects]]', |
2053 | 2053 | 'double-redirect-fixed-move' => 'This is the message in the log when the software (under the username {{msg|double-redirect-fixer}}) updates the redirects after a page move. See also {{msg|fix-double-redirects}}.', |
| 2054 | +'double-redirect-fixed-maintenance' => 'This is the message in the log when the software (under the username {{msg|double-redirect-fixer}}) updates the redirects after running maintenance/fixDoubleRedirects.php. Compare with {{msg|double-redirect-fixed-move}}.', |
2054 | 2055 | 'double-redirect-fixer' => "This is the '''username''' of the user who updates the double redirects after a page move. A user is created with this username, so it is perhaps better to not change this message too often. See also {{msg|double-redirect-fixed-move}} and {{msg|fix-double-redirects}}.", |
2055 | 2056 | |
2056 | 2057 | 'brokenredirects' => 'Name of [[Special:BrokenRedirects]] displayed in [[Special:SpecialPages]]', |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -2435,6 +2435,7 @@ |
2436 | 2436 | <del>Crossed out</del> entries have been solved.', |
2437 | 2437 | 'double-redirect-fixed-move' => '[[$1]] has been moved. |
2438 | 2438 | It now redirects to [[$2]].', |
| 2439 | +'double-redirect-fixed-maintenance' => 'Fixing double redirect from [[$1]] to [[$2]].', |
2439 | 2440 | 'double-redirect-fixer' => 'Redirect fixer', |
2440 | 2441 | |
2441 | 2442 | 'brokenredirects' => 'Broken redirects', |
Index: trunk/phase3/languages/messages/MessagesFi.php |
— | — | @@ -1871,6 +1871,7 @@ |
1872 | 1872 | Jokaisella rivillä on linkit ensimmäiseen ja toiseen ohjaukseen sekä toisen ohjauksen kohteen ensimmäiseen riviin, eli yleensä ”oikeaan” kohteeseen, johon ensimmäisen ohjauksen pitäisi osoittaa. |
1873 | 1873 | <del>Yliviivatut</del> kohteet on korjattu.', |
1874 | 1874 | 'double-redirect-fixed-move' => '[[$1]] on siirretty, ja se ohjaa nyt sivulle [[$2]]', |
| 1875 | +'double-redirect-fixed-maintenance' => 'Korjataan kaksinkertainen ohjaus sivulta [[$1]] sivulle [[$2]]', |
1875 | 1876 | 'double-redirect-fixer' => 'Ohjausten korjaaja', |
1876 | 1877 | |
1877 | 1878 | 'brokenredirects' => 'Virheelliset ohjaukset', |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -58,6 +58,7 @@ |
59 | 59 | * (bug 26285) Extensions will be automatically generated on upload if the user |
60 | 60 | specified a filename without extension. |
61 | 61 | * (bug 26851) Special:UserRights now allows to prefill the reason field |
| 62 | +* New maintenance script to fix double redirects (maintenance/fixDoubleRedirects.php) |
62 | 63 | |
63 | 64 | === Bug fixes in 1.18 === |
64 | 65 | * (bug 23119) WikiError class and subclasses are now marked as deprecated |