Paladox has uploaded a new change for review.

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

Change subject: Replace usage of addScript with addModules
......................................................................

Replace usage of addScript with addModules

This fully removes support for mediawiki 1.26.

Change-Id: I2689135eb954f79a5ab868df88fbbba8cfbcc11e
---
M SemanticForms.php
M extension.json
M includes/SF_PageSchemas.php
A libs/SF_CreateProperty.js
A libs/SF_CreateTemplate.js
A libs/SF_PageSchemas.js
M specials/SF_CreateProperty.php
M specials/SF_CreateTemplate.php
M specials/SF_UploadWindow.php
9 files changed, 126 insertions(+), 108 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticForms 
refs/changes/88/258688/1

diff --git a/SemanticForms.php b/SemanticForms.php
index 46dbf45..3079dd1 100644
--- a/SemanticForms.php
+++ b/SemanticForms.php
@@ -122,7 +122,10 @@
 $GLOBALS['wgHooks']['ArticlePurge'][] = 'SFFormUtils::purgeCache';
 $GLOBALS['wgHooks']['ArticleSave'][] = 'SFFormUtils::purgeCache';
 $GLOBALS['wgHooks']['ParserFirstCallInit'][] = 
'SFParserFunctions::registerFunctions';
-$GLOBALS['wgHooks']['MakeGlobalVariablesScript'][] = 
'SFFormUtils::setGlobalJSVariables';
+$GLOBALS['wgHooks']['MakeGlobalVariablesScript'][] = array(
+       'SFFormUtils::setGlobalJSVariables',
+       'SFUploadWindow::addUploadJS'
+);
 $GLOBALS['wgHooks']['PageSchemasRegisterHandlers'][] = 
'SFPageSchemas::registerClass';
 $GLOBALS['wgHooks']['EditPage::importFormData'][] = 'SFUtils::showFormPreview';
 $GLOBALS['wgHooks']['CanonicalNamespaces'][] = 'SFUtils::registerNamespaces';
@@ -357,6 +360,21 @@
                        'libs/ext.sf.js',
                ),
        ),
+       'SF_CreateProperty' => $sfgResourceTemplate + array(
+               'scripts' => array(
+                       'libs/SF_CreateProperty.js',
+               ),
+       ),
+       'SF_PageSchemas' => $sfgResourceTemplate + array(
+               'scripts' => array(
+                       'libs/SF_PageSchemas.js',
+               ),
+       ),
+       'SF_CreateTemplate' => $sfgResourceTemplate + array(
+               'scripts' => array(
+                       'libs/SF_CreateTemplate.js',
+               ),
+       ),
 );
 
 // PHP fails to find relative includes at some level of inclusion:
diff --git a/extension.json b/extension.json
index 5a2543f..b9cce66 100644
--- a/extension.json
+++ b/extension.json
@@ -242,6 +242,21 @@
                        "scripts": [
                                "libs/ext.sf.js"
                        ]
