r37422 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37421‎ | r37422 | r37423 >
Date:17:49, 9 July 2008
Author:vasilievvv
Status:old
Tags:
Comment:
* (bug 13507) Account cannot be renamed to a global username
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuth.i18n.php (modified) (history)
  • /trunk/extensions/CentralAuth/CentralAuth.php (modified) (history)
  • /trunk/extensions/CentralAuth/CentralAuthHooks.php (modified) (history)
  • /trunk/extensions/Renameuser/SpecialRenameuser.i18n.php (modified) (history)
  • /trunk/extensions/Renameuser/SpecialRenameuser_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Renameuser/SpecialRenameuser_body.php
@@ -54,6 +54,10 @@
5555 if ( $wgRequest->wasPosted() && ! $wgRequest->getCheck( 'movepages' ) ) {
5656 $is_checked = false;
5757 }
 58+ $warnings = array();
 59+ if( $oun && $nun && !$wgRequest->getCheck( 'confirmaction' ) ) {
 60+ wfRunHooks( 'RenameUserWarning', array( $oun, $nun, &$warnings ) );
 61+ }
5862
5963 $wgOut->addHTML( "
6064 <!-- Current contributions limit is " . RENAMEUSER_CONTRIBLIMIT . " -->" .
@@ -97,16 +101,41 @@
98102 </tr>"
99103 );
100104 }
 105+ if( $warnings ) {
 106+ $warningsHtml = array();
 107+ foreach( $warnings as $warning )
 108+ $warningsHtml[] = is_array( $warning ) ?
 109+ call_user_func_array( 'wfMsgWikiHtml', $warning ) :
 110+ wfMsgHtml( $warning );
 111+ $wgOut->addHTML( "
 112+ <tr>
 113+ <td>".wfMsgWikiHtml( 'renameuserwarnings' ) ."
 114+ </td>
 115+ <td class='mw-input'>" .
 116+ '<ul style="color: red; font-weight: bold"><li>'.implode( '</li><li>', $warningsHtml ).'</li></ul>'.
 117+ "</td>
 118+ </tr>"
 119+ );
 120+ $wgOut->addHTML( "
 121+ <tr>
 122+ <td>&nbsp;
 123+ </td>
 124+ <td class='mw-input'>" .
 125+ Xml::checkLabel( wfMsg( 'renameuserconfirm' ), 'confirmaction', 'confirmaction', false, array( 'tabindex' => '5' ) ) .
 126+ "</td>
 127+ </tr>"
 128+ );
 129+ }
101130
102131 $wgOut->addHTML( "
103132 <tr>
104133 <td>&nbsp;
105134 </td>
106135 <td class='mw-submit'>" .
107 - Xml::submitButton( wfMsg( 'renameusersubmit' ), array( 'name' => 'submit', 'tabindex' => '5', 'id' => 'submit' ) ) .
 136+ Xml::submitButton( wfMsg( 'renameusersubmit' ), array( 'name' => 'submit', 'tabindex' => '6', 'id' => 'submit' ) ) .
108137 ' ' .
109138 Xml::submitButton( wfMsg( 'blocklogpage' ), array ( 'name' => 'submit-showBlockLog',
110 - 'id' => 'submit-showBlockLog', 'tabindex' => '6' ) ) .
 139+ 'id' => 'submit-showBlockLog', 'tabindex' => '7' ) ) .
