This question about Using an extension: Answered

javascript processing

We have been using TWiki and PublishContrib to manage our public website (see http://www.lepp.cornell.edu), and are attempting to upgrade to Foswiki 1.1.5 and the latest PublishPlugin. With this upgrade, our one piece of javascript is no longer rendered properly.

On our home page, we use the following javascript to rotate through images:

<script language="Javascript">
<!--
image = new Array(4);
link = new Array(4);
image[0] = "cms.jpg";
link[0] = "./Research/EPP/CMS/";
image[1] = "control.jpg";
link[1] = "./Research/AP/CESR/";
image[2] = "ilc.jpg";
link[2] = "./Research/AP/ILC/";
image[3] = "erl.jpg";
link[3] = "./Research/AP/ERL/";
image[4] = "edu_outreach.jpg";
link[4] = "./Education/";
image[5] = "CLEO_Exp.jpg";
link[5] = "./Research/EPP/CLEO/";
index = Math.floor(Math.random() * image.length);
document.write("<p><a href='" + link[index] + "'><img border='0' src='/pub/Support/Question1077/" + image[index] + "' width='365' height='168' /></a></p>");
//-->
</script>

After upgrading, we see the following errors when trying to publish this page:

ERROR: /mnt/wiki/foswiki/pub/LEPP/WebHome/" + image[index] + " is not readable
ERROR: MISSING RESOURCE LEPP/WebHome/" + image[index] + "

And the javascript in the published page becomes:

<script language="Javascript">
<!--
image = new Array(4);
link  = new Array(4);
image[0] = "cms.jpg";
 link[0] = "./Research/EPP/CMS/";
image[1] = "control.jpg";
 link[1] = "./Research/AP/CESR/";
image[2] = "ilc.jpg";
 link[2] = "./Research/AP/ILC/";
image[3] = "erl.jpg";
 link[3] = "./Research/AP/ERL/";
image[4] = "edu_outreach.jpg";
 link[4] = "./Education/";
image[5] = "CLEO_Exp.jpg";
 link[5] = "./Research/EPP/CLEO/";
index = Math.floor(Math.random() * image.length);
document.write("<p><a href='" + link[index] + "'><img border='0' src='../MISSING RESOURCE LEPP/WebHome/" + image[index] + "' width='365' height='168' /></a></p>");
//-->
</script>

The published page looks correct if I change the code from:

src='%ATTACHURLPATH%/" + image[index] + "'

to: src='rsrc/LEPP/WebHome/" + image[index] + "'

However, then the wiki version does not render the images. Is there any chance of getting this behavior changed in PublishPlugin (we don't see the "problem" with PublishContrib version 17710)?

-- DevinBougie - 23 Apr 2012

With the way the PublishPlugin works, it looks like we're better off giving it paths it can interpret as a complete resource path, rather than assembling the resource path out of string operators. This means a bunch of extra ATTACHURLPATH strings, but it looks like this will keep the plugin happier.

With the following rewrite:

var image = [
       [ "%ATTACHURLPATH%/cms.jpg",          "./Research/EPP/CMS/"  ],
       [ "%ATTACHURLPATH%/control.jpg",      "./Research/AP/CESR/"  ],
       [ "%ATTACHURLPATH%/ilc.jpg",          "./Research/AP/ILC/"   ],
       [ "%ATTACHURLPATH%/erl.jpg",          "./Research/AP/ERL/"   ],
       [ "%ATTACHURLPATH%/edu_outreach.jpg", "./Education/"         ],
       [ "%ATTACHURLPATH%/CLEO_Exp.jpg",     "./Research/EPP/CLEO/" ]
];
var index = Math.floor(Math.random() * image.length);
document.write("<p><a href='" + image[index][1] + "'><img border='0' src='" + image[index][0] + "' width='365' height='168' /></a></p>");

PublishPlugin breaks the document.write by turning it into:
document.write("<p><a href='" + image[index][1] + "'><img border='0' src='../../mnt/leppwwwwiki/Foswiki-1.1.8/bin/" + image[index][0] + "' width='365' height='168' /></a></p>");

instead of:
document.write("<p><a href='" + image[index][1] + "'><img border='0' src='" + image[index][0] + "' width='365' height='168' /></a></p>");

-- DevinBougie - 29 Apr 2013

And finally, an ugly workaround is to change the document.write in the script so that it doesn't match the regexp looking for 'img src='.

In total, that makes the final working script:

var image = [
       [ "%ATTACHURLPATH%/cms.jpg",          "./Research/EPP/CMS/"  ],
       [ "%ATTACHURLPATH%/control.jpg",      "./Research/AP/CESR/"  ],
       [ "%ATTACHURLPATH%/ilc.jpg",          "./Research/AP/ILC/"   ],
       [ "%ATTACHURLPATH%/erl.jpg",          "./Research/AP/ERL/"   ],
       [ "%ATTACHURLPATH%/edu_outreach.jpg", "./Education/"         ],
       [ "%ATTACHURLPATH%/CLEO_Exp.jpg",     "./Research/EPP/CLEO/" ]
];
var index = Math.floor(Math.random() * image.length);
document.write("<p><a href='" + image[index][1] + "'><img border='0' s" + "rc='" + image[index][0] + "' width='365' height='168' /></a></p>");

-- DevinBougie - 29 Apr 2013

Good detective work. The PublshPlugin was "improved" to be more aggressive in finding mappable URLs, as that was a frequent request; you have demonstrated the risks inherent in this.

-- CrawfordCurrie - 30 Apr 2013

QuestionForm edit

Subject Using an extension
Extension PublishPlugin
Version Foswiki 1.1.8
Status Answered
Related Topics
Topic revision: r3 - 30 Apr 2013, CrawfordCurrie
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