2 rcs_id('$Id: PageGroup.php,v 1.7 2004-05-03 15:53:20 rurban Exp $');
4 Copyright 1999,2000,2001,2002,2004 $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, '/'));
69 if (preg_match("/ ^(!{1,})\\s*$qsection" // section header
70 . " \\s*$\\n?" // possible blank lines
71 . " ( (?: ^.*\\n? )*? )" // some lines
72 . " (?= ^\\1 | \\Z)/xm", // sec header (same or higher level) (or EOF)
73 implode("\n", $content),
76 //FIXME: return list of Wiki_Pagename objects
77 foreach (explode("\n", $match[2]) as $line) {
79 // Strip trailing blanks lines and ---- <hr>s
80 $text = preg_replace("/\\s*^-{4,}\\s*$/", "", $text);
81 // Strip leading list chars: * or #
82 $text = preg_replace("/^[\*#]+\s*(\S.+)$/", "\\1", $text);
83 // Strip surrounding []
84 // FIXME: parse [ name | link ]
85 $text = preg_replace("/^\[\s*(\S.+)\s*\]$/", "\\1", $text);
91 return array(sprintf(_("<%s: no such section>"), $page ." ". $section));
94 function run($dbi, $argstr, &$request, $basepage) {
96 $args = $this->getArgs($argstr, $request);
100 // FIXME: WikiPlugin has no way to report when
101 // required args are missing?
102 $error_text = fmt("%s: %s", "WikiPlugin_" .$this->getName(),
104 $error_text .= " " . sprintf(_("A required argument '%s' is missing."), 'parent');
108 $directions = array ('next' => _("Next"),
109 'previous' => _("Previous"),
110 'contents' => _("Contents"),
111 'first' => _("First"),
116 $sep = $Theme->getButtonSeparator();
118 $sep = " | "; // force some kind of separator
122 $label = $Theme->makeLinkButton($parent);
124 // This is where the list extraction occurs from the named
125 // $section on the $parent page.
127 $p = $dbi->getPage($parent);
129 $r = $p->getRevision($rev);
131 $this->error(sprintf(_("%s(%d): no such revision"), $parent,
136 $r = $p->getCurrentRevision();
139 $c = $r->getContent();
140 $c = $this->extractSection($section, $c, $parent);
142 $pagename = $request->getArg('pagename');
144 // The ordered list of page names determines the page
145 // ordering. Right now it doesn't work with a WikiList, only
146 // normal lines of text containing the page names.
148 $thispage = array_search($pagename, $c);
150 $go = array ('previous','next');
152 $links->pushcontent($label);
153 $links->pushcontent(" [ "); // an experiment
154 $lastindex = count($c) - 1; // array is 0-based, count is 1-based!
156 foreach ( $go as $go_item ) {
157 //yuck this smells, needs optimization.
158 if ($go_item == 'previous') {
160 if ($thispage == 0) {
161 $linkpage = $c[$lastindex];
163 $linkpage = $c[$thispage - 1];
165 // mind the French : punctuation
166 $text = fmt("%s: %s", $directions[$go_item],
167 $Theme->makeLinkButton($linkpage));
168 $links->pushcontent($text);
169 $links->pushcontent($sep); // this works because
170 // there are only 2 go
171 // items, previous,next
173 if ($thispage == 0) {
176 $linkpage = $c[$thispage - 1];
177 $text = fmt("%s: %s", $directions[$go_item],
178 $Theme->makeLinkButton($linkpage));
179 $links->pushcontent($text);
180 $links->pushcontent($sep); //this works
186 } else if ($go_item == 'next') {
188 if ($thispage == $lastindex) {
191 $linkpage = $c[$thispage + 1];
193 $text = fmt("%s: %s", $directions[$go_item],
194 $Theme->makeLinkButton($linkpage));
196 if ($thispage == $lastindex) {
199 $linkpage = $c[$thispage + 1];
200 $text = fmt("%s: %s", $directions[$go_item],
201 $Theme->makeLinkButton($linkpage));
204 $links->pushcontent($text);
207 $links->pushcontent(" ] "); // an experiment
212 // $Log: not supported by cvs2svn $
213 // Revision 1.6 2004/02/17 12:11:36 rurban
214 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
216 // Revision 1.5 2003/01/18 21:49:00 carstenklapp
218 // Reformatting & tabs to spaces;
219 // Added copyleft, getVersion, getDescription, rcs_id.
226 // c-hanging-comment-ender-p: nil
227 // indent-tabs-mode: nil