48 parent::__construct();
50 $this->
addOption(
'namespace',
'Namespace number to run caps cleanup on',
false,
true );
56 $this->
namespace = intval( $this->
getOption( 'namespace', 0 ) );
59 MediaWikiServices::getInstance()->getNamespaceInfo()->
60 isCapitalized( $this->
namespace )
62 $this->
output(
"Will be moving pages to first letter capitalized titles" );
63 $callback =
'processRowToUppercase';
65 $this->
output(
"Will be moving pages to first letter lowercase titles" );
66 $callback =
'processRowToLowercase';
69 $this->dryrun = $this->
hasOption(
'dry-run' );
73 'conds' => [
'page_namespace' => $this->
namespace ],
75 'callback' => $callback ] );
79 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
81 $lower = $row->page_title;
82 $upper = MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $row->page_title );
83 if ( $upper == $lower ) {
84 $this->
output(
"\"$display\" already uppercase.\n" );
89 $target = Title::makeTitle( $row->page_namespace, $upper );
92 $target = Title::newFromText(
'CapsCleanup/' . $display );
94 $ok = $this->movePage(
98 'Converting page title to first-letter uppercase',
103 if ( $row->page_namespace == $this->namespace ) {
105 $row->page_namespace = $talk->getNamespace();
106 if ( $talk->exists() ) {
116 $current = Title::makeTitle( $row->page_namespace, $row->page_title );
118 $upper = $row->page_title;
119 $lower = MediaWikiServices::getInstance()->getContentLanguage()->lcfirst( $row->page_title );
120 if ( $upper == $lower ) {
121 $this->
output(
"\"$display\" already lowercase.\n" );
126 $target = Title::makeTitle( $row->page_namespace, $lower );
127 if ( $target->
exists() ) {
129 $this->
output(
"\"$display\" skipped; \"$targetDisplay\" already exists\n" );
134 $ok = $this->movePage( $current, $target,
'Converting page titles to lowercase',
true );
135 if ( $ok ===
true ) {
137 if ( $row->page_namespace == $this->namespace ) {
139 $row->page_namespace = $talk->getNamespace();
140 if ( $talk->exists() ) {
156 private function movePage(
Title $current,
Title $target, $reason, $createRedirect ) {
160 if ( $this->dryrun ) {
161 $this->
output(
"\"$display\" -> \"$targetDisplay\": DRY RUN, NOT MOVED\n" );
164 $mp = MediaWikiServices::getInstance()->getMovePageFactory()
165 ->newMovePage( $current, $target );
166 $status = $mp->move( $this->user, $reason, $createRedirect );
167 $ok = $status->isOK() ?
'OK' : $status->getMessage(
false,
false,
'en' )->text();
168 $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.