2 rcs_id('$Id: IncludePage.php,v 1.4 2001-12-16 18:33:25 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
15 return _("IncludePage");
18 function getDefaultArguments() {
19 return array( 'page' => false, // the page to include
20 'rev' => false, // the revision (defaults to most recent)
21 'quiet' => false, // if set, inclusion appears as normal content
22 'words' => false, // maximum number of words to include
23 'lines' => false // maximum number of lines to include
27 function firstNWordsOfContent( $n, $content ) {
30 foreach ($content as $line) {
31 $words = explode(' ', $line);
32 if ($wordcount + count($words) > $n) {
33 $new[] = implode(' ', array_slice($words, 0, $n - $wordcount))
34 . "... (first $n words)";
37 $wordcount += count($words);
44 function error($msg) {
45 // FIXME: better error reporting?
46 trigger_error($msg, E_USER_NOTICE);
49 function run($dbi, $argstr, $request) {
51 extract($this->getArgs($argstr, $request));
54 $this->error(_("no page specified"));
58 static $included_pages = array();
59 if ($page == $request->getArg('pagename')
60 || in_array($page, $included_pages)) {
61 $this->error(sprintf(_("recursive inclusion of page %s"), $page));
65 $p = $dbi->getPage($page);
68 $r = $p->getRevision($rev);
70 $this->error(sprintf(_("%s(%d): no such revision"), $page, $rev));
74 $r = $p->getCurrentRevision();
77 $c = $r->getContent();
80 $c = array_slice($c, 0, $lines);
82 $c = $this->firstNWordsOfContent($words, $c);
84 array_push($included_pages, $page);
85 $content = do_transform($c);
86 array_pop($included_pages);
88 if ($quiet) return $content;
90 return Element('p', array('class' => 'transclusion-title'),
91 sprintf(_("Included from %s"), LinkExistingWikiWord($page)))
92 . Element('div', array('class' => 'transclusion'),
97 // This is an excerpt from the css file I use:
99 // .transclusion-title {
100 // font-style: oblique;
101 // font-size: 0.75em;
102 // text-decoration: underline;
103 // text-align: right;
106 // DIV.transclusion {
107 // background: lightgreen;
109 // border-style: solid;
110 // padding-left: 0.8em;
111 // padding-right: 0.8em;
113 // padding-bottom: 0px;
114 // margin: 0.5ex 0px;
118 // - line & word limit doesn't work if the included page itself includes a plugin
119 // - we need an error reporting scheme
126 // c-hanging-comment-ender-p: nil
127 // indent-tabs-mode: nil