Skip to content

Commit

Permalink
Item9874: Fix format string, check that $topicObj actually defined be…
Browse files Browse the repository at this point in the history
…fore

calling methods on them

git-svn-id: http://svn.foswiki.org/trunk/TopicRecursePlugin@11297 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
PaulHarvey authored and PaulHarvey committed Apr 4, 2011
1 parent 34592e2 commit c0b63fa
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 23 deletions.
8 changes: 4 additions & 4 deletions lib/Foswiki/Plugins/TopicRecursePlugin/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sub extractParams {
$args{$item} = $params->{$item};
}
$args{header} ||= '*Search: \'$rootquery\' from <nop>$root* $n';
$args{format} = '$indent* [[$web.$topic][$topic]]';
$args{format} ||= '$indent* [[$web.$topic][$topic]]';
$args{formatbranch} ||= $args{format};
$args{formatleaf} ||= $args{format};
$args{separator} ||= '$n';
Expand Down Expand Up @@ -62,7 +62,7 @@ sub TOPICRECURSE {
writeDebug( "rootNode: $rootNode->{webtopic}", 'TOPICRECURSE', 4 );
my $spec = extractParams(
$params,
qw(header formatbranch formatleaf separator footer),
qw(header format formatbranch formatleaf separator footer),
qw(nodelimit depthlimit breadthlimit)
);
my @renderednodes = formatNodes( $rootNode, $spec );
Expand Down Expand Up @@ -148,10 +148,10 @@ sub execToken {
else {
$result = $completetoken;
}
writeDebug( "\$$tokenname($tokenarg) = '$result' depth: $node->{depth}",
writeDebug( '$' . ($tokenname || '') . '(' . ($tokenarg || '') . ') = \'' . ($result || '') . '\' depth:' . $node->{depth},
'execToken', 4 );

return $result;
return $result || '';
}

sub writeDebug {
Expand Down
99 changes: 80 additions & 19 deletions lib/Foswiki/Plugins/TopicRecursePlugin/Node.pm
Original file line number Diff line number Diff line change
Expand Up @@ -342,37 +342,98 @@ sub getStandardTokens {
nodeindex => $this->{nodeindex},
indent => $this->buildIndent(' '),
'indent()' => sub { $this->buildIndent(@_) },
'parent()' => sub { $this->getTopicObject()->getParent() },
'date()' => sub { $this->getTopicObject()->getRevisionInfo()->{date} },
'parent()' => sub {
my $topicObj = $this->getTopicObject();

if ($topicObj) {
$topicObj->getParent();
}
},
'date()' => sub {
my $topicObj = $this->getTopicObject();

if ($topicObj) {
$topicObj->getRevisionInfo()->{date};
}
},
index => $this->{nodeindex},
item => $this->{webtopic},
'rev()' => sub { $this->getTopicObject()->getLoadedRev() },
'username()' =>
sub { $this->getTopicObject()->getRevisionInfo()->{author} },
'rev()' => sub {
my $topicObj = $this->getTopicObject();

if ($topicObj) {
$topicObj->getLoadedRev();
}
},
'username()' => sub {
my $topicObj = $this->getTopicObject();

if ($topicObj) {
$topicObj->getRevisionInfo()->{author};
}
},
'wikiname()' => sub {
Foswiki::Func::getWikiName(
$this->getTopicObject()->getRevisionInfo()->{author} );
my $topicObj = $this->getTopicObject();

if ($topicObj) {
Foswiki::Func::getWikiName(
$topicObj->getRevisionInfo()->{author} );
}
},
'wikiusername()' => sub {
Foswiki::Func::getWikiUserName(
$this->getTopicObject()->getRevisionInfo()->{author} );
my $topicObj = $this->getTopicObject();

if ($topicObj) {
Foswiki::Func::getWikiUserName(
$topicObj->getRevisionInfo()->{author} );
}
},
'createdate()' => sub {
my $topicObj = $this->getTopicObject(1);

if ($topicObj) {
$topicObj->getRevisionInfo()->{date};
}
},
'createusername()' => sub {
my $topicObj = $this->getTopicObject(1);

if ($topicObj) {
$topicObj->getRevisionInfo()->{author};
}
},
'createdate()' =>
sub { $this->getTopicObject(1)->getRevisionInfo()->{date} },
'createusername()' =>
sub { $this->getTopicObject(1)->getRevisionInfo()->{author} },
'createwikiname()' => sub {
Foswiki::Func::getWikiName(
$this->getTopicObject(1)->getRevisionInfo()->{author} );
my $topicObj = $this->getTopicObject(1);

if ($topicObj) {
Foswiki::Func::getWikiName(
$topicObj->getRevisionInfo()->{author} );
}
},
'createwikiusername()' => sub {
Foswiki::Func::getWikiUserName(
$this->getTopicObject(1)->getRevisionInfo()->{author} );
my $topicObj = $this->getTopicObject(1);

if ($topicObj) {
Foswiki::Func::getWikiUserName(
$topicObj->getRevisionInfo()->{author} );
}
},
'formname()' => sub {
my $topicObj = $this->getTopicObject();

if ($topicObj) {
$topicObj->getFormName();
}
},
'formname()' => sub { $this->getTopicObject()->getFormName() },

# TODO: Make this actually do the SEARCH equivalent (bypassing renderFor)
'formfield()' => sub { $this->getTopicObject()->get( 'FIELD', $_[0] ) },
'formfield()' => sub {
my $topicObj = $this->getTopicObject();

if ($topicObj) {
$topicObj->get( 'FIELD', $_[0] );
}
},
ntopics => $this->{rootNode}->{nodecount},

# SMELL: What the...
Expand Down

0 comments on commit c0b63fa

Please sign in to comment.