MediaWiki REL1_28
cleanupCaps.php
Go to the documentation of this file.
1<?php
32require_once __DIR__ . '/cleanupTable.inc';
33
41
42 private $user;
43 private $namespace;
44
45 public function __construct() {
46 parent::__construct();
47 $this->addDescription( 'Script to cleanup capitalization' );
48 $this->addOption( 'namespace', 'Namespace number to run caps cleanup on', false, true );
49 }
50
51 public function execute() {
52 $this->user = User::newSystemUser( 'Conversion script', [ 'steal' => true ] );
53
54 $this->namespace = intval( $this->getOption( 'namespace', 0 ) );
55
56 if ( MWNamespace::isCapitalized( $this->namespace ) ) {
57 $this->output( "Will be moving pages to first letter capitalized titles" );
58 $callback = 'processRowToUppercase';
59 } else {
60 $this->output( "Will be moving pages to first letter lowercase titles" );
61 $callback = 'processRowToLowercase';
62 }
63
64 $this->dryrun = $this->hasOption( 'dry-run' );
65
66 $this->runTable( [
67 'table' => 'page',
68 'conds' => [ 'page_namespace' => $this->namespace ],
69 'index' => 'page_id',
70 'callback' => $callback ] );
71 }
72
73 protected function processRowToUppercase( $row ) {
75
76 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
77 $display = $current->getPrefixedText();
78 $lower = $row->page_title;
79 $upper = $wgContLang->ucfirst( $row->page_title );
80 if ( $upper == $lower ) {
81 $this->output( "\"$display\" already uppercase.\n" );
82
83 return $this->progress( 0 );
84 }
85
86 $target = Title::makeTitle( $row->page_namespace, $upper );
87 if ( $target->exists() ) {
88 // Prefix "CapsCleanup" to bypass the conflict
89 $target = Title::newFromText( __CLASS__ . '/' . $display );
90 }
91 $ok = $this->movePage(
92 $current,
93 $target,
94 'Converting page title to first-letter uppercase',
95 false
96 );
97 if ( $ok ) {
98 $this->progress( 1 );
99 if ( $row->page_namespace == $this->namespace ) {
100 $talk = $target->getTalkPage();
101 $row->page_namespace = $talk->getNamespace();
102 if ( $talk->exists() ) {
103 return $this->processRowToUppercase( $row );
104 }
105 }
106 }
107
108 return $this->progress( 0 );
109 }
110
111 protected function processRowToLowercase( $row ) {
113
114 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
115 $display = $current->getPrefixedText();
116 $upper = $row->page_title;
117 $lower = $wgContLang->lcfirst( $row->page_title );
118 if ( $upper == $lower ) {
119 $this->output( "\"$display\" already lowercase.\n" );
120
121 return $this->progress( 0 );
122 }
123
124 $target = Title::makeTitle( $row->page_namespace, $lower );
125 if ( $target->exists() ) {
126 $targetDisplay = $target->getPrefixedText();
127 $this->output( "\"$display\" skipped; \"$targetDisplay\" already exists\n" );
128
129 return $this->progress( 0 );
130 }
131
132 $ok = $this->movePage( $current, $target, 'Converting page titles to lowercase', true );
133 if ( $ok === true ) {
134 $this->progress( 1 );
135 if ( $row->page_namespace == $this->namespace ) {
136 $talk = $target->getTalkPage();
137 $row->page_namespace = $talk->getNamespace();
138 if ( $talk->exists() ) {
139 return $this->processRowToLowercase( $row );
140 }
141 }
142 }
143
144 return $this->progress( 0 );
145 }
146
154 private function movePage( Title $current, Title $target, $reason, $createRedirect ) {
155 $display = $current->getPrefixedText();
156 $targetDisplay = $target->getPrefixedText();
157
158 if ( $this->dryrun ) {
159 $this->output( "\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
160 $ok = 'OK';
161 } else {
162 $mp = new MovePage( $current, $target );
163 $status = $mp->move( $this->user, $reason, $createRedirect );
164 $ok = $status->isOK() ? 'OK' : $status->getWikiText( false, false, 'en' );
165 $this->output( "\"$display\" -> \"$targetDisplay\": $ok\n" );
166 }
167
168 return $ok === 'OK';
169 }
170}
171
172$maintClass = "CapsCleanup";
173require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script to clean up broken page links when somebody turns on or off $wgCapitalLinks.
movePage(Title $current, Title $target, $reason, $createRedirect)
execute()
Do the actual work.
__construct()
Default constructor.
processRowToUppercase( $row)
processRowToLowercase( $row)
hasOption( $name)
Checks to see if a particular param exists.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
Handles the backend logic of moving a page from one title to another.
Definition MovePage.php:30
Generic class to cleanup a database table.
progress( $updated)
runTable( $params)
Represents a title within MediaWiki.
Definition Title.php:36
getPrefixedText()
Get the prefixed title with spaces.
Definition Title.php:1455
$maintClass
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 local content language as $wgContLang
Definition design.txt:57
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Wikitext formatted, in the key only.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition hooks.txt:1049
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
require_once RUN_MAINTENANCE_IF_MAIN