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
00032 $optionsWithArgs = array( 'namespace' );
00033
00034 require_once( 'commandLine.inc' );
00035 require_once( 'cleanupTable.inc' );
00036
00040 class CapsCleanup extends TableCleanup {
00041 function __construct( $dryrun = false, $namespace = 0 ) {
00042 parent::__construct( 'page', $dryrun );
00043 $this->namespace = intval( $namespace );
00044 }
00045
00046 function cleanup() {
00047 global $wgCapitalLinks;
00048 if( $wgCapitalLinks ) {
00049 echo "\$wgCapitalLinks is on -- no need for caps links cleanup.\n";
00050 return false;
00051 }
00052
00053 $this->runTable( $this->targetTable,
00054 'WHERE page_namespace=' . $this->namespace,
00055 array( &$this, 'processPage' ) );
00056 }
00057
00058 function processPage( $row ) {
00059 global $wgContLang;
00060
00061 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
00062 $display = $current->getPrefixedText();
00063 $upper = $row->page_title;
00064 $lower = $wgContLang->lcfirst( $row->page_title );
00065 if( $upper == $lower ) {
00066 $this->log( "\"$display\" already lowercase." );
00067 return $this->progress( 0 );
00068 }
00069
00070 $target = Title::makeTitle( $row->page_namespace, $lower );
00071 $targetDisplay = $target->getPrefixedText();
00072 if( $target->exists() ) {
00073 $this->log( "\"$display\" skipped; \"$targetDisplay\" already exists" );
00074 return $this->progress( 0 );
00075 }
00076
00077 if( $this->dryrun ) {
00078 $this->log( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED" );
00079 $ok = true;
00080 } else {
00081 $ok = $current->moveTo( $target, false, 'Converting page titles to lowercase' );
00082 $this->log( "\"$display\" -> \"$targetDisplay\": $ok" );
00083 }
00084 if( $ok === true ) {
00085 $this->progress( 1 );
00086
00087 if( $row->page_namespace == $this->namespace ) {
00088 $talk = $target->getTalkPage();
00089 $row->page_namespace = $talk->getNamespace();
00090 if( $talk->exists() ) {
00091 return $this->processPage( $row );
00092 }
00093 }
00094 } else {
00095 $this->progress( 0 );
00096 }
00097 }
00098
00099 }
00100
00101 $wgUser->setName( 'Conversion script' );
00102 $ns = isset( $options['namespace'] ) ? $options['namespace'] : 0;
00103 $caps = new CapsCleanup( isset( $options['dry-run'] ), $ns );
00104 $caps->cleanup();