r60735 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60734‎ | r60735 | r60736 >
Date:16:00, 6 January 2010
Author:ialex
Status:deferred (Comments)
Tags:
Comment:
* (bug 17654) Automatic creation of the user on OpenID login is now optional
* (bug 17660) Overriding personal settings from OpenID is now more granular
Modified paths:
  • /trunk/extensions/OpenID/OpenID.i18n.php (modified) (history)
  • /trunk/extensions/OpenID/SpecialOpenIDLogin.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenID/OpenID.i18n.php
@@ -63,15 +63,16 @@
6464 'openidemail' => 'E-mail address',
6565 'openidlanguage' => 'Language',
6666 'openidtimezone' => 'Time zone',
67 - 'openidnotavailable' => 'Your preferred nickname ($1) is already in use by another user.',
68 - 'openidnotprovided' => 'Your OpenID server did not provide a nickname (either because it cannot, or because you told it not to).',
 67+ 'openidchooselegend' => 'Username choice',
6968 'openidchooseinstructions' => 'All users need a nickname;
7069 you can choose one from the options below.',
 70+ 'openidchoosenick' => 'Your nickname ($1)',
7171 'openidchoosefull' => 'Your full name ($1)',
7272 'openidchooseurl' => 'A name picked from your OpenID ($1)',
7373 'openidchooseauto' => 'An auto-generated name ($1)',
7474 'openidchoosemanual' => 'A name of your choice:',
75 - 'openidchooseexisting' => 'An existing account on this wiki:',
 75+ 'openidchooseexisting' => 'An existing account on this wiki',
 76+ 'openidchooseusername' => 'username:',
