(bug 40352) fixDoubleRedirects.php: Support interwiki redirects
authorTimo Tijhof <ttijhof@wikimedia.org>
Wed, 19 Sep 2012 13:32:30 +0000 (15:32 +0200)
committerTimo Tijhof <ttijhof@wikimedia.org>
Wed, 26 Sep 2012 07:16:42 +0000 (09:16 +0200)
While at it, prettified code a bit and added list to output.

Change-Id: I989b5742ad46a9dd8c928a4ff5f76c869924730e

RELEASE-NOTES-1.20
includes/job/DoubleRedirectJob.php
maintenance/fixDoubleRedirects.php

index 3ba5a13..ba828d8 100644 (file)
@@ -248,6 +248,7 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
 * (bug 39941) Add missing stylesheets to the installer pages
 * In HTML5 mode, allow new input element types values (such as color, range..)
 * (bug 40353) SpecialDoubleRedirect should support for interwiki redirects.
+* (bug 40352) fixDoubleRedirects.php should support for interwiki redirects.
 
 === API changes in 1.20 ===
 * (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API.
@@ -286,7 +287,7 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
 * (bug 11142) Improve file extension blacklist error reporting in API upload.
 * (bug 39665) Cache AllowedGenerator array so it doesn't autoload all query classes
   on every request.
-* (bug 35693) ApiQueryImageInfo now suppresses errors when unserializing metadata
+* (bug 35693) ApiQueryImageInfo now suppresses errors when unserializing metadata.
 
 === Languages updated in 1.20 ===
 
index 08af997..f9c4b0f 100644 (file)
@@ -27,7 +27,7 @@
  * @ingroup JobQueue
  */
 class DoubleRedirectJob extends Job {
-       var $reason, $redirTitle, $destTitleText;
+       var $reason, $redirTitle;
 
        /**
         * @var User
@@ -77,7 +77,6 @@ class DoubleRedirectJob extends Job {
                parent::__construct( 'fixDoubleRedirect', $title, $params, $id );
                $this->reason = $params['reason'];
                $this->redirTitle = Title::newFromText( $params['redirTitle'] );
-               $this->destTitleText = !empty( $params['destTitle'] ) ? $params['destTitle'] : '';
        }
 
        /**
@@ -122,7 +121,7 @@ class DoubleRedirectJob extends Job {
 
                # Preserve fragment (bug 14904)
                $newTitle = Title::makeTitle( $newTitle->getNamespace(), $newTitle->getDBkey(),
-                       $currentDest->getFragment() );
+                       $currentDest->getFragment(), $newTitle->getInterwiki() );
 
                # Fix the text
                # Remember that redirect pages can have categories, templates, etc.,
@@ -171,9 +170,17 @@ class DoubleRedirectJob extends Job {
                        }
                        $seenTitles[$titleText] = true;
 
+                       if ( $title->getInterwiki() ) {
+                               // If the target is interwiki, we have to break early (bug 40352).
+                               // Otherwise it will look up a row in the local page table
+                               // with the namespace/page of the interwiki target which can cause
+                               // unexpected results (e.g. X -> foo:Bar -> Bar -> .. )
+                               break;
+                       }
+
                        $row = $dbw->selectRow(
                                array( 'redirect', 'page' ),
-                               array( 'rd_namespace', 'rd_title' ),
+                               array( 'rd_namespace', 'rd_title', 'rd_interwiki' ),
                                array(
                                        'rd_from=page_id',
                                        'page_namespace' => $title->getNamespace(),
@@ -183,7 +190,7 @@ class DoubleRedirectJob extends Job {
                                # No redirect from here, chain terminates
                                break;
                        } else {
-                               $dest = $title = Title::makeTitle( $row->rd_namespace, $row->rd_title );
+                               $dest = $title = Title::makeTitle( $row->rd_namespace, $row->rd_title, '', $row->rd_interwiki );
                        }
                }
                return $dest;
index 6f017ec..d808500 100644 (file)
@@ -55,7 +55,12 @@ class FixDoubleRedirects extends Maintenance {
 
                $dbr = wfGetDB( DB_SLAVE );
 
-               $tables = array( 'redirect', 'pa' => 'page', 'pb' => 'page' );
+               // See also SpecialDoubleRedirects
+               $tables = array(
+                       'redirect',
+                       'pa' => 'page',
+                       'pb' => 'page',
+               );
                $fields = array(
                        'pa.page_namespace AS pa_namespace',
                        'pa.page_title AS pa_title',
@@ -66,6 +71,7 @@ class FixDoubleRedirects extends Maintenance {
                        'rd_from = pa.page_id',
                        'rd_namespace = pb.page_namespace',
                        'rd_title = pb.page_title',
+                       '(rd_interwiki IS NULL OR rd_interwiki = "")', // bug 40352
                        'pb.page_is_redirect' => 1,
                );
 
@@ -83,12 +89,18 @@ class FixDoubleRedirects extends Maintenance {
                }
 
                $jobs = array();
+               $processedTitles = "\n";
                $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() ) );
+                       $processedTitles .= "* [[$titleA]]\n";
+
+                       $job = new DoubleRedirectJob( $titleA, array(
+                               'reason' => 'maintenance',
+                               'redirTitle' => $titleB->getPrefixedDBkey()
+                       ) );
 
                        if ( !$async ) {
                                $success = ( $dryrun ? true : $job->run() );
@@ -112,7 +124,7 @@ class FixDoubleRedirects extends Maintenance {
                if ( count( $jobs ) ) {
                        $this->queueJobs( $jobs, $dryrun );
                }
-               $this->output( "$n double redirects processed.\n" );
+               $this->output( "$n double redirects processed" . $processedTitles . "\n" );
        }
 
        protected function queueJobs( $jobs, $dryrun = false ) {