Skip to content

Commit

Permalink
Item12876: added support for TopicTitles
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/FlexWebListPlugin@17604 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Apr 29, 2014
1 parent f850aaf commit 04beb6d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
4 changes: 3 additions & 1 deletion data/System/FlexWebListPlugin.txt
Expand Up @@ -68,6 +68,7 @@ that are replaced with a current value:
* =$web=: the full name of the web, e.g. =Main/Foo/Bar=
* =$qname=: the full name of the web in quotes, e.g. ="Main/Foo/Bar"= (deprecated)
* =$name=: the name of the web without the leading parent webs, e.g. =Bar=
* =$title=: the title of the web as specified in the !TopicTitle of the !WebHome topic
* =$origname=: the original name of the web despite any name mapping
* =$parent=: the name of the parent web of a sub web or the empty string if there's none
* =$marker=: marker text (see above) if the current item is selected, empty otherwise
Expand Down Expand Up @@ -148,7 +149,8 @@ See FlexWebListExamples and FlexWebListTree.
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: |   |
| 18 Nov 2014: | support =WEBSUMMARY=; deprecate =SITEMAPWAT= and =SITEMAPUSETO= |
| 28 Apr 2014: | added support for !TopicTitle |
| 18 Nov 2013: | support =WEBSUMMARY=; deprecate =SITEMAPWAT= and =SITEMAPUSETO= |
| 07 Nov 2013: | fixed caching issue |
| 19 Nov 2012: | improve performance on large foswikis by caching a webs iterator to be reused |
| 10 Jan 2012: | fixed setting format strings to the empty string |
Expand Down
6 changes: 4 additions & 2 deletions lib/Foswiki/Plugins/FlexWebListPlugin.pm
Expand Up @@ -17,8 +17,8 @@ package Foswiki::Plugins::FlexWebListPlugin;
use strict;
use warnings;

our $VERSION = '1.81';
our $RELEASE = '1.81';
our $VERSION = '1.90';
our $RELEASE = '1.90';
our $NO_PREFS_IN_TOPIC = 1;
our $SHORTDESCRIPTION = 'Flexible way to display hierarchical weblists';
our $core;
Expand Down Expand Up @@ -46,6 +46,8 @@ sub afterRenameHandler {
my ($oldWeb, $oldTopic, $oldAttachment, $newWeb, $newTopic, $newAttachment) = @_;

return if $oldTopic;

# SMELL: does not fire on web-creation
core->reset;
}

Expand Down
55 changes: 49 additions & 6 deletions lib/Foswiki/Plugins/FlexWebListPlugin/Core.pm
Expand Up @@ -19,7 +19,6 @@ use warnings;

use Foswiki::Func ();
use Foswiki::Plugins ();
use Foswiki::Meta ();
use Foswiki::WebFilter ();

use constant TRACE => 0; # toggle me
Expand Down Expand Up @@ -272,19 +271,25 @@ sub formatWeb {
$summary =~ s/<nop>//g;
}

my $title = $name || '';
if ($result =~ /\$title/) {
$title = getTopicTitle($web->{key}, $this->{homeTopic});
}


my $color = '';
if ($result =~ /\$color/) {
$color =
Foswiki::Func::getPreferencesValue('WEBBGCOLOR', $web->{key}) || '';
}

$result =~ s/\$parent/$web->{parentName}/go;
$result =~ s/\$name/$name/go;
$result =~ s/\$origname/$web->{name}/go;
$result =~ s/\$parent/$web->{parentName}/g;
$result =~ s/\$name/$name/g;
$result =~ s/\$title/$title/g;
$result =~ s/\$origname/$web->{name}/g;
$result =~ s/\$qname/"$web->{key}"/g;# historical
$result =~ s/\$web/$web->{key}/go;
$result =~ s/\$depth/$web->{depth}/go;
$result =~ s/\$web/$web->{key}/g;
$result =~ s/\$depth/$web->{depth}/g;
$result =~ s/\$indent\((.+?)\)/$1 x $web->{depth}/ge;
$result =~ s/\$indent/' ' x $web->{depth}/ge;
$result =~ s/\$nrsubwebs/$nrSubWebs/g;
Expand Down Expand Up @@ -426,4 +431,42 @@ sub escapeParameter {
$_[0] =~ s/\$dollar/\$/g;
}

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

my ($meta, $text) = Foswiki::Func::readTopic($web, $topic);

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

# read the formfield value
my $title = $meta->get('FIELD', 'TopicTitle');
$title = $title->{value} if $title;

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

# 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;
}

1;

0 comments on commit 04beb6d

Please sign in to comment.