7677 'openidchoosepassword' => 'password:',
7778 'openidconvertinstructions' => 'This form lets you change your user account to use an OpenID URL or add more OpenID URLs',
7879 'openidconvertoraddmoreids' => 'Convert to OpenID or add another OpenID URL',
@@ -96,7 +97,7 @@
9798 To use OpenID in the future, you can [[Special:OpenIDConvert|convert your account to OpenID]] after you have logged in normally.
9899
99100 There are many [http://openid.net/get/ OpenID providers], and you may already have an OpenID-enabled account on another service.',
100 - 'openidupdateuserinfo' => 'Update my personal information',
 101+ 'openidupdateuserinfo' => 'Update my personal information:',
101102
102103 'openiddelete' => 'Delete OpenID',
103104 'openiddelete-text' => 'By clicking the "{{int:openiddelete-button}}" button, you will remove the OpenID $1 from your account.
Index: trunk/extensions/OpenID/SpecialOpenIDLogin.body.php
@@ -172,16 +172,14 @@
173173
174174 if ( $messagekey ) {
175175 $wgOut->addWikiMsg( $messagekey );
176 - } else if ( array_key_exists( 'nickname', $sreg ) ) {
177 - $wgOut->addWikiMsg( 'openidnotavailable', $sreg['nickname'] );
178 - } else {
179 - $wgOut->addWikiMsg( 'openidnotprovided' );
180176 }
181177 $wgOut->addWikiMsg( 'openidchooseinstructions' );
182178
183179 $wgOut->addHTML(
184180 Xml::openElement( 'form',
185 - array( 'action' => $this->getTitle( 'ChooseName' )->getLocalUrl(), 'method' => 'POST' ) ) . "\n"
 181+ array( 'action' => $this->getTitle( 'ChooseName' )->getLocalUrl(), 'method' => 'POST' ) ) . "\n" .
 182+ Xml::fieldset( wfMsg( 'openidchooselegend' ), false, array( 'id' => 'mw-openid-choosename' ) ) . "\n" .
 183+ Xml::openElement( 'table' )
186184 );
187185 $def = false;
188186
@@ -206,37 +204,67 @@
207205 }
208206
209207 if ( array_key_exists( $oidAttr, $sreg ) ) {
210 - $oidAttributes[] = Xml::tags( 'div', array(), wfMsgHtml( "openid$oidAttr" ) . ': ' . Xml::tags( 'i', array(), $sreg[$oidAttr] ) );
 208+ $checkName = 'wpUpdateUserInfo' . $oidAttr;
 209+ $oidAttributes[] = Xml::tags( 'li', array(),
 210+ Xml::check( $checkName, false, array( 'id' => $checkName ) ) .
 211+ Xml::tags( 'label', array( 'for' => $checkName ),
 212+ wfMsgHtml( "openid$oidAttr" ) . wfMsgExt( 'colon-separator', array( 'escapenoentities' ) ) .
 213+ Xml::tags( 'i', array(), $sreg[$oidAttr] )
 214+ )
 215+ );
211216 }
212217 }
213218
214219 $oidAttributesUpdate = '';
215220 if ( count( $oidAttributes ) > 0 ) {
216 - $oidAttributesUpdate = Xml::openElement( 'div', array( 'style' => 'margin-left: 25px' ) ) . "\n" .
217 - Xml::check( 'wpUpdateUserInfo', false, array( 'id' => 'wpUpdateUserInfo' ) ) . "\n" .
218 - Xml::openElement( 'label', array( 'for' => 'wpUpdateUserInfo' ) ) .
219 - wfMsgHtml( 'openidupdateuserinfo' ) .
220 - Xml::tags( 'div', array( 'style' => 'margin-left: 25px' ), implode( "\n", $oidAttributes ) ) .
221 - Xml::closeElement( 'label' ) . Xml::closeElement( 'div' );
 221+ $oidAttributesUpdate = "<br />\n" .
 222+ wfMsgHtml( 'openidupdateuserinfo' ) . "\n" .
 223+ Xml::tags( 'ul', array(), implode( "\n", $oidAttributes ) );
222224 }
223225
224226 $wgOut->addHTML(
225 - Xml::openElement( 'div' ) .
226 - Xml::radioLabel( wfMsg( 'openidchooseexisting' ), 'wpNameChoice', 'existing', 'wpNameChoiceExisting' ) . "\n" .
227 - Xml::input( 'wpExistingName', 16, $name, array( 'id' => 'wpExistingName' ) ) . "\n" .
228 - wfMsgHtml( 'openidchoosepassword' ) . "\n" .
229 - Xml::password( 'wpExistingPassword' ) . "\n" .
230 - $oidAttributesUpdate . "\n" .
231 - Xml::closeElement( 'div' )
 227+ Xml::openElement( 'tr' ) .
 228+ Xml::tags( 'td', array( 'class' => 'mw-label' ),
 229+ Xml::radio( 'wpNameChoice', 'existing', false, array( 'id' => 'wpNameChoiceExisting' ) )
 230+ ) . "\n" .
 231+ Xml::tags( 'td', array( 'class' => 'mw-input' ),
 232+ Xml::label( wfMsg( 'openidchooseexisting' ), 'wpNameChoiceExisting' ) . "<br />\n" .
 233+ wfMsgHtml( 'openidchooseusername' ) . "\n" .
 234+ Xml::input( 'wpExistingName', 16, $name, array( 'id' => 'wpExistingName' ) ) . "\n" .
 235+ wfMsgHtml( 'openidchoosepassword' ) . "\n" .
 236+ Xml::password( 'wpExistingPassword' ) . "\n" .
 237+ $oidAttributesUpdate . "\n"
 238+ ) . "\n" .
 239+ Xml::closeElement( 'tr' ) . "\n"
232240 );
233241 }
234242
235243 # These options won't exist if we can't get them.
 244+ if ( array_key_exists( 'nickname', $sreg ) && $this->userNameOK( $sreg['nickname'] ) ) {
 245+ $wgOut->addHTML(
 246+ Xml::openElement( 'tr' ) .
 247+ Xml::tags( 'td', array( 'class' => 'mw-label' ),
 248+ Xml::radio( 'wpNameChoice', 'nick', !$def, array( 'id' => 'wpNameChoiceNick' ) )
 249+ ) .
 250+ Xml::tags( 'td', array( 'class' => 'mw-input' ),
 251+ Xml::label( wfMsg( 'openidchoosenick', $sreg['nickname'] ), 'wpNameChoiceNick' )
 252+ ) .
 253+ Xml::closeElement( 'tr' ) . "\n"
 254+ );
 255+ $def = true;
 256+ }
 257+
 258+ # These options won't exist if we can't get them.
