Question
Could anybody please explain the purpose that the $TranslationToken serves, which is wrapped around the words when links are created? In particular, I am puzzled why these are wrapped around the text corresponding to the links.
Note that these mess up the handler that is provided to call word rendering in plugins (
TWiki::Plugins::renderWikiWordHandler), when
internalLink is called from
internalCrosswebLink.
Environment
--
ThomasWeigert - 08 Feb 2005
Answer
The $TranslationToken is inserted into text temporarily to defuse a regular expression search. Example:
# "TopicName" to "Web.TopicName"
$text =~ s/(^|[\s\(])($regex{webNameRegex}\.$regex{wikiWordRegex})/$1$TranslationToken$2/go;
$text =~ s/(^|[\s\(])($regex{wikiWordRegex})/$1$theWeb\.$2/go;
$text =~ s/(^|[\s\(])$TranslationToken/$1/go;
The first regex prefixes Web.TopicNames with a token so that the word is no longer prefixed by whitespace or parenthesis. The second regex looks for WikiWords. It won't find web names that happen to be!WikiWords such as WebName.TopicNames because of the prefixed token. The third regex removes the temporary token.
$TranslationToken should only be added temporarily and should not be passed into subroutines. File a
BugReport if this is the case.
--
PeterThoeny - 10 Feb 2005
Peter, thanks. I definitely see that
$TranslationToken is passed into subroutines. I will submit a
BugReport.
But just to verify... I understand you as saying that there would be no harm done if I were to take the
$TranslationToken out before entering the subroutine, without putting it back in afterwards?
--
ThomasWeigert - 10 Feb 2005
Not sure if it is OK to remove the token out of context. The code neeeds to be looked at.
--
PeterThoeny - 11 Feb 2005
Bug report filed as
TranslationTokenPassedIntoSubroutines. I have also added a patch that solves the problem for me, but it appears rather awkward.
--
ThomasWeigert - 11 Feb 2005