31 $out->addWikiMsg(
'renameuser-summary' );
34 if ( !$user->isAllowed(
'renameuser' ) ) {
42 if ( $user->isBlocked() ) {
49 $showBlockLog =
$request->getBool(
'submit-showBlockLog' );
50 $usernames = explode(
'/', $par, 2 );
51 $oldnamePar = trim( str_replace(
'_',
' ',
$request->getText(
'oldusername', $usernames[0] ) ) );
52 $oldusername = Title::makeTitle( NS_USER, $oldnamePar );
53 $newnamePar = isset( $usernames[1] ) ? $usernames[1] :
null;
54 $newnamePar = trim( str_replace(
'_',
' ',
$request->getText(
'newusername', $newnamePar ) ) );
57 $newusername = Title::makeTitleSafe( NS_USER,
$wgContLang->ucfirst( $newnamePar ) );
58 $oun = is_object( $oldusername ) ? $oldusername->getText() :
'';
59 $nun = is_object( $newusername ) ? $newusername->getText() :
'';
60 $token = $user->getEditToken();
61 $reason =
$request->getText(
'reason' );
64 $suppress_checked =
$request->getCheck(
'suppressredirect' );
67 if ( $oun && $nun && !
$request->getCheck(
'confirmaction' ) ) {
68 Hooks::run(
'RenameUserWarning', [ $oun, $nun, &$warnings ] );
72 Xml::openElement(
'form', [
77 Xml::openElement(
'fieldset' ) .
78 Xml::element(
'legend',
null, $this->
msg(
'renameuser' )->
text() ) .
79 Xml::openElement(
'table', [
'id' =>
'mw-renameuser-table' ] ) .
81 <td class='mw-label'>" .
82 Xml::label( $this->
msg(
'renameuserold' )->
text(),
'oldusername' ) .
84 <td class='mw-input'>" .
85 Xml::input(
'oldusername', 20, $oun, [
'type' =>
'text',
'tabindex' =>
'1' ] ) .
' ' .
89 <td class='mw-label'>" .
90 Xml::label( $this->
msg(
'renameusernew' )->
text(),
'newusername' ) .
92 <td class='mw-input'>" .
93 Xml::input(
'newusername', 20, $nun, [
'type' =>
'text',
'tabindex' =>
'2' ] ) .
97 <td class='mw-label'>" .
98 Xml::label( $this->
msg(
'renameuserreason' )->
text(),
'reason' ) .
100 <td class='mw-input'>" .
105 [
'type' =>
'text',
'tabindex' =>
'3',
'maxlength' => 255 ]
110 if ( $user->isAllowed(
'move' ) ) {
115 <td class='mw-input'>" .
116 Xml::checkLabel( $this->
msg(
'renameusermove' )->
text(),
'movepages',
'movepages',
117 $move_checked, [
'tabindex' =>
'4' ] ) .
122 if ( $user->isAllowed(
'suppressredirect' ) ) {
127 <td class='mw-input'>" .
129 $this->
msg(
'renameusersuppress' )->
text(),
133 [
'tabindex' =>
'5' ]
142 foreach ( $warnings as $warning ) {
143 $warningsHtml[] = is_array( $warning ) ?
144 $this->
msg( $warning[0] )->rawParams( array_slice( $warning, 1 ) )->escaped() :
145 $this->
msg( $warning )->escaped();
150 <td class='mw-label'>" . $this->
msg(
'renameuserwarnings' )->escaped() .
"
152 <td class='mw-input'>" .
153 '<ul class="error"><li>' .
154 implode(
'</li><li>', $warningsHtml ) .
'</li></ul>' .
162 <td class='mw-input'>" .
164 $this->
msg(
'renameuserconfirm' )->
text(),
168 [
'tabindex' =>
'6' ]
178 <td class='mw-submit'>" .
180 $this->
msg(
'renameusersubmit' )->
text(),
189 $this->
msg(
'renameuser-submit-blocklog' )->
text(),
191 'name' =>
'submit-showBlockLog',
192 'id' =>
'submit-showBlockLog',
198 Xml::closeElement(
'table' ) .
199 Xml::closeElement(
'fieldset' ) .
200 Html::hidden(
'token', $token ) .
201 Xml::closeElement(
'form' ) .
"\n"
205 if ( $showBlockLog && is_object( $oldusername ) ) {
211 if (
$request->getText(
'token' ) ===
'' ) {
212 # They probably haven't even submitted the form, so don't go further.
214 } elseif ( $warnings ) {
215 # Let user read warnings
217 } elseif ( !
$request->wasPosted() || !$user->matchEditToken(
$request->getVal(
'token' ) ) ) {
218 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
'renameuser-error-request' );
221 } elseif ( !is_object( $oldusername ) ) {
222 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
223 [
'renameusererrorinvalid',
$request->getText(
'oldusername' ) ] );
226 } elseif ( !is_object( $newusername ) ) {
227 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
228 [
'renameusererrorinvalid',
$request->getText(
'newusername' ) ] );
231 } elseif ( $oldusername->getText() === $newusername->getText() ) {
232 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
'renameuser-error-same-user' );
242 if ( !is_object( $olduser ) ) {
243 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
244 [
'renameusererrorinvalid', $oldusername->getText() ] );
249 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
250 [
'renameusererrorinvalid', $newusername->getText() ] );
257 if ( $oldusername->getText() !==
$wgContLang->ucfirst( $oldusername->getText() ) ) {
260 $uid =
$dbr->selectField(
'user',
'user_id',
261 [
'user_name' => $oldusername->getText() ],
263 if ( $uid ===
false ) {
268 $uid = $olduser->idForName();
269 $oldusername = Title::makeTitleSafe( NS_USER, $olduser->getName() );
274 $uid = $olduser->idForName();
278 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
279 [
'renameusererrordoesnotexist', $oldusername->getText() ] );
284 if ( $newuser->idForName() !== 0 ) {
285 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
286 [
'renameusererrorexists', $newusername->getText() ] );
294 [ $uid, $oldusername->getText(), $newusername->getText() ]
301 $oldusername->getText(),
302 $newusername->getText(),
305 [
'reason' => $reason ]
307 if ( !$rename->rename() ) {
313 if ( $user->getId() === $uid ) {
314 $user->setName( $newusername->getText() );
318 if (
$request->getCheck(
'movepages' ) && $user->isAllowed(
'move' ) ) {
321 $pages =
$dbr->select(
323 [
'page_namespace',
'page_title' ],
327 'page_title ' .
$dbr->buildLike( $oldusername->getDBkey() .
'/',
$dbr->anyString() ),
328 'page_title = ' .
$dbr->addQuotes( $oldusername->getDBkey() ),
334 $suppressRedirect =
false;
336 if (
$request->getCheck(
'suppressredirect' ) && $user->isAllowed(
'suppressredirect' ) ) {
337 $suppressRedirect =
true;
342 foreach ( $pages as $row ) {
343 $oldPage = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
344 $newPage = Title::makeTitleSafe( $row->page_namespace,
345 preg_replace(
'!^[^/]+!', $newusername->getDBkey(), $row->page_title ) );
346 # Do not autodelete or anything, title must not exist
347 if ( $newPage->exists() && !$oldPage->isValidMoveTarget( $newPage ) ) {
351 [
'class' =>
'mw-renameuser-pe' ],
352 $this->
msg(
'renameuser-page-exists' )->rawParams(
$link )->escaped()
359 'renameuser-move-log',
360 $oldusername->getText(),
361 $newusername->getText() )->inContentLanguage()->text(),
365 # oldPage is not known in case of redirect suppression
366 $oldLink =
$linkRenderer->makeLink( $oldPage,
null, [], [
'redirect' =>
'no' ] );
368 # newPage is always known because the move was successful
373 [
'class' =>
'mw-renameuser-pm' ],
374 $this->
msg(
'renameuser-page-moved' )->rawParams( $oldLink, $newLink )->escaped()
380 'li', [
'class' =>
'mw-renameuser-pu' ],
381 $this->
msg(
'renameuser-page-unmoved' )->rawParams( $oldLink, $newLink )->escaped()
387 $out->addHTML( Html::rawElement(
'ul', [],
$output ) );
392 $out->wrapWikiMsg(
"<div class=\"successbox\">$1</div><br style=\"clear:both\" />",
393 [
'renameusersuccess', $oldusername->getText(), $newusername->getText() ] );