Bmansurov has uploaded a new change for review. https://gerrit.wikimedia.org/r/269351
Change subject: Add URL parameter for external surveys ...................................................................... Add URL parameter for external surveys Bug: T124511 Change-Id: Ib39422da8cbe7553fb3112ed88f2a6c453326d1e --- M extension.json M includes/ExternalSurvey.php M includes/SurveyFactory.php M resources/ext.quicksurveys.views/ExternalSurvey.js M tests/browser/LocalSettings.php 5 files changed, 34 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/QuickSurveys refs/changes/51/269351/1 diff --git a/extension.json b/extension.json index 0cbead6..5558026 100644 --- a/extension.json +++ b/extension.json @@ -39,6 +39,7 @@ "ext.quicksurveys.lib", "oojs-ui", "mediawiki.user", + "mediawiki.Uri", "schema.QuickSurveysResponses" ], "targets": [ @@ -167,6 +168,8 @@ "description": "ext-quicksurveys-example-external-survey-description", "@link": "external link to the survey", "link": "ext-quicksurveys-example-external-survey-link", + "@instanceTokenParameterName": "parameter to add to link", + "instanceTokenParameterName": "parameterName", "@privacyPolicy": "The i18n key of the privacy policy text.", "privacyPolicy": "ext-quicksurveys-example-external-survey-privacy-policy", "@enabled": "whether the survey is enabled", diff --git a/includes/ExternalSurvey.php b/includes/ExternalSurvey.php index a26dcb1..cea52a5 100644 --- a/includes/ExternalSurvey.php +++ b/includes/ExternalSurvey.php @@ -19,6 +19,11 @@ private $link; /** + * @var string The name of the URL parameter filled with the instance token appended to $link. + */ + private $instanceTokenParameterName; + + /** * @var string The description of the privacy policy of the website that hosts the external survey. */ private $privacyPolicy; @@ -31,18 +36,22 @@ $coverage, $platforms, $link, + $instanceTokenParameterName, $privacyPolicy ) { parent::__construct( $name, $question, $description, $isEnabled, $coverage, $platforms ); $this->name = $name; $this->link = $link; + $this->instanceTokenParameterName = $instanceTokenParameterName; $this->privacyPolicy = $privacyPolicy; $this->isInsecure = !preg_match( '/https/i', wfMessage( $this->link )->plain() ) ? true : false; } public function getMessages() { - return array_merge( parent::getMessages(), array( $this->privacyPolicy, $this->link ) ); + return array_merge( + parent::getMessages(), array( $this->privacyPolicy, $this->link ) + ); } public function toArray() { @@ -50,6 +59,7 @@ 'name' => $this->name, 'type' => 'external', 'link' => $this->link, + 'instanceTokenParameterName' => $this->instanceTokenParameterName, 'isInsecure' => $this->isInsecure, 'privacyPolicy' => $this->privacyPolicy, ); diff --git a/includes/SurveyFactory.php b/includes/SurveyFactory.php index 4da6a96..f2bc9c8 100644 --- a/includes/SurveyFactory.php +++ b/includes/SurveyFactory.php @@ -116,6 +116,10 @@ ); } + if ( !isset( $spec['instanceTokenParameterName'] ) ) { + $spec['instanceTokenParameterName'] = ""; + } + return new ExternalSurvey( $spec['name'], $spec['question'], @@ -124,6 +128,7 @@ $spec['coverage'], $spec['platforms'], $spec['link'], + $spec['instanceTokenParameterName'], $spec['privacyPolicy'] ); } diff --git a/resources/ext.quicksurveys.views/ExternalSurvey.js b/resources/ext.quicksurveys.views/ExternalSurvey.js index 2a0af0e..4f84a77 100644 --- a/resources/ext.quicksurveys.views/ExternalSurvey.js +++ b/resources/ext.quicksurveys.views/ExternalSurvey.js @@ -23,9 +23,20 @@ */ renderButtons: function () { var $btnContainer = this.initialPanel.$element.find( '.survey-button-container' ), - buttons = [ + btnHref, + buttons, + self = this; + + btnHref = new mw.Uri( mw.message( this.config.survey.link ).parse() ); + + if ( this.config.survey.instanceTokenParameterName ) { + btnHref.query[this.config.survey.instanceTokenParameterName] = + this.config.surveyInstanceToken; + } + + buttons = [ { - href: mw.message( this.config.survey.link ).parse(), + href: btnHref.toString(), target: '_blank', label: mw.msg( 'ext-quicksurveys-external-survey-yes-button' ), flags: 'constructive', @@ -39,8 +50,7 @@ answer: 'ext-quicksurveys-external-survey-no-button' } } - ], - self = this; + ]; $.each( buttons, function () { var button = new OO.ui.ButtonWidget( this ); diff --git a/tests/browser/LocalSettings.php b/tests/browser/LocalSettings.php index 7dd71ca..c345bf5 100644 --- a/tests/browser/LocalSettings.php +++ b/tests/browser/LocalSettings.php @@ -43,6 +43,7 @@ "question" => "ext-quicksurveys-example-external-survey-question", "description" => "ext-quicksurveys-example-external-survey-description", "link" => "ext-quicksurveys-example-external-survey-link", + "instanceTokenParameterName" => "parameterName", "privacyPolicy" => "ext-quicksurveys-example-external-survey-privacy-policy", "coverage" => .5, "enabled" => true, -- To view, visit https://gerrit.wikimedia.org/r/269351 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib39422da8cbe7553fb3112ed88f2a6c453326d1e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/QuickSurveys Gerrit-Branch: master Gerrit-Owner: Bmansurov <bmansu...@wikimedia.org> Gerrit-Reviewer: Nschaaf <nsch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits