MediaWiki  1.23.2
cleanupCaps.php
Go to the documentation of this file.
1 <?php
32 require_once __DIR__ . '/cleanupTable.inc';
33 
39 class CapsCleanup extends TableCleanup {
40  public function __construct() {
41  parent::__construct();
42  $this->mDescription = "Script to cleanup capitalization";
43  $this->addOption( 'namespace', 'Namespace number to run caps cleanup on', false, true );
44  }
45 
46  public function execute() {
47  global $wgCapitalLinks, $wgUser;
48 
49  if ( $wgCapitalLinks ) {
50  $this->error( "\$wgCapitalLinks is on -- no need for caps links cleanup.", true );
51  }
52 
53  $wgUser = User::newFromName( 'Conversion script' );
54 
55  $this->namespace = intval( $this->getOption( 'namespace', 0 ) );
56  $this->dryrun = $this->hasOption( 'dry-run' );
57 
58  $this->runTable( array(
59  'table' => 'page',
60  'conds' => array( 'page_namespace' => $this->namespace ),
61  'index' => 'page_id',
62  'callback' => 'processRow' ) );
63  }
64 
65  protected function processRow( $row ) {
67 
68  $current = Title::makeTitle( $row->page_namespace, $row->page_title );
69  $display = $current->getPrefixedText();
70  $upper = $row->page_title;
71  $lower = $wgContLang->lcfirst( $row->page_title );
72  if ( $upper == $lower ) {
73  $this->output( "\"$display\" already lowercase.\n" );
74  return $this->progress( 0 );
75  }
76 
77  $target = Title::makeTitle( $row->page_namespace, $lower );
78  $targetDisplay = $target->getPrefixedText();
79  if ( $target->exists() ) {
80  $this->output( "\"$display\" skipped; \"$targetDisplay\" already exists\n" );
81  return $this->progress( 0 );
82  }
83 
84  if ( $this->dryrun ) {
85  $this->output( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
86  $ok = true;
87  } else {
88  $ok = $current->moveTo( $target, false, 'Converting page titles to lowercase' );
89  $this->output( "\"$display\" -> \"$targetDisplay\": $ok\n" );
90  }
91  if ( $ok === true ) {
92  $this->progress( 1 );
93  if ( $row->page_namespace == $this->namespace ) {
94  $talk = $target->getTalkPage();
95  $row->page_namespace = $talk->getNamespace();
96  if ( $talk->exists() ) {
97  return $this->processRow( $row );
98  }
99  }
100  }
101  return $this->progress( 0 );
102  }
103 }
104 
105 $maintClass = "CapsCleanup";
106 require_once RUN_MAINTENANCE_IF_MAIN;
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
$wgUser
$wgUser
Definition: Setup.php:552
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:388
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
CapsCleanup\execute
execute()
Do the actual work.
Definition: cleanupCaps.php:46
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
TableCleanup\progress
progress( $updated)
Definition: cleanupTable.inc:74
$maintClass
$maintClass
Definition: cleanupCaps.php:105
$ok
$ok
Definition: UtfNormalTest.php:71
TableCleanup
Generic class to cleanup a database table.
Definition: cleanupTable.inc:31
TableCleanup\runTable
runTable( $params)
Definition: cleanupTable.inc:108
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:333
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:181
CapsCleanup
Maintenance script to clean up broken page links when somebody turns on $wgCapitalLinks.
Definition: cleanupCaps.php:39
CapsCleanup\__construct
__construct()
Default constructor.
Definition: cleanupCaps.php:40
CapsCleanup\processRow
processRow( $row)
Definition: cleanupCaps.php:65