r24587 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24586‎ | r24587 | r24588 >
Date:15:43, 4 August 2007
Author:brion
Status:old
Tags:
Comment:
Some interaction between Special:Renameuser and the CentralAuth system:
* Prevent renames of attached local accounts
* Update migration records when renaming an unattached account
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuth.i18n.php (modified) (history)
  • /trunk/extensions/CentralAuth/CentralAuth.php (modified) (history)
  • /trunk/extensions/Renameuser/SpecialRenameuser_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Renameuser/SpecialRenameuser_body.php
@@ -175,6 +175,11 @@
176176 return;
177177 }
178178 }
 179+
 180+ // Give other affected extensions a chance to validate or abort
 181+ if( !wfRunHooks( 'RenameUserAbort', array( $uid, $oldusername->getText(), $newusername->getText() ) ) ) {
 182+ return;
 183+ }
179184
180185 $rename = new RenameuserSQL( $oldusername->getText(), $newusername->getText(), $uid );
181186 $rename->rename();
@@ -384,6 +389,7 @@
385390 $user = User::newFromId( $this->uid );
386391 $user->invalidateCache();
387392 $wgAuth->updateExternalDB( $user );
 393+ wfRunHooks( 'RenameUserComplete', array( $this->uid, $this->old, $this->new ) );
388394
389395 wfProfileOut( __METHOD__ );
390396 }
Index: trunk/extensions/CentralAuth/CentralAuth.php
@@ -44,6 +44,10 @@
4545 $wgHooks['AddNewAccount'][] = 'wfCentralAuthAddNewAccount';
4646 $wgHooks['PreferencesUserInformationPanel'][] = 'wfCentralAuthInformationPanel';
4747
 48+// For interaction with the Special:Renameuser extension
 49+$wgHooks['RenameUserAbort'][] = 'wfCentralAuthRenameUserAbort';
 50+$wgHooks['RenameUserComplete'][] = 'wfCentralAuthRenameUserComplete';
 51+
4852 $wgGroupPermissions['steward']['centralauth-admin'] = true;
4953
5054 $wgSpecialPages['CentralAuth'] = 'SpecialCentralAuth';
@@ -125,3 +129,32 @@
126130 $central->addLocalName( $wgDBname );
127131 return true;
128132 }
 133+
 134+/**
 135+ * Don't allow an attached local account to be renamed with the old system.
 136+ */
 137+function wfCentralAuthRenameUserAbort( $userId, $oldName, $newName ) {
 138+ $central = new CentralAuthUser( $oldName );
 139+ if( $central->exists() && $central->isAttached() ) {
 140+ global $wgOut;
 141+ $wgOut->addWikiText( wfMsg( 'centralauth-renameuser-abort', $oldName ) );
 142+ return false;
 143+ }
 144+
 145+ // If no central record is present or this local account isn't attached,
 146+ // do as thou wilt.
 147+ return true;
 148+}
 149+
 150+/**
 151+ * When renaming an account, ensure that the presence records are updated.
 152+ */
 153+function wfCentralAuthRenameUserComplete( $userId, $oldName, $newName ) {
 154+ global $wgDBname;
 155+
 156+ $oldCentral = new CentralAuthUser( $oldName );
 157+ $oldCentral->removeLocalName( $wgDBname );
 158+
 159+ $newCentral = new CentralAuthUser( $newName );
 160+ $newCentral->addLocalName( $wgDBname );
 161+}
Index: trunk/extensions/CentralAuth/CentralAuth.i18n.php
@@ -186,6 +186,12 @@
187187 'centralauth-prefs-manage' =>
188188 'Manage your global account',
189189
 190+ // Interaction with Special:Renameuser
 191+ 'centralauth-renameuser-abort' =>
 192+ "<div class=\"errorbox\">" .
 193+ "Cannot rename user $1 locally as this username has been migrated to the " .
 194+ "unified login system.</div>",
 195+
190196 );
191197
192198 /* Arabic (Meno25) */

Status & tagging log