Reedy has uploaded a new change for review. https://gerrit.wikimedia.org/r/311202
Change subject: Fixup some docblocks ...................................................................... Fixup some docblocks array() -> [] Minor trivial cleanup Change-Id: I95735f928d3e5d6ac9d2a10d92b40ed01cf2737c --- M OATHAuth.alias.php M OATHAuth.hooks.legacy.php M OATHAuth.hooks.php M OATHAuthKey.php M OATHAuthUtils.php M OATHUser.php M OATHUserRepository.php M auth/TOTPAuthenticationRequest.php M auth/TOTPSecondaryAuthenticationProvider.php M modules/jquery.qrcode.js M special/ProxySpecialPage.php M special/SpecialOATHDisable.php M special/SpecialOATHEnable.php M special/SpecialOATHLogin.php 14 files changed, 113 insertions(+), 107 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/OATHAuth refs/changes/02/311202/1 diff --git a/OATHAuth.alias.php b/OATHAuth.alias.php index e454fd8..4de0434 100644 --- a/OATHAuth.alias.php +++ b/OATHAuth.alias.php @@ -7,39 +7,39 @@ */ // @codingStandardsIgnoreFile -$specialPageAliases = array(); +$specialPageAliases = []; /** English (English) */ -$specialPageAliases['en'] = array( - 'OATH' => array( 'OATH', 'OATHAuth' ), -); +$specialPageAliases['en'] = [ + 'OATH' => [ 'OATH', 'OATHAuth' ], +]; /** Arabic (العربية) */ -$specialPageAliases['ar'] = array( - 'OATH' => array( 'أواث', 'أواث_أوث' ), -); +$specialPageAliases['ar'] = [ + 'OATH' => [ 'أواث', 'أواث_أوث' ], +]; /** Egyptian Arabic (مصرى) */ -$specialPageAliases['arz'] = array( - 'OATH' => array( 'اواث', 'اواث_اوث' ), -); +$specialPageAliases['arz'] = [ + 'OATH' => [ 'اواث', 'اواث_اوث' ], +]; /** Northern Luri (لۊری شومالی) */ -$specialPageAliases['lrc'] = array( - 'OATH' => array( 'قأسأم' ), -); +$specialPageAliases['lrc'] = [ + 'OATH' => [ 'قأسأم' ], +]; /** Urdu (اردو) */ -$specialPageAliases['ur'] = array( - 'OATH' => array( 'حلف_نامہ' ), -); +$specialPageAliases['ur'] = [ + 'OATH' => [ 'حلف_نامہ' ], +]; /** Simplified Chinese (中文(简体)) */ -$specialPageAliases['zh-hans'] = array( - 'OATH' => array( 'OATH验证' ), -); +$specialPageAliases['zh-hans'] = [ + 'OATH' => [ 'OATH验证' ], +]; /** Traditional Chinese (中文(繁體)) */ -$specialPageAliases['zh-hant'] = array( - 'OATH' => array( 'OATH_認證' ), -); \ No newline at end of file +$specialPageAliases['zh-hant'] = [ + 'OATH' => [ 'OATH_認證' ], +]; \ No newline at end of file diff --git a/OATHAuth.hooks.legacy.php b/OATHAuth.hooks.legacy.php index dbe0a9f..d62b3ec 100644 --- a/OATHAuth.hooks.legacy.php +++ b/OATHAuth.hooks.legacy.php @@ -10,7 +10,7 @@ * @return bool */ static function ChangePasswordForm( &$extraFields ) { - $tokenField = array( 'wpOATHToken', 'oathauth-token', 'password', '' ); + $tokenField = [ 'wpOATHToken', 'oathauth-token', 'password', '' ]; array_push( $extraFields, $tokenField ); return true; diff --git a/OATHAuth.hooks.php b/OATHAuth.hooks.php index d500a6e..4812e45 100644 --- a/OATHAuth.hooks.php +++ b/OATHAuth.hooks.php @@ -2,8 +2,6 @@ use MediaWiki\Auth\AuthenticationRequest; use MediaWiki\Auth\AuthManager; -use MediaWiki\Auth\ConfirmLinkSecondaryAuthenticationProvider; -use MediaWiki\Auth\EmailNotificationSecondaryAuthenticationProvider; /** * Hooks for Extension:OATHAuth @@ -119,18 +117,17 @@ $title = SpecialPage::getTitleFor( 'OATH' ); $msg = $oathUser->getKey() !== null ? 'oathauth-disable' : 'oathauth-enable'; - $preferences[$msg] = array( + $preferences[$msg] = [ 'type' => 'info', 'raw' => 'true', 'default' => Linker::link( $title, wfMessage( $msg )->escaped(), - array(), - array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText() ) + [], + [ 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText() ] ), 'label-message' => 'oathauth-prefs-label', - 'section' => 'personal/info', - ); + 'section' => 'personal/info', ]; return true; } @@ -145,7 +142,7 @@ case 'mysql': case 'sqlite': $updater->addExtensionTable( 'oathauth_users', "$base/sql/mysql/tables.sql" ); - $updater->addExtensionUpdate( array( array( __CLASS__, 'schemaUpdateOldUsersFromInstaller' ) ) ); + $updater->addExtensionUpdate( [ [ __CLASS__, 'schemaUpdateOldUsersFromInstaller' ] ] ); $updater->dropExtensionField( 'oathauth_users', 'secret_reset', "$base/sql/mysql/patch-remove_reset.sql" ); break; @@ -180,8 +177,8 @@ $res = $db->select( 'oathauth_users', - array( 'id', 'scratch_tokens' ), - array( 'is_validated != 0' ), + [ 'id', 'scratch_tokens' ], + [ 'is_validated != 0' ], __METHOD__ ); @@ -190,15 +187,15 @@ if ( $scratchTokens ) { $db->update( 'oathauth_users', - array( 'scratch_tokens' => implode( ',', $scratchTokens ) ), - array( 'id' => $row->id ), + [ 'scratch_tokens' => implode( ',', $scratchTokens ) ], + [ 'id' => $row->id ], __METHOD__ ); } } // Remove rows from the table where user never completed the setup process - $db->delete( 'oathauth_users', array( 'is_validated' => 0 ), __METHOD__ ); + $db->delete( 'oathauth_users', [ 'is_validated' => 0 ], __METHOD__ ); return true; } diff --git a/OATHAuthKey.php b/OATHAuthKey.php index fb67283..67c2b2f 100644 --- a/OATHAuthKey.php +++ b/OATHAuthKey.php @@ -34,7 +34,7 @@ public static function newFromRandom() { $object = new self( Base32::encode( MWCryptRand::generate( 10, true ) ), - array() + [] ); $object->regenerateScratchTokens(); @@ -48,12 +48,12 @@ */ public function __construct( $secret, array $scratchTokens ) { // Currently harcoded values; might be used in future - $this->secret = array( + $this->secret = [ 'mode' => 'hotp', 'secret' => $secret, 'period' => 30, 'algorithm' => 'SHA1', - ); + ]; $this->scratchTokens = $scratchTokens; } @@ -65,7 +65,7 @@ } /** - * @return Array + * @return array */ public function getScratchTokens() { return $this->scratchTokens; @@ -88,7 +88,7 @@ } // Prevent replay attacks - $memc = ObjectCache::newAnything( array() ); + $memc = ObjectCache::newAnything( [] ); $uid = CentralIdLookup::factory()->centralIdFromLocalUser( $user->getUser() ); $memcKey = wfMemcKey( 'oauthauth', 'usedtokens', $uid ); $lastWindow = (int)$memc->get( $memcKey ); @@ -138,7 +138,7 @@ } public function regenerateScratchTokens() { - $scratchTokens = array(); + $scratchTokens = []; for ( $i = 0; $i < 5; $i++ ) { array_push( $scratchTokens, Base32::encode( MWCryptRand::generate( 10, true ) ) ); } diff --git a/OATHAuthUtils.php b/OATHAuthUtils.php index 9d8b401..00fe248 100644 --- a/OATHAuthUtils.php +++ b/OATHAuthUtils.php @@ -11,8 +11,8 @@ * Encrypt an aray of variables to put into the user's session. We use this * when storing the user's password in their session. We can use json as the * serialization format because $plaintextVars is an array of strings. - * @param array of user input strings - * @param int user_id, passed to key derivation functions so each user uses + * @param array $plaintextVars array of user input strings + * @param int $userId, passed to key derivation functions so each user uses * distinct encryption and hmac keys * @return string encrypted data packet */ @@ -24,7 +24,8 @@ /** * Decrypt an encrypted packet, generated with encryptSessionData - * @param string Encrypted data packet + * @param string $ciphertext Encrypted data packet + * @param string|int $userId * @return array of strings */ public static function decryptSessionData( $ciphertext, $userId ) { @@ -51,16 +52,16 @@ */ private static function getUserKeys( $secret, $userid ) { $keymats = hash_pbkdf2( 'sha256', $secret, "oath-$userid", 10001, 64, true ); - return array( + return [ 'encrypt' => substr( $keymats, 0, 32 ), 'hmac' => substr( $keymats, 32, 32 ), - ); + ]; } /** * Actually encrypt the data, using a new random IV, and prepend the hmac * of the encrypted data + IV, using a separate hmac key. - * @return $hmac.$iv.$ciphertext, each component b64 encoded + * @return string $hmac.$iv.$ciphertext, each component b64 encoded */ private static function seal( $data, $encKey, $hmacKey ) { $iv = MWCryptRand::generate( 16, true ); @@ -79,7 +80,11 @@ /** * Decrypt data sealed using seal(). First checks the hmac to prevent various * attacks. - * @return plaintext + * @param $encrypted + * @param $encKey + * @param $hmacKey + * @return string plaintext + * @throws Exception */ private static function unseal( $encrypted, $encKey, $hmacKey ) { $pieces = explode( '.', $encrypted ); diff --git a/OATHUser.php b/OATHUser.php index 64efd33..4d80fa1 100644 --- a/OATHUser.php +++ b/OATHUser.php @@ -22,6 +22,9 @@ $this->key = $key; } + /** + * @return User + */ public function getUser() { return $this->user; } diff --git a/OATHUserRepository.php b/OATHUserRepository.php index ed48c51..a7f6a33 100644 --- a/OATHUserRepository.php +++ b/OATHUserRepository.php @@ -8,12 +8,16 @@ $this->lb = $lb; } + /** + * @param User $user + * @return OATHUser + */ public function findByUser( User $user ) { $oathUser = new OATHUser( $user, null ); $uid = CentralIdLookup::factory()->centralIdFromLocalUser( $user ); $res = $this->getDB( DB_SLAVE ) - ->selectRow( 'oathauth_users', '*', array( 'id' => $uid ), __METHOD__ ); + ->selectRow( 'oathauth_users', '*', [ 'id' => $uid ], __METHOD__ ); if ( $res ) { $key = new OATHAuthKey( $res->secret, explode( ',', $res->scratch_tokens ) ); $oathUser->setKey( $key ); @@ -25,12 +29,12 @@ public function persist( OATHUser $user ) { $this->getDB( DB_MASTER )->replace( 'oathauth_users', - array( 'id' ), - array( + [ 'id' ], + [ 'id' => CentralIdLookup::factory()->centralIdFromLocalUser( $user->getUser() ), 'secret' => $user->getKey()->getSecret(), 'scratch_tokens' => implode( ',', $user->getKey()->getScratchTokens() ), - ), + ], __METHOD__ ); } @@ -38,7 +42,7 @@ public function remove( OATHUser $user ) { $this->getDB( DB_MASTER )->delete( 'oathauth_users', - array( 'id' => CentralIdLookup::factory()->centralIdFromLocalUser( $user->getUser() ) ), + [ 'id' => CentralIdLookup::factory()->centralIdFromLocalUser( $user->getUser() ) ], __METHOD__ ); } @@ -50,6 +54,6 @@ private function getDB( $index ) { global $wgOATHAuthDatabase; - return $this->lb->getConnectionRef( $index, array(), $wgOATHAuthDatabase ); + return $this->lb->getConnectionRef( $index, [], $wgOATHAuthDatabase ); } } diff --git a/auth/TOTPAuthenticationRequest.php b/auth/TOTPAuthenticationRequest.php index 99220ce..f1f5dd6 100644 --- a/auth/TOTPAuthenticationRequest.php +++ b/auth/TOTPAuthenticationRequest.php @@ -17,12 +17,10 @@ } public function getFieldInfo() { - return array( - 'OATHToken' => array( + return [ + 'OATHToken' => [ 'type' => 'string', 'label' => wfMessage( 'oathauth-auth-token-label' ), - 'help' => wfMessage( 'oathauth-auth-token-help' ), - ), - ); + 'help' => wfMessage( 'oathauth-auth-token-help' ), ], ]; } } diff --git a/auth/TOTPSecondaryAuthenticationProvider.php b/auth/TOTPSecondaryAuthenticationProvider.php index 2ca930a..0fb9d09 100644 --- a/auth/TOTPSecondaryAuthenticationProvider.php +++ b/auth/TOTPSecondaryAuthenticationProvider.php @@ -38,7 +38,7 @@ if ( $oathuser->getKey() === null ) { return AuthenticationResponse::newAbstain(); } else { - return AuthenticationResponse::newUI( array( new TOTPAuthenticationRequest() ), + return AuthenticationResponse::newUI( [ new TOTPAuthenticationRequest() ], wfMessage( 'oathauth-auth-ui' ) ); } } @@ -51,14 +51,14 @@ /** @var TOTPAuthenticationRequest $request */ $request = AuthenticationRequest::getRequestByClass( $reqs, TOTPAuthenticationRequest::class ); if ( !$request ) { - return AuthenticationResponse::newUI( array( new TOTPAuthenticationRequest() ), + return AuthenticationResponse::newUI( [ new TOTPAuthenticationRequest() ], wfMessage( 'oathauth-login-failed' ) ); } $throttler = new Throttler( null, [ 'type' => 'TOTP' ] ); $result = $throttler->increase( $user->getName(), null, __METHOD__ ); if ( $result ) { - return AuthenticationResponse::newUI( array( new TOTPAuthenticationRequest() ), + return AuthenticationResponse::newUI( [ new TOTPAuthenticationRequest() ], new Message( 'oathauth-throttled', [ Message::durationParam( $result['wait'] ) ] ) ); } @@ -75,7 +75,7 @@ $throttler->clear( $user->getName(), null ); return AuthenticationResponse::newPass(); } else { - return AuthenticationResponse::newUI( array( new TOTPAuthenticationRequest() ), + return AuthenticationResponse::newUI( [ new TOTPAuthenticationRequest() ], wfMessage( 'oathauth-login-failed' ) ); } } diff --git a/modules/jquery.qrcode.js b/modules/jquery.qrcode.js index 6e07fcd..15a1c66 100644 --- a/modules/jquery.qrcode.js +++ b/modules/jquery.qrcode.js @@ -13,8 +13,8 @@ height : 256, typeNumber : -1, correctLevel : QRErrorCorrectLevel.H, - background : "#ffffff", - foreground : "#000000" + background : "#ffffff", + foreground : "#000000" }, options); var createCanvas = function(){ diff --git a/special/ProxySpecialPage.php b/special/ProxySpecialPage.php index 23e84de..193485a 100644 --- a/special/ProxySpecialPage.php +++ b/special/ProxySpecialPage.php @@ -39,7 +39,7 @@ */ public function __call( $method, $args ) { $this->init(); - return call_user_func_array( array( $this->target, $method ), $args ); + return call_user_func_array( [ $this->target, $method ], $args ); } diff --git a/special/SpecialOATHDisable.php b/special/SpecialOATHDisable.php index 3ae265c..b1879b9 100644 --- a/special/SpecialOATHDisable.php +++ b/special/SpecialOATHDisable.php @@ -36,7 +36,7 @@ public function alterForm( HTMLForm $form ) { $form->setMessagePrefix( 'oathauth' ); $form->setWrapperLegend( false ); - $form->getOutput()->setPagetitle( $this->msg( 'oathauth-disable' ) ); + $form->getOutput()->setPageTitle( $this->msg( 'oathauth-disable' ) ); } /** @@ -70,23 +70,23 @@ * @return array[] */ protected function getFormFields() { - return array( - 'token' => array( + return [ + 'token' => [ 'type' => 'text', 'label-message' => 'oathauth-entertoken', 'name' => 'token', - ), - 'returnto' => array( + ], + 'returnto' => [ 'type' => 'hidden', 'default' => $this->getRequest()->getVal( 'returnto' ), 'name' => 'returnto', - ), - 'returntoquery' => array( + ], + 'returntoquery' => [ 'type' => 'hidden', 'default' => $this->getRequest()->getVal( 'returntoquery' ), 'name' => 'returntoquery', - ) - ); + ] + ]; } /** @@ -96,7 +96,7 @@ */ public function onSubmit( array $formData ) { if ( !$this->OATHUser->getKey()->verifyToken( $formData['token'], $this->OATHUser ) ) { - return array( 'oathauth-failedtovalidateoauth' ); + return [ 'oathauth-failedtovalidateoauth' ]; } $this->OATHUser->setKey( null ); diff --git a/special/SpecialOATHEnable.php b/special/SpecialOATHEnable.php index 49439e7..ecc26a1 100644 --- a/special/SpecialOATHEnable.php +++ b/special/SpecialOATHEnable.php @@ -37,7 +37,7 @@ public function alterForm( HTMLForm $form ) { $form->setMessagePrefix( 'oathauth' ); $form->setWrapperLegend( false ); - $form->getOutput()->setPagetitle( $this->msg( 'oathauth-enable' ) ); + $form->getOutput()->setPageTitle( $this->msg( 'oathauth-enable' ) ); $form->getOutput()->addModules( 'ext.oath.showqrcode' ); } @@ -93,20 +93,20 @@ 'style' => 'width: 256px; height: 256px;' ] ); - return array( - 'app' => array( + return [ + 'app' => [ 'type' => 'info', 'default' => $this->msg( 'oathauth-step1-test' )->escaped(), 'raw' => true, 'section' => 'step1', - ), - 'qrcode' => array( + ], + 'qrcode' => [ 'type' => 'info', 'default' => $qrcodeElement, 'raw' => true, 'section' => 'step2', - ), - 'manual' => array( + ], + 'manual' => [ 'type' => 'info', 'label-message' => 'oathauth-step2alt', 'default' => @@ -116,33 +116,32 @@ . $key->getSecret() . '<br/>', 'raw' => true, 'section' => 'step2', - ), - 'scratchtokens' => array( + ], + 'scratchtokens' => [ 'type' => 'info', 'default' => $this->msg( 'openstackmanager-scratchtokens' ) . $this->createResourceList( $key->getScratchTokens() ), 'raw' => true, 'section' => 'step3', - ), - 'token' => array( + ], + 'token' => [ 'type' => 'text', 'default' => '', 'label-message' => 'oathauth-entertoken', 'name' => 'token', 'section' => 'step4', - ), - 'returnto' => array( + ], + 'returnto' => [ 'type' => 'hidden', 'default' => $this->getRequest()->getVal( 'returnto' ), 'name' => 'returnto', - ), - 'returntoquery' => array( + ], + 'returntoquery' => [ 'type' => 'hidden', 'default' => $this->getRequest()->getVal( 'returntoquery' ), - 'name' => 'returntoquery', - ) - ); + 'name' => 'returntoquery', ] + ]; } /** @@ -155,7 +154,7 @@ $key = $this->getRequest()->getSessionData( 'oathauth_key' ); if ( !$key->verifyToken( $formData['token'], $this->OATHUser ) ) { - return array( 'oathauth-failedtovalidateoauth' ); + return [ 'oathauth-failedtovalidateoauth' ]; } $this->getRequest()->setSessionData( 'oathauth_key', null ); @@ -177,8 +176,8 @@ private function createResourceList( $resources ) { $resourceList = ''; foreach ( $resources as $resource ) { - $resourceList .= Html::rawElement( 'li', array(), $resource ); + $resourceList .= Html::rawElement( 'li', [], $resource ); } - return Html::rawElement( 'ul', array(), $resourceList ); + return Html::rawElement( 'ul', [], $resourceList ); } } diff --git a/special/SpecialOATHLogin.php b/special/SpecialOATHLogin.php index 0749535..a50cc6c 100644 --- a/special/SpecialOATHLogin.php +++ b/special/SpecialOATHLogin.php @@ -38,7 +38,7 @@ public function alterForm( HTMLForm $form ) { $form->setMessagePrefix( 'oathauth' ); $form->setWrapperLegend( false ); - $form->getOutput()->setPagetitle( $this->msg( 'oathauth-login' ) ); + $form->getOutput()->setPageTitle( $this->msg( 'oathauth-login' ) ); } /** @@ -59,25 +59,25 @@ * @return array[] */ protected function getFormFields() { - return array( - 'token' => array( + return [ + 'token' => [ 'type' => 'text', 'default' => '', 'label-message' => 'oathauth-entertoken', 'name' => 'token', 'required' => true - ), - 'returnto' => array( + ], + 'returnto' => [ 'type' => 'hidden', 'default' => $this->getRequest()->getVal( 'returnto' ), 'name' => 'returnto', - ), - 'returntoquery' => array( + ], + 'returntoquery' => [ 'type' => 'hidden', 'default' => $this->getRequest()->getVal( 'returntoquery' ), 'name' => 'returntoquery', - ) - ); + ] + ]; } /** -- To view, visit https://gerrit.wikimedia.org/r/311202 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I95735f928d3e5d6ac9d2a10d92b40ed01cf2737c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/OATHAuth Gerrit-Branch: master Gerrit-Owner: Reedy <re...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits