[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 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 <[email protected]> 10 * https://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 __DIR__ . '/cleanupTable.inc'; 33 34 /** 35 * Maintenance script to clean up broken page links when somebody turns on $wgCapitalLinks. 36 * 37 * @ingroup Maintenance 38 */ 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 ); 44 } 45 46 public function execute() { 47 global $wgCapitalLinks, $wgUser; 48 49 if ( $wgCapitalLinks ) { 50 $this->error( "\$wgCapitalLinks is on -- no need for caps links cleanup.", true ); 51 } 52 53 $wgUser = User::newFromName( 'Conversion script' ); 54 55 $this->namespace = intval( $this->getOption( 'namespace', 0 ) ); 56 $this->dryrun = $this->hasOption( 'dry-run' ); 57 58 $this->runTable( array( 59 'table' => 'page', 60 'conds' => array( 'page_namespace' => $this->namespace ), 61 'index' => 'page_id', 62 'callback' => 'processRow' ) ); 63 } 64 65 protected function processRow( $row ) { 66 global $wgContLang; 67 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 75 return $this->progress( 0 ); 76 } 77 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" ); 82 83 return $this->progress( 0 ); 84 } 85 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" ); 92 } 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 ); 100 } 101 } 102 } 103 104 return $this->progress( 0 ); 105 } 106 } 107 108 $maintClass = "CapsCleanup"; 109 require_once RUN_MAINTENANCE_IF_MAIN;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |