Item10572: Make DBCachePlugin dependency optional
Priority: Enhancement
Current State: Closed
Released In: n/a
Target Release: n/a
We've written the following patch to avoid
DBCachePlugin dependency with
WebLinkPlugin.
diff --git a/lib/Foswiki/Plugins/WebLinkPlugin/Core.pm b/lib/Foswiki/Plugins/WebLinkPlugin/Core.pm
index 40d5df6..20aec73 100644
--- a/lib/Foswiki/Plugins/WebLinkPlugin/Core.pm
+++ b/lib/Foswiki/Plugins/WebLinkPlugin/Core.pm
@@ -109,8 +109,10 @@ sub WEBLINK {
if (Foswiki::Func::getContext()->{DBCachePluginEnabled}) {
require Foswiki::Plugins::DBCachePlugin;
$title = Foswiki::Plugins::DBCachePlugin::getTopicTitle($theWeb, $homeTopic);
- }
- $title = $theName if $title eq $homeTopic;
+ } else {
+ $title = getTopicTitle($theWeb, $homeTopic);
+ }
+ $title = $theName if not defined $title or $title eq $homeTopic;
}
my $result = $theFormat;
@@ -127,4 +129,29 @@ sub WEBLINK {
return $result;
}
+sub getTopicTitle {
+ my ($web, $topic) = @_;
+ my ($topicObj, undef) = Foswiki::Func::readTopic($web, $topic);
+ my $title = $topicObj->get('PREFERENCE', 'TOPICTITLE');
+
+ if ($title) {
+ $title = $title->{value};
+ }
+ if (not $title) {
+ $title = $topicObj->getPreference('TOPICTITLE');
+ if (not $title) {
+ $title = $topicObj->get('FIELD', 'TopicTitle');
+ if ($title) {
+ $title = $title->{value};
+ }
+ }
+ }
+ if ($title) {
+ $title =~ s/\s*$//;
+ $title =~ s/^\s*//;
+ }
+
+ return $title;
+}
+
1;
--
PaulHarvey - 30 Mar 2011
Good idea, but this has got two issues: (1) TopicType formfields have higher priority wrt TOPICTYPE preferences. (2) reading the preference value needs to make use of pushTopicContext/popTopicContext to get the correct distant preference value.
... something like this:
sub getTopicTitle {
my ($web, $topic) = @_;
if (Foswiki::Func::getContext()->{DBCachePluginEnabled}) {
require Foswiki::Plugins::DBCachePlugin;
return Foswiki::Plugins::DBCachePlugin::getTopicTitle($web, $topic);
}
my ($meta, undef) = Foswiki::Func::readTopic($web, $topic);
# read the formfield value
my $title = $meta->get('FIELD', 'TopicTitle');
if ($title) {
$title = $title->{value};
}
# read the topic preference
unless ($title) {
$title = $meta->get('PREFERENCE', 'TOPICTITLE');
if ($title) {
$title = $title->{value};
}
}
# read the preference
unless ($title) {
Foswiki::Func::pushTopicContext($web, $topic);
$title = Foswiki::Func::getPreferencesValue('TOPICTITLE');
Foswiki::Func::popTopicContext();
}
# default to topic name
$title ||= $topic;
$title =~ s/\s*$//;
$title =~ s/^\s*//;
return $title;
}
--
MichaelDaum - 05 Apr 2011
Hi Temi, do you have time to test Michael's code? We should probably deploy it, post another patch here, Michael can apply it, and then this task can be closed.
Also note: there's no mention of DBCache as a dependency in the DEPENDENCY file. After this fix is in place, it should be optional
--
PaulHarvey - 10 May 2011
released as 1.10
--
MichaelDaum - 30 Sep 2011