From c0b63fa4416af6cfd423c287d6f366fb295c7073 Mon Sep 17 00:00:00 2001 From: PaulHarvey Date: Mon, 4 Apr 2011 04:03:02 +0000 Subject: [PATCH] Item9874: Fix format string, check that $topicObj actually defined before calling methods on them git-svn-id: http://svn.foswiki.org/trunk/TopicRecursePlugin@11297 0b4bb1d4-4e5a-0410-9cc4-b2b747904278 --- .../Plugins/TopicRecursePlugin/Core.pm | 8 +- .../Plugins/TopicRecursePlugin/Node.pm | 99 +++++++++++++++---- 2 files changed, 84 insertions(+), 23 deletions(-) diff --git a/lib/Foswiki/Plugins/TopicRecursePlugin/Core.pm b/lib/Foswiki/Plugins/TopicRecursePlugin/Core.pm index 0f0f475..efbe522 100644 --- a/lib/Foswiki/Plugins/TopicRecursePlugin/Core.pm +++ b/lib/Foswiki/Plugins/TopicRecursePlugin/Core.pm @@ -30,7 +30,7 @@ sub extractParams { $args{$item} = $params->{$item}; } $args{header} ||= '*Search: \'$rootquery\' from $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'; @@ -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 ); @@ -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 { diff --git a/lib/Foswiki/Plugins/TopicRecursePlugin/Node.pm b/lib/Foswiki/Plugins/TopicRecursePlugin/Node.pm index 99227d9..a2acf61 100644 --- a/lib/Foswiki/Plugins/TopicRecursePlugin/Node.pm +++ b/lib/Foswiki/Plugins/TopicRecursePlugin/Node.pm @@ -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...