Currently it is not possible to have a TOC in a skin because the TOC handling only loads the topic text if the TOC has to be built for another topic. The TOC fails because the skin handling is done in the context of the current topic and ths skin does not have the topic content.
This fixes the issue by checking if TOC is in skin context. If so, it reads the topic text before building the TOC.
--
TWiki:Main/PeterThoeny
- 2013-06-27
This is now in SVN trunk and 5.1 branch.
Patch for TWiki-5.1.x:
--- TWiki.pm (revision 26021)
+++ TWiki.pm (working copy)
@@ -1921,6 +1921,7 @@
undef $this->{user};
undef $this->{SESSION_TAGS};
undef $this->{_INCLUDES};
+ undef $this->{ignoreTOC};
undef $this->{response};
undef $this->{evaluating_if};
}
@@ -2229,6 +2230,8 @@
sub _TOC {
my ( $this, $text, $defaultTopic, $defaultWeb, $args ) = @_;
+ return '' if( $this->{ignoreTOC} ); # prevent infinite recursion
+
require TWiki::Attrs;
my $params = new TWiki::Attrs( $args );
@@ -2253,7 +2256,9 @@
my $title = $params->{title} || $this->{prefs}->getPreferencesValue('TOC_TITLE') || '';
$title = CGI::span( { class => 'twikiTocTitle' }, $title ) if( $title );
- if( $web ne $defaultWeb || $topic ne $defaultTopic ) {
+ # Item7286: Load topic text if TOC is built for another topic,
+ # or if in skin context of the current topic
+ unless( $isSameTopic && $this->inContext( 'body_text' ) ) {
unless( $this->security->checkAccessPermission
( 'VIEW', $this->{user}, undef, undef, $topic, $web ) ) {
return $this->inlineAlert( 'alerts', 'access_denied', $web, $topic );
@@ -2261,13 +2266,13 @@
my $meta;
( $meta, $text ) = $this->{store}->readTopic( $this->{user}, $web, $topic );
- # Item7166: Escape %TOC% to avoid infinite recursion.
- $text =~ s/%(TOC[{%])/%<nop>$1/g;
-
+ # prevent infinite recursion - could happen if there is a TOC in the text or in INCLUDE
+ $this->{ignoreTOC} = 1;
# Item6864: 2012-03-29 TWiki:Main.GertjanVanOosten, gertjan at west dot nl:
# Handle common tags, as the text may contain variables etc. that need
# to be expanded before generating the TOC for another topic.
$text = $this->handleCommonTags( $text, $web, $topic, $meta );
+ $this->{ignoreTOC} = undef;
}
my $insidePre = 0;
--
TWiki:Main/PeterThoeny
- 2013-06-27