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" );
68 $callback =
'processRowToUppercase';
70 $this->
output(
"Will be moving pages to first letter lowercase titles" );
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 );
86 $lower = $row->page_title;
88 if ( $upper == $lower ) {
89 $this->
output(
"\"$display\" already uppercase.\n" );
95 $target = Title::makeTitle( $row->page_namespace, $upper );
98 $target = Title::newFromText(
'CapsCleanup/' . $display );
100 $ok = $this->movePage(
104 'Converting page title to first-letter uppercase',
109 if ( $row->page_namespace == $this->namespace ) {
111 $row->page_namespace = $talk->getNamespace();
112 if ( $talk->exists() ) {
123 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
125 $upper = $row->page_title;
127 if ( $upper == $lower ) {
128 $this->
output(
"\"$display\" already lowercase.\n" );
134 $target = Title::makeTitle( $row->page_namespace, $lower );
135 if ( $target->
exists() ) {
137 $this->
output(
"\"$display\" skipped; \"$targetDisplay\" already exists\n" );
143 $ok = $this->movePage( $current, $target,
'Converting page titles to lowercase',
true );
144 if ( $ok ===
true ) {
146 if ( $row->page_namespace == $this->namespace ) {
148 $row->page_namespace = $talk->getNamespace();
149 if ( $talk->exists() ) {
166 private function movePage(
Title $current,
Title $target, $reason, $createRedirect ) {
170 if ( $this->dryrun ) {
171 $this->
output(
"\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
175 ->newMovePage( $current, $target );
176 $status = $mp->move( $this->user, $reason, $createRedirect );
177 $ok = $status->isOK() ?
'OK' :
'FAILED';
178 $this->
output(
"\"$display\" -> \"$targetDisplay\": $ok\n" );
179 if ( !$status->isOK() ) {
180 $this->
error( $status );
error( $err, $die=0)
Throw an error to the user.
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.