4 * Copyright 1999,2000,2001,2002,2004 $ThePhpWikiProgrammingTeam
5 * Copyright 2009 Marc-Etienne Vargenau, Alcatel-Lucent
7 * This file is part of PhpWiki.
9 * PhpWiki is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * PhpWiki is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with PhpWiki; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * <?plugin PageGroup parent=MyTableOfContents ?>
30 * parent=MyTableOfContents
31 * label="Visit more pages in MyTableOfContents"
34 * <?plugin PageGroup parent=MyTableOfContents section=PartTwo loop=true ?>
36 * <?plugin PageGroup parent=MyTableOfContents loop=1 ?>
39 * Updated to use new HTML(). It mostly works, but it's still a giant hackish mess.
41 class WikiPlugin_PageGroup
45 return _("PageGroup");
48 function getDescription() {
49 return sprintf(_("PageGroup for %s"),'[pagename]');
52 function getDefaultArguments() {
56 'section' => _("Contents"),
62 // Stolen from IncludePage.php
63 function extractGroupSection ($section, $content, $page) {
64 $qsection = preg_replace('/\s+/', '\s+', preg_quote($section, '/'));
65 if (preg_match("/ ^(!{1,})\\s*$qsection" // section header
66 . " \\s*$\\n?" // possible blank lines
67 . " ( (?: ^.*\\n? )*? )" // some lines
68 . " (?= ^\\1 | \\Z)/xm", // sec header (same or higher level) (or EOF)
69 implode("\n", $content),
72 //FIXME: return list of Wiki_Pagename objects
73 foreach (explode("\n", $match[2]) as $line) {
75 // Strip trailing blanks lines and ---- <hr>s
76 $text = preg_replace("/\\s*^-{4,}\\s*$/", "", $text);
77 // Strip leading list chars: * or #
78 $text = preg_replace("/^[\*#]+\s*(\S.+)$/", "\\1", $text);
79 // Strip surrounding []
80 // FIXME: parse [ name | link ]
81 $text = preg_replace("/^\[\s*(\S.+)\s*\]$/", "\\1", $text);
87 return array(sprintf(_("<%s: no such section>"), $page ." ". $section));
90 function run($dbi, $argstr, &$request, $basepage) {
92 $args = $this->getArgs($argstr, $request);
95 // FIXME: WikiPlugin has no way to report when
96 // required args are missing?
97 $error_text = sprintf("%s: ", "WikiPlugin_" .$this->getName());
98 $error_text .= sprintf(_("A required argument '%s' is missing."), 'parent');
99 return HTML::div(array('class' => "error"), $error_text);
101 $directions = array ('next' => _("Next"),
102 'previous' => _("Previous"),
103 'contents' => _("Contents"),
104 'first' => _("First"),
109 $sep = $WikiTheme->getButtonSeparator();
111 $sep = " | "; // force some kind of separator
115 $label = $WikiTheme->makeLinkButton($parent);
117 // This is where the list extraction occurs from the named
118 // $section on the $parent page.
120 $p = $dbi->getPage($parent);
122 $r = $p->getRevision($rev);
124 $this->error(sprintf(_("%s(%d): no such revision"), $parent,
129 $r = $p->getCurrentRevision();
132 $c = $r->getContent();
133 $c = $this->extractGroupSection($section, $c, $parent);
135 $pagename = $request->getArg('pagename');
137 // The ordered list of page names determines the page
138 // ordering. Right now it doesn't work with a WikiList, only
139 // normal lines of text containing the page names.
141 $thispage = array_search($pagename, $c);
143 $go = array ('previous','next');
145 $links->pushcontent($label);
146 $links->pushcontent(" [ "); // an experiment
147 $lastindex = count($c) - 1; // array is 0-based, count is 1-based!
149 foreach ( $go as $go_item ) {
150 //yuck this smells, needs optimization.
151 if ($go_item == 'previous') {
153 if ($thispage == 0) {
154 $linkpage = $c[$lastindex];
156 $linkpage = $c[$thispage - 1];
158 // mind the French : punctuation
159 $text = fmt("%s: %s", $directions[$go_item],
160 $WikiTheme->makeLinkButton($linkpage));
161 $links->pushcontent($text);
162 $links->pushcontent($sep); // this works because
163 // there are only 2 go
164 // items, previous,next
166 if ($thispage == 0) {
169 $linkpage = $c[$thispage - 1];
170 $text = fmt("%s: %s", $directions[$go_item],
171 $WikiTheme->makeLinkButton($linkpage));
172 $links->pushcontent($text);
173 $links->pushcontent($sep); //this works
179 } else if ($go_item == 'next') {
181 if ($thispage == $lastindex) {
184 $linkpage = $c[$thispage + 1];
186 $text = fmt("%s: %s", $directions[$go_item],
187 $WikiTheme->makeLinkButton($linkpage));
189 if ($thispage == $lastindex) {
192 $linkpage = $c[$thispage + 1];
193 $text = fmt("%s: %s", $directions[$go_item],
194 $WikiTheme->makeLinkButton($linkpage));
197 $links->pushcontent($text);
200 $links->pushcontent(" ] "); // an experiment
209 // c-hanging-comment-ender-p: nil
210 // indent-tabs-mode: nil