]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/IncludePage.php
just whitespace
[SourceForge/phpwiki.git] / lib / plugin / IncludePage.php
1 <?php // -*-php-*-
2 rcs_id('$Id: IncludePage.php,v 1.27 2004-11-17 20:07:18 rurban Exp $');
3 /*
4  Copyright 1999, 2000, 2001, 2002 $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 /**
25  * IncludePage:  include text from another wiki page in this one
26  * usage:   <?plugin IncludePage page=OtherPage rev=6 quiet=1 words=50 lines=6?>
27  * author:  Joe Edelman <joe@orbis-tertius.net>
28  */
29
30 class WikiPlugin_IncludePage
31 extends WikiPlugin
32 {
33     function getName() {
34         return _("IncludePage");
35     }
36
37     function getDescription() {
38         return _("Include text from another wiki page.");
39     }
40
41     function getVersion() {
42         return preg_replace("/[Revision: $]/", '',
43                             "\$Revision: 1.27 $");
44     }
45
46     function getDefaultArguments() {
47         return array( 'page'    => false, // the page to include
48                       'rev'     => false, // the revision (defaults to most recent)
49                       'quiet'   => false, // if set, inclusion appears as normal content
50                       'words'   => false, // maximum number of words to include
51                       'lines'   => false, // maximum number of lines to include
52                       'section' => false, // include a named section
53                       'sectionhead' => false // when including a named section show the heading
54                       );
55     }
56
57     function getWikiPageLinks($argstr, $basepage) {
58         extract($this->getArgs($argstr));
59
60         if ($page) {
61             // Expand relative page names.
62             $page = new WikiPageName($page, $basepage);
63         }
64         if (!$page or !$page->name)
65             return false;
66         return array($page->name);
67     }
68                 
69     function run($dbi, $argstr, &$request, $basepage) {
70         extract($this->getArgs($argstr, $request));
71         if ($page) {
72             // Expand relative page names.
73             $page = new WikiPageName($page, $basepage);
74             $page = $page->name;
75         }
76         if (!$page) {
77             return $this->error(_("no page specified"));
78         }
79
80         // A page can include itself once (this is needed, e.g.,  when editing
81         // TextFormattingRules).
82         static $included_pages = array();
83         if (in_array($page, $included_pages)) {
84             return $this->error(sprintf(_("recursive inclusion of page %s"),
85                                         $page));
86         }
87
88         $p = $dbi->getPage($page);
89         if ($rev) {
90             $r = $p->getRevision($rev);
91             if (!$r) {
92                 return $this->error(sprintf(_("%s(%d): no such revision"),
93                                             $page, $rev));
94             }
95         } else {
96             $r = $p->getCurrentRevision();
97         }
98         $c = $r->getContent();
99
100         if ($section)
101             $c = extractSection($section, $c, $page, $quiet, $sectionhead);
102         if ($lines)
103             $c = array_slice($c, 0, $lines);
104         if ($words)
105             $c = firstNWordsOfContent($words, $c);
106
107         array_push($included_pages, $page);
108
109         include_once('lib/BlockParser.php');
110         $content = TransformText(implode("\n", $c), $r->get('markup'), $page);
111
112         array_pop($included_pages);
113
114         if ($quiet)
115             return $content;
116
117         return HTML(HTML::p(array('class' => 'transclusion-title'),
118                             fmt("Included from %s", WikiLink($page))),
119
120                     HTML::div(array('class' => 'transclusion'),
121                               false, $content));
122     }
123 };
124
125 // This is an excerpt from the css file I use:
126 //
127 // .transclusion-title {
128 //   font-style: oblique;
129 //   font-size: 0.75em;
130 //   text-decoration: underline;
131 //   text-align: right;
132 // }
133 //
134 // DIV.transclusion {
135 //   background: lightgreen;
136 //   border: thin;
137 //   border-style: solid;
138 //   padding-left: 0.8em;
139 //   padding-right: 0.8em;
140 //   padding-top: 0px;
141 //   padding-bottom: 0px;
142 //   margin: 0.5ex 0px;
143 // }
144
145 // KNOWN ISSUES:
146 // - line & word limit doesn't work if the included page itself
147 //   includes a plugin
148
149
150 // $Log: not supported by cvs2svn $
151 // Revision 1.26  2004/09/25 16:35:09  rurban
152 // use stdlib firstNWordsOfContent, extractSection
153 //
154 // Revision 1.25  2004/07/08 20:30:07  rurban
155 // plugin->run consistency: request as reference, added basepage.
156 // encountered strange bug in AllPages (and the test) which destroys ->_dbi
157 //
158 // Revision 1.24  2004/02/17 12:11:36  rurban
159 // 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, ...)
160 //
161 // Revision 1.23  2003/03/25 21:01:52  dairiki
162 // Remove debugging cruft.
163 //
164 // Revision 1.22  2003/03/13 18:57:56  dairiki
165 // Hack so that (when using the IncludePage plugin) the including page shows
166 // up in the BackLinks of the included page.
167 //
168 // Revision 1.21  2003/02/21 04:12:06  dairiki
169 // Minor fixes for new cached markup.
170 //
171 // Revision 1.20  2003/01/18 21:41:02  carstenklapp
172 // Code cleanup:
173 // Reformatting & tabs to spaces;
174 // Added copyleft, getVersion, getDescription, rcs_id.
175 //
176
177 // For emacs users
178 // Local Variables:
179 // mode: php
180 // tab-width: 8
181 // c-basic-offset: 4
182 // c-hanging-comment-ender-p: nil
183 // indent-tabs-mode: nil
184 // End:
185 ?>