MediaWiki  REL1_22
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             return $this->progress( 0 );
00075         }
00076 
00077         $target = Title::makeTitle( $row->page_namespace, $lower );
00078         $targetDisplay = $target->getPrefixedText();
00079         if ( $target->exists() ) {
00080             $this->output( "\"$display\" skipped; \"$targetDisplay\" already exists\n" );
00081             return $this->progress( 0 );
00082         }
00083 
00084         if ( $this->dryrun ) {
00085             $this->output( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
00086             $ok = true;
00087         } else {
00088             $ok = $current->moveTo( $target, false, 'Converting page titles to lowercase' );
00089             $this->output( "\"$display\" -> \"$targetDisplay\": $ok\n" );
00090         }
00091         if ( $ok === true ) {
00092             $this->progress( 1 );
00093             if ( $row->page_namespace == $this->namespace ) {
00094                 $talk = $target->getTalkPage();
00095                 $row->page_namespace = $talk->getNamespace();
00096                 if ( $talk->exists() ) {
00097                     return $this->processRow( $row );
00098                 }
00099             }
00100         }
00101         return $this->progress( 0 );
00102     }
00103 }
00104 
00105 $maintClass = "CapsCleanup";
00106 require_once RUN_MAINTENANCE_IF_MAIN;