Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Item13529: extract list of section names
also:

- added rev param to getTopicTitle to extract the topic title from any revision
- unicode fixes for Foswiki-2.0 compatibility
- added "random" sorting to DBQUERY
  • Loading branch information
MichaelDaum committed Jul 17, 2015
1 parent faa732b commit 2643c9c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 35 deletions.
5 changes: 3 additions & 2 deletions data/System/DBCachePlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1425456531" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1437149467" format="1.1" version="1"}%
---+!! <nop>%TOPIC%
%TOC%

Expand Down Expand Up @@ -96,7 +96,7 @@ tool or (b) as a tool to extract properties of (a set of) known topics.
defaults to "$n"; the special separator "none" disables separation |
| =include="..."= | pattern each found topic name must match to be considered a hit |
| =exclude="..."= | pattern each found topic name must not match to be considered a hit |
| =sort="..."= | specifies the sorting of hits; this can be a comma separted list of attributes to specify more complicated sortings; defaults to "name" |
| =sort="..."= | specifies the sorting of hits; this can be a comma separted list of attributes to specify more complicated sortings; special value "random"; defaults to "name" |
| =reverse="..."= | specify if hits should be sorted in reverse order; defaults to "off" |
| =limit="..."= | maximum number of topics to include in the hit set |
| =skip="..."= | number of topics to skip while constructing the hit set; defaults to "0" |
Expand Down Expand Up @@ -422,6 +422,7 @@ automatically from there on.
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 25 May 2015: | added =sections= to database, a list of known named sections |
| 04 Mar 2015: | fixing interaction between DBDUMP generating a heading and Foswiki:Extensions/EditChapterPlugin |
| 20 Jan 2015: | added =$html()= |
| 27 Nov 2014: | fixed security of rest handlers and DBDUMP macro |
Expand Down
4 changes: 2 additions & 2 deletions lib/Foswiki/Plugins/DBCachePlugin.pm
Expand Up @@ -25,8 +25,8 @@ use Foswiki::Plugins();
#Monitor::MonitorMethod('Foswiki::Contrib::DBCachePlugin::Core');
#Monitor::MonitorMethod('Foswiki::Contrib::DBCachePlugin::WebDB');

our $VERSION = '6.11';
our $RELEASE = '04 Mar 2015';
our $VERSION = '7.00';
our $RELEASE = '17 Jul 2015';
our $NO_PREFS_IN_TOPIC = 1;
our $SHORTDESCRIPTION = 'Lightweighted frontend to the DBCacheContrib';

Expand Down
84 changes: 58 additions & 26 deletions lib/Foswiki/Plugins/DBCachePlugin/Core.pm
Expand Up @@ -40,6 +40,7 @@ use Foswiki::Sandbox ();
use Foswiki::Time ();
use Foswiki::Func ();
use Cwd;
use Encode();

