Pmiazga has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/362557 )
Change subject: POC: Hack user preferences and trigger event on user prefs save
......................................................................
POC: Hack user preferences and trigger event on user prefs save
Currently there is no possibility to detect changes on user
preferences save. This is a possible solution to log disabled|enabled
events on user preferences save.
Additionally we do not have possibility to retrieve all data for
the event like sessionToken, pageToken, previewCountBucket, etc.
Bug: T167365
Change-Id: I33947619fa03b2c6fa550c01981e1c4840df7b54
---
M extension.json
M includes/PopupsContext.php
A includes/UserPreferencesHook.php
3 files changed, 73 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups
refs/changes/57/362557/1
diff --git a/extension.json b/extension.json
index 61da6ee..11e543f 100644
--- a/extension.json
+++ b/extension.json
@@ -10,6 +10,7 @@
"type": "betafeatures",
"AutoloadClasses": {
"Popups\\PopupsHooks": "includes/PopupsHooks.php",
+ "Popups\\UserPreferencesHook":
"includes/UserPreferencesHook.php",
"Popups\\PopupsContext": "includes/PopupsContext.php",
"Popups\\PopupsGadgetsIntegration":
"includes/PopupsGadgetsIntegration.php"
},
@@ -27,7 +28,11 @@
"Popups\\PopupsHooks::onResourceLoaderGetConfigVars"
],
"GetPreferences": [
- "Popups\\PopupsHooks::onGetPreferences"
+ "Popups\\PopupsHooks::onGetPreferences",
+ "Popups\\UserPreferencesHook::onGetPreferences"
+ ],
+ "UserSaveSettings": [
+ "Popups\\UserPreferencesHook::onUserSaveSettings"
],
"UserGetDefaultOptions": [
"Popups\\PopupsHooks::onUserGetDefaultOptions"
diff --git a/includes/PopupsContext.php b/includes/PopupsContext.php
index c712bcd..69b50be 100644
--- a/includes/PopupsContext.php
+++ b/includes/PopupsContext.php
@@ -173,6 +173,20 @@
return $areMet;
}
+
+ public function logUserChangeOptionsEvent( $isEnabled ) {
+ $config = $this->getConfig();
+ $event = [
+ 'action' => $isEnabled == self::PREVIEWS_ENABLED ?
'enabled' : 'disabled',
+ 'isAnon' => false,
+ 'popupEnabled' => $isEnabled
+ ];
+ \EventLogging::logEvent(
+ 'event.Popups',
+ $config->get( 'EventLoggingSchemas' ),
+ $event
+ );
+ }
/**
* Get module logger
*
diff --git a/includes/UserPreferencesHook.php b/includes/UserPreferencesHook.php
new file mode 100644
index 0000000..1219e35
--- /dev/null
+++ b/includes/UserPreferencesHook.php
@@ -0,0 +1,53 @@
+<?php
+/*
+ * This file is part of the MediaWiki extension Popups.
+ *
+ * Popups is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Popups is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Popups. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @file
+ * @ingroup extensions
+ */
+namespace Popups;
+
+use User;
+use ExtensionRegistry;
+
+/**
+ * Hooks definitions for Popups extension
+ *
+ * @package Popups
+ */
+class UserPreferencesHook {
+ private static $oldState;
+
+ private static function getOptionValue( User $user ) {
+ return $user->getOption(
PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME );
+ }
+
+ public static function onGetPreferences( User $user, array &$prefs ) {
+ self::$oldState = self::getOptionValue( $user );
+ }
+
+ public static function onUserSaveSettings( User $user ) {
+ if ( !ExtensionRegistry::getInstance()->isLoaded(
'EventLogging' ) ) {
+ return;
+ }
+ $newState = self::getOptionValue( $user );
+ if ( self::$oldState == PopupsContext::PREVIEWS_ENABLED
+ && $newState == PopupsContext::PREVIEWS_DISABLED ) {
+
PopupsContext::getInstance()->logUserChangeOptionsEvent( $newState );
+ }
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/362557
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I33947619fa03b2c6fa550c01981e1c4840df7b54
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: Pmiazga <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits