]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/UnfoldSubpages.php
enable action=remove which is undoable and seeable in RecentChanges: ADODB ony for...
[SourceForge/phpwiki.git] / lib / plugin / UnfoldSubpages.php
1 <?php // -*-php-*-
2 rcs_id('$Id: UnfoldSubpages.php,v 1.18 2004-12-06 19:50:05 rurban Exp $');
3 /*
4  Copyright 2002, 2004 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
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.
12
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.
17
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
21  */
22
23 /**
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:   <?plugin UnfoldSubpages sortby=-mtime words=50 maxpages=5 ?>
29  * Author:  Reini Urban <rurban@x-ray.at>
30  */
31 include_once("lib/PageList.php");
32 class WikiPlugin_UnfoldSubpages
33 extends WikiPlugin
34 {
35     function getName() {
36         return _("UnfoldSubpages");
37     }
38
39     function getDescription () {
40         return _("Includes the content of all SubPages of the current page.");
41     }
42
43     function getVersion() {
44         return preg_replace("/[Revision: $]/", '',
45                             "\$Revision: 1.18 $");
46     }
47
48     function getDefaultArguments() {
49         return array_merge
50             (
51              PageList::supportedArgs(),
52              array(
53                    'pagename' => '[pagename]', // default: current page
54                    //'header'  => '',  // expandable string
55                    'quiet'   => false, // print no header
56                    'sortby'   => 'pagename', // [+|-]pagename, [+|-]mtime, [+|-]hits
57                    'maxpages' => false, // maximum number of pages to include
58                    'sections' => false, // maximum number of sections per page to include
59                    'smalltitle' => false, // if set, hide transclusion-title,
60                                         //  just have a small link at the start of 
61                                         //  the page.
62                    'words'   => false,  // maximum number of words
63                                         //  per page to include
64                    'lines'   => false,  // maximum number of lines
65                                         //  per page to include
66                    'bytes'   => false,  // maximum number of bytes
67                                         //  per page to include
68                    'section' => false,  // this named section per page only
69                    'sectionhead' => false // when including a named
70                                         //  section show the heading
71                    ));
72     }
73
74     function run($dbi, $argstr, &$request, $basepage) {
75         static $included_pages = false;
76         if (!$included_pages) $included_pages = array($basepage);
77         
78         $args = $this->getArgs($argstr, $request);
79         extract($args);
80         $subpages = explodePageList($pagename . SUBPAGE_SEPARATOR . '*', false, $sortby, $limit, $exclude);
81         if (! $subpages ) {
82             return $this->error(_("The current page has no subpages defined."));
83         }           
84         $content = HTML();
85         if ($maxpages) {
86           $subpages = array_slice ($subpages, 0, $maxpages);
87         }
88
89         include_once('lib/BlockParser.php');
90
91         foreach ($subpages as $page) {
92             // A page cannot include itself. Avoid doublettes.
93             if (in_array($page, $included_pages)) {
94                 $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"),
95                                                       $page)));
96                 continue;
97             }
98             // trap any remaining nonexistant subpages
99             if ($dbi->isWikiPage($page)) {
100                 $p = $dbi->getPage($page);
101                 $r = $p->getCurrentRevision();
102                 $c = $r->getContent();
103                 $ct = implode("\n", $c);
104                 // trap recursive redirects
105                 if (preg_match('/<'.'\?plugin\s+RedirectTo\s+page=(\w+)\s+\?'.'>/',$ct,$m)) {
106                     if (in_array($m[1], $included_pages)) {
107                         //$content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"),
108                         //                              $page.' => '.$m[1])));
109                         continue;
110                     }
111                 }
112                 if ($section)
113                     $c = extractSection($section, $c, $page, $quiet,
114                                         $sectionhead);
115                 if ($lines)
116                     $c = array_slice($c, 0, $lines)
117                         . sprintf(_(" ... first %d lines"), $bytes);
118                 if ($words)
119                     $c = firstNWordsOfContent($words, $c);
120                 if ($bytes) {
121                     if (strlen($c) > $bytes)
122                         $c = substr($c, 0, $bytes)
123                             . sprintf(_(" ... first %d bytes"), $bytes);
124                 }
125
126                 array_push($included_pages, $page);
127                 if ($smalltitle) {
128                     $pname = array_pop(explode("/", $page)); // get last subpage name
129                     // Use _("%s: %s") instead of .": ". for French punctuation
130                     $ct = TransformText(sprintf(_("%s: %s"), "[$pname|$page]",
131                                                 $ct),
132                                         $r->get('markup'), $page);
133                 }
134                 else {
135                     $ct = TransformText($ct, $r->get('markup'), $page);
136                 }
137                 array_pop($included_pages);
138                 if (! $smalltitle) {
139                     $content->pushContent(HTML::p(array('class' => $quiet ?
140                                                         '' : 'transclusion-title'),
141                                                   fmt("Included from %s:",
142                                                       WikiLink($page))));
143                 }
144                 $content->pushContent(HTML(HTML::div(array('class' => $quiet ?
145                                                            '' : 'transclusion'),
146                                                      false, $ct)));
147             }
148         }
149         return $content;
150     }
151 };
152
153 // $Log: not supported by cvs2svn $
154 // Revision 1.17  2004/11/23 15:17:19  rurban
155 // better support for case_exact search (not caseexact for consistency),
156 // plugin args simplification:
157 //   handle and explode exclude and pages argument in WikiPlugin::getArgs
158 //     and exclude in advance (at the sql level if possible)
159 //   handle sortby and limit from request override in WikiPlugin::getArgs
160 // ListSubpages: renamed pages to maxpages
161 //
162 // Revision 1.16  2004/09/25 16:35:09  rurban
163 // use stdlib firstNWordsOfContent, extractSection
164 //
165 // Revision 1.15  2004/07/03 14:48:18  rurban
166 // Tested new mysql 4.1.3-beta: binary search bug as fixed.
167 // => fixed action=upgrade,
168 // => version check in PearDB also (as in ADODB)
169 //
170 // Revision 1.14  2004/07/03 08:19:40  rurban
171 // trap recursive redirects
172 //
173 // Revision 1.13  2004/03/12 15:48:08  rurban
174 // fixed explodePageList: wrong sortby argument order in UnfoldSubpages
175 // simplified lib/stdlib.php:explodePageList
176 //
177 // Revision 1.12  2004/02/22 23:20:33  rurban
178 // fixed DumpHtmlToDir,
179 // enhanced sortby handling in PageList
180 //   new button_heading th style (enabled),
181 // added sortby and limit support to the db backends and plugins
182 //   for paging support (<<prev, next>> links on long lists)
183 //
184 // Revision 1.11  2004/02/17 12:11:36  rurban
185 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
186 //
187 // Revision 1.10  2004/01/27 12:10:45  rurban
188 // fixed UnfoldSubpages and added docs.
189 // new arguments: pagename, maxpages
190 // some arguments are deprecated: sort (use sortby), pages (use maxpages)
191 // fixed sortby, added docs
192 //
193 // Revision 1.9  2004/01/26 09:18:00  rurban
194 // * changed stored pref representation as before.
195 //   the array of objects is 1) bigger and 2)
196 //   less portable. If we would import packed pref
197 //   objects and the object definition was changed, PHP would fail.
198 //   This doesn't happen with an simple array of non-default values.
199 // * use $prefs->retrieve and $prefs->store methods, where retrieve
200 //   understands the interim format of array of objects also.
201 // * simplified $prefs->get() and fixed $prefs->set()
202 // * added $user->_userid and class '_WikiUser' portability functions
203 // * fixed $user object ->_level upgrading, mostly using sessions.
204 //   this fixes yesterdays problems with loosing authorization level.
205 // * fixed WikiUserNew::checkPass to return the _level
206 // * fixed WikiUserNew::isSignedIn
207 // * added explodePageList to class PageList, support sortby arg
208 // * fixed UserPreferences for WikiUserNew
209 // * fixed WikiPlugin for empty defaults array
210 // * UnfoldSubpages: added pagename arg, renamed pages arg,
211 //   removed sort arg, support sortby arg
212 //
213 // Revision 1.8  2004/01/25 10:52:16  rurban
214 // added sortby support to explodePageList() and UnfoldSubpages
215 // fixes [ 758044 ] Plugin UnfoldSubpages does not sort (includes fix)
216 //
217 // Revision 1.7  2003/02/21 04:12:06  dairiki
218 // Minor fixes for new cached markup.
219 //
220 // Revision 1.6  2003/02/11 09:34:34  rurban
221 // fix by Steven D. Brewer <sbrewer@bio.umass.edu> to respect the $pages argument
222 //
223 // Revision 1.5  2003/01/18 22:11:44  carstenklapp
224 // Code cleanup:
225 // Reformatting & tabs to spaces;
226 // Added copyleft, getVersion, getDescription, rcs_id.
227 //
228 // Revision 1.4  2003/01/05 02:37:30  carstenklapp
229 // New: Implemented 'smalltitle' argument and date sorting fix from
230 // Cuthbert Cat's sf patch 655095. Added getVersion & getDescription;
231 // code rewrapping.
232 //
233 // Revision 1.3  2003/01/04 22:46:07  carstenklapp
234 // Workaround: when page has no subpages avoid include of nonexistant pages.
235 //
236
237 // KNOWN ISSUES:
238 // - line & word limit doesn't work if the included page itself
239 //   includes a plugin
240
241 // For emacs users
242 // Local Variables:
243 // mode: php
244 // tab-width: 8
245 // c-basic-offset: 4
246 // c-hanging-comment-ender-p: nil
247 // indent-tabs-mode: nil
248 // End:
249 ?>