2 rcs_id('$Id: IncludePage.php,v 1.3 2001-12-16 16:52:45 carstenklapp Exp $');
4 * IncludePage: include text from another wiki page in this one
5 * usage: <?plugin IncludePage page=OtherPage rev=6 quiet=1 words=50 lines=6?>
6 * author: Joe Edelman <joe@orbis-tertius.net>
9 require_once('lib/transform.php');
11 class WikiPlugin_IncludePage
14 var $name='IncludePage';
15 var $description='Embeds text from another page.';
17 function getDefaultArguments() {
18 return array( 'page' => false, // the page to include
19 'rev' => false, // the revision (defaults to most recent)
20 'quiet' => false, // if set, inclusion appears as normal content
21 'words' => false, // maximum number of words to include
22 'lines' => false // maximum number of lines to include
26 function firstNWordsOfContent( $n, $content ) {
29 foreach ($content as $line) {
30 $words = explode(' ', $line);
31 if ($wordcount + count($words) > $n) {
32 $new[] = implode(' ', array_slice($words, 0, $n - $wordcount))
33 . "... (first $n words)";
36 $wordcount += count($words);
43 function error($msg) {
44 // FIXME: better error reporting?
45 trigger_error($msg, E_USER_NOTICE);
48 function run($dbi, $argstr, $request) {
50 extract($this->getArgs($argstr, $request));
53 $this->error(_("no page specified"));
57 static $included_pages = array();
58 if ($page == $request->getArg('pagename')
59 || in_array($page, $included_pages)) {
60 $this->error(sprintf(_("recursive inclusion of page %s"), $page));
64 $p = $dbi->getPage($page);
67 $r = $p->getRevision($rev);
69 $this->error(sprintf(_("%s(%d): no such revision"), $page, $rev));
73 $r = $p->getCurrentRevision();
76 $c = $r->getContent();
79 $c = array_slice($c, 0, $lines);
81 $c = $this->firstNWordsOfContent($words, $c);
83 array_push($included_pages, $page);
84 $content = do_transform($c);
85 array_pop($included_pages);
87 if ($quiet) return $content;
89 return Element('p', array('class' => 'transclusion-title'),
90 sprintf(_("Included from %s"), LinkExistingWikiWord($page)))
91 . Element('div', array('class' => 'transclusion'),
96 // This is an excerpt from the css file I use:
98 // .transclusion-title {
99 // font-style: oblique;
100 // font-size: 0.75em;
101 // text-decoration: underline;
102 // text-align: right;
105 // DIV.transclusion {
106 // background: lightgreen;
108 // border-style: solid;
109 // padding-left: 0.8em;
110 // padding-right: 0.8em;
112 // padding-bottom: 0px;
113 // margin: 0.5ex 0px;
117 // - line & word limit doesn't work if the included page itself includes a plugin
118 // - we need an error reporting scheme
125 // c-hanging-comment-ender-p: nil
126 // indent-tabs-mode: nil