mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-13 17:48:17 +00:00
Hooks: Replace AddNewAccount, AuthPluginAutoCreate with LocalUserCreated
The first two are deprecated. Take advantage of this to consolidate the
code and add comments. Note that these config options are not currently
used in WMF production, and might never be used again, depending on how
futher roll-outs go.
Bug: T135071
Change-Id: Ie7638b1aed9f71c19d0735e831956f853201902b
(cherry picked from commit 0549dc0e47
)
This commit is contained in:
parent
11b1198bc9
commit
74458204f7
|
@ -929,42 +929,47 @@ class VisualEditorHooks {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets user preference to enable the VisualEditor account if the account's
|
||||
* userID is matches modulo $wgVisualEditorNewAccountEnableProportion, if set.
|
||||
* If set to '1', all new accounts would have VisualEditor enabled; at '2',
|
||||
* 50% would; at '20', 5% would, and so on.
|
||||
* Set user preferences for new and auto-created accounts if so configured.
|
||||
*
|
||||
* To be removed once no longer needed.
|
||||
*/
|
||||
public static function onAddNewAccount( $user, $byEmail ) {
|
||||
$x = RequestContext::getMain()->getConfig()->get( 'VisualEditorNewAccountEnableProportion' );
|
||||
|
||||
if (
|
||||
$x &&
|
||||
$user->isLoggedin() &&
|
||||
( ( $user->getId() % $x ) === 0 )
|
||||
) {
|
||||
$user->setOption( 'visualeditor-enable', 1 );
|
||||
$user->saveSettings();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets user preference to enable the VisualEditor account for new auto-
|
||||
* created ('auth') accounts, if $wgVisualEditorAutoAccountEnable is set.
|
||||
*
|
||||
* Sets user preference to enable the VisualEditor account for new non-auto-
|
||||
* created accounts, if the account's userID matches, modulo the value of
|
||||
* $wgVisualEditorNewAccountEnableProportion, if set. If set to '1', all new
|
||||
* accounts would have VisualEditor enabled; at '2', 50% would; at '20',
|
||||
* 5% would, and so on.
|
||||
*
|
||||
* To be removed once no longer needed.
|
||||
*/
|
||||
public static function onAuthPluginAutoCreate( $user ) {
|
||||
public static function onLocalUserCreated( $user, $autocreated ) {
|
||||
$config = RequestContext::getMain()->getConfig();
|
||||
$enableProportion = $config->get( 'VisualEditorNewAccountEnableProportion' );
|
||||
|
||||
if (
|
||||
RequestContext::getMain()->getConfig()->get( 'VisualEditorAutoAccountEnable' ) &&
|
||||
!User::getDefaultOption( 'visualeditor-editor' ) &&
|
||||
$user->isLoggedin()
|
||||
// Only act on actual accounts (avoid race condition bugs)
|
||||
$user->isLoggedin() &&
|
||||
// Only act if the default isn't already set
|
||||
!User::getDefaultOption( 'visualeditor-enable' ) &&
|
||||
// Act if either …
|
||||
(
|
||||
// … this is an auto-created account and we're configured so to do
|
||||
(
|
||||
$autocreated &&
|
||||
$config->get( 'VisualEditorAutoAccountEnable' )
|
||||
) ||
|
||||
// … this is a real new account that matches the modulo and we're configured so to do
|
||||
(
|
||||
!$autocreated &&
|
||||
$enableProportion &&
|
||||
( ( $user->getId() % $enableProportion ) === 0 )
|
||||
)
|
||||
)
|
||||
) {
|
||||
$user->setOption( 'visualeditor-enable', 1 );
|
||||
$user->saveSettings();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -175,11 +175,8 @@
|
|||
"BeforeInitialize": [
|
||||
"VisualEditorHooks::onBeforeInitialize"
|
||||
],
|
||||
"AddNewAccount": [
|
||||
"VisualEditorHooks::onAddNewAccount"
|
||||
],
|
||||
"AuthPluginAutoCreate": [
|
||||
"VisualEditorHooks::onAuthPluginAutoCreate"
|
||||
"LocalUserCreated": [
|
||||
"VisualEditorHooks::onLocalUserCreated"
|
||||
],
|
||||
"CustomEditor": [
|
||||
"VisualEditorHooks::onCustomEditor"
|
||||
|
|
Loading…
Reference in a new issue