aboutsummaryrefslogtreecommitdiffstats
path: root/maintenance
diff options
context:
space:
mode:
authorPppery <mapreader@olum.org>2024-07-30 12:46:10 -0400
committerPppery <mapreader@olum.org>2024-07-30 13:07:48 -0400
commit48e90e8ec547e1d99d5c0977fc8fc159185b6a90 (patch)
tree0d4e6f6babe852a15795f627d718edd3a87818d9 /maintenance
parent09d38b155724c7638c0d0c82caffbb328058d0ee (diff)
downloadmediawikicore-48e90e8ec547e1d99d5c0977fc8fc159185b6a90.tar.gz
mediawikicore-48e90e8ec547e1d99d5c0977fc8fc159185b6a90.zip
CleanupTitles: Turn "Talk:Project:Foo" into "Project talk:Foo"
Rather than a broken title. This is a common kind of invalid title as it happens if a new namespace or namespace alias is added. Bug: T196088 Change-Id: Ie7d32858a5267615995ff0eb8074edf4248c03d8
Diffstat (limited to 'maintenance')
-rw-r--r--maintenance/cleanupTitles.php47
1 files changed, 32 insertions, 15 deletions
diff --git a/maintenance/cleanupTitles.php b/maintenance/cleanupTitles.php
index 59deca399407..cfd825d250fb 100644
--- a/maintenance/cleanupTitles.php
+++ b/maintenance/cleanupTitles.php
@@ -129,40 +129,57 @@ class TitleCleanup extends TableCleanup {
$legalizedUnprefixed = '(space)';
}
$ns = (int)$row->page_namespace;
- // Move all broken pages to the main namespace so they can be found together
- if ( $ns !== 0 ) {
- $namespaceInfo = $this->getServiceContainer()->getNamespaceInfo();
- $namespaceName = $namespaceInfo->getCanonicalName( $ns );
- if ( $namespaceName === false ) {
- $namespaceName = "NS$ns"; // Fallback for unknown namespaces
+
+ $title = null;
+ // Try to move "Talk:Project:Foo" -> "Project talk:Foo"
+ if ( $ns === 1 ) {
+ $subjectTitle = Title::newFromText( $legalizedUnprefixed );
+ if ( $subjectTitle && !$subjectTitle->isTalkPage() ) {
+ $talkTitle = $subjectTitle->getTalkPageIfDefined();
+ if ( $talkTitle !== null && !$talkTitle->exists() ) {
+ $ns = $talkTitle->getNamespace();
+ $title = $talkTitle;
+ }
}
- $legalizedUnprefixed = "$namespaceName:$legalizedUnprefixed";
}
- $legalized = $this->prefix . $legalizedUnprefixed;
- $title = Title::newFromText( $legalized );
+ if ( $title === null ) {
+ // Not a talk page or that didn't work
+ // move any other broken pages to the main namespace so they can be found together
+ if ( $ns !== 0 ) {
+ $namespaceInfo = $this->getServiceContainer()->getNamespaceInfo();
+ $namespaceName = $namespaceInfo->getCanonicalName( $ns );
+ if ( $namespaceName === false ) {
+ $namespaceName = "NS$ns"; // Fallback for unknown namespaces
+ }
+ $ns = 0;
+ $legalizedUnprefixed = "$namespaceName:$legalizedUnprefixed";
+ }
+ $title = Title::newFromText( $this->prefix . $legalizedUnprefixed );
+ }
if ( $title === null ) {
// It's still not a valid title, try again with a much smaller
// allowed character set. This will mangle any titles with non-ASCII
// characters, but if we don't do this the result will be
// falling back to the Broken/id:foo failsafe below which is worse
- $legalizedUnprefixed = preg_replace_callback( '!([^A-Za-z0-9_\\-:])!',
+ $legalizedUnprefixed = preg_replace_callback( '!([^A-Za-z0-9_:\\-])!',
[ $this, 'hexChar' ],
$legalizedUnprefixed
);
- $legalized = $this->prefix . $legalizedUnprefixed;
- $title = Title::newFromText( $legalized );
+ $title = Title::newFromText( $this->prefix . $legalizedUnprefixed );
}
if ( $title === null ) {
// Oh well, we tried
$clean = $this->prefix . 'id:' . $row->page_id;
+ $legalized = $this->prefix . $legalizedUnprefixed;
$this->output( "Couldn't legalize; form '$legalized' still invalid; using '$clean'\n" );
$title = Title::newFromText( $clean );
} elseif ( $title->exists() ) {
$clean = $this->prefix . 'id:' . $row->page_id;
- $this->output( "Legalized for '$legalized' exists; using '$clean'\n" );
+ $conflict = $title->getDBKey();
+ $this->output( "Legalized for '$conflict' exists; using '$clean'\n" );
$title = Title::newFromText( $clean );
}
@@ -177,14 +194,14 @@ class TitleCleanup extends TableCleanup {
$dest = $title->getDBkey();
if ( $this->dryrun ) {
$this->output( "DRY RUN: would rename $row->page_id ($row->page_namespace," .
- "'$row->page_title') to (0,'$dest')\n" );
+ "'$row->page_title') to ($ns,'$dest')\n" );
} else {
$this->output( "renaming $row->page_id ($row->page_namespace," .
"'$row->page_title') to ($row->page_namespace,'$dest')\n" );
$this->getPrimaryDB()
->newUpdateQueryBuilder()
->update( 'page' )
- ->set( [ 'page_title' => $dest, 'page_namespace' => 0 ] )
+ ->set( [ 'page_title' => $dest, 'page_namespace' => $ns ] )
->where( [ 'page_id' => $row->page_id ] )
->caller( __METHOD__ )->execute();
}