3 * Script to clean up broken page links when somebody turns on $wgCapitalLinks.
5 * Usage: php cleanupCaps.php [--dry-run]
7 * --dry-run don't actually try moving them
9 * Copyright (C) 2005 Brion Vibber <brion@pobox.com>
10 * http://www.mediawiki.org/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 * http://www.gnu.org/copyleft/gpl.html
28 * @author Brion Vibber <brion at pobox.com>
29 * @ingroup maintenance
32 $optionsWithArgs = array( 'namespace' );
34 require_once( 'commandLine.inc' );
35 require_once( 'CleanupTable.inc' );
38 * @ingroup Maintenance
40 class CapsCleanup
extends TableCleanup
{
41 function __construct( $dryrun = false, $namespace = 0 ) {
42 parent
::__construct( 'page', $dryrun );
43 $this->namespace = intval( $namespace );
47 global $wgCapitalLinks;
48 if( $wgCapitalLinks ) {
49 echo "\$wgCapitalLinks is on -- no need for caps links cleanup.\n";
53 $this->runTable( $this->targetTable
,
54 'WHERE page_namespace=' . $this->namespace,
55 array( &$this, 'processPage' ) );
58 function processPage( $row ) {
61 $current = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
62 $display = $current->getPrefixedText();
63 $upper = $row->page_title
;
64 $lower = $wgContLang->lcfirst( $row->page_title
);
65 if( $upper == $lower ) {
66 $this->log( "\"$display\" already lowercase." );
67 return $this->progress( 0 );
70 $target = Title
::makeTitle( $row->page_namespace
, $lower );
71 $targetDisplay = $target->getPrefixedText();
72 if( $target->exists() ) {
73 $this->log( "\"$display\" skipped; \"$targetDisplay\" already exists" );
74 return $this->progress( 0 );
78 $this->log( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED" );
81 $ok = $current->moveTo( $target, false, 'Converting page titles to lowercase' );
82 $this->log( "\"$display\" -> \"$targetDisplay\": $ok" );
87 if( $row->page_namespace
== $this->namespace ) {
88 $talk = $target->getTalkPage();
89 $row->page_namespace
= $talk->getNamespace();
90 if( $talk->exists() ) {
91 return $this->processPage( $row );
101 $wgUser->setName( 'Conversion script' );
102 $ns = isset( $options['namespace'] ) ?
$options['namespace'] : 0;
103 $caps = new CapsCleanup( isset( $options['dry-run'] ), $ns );