Update for AuthManager

* Replace AddNewAccount hook with LocalUserCreated
* When AuthManager is enabled, use it instead of AuthPlugin when
  checking if the email address can be changed.

Bug: T110285
Change-Id: I7e28c574ae6e3b5443e39b38e12a9bded31c283b
This commit is contained in:
Brad Jorsch 2016-05-25 15:03:29 -04:00 committed by Roan Kattouw
parent f6d2360d08
commit 14046ada09
2 changed files with 38 additions and 21 deletions

View file

@ -99,7 +99,7 @@ $wgHooks['EchoAbortEmailNotification'][] = 'EchoHooks::onEchoAbortEmailNotificat
// Hook appropriate events
$wgHooks['ArticleSaveComplete'][] = 'EchoHooks::onArticleSaved';
$wgHooks['AddNewAccount'][] = 'EchoHooks::onAccountCreated';
$wgHooks['LocalUserCreated'][] = 'EchoHooks::onLocalUserCreated';
$wgHooks['ArticleRollbackComplete'][] = 'EchoHooks::onRollbackComplete';
$wgHooks['UserSaveSettings'][] = 'EchoHooks::onUserSaveSettings';

View file

@ -1,5 +1,6 @@
<?php
use MediaWiki\Auth\AuthManager;
use MediaWiki\Logger\LoggerFactory;
class EchoHooks {
@ -240,7 +241,7 @@ class EchoHooks {
* @return bool true in all cases
*/
public static function getPreferences( $user, &$preferences ) {
global $wgAuth, $wgEchoEnableEmailBatch,
global $wgEchoEnableEmailBatch,
$wgEchoNotifiers, $wgEchoNotificationCategories, $wgEchoNotifications,
$wgEchoNewMsgAlert, $wgAllowHTMLEmail, $wgEchoUseCrossWikiBetaFeature,
$wgEchoShowFooterNotice, $wgEchoCrossWikiNotifications;
@ -280,7 +281,7 @@ class EchoHooks {
);
$emailAddress = $user->getEmail() && $user->isAllowed( 'viewmyprivateinfo' )
? htmlspecialchars( $user->getEmail() ) : '';
if ( $user->isAllowed( 'editmyprivateinfo' ) && $wgAuth->allowPropChange( 'emailaddress' ) ) {
if ( $user->isAllowed( 'editmyprivateinfo' ) && self::isEmailChangeAllowed() ) {
if ( $emailAddress === '' ) {
$emailAddress .= $link;
} else {
@ -422,6 +423,20 @@ class EchoHooks {
return true;
}
/**
* Test whether email address change is supposed to be allowed
* @return boolean
*/
private static function isEmailChangeAllowed() {
global $wgAuth, $wgDisableAuthManager;
if ( class_exists( AuthManager::class ) && !$wgDisableAuthManager ) {
return AuthManager::singleton()->allowsPropertyChange( 'emailaddress' );
} else {
return $wgAuth->allowPropChange( 'emailaddress' );
}
}
/**
* Handler for ArticleSaveComplete hook
* @see http://www.mediawiki.org/wiki/Manual:Hooks/ArticleSaveComplete
@ -574,29 +589,31 @@ class EchoHooks {
}
/**
* Handler for AddNewAccount hook.
* @see http://www.mediawiki.org/wiki/Manual:Hooks/AddNewAccount
* Handler for LocalUserCreated hook.
* @see http://www.mediawiki.org/wiki/Manual:Hooks/LocalUserCreated
* @param $user User object that was created.
* @param $byEmail bool True when account was created "by email".
* @param $autocreated bool True when account was auto-created
* @return bool
*/
public static function onAccountCreated( $user, $byEmail ) {
$overrides = self::getNewUserPreferenceOverrides();
foreach ( $overrides as $prefKey => $value ) {
$user->setOption( $prefKey, $value );
public static function onLocalUserCreated( $user, $autocreated ) {
if ( !$autocreated ) {
$overrides = self::getNewUserPreferenceOverrides();
foreach ( $overrides as $prefKey => $value ) {
$user->setOption( $prefKey, $value );
}
$user->saveSettings();
EchoEvent::create( array(
'type' => 'welcome',
'agent' => $user,
// Welcome notification is sent to the agent
'extra' => array(
'notifyAgent' => true
)
) );
}
$user->saveSettings();
EchoEvent::create( array(
'type' => 'welcome',
'agent' => $user,
// Welcome notification is sent to the agent
'extra' => array(
'notifyAgent' => true
)
) );
return true;
}