Jpond has uploaded a new change for review.

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


Change subject: (bug 50430) Generates null array errors in strict php mode for 
fullname and email
......................................................................

(bug 50430) Generates null array errors in strict php mode for fullname and 
email

Fixed by adding function getFullAXUserName that returns the first and last 
name, or first name, or last name (depending on what is available).

Also fixed the array key for contact email which would have caused programs

Change-Id: Ie10c630a1a2029d66450cc26c08a5fb9d009a030
---
M SpecialOpenIDLogin.body.php
1 file changed, 24 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/OpenID 
refs/changes/56/71256/1

diff --git a/SpecialOpenIDLogin.body.php b/SpecialOpenIDLogin.body.php
index 3c6cd4a..267005b 100644
--- a/SpecialOpenIDLogin.body.php
+++ b/SpecialOpenIDLogin.body.php
@@ -333,9 +333,9 @@
                                        $fullname = $sreg['fullname'];
                                }
 
-                               if ( array_key_exists( 
'http://axschema.org/namePerson/first', $ax )
-                                       || array_key_exists( 
'http://axschema.org/namePerson/last', $ax ) ) {
-                                       $fullname = 
$ax['http://axschema.org/namePerson/first'][0] . " " . 
$ax['http://axschema.org/namePerson/last'][0];
+                               $xSetRealName = $this->getFullAXUserName( $ax );
+                               if (!is_null($xSetRealName) ) {
+                                       $fullname = $xSetRealName;
                                }
 
                                if ( $fullname && $this->userNameOK( $fullname 
) ) {
@@ -656,7 +656,7 @@
                        if ( array_key_exists( 'email', $sreg ) ) {
                                $email = $sreg['email'];
                        }
-                       if ( array_key_exists ( 
'http://axschema.org/contact/email', $ax ) ) {
+                       if ( array_key_exists ( 0, 
$ax['http://axschema.org/contact/email']) ) {
                                $email = 
$ax['http://axschema.org/contact/email'][0];
                        }
                        if ( $email ) {
@@ -686,10 +686,9 @@
                                $user->setRealName( $sreg['fullname'] );
                        }
 
-                       if ( array_key_exists( 
'http://axschema.org/namePerson/first', $ax )
-                               || array_key_exists( 
'http://axschema.org/namePerson/last', $ax ) ) {
-
-                               $user->setRealName( 
$ax['http://axschema.org/namePerson/first'][0] . " " . 
$ax['http://axschema.org/namePerson/last'][0] );
+                       $xSetRealName = $this->getFullAXUserName( $ax );
+                       if (!is_null($xSetRealName) ) {
+                               $user->setRealName($xSetRealName);
                        }
 
                }
@@ -896,7 +895,7 @@
 
                # return the part before the @ in the e-mail address;
                # look at AX, then SREG.
-               if ( array_key_exists ( 'http://axschema.org/contact/email', 
$ax ) ) {
+               if ( array_key_exists ( 0, 
$ax['http://axschema.org/contact/email']) ) {
                        $addr = explode( "@", 
$ax['http://axschema.org/contact/email'][0] );
                        if ( $addr ) {
                                return $addr[0];
@@ -1006,6 +1005,22 @@
                                !in_array( $name, $wgReservedUsernames ) );
        }
 
+       /**
+        * Get the partial or full user name from the ax array (if exists)
+        * @param $ax
+        * @return mixed|null|string
+        */
+       function getFullAXUserName( $ax ) {
+               $xSetRealName = "";
+               if ( array_key_exists( 
0,$ax['http://axschema.org/namePerson/first']) ) {
+                       $xSetRealName = 
$ax['http://axschema.org/namePerson/first'][0];
+               }
+               if ( array_key_exists( 
0,$ax['http://axschema.org/namePerson/last']) ) {
+                       $xSetRealName = strlen($xSetRealName) ? $xSetRealName. 
" ".$ax['http://axschema.org/namePerson/last'][0] : 
$ax['http://axschema.org/namePerson/last'][0];
+               }
+               return (strlen($xSetRealName) ? $xSetRealNameS : null);
+       }
+
        # Session stuff
        # -------------
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie10c630a1a2029d66450cc26c08a5fb9d009a030
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/OpenID
Gerrit-Branch: master
Gerrit-Owner: Jpond <jack.p...@psitex.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to