236259 if ( array_key_exists( 'fullname', $sreg ) && $this->userNameOK( $sreg['fullname'] ) ) {
237260 $wgOut->addHTML(
238 - Xml::openElement( 'div' ) .
239 - Xml::radioLabel( wfMsg( 'openidchoosefull', $sreg['fullname'] ), 'wpNameChoice', 'full', 'wpNameChoiceFull', !$def ) .
240 - Xml::closeElement( 'div' )
 261+ Xml::openElement( 'tr' ) .
 262+ Xml::tags( 'td', array( 'class' => 'mw-label' ),
 263+ Xml::radio( 'wpNameChoice', 'full', !$def, array( 'id' => 'wpNameChoiceFull' ) )
 264+ ) .
 265+ Xml::tags( 'td', array( 'class' => 'mw-input' ),
 266+ Xml::label( wfMsg( 'openidchoosefull', $sreg['fullname'] ), 'wpNameChoiceFull' )
 267+ ) .
 268+ Xml::closeElement( 'tr' ) . "\n"
241269 );
242270 $def = true;
243271 }
@@ -244,23 +272,49 @@
245273 $idname = $this->toUserName( $openid );
246274 if ( $idname && $this->userNameOK( $idname ) ) {
247275 $wgOut->addHTML(
248 - Xml::openElement( 'div' ) .
249 - Xml::radioLabel( wfMsg( 'openidchooseurl', $idname ), 'wpNameChoice', 'url', 'wpNameChoiceUrl', !$def ) .
250 - Xml::closeElement( 'div' )
 276+ Xml::openElement( 'tr' ) .
 277+ Xml::tags( 'td', array( 'class' => 'mw-label' ),
 278+ Xml::radio( 'wpNameChoice', 'url', !$def, array( 'id' => 'wpNameChoiceUrl' ) )
 279+ ) .
 280+ Xml::tags( 'td', array( 'class' => 'mw-input' ),
 281+ Xml::label( wfMsg( 'openidchooseurl', $idname ), 'wpNameChoiceUrl' )
 282+ ) .
 283+ Xml::closeElement( 'tr' ) . "\n"
251284 );
252285 $def = true;
253286 }
254287
255288 # These are always available
256289 $wgOut->addHTML(
257 - Xml::openElement( 'div' ) . "\n" .
258 - Xml::radioLabel( wfMsg( 'openidchooseauto', $this->automaticName( $sreg ) ), 'wpNameChoice', 'auto', 'wpNameChoiceAuto', !$def ) . "\n" .
259 - Xml::closeElement( 'div' ) . "\n" .
260 - Xml::openElement( 'div' ) . "\n" .
261 - Xml::radioLabel( wfMsg( 'openidchoosemanual' ), 'wpNameChoice', 'manual', 'wpNameChoiceManual' ) . "\n" .
262 - Xml::input( 'wpNameValue', 16, false, array( 'id' => 'wpNameValue' ) ) . "\n" .
263 - Xml::closeElement( 'div' ) . "\n" .
264 - Xml::submitButton( wfMsg( 'login' ), array( 'name' => 'wpOK' ) ) . Xml::submitButton( wfMsg( 'cancel' ), array( 'name' => 'wpCancel' ) ) . "\n" .
 290+ Xml::openElement( 'tr' ) .
 291+ Xml::tags( 'td', array( 'class' => 'mw-label' ),
 292+ Xml::radio( 'wpNameChoice', 'auto', !$def, array( 'id' => 'wpNameChoiceAuto' ) )
 293+ ) .
 294+ Xml::tags( 'td', array( 'class' => 'mw-input' ),
 295+ Xml::label( wfMsg( 'openidchooseauto', $this->automaticName( $sreg ) ), 'wpNameChoiceAuto' )
 296+ ) .
 297+ Xml::closeElement( 'tr' ) . "\n" .
 298+
 299+ Xml::openElement( 'tr' ) .
 300+ Xml::tags( 'td', array( 'class' => 'mw-label' ),
 301+ Xml::radio( 'wpNameChoice', 'manual', !$def, array( 'id' => 'wpNameChoiceManual' ) )
 302+ ) .
 303+ Xml::tags( 'td', array( 'class' => 'mw-input' ),
 304+ Xml::label( wfMsg( 'openidchoosemanual' ), 'wpNameChoiceManual' ) . '&nbsp;' .
 305+ Xml::input( 'wpNameValue', 16, false, array( 'id' => 'wpNameValue' ) )
 306+ ) .
 307+ Xml::closeElement( 'tr' ) . "\n" .
 308+
 309+ Xml::openElement( 'tr' ) . "\n" .
 310+ Xml::element( 'td', array(), '' ) . "\n" .
 311+ Xml::tags( 'td', array( 'class' => 'mw-submit' ),
 312+ Xml::submitButton( wfMsg( 'login' ), array( 'name' => 'wpOK' ) ) .
 313+ Xml::submitButton( wfMsg( 'cancel' ), array( 'name' => 'wpCancel' ) )
 314+ ) . "\n" .
 315+ Xml::closeElement( 'tr' ) . "\n" .
 316+
 317+ Xml::closeElement( 'table' ) .
 318+ Xml::closeElement( 'fieldset' ) .
265319 Xml::closeElement( 'form' )
266320 );
267321 }
@@ -300,9 +354,12 @@
301355 return;
302356 }
303357
304 - if ( $wgRequest->getText( 'wpUpdateUserInfo' ) ) {
305 - $this->updateUser( $user, $sreg );
 358+ $force = array();
 359+ foreach( array( 'fullname', 'nickname', 'email', 'language' ) as $option ) {
 360+ if ( $wgRequest->getCheck( 'wpUpdateUserInfo' . $option ) )
 361+ $force[] = $option;
306362 }
 363+ $this->updateUser( $user, $sreg );
307364 } else {
308365 $name = $this->getUserName( $openid, $sreg, $choice, $nameValue );
309366
@@ -376,25 +433,12 @@
377434
378435 if ( $user instanceof User ) {
379436 $this->updateUser( $user, $sreg ); # update from server
380 - } else {
381 - # For easy names
382 - $name = $this->createName( $openid, $sreg );
383 - if ( $name ) {
384 - $user = $this->createUser( $openid, $sreg, $name );
385 - } else {
386 - # For hard names
387 - $this->saveValues( $openid, $sreg );
388 - $this->chooseNameForm( $openid, $sreg );
389 - return;
390 - }
391 - }
392 -
393 - if ( !$user instanceof User ) {
394 - wfDebug( "OpenID: aborting in auth success because we could not create user object\n" );
395 - $wgOut->showErrorPage( 'openiderror', 'openiderrortext' );
396 - } else {
397437 $wgUser = $user;
398438 $this->displaySuccessLogin( $openid );
 439+ } else {
 440+ $this->saveValues( $openid, $sreg );
 441+ $this->chooseNameForm( $openid, $sreg );
 442+ return;
399443 }
400444 }
401445 }
@@ -409,18 +453,15 @@
410454 function updateUser( $user, $sreg, $force = false ) {
411455 global $wgAllowRealName, $wgEmailAuthentication;
412456
413 - // Back compat with old option
414 - $updateAll = $force || $user->getOption( 'openid-update-userinfo-on-login' );
415 -
416457 // Nick name
417 - if ( $updateAll || $user->getOption( 'openid-update-userinfo-on-login-nickname' ) ) {
 458+ if ( $this->updateOption( 'nickname', $user, $force ) ) {
418459 // FIXME: only update if there's been a change
419460 if ( array_key_exists( 'nickname', $sreg ) )
420461 $user->setOption( 'nickname', $sreg['nickname'] );
421462 }
422463
423464 // E-mail
424 - if ( $updateAll || $user->getOption( 'openid-update-userinfo-on-login-email' ) ) {
 465+ if ( $this->updateOption( 'email', $user, $force ) ) {
425466 if ( array_key_exists( 'email', $sreg ) ) {
426467 $email = $sreg['email'];
427468 // If email changed, then email a confirmation mail
@@ -438,20 +479,20 @@
439480 }
440481
441482 // Full name
442 - if ( $wgAllowRealName && ( $updateAll || $user->getOption( 'openid-update-userinfo-on-login-fullname' ) ) ) {
 483+ if ( $wgAllowRealName && ( $this->updateOption( 'fullname', $user, $force ) ) ) {
443484 if ( array_key_exists( 'fullname', $sreg ) )
444485 $user->setRealName( $sreg['fullname'] );
445486 }
446487
447488 // Language
448 - if ( $updateAll || $user->getOption( 'openid-update-userinfo-on-login-language' ) ) {
 489+ if ( $this->updateOption( 'language', $user, $force ) ) {
449490 if ( array_key_exists( 'language', $sreg ) ) {
450491 # FIXME: check and make sure the language exists
451492 $user->setOption( 'language', $sreg['language'] );
452493 }
453494 }
454495
455 - if ( $updateAll || $user->getOption( 'openid-update-userinfo-on-login-timezone' ) ) {
 496+ if ( $this->updateOption( 'timezone', $user, $force ) ) {
456497 if ( array_key_exists( 'timezone', $sreg ) ) {
457498 # FIXME: do something with it.
458499 # $offset = OpenIDTimezoneToTzoffset($sreg['timezone']);
@@ -463,6 +504,15 @@
464505 }
465506
466507 /**
 508+ * Helper function for updateUser()
 509+ */
 510+ private function updateOption( $option, User $user, $force ) {
 511+ return $force === true || ( is_array( $force ) && in_array( $option, $force ) ) ||
 512+ $user->getOption( 'openid-update-userinfo-on-login-' . $option ) ||
 513+ $user->getOption( 'openid-update-userinfo-on-login' ); // Back compat with old option
 514+ }
 515+
 516+ /**
467517 * Display the final "Successful login"
468518 *
469519 * @param $openid String: OpenID url
@@ -539,19 +589,11 @@
540590 # Methods to get the user name
541591 # ----------------------------
542592
543 - function createName( $openid, $sreg ) {
544 - # try nickname
545 - if ( array_key_exists( 'nickname', $sreg ) &&
546 - $this->userNameOK( $sreg['nickname'] ) ) {
547 - return $sreg['nickname'];
548 - } else {
549 - return null;
550 - }
551 - }
552 -
553 -
554593 function getUserName( $openid, $sreg, $choice, $nameValue ) {
555594 switch ( $choice ) {
 595+ case 'nick':
 596+ return ( ( array_key_exists( 'nickname', $sreg ) ) ? $sreg['nickname'] : null );
 597+ break;
556598 case 'full':
557599 return ( ( array_key_exists( 'fullname', $sreg ) ) ? $sreg['fullname'] : null );
558600 break;
@@ -690,7 +732,9 @@
691733 }
692734
693735 function fetchValues() {
694 - return array( $_SESSION['openid_consumer_response'], $_SESSION['openid_consumer_sreg'] );
 736+ $response = isset( $_SESSION['openid_consumer_response'] ) ? $_SESSION['openid_consumer_response'] : null;
 737+ $sreg = isset( $_SESSION['openid_consumer_sreg'] ) ? $_SESSION['openid_consumer_sreg'] : null;
 738+ return array( $response, $sreg );
695739 }
696740
697741 function returnTo() {

Follow-up revisions

RevisionCommit summaryAuthorDate
r60798Per Raymond's comment on r60735: capitalise "Username" and "Password"ialex18:55, 7 January 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r52236Big changes to OpenID extension:...ialex12:41, 21 June 2009

Comments

#Comment by Raymond (talk | contribs)   17:06, 6 January 2010

I wonder if lowercase

'openidchooseusername' => 'username:',
'openidchoosepassword' => 'password:',

are correct. Or should the words be capitalized?

#Comment by IAlex (talk | contribs)   18:55, 7 January 2010

Done in r60798.

Status & tagging log