]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - maintenance/cleanupCaps.php
MediaWiki 1.17.0
[autoinstalls/mediawiki.git] / maintenance / cleanupCaps.php
1 <?php
2 /**
3  * Script to clean up broken page links when somebody turns on $wgCapitalLinks.
4  *
5  * Usage: php cleanupCaps.php [--dry-run]
6  * Options:
7  *   --dry-run  don't actually try moving them
8  *
9  * Copyright © 2005 Brion Vibber <brion@pobox.com>
10  * http://www.mediawiki.org/
11  *
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.
16  *
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.
21  *
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
26  *
27  * @file
28  * @author Brion Vibber <brion at pobox.com>
29  * @ingroup Maintenance
30  */
31
32 require_once( dirname( __FILE__ ) . '/cleanupTable.inc' );
33
34 class CapsCleanup extends TableCleanup {
35         public function __construct() {
36                 parent::__construct();
37                 $this->mDescription = "Script to cleanup capitalization";
38                 $this->addOption( 'namespace', 'Namespace number to run caps cleanup on', false, true );
39         }
40
41         public function execute() {
42                 global $wgCapitalLinks, $wgUser;
43                 $this->namespace = intval( $this->getOption( 'namespace', 0 ) );
44                 $this->dryrun = $this->hasOption( 'dry-run' );
45                 $wgUser->setName( 'Conversion script' );
46                 if ( $wgCapitalLinks )
47                         $this->error( "\$wgCapitalLinks is on -- no need for caps links cleanup.", true );
48
49                 $this->runTable( array(
50                         'table' => 'page',
51                         'conds' => array( 'page_namespace' => $this->namespace ),
52                         'index' => 'page_id',
53                         'callback' => 'processRow' ) );
54         }
55
56         protected function processRow( $row ) {
57                 global $wgContLang;
58
59                 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
60                 $display = $current->getPrefixedText();
61                 $upper = $row->page_title;
62                 $lower = $wgContLang->lcfirst( $row->page_title );
63                 if ( $upper == $lower ) {
64                         $this->output( "\"$display\" already lowercase.\n" );
65                         return $this->progress( 0 );
66                 }
67
68                 $target = Title::makeTitle( $row->page_namespace, $lower );
69                 $targetDisplay = $target->getPrefixedText();
70                 if ( $target->exists() ) {
71                         $this->output( "\"$display\" skipped; \"$targetDisplay\" already exists\n" );
72                         return $this->progress( 0 );
73                 }
74
75                 if ( $this->dryrun ) {
76                         $this->output( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
77                         $ok = true;
78                 } else {
79                         $ok = $current->moveTo( $target, false, 'Converting page titles to lowercase' );
80                         $this->output( "\"$display\" -> \"$targetDisplay\": $ok\n" );
81                 }
82                 if ( $ok === true ) {
83                         $this->progress( 1 );
84                         if ( $row->page_namespace == $this->namespace ) {
85                                 $talk = $target->getTalkPage();
86                                 $row->page_namespace = $talk->getNamespace();
87                                 if ( $talk->exists() ) {
88                                         return $this->processRow( $row );
89                                 }
90                         }
91                 } else {
92                         $this->progress( 0 );
93                 }
94         }
95 }
96
97 $maintClass = "CapsCleanup";
98 require_once( RUN_MAINTENANCE_IF_MAIN );