You are here: Foswiki>Tasks Web>Item11526 (11 Apr 2012, GeorgeClark)Edit Attach

Item11526: The renderWikiWordHandler is called for things that are not WikiWord links

pencil
Priority: Normal
Current State: Closed
Released In: 1.1.5
Target Release: patch
Applies To: Engine
Component: pluginHandlers
Branches: Release01x01 trunk
Reported By: SvenDowideit
Waiting For:
Last Change By: GeorgeClark
sub test_renderWikiWordHandler {
    my $this = shift;
    $this->makePlugin( 'renderWikiWordHandler', <<'HERE');
#($linkText, $hasExplicitLinkLabel, $web, $topic) -> $linkText
sub renderWikiWordHandler {
    my ($linkText, $hasExplicitLinkLabel, $web, $topic) = @_;
    $called->{renderWikiWordHandler}++;
    $called->{renderWikiWordHandlerLinks}->{$web.'___'.$topic} = $linkText.'___'.($hasExplicitLinkLabel||'undef');
    #die $topic if ($topic eq 'ALLOWTOPICVIEW');
}
HERE
    $this->checkCalls( 0, 'renderWikiWordHandler' );
    my $html = Foswiki::Func::renderText( <<'HERE', 'Sandbox', 'TestThisCarefully' );
    This is AWikiWord and some NoSuchWeb.NoTopic that we CANNOT
   * Set ALLOWTOPICCHANGE=guest
 %ATTACHURL%/Foswiki-1.1.4.tar.gz
 
 %ATTACHURL%/releases/Foswiki-1.0.4.tar.gz
 %ATTACHURL%/releases/other/file-3.0.4.tar.gz

 %SYSTEMWEB%.WebHome
 %SYSTEMWEB%.WikiWords
 
 %USERSWEB%.%SYSTEMWEB%Topic
 
 %ATTACHURL%/Foswiki-1.1.4.tar.gz
 
 %ATTACHURL%/releases/Foswiki-1.0.4.tar.gz
 [[%ATTACHURL%/releases/other/file-3.0.4.tar.gz]]

 [[%SYSTEMWEB%.WebHome]]
 [[%SYSTEMWEB%.WikiWords]]
 
 [[%USERSWEB%.%SYSTEMWEB%Topic]]

[[some test link]] [[text][link text]]
HERE
    $this->checkCalls( 10, 'renderWikiWordHandler' );
    #$Foswiki::Plugins::$this->{plugin_name}::called->{$name}
    my $hashRef = eval "\$Foswiki::Plugins::$this->{plugin_name}::called->{renderWikiWordHandlerLinks}";
use Data::Dumper;
print STDERR "------ ".Dumper($hashRef)."\n";
#TODO: this is not correct, its just what we have
    $this->assert_deep_equals({
          'ATTACHURL/releases/other/file-3/0/4/tar___gz' => '%ATTACHURL%/releases/other/file-3.0.4.tar.gz___undef',
          'SYSTEMWEB___WikiWords' => '%SYSTEMWEB%.WikiWords___undef',
          'Sandbox___Text' => 'link text___1',
          'SYSTEMWEB___WebHome' => '%SYSTEMWEB%.WebHome___undef',
          'NoSuchWeb___NoTopic' => 'NoTopic___undef',
          'Sandbox___ALLOWTOPICCHANGE' => 'ALLOWTOPICCHANGE___undef',
          'USERSWEB___SYSTEMWEBTopic' => '%USERSWEB%.%SYSTEMWEB%Topic___undef',
          'Sandbox___AWikiWord' => 'AWikiWord___undef',
          'Sandbox___SomeTestLink' => 'some test link___undef',
          'Sandbox___CANNOT' => 'CANNOT___undef'
        }, $hashRef);

    return;
}

I'm on trunk, but will commit and look at 1.1 too

-- SvenDowideit - 16 Feb 2012

ok, so ACRONYMS work this way - they are possible links for which the plugin can ammend the linktext.

remaining things to investigate:
  1. why are the %'s removed from the web and topic values - making it impossible for the plugin to know if its a var or literal text
  2. is there a problem with the ATTACHURL case (i suspect not putting http://foswiki.org/pub/Tasks/Item11526/releases/other/file-3.0.4.tar.gz causes foswiki to expect that there is a topic by that name.

-- SvenDowideit - 16 Feb 2012

ok, so fundamentally, I always forget that renderText must have all MACROS already expanded - it does not do it for you.

wrt ACRONYMS, Foswiki::Func::internalLink will return non-linked text, so taht can be used to detect that what is passed to the renderWikiWordHandler is not actually a link.

so, I've added a few more tests, and might have added just enough docco to help me in 4 years time when i hit it again.

-- SvenDowideit - 16 Feb 2012

merged over to 1.1 too, as its docco and tests.

-- SvenDowideit - 01 Mar 2012
 
Topic revision: r14 - 11 Apr 2012, GeorgeClark
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