Check $wgCheckFileExtensions on client side on Special:Upload
[mediawiki.git] / maintenance / cleanupCaps.php
blob6234db48cacf118cc0adc5d1827277ae2ed44227
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 {
41 private $user;
43 public function __construct() {
44 parent::__construct();
45 $this->mDescription = "Script to cleanup capitalization";
46 $this->addOption( 'namespace', 'Namespace number to run caps cleanup on', false, true );
49 public function execute() {
50 global $wgCapitalLinks;
52 if ( $wgCapitalLinks ) {
53 $this->error( "\$wgCapitalLinks is on -- no need for caps links cleanup.", true );
56 $this->user = User::newFromName( 'Conversion script' );
58 $this->namespace = intval( $this->getOption( 'namespace', 0 ) );
59 $this->dryrun = $this->hasOption( 'dry-run' );
61 $this->runTable( array(
62 'table' => 'page',
63 'conds' => array( 'page_namespace' => $this->namespace ),
64 'index' => 'page_id',
65 'callback' => 'processRow' ) );
68 protected function processRow( $row ) {
69 global $wgContLang;
71 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
72 $display = $current->getPrefixedText();
73 $upper = $row->page_title;
74 $lower = $wgContLang->lcfirst( $row->page_title );
75 if ( $upper == $lower ) {
76 $this->output( "\"$display\" already lowercase.\n" );
78 return $this->progress( 0 );
81 $target = Title::makeTitle( $row->page_namespace, $lower );
82 $targetDisplay = $target->getPrefixedText();
83 if ( $target->exists() ) {
84 $this->output( "\"$display\" skipped; \"$targetDisplay\" already exists\n" );
86 return $this->progress( 0 );
89 if ( $this->dryrun ) {
90 $this->output( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
91 $ok = true;
92 } else {
93 $mp = new MovePage( $current, $target );
94 $status = $mp->move( $this->user, 'Converting page titles to lowercase', true );
95 $ok = $status->isOK() ? 'OK' : $status->getWikiText();
96 $this->output( "\"$display\" -> \"$targetDisplay\": $ok\n" );
98 if ( $ok === true ) {
99 $this->progress( 1 );
100 if ( $row->page_namespace == $this->namespace ) {
101 $talk = $target->getTalkPage();
102 $row->page_namespace = $talk->getNamespace();
103 if ( $talk->exists() ) {
104 return $this->processRow( $row );
109 return $this->progress( 0 );
113 $maintClass = "CapsCleanup";
114 require_once RUN_MAINTENANCE_IF_MAIN;