+               },
+               "SF_CreateProperty": {
+                       "scripts": [
+                               "libs/SF_CreateProperty.js"
+                       ]
+               },
+               "SF_PageSchemas": {
+                       "scripts": [
+                               "libs/SF_PageSchemas.js"
+                       ]
+               },
+               "SF_CreateTemplate": {
+                       "scripts": [
+                               "libs/SF_CreateTemplate.js"
+                       ]
                }
        },
        "ResourceFileModulePaths": {
@@ -273,7 +288,8 @@
                        "SFParserFunctions::registerFunctions"
                ],
                "MakeGlobalVariablesScript": [
-                       "SFFormUtils::setGlobalJSVariables"
+                       "SFFormUtils::setGlobalJSVariables",
+                       "SFUploadWindow::addUploadJS"
                ],
                "PageSchemasRegisterHandlers": [
                        "SFPageSchemas::registerClass"
diff --git a/includes/SF_PageSchemas.php b/includes/SF_PageSchemas.php
index e465b39..202c730 100644
--- a/includes/SF_PageSchemas.php
+++ b/includes/SF_PageSchemas.php
@@ -373,28 +373,10 @@
                $text .= "</p>";
                $text .= "</div>\n";
 
+               global $wgOut;
                // Separately, add Javascript for getting the checkbox to
                // hide certain fields.
-               $jsText = <<<END
-<script type="text/javascript">
-jQuery.fn.toggleFormDataDisplay = function() {
-       if (jQuery(this).is(":checked")) {
-               jQuery('#sf-page-name-formula').css('display', 'none');
-               jQuery('#sf-edit-title').css('display', 'block');
-       } else {
-               jQuery('#sf-page-name-formula').css('display', 'block');
-               jQuery('#sf-edit-title').css('display', 'none');
-       }
-}
-jQuery('#sf-two-step-process').toggleFormDataDisplay();
-jQuery('#sf-two-step-process').click( function() {
-       jQuery(this).toggleFormDataDisplay();
-} );
-</script>
-
-END;
-               global $wgOut;
-               $wgOut->addScript( $jsText );
+               $wgOut->addModules( array( 'SF_PageSchemas' ) );
 
                return array( $text, $hasExistingValues );
        }
diff --git a/libs/SF_CreateProperty.js b/libs/SF_CreateProperty.js
new file mode 100644
index 0000000..22abc8d
--- /dev/null
+++ b/libs/SF_CreateProperty.js
@@ -0,0 +1,22 @@
+function toggleDefaultForm(property_type) {
+       var default_form_div = document.getElementById("default_form_div");
+       if (property_type == '$pageTypeLabel') {
+               default_form_div.style.display = "";
+       } else {
+               default_form_div.style.display = "none";
+       }
+}
+
+function toggleAllowedValues(property_type) {
+       var allowed_values_div = document.getElementById("allowed_values");
+       // Page, String (or Text, for SMW 1.9+), Number, Email - is that a
+       // reasonable set of types for which enumerations should be allowed?
+       if (property_type == '$pageTypeLabel' ||
+               property_type == '$stringTypeLabel' ||
+               property_type == '$numberTypeLabel' ||
+               property_type == '$emailTypeLabel') {
+               allowed_values_div.style.display = "";
+       } else {
+               allowed_values_div.style.display = "none";
+       }
+}
diff --git a/libs/SF_CreateTemplate.js b/libs/SF_CreateTemplate.js
new file mode 100644
index 0000000..2c14340
--- /dev/null
+++ b/libs/SF_CreateTemplate.js
@@ -0,0 +1,41 @@
+var fieldNum = 1;
+function createTemplateAddField() {
+       fieldNum++;
+       newField = jQuery('#starterField').clone().css('display', 
'').removeAttr('id');
+       newHTML = newField.html().replace(/starter/g, fieldNum);
+       newField.html(newHTML);
+       newField.find(".deleteField").click( function() {
+               // Remove the encompassing div for this instance.
+               jQuery(this).closest(".fieldBox")
+                       .fadeOut('fast', function() { jQuery(this).remove(); });
+       });
+       newField.find(".isList").click( function() {
+               jQuery(this).closest(".fieldBox").find(".delimiter").toggle();
+       });
+       var combobox = new sf.select2.combobox();
+       combobox.apply($(newField.find('.sfComboBox')));
+       jQuery('#fieldsList').append(newField);
+}
+
+function validateCreateTemplateForm() {
+       templateName = jQuery('#template_name').val();
+       if (templateName === '') {
+               scroll(0, 0);
+               jQuery('#template_name_p').append(' <font 
color="red">$template_name_error_str</font>');
+               return false;
+       } else {
+               return true;
+       }
+}
+
+jQuery(document).ready(function() {
+       jQuery(".deleteField").click( function() {
+               // Remove the encompassing div for this instance.
+               jQuery(this).closest(".fieldBox")
+                       .fadeOut('fast', function() { jQuery(this).remove(); });
+       });
+       jQuery(".isList").click( function() {
+               jQuery(this).closest(".fieldBox").find(".delimiter").toggle();
+       });
+       jQuery('#createTemplateForm').submit( function() { return 
validateCreateTemplateForm(); } );
+});
diff --git a/libs/SF_PageSchemas.js b/libs/SF_PageSchemas.js
new file mode 100644
index 0000000..b58bbe8
--- /dev/null
+++ b/libs/SF_PageSchemas.js
@@ -0,0 +1,13 @@
+jQuery.fn.toggleFormDataDisplay = function() {
+       if (jQuery(this).is(":checked")) {
+               jQuery('#sf-page-name-formula').css('display', 'none');
+               jQuery('#sf-edit-title').css('display', 'block');
+       } else {
+               jQuery('#sf-page-name-formula').css('display', 'block');
+               jQuery('#sf-edit-title').css('display', 'none');
+       }
+}
+jQuery('#sf-two-step-process').toggleFormDataDisplay();
+jQuery('#sf-two-step-process').click( function() {
+       jQuery(this).toggleFormDataDisplay();
+} );
diff --git a/specials/SF_CreateProperty.php b/specials/SF_CreateProperty.php
index a2cea3a..1d866ce 100644
--- a/specials/SF_CreateProperty.php
+++ b/specials/SF_CreateProperty.php
@@ -113,32 +113,6 @@
                $numberTypeLabel = $datatypeLabels['_num'];
                $emailTypeLabel = $datatypeLabels['_ema'];
 
-               $javascript_text = <<<END
-function toggleDefaultForm(property_type) {
-       var default_form_div = document.getElementById("default_form_div");
-       if (property_type == '$pageTypeLabel') {
-               default_form_div.style.display = "";
-       } else {
-               default_form_div.style.display = "none";
-       }
-}
-
-function toggleAllowedValues(property_type) {
-       var allowed_values_div = document.getElementById("allowed_values");
-       // Page, String (or Text, for SMW 1.9+), Number, Email - is that a
-       // reasonable set of types for which enumerations should be allowed?
-       if (property_type == '$pageTypeLabel' ||
-               property_type == '$stringTypeLabel' ||
-               property_type == '$numberTypeLabel' ||
-               property_type == '$emailTypeLabel') {
-               allowed_values_div.style.display = "";
-       } else {
-               allowed_values_div.style.display = "none";
-       }
-}
-
-END;
-
                global $wgContLang;
                $mw_namespace_labels = $wgContLang->getNamespaces();
                $name_label = wfMessage( 'sf_createproperty_propname' 
)->escaped();
@@ -183,7 +157,7 @@
                $text .= "\t" . Html::rawElement( 'div', array( 'class' => 
'editButtons' ), $edit_buttons ) . "\n";
                $text .= "\t</form>\n";
 
-               $out->addScript( '<script type="text/javascript">' . 
$javascript_text . '</script>' );
+               $out->addModules( array( 'SF_CreateProperty' ) );
                $out->addHTML( $text );
        }
 
