Localization update for he and fixing comment in en.
[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 (C) 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 $optionsWithArgs = array( 'namespace' );
33
34 require_once( 'commandLine.inc' );
35 require_once( 'cleanupTable.inc' );
36
37 /**
38 * @ingroup Maintenance
39 */
40 class CapsCleanup extends TableCleanup {
41 function __construct( $dryrun = false, $namespace = 0 ) {
42 parent::__construct( 'page', $dryrun );
43 $this->namespace = intval( $namespace );
44 }
45
46 function cleanup() {
47 global $wgCapitalLinks;
48 if( $wgCapitalLinks ) {
49 echo "\$wgCapitalLinks is on -- no need for caps links cleanup.\n";
50 return false;
51 }
52
53 $this->runTable( $this->targetTable,
54 'WHERE page_namespace=' . $this->namespace,
55 array( &$this, 'processPage' ) );
56 }
57
58 function processPage( $row ) {
59 global $wgContLang;
60
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 );
68 }
69
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 );
75 }
76
77 if( $this->dryrun ) {
78 $this->log( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED" );
79 $ok = true;
80 } else {
81 $ok = $current->moveTo( $target, false, 'Converting page titles to lowercase' );
82 $this->log( "\"$display\" -> \"$targetDisplay\": $ok" );
83 }
84 if( $ok === true ) {
85 $this->progress( 1 );
86
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 );
92 }
93 }
94 } else {
95 $this->progress( 0 );
96 }
97 }
98
99 }
100
101 $wgUser->setName( 'Conversion script' );
102 $ns = isset( $options['namespace'] ) ? $options['namespace'] : 0;
103 $caps = new CapsCleanup( isset( $options['dry-run'] ), $ns );
104 $caps->cleanup();