From: Timo Tijhof Date: Wed, 19 Sep 2012 13:32:30 +0000 (+0200) Subject: (bug 40352) fixDoubleRedirects.php: Support interwiki redirects X-Git-Tag: 1.31.0-rc.0~22273 X-Git-Url: http://git.cyclocoop.org//%22%22._DIR_PLUGIN_FULLCALENDAR.%22prive/themes/spip/images/event_edit.png/%22?a=commitdiff_plain;h=f85255bd3b1255b642f529cb90882898176b4cf7;p=lhc%2Fweb%2Fwiklou.git (bug 40352) fixDoubleRedirects.php: Support interwiki redirects While at it, prettified code a bit and added list to output. Change-Id: I989b5742ad46a9dd8c928a4ff5f76c869924730e --- diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index 3ba5a13897..ba828d8fec 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -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 === diff --git a/includes/job/DoubleRedirectJob.php b/includes/job/DoubleRedirectJob.php index 08af997585..f9c4b0fff2 100644 --- a/includes/job/DoubleRedirectJob.php +++ b/includes/job/DoubleRedirectJob.php @@ -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; diff --git a/maintenance/fixDoubleRedirects.php b/maintenance/fixDoubleRedirects.php index 6f017eca48..d808500d3d 100644 --- a/maintenance/fixDoubleRedirects.php +++ b/maintenance/fixDoubleRedirects.php @@ -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 ) {