00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 require_once( dirname(__FILE__) . '/cleanupTable.inc' );
00032
00033 class CapsCleanup extends TableCleanup {
00034 public function __construct() {
00035 parent::__construct();
00036 $this->mDescription = "Script to cleanup capitalization";
00037 $this->addOption( 'namespace', 'Namespace number to run caps cleanup on', false, true );
00038 }
00039
00040 public function execute() {
00041 global $wgCapitalLinks, $wgUser;
00042 $this->namespace = intval( $this->getOption( 'namespace', 0 ) );
00043 $this->dryrun = $this->hasOption( 'dry-run' );
00044 $wgUser->setName( 'Conversion script' );
00045 if( $wgCapitalLinks )
00046 $this->error( "\$wgCapitalLinks is on -- no need for caps links cleanup.", true );
00047
00048 $this->runTable( array(
00049 'table' => 'page',
00050 'conds' => array( 'page_namespace' => $this->namespace ),
00051 'index' => 'page_id',
00052 'callback' => 'processRow' ) );
00053 }
00054
00055 protected function processRow( $row ) {
00056 global $wgContLang;
00057
00058 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
00059 $display = $current->getPrefixedText();
00060 $upper = $row->page_title;
00061 $lower = $wgContLang->lcfirst( $row->page_title );
00062 if( $upper == $lower ) {
00063 $this->output( "\"$display\" already lowercase.\n" );
00064 return $this->progress( 0 );
00065 }
00066
00067 $target = Title::makeTitle( $row->page_namespace, $lower );
00068 $targetDisplay = $target->getPrefixedText();
00069 if( $target->exists() ) {
00070 $this->output( "\"$display\" skipped; \"$targetDisplay\" already exists\n" );
00071 return $this->progress( 0 );
00072 }
00073
00074 if( $this->dryrun ) {
00075 $this->output( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
00076 $ok = true;
00077 } else {
00078 $ok = $current->moveTo( $target, false, 'Converting page titles to lowercase' );
00079 $this->output( "\"$display\" -> \"$targetDisplay\": $ok\n" );
00080 }
00081 if( $ok === true ) {
00082 $this->progress( 1 );
00083 if( $row->page_namespace == $this->namespace ) {
00084 $talk = $target->getTalkPage();
00085 $row->page_namespace = $talk->getNamespace();
00086 if( $talk->exists() ) {
00087 return $this->processRow( $row );
00088 }
00089 }
00090 } else {
00091 $this->progress( 0 );
00092 }
00093 }
00094 }
00095
00096 $maintClass = "CapsCleanup";
00097 require_once( DO_MAINTENANCE );