Item14388: NatEditPlugin does not honor the ScriptSuffix setting, and doesn't accommodate short URLs.

pencil
Priority: Urgent
Current State: Closed
Released In: 2.1.4
Target Release: patch
Applies To: Extension
Component: NatEditPlugin
Branches: Release02x01 master Item14288
Reported By: GeorgeClark
Waiting For: MichaelDaum
Last Change By: GeorgeClark
The javascript is hardcoded for /rest/NatEditPlugin/... and fails on Windows or other platforms where the scripts have to be renamed to enable CGI.

-- GeorgeClark - 02 May 2017

System/NatEditPlugin/jquery.natedit.js:
 url = self.opts.scriptUrl+"/rest/JQueryPlugin/tmpl?topic="+self.opts.web+"."+self.opts.topic+"&load="+self.opts.toolbar;
 url: self.opts.scriptUrl + '/rest/NatEditPlugin/save', // SMELL: use this one for REST as long as the normal save can't cope with REST
 url: self.opts.scriptUrl + '/rest/NatEditPlugin/save', // SMELL: use this one for REST as long as the normal save can't cope with REST
 opts.url = self.opts.scriptUrl+"/rest/JQueryPlugin/tmpl?topic="+self.opts.web+"."+self.opts.topic+"&load=editdialog&name="+opts.name;
 url: self.opts.scriptUrl+"/rest/NatEditPlugin/attachments",

All of these (at least) need to support the ScriptSuffix setting.

Shouldn't they be using the base function foswiki.getScriptUrl = function(script, web, topic, params) provided by jquery.foswiki.js?

-- GeorgeClark - 02 May 2017

The simple fix - adding self.opts.scriptSuffix is easy enough. But in reviewing the code, it also doesn't take into account Short URLs. which means that on many sites, "view" requests are going to end up redirecting.

This really ought to be changed to use the jquery utility, getScripturl, which handles both Short URLs and ScriptSuffix.

-- GeorgeClark - 02 May 2017

