1 <?php rcs_id('$Id: PageGroup.php,v 1.4 2002-02-16 02:08:26 carstenklapp Exp $');
5 * <?plugin PageGroup parent=MyTableOfContents ?>
7 * <?plugin PageGroup parent=MyTableOfContents label="Visit more pages in MyTableOfContents" ?>
9 * <?plugin PageGroup parent=MyTableOfContents section=PartTwo loop=true ?>
11 * <?plugin PageGroup parent=MyTableOfContents loop=1 ?>
14 * Updated to use new HTML(). It mostly works, but it's still a giant hackish mess.
16 class WikiPlugin_PageGroup
20 return _("PageGroup");
23 function getDescription() {
24 return sprintf(_("PageGroup for %s"),'[pagename]');
27 function getDefaultArguments() {
31 'section' => _("Contents"),
37 // Stolen from IncludePage.php
38 function extractSection ($section, $content, $page) {
39 $qsection = preg_replace('/\s+/', '\s+', preg_quote($section, '/'));
41 if (preg_match("/ ^(!{1,})\\s*$qsection" // section header
42 . " \\s*$\\n?" // possible blank lines
43 . " ( (?: ^.*\\n? )*? )" // some lines
44 . " (?= ^\\1 | \\Z)/xm", // sec header (same or higher level) (or EOF)
45 implode("\n", $content),
47 // Strip trailing blanks lines and ---- <hr>s
48 $text = preg_replace("/\\s*^-{4,}\\s*$/m", "", $match[2]);
49 return explode("\n", $text);
51 return array(sprintf(_("<%s: no such section>"), $page ." ". $section));
54 function run($dbi, $argstr, $request) {
56 $args = $this->getArgs($argstr, $request);
60 // FIXME: WikiPlugin has no way to report when
61 // required args are missing?
62 $error_text = fmt("%s: %s", "WikiPlugin_" .$this->getName(),
64 $error_text .= " " . sprintf(_("A required argument '%s' is missing."),
70 $directions = array ('next' => _("Next"),
71 'previous' => _("Previous"),
72 'contents' => _("Contents"),
73 'first' => _("First"),
78 $sep = $Theme->getButtonSeparator();
80 $sep = " | "; // force some kind of separator
84 $label = $Theme->makeLinkButton($parent);
86 // This is where the list extraction occurs from the named
87 // $section on the $parent page.
89 $p = $dbi->getPage($parent);
91 $r = $p->getRevision($rev);
93 $this->error(sprintf(_("%s(%d): no such revision"), $parent,
98 $r = $p->getCurrentRevision();
101 $c = $r->getContent();
102 $c = $this->extractSection($section, $c, $parent);
104 $pagename = $request->getArg('pagename');
106 // The ordered list of page names determines the page
107 // ordering. Right now it doesn't work with a WikiList, only
108 // normal lines of text containing the page names.
110 $thispage = array_search($pagename, $c);
112 $go = array ('previous','next');
114 $links->pushcontent($label);
115 $links->pushcontent(" [ "); // an experiment
116 $lastindex = count($c) - 1; // array is 0-based, count is 1-based!
118 foreach ( $go as $go_item ) {
119 //yuck this smells, needs optimization.
120 if ($go_item == 'previous') {
122 if ($thispage == 0) {
123 $linkpage = $c[$lastindex];
125 $linkpage = $c[$thispage - 1];
127 // mind the French : punctuation
128 $text = fmt("%s: %s", $directions[$go_item], $Theme->makeLinkButton($linkpage));
129 $links->pushcontent($text);
130 $links->pushcontent($sep); //this works because there are only 2 go items, previous,next
132 if ($thispage == 0) {
135 $linkpage = $c[$thispage - 1];
136 $text = fmt("%s: %s", $directions[$go_item], $Theme->makeLinkButton($linkpage));
137 $links->pushcontent($text);
138 $links->pushcontent($sep); //this works because there are only 2 go items, previous,next
141 } else if ($go_item == 'next') {
143 if ($thispage == $lastindex) {
146 $linkpage = $c[$thispage + 1];
148 $text = fmt("%s: %s", $directions[$go_item], $Theme->makeLinkButton($linkpage));
150 if ($thispage == $lastindex) {
153 $linkpage = $c[$thispage + 1];
154 $text = fmt("%s: %s", $directions[$go_item], $Theme->makeLinkButton($linkpage));
157 $links->pushcontent($text);
160 $links->pushcontent(" ] "); // an experiment
171 // c-hanging-comment-ender-p: nil
172 // indent-tabs-mode: nil