2005-06-30 00:37:56 +00:00
|
|
|
<?php
|
2010-09-05 13:15:48 +00:00
|
|
|
/**
|
2012-06-25 19:54:41 +00:00
|
|
|
* Clean up broken page links when somebody turns on $wgCapitalLinks.
|
2005-06-30 00:37:56 +00:00
|
|
|
*
|
|
|
|
|
* Usage: php cleanupCaps.php [--dry-run]
|
|
|
|
|
* Options:
|
|
|
|
|
* --dry-run don't actually try moving them
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2010-09-05 13:15:48 +00:00
|
|
|
* Copyright © 2005 Brion Vibber <brion@pobox.com>
|
2014-03-20 15:45:01 +00:00
|
|
|
* https://www.mediawiki.org/
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-06-30 00:37:56 +00:00
|
|
|
* 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
|
2006-01-07 13:09:30 +00:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
2005-06-30 00:37:56 +00:00
|
|
|
* (at your option) any later version.
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-06-30 00:37:56 +00:00
|
|
|
* 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.
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-06-30 00:37:56 +00:00
|
|
|
* 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.,
|
2006-04-05 07:43:17 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-06-30 00:37:56 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2010-09-05 13:15:48 +00:00
|
|
|
* @file
|
2005-06-30 00:37:56 +00:00
|
|
|
* @author Brion Vibber <brion at pobox.com>
|
2010-09-05 13:15:48 +00:00
|
|
|
* @ingroup Maintenance
|
2005-06-30 00:37:56 +00:00
|
|
|
*/
|
|
|
|
|
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/cleanupTable.inc';
|
2005-06-30 00:37:56 +00:00
|
|
|
|
2012-06-25 19:54:41 +00:00
|
|
|
/**
|
2015-06-06 04:42:45 +00:00
|
|
|
* Maintenance script to clean up broken page links when somebody turns
|
|
|
|
|
* on or off $wgCapitalLinks.
|
2012-06-25 19:54:41 +00:00
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-02-16 19:09:28 +00:00
|
|
|
class CapsCleanup extends TableCleanup {
|
2014-10-11 05:43:02 +00:00
|
|
|
|
|
|
|
|
private $user;
|
2015-06-06 04:42:45 +00:00
|
|
|
private $namespace;
|
2014-10-11 05:43:02 +00:00
|
|
|
|
2009-08-24 02:14:52 +00:00
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Script to cleanup capitalization' );
|
2009-08-24 02:14:52 +00:00
|
|
|
$this->addOption( 'namespace', 'Namespace number to run caps cleanup on', false, true );
|
2005-06-30 00:37:56 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2009-08-24 02:14:52 +00:00
|
|
|
public function execute() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->user = User::newSystemUser( 'Conversion script', [ 'steal' => true ] );
|
2011-12-28 19:49:44 +00:00
|
|
|
|
2009-08-24 02:14:52 +00:00
|
|
|
$this->namespace = intval( $this->getOption( 'namespace', 0 ) );
|
2015-06-06 04:42:45 +00:00
|
|
|
|
|
|
|
|
if ( MWNamespace::isCapitalized( $this->namespace ) ) {
|
|
|
|
|
$this->output( "Will be moving pages to first letter capitalized titles" );
|
|
|
|
|
$callback = 'processRowToUppercase';
|
|
|
|
|
} else {
|
|
|
|
|
$this->output( "Will be moving pages to first letter lowercase titles" );
|
|
|
|
|
$callback = 'processRowToLowercase';
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-24 02:14:52 +00:00
|
|
|
$this->dryrun = $this->hasOption( 'dry-run' );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->runTable( [
|
2009-09-24 04:19:25 +00:00
|
|
|
'table' => 'page',
|
2016-02-17 09:09:32 +00:00
|
|
|
'conds' => [ 'page_namespace' => $this->namespace ],
|
2009-09-24 04:19:25 +00:00
|
|
|
'index' => 'page_id',
|
2015-06-06 04:42:45 +00:00
|
|
|
'callback' => $callback ] );
|
2005-06-30 00:37:56 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2015-06-06 04:42:45 +00:00
|
|
|
protected function processRowToUppercase( $row ) {
|
|
|
|
|
global $wgContLang;
|
|
|
|
|
|
|
|
|
|
$current = Title::makeTitle( $row->page_namespace, $row->page_title );
|
|
|
|
|
$display = $current->getPrefixedText();
|
|
|
|
|
$lower = $row->page_title;
|
|
|
|
|
$upper = $wgContLang->ucfirst( $row->page_title );
|
|
|
|
|
if ( $upper == $lower ) {
|
|
|
|
|
$this->output( "\"$display\" already uppercase.\n" );
|
|
|
|
|
|
|
|
|
|
return $this->progress( 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$target = Title::makeTitle( $row->page_namespace, $upper );
|
|
|
|
|
if ( $target->exists() ) {
|
|
|
|
|
// Prefix "CapsCleanup" to bypass the conflict
|
|
|
|
|
$target = Title::newFromText( __CLASS__ . '/' . $display );
|
|
|
|
|
}
|
|
|
|
|
$ok = $this->movePage(
|
|
|
|
|
$current,
|
|
|
|
|
$target,
|
|
|
|
|
'Converting page title to first-letter uppercase',
|
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
if ( $ok ) {
|
|
|
|
|
$this->progress( 1 );
|
|
|
|
|
if ( $row->page_namespace == $this->namespace ) {
|
|
|
|
|
$talk = $target->getTalkPage();
|
|
|
|
|
$row->page_namespace = $talk->getNamespace();
|
|
|
|
|
if ( $talk->exists() ) {
|
|
|
|
|
return $this->processRowToUppercase( $row );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->progress( 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function processRowToLowercase( $row ) {
|
2005-06-30 00:37:56 +00:00
|
|
|
global $wgContLang;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-06-30 00:37:56 +00:00
|
|
|
$current = Title::makeTitle( $row->page_namespace, $row->page_title );
|
|
|
|
|
$display = $current->getPrefixedText();
|
|
|
|
|
$upper = $row->page_title;
|
|
|
|
|
$lower = $wgContLang->lcfirst( $row->page_title );
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $upper == $lower ) {
|
2009-09-24 04:19:25 +00:00
|
|
|
$this->output( "\"$display\" already lowercase.\n" );
|
2014-04-23 18:08:42 +00:00
|
|
|
|
2005-06-30 00:37:56 +00:00
|
|
|
return $this->progress( 0 );
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-06-30 00:37:56 +00:00
|
|
|
$target = Title::makeTitle( $row->page_namespace, $lower );
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $target->exists() ) {
|
2015-06-06 04:42:45 +00:00
|
|
|
$targetDisplay = $target->getPrefixedText();
|
2009-09-24 04:19:25 +00:00
|
|
|
$this->output( "\"$display\" skipped; \"$targetDisplay\" already exists\n" );
|
2014-04-23 18:08:42 +00:00
|
|
|
|
2005-06-30 00:37:56 +00:00
|
|
|
return $this->progress( 0 );
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2015-06-06 04:42:45 +00:00
|
|
|
$ok = $this->movePage( $current, $target, 'Converting page titles to lowercase', true );
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $ok === true ) {
|
2005-06-30 00:37:56 +00:00
|
|
|
$this->progress( 1 );
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $row->page_namespace == $this->namespace ) {
|
2005-10-22 20:52:30 +00:00
|
|
|
$talk = $target->getTalkPage();
|
|
|
|
|
$row->page_namespace = $talk->getNamespace();
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $talk->exists() ) {
|
2015-06-06 04:42:45 +00:00
|
|
|
return $this->processRowToLowercase( $row );
|
2005-06-30 00:37:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-23 18:08:42 +00:00
|
|
|
|
2011-10-18 17:31:54 +00:00
|
|
|
return $this->progress( 0 );
|
2005-06-30 00:37:56 +00:00
|
|
|
}
|
2015-06-06 04:42:45 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Title $current
|
|
|
|
|
* @param Title $target
|
|
|
|
|
* @param string $reason
|
|
|
|
|
* @param bool $createRedirect
|
|
|
|
|
* @return bool Success
|
|
|
|
|
*/
|
|
|
|
|
private function movePage( Title $current, Title $target, $reason, $createRedirect ) {
|
|
|
|
|
$display = $current->getPrefixedText();
|
|
|
|
|
$targetDisplay = $target->getPrefixedText();
|
|
|
|
|
|
|
|
|
|
if ( $this->dryrun ) {
|
|
|
|
|
$this->output( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
|
|
|
|
|
$ok = 'OK';
|
|
|
|
|
} else {
|
|
|
|
|
$mp = new MovePage( $current, $target );
|
|
|
|
|
$status = $mp->move( $this->user, $reason, $createRedirect );
|
|
|
|
|
$ok = $status->isOK() ? 'OK' : $status->getWikiText( false, false, 'en' );
|
|
|
|
|
$this->output( "\"$display\" -> \"$targetDisplay\": $ok\n" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $ok === 'OK';
|
|
|
|
|
}
|
2005-06-30 00:37:56 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = CapsCleanup::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|