111140 "</td>
112141 </tr>" .
113142 Xml::closeElement( 'table' ) .
@@ -124,6 +153,9 @@
125154 if( $wgRequest->getText( 'token' ) === '' ) {
126155 # They probably haven't even submitted the form, so don't go further.
127156 return;
 157+ } elseif( $warnings ) {
 158+ # Let user read warnings
 159+ return;
128160 } elseif( !$wgRequest->wasPosted() || !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
129161 $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameuser-error-request' ) . "</div>" );
130162 return;
@@ -372,6 +404,8 @@
373405
374406 wfProfileIn( __METHOD__ );
375407
 408+ wfRunHooks( 'RenameUserPreRename', array( $this->uid, $this->old, $this->new ) );
 409+
376410 $dbw = wfGetDB( DB_MASTER );
377411 // Rename and touch the user before re-attributing edits,
378412 // this avoids users still being logged in and making new edits while
Index: trunk/extensions/Renameuser/SpecialRenameuser.i18n.php
@@ -8,13 +8,15 @@
99 $messages = array();
1010
1111 $messages['en'] = array(
12 - 'renameuser' => 'Rename user',
13 - 'renameuser-desc' => 'Rename a user (need \'\'renameuser\'\' right)',
14 - 'renameuserold' => 'Current username:',
15 - 'renameusernew' => 'New username:',
16 - 'renameuserreason' => 'Reason for rename:',
17 - 'renameusermove' => 'Move user and talk pages (and their subpages) to new name',
18 - 'renameusersubmit' => 'Submit',
 12+ 'renameuser' => 'Rename user',
 13+ 'renameuser-desc' => 'Rename a user (need \'\'renameuser\'\' right)',
 14+ 'renameuserold' => 'Current username:',
 15+ 'renameusernew' => 'New username:',
 16+ 'renameuserreason' => 'Reason for rename:',
 17+ 'renameusermove' => 'Move user and talk pages (and their subpages) to new name',
 18+ 'renameuserwarnings' => 'Warnings:',
 19+ 'renameuserconfirm' => 'Yes, rename the user',
 20+ 'renameusersubmit' => 'Submit',
1921
2022 'renameusererrordoesnotexist' => 'The user "<nowiki>$1</nowiki>" does not exist.',
2123 'renameusererrorexists' => 'The user "<nowiki>$1</nowiki>" already exists.',
Index: trunk/extensions/CentralAuth/CentralAuth.php
@@ -166,7 +166,8 @@
167167 $wgHooks['getUserPermissionsErrorsExpensive'][] = 'CentralAuthHooks::onGetUserPermissionsErrorsExpensive';
168168
169169 // For interaction with the Special:Renameuser extension
170 -$wgHooks['RenameUserAbort'][] = 'CentralAuthHooks::onRenameUserAbort';
 170+$wgHooks['RenameUserWarning'][] = 'CentralAuthHooks::onRenameUserWarning';
 171+$wgHooks['RenameUserPreRename'][] = 'CentralAuthHooks::onRenameUserPreRename';
171172 $wgHooks['RenameUserComplete'][] = 'CentralAuthHooks::onRenameUserComplete';
172173
173174 $wgAvailableRights[] = 'centralauth-admin';
Index: trunk/extensions/CentralAuth/CentralAuthHooks.php
@@ -278,27 +278,31 @@
279279 /**
280280 * Don't allow an attached local account to be renamed with the old system.
281281 */
282 - static function onRenameUserAbort( $userId, $oldName, $newName ) {
 282+ static function onRenameUserWarning( $oldName, $newName, &$warnings ) {
283283 $oldCentral = new CentralAuthUser( $oldName );
284284 if ( $oldCentral->exists() && $oldCentral->isAttached() ) {
285285 global $wgOut;
286286 wfLoadExtensionMessages('SpecialCentralAuth');
287 - $wgOut->addWikiMsg( 'centralauth-renameuser-abort', $oldName, $newName );
 287+ $warnings[] = array( 'centralauth-renameuser-abort', $oldName, $newName );
288288 return false;
289289 }
290290 $newCentral = new CentralAuthUser( $newName );
291 - if ( $newCentral->exists() ) {
 291+ if ( $newCentral->exists() && !$newCentral->isAttached() ) {
292292 global $wgOut;
293293 wfLoadExtensionMessages('SpecialCentralAuth');
294 - $wgOut->addWikiMsg( 'centralauth-renameuser-exists', $oldName, $newName );
295 - return false;
 294+ $warnings[] = array( 'centralauth-renameuser-exists', $oldName, $newName );
296295 }
 296+ return true;
 297+ }
297298
298 - // If no central record is present or this local account isn't attached,
299 - // do as thou wilt.
 299+ static function onRenameUserPreRename( $uid, $oldName, $newName ) {
 300+ $oldCentral = new CentralAuthUser( $oldName );
 301+ if( $oldCentral->exists() && $oldCentral->isAttached() ) {
 302+ $oldCentral->adminUnattach( array( wfWikiID() ) );
 303+ }
300304 return true;
301305 }
302 -
 306+
303307 /**
304308 * When renaming an account, ensure that the presence records are updated.
305309 */
Index: trunk/extensions/CentralAuth/CentralAuth.i18n.php
@@ -209,8 +209,8 @@
210210 'centralauth-prefs-manage' => 'Manage your global account',
211211
212212 // Interaction with Special:Renameuser
213 - 'centralauth-renameuser-abort' => "<div class=\"errorbox\">Cannot rename user $1 locally as this username has been migrated to the unified login system.</div>",
214 - 'centralauth-renameuser-exists' => "<div class=\"errorbox\">Cannot rename user $2 as this username is reserved for a global account.</div>",
 213+ 'centralauth-renameuser-abort' => "User $1 has been migrated to the unified login system. Renaming it will cause local user detached from the global one.",
 214+ 'centralauth-renameuser-exists' => "User $2 is reserved for a global account.",
215215
216216 // Other messages
217217 'centralauth-invalid-wiki' => 'No such wiki database: $1',

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r35997* (bug 13507) Account cannot be renamed to a global username...vasilievvv17:42, 7 June 2008

Status & tagging log