49 parent::__construct();
51 $this->
addOption(
'namespace',
'Namespace number to run caps cleanup on',
false,
true );
57 $this->
namespace = intval( $this->
getOption( 'namespace', 0 ) );
60 MediaWikiServices::getInstance()->getNamespaceInfo()->
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;
83 $upper = MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $row->page_title );
84 if ( $upper == $lower ) {
85 $this->
output(
"\"$display\" already uppercase.\n" );
90 $target = Title::makeTitle( $row->page_namespace, $upper );
93 $target = Title::newFromText(
'CapsCleanup/' . $display );
95 $ok = $this->movePage(
99 'Converting page title to first-letter uppercase',
104 if ( $row->page_namespace == $this->namespace ) {
106 $row->page_namespace = $talk->getNamespace();
107 if ( $talk->exists() ) {
117 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
119 $upper = $row->page_title;
120 $lower = MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $row->page_title );
121 if ( $upper == $lower ) {
122 $this->
output(
"\"$display\" already lowercase.\n" );
127 $target = Title::makeTitle( $row->page_namespace, $lower );
128 if ( $target->
exists() ) {
130 $this->
output(
"\"$display\" skipped; \"$targetDisplay\" already exists\n" );
135 $ok = $this->movePage( $current, $target,
'Converting page titles to lowercase',
true );
136 if ( $ok ===
true ) {
138 if ( $row->page_namespace == $this->namespace ) {
140 $row->page_namespace = $talk->getNamespace();
141 if ( $talk->exists() ) {
157 private function movePage(
Title $current,
Title $target, $reason, $createRedirect ) {
161 if ( $this->dryrun ) {
162 $this->
output(
"\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
165 $mp = MediaWikiServices::getInstance()->getMovePageFactory()
166 ->newMovePage( $current, $target );
167 $status = $mp->move( $this->user, $reason, $createRedirect );
168 $ok = $status->isOK() ?
'OK' : $status->getMessage(
false,
false,
'en' )->text();
169 $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.
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.