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