30 $out->addWikiMsg(
'renameuser-summary' );
33 if ( !$user->isAllowed(
'renameuser' ) ) {
41 if ( $user->isBlocked() ) {
48 $showBlockLog =
$request->getBool(
'submit-showBlockLog' );
49 $usernames = explode(
'/', $par, 2 );
50 $oldnamePar = trim( str_replace(
'_',
' ',
$request->getText(
'oldusername', $usernames[0] ) ) );
51 $oldusername = Title::makeTitle( NS_USER, $oldnamePar );
52 $newnamePar = isset( $usernames[1] ) ? $usernames[1] :
null;
53 $newnamePar = trim( str_replace(
'_',
' ',
$request->getText(
'newusername', $newnamePar ) ) );
56 $newusername = Title::makeTitleSafe( NS_USER,
$wgContLang->ucfirst( $newnamePar ) );
57 $oun = is_object( $oldusername ) ? $oldusername->getText() :
'';
58 $nun = is_object( $newusername ) ? $newusername->getText() :
'';
59 $token = $user->getEditToken();
60 $reason =
$request->getText(
'reason' );
63 $suppress_checked =
$request->getCheck(
'suppressredirect' );
66 if ( $oun && $nun && !
$request->getCheck(
'confirmaction' ) ) {
67 Hooks::run(
'RenameUserWarning', [ $oun, $nun, &$warnings ] );
71 Xml::openElement(
'form', [
76 Xml::openElement(
'fieldset' ) .
77 Xml::element(
'legend',
null, $this->
msg(
'renameuser' )->
text() ) .
78 Xml::openElement(
'table', [
'id' =>
'mw-renameuser-table' ] ) .
80 <td class='mw-label'>" .
81 Xml::label( $this->
msg(
'renameuserold' )->
text(),
'oldusername' ) .
83 <td class='mw-input'>" .
84 Xml::input(
'oldusername', 20, $oun, [
'type' =>
'text',
'tabindex' =>
'1' ] ) .
' ' .
88 <td class='mw-label'>" .
89 Xml::label( $this->
msg(
'renameusernew' )->
text(),
'newusername' ) .
91 <td class='mw-input'>" .
92 Xml::input(
'newusername', 20, $nun, [
'type' =>
'text',
'tabindex' =>
'2' ] ) .
96 <td class='mw-label'>" .
97 Xml::label( $this->
msg(
'renameuserreason' )->
text(),
'reason' ) .
99 <td class='mw-input'>" .
104 [
'type' =>
'text',
'tabindex' =>
'3',
'maxlength' => 255 ]
109 if ( $user->isAllowed(
'move' ) ) {
114 <td class='mw-input'>" .
115 Xml::checkLabel( $this->
msg(
'renameusermove' )->
text(),
'movepages',
'movepages',
116 $move_checked, [
'tabindex' =>
'4' ] ) .
121 if ( $user->isAllowed(
'suppressredirect' ) ) {
126 <td class='mw-input'>" .
128 $this->
msg(
'renameusersuppress' )->
text(),
132 [
'tabindex' =>
'5' ]
141 foreach ( $warnings as $warning ) {
142 $warningsHtml[] = is_array( $warning ) ?
143 $this->
msg( $warning[0] )->rawParams( array_slice( $warning, 1 ) )->escaped() :
144 $this->
msg( $warning )->escaped();
149 <td class='mw-label'>" . $this->
msg(
'renameuserwarnings' )->escaped() .
"
151 <td class='mw-input'>" .
152 '<ul class="error"><li>' .
153 implode(
'</li><li>', $warningsHtml ) .
'</li></ul>' .
161 <td class='mw-input'>" .
163 $this->
msg(
'renameuserconfirm' )->
text(),
167 [
'tabindex' =>
'6' ]
177 <td class='mw-submit'>" .
179 $this->
msg(
'renameusersubmit' )->
text(),
188 $this->
msg(
'renameuser-submit-blocklog' )->
text(),
190 'name' =>
'submit-showBlockLog',
191 'id' =>
'submit-showBlockLog',
197 Xml::closeElement(
'table' ) .
198 Xml::closeElement(
'fieldset' ) .
199 Html::hidden(
'token', $token ) .
200 Xml::closeElement(
'form' ) .
"\n"
204 if ( $showBlockLog && is_object( $oldusername ) ) {
210 if (
$request->getText(
'token' ) ===
'' ) {
211 # They probably haven't even submitted the form, so don't go further.
213 } elseif ( $warnings ) {
214 # Let user read warnings
216 } elseif ( !
$request->wasPosted() || !$user->matchEditToken(
$request->getVal(
'token' ) ) ) {
217 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
'renameuser-error-request' );
220 } elseif ( !is_object( $oldusername ) ) {
221 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
222 [
'renameusererrorinvalid',
$request->getText(
'oldusername' ) ] );
225 } elseif ( !is_object( $newusername ) ) {
226 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
227 [
'renameusererrorinvalid',
$request->getText(
'newusername' ) ] );
230 } elseif ( $oldusername->getText() === $newusername->getText() ) {
231 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
'renameuser-error-same-user' );
237 $olduser = User::newFromName( $oldusername->getText(),
false );
238 $newuser = User::newFromName( $newusername->getText(),
'creatable' );
241 if ( !is_object( $olduser ) ) {
242 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
243 [
'renameusererrorinvalid', $oldusername->getText() ] );
247 if ( !is_object( $newuser ) || !User::isCreatableName( $newuser->getName() ) ) {
248 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
249 [
'renameusererrorinvalid', $newusername->getText() ] );
256 if ( $oldusername->getText() !==
$wgContLang->ucfirst( $oldusername->getText() ) ) {
259 $uid =
$dbr->selectField(
'user',
'user_id',
260 [
'user_name' => $oldusername->getText() ],
262 if ( $uid ===
false ) {
267 $uid = $olduser->idForName();
268 $oldusername = Title::makeTitleSafe( NS_USER, $olduser->getName() );
273 $uid = $olduser->idForName();
277 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
278 [
'renameusererrordoesnotexist', $oldusername->getText() ] );
283 if ( $newuser->idForName() !== 0 ) {
284 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
285 [
'renameusererrorexists', $newusername->getText() ] );
293 [ $uid, $oldusername->getText(), $newusername->getText() ]
300 $oldusername->getText(),
301 $newusername->getText(),
304 [
'reason' => $reason ]
306 if ( !$rename->rename() ) {
312 if ( $user->getId() === $uid ) {
313 $user->setName( $newusername->getText() );
317 if (
$request->getCheck(
'movepages' ) && $user->isAllowed(
'move' ) ) {
320 $pages =
$dbr->select(
322 [
'page_namespace',
'page_title' ],
324 'page_namespace IN (' . NS_USER .
',' .
NS_USER_TALK .
')',
325 '(page_title ' .
$dbr->buildLike( $oldusername->getDBkey() .
'/',
$dbr->anyString() ) .
326 ' OR page_title = ' .
$dbr->addQuotes( $oldusername->getDBkey() ) .
')'
331 $suppressRedirect =
false;
333 if (
$request->getCheck(
'suppressredirect' ) && $user->isAllowed(
'suppressredirect' ) ) {
334 $suppressRedirect =
true;
338 foreach ( $pages as $row ) {
339 $oldPage = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
340 $newPage = Title::makeTitleSafe( $row->page_namespace,
341 preg_replace(
'!^[^/]+!', $newusername->getDBkey(), $row->page_title ) );
342 # Do not autodelete or anything, title must not exist
343 if ( $newPage->exists() && !$oldPage->isValidMoveTarget( $newPage ) ) {
347 [
'class' =>
'mw-renameuser-pe' ],
348 $this->
msg(
'renameuser-page-exists' )->rawParams(
$link )->escaped()
355 'renameuser-move-log',
356 $oldusername->getText(),
357 $newusername->getText() )->inContentLanguage()->text(),
361 # oldPage is not known in case of redirect suppression
362 $oldLink =
Linker::link( $oldPage,
null, [], [
'redirect' =>
'no' ] );
364 # newPage is always known because the move was successful
369 [
'class' =>
'mw-renameuser-pm' ],
370 $this->
msg(
'renameuser-page-moved' )->rawParams( $oldLink, $newLink )->escaped()
376 'li', [
'class' =>
'mw-renameuser-pu' ],
377 $this->
msg(
'renameuser-page-unmoved' )->rawParams( $oldLink, $newLink )->escaped()
383 $out->addHTML( Html::rawElement(
'ul', [],
$output ) );
388 $out->wrapWikiMsg(
"<div class=\"successbox\">$1</div><br style=\"clear:both\" />",
389 [
'renameusersuccess', $oldusername->getText(), $newusername->getText() ] );