PrefixSearch: Avoid notice when no subpage exists
[mediawiki.git] / maintenance / cleanupCaps.php
blob9e88c13593ec27b0d32b190cfd6ad05e05b82b02
1 <?php
2 /**
3 * Clean up broken page links when somebody turns on $wgCapitalLinks.
5 * Usage: php cleanupCaps.php [--dry-run]
6 * Options:
7 * --dry-run don't actually try moving them
9 * Copyright © 2005 Brion Vibber <brion@pobox.com>
10 * https://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
27 * @file
28 * @author Brion Vibber <brion at pobox.com>
29 * @ingroup Maintenance
32 require_once __DIR__ . '/cleanupTable.inc';
34 /**
35 * Maintenance script to clean up broken page links when somebody turns on $wgCapitalLinks.
37 * @ingroup Maintenance
39 class CapsCleanup extends TableCleanup {
40 public function __construct() {
41 parent::__construct();
42 $this->mDescription = "Script to cleanup capitalization";
43 $this->addOption( 'namespace', 'Namespace number to run caps cleanup on', false, true );
46 public function execute() {
47 global $wgCapitalLinks, $wgUser;
49 if ( $wgCapitalLinks ) {
50 $this->error( "\$wgCapitalLinks is on -- no need for caps links cleanup.", true );
53 $wgUser = User::newFromName( 'Conversion script' );
55 $this->namespace = intval( $this->getOption( 'namespace', 0 ) );
56 $this->dryrun = $this->hasOption( 'dry-run' );
58 $this->runTable( array(
59 'table' => 'page',
60 'conds' => array( 'page_namespace' => $this->namespace ),
61 'index' => 'page_id',
62 'callback' => 'processRow' ) );
65 protected function processRow( $row ) {
66 global $wgContLang;
68 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
69 $display = $current->getPrefixedText();
70 $upper = $row->page_title;
71 $lower = $wgContLang->lcfirst( $row->page_title );
72 if ( $upper == $lower ) {
73 $this->output( "\"$display\" already lowercase.\n" );
75 return $this->progress( 0 );
78 $target = Title::makeTitle( $row->page_namespace, $lower );
79 $targetDisplay = $target->getPrefixedText();
80 if ( $target->exists() ) {
81 $this->output( "\"$display\" skipped; \"$targetDisplay\" already exists\n" );
83 return $this->progress( 0 );
86 if ( $this->dryrun ) {
87 $this->output( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
88 $ok = true;
89 } else {
90 $ok = $current->moveTo( $target, false, 'Converting page titles to lowercase' );
91 $this->output( "\"$display\" -> \"$targetDisplay\": $ok\n" );
93 if ( $ok === true ) {
94 $this->progress( 1 );
95 if ( $row->page_namespace == $this->namespace ) {
96 $talk = $target->getTalkPage();
97 $row->page_namespace = $talk->getNamespace();
98 if ( $talk->exists() ) {
99 return $this->processRow( $row );
104 return $this->progress( 0 );
108 $maintClass = "CapsCleanup";
109 require_once RUN_MAINTENANCE_IF_MAIN;