32 $out->addWikiMsg(
'renameuser-summary' );
35 if ( !$user->isAllowed(
'renameuser' ) ) {
43 if ( $user->isBlocked() ) {
50 $showBlockLog =
$request->getBool(
'submit-showBlockLog' );
51 $usernames = explode(
'/', $par, 2 );
52 $oldnamePar = trim( str_replace(
'_',
' ',
$request->getText(
'oldusername', $usernames[0] ) ) );
53 $oldusername = Title::makeTitle( NS_USER, $oldnamePar );
54 $newnamePar = isset( $usernames[1] ) ? $usernames[1] :
null;
55 $newnamePar = trim( str_replace(
'_',
' ',
$request->getText(
'newusername', $newnamePar ) ) );
58 $newusername = Title::makeTitleSafe( NS_USER,
$wgContLang->ucfirst( $newnamePar ) );
59 $oun = is_object( $oldusername ) ? $oldusername->getText() :
'';
60 $nun = is_object( $newusername ) ? $newusername->getText() :
'';
61 $token = $user->getEditToken();
62 $reason =
$request->getText(
'reason' );
65 $suppress_checked =
$request->getCheck(
'suppressredirect' );
68 if ( $oun && $nun && !
$request->getCheck(
'confirmaction' ) ) {
69 Hooks::run(
'RenameUserWarning', [ $oun, $nun, &$warnings ] );
73 Xml::openElement(
'form', [
78 Xml::openElement(
'fieldset' ) .
79 Xml::element(
'legend',
null, $this->
msg(
'renameuser' )->
text() ) .
80 Xml::openElement(
'table', [
'id' =>
'mw-renameuser-table' ] ) .
82 <td class='mw-label'>" .
83 Xml::label( $this->
msg(
'renameuserold' )->
text(),
'oldusername' ) .
85 <td class='mw-input'>" .
86 Xml::input(
'oldusername', 20, $oun, [
'type' =>
'text',
'tabindex' =>
'1' ] ) .
' ' .
90 <td class='mw-label'>" .
91 Xml::label( $this->
msg(
'renameusernew' )->
text(),
'newusername' ) .
93 <td class='mw-input'>" .
94 Xml::input(
'newusername', 20, $nun, [
'type' =>
'text',
'tabindex' =>
'2' ] ) .
98 <td class='mw-label'>" .
99 Xml::label( $this->
msg(
'renameuserreason' )->
text(),
'reason' ) .
101 <td class='mw-input'>" .
106 [
'type' =>
'text',
'tabindex' =>
'3',
'maxlength' => 255 ]
111 if ( $user->isAllowed(
'move' ) ) {
116 <td class='mw-input'>" .
117 Xml::checkLabel( $this->
msg(
'renameusermove' )->
text(),
'movepages',
'movepages',
118 $move_checked, [
'tabindex' =>
'4' ] ) .
123 if ( $user->isAllowed(
'suppressredirect' ) ) {
128 <td class='mw-input'>" .
130 $this->
msg(
'renameusersuppress' )->
text(),
134 [
'tabindex' =>
'5' ]
143 foreach ( $warnings as $warning ) {
144 $warningsHtml[] = is_array( $warning ) ?
145 $this->
msg( $warning[0] )->rawParams( array_slice( $warning, 1 ) )->escaped() :
146 $this->
msg( $warning )->escaped();
151 <td class='mw-label'>" . $this->
msg(
'renameuserwarnings' )->escaped() .
"
153 <td class='mw-input'>" .
154 '<ul class="error"><li>' .
155 implode(
'</li><li>', $warningsHtml ) .
'</li></ul>' .
163 <td class='mw-input'>" .
165 $this->
msg(
'renameuserconfirm' )->
text(),
169 [
'tabindex' =>
'6' ]
179 <td class='mw-submit'>" .
181 $this->
msg(
'renameusersubmit' )->
text(),
190 $this->
msg(
'renameuser-submit-blocklog' )->
text(),
192 'name' =>
'submit-showBlockLog',
193 'id' =>
'submit-showBlockLog',
199 Xml::closeElement(
'table' ) .
200 Xml::closeElement(
'fieldset' ) .
201 Html::hidden(
'token', $token ) .
202 Xml::closeElement(
'form' ) .
"\n"
206 if ( $showBlockLog && is_object( $oldusername ) ) {
212 if (
$request->getText(
'token' ) ===
'' ) {
213 # They probably haven't even submitted the form, so don't go further.
215 } elseif ( $warnings ) {
216 # Let user read warnings
218 } elseif ( !
$request->wasPosted() || !$user->matchEditToken(
$request->getVal(
'token' ) ) ) {
219 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
'renameuser-error-request' );
222 } elseif ( !is_object( $oldusername ) ) {
223 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
224 [
'renameusererrorinvalid',
$request->getText(
'oldusername' ) ] );
227 } elseif ( !is_object( $newusername ) ) {
228 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
229 [
'renameusererrorinvalid',
$request->getText(
'newusername' ) ] );
232 } elseif ( $oldusername->getText() === $newusername->getText() ) {
233 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
'renameuser-error-same-user' );
243 if ( !is_object( $olduser ) ) {
244 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
245 [
'renameusererrorinvalid', $oldusername->getText() ] );
250 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
251 [
'renameusererrorinvalid', $newusername->getText() ] );
258 if ( $oldusername->getText() !==
$wgContLang->ucfirst( $oldusername->getText() ) ) {
261 $uid =
$dbr->selectField(
'user',
'user_id',
262 [
'user_name' => $oldusername->getText() ],
264 if ( $uid ===
false ) {
269 $uid = $olduser->idForName();
270 $oldusername = Title::makeTitleSafe( NS_USER, $olduser->getName() );
275 $uid = $olduser->idForName();
279 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
280 [
'renameusererrordoesnotexist', $oldusername->getText() ] );
285 if ( $newuser->idForName() !== 0 ) {
286 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
287 [
'renameusererrorexists', $newusername->getText() ] );
295 [ $uid, $oldusername->getText(), $newusername->getText() ]
302 $oldusername->getText(),
303 $newusername->getText(),
306 [
'reason' => $reason ]
308 if ( !$rename->rename() ) {
314 if ( $user->getId() === $uid ) {
315 $user->setName( $newusername->getText() );
319 if (
$request->getCheck(
'movepages' ) && $user->isAllowed(
'move' ) ) {
322 $pages =
$dbr->select(
324 [
'page_namespace',
'page_title' ],
328 'page_title ' .
$dbr->buildLike( $oldusername->getDBkey() .
'/',
$dbr->anyString() ),
329 'page_title = ' .
$dbr->addQuotes( $oldusername->getDBkey() ),
335 $suppressRedirect =
false;
337 if (
$request->getCheck(
'suppressredirect' ) && $user->isAllowed(
'suppressredirect' ) ) {
338 $suppressRedirect =
true;
343 foreach ( $pages as $row ) {
344 $oldPage = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
345 $newPage = Title::makeTitleSafe( $row->page_namespace,
346 preg_replace(
'!^[^/]+!', $newusername->getDBkey(), $row->page_title ) );
347 # Do not autodelete or anything, title must not exist
348 if ( $newPage->exists() && !$oldPage->isValidMoveTarget( $newPage ) ) {
352 [
'class' =>
'mw-renameuser-pe' ],
353 $this->
msg(
'renameuser-page-exists' )->rawParams(
$link )->escaped()
360 'renameuser-move-log',
361 $oldusername->getText(),
362 $newusername->getText() )->inContentLanguage()->text(),
366 # oldPage is not known in case of redirect suppression
367 $oldLink =
$linkRenderer->makeLink( $oldPage,
null, [], [
'redirect' =>
'no' ] );
369 # newPage is always known because the move was successful
374 [
'class' =>
'mw-renameuser-pm' ],
375 $this->
msg(
'renameuser-page-moved' )->rawParams( $oldLink, $newLink )->escaped()
381 'li', [
'class' =>
'mw-renameuser-pu' ],
382 $this->
msg(
'renameuser-page-unmoved' )->rawParams( $oldLink, $newLink )->escaped()
388 $out->addHTML( Html::rawElement(
'ul', [],
$output ) );
393 $out->wrapWikiMsg(
"<div class=\"successbox\">$1</div><br style=\"clear:both\" />",
394 [
'renameusersuccess', $oldusername->getText(), $newusername->getText() ] );