diff --git a/specials/SF_CreateTemplate.php b/specials/SF_CreateTemplate.php
index b4eba30..0204b2e 100644
--- a/specials/SF_CreateTemplate.php
+++ b/specials/SF_CreateTemplate.php
@@ -140,53 +140,8 @@
        function addJavascript() {
                // TODO - this should be in a JS file
                $template_name_error_str = wfMessage( 'sf_blank_error' 
)->escaped();
-               $jsText =<<<END
-<script type="text/javascript">
-var fieldNum = 1;
-function createTemplateAddField() {
-       fieldNum++;
-       newField = jQuery('#starterField').clone().css('display', 
'').removeAttr('id');
-       newHTML = newField.html().replace(/starter/g, fieldNum);
-       newField.html(newHTML);
-       newField.find(".deleteField").click( function() {
-               // Remove the encompassing div for this instance.
-               jQuery(this).closest(".fieldBox")
-                       .fadeOut('fast', function() { jQuery(this).remove(); });
-       });
-       newField.find(".isList").click( function() {
-               jQuery(this).closest(".fieldBox").find(".delimiter").toggle();
-       });
-       var combobox = new sf.select2.combobox();
-       combobox.apply($(newField.find('.sfComboBox')));
-       jQuery('#fieldsList').append(newField);
-}
 
-function validateCreateTemplateForm() {
-       templateName = jQuery('#template_name').val();
-       if (templateName === '') {
-               scroll(0, 0);
-               jQuery('#template_name_p').append(' <font 
color="red">$template_name_error_str</font>');
-               return false;
-       } else {
-               return true;
-       }
-}
-
-jQuery(document).ready(function() {
-       jQuery(".deleteField").click( function() {
-               // Remove the encompassing div for this instance.
-               jQuery(this).closest(".fieldBox")
-                       .fadeOut('fast', function() { jQuery(this).remove(); });
-       });
-       jQuery(".isList").click( function() {
-               jQuery(this).closest(".fieldBox").find(".delimiter").toggle();
-       });
-       jQuery('#createTemplateForm').submit( function() { return 
validateCreateTemplateForm(); } );
-});
-</script>
-
-END;
-               $this->getOutput()->addScript( $jsText );
+               $this->getOutput()->addModules( array( 'SF_CreateTemplate' ) );
        }
 
        static function printTemplateStyleButton( $formatStr, $formatMsg, 
$htmlFieldName, $curSelection ) {
diff --git a/specials/SF_UploadWindow.php b/specials/SF_UploadWindow.php
index 3b9d8a1..aed23e0 100644
--- a/specials/SF_UploadWindow.php
+++ b/specials/SF_UploadWindow.php
@@ -957,7 +957,6 @@
         * Add the upload JS and show the form.
         */
        public function show() {
-               $this->addUploadJS();
                parent::show();
                // disable output - we'll print out the page manually,
                // taking the body created by the form, plus the necessary
@@ -1009,24 +1008,22 @@
         * @param bool $autofill Whether or not to autofill the destination
         *      filename text box
         */
-       protected function addUploadJS( $autofill = true ) {
+       public static function addUploadJS( &$vars, $autofill = true ) {
                global $wgUseAjax, $wgAjaxUploadDestCheck, 
$wgAjaxLicensePreview;
                global $wgStrictFileExtensions, $wgMaxUploadSize;
 
-               $scriptVars = array(
-                       'wgAjaxUploadDestCheck' => $wgUseAjax && 
$wgAjaxUploadDestCheck,
-                       'wgAjaxLicensePreview' => $wgUseAjax && 
$wgAjaxLicensePreview,
-                       'wgUploadAutoFill' => (bool)$autofill &&
+               $vars['wgAjaxUploadDestCheck'] = $wgUseAjax && 
$wgAjaxUploadDestCheck;
+               $vars['wgAjaxLicensePreview'] = $wgUseAjax && 
$wgAjaxLicensePreview;
+               $vars['wgUploadAutoFill'] = (bool)$autofill &&
                                // If we received mDestFile from the request, 
don't autofill
                                // the wpDestFile textbox
-                               $this->mDestFile === '',
-                       'wgUploadSourceIds' => $this->mSourceIds,
-                       'wgStrictFileExtensions' => $wgStrictFileExtensions,
-                       'wgCapitalizeUploads' => MWNamespace::isCapitalized( 
NS_FILE ),
-                       'wgMaxUploadSize' => $wgMaxUploadSize,
-               );
+                               $this->mDestFile === '';
+               $vars['wgUploadSourceIds'] = $this->mSourceIds;
+               $vars['wgStrictFileExtensions'] = $wgStrictFileExtensions;
+               $vars['wgCapitalizeUploads'] = MWNamespace::isCapitalized( 
NS_FILE );
+               $vars['wgMaxUploadSize'] = $wgMaxUploadSize;
 
-               $this->getOutput()->addScript( Skin::makeVariablesScript( 
$scriptVars ) );
+               return true;
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2689135eb954f79a5ab868df88fbbba8cfbcc11e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticForms
Gerrit-Branch: master
Gerrit-Owner: Paladox <[email protected]>

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

Reply via email to