Jack Phoenix has uploaded a new change for review.

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

Change subject: Modernization & cleanup
......................................................................

Modernization & cleanup

* wfMsg() -> wfMessage()
* dirname( __FILE__ ) -> __DIR__
* added missing parameter to the 'login-throttled' message
* added my email address to the setup file
* bumped version number to 0.8.1
* bumped copyright year

Change-Id: I7a6f36584c761720816db54ce97db15a01d2bfd2
---
M MediaWikiAuth.php
M MediaWikiAuthPlugin.class.php
2 files changed, 33 insertions(+), 29 deletions(-)


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

diff --git a/MediaWikiAuth.php b/MediaWikiAuth.php
index 3aa8c8b..6b34cd7 100644
--- a/MediaWikiAuth.php
+++ b/MediaWikiAuth.php
@@ -5,14 +5,14 @@
  *
  * @file
  * @ingroup Extensions
- * @version 0.7.1
+ * @version 0.8.1
  * @author Laurence "GreenReaper" Parry
- * @author Jack Phoenix
+ * @author Jack Phoenix <[email protected]>
  * @author Kim Schoonover
  * @author Ryan Schmidt
  * @copyright © 2009-2010 Laurence "GreenReaper" Parry
- * @copyright © 2010-2013 Jack Phoenix, Ryan Schmidt
- * @copyright © 2012-2013 Kim Schoonover
+ * @copyright © 2010-2015 Jack Phoenix, Ryan Schmidt
+ * @copyright © 2012-2015 Kim Schoonover
  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
2.0 or later
  * @link https://www.mediawiki.org/wiki/Extension:MediaWikiAuth Documentation
  */
@@ -40,13 +40,13 @@
        'path' => __FILE__,
        'name' => 'MediaWikiAuth',
        'author' => array( 'Laurence Parry', 'Jack Phoenix', 'Kim Schoonover', 
'Ryan Schmidt' ),
-       'version' => '0.8.0',
+       'version' => '0.8.1',
        'url' => 'https://www.mediawiki.org/wiki/Extension:MediaWikiAuth',
        'description' => 'Authenticates against and imports logins from an 
external MediaWiki instance',
 );
 
 # Stuff
 $wgMessagesDirs['MediaWikiAuth'] = __DIR__ . '/i18n';
-$wgExtensionMessagesFiles['MediaWikiAuth'] = dirname( __FILE__ ) . 
'/MediaWikiAuth.i18n.php';
+$wgExtensionMessagesFiles['MediaWikiAuth'] = __DIR__ . 
'/MediaWikiAuth.i18n.php';
 
 $wgAutoloadClasses['MediaWikiAuthPlugin'] = __DIR__ . 
'/MediaWikiAuthPlugin.class.php';
\ No newline at end of file
diff --git a/MediaWikiAuthPlugin.class.php b/MediaWikiAuthPlugin.class.php
index 4bae5d8..ad83a7b 100644
--- a/MediaWikiAuthPlugin.class.php
+++ b/MediaWikiAuthPlugin.class.php
@@ -35,11 +35,13 @@
         * Using &$errormsg requires a patch, otherwise it'll always be "bad 
password"
         * See Extension:MediaWikiAuth for this patch
         *
-        * @param $username Mixed: username
-        * @param $password Mixed: password to the above username
-        * @param $errormsg Mixed: error message or null
+        * @param string $username Username
+        * @param string $password Password to the above username
+        * @param string|null $errormsg Error message, if any
         */
        function authenticate( $username, $password, &$errormsg = null ) {
+               global $wgMediaWikiAuthAPIURL;
+
                $dbr = wfGetDB( DB_SLAVE );
 
                # If the user exists locally, fall back to local auth
@@ -56,11 +58,10 @@
                                return false;
                        }
                }
-               global $wgMediaWikiAuthAPIURL;
 
                # This is loaded here so it isn't loaded needlessly
                if ( !class_exists( 'Snoopy', false ) ) {
-                       require_once( dirname( __FILE__ ) . '/Snoopy.class.php' 
);
+                       require_once( __DIR__ . '/Snoopy.class.php' );
                }
                $this->snoopy = new Snoopy();
                $this->snoopy->agent = 'Mozilla/5.0 (compatible; MSIE 9.0; 
Windows NT 6.1; Trident/5.0)';
@@ -78,7 +79,7 @@
                        # Did we get in? Look for result: 'Success'
                        $results = unserialize( $this->snoopy->results );
                        wfDebugLog( 'MediaWikiAuth', 'Login result:' . print_r( 
$results, true ) );
-                       $errormsg = wfMsg( 'mwa-error-unknown' );
+                       $errormsg = wfMessage( 'mwa-error-unknown' )->escaped();
                        if ( isset( $results['login'] ) ) {
                                $login = $results['login'];
                                # This ignores the NoName option as it will be 
filtered out before now
@@ -98,7 +99,7 @@
                                                                array( 
'user_id' => $this->old_user_id ),
                                                                __METHOD__
                                                        );
-                                                       if( $dbr->fetchObject( 
$localUser ) ) {
+                                                       if ( $dbr->fetchObject( 
$localUser ) ) {
                                                                $resid = 
(int)$dbr->selectField(
                                                                        'user',
                                                                        
'user_id',
@@ -114,10 +115,10 @@
 
                                        case 'NotExists':
                                                global $wgUser;
-                                               if( $wgUser->isAllowed( 
'createaccount' ) ) {
-                                                       $errormsg = 
wfMsgWikiHtml( 'nosuchuser', htmlspecialchars( $username ) );
+                                               if ( $wgUser->isAllowed( 
'createaccount' ) ) {
+                                                       $errormsg = wfMessage( 
'nosuchuser', htmlspecialchars( $username ) )->escaped();
                                                } else {
-                                                       $errormsg = wfMsg( 
'nosuchusershort', htmlspecialchars( $username ) );
+                                                       $errormsg = wfMessage( 
'nosuchusershort', htmlspecialchars( $username ) )->escaped();
                                                }
                                                break;
 
@@ -128,32 +129,33 @@
                                                break;
 
                                        case 'WrongToken':
-                                               $errormsg = wfMsg( 
'mwa-error-wrong-token' );
+                                               $errormsg = wfMessage( 
'mwa-error-wrong-token' )->escaped();
                                                break;
 
                                        case 'EmptyPass':
-                                               $errormsg = wfMsg( 
'wrongpasswordempty' );
+                                               $errormsg = wfMessage( 
'wrongpasswordempty' )->escaped();
                                                break;
 
                                        case 'WrongPass':
                                        case 'WrongPluginPass':
-                                               $errormsg = wfMsg( 
'wrongpassword' );
+                                               $errormsg = wfMessage( 
'wrongpassword' )->escaped();
                                                break;
 
                                        case 'CreateBlocked':
-                                               $errormsg = wfMsg( 
'mwa-autocreate-blocked' );
+                                               $errormsg = wfMessage( 
'mwa-autocreate-blocked' )->escaped();
                                                break;
 
                                        case 'Throttled':
-                                               $errormsg = wfMsg( 
'login-throttled' );
+                                               global $wgLang, 
$wgPasswordAttemptThrottle;
+                                               $errormsg = wfMessage( 
'login-throttled' )->params( $wgLang->formatDuration( 
$wgPasswordAttemptThrottle['seconds'] ) )->text();
                                                break;
 
                                        case 'ResetPass':
-                                               $errormsg = wfMsg( 
'mwa-resetpass' );
+                                               $errormsg = wfMessage( 
'mwa-resetpass' )->escaped();
                                                break;
                                }
                                if ( isset( $login['wait'] ) ) {
-                                       $errormsg .= ' ' . wfMsg( 'mwa-wait', 
$login['wait'] );
+                                       $errormsg .= ' ' . wfMessage( 
'mwa-wait', $login['wait'] )->escaped();
                                }
                        }
                } while ( isset( $results['login'] ) && $login['result'] == 
'NeedToken' );
@@ -243,11 +245,11 @@
                                        __METHOD__,
                                        array( 'ORDER BY' => 'rev_timestamp 
ASC', 'LIMIT' => 1 )
                                );
-                               if( $res->numRows() ) {
+                               if ( $res->numRows() ) {
                                        $results = $dbr->fetchObject( $res 
)->rev_timestamp;
                                }
                        }
-                       if( is_numeric( $results ) ) {
+                       if ( is_numeric( $results ) ) {
                                $dbw->update(
                                        'user',
                                        array( 'user_registration' => $results 
),
@@ -368,14 +370,15 @@
                                        $user->setRealName( stripslashes( 
html_entity_decode( $matches[3], ENT_QUOTES, 'UTF-8' ) ) );
                                }
                                # wpUserEmail = 1.15 and older, wpemailaddress 
= 1.16+
-                               if ( $user->mEmail == "" && preg_match( 
'^.*(wpUserEmail|wpemailaddress).*value="(.*?)".*^', $result, $matches ) ) {
+                               if ( $user->mEmail == '' && preg_match( 
'^.*(wpUserEmail|wpemailaddress).*value="(.*?)".*^', $result, $matches ) ) {
                                        $user->mEmail = stripslashes( 
html_entity_decode( $matches[2], ENT_QUOTES, 'UTF-8' ) );
                                        wfRunHooks( 'UserSetEmail', array( 
$this, &$this->mEmail ) );
                                        # We assume the target server knows 
what it is doing.
                                        if (
-                                               strpos( $result, 
'(emailauthenticated: ' )
-                                               || strpos( $result, 
'(usersignup-user-pref-emailauthenticated)' ) # Wikia
-                                       ) {
+                                               strpos( $result, 
'(emailauthenticated: ' ) ||
+                                               strpos( $result, 
'(usersignup-user-pref-emailauthenticated)' ) # Wikia
+                                       )
+                                       {
                                                $user->confirmEmail();
                                        } else {
                                                $user->sendConfirmationMail();
@@ -402,6 +405,7 @@
                        $logout_vars = array( 'action' => 'logout' );
                        $this->snoopy->submit( $wgMediaWikiAuthAPIURL, 
$logout_vars );
                }
+
                return true;
        }
 }
\ No newline at end of file

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

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

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

Reply via email to