mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-27 17:20:40 +00:00
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:
parent
f6d2360d08
commit
14046ada09
2
Echo.php
2
Echo.php
|
@ -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';
|
||||
|
||||
|
|
57
Hooks.php
57
Hooks.php
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue