Robmoen has uploaded a new change for review.

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

Change subject: Example QuickSurvey config and expose enabled surveys to browser
......................................................................

Example QuickSurvey config and expose enabled surveys to browser

To test, require QuickSurveys.php as it will load the config.
Enable the example survey by editing the config
run mw.config.get( 'wgEnabledQuickSurveys ') in console.

Bug: T107586
Change-Id: I2e65c4b008635cd0ee42ba8501cf64dea047b0ae
---
D QuickSurveys.hooks.php
M QuickSurveys.php
M extension.json
M i18n/en.json
A includes/Config.php
A includes/QuickSurveys.hooks.php
6 files changed, 96 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/QuickSurveys 
refs/changes/89/229989/1

diff --git a/QuickSurveys.hooks.php b/QuickSurveys.hooks.php
deleted file mode 100644
index fb0d82e..0000000
--- a/QuickSurveys.hooks.php
+++ /dev/null
@@ -1,11 +0,0 @@
-<?php
-/**
- * Hooks for QuickSurveys extension
- *
- * @file
- * @ingroup Extensions
- */
-
-class QuickSurveysHooks {
-
-}
diff --git a/QuickSurveys.php b/QuickSurveys.php
index b88b819..b7594e9 100644
--- a/QuickSurveys.php
+++ b/QuickSurveys.php
@@ -7,7 +7,16 @@
                'Deprecated PHP entry point used for QuickSurveys extension. 
Please use wfLoadExtension instead, ' .
                'see https://www.mediawiki.org/wiki/Extension_registration for 
more details.'
        ); */
-       return;
 } else {
        die( 'This version of the QuickSurveys extension requires MediaWiki 
1.25+' );
 }
+
+/**
+ * Begin configuration variables
+ * FIXME: Ideally survey configuration would live in extension.json and it
+ * must be loaded somewhere other than here before being deployed in 
production.
+ * However, since it is a requirement that disabled surveys be hidden from
+ * the browser, they cannot live in extension.json for now as it is viewable.
+ * See: https://phabricator.wikimedia.org/T107586
+ */
+require_once __DIR__ . "/includes/Config.php";
\ No newline at end of file
diff --git a/extension.json b/extension.json
index 3270830..32cdad9 100644
--- a/extension.json
+++ b/extension.json
@@ -16,8 +16,16 @@
                        "i18n"
                ]
        },
-       "AutoloadClasses": {
-               "QuickSurveysHooks": "QuickSurveys.hooks.php"
+       "ConfigRegistry": {
+               "quicksurveys": "GlobalVarConfig::newInstance"
        },
-       "manifest_version": 1
+       "AutoloadClasses": {
+               "QuickSurveys\\Hooks": "includes/QuickSurveys.hooks.php"
+       },
+       "manifest_version": 1,
+       "Hooks": {
+               "ResourceLoaderGetConfigVars": [
+                       "QuickSurveys\\Hooks::onResourceLoaderGetConfigVars"
+               ]
+       }
 }
diff --git a/i18n/en.json b/i18n/en.json
index df2fe84..5cdd611 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -7,5 +7,9 @@
                        "Rob Moen"
                ]
        },
-       "quicksurveys-desc": "Displays configured surveys on Mobile and 
Desktop."
+       "quicksurveys-desc": "Displays configured surveys on Mobile and 
Desktop.",
+       "ext-quicksurveys-example-question": "Which describes your thoughts 
about Wikipedia.",
+       "ext-quicksurveys-example-answer-positive": "Love it",
+       "ext-quicksurveys-example-answer-neutral" : "It's ok",
+       "ext-quicksurveys-example-answer-negative": "Not for me"
 }
diff --git a/includes/Config.php b/includes/Config.php
new file mode 100644
index 0000000..8c3b0bd
--- /dev/null
+++ b/includes/Config.php
@@ -0,0 +1,28 @@
+<?php
+
+/* Example QuickSurveys config */
+$wgQuickSurveysConfig[] = array(
+       // Survey name
+       'name' => 'example',
+       // Internal or external link survey
+       'type' => 'internal',
+       // Survey question message key
+       'question' => 'ext-quicksurveys-example-question',
+       // Possible answer message keys for positive, neutral, and negative
+       'answers' => array(
+               'positive' => 'ext-quicksurveys-example-answer-positive',
+               'neutral' =>  'ext-quicksurveys-example-answer-neutral',
+               'negative' => 'ext-quicksurveys-example-answer-negative',
+       ),
+       // Which schema to log to
+       'schema' => 'QuickSurveysResponses',
+       // Percentage of users that will see the survey
+       'coverage' => '50',
+       // Is the survey enabled
+       'enabled' => false,
+       // For each platform (desktop, mobile), which version of it is targeted 
(stable, beta, alpha)
+       'platform' => array(
+               'desktop' => array( 'stable' ),
+               'mobile' => array( 'stable', 'beta', 'alpha' ),
+       ),
+);
\ No newline at end of file
diff --git a/includes/QuickSurveys.hooks.php b/includes/QuickSurveys.hooks.php
new file mode 100644
index 0000000..3e71c50
--- /dev/null
+++ b/includes/QuickSurveys.hooks.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Hooks for QuickSurveys extension
+ *
+ * @file
+ * @ingroup Extensions
+ */
+
+namespace QuickSurveys;
+use ConfigFactory;
+
+/**
+ * Hook handlers for QuickSurveys extension
+ *
+ * Hook handler method names should be in the form of:
+ *     on<HookName>()
+ * For intance, the hook handler for the 'RequestContextCreateSkin' would be 
called:
+ *     onRequestContextCreateSkin()
+ */
+class Hooks {
+       /**
+        * ResourceLoaderGetConfigVars hook handler
+        * @see 
https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetConfigVars
+        *
+        * @param array $vars
+        * @return boolean
+        */
+       public static function onResourceLoaderGetConfigVars( &$vars ) {
+               $config = ConfigFactory::getDefaultInstance()->makeConfig( 
'quicksurveys' );
+               // Get configured surveys
+               $configuredSurveys = $config->get( 'QuickSurveysConfig' );
+               $enabledQuickSurveys = array();
+               // Make enabled surveys available to the browser
+               foreach ( $configuredSurveys as $survey ) {
+                       if ( $survey['enabled'] === true ) {
+                               $enabledQuickSurveys = $survey;
+                       }
+               }
+               $vars['wgEnabledQuickSurveys'] = $enabledQuickSurveys;
+               return true;
+       }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2e65c4b008635cd0ee42ba8501cf64dea047b0ae
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/QuickSurveys
Gerrit-Branch: master
Gerrit-Owner: Robmoen <rm...@wikimedia.org>

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

Reply via email to