49 parent::__construct();
51 $this->
addOption(
'namespace',
'Namespace number to run caps cleanup on',
false,
true );
55 $this->user = User::newSystemUser(
'Conversion script', [
'steal' =>
true ] );
57 $this->
namespace = intval( $this->
getOption( 'namespace', 0 ) );
61 isCapitalized( $this->
namespace )
63 $this->
output(
"Will be moving pages to first letter capitalized titles" );
64 $callback =
'processRowToUppercase';
66 $this->
output(
"Will be moving pages to first letter lowercase titles" );
67 $callback =
'processRowToLowercase';
70 $this->dryrun = $this->
hasOption(
'dry-run' );
74 'conds' => [
'page_namespace' => $this->
namespace ],
76 'callback' => $callback ] );
80 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
82 $lower = $row->page_title;
84 if ( $upper == $lower ) {
85 $this->
output(
"\"$display\" already uppercase.\n" );
91 $target = Title::makeTitle( $row->page_namespace, $upper );
94 $target = Title::newFromText(
'CapsCleanup/' . $display );
96 $ok = $this->movePage(
100 'Converting page title to first-letter uppercase',
105 if ( $row->page_namespace == $this->namespace ) {
107 $row->page_namespace = $talk->getNamespace();
108 if ( $talk->exists() ) {
119 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
121 $upper = $row->page_title;
123 if ( $upper == $lower ) {
124 $this->
output(
"\"$display\" already lowercase.\n" );
130 $target = Title::makeTitle( $row->page_namespace, $lower );
131 if ( $target->
exists() ) {
133 $this->
output(
"\"$display\" skipped; \"$targetDisplay\" already exists\n" );
139 $ok = $this->movePage( $current, $target,
'Converting page titles to lowercase',
true );
140 if ( $ok ===
true ) {
142 if ( $row->page_namespace == $this->namespace ) {
144 $row->page_namespace = $talk->getNamespace();
145 if ( $talk->exists() ) {
162 private function movePage(
Title $current,
Title $target, $reason, $createRedirect ) {
166 if ( $this->dryrun ) {
167 $this->
output(
"\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
171 ->newMovePage( $current, $target );
172 $status = $mp->move( $this->user, $reason, $createRedirect );
173 $ok = $status->isOK() ?
'OK' : $status->getMessage(
false,
false,
'en' )->text();
174 $this->
output(
"\"$display\" -> \"$targetDisplay\": $ok\n" );
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
getServiceContainer()
Returns the main service container.
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.