22require_once __DIR__ .
'/TableCleanup.php';
39 parent::__construct();
41 $this->
addOption(
'namespace',
'Namespace number to run caps cleanup on',
false,
true );
45 $this->user = User::newSystemUser(
'Conversion script', [
'steal' =>
true ] );
47 $this->
namespace = intval( $this->
getOption( 'namespace', 0 ) );
51 isCapitalized( $this->
namespace )
53 $this->
output(
"Will be moving pages to first letter capitalized titles\n" );
54 $callback =
'processRowToUppercase';
56 $this->
output(
"Will be moving pages to first letter lowercase titles\n" );
57 $callback =
'processRowToLowercase';
60 $this->dryrun = $this->
hasOption(
'dry-run' );
64 'conds' => [
'page_namespace' => $this->
namespace ],
66 'callback' => $callback ] );
70 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
74 $current->mArticleID = $row->page_id;
76 $lower = $row->page_title;
78 if ( $upper == $lower ) {
79 $this->
output(
"\"$display\" already uppercase.\n" );
85 $target = Title::makeTitle( $row->page_namespace, $upper );
88 $target = Title::newFromText(
'CapsCleanup/' . $display );
90 $ok = $this->movePage(
94 'Converting page title to first-letter uppercase',
103 if ( $row->page_namespace == $this->namespace ) {
108 if ( $namespaceInfo->canHaveTalkPage( $current ) ) {
109 $talkNamespace = $namespaceInfo->getTalk( $row->page_namespace );
110 $talkPageExists = $this->
getReplicaDB()->newSelectQueryBuilder()
113 ->where( [
'page_title' => $row->page_title,
'page_namespace' => $talkNamespace ] )
114 ->caller( __METHOD__ )
116 if ( $talkPageExists ) {
117 $row->page_namespace = $talkNamespace;
125 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
127 $upper = $row->page_title;
129 if ( $upper == $lower ) {
130 $this->
output(
"\"$display\" already lowercase.\n" );
136 $target = Title::makeTitle( $row->page_namespace, $lower );
137 if ( $target->
exists() ) {
139 $this->
output(
"\"$display\" skipped; \"$targetDisplay\" already exists\n" );
145 $ok = $this->movePage( $current, $target,
'Converting page titles to lowercase',
true );
146 if ( $ok !==
true ) {
151 if ( $row->page_namespace == $this->namespace ) {
153 if ( $talk->exists() ) {
154 $row->page_namespace = $talk->getNamespace();
167 private function movePage(
Title $current,
Title $target, $reason, $createRedirect ) {
171 if ( $this->dryrun ) {
172 $this->
output(
"\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
176 ->newMovePage( $current, $target );
177 $status = $mp->move( $this->user, $reason, $createRedirect );
178 $ok = $status->isOK() ?
'OK' :
'FAILED';
179 $this->
output(
"\"$display\" -> \"$targetDisplay\": $ok\n" );
180 if ( !$status->isOK() ) {
181 $this->
error( $status );
191require_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.
getReplicaDB(string|false $virtualDomain=false)
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.