From e41ee076adf1b7f872acca04f1ef06cca0013587 Mon Sep 17 00:00:00 2001 From: vargenau Date: Mon, 20 Sep 2010 16:09:07 +0000 Subject: [PATCH] Display correct TOC in history git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@7701 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/plugin/CreateToc.php | 42 +++++++++++++++++++++++++----------- pgsrc/Help%2FCreateTocPlugin | 6 +++++- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/lib/plugin/CreateToc.php b/lib/plugin/CreateToc.php index 55fc0aadb..b8caea91b 100644 --- a/lib/plugin/CreateToc.php +++ b/lib/plugin/CreateToc.php @@ -67,6 +67,7 @@ extends WikiPlugin 'width' => '200px', 'with_counter' => 0, 'with_toclink' => 0, // link back to TOC + 'version' => false, ); } // Initialisation of toc counter @@ -168,13 +169,13 @@ extends WikiPlugin $level, &$hstart, &$hend, $basepage=false) { $hstart = 0; $hend = 0; - $h = $this->_getHeader($level); + $h = $this->_getHeader($level); $qheading = $this->_quote($heading); - for ($j=$start_index; $j < count($content); $j++) { + for ($j=$start_index; $j < count($content); $j++) { if (is_string($content[$j])) { - if (preg_match("/<$h>$qheading<\/$h>/", + if (preg_match("/<$h>$qheading<\/$h>/", $content[$j])) - return $j; + return $j; } elseif (isa($content[$j], 'cached_link')) { @@ -213,10 +214,10 @@ extends WikiPlugin } } } - } } - trigger_error("Heading <$h> $heading not found\n", E_USER_NOTICE); - return 0; + } + trigger_error("Heading <$h> $heading not found\n", E_USER_NOTICE); + return 0; } /** prevent from duplicate anchors, @@ -371,7 +372,7 @@ extends WikiPlugin $pagename = $page->name; } if (!$pagename) { - return $this->error(_("no page specified")); + return $this->error(_("No page specified.")); } if (isBrowserIE() and browserDetect("Mac")) { $jshide = 0; @@ -380,22 +381,39 @@ extends WikiPlugin $with_counter = 1; } - // Check if user is allowed to get the Page. + // Check if page exists. + if (!($dbi->isWikiPage($pagename))) { + return $this->error(sprintf(_("Page '%s' does not exist."), $pagename)); + } + + // Check if user is allowed to get the page. if (!mayAccessPage ('view', $pagename)) { return $this->error(sprintf(_("Illegal access to page %s: no read access"), $pagename)); } $page = $dbi->getPage($pagename); + + if ($version) { + $r = $page->getRevision($version); + if ((!$r) || ($r->hasDefaultContents())) { + return $this->error(sprintf(_("%s: no such revision %d."), + $pagename, $version)); + } + } else { + $r = $page->getCurrentRevision(); + } + $current = $page->getCurrentRevision(); //FIXME: I suspect this only to crash with Apache2 if (!$current->get('markup') or $current->get('markup') < 2) { if (in_array(php_sapi_name(),array('apache2handler','apache2filter'))) { - trigger_error(_("CreateToc disabled for old markup"), E_USER_WARNING); - return ''; + return $this->error(_("CreateToc disabled for old markup.")); } } - $content = $current->getContent(); + + $content = $r->getContent(); + $html = HTML::div(array('class' => 'toc', 'id'=> GenerateId("toc"))); if ($notoc) { $html->setAttr('style','display:none;'); diff --git a/pgsrc/Help%2FCreateTocPlugin b/pgsrc/Help%2FCreateTocPlugin index f25f1ab9d..848093e6d 100644 --- a/pgsrc/Help%2FCreateTocPlugin +++ b/pgsrc/Help%2FCreateTocPlugin @@ -1,4 +1,4 @@ -Date: Fri, 10 Sep 2010 13:46:13 +0000 +Date: Mon, 20 Sep 2010 18:07:40 +0000 Mime-Version: 1.0 (Produced by PhpWiki 1.4.0RC1) X-Rcs-Id: $Id$ Content-Type: application/x-phpwiki; @@ -63,6 +63,10 @@ The Table of Contents can easily be inserted by clicking on the TOC button in th | Table of Contents of which page? | current pagename |- +| **version** +| page version +| most recent version +|- | **position** | Where to display the Table of Contents: full, left or right. | full -- 2.45.0