Legoktm has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/88150


Change subject: Use the API to fetch the email if possible
......................................................................

Use the API to fetch the email if possible

Change-Id: I77a9d299f9de623e5257d04ea00f65e33167cb6c
---
M MediaWikiAuth.php
1 file changed, 34 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MediaWikiAuth 
refs/changes/50/88150/1

diff --git a/MediaWikiAuth.php b/MediaWikiAuth.php
index 0c52391..cfa43c9 100644
--- a/MediaWikiAuth.php
+++ b/MediaWikiAuth.php
@@ -349,39 +349,47 @@
                        $prefs_vars = array(
                                'action' => 'query',
                                'meta' => 'userinfo',
-                               'uiprop' => 'options',
+                               'uiprop' => 'options|email',
                                'format' => 'php'
                        );
 
                        $this->snoopy->submit( $wgMediaWikiAuthAPIURL, 
$prefs_vars );
                        $results = unserialize( $this->snoopy->results );
-                       if (
-                               isset( $results['query'] ) &&
-                               isset( $results['query']['userinfo'] ) &&
-                               isset( $results['query']['userinfo']['options'] 
)
-                       ) {
-                               $options = 
$results['query']['userinfo']['options'];
-                               # Don't need some options
-                               $ignoredOptions = array(
-                                       'widgets', 'showAds', 'theme',
-                                       'disableeditingtips', 'edit-similar',
-                                       'skinoverwrite', 'htmlemails', 
'marketing',
-                                       'notifyhonorifics', 'notifychallenge',
-                                       'notifygift', 'notifyfriendsrequest',
-                                       'blackbirdenroll', 'marketingallowed',
-                                       'disablecategorysuggest', 
'myhomedisableredirect',
-                                       'avatar', 'widescreeneditingtips',
-                                       'disablelinksuggest', 
'watchlistdigestclear',
-                                       'hidefollowedpages', 
'enotiffollowedpages',
-                                       'enotiffollowedminoredits', 
'myhomedefaultview',
-                                       'disablecategoryselect'
-                               );
-                               foreach ( $ignoredOptions as $optName ) {
-                                       if ( isset( $options[$optName] ) ) {
-                                               unset( $options[$optName] );
+                       if ( isset( $results['query'] ) && isset( 
$results['query']['userinfo'] ) ) {
+                               if ( isset( 
$results['query']['userinfo']['options'] ) ) {
+                                       $options = 
$results['query']['userinfo']['options'];
+                                       # Don't need some options
+                                       $ignoredOptions = array(
+                                               'widgets', 'showAds', 'theme',
+                                               'disableeditingtips', 
'edit-similar',
+                                               'skinoverwrite', 'htmlemails', 
'marketing',
+                                               'notifyhonorifics', 
'notifychallenge',
+                                               'notifygift', 
'notifyfriendsrequest',
+                                               'blackbirdenroll', 
'marketingallowed',
+                                               'disablecategorysuggest', 
'myhomedisableredirect',
+                                               'avatar', 
'widescreeneditingtips',
+                                               'disablelinksuggest', 
'watchlistdigestclear',
+                                               'hidefollowedpages', 
'enotiffollowedpages',
+                                               'enotiffollowedminoredits', 
'myhomedefaultview',
+                                               'disablecategoryselect'
+                                       );
+                                       foreach ( $ignoredOptions as $optName ) 
{
+                                               if ( isset( $options[$optName] 
) ) {
+                                                       unset( 
$options[$optName] );
+                                               }
+                                       }
+                                       $user->mOptions = array_merge( 
$user->mOptions, $options );
+                               }
+                               // Older wikis might not expose this in the API
+                               if ( isset( 
$results['query']['userinfo']['email'] ) ) {
+                                       $user->mEmail = 
$results['query']['userinfo']['email'];
+                                       wfRunHooks( 'UserSetEmail', array( 
$this, &$this->mEmail ) );
+                                       if ( isset( 
$results['query']['userinfo']['emailauthenticated'] ) ) {
+                                               $user->confirmEmail();
+                                       } else {
+                                               $user->sendConfirmationMail();
                                        }
                                }
-                               $user->mOptions = array_merge( $user->mOptions, 
$options );
                        }
 
                        # Scraping stuff; there really should be api queries 
for this...

-- 
To view, visit https://gerrit.wikimedia.org/r/88150
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I77a9d299f9de623e5257d04ea00f65e33167cb6c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MediaWikiAuth
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to