Jforrester has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/289654

Change subject: Hooks: Replace AddNewAccount, AuthPluginAutoCreate with 
LocalUserCreated
......................................................................

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
---
M VisualEditor.hooks.php
M extension.json
2 files changed, 27 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/54/289654/1

diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php
index 47458ac..7162e98 100644
--- a/VisualEditor.hooks.php
+++ b/VisualEditor.hooks.php
@@ -929,42 +929,43 @@
        }
 
        /**
-        * 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 us preference to enable the VisualEditor account for new 
non-auto-
+        * created accounts, 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.
+        *
         * To be removed once no longer needed.
         */
-       public static function onAuthPluginAutoCreate( $user ) {
+       public static function onLocalUserCreated( $user, $autocreated ) {
+               $config = RequestContext::getMain()->getConfig();
+
                if (
-                       RequestContext::getMain()->getConfig()->get( 
'VisualEditorAutoAccountEnable' ) &&
+                       // Only act on actual accounts (avoid race condition 
bugs)
+                       $user->isLoggedin() &&
+                       // Only act if the default isn't already set
                        !User::getDefaultOption( 'visualeditor-editor' ) &&
-                       $user->isLoggedin()
+                       // 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 &&
+                                       ( ( $user->getId() % $x ) === 0 ) &&
+                                       $config->get( 
'VisualEditorNewAccountEnableProportion' )
+                               )
+                       )
                ) {
                        $user->setOption( 'visualeditor-enable', 1 );
                        $user->saveSettings();
                }
+
                return true;
        }
 
diff --git a/extension.json b/extension.json
index 1f09028..10b0e8e 100644
--- a/extension.json
+++ b/extension.json
@@ -175,11 +175,8 @@
                "BeforeInitialize": [
                        "VisualEditorHooks::onBeforeInitialize"
                ],
-               "AddNewAccount": [
-                       "VisualEditorHooks::onAddNewAccount"
-               ],
-               "AuthPluginAutoCreate": [
-                       "VisualEditorHooks::onAuthPluginAutoCreate"
+               "LocalUserCreated": [
+                       "VisualEditorHooks::onLocalUserCreated"
                ],
                "CustomEditor": [
                        "VisualEditorHooks::onCustomEditor"

-- 
To view, visit https://gerrit.wikimedia.org/r/289654
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie7638b1aed9f71c19d0735e831956f853201902b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Jforrester <jforres...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to