Confirmed that the AjaxHelper used in the Link button is getting a 302 redirect on sites running short URls. The following patch seems to resolve the redirecting and probably fixes the script suffix.
diff --git a/NatEditPlugin/pub/System/NatEditPlugin/jquery.natedit.uncompressed.js b/NatEditPlugin/pub/System/NatEditPlugin/jquery.natedit.uncompressed.js
index bc6a2c0..152573f 100644
--- a/NatEditPlugin/pub/System/NatEditPlugin/jquery.natedit.uncompressed.js
+++ b/NatEditPlugin/pub/System/NatEditPlugin/jquery.natedit.uncompressed.js
@@ -482,7 +482,8 @@ $.NatEditor.prototype.initGui = function() {
     onDeselect: updateDetails,
     onClear: updateDetails,
     onReset: updateDetails,
-    autocomplete: self.opts.scriptUrl + "/view/" + self.opts.systemWeb + "/JQueryAjaxHelper?section=user;skin=text;contenttype=application/json"
+    autocomplete: foswiki.getScriptUrl('view', self.opts.systemWeb, 'JQueryAjaxHelper') + "?section=user;skin=text;contenttype=application/json"
+
   });
 
   function setPermissionSet(data) {
@@ -533,7 +534,7 @@ $.NatEditor.prototype.switchToWYSIWYG = function(ev) {
 $.NatEditor.prototype.initToolbar = function() {
   var self = this, 
       $txtarea = $(self.txtarea),
-      url = self.opts.scriptUrl+"/rest/JQueryPlugin/tmpl?topic="+self.opts.web+"."+self.opts.topic+"&load="+self.opts.toolbar;
+      url = foswiki.getScriptUrl('rest', "JQueryPlugin", "tmpl")+"?topic="+self.opts.web+"."+self.opts.topic+";load="+self.opts.toolbar;
 
   // load toolbar
   $.loadTemplate({
@@ -910,7 +911,7 @@ $.NatEditor.prototype.initForm = function() {
             self.form.submit();
           } else {
             self.form.ajaxSubmit({
-              url: self.opts.scriptUrl + '/rest/NatEditPlugin/save', // SMELL: use this one for REST as long as the normal save can't cope with REST
+              url: foswiki.getScriptUrl( 'rest', 'NatEditPlugin', 'save'),  // SMELL: use this one for REST as long as the normal save can't cope with REST
               beforeSubmit: function() {
                 self.hideMessages();
                 document.title = "Saving ...";
@@ -961,7 +962,7 @@ $.NatEditor.prototype.initForm = function() {
       self.beforeSubmit("preview");
 
       self.form.ajaxSubmit({
-        url: self.opts.scriptUrl + '/rest/NatEditPlugin/save', // SMELL: use this one for REST as long as the normal save can't cope with REST
+        url: foswiki.getScriptUrl( 'rest', 'NatEditPlugin', 'save'),  // SMELL: use this one for REST as long as the normal save can't cope with REST
         beforeSubmit: function() {
           self.hideMessages();
           $.blockUI({
@@ -1849,7 +1850,7 @@ $.NatEditor.prototype.dialog = function(opts) {
   }
 
   if (typeof(opts.url) === 'undefined' && typeof(opts.name) !== 'undefined') {
-    opts.url = self.opts.scriptUrl+"/rest/JQueryPlugin/tmpl?topic="+self.opts.web+"."+self.opts.topic+"&load=editdialog&name="+opts.name;
+    opts.url = foswiki.getScriptUrl( 'rest', 'JQueryPlugin', 'tmpl')+"?topic="+self.opts.web+"."+self.opts.topic+";load=editdialog;name="+opts.name;
   }
 
   opts = $.extend({}, defaults, opts);
@@ -2280,7 +2281,7 @@ $.NatEditor.prototype.initLinkDialog = function(elem, data) {
 
   $dialog.find("input[name='web']").each(function() {
     $(this).autocomplete({
-      source: self.opts.scriptUrl+"/view/"+self.opts.systemWeb+"/JQueryAjaxHelper?section=web&skin=text&contenttype=application/json"
+      source: foswiki.getScriptUrl('view', self.opts.systemWeb, 'JQueryAjaxHelper')+"?section=web;skin=text;contenttype=application/json"
     });
   });
 
@@ -2291,7 +2292,7 @@ $.NatEditor.prototype.initLinkDialog = function(elem, data) {
           xhr.abort();
         }
         xhr = $.ajax({
-          url: self.opts.scriptUrl+"/view/"+self.opts.systemWeb+"/JQueryAjaxHelper",
+          url: foswiki.getScriptUrl('view', self.opts.systemWeb, 'JQueryAjaxHelper'),
           data: $.extend(request, {
             section: 'topic',
             skin: 'text',
@@ -2324,9 +2325,10 @@ $.NatEditor.prototype.initLinkDialog = function(elem, data) {
           xhr.abort();
         }
         xhr = $.ajax({
-          url: self.opts.scriptUrl+"/rest/NatEditPlugin/attachments",
+          url: foswiki.getScriptUrl('rest', 'NatEditPlugin', 'attachments'),
           data: $.extend(request, {
-            topic: $container.find("input[name='web']").val()+'.'+$container.find("input[name='topic']").val()
+            // The topic autocomplete actually returns the Web.Topic
+            topic: $container.find("input[name='topic']").val()
           }),
           dataType: "json",
           autocompleteRequest: ++requestIndex,
@@ -2633,7 +2635,6 @@ $(function() {
   $.NatEditor.defaults.web = foswiki.getPreference("WEB");
   $.NatEditor.defaults.topic = foswiki.getPreference("TOPIC");
   $.NatEditor.defaults.systemWeb = foswiki.getPreference("SYSTEMWEB");
-  $.NatEditor.defaults.scriptUrl = foswiki.getPreference("SCRIPTURL");
   $.NatEditor.defaults.pubUrl = foswiki.getPreference("PUBURL");
   $.NatEditor.defaults.signatureMarkup = ['-- ', '[['+foswiki.getPreference("WIKIUSERNAME")+']]', ' - '+foswiki.getPreference("SERVERTIME")];
 

-- GeorgeClark - 02 May 2017

A couple of more observations / issues
  • The Insert attachment link, Web autofill requires FlexWebListPlugin
  • Same dialog, the Topic autofill actually selects Topic.Web
  • And the Attachment autofill searches for Web.Web.Topic - duplicating the web.

The above patch also fixes the web.web.topic - duplicated Web.

-- GeorgeClark - 02 May 2017

foswiki.getScriptUrl should be used like this:

foswiki.getScriptUrl("script", "web", "topic", {
 "param1": "value1",
 "param2": "value2",
 "param3": "value3"
});

-- MichaelDaum - 03 May 2017
 
Topic revision: r9 - 01 Jun 2017, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy