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 along
20 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * <<PageGroup parent=MyTableOfContents >>
30 * parent=MyTableOfContents
31 * label="Visit more pages in MyTableOfContents"
34 * <<PageGroup parent=MyTableOfContents section=PartTwo loop=true >>
36 * <<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
44 function getDescription()
46 return sprintf(_("PageGroup for %s."), '[pagename]');
49 function getDefaultArguments()
54 'section' => _("Contents"),
60 // Stolen from IncludePage.php
61 function extractGroupSection($section, $content, $page)
63 $qsection = preg_replace('/\s+/', '\s+', preg_quote($section, '/'));
64 if (preg_match("/ ^(!{1,})\\s*$qsection" // section header
65 . " \\s*$\\n?" // possible blank lines
66 . " ( (?: ^.*\\n? )*? )" // some lines
67 . " (?= ^\\1 | \\Z)/xm", // sec header (same or higher level) (or EOF)
68 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)
93 $args = $this->getArgs($argstr, $request);
96 return $this->error(sprintf(_("A required argument ā%sā is missing."), 'parent'));
98 $directions = array('next' => _("Next"),
99 'previous' => _("Previous"),
100 'contents' => _("Contents"),
101 'first' => _("First"),
106 $sep = $WikiTheme->getButtonSeparator();
108 $sep = " | "; // force some kind of separator
112 $label = $WikiTheme->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);
120 if ((!$r) || ($r->hasDefaultContents())) {
121 return $this->error(sprintf(_("%s: no such revision %d."),
125 $r = $p->getCurrentRevision();
128 $c = $r->getContent();
129 $c = $this->extractGroupSection($section, $c, $parent);
131 $pagename = $request->getArg('pagename');
133 // The ordered list of page names determines the page
134 // ordering. Right now it doesn't work with a WikiList, only
135 // normal lines of text containing the page names.
137 $thispage = array_search($pagename, $c);
139 $go = array('previous', 'next');
141 $links->pushcontent($label);
142 $links->pushcontent(" [ "); // an experiment
143 $lastindex = count($c) - 1; // array is 0-based, count is 1-based!
145 foreach ($go as $go_item) {
146 //yuck this smells, needs optimization.
147 if ($go_item == 'previous') {
149 if ($thispage == 0) {
150 $linkpage = $c[$lastindex];
152 $linkpage = $c[$thispage - 1];
154 // mind the French : punctuation
155 $text = fmt("%s: %s", $directions[$go_item],
156 $WikiTheme->makeLinkButton($linkpage));
157 $links->pushcontent($text);
158 $links->pushcontent($sep); // this works because
159 // there are only 2 go
160 // items, previous,next
162 if ($thispage == 0) {
165 $linkpage = $c[$thispage - 1];
166 $text = fmt("%s: %s", $directions[$go_item],
167 $WikiTheme->makeLinkButton($linkpage));
168 $links->pushcontent($text);
169 $links->pushcontent($sep); //this works
175 } elseif ($go_item == 'next') {
177 if ($thispage == $lastindex) {
180 $linkpage = $c[$thispage + 1];
182 $text = fmt("%s: %s", $directions[$go_item],
183 $WikiTheme->makeLinkButton($linkpage));
185 if ($thispage == $lastindex) {
188 $linkpage = $c[$thispage + 1];
189 $text = fmt("%s: %s", $directions[$go_item],
190 $WikiTheme->makeLinkButton($linkpage));
193 $links->pushcontent($text);
196 $links->pushcontent(" ] "); // an experiment
205 // c-hanging-comment-ender-p: nil
206 // indent-tabs-mode: nil