2 rcs_id('$Id: IncludePage.php,v 1.1 2001-12-02 02:12:21 joe_edelman 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 function getDefaultArguments() {
15 return array( 'page' => false, // the page to include
16 'rev' => false, // the revision (defaults to most recent)
17 'quiet' => false, // if set, inclusion appears as normal content
18 'words' => false, // maximum number of words to include
19 'lines' => false // maximum number of lines to include
23 function firstNWordsOfContent( $n, $content ) {
26 foreach ($content as $line) {
27 $words = explode(' ', $line);
28 if ($wordcount + count($words) > $n) {
29 $new[] = implode(' ', array_slice($words, 0, $n - $wordcount))
30 . "... (first $n words)";
33 $wordcount += count($words);
40 function run($dbi, $argstr, $request) {
41 extract($this->getArgs($argstr, $request));
42 if (!$page) return ''; // FIXME: error reporting?
43 $p = $dbi->getPage($page);
46 $r = $p->getRevision($rev);
47 if (!$r) return ''; // FIXME: error reporting?
49 $r = $p->getCurrentRevision();
52 $c = $r->getContent();
55 $c = array_slice($c, 0, $lines);
57 $c = $this->firstNWordsOfContent($words, $c);
59 $content = do_transform($c);
60 if ($quiet) return $content;
62 '<p class="transclusion-title">Included from '
63 . LinkExistingWikiWord($page)
65 . '<div class="transclusion">' . $content
70 // This is an excerpt from the css file I use:
72 // .transclusion-title {
73 // font-style: oblique;
75 // text-decoration: underline;
80 // background: lightgreen;
82 // border-style: solid;
83 // padding-left: 0.8em;
84 // padding-right: 0.8em;
86 // padding-bottom: 0px;
91 // - line & word limit doesn't work if the included page itself includes a plugin
92 // - we need an error reporting scheme
99 // c-hanging-comment-ender-p: nil
100 // indent-tabs-mode: nil