Merge "Show Log toolbox link for anon users, fix toolbox on DeletedContribs"
[lhc/web/wiklou.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
44 if ( $wgCapitalLinks ) {
45 $this->error( "\$wgCapitalLinks is on -- no need for caps links cleanup.", true );
46 }
47
48 $wgUser = User::newFromName( 'Conversion script' );
49
50 $this->namespace = intval( $this->getOption( 'namespace', 0 ) );
51 $this->dryrun = $this->hasOption( 'dry-run' );
52
53 $this->runTable( array(
54 'table' => 'page',
55 'conds' => array( 'page_namespace' => $this->namespace ),
56 'index' => 'page_id',
57 'callback' => 'processRow' ) );
58 }
59
60 protected function processRow( $row ) {
61 global $wgContLang;
62
63 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
64 $display = $current->getPrefixedText();
65 $upper = $row->page_title;
66 $lower = $wgContLang->lcfirst( $row->page_title );
67 if ( $upper == $lower ) {
68 $this->output( "\"$display\" already lowercase.\n" );
69 return $this->progress( 0 );
70 }
71
72 $target = Title::makeTitle( $row->page_namespace, $lower );
73 $targetDisplay = $target->getPrefixedText();
74 if ( $target->exists() ) {
75 $this->output( "\"$display\" skipped; \"$targetDisplay\" already exists\n" );
76 return $this->progress( 0 );
77 }
78
79 if ( $this->dryrun ) {
80 $this->output( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
81 $ok = true;
82 } else {
83 $ok = $current->moveTo( $target, false, 'Converting page titles to lowercase' );
84 $this->output( "\"$display\" -> \"$targetDisplay\": $ok\n" );
85 }
86 if ( $ok === true ) {
87 $this->progress( 1 );
88 if ( $row->page_namespace == $this->namespace ) {
89 $talk = $target->getTalkPage();
90 $row->page_namespace = $talk->getNamespace();
91 if ( $talk->exists() ) {
92 return $this->processRow( $row );
93 }
94 }
95 }
96 return $this->progress( 0 );
97 }
98 }
99
100 $maintClass = "CapsCleanup";
101 require_once( RUN_MAINTENANCE_IF_MAIN );