archive_me1Add my vote for this tag create new tag
, view all tags

Feature Proposal: Add a "no encode" parameter to SPACEDTOPIC


This came up with working on BacklinksTemplate:

There is one bug with the implementation: the %SPACEDTOPIC% that is used in the template returns a url-encoded string: a space becomes %20. When this is passed as query parameter, it works fine because the url-encoded characters are interpreted. But when used in a template, the %20 just stays what it is, and this results in topics not being found.


A solution could be to add a parameter to %SPACEDTOPIC%, for example encode=no. The search then becomes: search="%SPACEDTOPIC{encode="no"}%. For this a small change to TWiki::_SPACEDTOPIC is needed:

    my ( $this, $params, $theTopic ) = @_;
    my $topic = spaceOutWikiWord( $theTopic );
    $topic =~ s/ / */g;
    my $encode = $params->{'encode'};
    if ( $encode eq 'no' ) {
        return $topic;
    return urlEncode( $topic );

-- ArthurClemens - 02 May 2005


The SPACEDTOPIC variable is a hack and should be deprecated, and replaced with another tag that does the native function (spaceOutWikiWord). I really don't want to add more functionality to a hack, as every hack makes life harder in the future.

  • What would be the syntax of a proper variable? %SPACEOUTWIKIWORD{MyTopic}% perhaps? Or should this be done with SpacedWikiWordPlugin? (then this plugin would need to be part of the distribution, and on by default). -- ArthurClemens - 03 May 2005

-- CrawfordCurrie - 02 May 2005

Why not produce regular spaces in %SPACEDTOPIC% and use %URLENCODE{"%SPACEDTOPIC%"}% whenever needed?

-- MichaelDaum - 02 May 2005

The origin of %SPACEDTOPIC%: FlexibleWikiWords.

-- ArthurClemens - 03 May 2005

%SPACEOUT{"MyTopic"}% sounds fine to me. As does %URLENCODE{"%SPACEOUT("AddNoEncodeParameterToSpacedTopic"}%"}%. Since it is already a core function and we are just exposing it, it should not be done in a plugin. Remember, though, that if you space out a wikiword it will not be recognised as a wikiword (it won't be linked) so you will have to do this to get a link: [[WikiWord][Wiki Word]]. OK?

Also, note that %SPACEDTOPIC inserts a '*' after each space, so that the search matches any number of spaces. Personally I think it's worth losing this, especially since there is lot of other "fuzziness" that could be injected into the backlinks search string (case insensitivity? newlines in the string? punctuation?)

-- CrawfordCurrie - 03 May 2005

New SPACEOUT variable

I have implemented %SPACEOUT{MyTopic}% (SVN 4258). Documentation for TWiki.TWikiVariablesNtoZ:

---+++ SPACEDTOPIC -- topic name, spaced and encoded
    * __Deprecated: use [[#VarSPACEOUT][SPACEOUT]]__
   * The current topic name with added spaces, for regular expression search of Backlinks
   * Syntax: =%<nop>SPACEDTOPIC%=
   * Expands to: =%SPACEDTOPIC%=
   * Related: [[#VarTOPIC][TOPIC]]
---+++ SPACEOUT{MyTopic} -- topic name, spaced and encoded
   * The current topic name with added spaces, for less Wiki-like appearance of topic names; used in regular expression search of Backlinks
   * Syntax: =%<nop>SPACEOUT{WebHome}%=
   * Expands to: =%SPACEOUT{WebHome}%=
   * Example: =[[%<nop>SPACEOUT{WebHome}%]]= creates [[%SPACEOUT{WebHome}%]]
   * Related: [[#VarTOPIC][TOPIC]]

A couple of things to do:

  • How to get rid of the '*' while we still seem to need this in the backlinks search? Perhaps add a sep parameter, like %SPACEOUT{WebHome sep=" *"}%]] ?
  • Without the '*', you could simply use [[%SPACEOUT{WebHome}%]] to get Web Home.

I could do this:

sub spaceOutWikiWord {
    my $word = shift;
    my $sep = shift || ' ';
    $word =~ s/([$regex{lowerAlpha}])([$regex{upperAlpha}$regex{numeric}]+)/$1$sep$2/go;
    $word =~ s/([$regex{numeric}])([$regex{upperAlpha}])/$1$sep$2/go;
    return $word;
and call this from _SPACEOUT:
    my ( $this, $params, $theTopic ) = @_;
    my $spaceOutTopic = $params->{_DEFAULT};
    my $sep = $params->{'sep'};
    $spaceOutTopic = spaceOutWikiWord( $spaceOutTopic, $sep );
    return $spaceOutTopic;
Then in the backlink search, use [[%SPACEOUT{%TOPIC% sep=" *"}%]]

Does this make any sense?


my $word = shift;
my $sep = shift || ' ';
does not feel right to me (kind of hacky) but I am not that familiar with Perl. Is there a neater way to pass the $sep parameter?

-- ArthurClemens - 03 May 2005

That's exactly right, Arthur. It feels hacky because Perl is a hacky language.

-- CrawfordCurrie - 04 May 2005


-- WillNorris - 04 May 2005

Does this mean the sep parameter is acceptable? And the 'hacky' implementation?

-- ArthurClemens - 04 May 2005

yes, indeed. sorry, arthur, i was reacting to crawford's "comments" smile

-- WillNorris - 04 May 2005

This is now in SVN 4266. Updated documentation in Develop's TWiki.TWikiVariablesNtoZ.

-- ArthurClemens - 04 May 2005

Nice work, Arthur! One note. Don't rely on unquoted parameter values. Instead of writing %SPACEOUT{%TOPIC% sep=" *"}% you should always write %SPACEOUT{"%TOPIC%" sep=" *"}%. Why? Well, because you can't predict what syntax may be a valid topic name in the future, for one thing; for example, legal topic names may include spaces. Second, because it makes life an awful lot easier for parsers. I'd love to deprecate unquoted parameters at some point in the future.

-- CrawfordCurrie - 05 May 2005

Makes sense. How to account for the quotes? Or is this a documentation thing?

-- ArthurClemens - 05 May 2005

At the moment it's purely documentation. It'll work just fine without the quotes. All I'm saying is that it's bad practice so you should put them in even if they don't seem to be needed.

-- CrawfordCurrie - 05 May 2005

Edit | Attach | Watch | Print version | History: r17 < r16 < r15 < r14 < r13 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r17 - 2008-08-28 - TWikiJanitor
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.