###############################################################################
sub writeDebug {
Expand Down Expand Up @@ -214,6 +215,7 @@ sub handleTOPICTITLE {
my $thisWeb = $params->{web} || $baseWeb;
my $theEncoding = $params->{encode} || '';
my $theDefault = $params->{default};
my $theRev = $params->{rev};
my $theHideAutoInc = Foswiki::Func::isTrue($params->{hideautoinc}, 0);

$thisTopic =~ s/^\s+//go;
Expand All @@ -222,7 +224,7 @@ sub handleTOPICTITLE {
($thisWeb, $thisTopic) =
Foswiki::Func::normalizeWebTopicName($thisWeb, $thisTopic);

my $topicTitle = getTopicTitle($thisWeb, $thisTopic);
my $topicTitle = getTopicTitle($thisWeb, $thisTopic, $theRev);

if ($topicTitle eq $thisTopic && defined($theDefault)) {
$topicTitle = $theDefault;
Expand All @@ -239,31 +241,60 @@ sub handleTOPICTITLE {

###############################################################################
sub getTopicTitle {
my ($theWeb, $theTopic) = @_;
my ($web, $topic, $rev) = @_;

($theWeb, $theTopic) = Foswiki::Func::normalizeWebTopicName($theWeb, $theTopic);
($web, $topic) = Foswiki::Func::normalizeWebTopicName($web, $topic);

my $db = getDB($theWeb);
return $theTopic unless $db;
my $topicTitle = $topic;

if ($rev) {
my ($meta) = Foswiki::Func::readTopic($web, $topic, $rev);

my $topicObj = $db->fastget($theTopic);
return $theTopic unless $topicObj;
# read the formfield value
$topicTitle = $meta->get('FIELD', 'TopicTitle');
$topicTitle = $topicTitle->{value} if $topicTitle;

# read the topic preference
unless ($topicTitle) {
$topicTitle = $meta->get('PREFERENCE', 'TOPICTITLE');
$topicTitle = $topicTitle->{value} if $topicTitle;
}

if ($Foswiki::cfg{SecureTopicTitles}) {
my $wikiName = Foswiki::Func::getWikiName();
return $theTopic
unless Foswiki::Func::checkAccessPermission('VIEW', $wikiName, undef, $theTopic, $theWeb);
# read the preference
unless ($topicTitle) {
Foswiki::Func::pushTopicContext($web, $topic);
$topicTitle = Foswiki::Func::getPreferencesValue('TOPICTITLE');
Foswiki::Func::popTopicContext();
}

} else {
my $db = getDB($web);
return $topic unless $db;

my $topicObj = $db->fastget($topic);
return $topic unless $topicObj;

if ($Foswiki::cfg{SecureTopicTitles}) {
my $wikiName = Foswiki::Func::getWikiName();
return $topic
unless Foswiki::Func::checkAccessPermission('VIEW', $wikiName, undef, $topic, $web);
}

$topicTitle = $topicObj->fastget('topictitle');
}

my $topicTitle = $topicObj->fastget('topictitle');
return $topicTitle if $topicTitle;
# default to topic name
$topicTitle = $topic unless $topicTitle;

$topicTitle =~ s/\s*$//;
$topicTitle =~ s/^\s*//;

if ($theTopic eq $Foswiki::cfg{HomeTopicName}) {
$theWeb =~ s/^.*[\.\/]//;
return $theWeb;
if ($topicTitle eq $Foswiki::cfg{HomeTopicName}) {
$topicTitle = $web;
$topicTitle =~ s/^.*[\.\/]//;
}

return $theTopic;
return $topicTitle;
}

###############################################################################
Expand Down Expand Up @@ -886,7 +917,7 @@ sub _dbDump {
}
}

return "<verbatim style='margin:0'>\n$obj\n</verbatim>";
return "<verbatim>\n$obj\n</verbatim>";
}

###############################################################################
Expand All @@ -907,10 +938,10 @@ sub _dbDumpList {
sub _dbDumpHash {
my $hash = shift;

my $result = "<table class='foswikiTable' style='margin:0;font-size:1em'>\n";
my $result = "<table class='foswikiTable'>\n";

foreach my $key (sort keys %$hash) {
$result .= "<tr><th valign='top'>$key</th><td>\n";
$result .= "<tr><th>$key</th><td>\n";
$result .= _dbDump($hash->{$key});
$result .= "</td></tr>\n";
}
Expand All @@ -922,11 +953,11 @@ sub _dbDumpHash {
sub _dbDumpArray {
my $array = shift;

my $result = "<table class='foswikiTable' style='margin:0;font-size:1em'>\n";
my $result = "<table class='foswikiTable'\n";

my $index = 0;
foreach my $obj (sort $array->getValues()) {
$result .= "<tr><th valign='top'>";
$result .= "<tr><th>";
if (UNIVERSAL::can($obj, "fastget")) {
$result .= $obj->fastget('name');
} else {
Expand All @@ -945,12 +976,12 @@ sub _dbDumpArray {
sub _dbDumpMap {
my $map = shift;

my $result = "<table class='foswikiTable' style='margin:0;font-size:1em'>\n";
my $result = "<table class='foswikiTable'>\n";

my @keys = sort {lc($a) cmp lc($b)} $map->getKeys();

foreach my $key (@keys) {
$result .= "<tr><th valign='top'>$key</th><td>\n";
$result .= "<tr><th>$key</th><td>\n";
$result .= _dbDump($map->fastget($key));
$result .= "</td></tr>\n";
}
Expand All @@ -975,10 +1006,10 @@ sub dbDump {
unless ($topicObj) {
return inlineError("DBCachePlugin: $web.$topic not found");
}
my $result = "\n<noautolink>\n";
my $result = "\n<noautolink><div class='foswikiDBDump'>\n";
$result .= "<h2 > [[$web.$topic]]</h2>\n";
$result .= _dbDumpMap($topicObj);
return $result . "\n</noautolink>\n";
return $result . "\n</div></noautolink>\n";
}

###############################################################################
Expand Down Expand Up @@ -1368,6 +1399,7 @@ sub quoteEncode {
sub urlEncode {
my $text = shift;

$text = Encode::encode_utf8($text) if $Foswiki::UNICODE;
$text =~ s/([^0-9a-zA-Z-_.:~!*'\/%])/'%'.sprintf('%02x',ord($1))/ge;

return $text;
Expand Down
7 changes: 4 additions & 3 deletions lib/Foswiki/Plugins/DBCachePlugin/DEPENDENCIES
@@ -1,3 +1,4 @@
Foswiki::Contrib::DBCacheContrib,>=3.00,perl,Required.
Time::ParseDate,>=2003.0211,cpan,Required.
Storable,>=2.07,cpan,Required.
Foswiki::Contrib::DBCacheContrib,>=4.00,perl,Required
Time::ParseDate,>=2003.0211,cpan,Required
Storable,>=2.07,cpan,Required
Sereal,>=3.00,cpan,Optional
11 changes: 9 additions & 2 deletions lib/Foswiki/Plugins/DBCachePlugin/WebDB.pm
Expand Up @@ -120,12 +120,17 @@ sub onReload {
# CAUTION: %SECTION will be deleted in the near future.
# so please convert all %SECTION to %STARTSECTION

while ($text =~ s/%(?:START)?SECTION{(.*?)}%(.*?)%ENDSECTION{[^}]*?"(.*?)"}%//s) {
my $archivist = $this->getArchivist();

my @sections = ();
while ($text =~ s/%(?:START)?SECTION{(.*?)}%(.*?)%(?:STOP|END)SECTION{[^}]*?"(.*?)"}%//s) {
my $attrs = new Foswiki::Attrs($1);
my $name = $attrs->{name} || $attrs->{_DEFAULT} || '';
my $sectionText = $2;
push @sections, $name;
$topic->set("_section$name", $sectionText);
}
$topic->set('_sections', join(", ", @sections));

# get topic title

Expand Down Expand Up @@ -187,7 +192,6 @@ sub onReload {
my @comments = $meta->find('COMMENT');
my $commentDate = 0;
my $cmts;
my $archivist = $this->getArchivist();
foreach my $comment (@comments) {
my $cmt = $archivist->newMap(initial => $comment) ;
my $cmtDate = $comment->{date};
Expand Down Expand Up @@ -357,6 +361,9 @@ sub dbQuery {
} elsif ($theSort =~ /^(modified|info\.date)/) {
my $info = $topicObj->fastget('info');
$sorting{$topicName} = $info ? $info->fastget('date') : 0;
} elsif ($theSort =~ /^rand(om)?$/) {
$doNumericalSort = 1;
$sorting{$topicName} = rand();
} elsif ($theSort ne 'off') {
my $format = $theSort;
$format =~ s/\$web/$this->{web}/g;
Expand Down

0 comments on commit 2643c9c

Please sign in to comment.