65 $this->initServices();
67 $oldName = $this->getArg(
'old-name' );
68 $newName = $this->getArg(
'new-name' );
70 $oldUser = $this->userFactory->newFromName( $oldName );
72 $this->fatalError(
'The specified old username is invalid' );
75 if ( !$oldUser->isRegistered() ) {
76 $this->fatalError(
'The user does not exist' );
79 if ( !$this->getOption(
'force-global-detach' )
80 && $this->centralLookup
81 && $this->centralLookup->isAttached( $oldUser )
83 $this->fatalError(
'The user is globally attached. Use CentralAuth to rename this account.' );
86 $newUser = $this->userFactory->newFromName( $newName, UserFactory::RIGOR_CREATABLE );
88 $this->fatalError(
'The specified new username is invalid' );
89 } elseif ( $newUser->isRegistered() ) {
90 $this->fatalError(
'New username must be free' );
93 if ( $this->getOption(
'performer' ) ===
null ) {
94 $performer = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
96 $performer = $this->userFactory->
newFromName( $this->getOption(
'performer' ) );
100 $this->fatalError(
'Performer does not exist.' );
109 'reason' => $this->getOption(
'reason' )
113 if ( !$renamer->rename() ) {
114 $this->fatalError(
'Renaming failed.' );
116 $this->output(
"{$oldUser->getName()} was successfully renamed to {$newUser->getName()}.\n" );
120 if ( !$this->getOption(
'skip-page-moves' ) ) {
121 $numRenames += $this->movePageAndSubpages(
124 $newUser->getUserPage(),
127 $numRenames += $this->movePageAndSubpages(
130 $newUser->getTalkPage(),
134 if ( $numRenames > 0 ) {
135 $this->output(
"$numRenames user page(s) renamed\n" );