4 * Copyright 2002,2004,2005 $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 along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * UnfoldSubpages: Lists the content of all SubPages of the current page.
25 * This is e.g. useful for the CalendarPlugin, to see all entries at once.
26 * Warning: Better don't use it with non-existant sections!
27 * The section extractor is currently quite unstable.
28 * Usage: <<UnfoldSubpages sortby=-mtime words=50 maxpages=5 >>
29 * Author: Reini Urban <rurban@x-ray.at>
32 require_once 'lib/PageList.php';
33 require_once 'lib/TextSearchQuery.php';
34 require_once 'lib/plugin/IncludePage.php';
36 class WikiPlugin_UnfoldSubpages
37 extends WikiPlugin_IncludePage
41 return _("UnfoldSubpages");
44 function getDescription()
46 return _("Include the content of all SubPages of the current page.");
49 function getDefaultArguments()
53 PageList::supportedArgs(),
55 'pagename' => '[pagename]', // default: current page
56 //'header' => '', // expandable string
57 'quiet' => false, // print no header
58 'sortby' => '', // [+|-]pagename, [+|-]mtime, [+|-]hits
59 'maxpages' => false, // maximum number of pages to include (== limit)
60 'smalltitle' => false, // if set, hide transclusion-title,
61 // just have a small link at the start of
63 'words' => false, // maximum number of words
64 // per page to include
65 'lines' => false, // maximum number of lines
66 // per page to include
67 'bytes' => false, // maximum number of bytes
68 // per page to include
69 'sections' => false, // maximum number of sections per page to include
70 'section' => false, // this named section per page only
71 'sectionhead' => false // when including a named
72 // section show the heading
76 function run($dbi, $argstr, &$request, $basepage)
78 static $included_pages = false;
79 if (!$included_pages) $included_pages = array($basepage);
81 $args = $this->getArgs($argstr, $request);
83 $query = new TextSearchQuery($pagename . SUBPAGE_SEPARATOR . '*', true, 'glob');
84 $subpages = $dbi->titleSearch($query, $sortby, $limit, $exclude);
86 // $subpages = $subpages->applyFilters(array('sortby' => $sortby, 'limit' => $limit, 'exclude' => $exclude));
87 //$subpages = explodePageList($pagename . SUBPAGE_SEPARATOR . '*', false,
88 // $sortby, $limit, $exclude);
89 if (is_string($exclude) and !is_array($exclude))
90 $exclude = PageList::explodePageList($exclude, false, false, $limit);
93 include_once 'lib/BlockParser.php';
95 while ($page = $subpages->next()) {
96 $cpagename = $page->getName();
97 if ($maxpages and ($i++ > $maxpages)) {
100 if (in_array($cpagename, $exclude))
102 // A page cannot include itself. Avoid doublettes.
103 if (in_array($cpagename, $included_pages)) {
104 $content->pushContent(HTML::p(sprintf(_("Recursive inclusion of page %s ignored"),
109 // Check if user is allowed to get the Page.
110 if (!mayAccessPage('view', $cpagename)) {
111 return $this->error(sprintf(_("Illegal inclusion of page %s: no read access."),
115 // trap any remaining nonexistant subpages
116 if ($page->exists()) {
117 $r = $page->getCurrentRevision();
118 $c = $r->getContent(); // array of lines
120 if ((preg_match('/<' . '\?plugin\s+RedirectTo\s+page=(\S+)\s*\?' . '>/', implode("\n", $c), $m))
121 or (preg_match('/<' . '\?plugin\s+RedirectTo\s+page=(.*?)\s*\?' . '>/', implode("\n", $c), $m))
122 or (preg_match('/<<\s*RedirectTo\s+page=(\S+)\s*>>/', implode("\n", $c), $m))
123 or (preg_match('/<<\s*RedirectTo\s+page="(.*?)"\s*>>/', implode("\n", $c), $m))
125 // Strip quotes (simple or double) from page name if any
126 if ((string_starts_with($m[1], "'"))
127 or (string_starts_with($m[1], "\""))
129 $m[1] = substr($m[1], 1, -1);
131 // trap recursive redirects
132 if (in_array($m[1], $included_pages)) {
134 $content->pushContent(
135 HTML::p(sprintf(_("Recursive inclusion of page %s ignored"),
136 $cpagename . ' => ' . $m[1])));
141 // Check if user is allowed to get the Page.
142 if (!mayAccessPage('view', $cpagename)) {
143 return $this->error(sprintf(_("Illegal inclusion of page %s: no read access."),
147 $page = $dbi->getPage($cpagename);
148 $r = $page->getCurrentRevision();
149 $c = $r->getContent(); // array of lines
152 // moved to IncludePage
153 $ct = $this->extractParts($c, $cpagename, $args);
155 array_push($included_pages, $cpagename);
157 $pname = array_pop(explode(SUBPAGE_SEPARATOR, $cpagename)); // get last subpage name
158 // Use _("%s: %s") instead of .": ". for French punctuation
159 $ct = TransformText(sprintf(_("%s: %s"), "[$pname|$cpagename]",
161 $r->get('markup'), $cpagename);
163 $ct = TransformText($ct, $r->get('markup'), $cpagename);
165 array_pop($included_pages);
167 $content->pushContent(HTML::p(array('class' => $quiet ?
168 '' : 'transclusion-title'),
169 fmt("Included from %s", WikiLink($cpagename))));
171 $content->pushContent(HTML(HTML::div(array('class' => $quiet ?
172 '' : 'transclusion'),
176 if (!isset($cpagename)) {
177 return $this->error(sprintf(_("%s has no subpages defined."), $pagename));
187 // c-hanging-comment-ender-p: nil
188 // indent-tabs-mode: nil