86 $block = $performer->getBlock();
92 $out->addWikiMsg(
'renameuser-summary' );
99 $userNames = $par !==
null ? explode(
'/', $par, 2 ) : [];
102 $oldName = $request->getText(
'oldusername', $userNames[0] ??
'' );
103 $oldName = trim( str_replace(
'_',
' ', $oldName ) );
107 $origNewName = $request->getText(
'newusername', $userNames[1] ??
'' );
108 $origNewName = trim( str_replace(
'_',
' ', $origNewName ) );
111 $newTitle = $this->titleFactory->
makeTitleSafe(
NS_USER, $this->contentLanguage->ucfirst( $origNewName ) );
112 $newName = $newTitle ? $newTitle->
getText() :
'';
114 $reason = $request->getText(
'reason' );
115 $moveChecked = $request->getBool(
'movepages', !$request->wasPosted() );
116 $suppressChecked = $request->getCheck(
'suppressredirect' );
118 if ( $oldName !==
'' && $newName !==
'' && !$request->getCheck(
'confirmaction' ) ) {
119 $warnings = $this->getWarnings( $oldName, $newName );
124 $this->showForm( $oldName, $newName, $warnings, $reason, $moveChecked, $suppressChecked );
126 if ( $request->getText(
'token' ) ===
'' ) {
127 # They probably haven't even submitted the form, so don't go further.
129 } elseif ( $warnings ) {
130 # Let user read warnings
132 } elseif ( !$request->wasPosted() || !$performer->matchEditToken( $request->getVal(
'token' ) ) ) {
133 $out->addHTML( Html::errorBox( $out->msg(
'renameuser-error-request' )->parse() ) );
136 } elseif ( !$newTitle ) {
137 $out->addHTML( Html::errorBox(
138 $out->msg(
'renameusererrorinvalid' )->params( $request->getText(
'newusername' ) )->parse()
142 } elseif ( $oldName === $newName ) {
143 $out->addHTML( Html::errorBox( $out->msg(
'renameuser-error-same-user' )->parse() ) );
149 $oldUser = $this->userFactory->newFromName( $oldName, $this->userFactory::RIGOR_NONE );
150 $newUser = $this->userFactory->newFromName( $newName, $this->userFactory::RIGOR_CREATABLE );
154 $out->addHTML( Html::errorBox(
155 $out->msg(
'renameusererrorinvalid' )->params( $oldTitle->
getText() )->parse()
161 $out->addHTML( Html::errorBox(
162 $out->msg(
'renameusererrorinvalid' )->params( $newTitle->
getText() )->parse()
170 if ( $oldName !== $this->contentLanguage->ucfirst( $oldName ) ) {
172 $dbr = $this->dbConns->getReplicaDatabase();
173 $uid =
$dbr->newSelectQueryBuilder()
174 ->select(
'user_id' )
176 ->where( [
'user_name' => $oldName ] )
177 ->caller( __METHOD__ )
179 if ( $uid ===
false ) {
180 if ( !$this->
getConfig()->
get(
'CapitalLinks' ) ) {
184 $uid = $oldUser->idForName();
187 $out->addHTML( Html::errorBox(
188 $out->msg(
'renameusererrorinvalid' )->params( $oldName )->parse()
192 $oldName = $oldTitle->
getText();
197 $uid = $oldUser->idForName();
201 $out->addHTML( Html::errorBox(
202 $out->msg(
'renameusererrordoesnotexist' )->params( $oldName )->parse()
208 if ( $newUser->idForName() !== 0 ) {
209 $out->addHTML( Html::errorBox(
210 $out->msg(
'renameusererrorexists' )->params( $newName )->parse()
217 if ( !$this->
getHookRunner()->onRenameUserAbort( $uid, $oldName, $newName ) ) {
227 [
'reason' => $reason ]
229 if ( !$rename->rename() ) {
235 if ( $performer->getId() === $uid ) {
236 $performer->setName( $newTitle->
getText() );
240 if ( $moveChecked && $this->permissionManager->userHasRight( $performer,
'move' ) ) {
241 $suppressRedirect = $suppressChecked
242 && $this->permissionManager->userHasRight( $performer,
'suppressredirect' );
243 $this->movePages( $oldTitle, $newTitle, $suppressRedirect );
249 $out->msg(
'renameusersuccess' )