Cleanup: namespace this extension, move stuff into includes

Change-Id: I7cf55685de955912c8637681c397179553d17152
This commit is contained in:
Max Semenik 2017-06-15 15:56:12 -07:00 committed by Reedy
parent 176edf0826
commit 9b3bd403ec
4 changed files with 43 additions and 17 deletions

View file

@ -25,34 +25,34 @@
]
},
"AutoloadClasses": {
"LoginNotify": "LoginNotify_body.php",
"LoginNotifyHooks": "LoginNotify.hooks.php",
"LoginNotifyPresentationModel": "LoginNotifyPresentationModel.php"
"LoginNotify\\LoginNotify": "includes/LoginNotify.php",
"LoginNotify\\Hooks": "includes/Hooks.php",
"LoginNotify\\PresentationModel": "includes/PresentationModel.php"
},
"Hooks": {
"BeforeCreateEchoEvent": [
"LoginNotifyHooks::onBeforeCreateEchoEvent"
"LoginNotify\\Hooks::onBeforeCreateEchoEvent"
],
"EchoGetBundleRules": [
"LoginNotifyHooks::onEchoGetBundleRules"
"LoginNotify\\Hooks::onEchoGetBundleRules"
],
"LoginAuthenticateAudit": [
"LoginNotifyHooks::onLoginAuthenticateAudit"
],
"AuthManagerLoginAuthenticateAudit": [
"LoginNotifyHooks::onAuthManagerLoginAuthenticateAudit"
"LoginNotify\\Hooks::onAuthManagerLoginAuthenticateAudit"
],
"AddNewAccount": [
"LoginNotifyHooks::onAddNewAccount"
"LoginNotify\\Hooks::onAddNewAccount"
],
"UserLoadOptions": [
"LoginNotifyHooks::onUserLoadOptions"
"LoginNotify\\Hooks::onUserLoadOptions"
],
"UserSaveOptions": [
"LoginNotifyHooks::onUserSaveOptions"
"LoginNotify\\Hooks::onUserSaveOptions"
],
"LocalUserCreated": [
"LoginNotifyHooks::onLocalUserCreated"
"LoginNotify\\Hooks::onLocalUserCreated"
]
},
"config": {

View file

@ -6,9 +6,14 @@
* @ingroup Extensions
*/
use MediaWiki\Auth\AuthenticationResponse;
namespace LoginNotify;
class LoginNotifyHooks {
use EchoAttributeManager;
use LoginForm;
use MediaWiki\Auth\AuthenticationResponse;
use User;
class Hooks {
const OPTIONS_FAKE_TRUTH = 2;
const OPTIONS_FAKE_FALSE = 'fake-false';

View file

@ -6,10 +6,24 @@
* @ingroup Extensions
*/
namespace LoginNotify;
use BagOStuff;
use CentralAuthUser;
use Config;
use EchoEvent;
use WebRequest;
use Wikimedia\Rdbms\Database;
use Exception;
use IP;
use MediaWiki\Logger\LoggerFactory;
use MWCryptRand;
use ObjectCache;
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerAwareInterface;
use Wikimedia\Rdbms\DBConnectionError;
use RequestContext;
use UnexpectedValueException;
use User;
/**
* Handle sending notifications on login from unknown source.
@ -46,7 +60,7 @@ class LoginNotify implements LoggerAwareInterface {
$this->cache = $cache;
$this->config = $cfg;
// Generate salt just once to avoid duplicate cookies
$this->gSalt = Wikimedia\base_convert( MWCryptRand::generateHex( 8 ), 16, 36 );
$this->gSalt = \Wikimedia\base_convert( MWCryptRand::generateHex( 8 ), 16, 36 );
if ( $this->config->get( 'LoginNotifySecretKey' ) !== null ) {
$this->secret = $this->config->get( 'LoginNotifySecretKey' );
@ -517,7 +531,7 @@ class LoginNotify implements LoggerAwareInterface {
if ( !is_string( $res ) ) {
throw new UnexpectedValueException( "Hash failed" );
}
$encoded = $year . '-' . $salt . '-' . Wikimedia\base_convert( $res, 16, 36 );
$encoded = $year . '-' . $salt . '-' . \Wikimedia\base_convert( $res, 16, 36 );
return $encoded;
}
@ -529,7 +543,7 @@ class LoginNotify implements LoggerAwareInterface {
* @return string The cache key
*/
private function getKey( User $user, $type ) {
$userHash = Wikimedia\base_convert( sha1( $user->getName() ), 16, 36, 31 );
$userHash = \Wikimedia\base_convert( sha1( $user->getName() ), 16, 36, 31 );
return $this->cache->makeGlobalKey(
'loginnotify', $type, $userHash
);

View file

@ -1,5 +1,12 @@
<?php
class LoginNotifyPresentationModel extends EchoEventPresentationModel {
namespace LoginNotify;
use EchoEventPresentationModel;
use Message;
use SpecialPage;
class PresentationModel extends EchoEventPresentationModel {
/**
* Show an user avatar.