2 rcs_id('$Id: PageGroup.php,v 1.5 2003-01-18 21:49:00 carstenklapp Exp $');
4 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * <?plugin PageGroup parent=MyTableOfContents ?>
29 * parent=MyTableOfContents
30 * label="Visit more pages in MyTableOfContents"
33 * <?plugin PageGroup parent=MyTableOfContents section=PartTwo loop=true ?>
35 * <?plugin PageGroup parent=MyTableOfContents loop=1 ?>
38 * Updated to use new HTML(). It mostly works, but it's still a giant hackish mess.
40 class WikiPlugin_PageGroup
44 return _("PageGroup");
47 function getDescription() {
48 return sprintf(_("PageGroup for %s"),'[pagename]');
51 function getVersion() {
52 return preg_replace("/[Revision: $]/", '',
56 function getDefaultArguments() {
60 'section' => _("Contents"),
66 // Stolen from IncludePage.php
67 function extractSection ($section, $content, $page) {
68 $qsection = preg_replace('/\s+/', '\s+', preg_quote($section, '/'));
70 if (preg_match("/ ^(!{1,})\\s*$qsection" // section header
71 . " \\s*$\\n?" // possible blank lines
72 . " ( (?: ^.*\\n? )*? )" // some lines
73 . " (?= ^\\1 | \\Z)/xm", // sec header (same or higher level) (or EOF)
74 implode("\n", $content),
76 // Strip trailing blanks lines and ---- <hr>s
77 $text = preg_replace("/\\s*^-{4,}\\s*$/m", "", $match[2]);
78 return explode("\n", $text);
80 return array(sprintf(_("<%s: no such section>"), $page ." ". $section));
83 function run($dbi, $argstr, $request) {
85 $args = $this->getArgs($argstr, $request);
89 // FIXME: WikiPlugin has no way to report when
90 // required args are missing?
91 $error_text = fmt("%s: %s", "WikiPlugin_" .$this->getName(),
93 $error_text .= " " . sprintf(_("A required argument '%s' is missing."), 'parent');
98 $directions = array ('next' => _("Next"),
99 'previous' => _("Previous"),
100 'contents' => _("Contents"),
101 'first' => _("First"),
106 $sep = $Theme->getButtonSeparator();
108 $sep = " | "; // force some kind of separator
112 $label = $Theme->makeLinkButton($parent);
114 // This is where the list extraction occurs from the named
115 // $section on the $parent page.
117 $p = $dbi->getPage($parent);
119 $r = $p->getRevision($rev);
121 $this->error(sprintf(_("%s(%d): no such revision"), $parent,
126 $r = $p->getCurrentRevision();
129 $c = $r->getContent();
130 $c = $this->extractSection($section, $c, $parent);
132 $pagename = $request->getArg('pagename');
134 // The ordered list of page names determines the page
135 // ordering. Right now it doesn't work with a WikiList, only
136 // normal lines of text containing the page names.
138 $thispage = array_search($pagename, $c);
140 $go = array ('previous','next');
142 $links->pushcontent($label);
143 $links->pushcontent(" [ "); // an experiment
144 $lastindex = count($c) - 1; // array is 0-based, count is 1-based!
146 foreach ( $go as $go_item ) {
147 //yuck this smells, needs optimization.
148 if ($go_item == 'previous') {
150 if ($thispage == 0) {
151 $linkpage = $c[$lastindex];
153 $linkpage = $c[$thispage - 1];
155 // mind the French : punctuation
156 $text = fmt("%s: %s", $directions[$go_item],
157 $Theme->makeLinkButton($linkpage));
158 $links->pushcontent($text);
159 $links->pushcontent($sep); // this works because
160 // there are only 2 go
161 // items, previous,next
163 if ($thispage == 0) {
166 $linkpage = $c[$thispage - 1];
167 $text = fmt("%s: %s", $directions[$go_item],
168 $Theme->makeLinkButton($linkpage));
169 $links->pushcontent($text);
170 $links->pushcontent($sep); //this works
176 } else if ($go_item == 'next') {
178 if ($thispage == $lastindex) {
181 $linkpage = $c[$thispage + 1];
183 $text = fmt("%s: %s", $directions[$go_item],
184 $Theme->makeLinkButton($linkpage));
186 if ($thispage == $lastindex) {
189 $linkpage = $c[$thispage + 1];
190 $text = fmt("%s: %s", $directions[$go_item],
191 $Theme->makeLinkButton($linkpage));
194 $links->pushcontent($text);
197 $links->pushcontent(" ] "); // an experiment
202 // $Log: not supported by cvs2svn $
208 // c-hanging-comment-ender-p: nil
209 // indent-tabs-mode: nil