MediaWiki  REL1_24
cleanupCaps.php
Go to the documentation of this file.
00001 <?php
00032 require_once __DIR__ . '/cleanupTable.inc';
00033 
00039 class CapsCleanup extends TableCleanup {
00040     public function __construct() {
00041         parent::__construct();
00042         $this->mDescription = "Script to cleanup capitalization";
00043         $this->addOption( 'namespace', 'Namespace number to run caps cleanup on', false, true );
00044     }
00045 
00046     public function execute() {
00047         global $wgCapitalLinks, $wgUser;
00048 
00049         if ( $wgCapitalLinks ) {
00050             $this->error( "\$wgCapitalLinks is on -- no need for caps links cleanup.", true );
00051         }
00052 
00053         $wgUser = User::newFromName( 'Conversion script' );
00054 
00055         $this->namespace = intval( $this->getOption( 'namespace', 0 ) );
00056         $this->dryrun = $this->hasOption( 'dry-run' );
00057 
00058         $this->runTable( array(
00059             'table' => 'page',
00060             'conds' => array( 'page_namespace' => $this->namespace ),
00061             'index' => 'page_id',
00062             'callback' => 'processRow' ) );
00063     }
00064 
00065     protected function processRow( $row ) {
00066         global $wgContLang;
00067 
00068         $current = Title::makeTitle( $row->page_namespace, $row->page_title );
00069         $display = $current->getPrefixedText();
00070         $upper = $row->page_title;
00071         $lower = $wgContLang->lcfirst( $row->page_title );
00072         if ( $upper == $lower ) {
00073             $this->output( "\"$display\" already lowercase.\n" );
00074 
00075             return $this->progress( 0 );
00076         }
00077 
00078         $target = Title::makeTitle( $row->page_namespace, $lower );
00079         $targetDisplay = $target->getPrefixedText();
00080         if ( $target->exists() ) {
00081             $this->output( "\"$display\" skipped; \"$targetDisplay\" already exists\n" );
00082 
00083             return $this->progress( 0 );
00084         }
00085 
00086         if ( $this->dryrun ) {
00087             $this->output( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
00088             $ok = true;
00089         } else {
00090             $ok = $current->moveTo( $target, false, 'Converting page titles to lowercase' );
00091             $this->output( "\"$display\" -> \"$targetDisplay\": $ok\n" );
00092         }
00093         if ( $ok === true ) {
00094             $this->progress( 1 );
00095             if ( $row->page_namespace == $this->namespace ) {
00096                 $talk = $target->getTalkPage();
00097                 $row->page_namespace = $talk->getNamespace();
00098                 if ( $talk->exists() ) {
00099                     return $this->processRow( $row );
00100                 }
00101             }
00102         }
00103 
00104         return $this->progress( 0 );
00105     }
00106 }
00107 
00108 $maintClass = "CapsCleanup";
00109 require_once RUN_MAINTENANCE_IF_MAIN;