Add a maintenance script to fix double redirects (and corresponding edit summary...
authorIlmari Karonen <vyznev@users.mediawiki.org>
Wed, 2 Feb 2011 19:25:53 +0000 (19:25 +0000)
committerIlmari Karonen <vyznev@users.mediawiki.org>
Wed, 2 Feb 2011 19:25:53 +0000 (19:25 +0000)
RELEASE-NOTES
languages/messages/MessagesEn.php
languages/messages/MessagesFi.php
languages/messages/MessagesQqq.php
maintenance/fixDoubleRedirects.php [new file with mode: 0644]

index 89459c6..aa236a1 100644 (file)
@@ -58,6 +58,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 26285) Extensions will be automatically generated on upload if the user
   specified a filename without extension.
 * (bug 26851) Special:UserRights now allows to prefill the reason field
+* New maintenance script to fix double redirects (maintenance/fixDoubleRedirects.php)
 
 === Bug fixes in 1.18 ===
 * (bug 23119) WikiError class and subclasses are now marked as deprecated
index 4aadb9d..26dc3ca 100644 (file)
@@ -2435,6 +2435,7 @@ Each row contains links to the first and second redirect, as well as the target
 <del>Crossed out</del> entries have been solved.',
 'double-redirect-fixed-move' => '[[$1]] has been moved.
 It now redirects to [[$2]].',
+'double-redirect-fixed-maintenance' => 'Fixing double redirect from [[$1]] to [[$2]].',
 'double-redirect-fixer'      => 'Redirect fixer',
 
 'brokenredirects'         => 'Broken redirects',
index 16f4861..0bd7b89 100644 (file)
@@ -1871,6 +1871,7 @@ Tiedot [$2 tiedoston kuvaussivulta] näkyvät alla.',
 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.
 <del>Yliviivatut</del> kohteet on korjattu.',
 'double-redirect-fixed-move' => '[[$1]] on siirretty, ja se ohjaa nyt sivulle [[$2]]',
+'double-redirect-fixed-maintenance' => 'Korjataan kaksinkertainen ohjaus sivulta [[$1]] sivulle [[$2]]',
 'double-redirect-fixer'      => 'Ohjausten korjaaja',
 
 'brokenredirects'        => 'Virheelliset ohjaukset',
index 090ffbe..74665ff 100644 (file)
@@ -2050,6 +2050,7 @@ Possible alternatives to the word 'content' are 'subject matter' or 'wiki subjec
 'doubleredirects'            => 'Name of [[Special:DoubleRedirects]] displayed in [[Special:SpecialPages]]',
 'doubleredirectstext'        => 'Shown on top of [[Special:Doubleredirects]]',
 '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}}.',
+'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}}.',
 '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}}.",
 
 'brokenredirects'        => 'Name of [[Special:BrokenRedirects]] displayed in [[Special:SpecialPages]]',
diff --git a/maintenance/fixDoubleRedirects.php b/maintenance/fixDoubleRedirects.php
new file mode 100644 (file)
index 0000000..a6eb667
--- /dev/null
@@ -0,0 +1,120 @@
+<?php
+/**
+ * Script to fix double redirects.
+ *
+ * Copyright (C) 2010 Ilmari Karonen <nospam@vyznev.net>
+ * http://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @author Ilmari Karonen <nospam@vyznev.net>
+ * @ingroup Maintenance
+ */
+
+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+
+class FixDoubleRedirects extends Maintenance {
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "Script to fix double redirects";
+               $this->addOption( 'async', 'Don\'t fix anything directly, just add queue the jobs' );
+               $this->addOption( 'title', 'Fix only redirects pointing to this page', false, true );
+               $this->addOption( 'dry-run', 'Perform a dry run, fix nothing' );                
+       }
+
+       public function execute() {
+               $async = $this->getOption( 'async', false );
+               $dryrun = $this->getOption( 'dry-run', false );
+               $title = $this->getOption( 'title' );
+
+               if ( isset( $title ) ) {
+                       $title = Title::newFromText( $title );
+                       if ( !$title || !$title->isRedirect() ) {
+                               $this->error( $title->getPrefixedText() . " is not a redirect!\n", true );
+                       }
+               }
+
+               $dbr = wfGetDB( DB_SLAVE );
+
+               $tables = array( 'redirect', 'pa' => 'page', 'pb' => 'page' );
+               $fields = array(
+                       'pa.page_namespace AS pa_namespace',
+                       'pa.page_title AS pa_title',
+                       'pb.page_namespace AS pb_namespace',
+                       'pb.page_title AS pb_title',
+               );
+               $conds = array(
+                       'rd_from = pa.page_id',
+                       'rd_namespace = pb.page_namespace',
+                       'rd_title = pb.page_title',
+                       'pb.page_is_redirect' => 1,
+               );
+
+               if ( isset( $title ) ) {
+                       $conds['pb.page_namespace'] = $title->getNamespace();
+                       $conds['pb.page_title'] = $title->getDBkey();
+               }
+               // TODO: support batch querying
+
+               $res = $dbr->select( $tables, $fields, $conds, __METHOD__ );
+
+               if ( !$res->numRows() ) {
+                       $this->output( "No double redirects found.\n" );
+                       return;
+               }
+
+               $jobs = array();
+               $n = 0;
+               foreach ( $res as $row ) {
+                       $titleA = Title::makeTitle( $row->pa_namespace, $row->pa_title );
+                       $titleB = Title::makeTitle( $row->pb_namespace, $row->pb_title );
+
+                       $job = new DoubleRedirectJob( $titleA, array( 'reason' => 'maintenance', 'redirTitle' => $titleB->getPrefixedDBkey() ) );
+
+                       if ( !$async ) {
+                               $success = ( $dryrun ? true : $job->run() );
+                               if ( !$success ) {
+                                       $this->error( "Error fixing " . $titleA->getPrefixedText() . ": " . $job->getLastError() . "\n" );
+                               }
+                       } else {
+                               $jobs[] = $job;
+                               // FIXME: hardcoded constant 10000 copied from DoubleRedirectFixer class
+                               if ( count( $jobs ) > 10000 ) {
+                                       $this->queueJobs( $jobs, $dryrun );
+                                       $jobs = array();
+                               }
+                       }
+
+                       if ( ++$n % 100 == 0 ) {
+                               $this->output( "$n...\n" );
+                       }
+               }
+
+               if ( count( $jobs ) ) {
+                       $this->queueJobs( $jobs, $dryrun );
+               }
+               $this->output( "$n double redirects processed.\n" );
+       }
+
+       protected function queueJobs( $jobs, $dryrun = false ) {
+               $this->output( "Queuing batch of " . count( $jobs ) . " double redirects.\n" );
+               Job::batchInsert( $dryrun ? array() : $jobs );
+       }
+}
+
+$maintClass = "FixDoubleRedirects";
+require_once( RUN_MAINTENANCE_IF_MAIN );