r36150 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36149‎ | r36150 | r36151 >
Date:14:57, 10 June 2008
Author:tstarling
Status:old
Tags:
Comment:
* Make migrationDryRun() return detailed information about its reasons for failure, instead of just claiming every problem is due to a wrong password. Partially fixes bug 14481 which most likely was due to me not truncating the globalnames table when I truncated the localnames table.
* Do something reasonable when the home wiki has a different password to the current wiki. Instead of saying "wrong password, try again" ad nauseum, don't call initSession() and so let the local password remain in the working set, and then prompt the user for the home wiki password.
* In fact, don't call initSession() even if the password is wrong for the local account. If the user accidentally enters their home wiki password, and then their local password, it's insulting to ask them to enter their home wiki password again. Just save it and save them the effort.
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuth.i18n.php (modified) (history)
  • /trunk/extensions/CentralAuth/CentralAuthUser.php (modified) (history)
  • /trunk/extensions/CentralAuth/SpecialMergeAccount.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralAuth/CentralAuthUser.php
@@ -590,25 +590,25 @@
591591 * @param array &$unattached on success, list of wikis which won't be auto-attached
592592 * @param array &$methods on success, associative array of each wiki's attachment method
593593 * @param array &$blocked true if the home wiki is blocked
594 - * @return bool true if password matched current and home account
 594+ *
 595+ * @return Status object
595596 */
596 - function migrationDryRun( $passwords, &$home, &$attached, &$unattached, &$methods, &$blocked ) {
 597+ function migrationDryRun( $passwords, &$home, &$attached, &$unattached, &$methods ) {
597598 $home = false;
598599 $attached = array();
599600 $unattached = array();
600 - $blocked = false;
601601
602602 // First, make sure we were given the current wiki's password.
603603 $self = $this->localUserData( wfWikiID() );
604604 if( !$this->matchHashes( $passwords, $self['id'], $self['password'] ) ) {
605605 wfDebugLog( 'CentralAuth', "dry run: failed self-password check" );
606 - return false;
 606+ return Status::newFatal( 'wrongpassword' );
607607 }
608608
609609 $migrationSet = $this->queryUnattached();
610610 if( empty( $migrationSet ) ) {
611611 wfDebugLog( 'CentralAuth', 'dry run: no accounts to merge, failed migration' );
612 - return false;
 612+ return Status::newFatal( 'centralauth-merge-no-accounts' );
613613 }
614614 $home = $this->chooseHomeWiki( $migrationSet );
615615 $local = $migrationSet[$home];
@@ -616,8 +616,7 @@
617617 // If home account is blocked...
618618 if( $local['blocked'] ) {
619619 wfDebugLog( 'CentralAuth', "dry run: $home blocked, forbid migration" );
620 - $blocked = true;
621 - return false;
 620+ return Status::newFatal( 'centralauth-blocked-text' );
622621 }
623622
624623 // And we need to match the home wiki before proceeding...
@@ -625,7 +624,7 @@
626625 wfDebugLog( 'CentralAuth', "dry run: passed password match to home $home" );
627626 } else {
628627 wfDebugLog( 'CentralAuth', "dry run: failed password match to home $home" );
629 - return false;
 628+ return Status::newFatal( 'centralauth-merge-home-password' );
630629 }
631630
632631 $this->mHomeWiki = $home;
@@ -642,7 +641,7 @@
643642 sort( $unattached );
644643 ksort( $methods );
645644
646 - return true;
 645+ return Status::newGood();
647646 }
648647
649648 /**
Index: trunk/extensions/CentralAuth/SpecialMergeAccount.php
@@ -176,10 +176,9 @@
177177 $attached = array();
178178 $unattached = array();
179179 $methods = array();
180 - $blocked = false;
181 - $ok = $globalUser->migrationDryRun( $passwords, $home, $attached, $unattached, $methods, $blocked );
 180+ $status = $globalUser->migrationDryRun( $passwords, $home, $attached, $unattached, $methods );
182181
183 - if( $ok ) {
 182+ if( $status->isGood() ) {
184183 // This is the global account or matched it
185184 if( count( $unattached ) == 0 ) {
186185 // Everything matched -- very convenient!
@@ -195,25 +194,24 @@
196195
197196 $subAttached = array_diff( $attached, array( $home ) );
198197 $wgOut->addHtml( $this->step3ActionForm( $home, $subAttached, $methods ) );
 198+ } else {
 199+ // Show error message from status
 200+ $wgOut->addHtml( '<div class="errorbox" style="float:none;">' );
 201+ $wgOut->addWikiText( $status->getWikiText() );
 202+ $wgOut->addHtml( '</div>' );
199203
200 - } elseif( $home ) {
201 - if( $blocked ) {
202 - $wgOut->addWikiText( wfMsg( 'centralauth-blocked-text' ) );
203 - } else {
204 - $wgOut->addWikiText( wfMsg( 'centralauth-merge-dryrun-home' ) );
 204+ // Show wiki list if required
 205+ if ( $status->hasMessage( 'centralauth-blocked-text' )
 206+ || $status->hasMessage( 'centralauth-merge-home-password' ) )
 207+ {
 208+ $out = '<h2>' . wfMsgHtml( 'centralauth-list-home-title' ) . '</h2>';
 209+ $out .= wfMsgExt( 'centralauth-list-home-dryrun', 'parse' );
 210+ $out .= $this->listAttached( array( $home ), array( $home => 'primary' ) );
 211+ $wgOut->addHtml( $out );
205212 }
206 - $out = '<h2>' . wfMsgHtml( 'centralauth-list-home-title' ) . '</h2>';
207 - $out .= wfMsgExt( 'centralauth-list-home-dryrun', 'parse' );
208 - $out .= $this->listAttached( array( $home ), array( $home => 'primary' ) );
209 - $wgOut->addHtml( $out );
210 - } else {
211 - // Didn't get your own password right? Laaaame!
212 - $this->initSession();
213 - $wgOut->addHtml(
214 - '<div class="errorbox">' .
215 - wfMsg( 'wrongpassword' ) .
216 - '</div>' .
217 - $this->step1PasswordForm() );
 213+
 214+ // Show password box
 215+ $wgOut->addHTML( $this->step1PasswordForm() );
218216 }
219217 }
220218
Index: trunk/extensions/CentralAuth/CentralAuth.i18n.php
@@ -51,6 +51,10 @@
5252 'centralauth-merge-step3-title' => 'Create unified account',
5353 'centralauth-merge-step3-detail' => "You are ready to create your unified account, with the following wikis attached:",
5454 'centralauth-merge-step3-submit' => 'Unify accounts',
 55+ 'centralauth-merge-no-accounts' => 'No accounts matching your name were found in the central account
 56+tracking table! The database must be corrupt.',
 57+ 'centralauth-merge-home-password' => 'The home wiki for this account (listed below) has a different
 58+password to the one you entered. Please enter the password for the home wiki.',
5559
5660 // Big text on completion
5761 'centralauth-complete' => 'Login unification complete!',

Status & tagging log