Whitelist the <wbr> element.
[mediawiki.git] / maintenance / cleanupCaps.php
blob1a47ac4e52098ad0f86a5d33184efb6e45335363
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 * http://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" );
74 return $this->progress( 0 );
77 $target = Title::makeTitle( $row->page_namespace, $lower );
78 $targetDisplay = $target->getPrefixedText();
79 if ( $target->exists() ) {
80 $this->output( "\"$display\" skipped; \"$targetDisplay\" already exists\n" );
81 return $this->progress( 0 );
84 if ( $this->dryrun ) {
85 $this->output( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
86 $ok = true;
87 } else {
88 $ok = $current->moveTo( $target, false, 'Converting page titles to lowercase' );
89 $this->output( "\"$display\" -> \"$targetDisplay\": $ok\n" );
91 if ( $ok === true ) {
92 $this->progress( 1 );
93 if ( $row->page_namespace == $this->namespace ) {
94 $talk = $target->getTalkPage();
95 $row->page_namespace = $talk->getNamespace();
96 if ( $talk->exists() ) {
97 return $this->processRow( $row );
101 return $this->progress( 0 );
105 $maintClass = "CapsCleanup";
106 require_once RUN_MAINTENANCE_IF_MAIN;