• Do not register here on develop.twiki.org, login with your twiki.org account.
• Use View topic Item7848 for generic doc work for TWiki-6.1.1. Use View topic Item7851 for doc work on extensions that are not part of a release. More... Close
• Anything you create or change in standard webs (Main, TWiki, Sandbox etc) will be automatically reverted on every SVN update.
Does this site look broken?. Use the LitterTray web for test cases.

Item5627: Image and Attachment references are trashed when using short URLs

Item Form Data

AppliesTo: Component: Priority: CurrentState: WaitingFor: TargetRelease ReleasedIn
Extension TinyMCEPlugin Low Closed   patch 4.2.1, 5.0.0

Edit Form Data

Summary:
Reported By:
Codebase:
Applies To:
Component:
Priority:
Current State:
Waiting For:
Target Release:
Released In:
 

Detail

When using extra-short URLs of the form http://domain/SomeWikiPage in TWiki (with an implied default web of SomeWeb), the TinyMCE plugin mangles image and attachment URLs. This is because in this case VIEWSCRIPTURL is just http://domain/ instead of http://domain/twiki/bin/view/, so the view URL alone is not enough to distinguish that a particular link is a view link. The result is that non-view links such as "http://domain/pub/SomeWeb/MyPage/file.txt" are incorrectly shortened to "pub.SomeWeb.MyPage.file.txt". The following change adds a check to ensure that the page name following the view URL begins with an upper-case character; this is usually sufficient to determine that http://domain/pub/SomeWeb/MyPage is not a view link, while correctly interpreting http://domain/MyPage as a view link. This change should not affect URL parsing in the normal (unshortened) case.

Since all legal WikiNames begin with an uppercase alpha character, this should be safe. If it turns out not to be safe on some site, the appropriate fix is probably to check the string immediately following the matched VIEWSCRIPTURL against "bin/" and "pub/" - the only two commonly exposed non-page/non-web URLs in an extra-short URL twiki install, and fail the VIEWSCRIPTURL test if either is present.

There's probably a better way to do this, but I don't write a lot of JS.

In convertLink, on or around line 250 of twiki_tiny_src.js, change:

            if (url.indexOf(vsu + '/') == 0) { ...to...             if (url.indexOf(vsu + '/') == 0                 && url.charAt(vsu.length+1)>='A'                 && url.charAt(vsu.length+1)<='Z') { 

-- TWiki:Main/DavidORiva - 14 May 2008

this is usually sufficient - unfortunately not. I have several sites where lower-case topic names are not unusual (though not the norm). Also, on UTF8 sites [A-Z] is not sufficient to identify an upper-case character.

Any ideas for a smarter solution? In the worst case we could always provide a config switch to disable the replacement on short-url sites.

-- TWiki:Main.CrawfordCurrie - 14 May 2008

How 'bout the second approach above, then? Something like:

if( url.indexOf( vsu+'/' ) == 0 )<br>{
if( vsu.indexOf( "/bin/view" ) >= 0 || ( url.indexOf("/bin/")!=vsu.length && url.indexOf("/pub/")!=vsu.length ) || url.indexOf("/bin/view/")==vsu.length ) {
... extra check for /bin/view/ after shortened URL ...
... transform to Web.Page ...
   }
}
Thus, if /bin/view is in the VIEWSCRIPTURL, it always acts exactly the way it does now. Otherwise, the determination is made by checking the string immediately after the occurrence of VIEWSCRIPTURL

  • If it's /bin/view/, then it's a long view URL, which happens occasionally even when the site is configured for shorter URLs. This requires an extra check in the transform code, because the extraneous /bin/view needs to be passed over before transforming to Web.Page.
  • If it's /pub/ or /bin/, then we assume that it is not a view URL. This will break sites that use short URLs and also have viewable pages named "bin" or "pub".
  • Otherwise, the URL is assumed to represent a view URL and is transformed accordingly. There should (maybe? eventually?) be some extra work done to get the transform right if the web name isn't present in the link - that is, when the link is to the implied default web. That's not necessary to fix this bug as stated (I just wanted image link processing to not break). The "right" fix for this is almost certainly to centralize URL parsing throughout TWiki, much the same as URL generation is largely centralized to TWiki::getScriptUrl.

-- TWiki:Main.DavidORiva - 14 May 2008

Like you, I have trouble thinking of a reliable heuristic. If it were possible to rely on the {ScriptUrlPaths} then that could be passed to the plugin, and the paths matched accordingly. But there are several ways to do shorter urls, including Apache rewriting rules.

I suppose it should be possible to configure it; write a regular expression into the configuration for TinyMCEPlugin that, if defined, overrides the default rules for pattern-matching urls.

I'm marking this as confirmed, and regrading to Low as there are workarounds and it doesn't affect most of the population.

-- CrawfordCurrie - 15 May 2008

Isn't the $PubUrl setting value enough to determine that the link starts with the $PubUrl?

I say this, because if $PubUrl is in the URL, you can never have a functional web or topic called the same as $PubUrl - it would always be innaccessible, otherwise apache would not serve files..

The same fact holds true for $BinUrl

testing

-- TWiki:Main.SvenDowideit - 16 May 2008

so my patch ==

Index: twiki42/twikiplugins/TinyMCEPlugin/pub/TWiki/TinyMCEPlugin/twiki_tiny.js
===================================================================
--- twiki42/twikiplugins/TinyMCEPlugin/pub/TWiki/TinyMCEPlugin/twiki_tiny.js   (revision 16812)
+++ twiki42/twikiplugins/TinyMCEPlugin/pub/TWiki/TinyMCEPlugin/twiki_tiny.js   (working copy)
@@ -15,11 +15,11 @@
 +TWikiTiny.request.req.statusText+"</div>");});var id=editor.editorId+"_2WYSIWYG";var el=document.getElementById(id);if(el){el.style.display="none";}},saveCallback:function(editor_id,html,body){var editor=tinyMCE.getInstanceById(editor_id);for(var i=0;i<TWikiTiny.html2tml.length;i++){var cb=TWikiTiny.html2tml[i];html=cb.apply(editor,[editor,html]);}
 var secret_id=tinyMCE.getParam('twiki_secret_id');if(secret_id!=null&&html.indexOf('<!--'+secret_id+'-->')==-1){html='<!--'+secret_id+'-->'+html;}
 return html;},convertLink:function(url,node,onSave){if(onSave==null)
-onSave=false;var orig=url;var vsu=TWikiTiny.getTWikiVar("VIEWSCRIPTURL");url=TWikiTiny.expandVariables(url);if(onSave){if(url.indexOf(vsu+'/')==0){url=url.substr(vsu.length+1);url=url.replace(/\/+/g,'.');if(url.indexOf(TWikiTiny.getTWikiVar('WEB')+'.')==0){url=url.substr(TWikiTiny.getTWikiVar('WEB').length+1);}}}else{if(url.indexOf('/')==-1){var match=/^((?:\w+\.)*)(\w+)$/.exec(url);if(match!=null){var web=match[1];var topic=match[2];if(web==null||web.length==0){web=TWikiTiny.getTWikiVar("WEB");}
+onSave=false;var orig=url;var pubUrl = TWikiTiny.getTWikiVar("PUBURL");var vsu=TWikiTiny.getTWikiVar("VIEWSCRIPTURL");url=TWikiTiny.expandVariables(url);if(onSave){if((url.indexOf(pubUrl + '/') != 0)&&(url.indexOf(vsu+'/')==0)){url=url.substr(vsu.length+1);url=url.replace(/\/+/g,'.');if(url.indexOf(TWikiTiny.getTWikiVar('WEB')+'.')==0){url=url.substr(TWikiTiny.getTWikiVar('WEB').length+1);}}}else{if(url.indexOf('/')==-1){var match=/^((?:\w+\.)*)(\w+)$/.exec(url);if(match!=null){var web=match[1];var topic=match[2];if(web==null||web.length==0){web=TWikiTiny.getTWikiVar("WEB");}
 web=web.replace(/\.+/g,'/');web=web.replace(/\/+$/,'');url=vsu+'/'+web+'/'+topic;}}}
 return url;},convertPubURL:function(url){var orig=url;var base=TWikiTiny.getTWikiVar("PUBURL")+'/'
 +TWikiTiny.getTWikiVar("WEB")+'/'
 +TWikiTiny.getTWikiVar("TOPIC")+'/';url=TWikiTiny.expandVariables(url);if(url.indexOf('/')==-1){url=base+url;}
 return url;},getMetaTag:function(inKey){if(TWikiTiny.metaTags==null||TWikiTiny.metaTags.length==0){var head=document.getElementsByTagName("META");head=head[0].parentNode.childNodes;TWikiTiny.metaTags=new Array();for(var i=0;i<head.length;i++){if(head[i].tagName!=null&&head[i].tagName.toUpperCase()=='META'){TWikiTiny.metaTags[head[i].name]=head[i].content;}}}
 return TWikiTiny.metaTags[inKey];},install:function(){var tmce_init=TWikiTiny.getMetaTag('TINYMCEPLUGIN_INIT');if(tmce_init!=null){eval("tinyMCE.init({"+unescape(tmce_init)+"});");return;}
-alert("Unable to install TinyMCE; <META name='TINYMCEPLUGIN_INIT' is missing");}};
\ No newline at end of file
+alert("Unable to install TinyMCE; <META name='TINYMCEPLUGIN_INIT' is missing");}};
Index: twiki42/twikiplugins/TinyMCEPlugin/pub/TWiki/TinyMCEPlugin/twiki_tiny_src.js
===================================================================
--- twiki42/twikiplugins/TinyMCEPlugin/pub/TWiki/TinyMCEPlugin/twiki_tiny_src.js   (revision 16812)
+++ twiki42/twikiplugins/TinyMCEPlugin/pub/TWiki/TinyMCEPlugin/twiki_tiny_src.js   (working copy)
@@ -244,10 +244,12 @@
         if(onSave == null)
             onSave = false;
         var orig = url;
+        var pubUrl = TWikiTiny.getTWikiVar("PUBURL");
         var vsu = TWikiTiny.getTWikiVar("VIEWSCRIPTURL");
         url = TWikiTiny.expandVariables(url);
         if (onSave) {
-            if (url.indexOf(vsu + '/') == 0) {
+            if ((url.indexOf(pubUrl + '/') != 0) &&     //don't do a conversion if it is a pubUrl
+                (url.indexOf(vsu + '/') == 0)) {
                 url = url.substr(vsu.length + 1);
                 url = url.replace(/\/+/g, '.');
                 if (url.indexOf(TWikiTiny.getTWikiVar('WEB') + '.') == 0) {

I think $BinUrl should really also be checked in the case that we are using ShortUrls - but I'd like to confirm first that this approach is not causing something else to go splat.

Also note the extra lines - this is a diff on 4.2.0 branch, with code copied from a new twiki i installed and updated via configure - so I presume that the branch has not been kept up to date with the plugin changes.

-- SvenDowideit - 16 May 2008

The approach is right, and should work for puburls, but the problem is with scripturls, especially where the shorter url doesn't even include a web name, as David suggests. In that case you have to pattern-match against the shorter url, but you don't know what it is (because it's defined in apache) unless it is passed in. And there might be more than one shorter url that you want to match.

-- TWiki:Main.CrawfordCurrie - 16 May 2008

This is really bugging me. I vote for a higher priority. The patch WorksForMe, however. Thanks Sven.

-- TWiki:Main.JoshuaCharlesCampbell - 27 May 2008

realising that I'm unlikely to make a satisfactory fix for the binUrl, I've checked in the fix for attachments - which is really the code subject of this bug - we can re-open or open a new one when we figure out more for complex binUrl settings (personally I think if you use somethig complex in apache, you need to think hard if its worth it)

-- SvenDowideit - 01 Jun 2008

ItemTemplate
Summary Image and Attachment references are trashed when using short URLs
ReportedBy TWiki:Main.DavidORiva
Codebase 4.2.0, ~twiki4
SVN Range TWiki-5.0.0, Sun, 04 May 2008, build 16770
AppliesTo Extension
Component TinyMCEPlugin
Priority Low
CurrentState Closed
WaitingFor

Checkins TWikirev:16863
TargetRelease patch
ReleasedIn 4.2.1, 5.0.0
Edit | Attach | Watch | Print version | History: r14 < r13 < r12 < r11 < r10 | Backlinks | Raw View |  Raw edit | More topic actions
Topic revision: r14 - 2008-08-04 - KennethLavrsen
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback