Jdlrobson has uploaded a new change for review.

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

Change subject: Assert that external surveys are in https in JavaScript
......................................................................

Assert that external surveys are in https in JavaScript

This allows better debugging and avoids throwing exceptions in the
tautology of the language code being qqx

Bug: T114485
Change-Id: I6b087f4349f6f2646646c7d8d3907af690d5bdab
---
M extension.json
M includes/SurveyFactory.php
M resources/ext.quicksurveys.lib/lib.js
3 files changed, 19 insertions(+), 9 deletions(-)


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

diff --git a/extension.json b/extension.json
index 157fc55..d3b7eea 100644
--- a/extension.json
+++ b/extension.json
@@ -129,7 +129,6 @@
                ]
        },
        "config": {
-               "QuickSurveysRequireHttps": true,
                "QuickSurveysConfig": [
                        {
                                "@name": "survey name",
diff --git a/includes/SurveyFactory.php b/includes/SurveyFactory.php
index 8a255af..9db3d94 100644
--- a/includes/SurveyFactory.php
+++ b/includes/SurveyFactory.php
@@ -69,12 +69,6 @@
                }
 
                $config = ConfigFactory::getDefaultInstance()->makeConfig( 
'quicksurveys' );
-               if (
-                       $config->get( 'QuickSurveysRequireHttps' ) &&
-                       !preg_match( '/https/i', wfMessage( $spec['link'] ) )
-               ) {
-                       throw new InvalidArgumentException( "The \"{$name}\" 
external survey link requires https." );
-               }
 
                if ( !isset( $spec['privacyPolicy'] ) ) {
                        throw new InvalidArgumentException(
diff --git a/resources/ext.quicksurveys.lib/lib.js 
b/resources/ext.quicksurveys.lib/lib.js
index 1b9c58c..d504b12 100644
--- a/resources/ext.quicksurveys.lib/lib.js
+++ b/resources/ext.quicksurveys.lib/lib.js
@@ -37,6 +37,22 @@
        }
 
        /**
+        * Check is a survey is valid.
+        * Throws warning when not.
+        *
+        * @param {Object} survey options
+        */
+       function isValidSurvey( survey ) {
+               if ( survey.type === 'external' ) {
+                       if ( survey.link.indexOf( 'https' ) === -1 ) {
+                               mw.log.warn( 'QuickSurvey with name ' + 
survey.name + ' has insecure survey link and will not be shown.' );
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       /**
         * Show survey
         *
         * @param {jQuery.Object} $bodyContent to add the panel
@@ -55,13 +71,14 @@
                                        mw.util.getParamValue( 'quicksurvey' ) 
|| '',
                                        enabledSurveys
                                );
-                               if ( enabledSurvey ) {
+                               if ( enabledSurvey && isValidSurvey( 
enabledSurvey ) ) {
                                        availableSurveys.push( enabledSurvey );
                                }
                                return false;
                        } else if (
                                getSurveyToken( enabledSurvey ) !== '~' &&
-                               getBucketForSurvey( enabledSurvey ) === 'A'
+                               getBucketForSurvey( enabledSurvey ) === 'A' &&
+                               isValidSurvey( enabledSurvey )
                        ) {
                                availableSurveys.push( enabledSurvey );
                        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b087f4349f6f2646646c7d8d3907af690d5bdab
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/QuickSurveys
Gerrit-Branch: dev
Gerrit-Owner: Jdlrobson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to