SID-01186: Interwiki does not encode URLs?
| Status: |
Answered |
TWiki version: |
4.2.3 |
Perl version: |
5.8.8 |
| Category: |
InterwikiPlugin |
Server OS: |
Fedora |
Last update: |
14 years ago |
I decided to try to use
InterwikiPlugin to simplify referencing photos in an external website.
The rules don't seem flexible enough - or I haven't figured out how to accomplish what's needed.
Here's what an external URL looks like:
https://www.example.com/photos/gallery.cgi?mode=view&photo=%2FFamily%2FDog%20Jumping%2F100_1027.jpg
One would like these to work like:
Photo:'/Family/Dog Jumping/100_1027.jpg', where the quotes are necessary because of the embedded space.
Or, even
[[Photo:/Family/Dog Jumping/100_1027.jpg]]
So I tried:
| Photo | https://www.example.com/photos/gallery.cgi?mode=view&photo=%ENCODE{$page}% | Display a photo '$page' from the internal photo gallery |
But: the %ENCODE was taken literally. I tried omitting the %ENCODE, but that doesn't quite work...
It looks to me like the syntax doesn't quite handle this external site.
I think we need a way to quote the string after Site:, and I think we need a way to specify that $page is to be url-encoded...
Or perhaps I'm missing something.
--
TimotheLitt - 2011-05-23
Discussion and Answer
Self-help: I have generated the attached patch
Patch for quote syntax and urlencode which solves my problem.
The patch is based on the latest (2010-07-12) release; I changed the release to -T1, but you'll want to make it whatever date you re-package.
- You can now specify an external link as Site:'anything at all' or Site:"anything at all", as well as Site:PreviousRestrictedSyntax. If you use either quote form, there is no escape character for the quotation mark that you choose; so if you need a single quote, use the double quote form and vice-versa. If you need both, you can make the regexes even more complex.
- When the $page variable is interpolated into the URL (explicitly or implicitly appended), it is urlencoded. This allows spaces and other strange characters to be passed in the href.
- If you use the $page variable elsewhere (e.g. for label or tooltip), it is NOT urlencoded, so the human readable stuff stays human readable.
I have not tested this with all the pre-defined interwikis (I don't have test URLs for them), but it should work. Hopefully there's a regression test for this plugin.
Let me know if there are any issues; if not, please put the patch into your source.
--
TimotheLitt - 2011-05-23
Thanks Timothe for the patch. I think it is too risky to change the behavior of URL encoding the $page part. I have used manually URL-encoded page names, so they would be double encoded, thus breaking the link.
I like however the idea of enclosing the page name in single quotes or double quotes. This is a new case where we can safely use the implicit URL encoding. This spec is an extension that does not break existing content.
--
PeterThoeny - 2011-05-24
That's too bad - the page should have been urlencoded from the start, but I do understand the legacy problem. Amazing what people will do with broken tools; manual urlencoding is truly ugly and hardly user friendly. But the compatibility argument is persuasive.
I have updated the patch to only urlencode when the page is quoted. That suffices for my needs and addresses your concern.
This is version T2.
Enjoy.
--
TimotheLitt - 2011-05-24
Thanks, tracked in
TWikibug:Item6731
.
--
PeterThoeny - 2011-05-26
This is now in SVN trunk and 5.1 branch.
Plugins.InterwikiPlugin is updated as well.
FYI, it took some time to update the docs. I also did some code cleanup, adding
$SHORTDESCRIPTION and
$NO_PREFS_IN_TOPIC, and changing
use vars qw() to
our.
You have SVN access, you could help the TWiki community by checking in code and docs directly. Or if you prefer to just provide patches, it would help to get updated docs with it as well.
--
PeterThoeny - 2011-05-26
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.