29 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
35 $out->addWikiMsg(
'renameuser-summary' );
38 if ( !$user->isAllowed(
'renameuser' ) ) {
46 if ( $user->isBlocked() ) {
53 $showBlockLog = $request->getBool(
'submit-showBlockLog' );
54 $usernames = explode(
'/', $par, 2 );
55 $oldnamePar = trim( str_replace(
'_',
' ', $request->getText(
'oldusername', $usernames[0] ) ) );
56 $oldusername = Title::makeTitle(
NS_USER, $oldnamePar );
57 $newnamePar = $usernames[1] ??
null;
58 $newnamePar = trim( str_replace(
'_',
' ', $request->getText(
'newusername', $newnamePar ) ) );
61 $newusername = Title::makeTitleSafe(
NS_USER, $contLang->ucfirst( $newnamePar ) );
62 $oun = is_object( $oldusername ) ? $oldusername->getText() :
'';
63 $nun = is_object( $newusername ) ? $newusername->getText() :
'';
64 $token = $user->getEditToken();
65 $reason = $request->getText(
'reason' );
67 $move_checked = $request->getBool(
'movepages', !$request->wasPosted() );
68 $suppress_checked = $request->getCheck(
'suppressredirect' );
71 if ( $oun && $nun && !$request->getCheck(
'confirmaction' ) ) {
72 Hooks::run(
'RenameUserWarning', [ $oun, $nun, &$warnings ] );
76 Xml::openElement(
'form', [
81 Xml::openElement(
'fieldset' ) .
82 Xml::element(
'legend',
null, $this->
msg(
'renameuser' )->text() ) .
83 Xml::openElement(
'table', [
'id' =>
'mw-renameuser-table' ] ) .
85 <td class='mw-label'>" .
86 Xml::label( $this->
msg(
'renameuserold' )->text(),
'oldusername' ) .
88 <td class='mw-input'>" .
89 Xml::input(
'oldusername', 20, $oun, [
'type' =>
'text',
'tabindex' =>
'1' ] ) .
' ' .
93 <td class='mw-label'>" .
94 Xml::label( $this->
msg(
'renameusernew' )->text(),
'newusername' ) .
96 <td class='mw-input'>" .
97 Xml::input(
'newusername', 20, $nun, [
'type' =>
'text',
'tabindex' =>
'2' ] ) .
101 <td class='mw-label'>" .
102 Xml::label( $this->
msg(
'renameuserreason' )->text(),
'reason' ) .
104 <td class='mw-input'>" .
109 [
'type' =>
'text',
'tabindex' =>
'3',
'maxlength' => 255 ]
114 if ( $user->isAllowed(
'move' ) ) {
119 <td class='mw-input'>" .
120 Xml::checkLabel( $this->
msg(
'renameusermove' )->text(),
'movepages',
'movepages',
121 $move_checked, [
'tabindex' =>
'4' ] ) .
126 if ( $user->isAllowed(
'suppressredirect' ) ) {
131 <td class='mw-input'>" .
133 $this->
msg(
'renameusersuppress' )->text(),
137 [
'tabindex' =>
'5' ]
146 foreach ( $warnings as $warning ) {
147 $warningsHtml[] = is_array( $warning ) ?
148 $this->
msg( $warning[0] )->rawParams( array_slice( $warning, 1 ) )->escaped() :
149 $this->
msg( $warning )->escaped();
154 <td class='mw-label'>" . $this->
msg(
'renameuserwarnings' )->escaped() .
"
156 <td class='mw-input'>" .
157 '<ul class="error"><li>' .
158 implode(
'</li><li>', $warningsHtml ) .
'</li></ul>' .
166 <td class='mw-input'>" .
168 $this->
msg(
'renameuserconfirm' )->text(),
172 [
'tabindex' =>
'6' ]
182 <td class='mw-submit'>" .
184 $this->
msg(
'renameusersubmit' )->text(),
193 $this->
msg(
'renameuser-submit-blocklog' )->text(),
195 'name' =>
'submit-showBlockLog',
196 'id' =>
'submit-showBlockLog',
202 Xml::closeElement(
'table' ) .
203 Xml::closeElement(
'fieldset' ) .
204 Html::hidden(
'token', $token ) .
205 Xml::closeElement(
'form' ) .
"\n"
209 if ( $showBlockLog && is_object( $oldusername ) ) {
215 if ( $request->getText(
'token' ) ===
'' ) {
216 # They probably haven't even submitted the form, so don't go further.
218 } elseif ( $warnings ) {
219 # Let user read warnings
221 } elseif ( !$request->wasPosted() || !$user->matchEditToken( $request->getVal(
'token' ) ) ) {
222 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
'renameuser-error-request' );
225 } elseif ( !is_object( $oldusername ) ) {
226 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
227 [
'renameusererrorinvalid', $request->getText(
'oldusername' ) ] );
230 } elseif ( !is_object( $newusername ) ) {
231 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
232 [
'renameusererrorinvalid', $request->getText(
'newusername' ) ] );
235 } elseif ( $oldusername->getText() === $newusername->getText() ) {
236 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
'renameuser-error-same-user' );
242 $olduser = User::newFromName( $oldusername->getText(),
false );
243 $newuser = User::newFromName( $newusername->getText(),
'creatable' );
246 if ( !is_object( $olduser ) ) {
247 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
248 [
'renameusererrorinvalid', $oldusername->getText() ] );
252 if ( !is_object( $newuser ) || !User::isCreatableName( $newuser->getName() ) ) {
253 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
254 [
'renameusererrorinvalid', $newusername->getText() ] );
261 if ( $oldusername->getText() !== $contLang->ucfirst( $oldusername->getText() ) ) {
264 $uid =
$dbr->selectField(
'user',
'user_id',
265 [
'user_name' => $oldusername->getText() ],
267 if ( $uid ===
false ) {
272 $uid = $olduser->idForName();
273 $oldusername = Title::makeTitleSafe(
NS_USER, $olduser->getName() );
278 $uid = $olduser->idForName();
282 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
283 [
'renameusererrordoesnotexist', $oldusername->getText() ] );
288 if ( $newuser->idForName() !== 0 ) {
289 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
290 [
'renameusererrorexists', $newusername->getText() ] );
298 [ $uid, $oldusername->getText(), $newusername->getText() ]
305 $oldusername->getText(),
306 $newusername->getText(),
309 [
'reason' => $reason ]
311 if ( !$rename->rename() ) {
317 if ( $user->getId() === $uid ) {
318 $user->setName( $newusername->getText() );
322 if ( $request->getCheck(
'movepages' ) && $user->isAllowed(
'move' ) ) {
325 $pages =
$dbr->select(
327 [
'page_namespace',
'page_title' ],
331 'page_title ' .
$dbr->buildLike( $oldusername->getDBkey() .
'/',
$dbr->anyString() ),
332 'page_title = ' .
$dbr->addQuotes( $oldusername->getDBkey() ),
338 $suppressRedirect =
false;
340 if ( $request->getCheck(
'suppressredirect' ) && $user->isAllowed(
'suppressredirect' ) ) {
341 $suppressRedirect =
true;
346 foreach ( $pages as $row ) {
347 $oldPage = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
348 $newPage = Title::makeTitleSafe( $row->page_namespace,
349 preg_replace(
'!^[^/]+!', $newusername->getDBkey(), $row->page_title ) );
351 $movePage =
new MovePage( $oldPage, $newPage );
352 $validMoveStatus = $movePage->isValidMove();
354 # Do not autodelete or anything, title must not exist
355 if ( $newPage->exists() && !$validMoveStatus->isOK() ) {
357 $output .= Html::rawElement(
359 [
'class' =>
'mw-renameuser-pe' ],
360 $this->
msg(
'renameuser-page-exists' )->rawParams( $link )->escaped()
363 $logReason = $this->
msg(
364 'renameuser-move-log', $oldusername->getText(), $newusername->getText()
365 )->inContentLanguage()->text();
367 $moveStatus = $movePage->move( $user, $logReason, !$suppressRedirect );
369 if ( $moveStatus->isOK() ) {
370 # oldPage is not known in case of redirect suppression
371 $oldLink =
$linkRenderer->makeLink( $oldPage,
null, [], [
'redirect' =>
'no' ] );
373 # newPage is always known because the move was successful
376 $output .= Html::rawElement(
378 [
'class' =>
'mw-renameuser-pm' ],
379 $this->
msg(
'renameuser-page-moved' )->rawParams( $oldLink, $newLink )->escaped()
384 $output .= Html::rawElement(
385 'li', [
'class' =>
'mw-renameuser-pu' ],
386 $this->
msg(
'renameuser-page-unmoved' )->rawParams( $oldLink, $newLink )->escaped()
392 $out->addHTML( Html::rawElement(
'ul', [], $output ) );
397 $out->wrapWikiMsg(
"<div class=\"successbox\">$1</div><br style=\"clear:both\" />",
398 [
'renameusersuccess', $oldusername->getText(), $newusername->getText() ] );