36require_once __DIR__ .
'/TableCleanup.php';
53 parent::__construct();
55 $this->
addOption(
'namespace',
'Namespace number to run caps cleanup on',
false,
true );
59 $this->user = User::newSystemUser(
'Conversion script', [
'steal' =>
true ] );
61 $this->
namespace = intval( $this->
getOption( 'namespace', 0 ) );
65 isCapitalized( $this->
namespace )
67 $this->
output(
"Will be moving pages to first letter capitalized titles\n" );
68 $callback =
'processRowToUppercase';
70 $this->
output(
"Will be moving pages to first letter lowercase titles\n" );
71 $callback =
'processRowToLowercase';
74 $this->dryrun = $this->
hasOption(
'dry-run' );
78 'conds' => [
'page_namespace' => $this->
namespace ],
80 'callback' => $callback ] );
84 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
88 $current->mArticleID = $row->page_id;
90 $lower = $row->page_title;
92 if ( $upper == $lower ) {
93 $this->
output(
"\"$display\" already uppercase.\n" );
99 $target = Title::makeTitle( $row->page_namespace, $upper );
100 if ( $target->
exists() ) {
102 $target = Title::newFromText(
'CapsCleanup/' . $display );
104 $ok = $this->movePage(
108 'Converting page title to first-letter uppercase',
117 if ( $row->page_namespace == $this->namespace ) {
122 if ( $namespaceInfo->canHaveTalkPage( $current ) ) {
123 $talkNamespace = $namespaceInfo->getTalk( $row->page_namespace );
124 $talkPageExists = $this->
getReplicaDB()->newSelectQueryBuilder()
127 ->where( [
'page_title' => $row->page_title,
'page_namespace' => $talkNamespace ] )
128 ->caller( __METHOD__ )
130 if ( $talkPageExists ) {
131 $row->page_namespace = $talkNamespace;
139 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
141 $upper = $row->page_title;
143 if ( $upper == $lower ) {
144 $this->
output(
"\"$display\" already lowercase.\n" );
150 $target = Title::makeTitle( $row->page_namespace, $lower );
151 if ( $target->
exists() ) {
153 $this->
output(
"\"$display\" skipped; \"$targetDisplay\" already exists\n" );
159 $ok = $this->movePage( $current, $target,
'Converting page titles to lowercase',
true );
160 if ( $ok !==
true ) {
165 if ( $row->page_namespace == $this->namespace ) {
167 if ( $talk->exists() ) {
168 $row->page_namespace = $talk->getNamespace();
181 private function movePage(
Title $current,
Title $target, $reason, $createRedirect ) {
185 if ( $this->dryrun ) {
186 $this->
output(
"\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
190 ->newMovePage( $current, $target );
191 $status = $mp->move( $this->user, $reason, $createRedirect );
192 $ok = $status->isOK() ?
'OK' :
'FAILED';
193 $this->
output(
"\"$display\" -> \"$targetDisplay\": $ok\n" );
194 if ( !$status->isOK() ) {
195 $this->
error( $status );
205require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script to clean up broken page links when somebody turns on or off $wgCapitalLinks.
processRowToUppercase(\stdClass $row)
__construct()
Default constructor.
processRowToLowercase(\stdClass $row)
execute()
Do the actual work.
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
Generic class to cleanup a database table.