11 parent::__construct(
'Renameuser',
'renameuser' );
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] ) ) );
57 $newnamePar = $usernames[1] ??
null;
58 $newnamePar = trim( str_replace(
'_',
' ', $request->getText(
'newusername', $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 ] );
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'>" .
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',
204 Html::hidden(
'token', $token ) .
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' );
246 if ( !is_object( $olduser ) ) {
247 $out->wrapWikiMsg(
"<div class=\"errorbox\">$1</div>",
248 [
'renameusererrorinvalid', $oldusername->getText() ] );
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();
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 ) {
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() ) {
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
378 [
'class' =>
'mw-renameuser-pm' ],
379 $this->
msg(
'renameuser-page-moved' )->rawParams( $oldLink, $newLink )->escaped()
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() ] );
407 # Show relevant lines from the logs:
409 $out->addHTML(
Xml::element(
'h2',
null, $logPage->getName()->text() ) .
"\n" );