Robmoen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/232210
Change subject: Register enabled surveys as RL modules via hook
......................................................................
Register enabled surveys as RL modules via hook
This creates a module per survey configured with survey messages
for server side translation. This can also be responsible for
registering any additional dependencies based on survey configuration.
Additionally:
- Fixed the QuickSurveysConfig so the config can be read
- Creates language keys for link, privacy-policy-link, and
privacy-policy-text
bug: T107586
Change-Id: I8ab993130bf3fe60de461ecdcff66b494281c310
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/QuickSurveys.hooks.php
4 files changed, 75 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/QuickSurveys
refs/changes/10/232210/1
diff --git a/extension.json b/extension.json
index 7e1a91c..30e4411 100644
--- a/extension.json
+++ b/extension.json
@@ -26,10 +26,13 @@
"Hooks": {
"ResourceLoaderGetConfigVars": [
"QuickSurveys\\Hooks::onResourceLoaderGetConfigVars"
+ ],
+ "ResourceLoaderRegisterModules": [
+ "QuickSurveys\\Hooks::onResourceLoaderRegisterModules"
]
},
"config": {
- "@QuickSurveysConfig": [
+ "QuickSurveysConfig": [
{
"@name": "survey name",
"name": "internal example survey",
@@ -48,7 +51,7 @@
"@schema": "Which schema to log to",
"schema": "QuickSurveysResponse",
"@enabled": "whether the survey is enabled",
- "enabled": false,
+ "enabled": true,
"@coverage": "percentage of users that will see
the survey",
"coverage": "50",
"@platform": "for each platform (desktop,
mobile), which version of it is targeted (stable, beta, alpha)",
@@ -64,13 +67,13 @@
"@description": "description of the survey",
"description":
"ext-quicksurveys-example-external-survey-description",
"@link": "external link to the survey",
- "link": "//example.org/survey",
+ "link":
"ext-quicksurveys-example-external-survey-link",
"@privacy-policy-link": "link to the privacy
policy",
- "privacy-policy-link":
"//example.org/privacy-policy",
+ "privacy-policy-link":
"ext-quicksurveys-example-external-survey-privacy-policy-link",
"@privacy-policy-text": "text of the privacy
policy",
"privacy-policy-text":
"ext-quicksurveys-example-external-survey-privacy-policy-text",
"@enabled": "whether the survey is enabled",
- "enabled": false,
+ "enabled": true,
"@coverage": "percentage of users that will see
the survey",
"coverage": "50",
"@platform": "for each platform (desktop,
mobile), which version of it is targeted (stable, beta, alpha)",
diff --git a/i18n/en.json b/i18n/en.json
index f53bfb4..b99949a 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -12,6 +12,8 @@
"ext-quicksurveys-example-internal-survey-answer-positive": "Yes",
"ext-quicksurveys-example-internal-survey-answer-neutral": "Not sure",
"ext-quicksurveys-example-internal-survey-answer-negative": "No",
+ "ext-quicksurveys-example-external-survey-link": "//example.org/survey",
"ext-quicksurveys-example-external-survey-description": "This is the
description of the example external survey.",
+ "ext-quicksurveys-example-external-survey-privacy-policy-link":
"//example.org/privacy-policy",
"ext-quicksurveys-example-external-survey-privacy-policy-text":
"Privacy Policy"
}
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 03c7a2a..bcf6063 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -13,6 +13,8 @@
"ext-quicksurveys-example-internal-survey-answer-positive": "The
positive answer for the example internal survey\n{{Identical|Yes}}",
"ext-quicksurveys-example-internal-survey-answer-neutral": "The neutral
answer for the example internal survey\n{{Identical|Not sure}}",
"ext-quicksurveys-example-internal-survey-answer-negative": "The
negative answer for the example internal survey\n{{Identical|No}}",
+ "ext-quicksurveys-example-external-survey-link": "Web link to the
external survey",
"ext-quicksurveys-example-external-survey-description": "description of
the example survey",
+ "ext-quicksurveys-example-external-survey-privacy-policy-link": "Web
link to the privacy policy",
"ext-quicksurveys-example-external-survey-privacy-policy-text": "text
of the privacy policy link\n{{Identical|Privacy policy}}"
}
diff --git a/includes/QuickSurveys.hooks.php b/includes/QuickSurveys.hooks.php
index 65831cf..9b339f5 100644
--- a/includes/QuickSurveys.hooks.php
+++ b/includes/QuickSurveys.hooks.php
@@ -9,6 +9,7 @@
namespace QuickSurveys;
use ConfigFactory;
+use ResourceLoader;
class Hooks {
/**
@@ -34,4 +35,66 @@
$vars['wgEnabledQuickSurveys'] = $enabledQuickSurveys;
return true;
}
+
+ /**
+ * ResourceLoaderRegisterModules hook handler
+ *
+ * Registers needed modules for enabled surveys
+ *
+ * @see
https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderRegisterModules
+ *
+ * @param ResourceLoader &$resourceLoader The ResourceLoader object
+ * @return bool Always trueregisterMobile
+ */
+ public static function onResourceLoaderRegisterModules( ResourceLoader
&$resourceLoader ) {
+ $config = ConfigFactory::getDefaultInstance()->makeConfig(
'quicksurveys' );
+ // Get configured surveys
+ $configuredSurveys = $config->has( 'QuickSurveysConfig' )
+ ? $config->get( 'QuickSurveysConfig' )
+ : array();
+
+ // Register enabled surveys as their own modules
+ foreach ( $configuredSurveys as $survey ) {
+ // ext.quicksurveys.survey.internal.example.survey
+ $surveyResourceLoaderModuleName =
'ext.quicksurveys.survey.' . str_replace( ' ', '.', $survey['name'] );
+ if ( $survey['enabled'] === true ) {
+ $surveyModule = array(
+ $surveyResourceLoaderModuleName =>
array(
+ //'dependencies' => array(
+ // TODO: Depend on
internal / external frontend modules when they exist
+ //
'ext.quicksurveys.type.' . $survey['type'],
+ //),
+ 'messages' => array(
+ $survey['description'],
+ $survey['question'],
+ ),
+ 'targets' => array( 'desktop',
'mobile' ),
+ )
+ );
+ $messagesToAdd = array();
+ // Add messages that are specific the survey
type
+ if ( $surveyModule['type'] === 'internal') {
+ $messagesToAdd = array(
+ $survey['question'],
+ $survey['answers']['positive'],
+ $survey['answers']['neutral'],
+ $survey['answers']['negative'],
+ );
+ } elseif ( $surveyModule['type'] === 'external'
) {
+ $messagesToAdd = array(
+ $survey['link'],
+ $survey['privacy-policy-link'],
+ $survey['privacy-policy-text'],
+ );
+ }
+
$surveyModule[$surveyResourceLoaderModuleName]['messages'] += $messagesToAdd;
+
+ // Regsiter the module
+ $resourceLoader->register( $surveyModule );
+ }
+ }
+
+ return true;
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/232210
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8ab993130bf3fe60de461ecdcff66b494281c310
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/QuickSurveys
Gerrit-Branch: master
Gerrit-Owner: Robmoen <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits