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
19 * along with PhpWiki; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
40 return _("UnfoldSubpages");
43 function getDescription () {
44 return _("Includes the content of all SubPages of the current page.");
47 function getDefaultArguments() {
50 PageList::supportedArgs(),
52 'pagename' => '[pagename]', // default: current page
53 //'header' => '', // expandable string
54 'quiet' => false, // print no header
55 'sortby' => '', // [+|-]pagename, [+|-]mtime, [+|-]hits
56 'maxpages' => false, // maximum number of pages to include (== limit)
57 'smalltitle' => false, // if set, hide transclusion-title,
58 // just have a small link at the start of
60 'words' => false, // maximum number of words
61 // per page to include
62 'lines' => false, // maximum number of lines
63 // per page to include
64 'bytes' => false, // maximum number of bytes
65 // per page to include
66 'sections' => false, // maximum number of sections per page to include
67 'section' => false, // this named section per page only
68 'sectionhead' => false // when including a named
69 // section show the heading
73 function run($dbi, $argstr, &$request, $basepage) {
74 static $included_pages = false;
75 if (!$included_pages) $included_pages = array($basepage);
77 $args = $this->getArgs($argstr, $request);
79 $query = new TextSearchQuery($pagename . SUBPAGE_SEPARATOR . '*', true, 'glob');
80 $subpages = $dbi->titleSearch($query, $sortby, $limit, $exclude);
82 // $subpages = $subpages->applyFilters(array('sortby' => $sortby, 'limit' => $limit, 'exclude' => $exclude));
83 //$subpages = explodePageList($pagename . SUBPAGE_SEPARATOR . '*', false,
84 // $sortby, $limit, $exclude);
85 if (is_string($exclude) and !is_array($exclude))
86 $exclude = PageList::explodePageList($exclude, false, false, $limit);
89 include_once('lib/BlockParser.php');
91 while ($page = $subpages->next()) {
92 $cpagename = $page->getName();
93 if ($maxpages and ($i++ > $maxpages)) {
96 if (in_array($cpagename, $exclude))
98 // A page cannot include itself. Avoid doublettes.
99 if (in_array($cpagename, $included_pages)) {
100 $content->pushContent(HTML::p(sprintf(_("Recursive inclusion of page %s ignored"),
105 // Check if user is allowed to get the Page.
106 if (!mayAccessPage ('view', $cpagename)) {
107 return $this->error(sprintf(_("Illegal inclusion of page %s: no read access"),
111 // trap any remaining nonexistant subpages
112 if ($page->exists()) {
113 $r = $page->getCurrentRevision();
114 $c = $r->getContent(); // array of lines
116 if ((preg_match('/<'.'\?plugin\s+RedirectTo\s+page=(\S+)\s*\?'.'>/', implode("\n", $c), $m))
117 or (preg_match('/<'.'\?plugin\s+RedirectTo\s+page=(.*?)\s*\?'.'>/', implode("\n", $c), $m))
118 or (preg_match('/<<\s*RedirectTo\s+page=(\S+)\s*>>/', implode("\n", $c), $m))
119 or (preg_match('/<<\s*RedirectTo\s+page="(.*?)"\s*>>/', implode("\n", $c), $m)))
121 // Strip quotes (simple or double) from page name if any
122 if ((string_starts_with($m[1], "'"))
123 or (string_starts_with($m[1], "\""))) {
124 $m[1] = substr($m[1], 1, -1);
126 // trap recursive redirects
127 if (in_array($m[1], $included_pages)) {
129 $content->pushContent(
130 HTML::p(sprintf(_("Recursive inclusion of page %s ignored"),
131 $cpagename.' => '.$m[1])));
136 // Check if user is allowed to get the Page.
137 if (!mayAccessPage ('view', $cpagename)) {
138 return $this->error(sprintf(_("Illegal inclusion of page %s: no read access"),
142 $page = $dbi->getPage($cpagename);
143 $r = $page->getCurrentRevision();
144 $c = $r->getContent(); // array of lines
147 // moved to IncludePage
148 $ct = $this->extractParts ($c, $cpagename, $args);
150 array_push($included_pages, $cpagename);
152 $pname = array_pop(explode(SUBPAGE_SEPARATOR, $cpagename)); // get last subpage name
153 // Use _("%s: %s") instead of .": ". for French punctuation
154 $ct = TransformText(sprintf(_("%s: %s"), "[$pname|$cpagename]",
156 $r->get('markup'), $cpagename);
159 $ct = TransformText($ct, $r->get('markup'), $cpagename);
161 array_pop($included_pages);
163 $content->pushContent(HTML::p(array('class' => $quiet ?
164 '' : 'transclusion-title'),
165 fmt("Included from %s:",
166 WikiLink($cpagename))));
168 $content->pushContent(HTML(HTML::div(array('class' => $quiet ?
169 '' : 'transclusion'),
173 if (! isset($cpagename)) {
174 return $this->error(sprintf(_("%s has no subpages defined."), $pagename));
184 // c-hanging-comment-ender-p: nil
185 // indent-tabs-mode: nil