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