2 rcs_id('$Id: IncludePage.php,v 1.2 2001-12-06 18:26:50 dairiki 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 error($msg) {
41 // FIXME: better error reporting?
42 trigger_error($msg, E_USER_NOTICE);
45 function run($dbi, $argstr, $request) {
47 extract($this->getArgs($argstr, $request));
50 $this->error(_("no page specified"));
54 static $included_pages = array();
55 if ($page == $request->getArg('pagename')
56 || in_array($page, $included_pages)) {
57 $this->error(sprintf(_("recursive inclusion of page %s"), $page));
61 $p = $dbi->getPage($page);
64 $r = $p->getRevision($rev);
66 $this->error(sprintf(_("%s(%d): no such revision"), $page, $rev));
70 $r = $p->getCurrentRevision();
73 $c = $r->getContent();
76 $c = array_slice($c, 0, $lines);
78 $c = $this->firstNWordsOfContent($words, $c);
80 array_push($included_pages, $page);
81 $content = do_transform($c);
82 array_pop($included_pages);
84 if ($quiet) return $content;
86 return Element('p', array('class' => 'transclusion-title'),
87 sprintf(_("Included from %s"), LinkExistingWikiWord($page)))
88 . Element('div', array('class' => 'transclusion'),
93 // This is an excerpt from the css file I use:
95 // .transclusion-title {
96 // font-style: oblique;
98 // text-decoration: underline;
102 // DIV.transclusion {
103 // background: lightgreen;
105 // border-style: solid;
106 // padding-left: 0.8em;
107 // padding-right: 0.8em;
109 // padding-bottom: 0px;
110 // margin: 0.5ex 0px;
114 // - line & word limit doesn't work if the included page itself includes a plugin
115 // - we need an error reporting scheme
122 // c-hanging-comment-ender-p: nil
123 // indent-tabs-mode: nil