2 rcs_id('$Id: PageType.php,v 1.17 2003-02-01 03:12:51 carstenklapp Exp $');
4 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 include_once('lib/BlockParser.php');
30 * require_once('lib/PageType.php');
31 * $transformedContent = PageType($pagerevisionhandle, $pagename, $markup);
33 * The pagename and markup args are only required when displaying the
34 * content for an edit preview, otherwise they will be extracted from
35 * the page $revision instance.
37 * See http://phpwiki.sourceforge.net/phpwiki/PageType
39 function PageType(&$rev, $pagename = false, $markup = false, $overridePageType = false) {
41 if (isa($rev, 'WikiDB_PageRevision')) {
42 $text = $rev->getPackedContent();
43 $pagename = $rev->getPageName();
44 $markup = $rev->get('markup');
48 // Hopefully only an edit preview gets us here, else we might
50 if ($pagename == false) {
51 //debugging message only
52 $error_text = "DEBUG: \$rev was not a 'WikiDB_PageRevision'. (Are you not previewing a page edit?)";
53 trigger_error($error_text, E_USER_NOTICE);
58 // PageType currently only works with InterWikiMap and WikiBlog.
59 // Once a contentType field has been implemented in the database
60 // then that can be used instead of this pagename check.
63 * Hook to allow plugins to provide their own or override a PageType.
64 * See InterWikiSearch plugin.
66 if ($overridePageType) {
67 $ContentTemplateName = '$overridePageType';
68 $content_template = new $overridePageType($text, $markup);
69 //trigger_error(sprintf("DEBUG: PageType overridden as %s", $overridePageType));
73 * Check whether pagename is InterWikiMap.
75 $isInterWikiMap = _("InterWikiMap");
78 * Check whether pagename indicates a blog. Adapted from the
81 // get subpage basename, don't forget subpages of subpages
82 $basename = explode(SUBPAGE_SEPARATOR, $pagename);
84 $escpage = implode(SUBPAGE_SEPARATOR, $basename);
85 // from WikiBlog plugin:
86 // If page contains '/', we must escape them
87 // FIXME: only works for '/' SUBPAGE_SEPARATOR
88 $escpage = preg_replace ("/\//", '\/', $escpage);
89 if (preg_match("/^$escpage\/Blog-([[:digit:]]{14})$/", $pagename, $matches))
90 $isWikiBlog = $pagename;
96 $ContentTemplateName = 'interwikimap';
97 $content_template = new interWikiMapPageType($text, $markup);
98 //trigger_error("DEBUG: PageType is an InterWikiMap");
101 $ContentTemplateName = 'wikiblog';
102 $content_template = new wikiBlogPageType($text, $markup);
103 $content_template->_summary = $rev->get('summary');
104 //trigger_error("DEBUG: PageType is a WikiBlog");
107 $ContentTemplateName = 'wikitext';
108 $content_template = new PageType($text, $markup);
109 //trigger_error("DEBUG: PageType is default");
112 return $content_template->getContent();
116 * The basic PageType formats a standard WikiPage with one section:
123 * This is a simple WikiPage
126 var $_markup = false;
127 var $_divs = array();
129 function PageType (&$content, $markup) {
130 $this->_content = $content;
131 $this->_markup = $markup;
132 $this->_html = HTML();
136 function _defineSections() {
138 * ... section_id => ('css_class', $this->_section_function)
140 $this->_divs = array('wikitext' => array('wikitext',
141 $this->_extractText()));
144 function _populateSections() {
145 foreach ($this->_divs as $section => $data) {
146 list($class, $function) = $data;
147 if (!empty($function))
148 $this->_html->pushContent(HTML::div(array('class' => $class),
153 function _extractText() {
155 * Custom text extractions might want to check if the section
156 * contains any text using trim() before returning any
157 * transformed text, to avoid displaying blank boxes.
159 * See interWikiMapPageType->_extractStartText()
160 * and interWikiMapPageType->_extractEndText() for examples.
162 return TransformText($this->_content, $this->_markup);
165 function getContent() {
166 // _defineSections & _populateSections execution moved to here
167 // from constructor, to allow custom vars (used for WikiBlog
168 // page summary field)
169 $this->_defineSections();
170 $this->_populateSections();
176 * wikiBlogPageType formats a Wiki page as a blog, with two sections:
181 class wikiBlogPageType
186 function _defineSections() {
188 * section_id => ('css_class', $this->_section_function)
190 // FIXME: Create new css styles
191 $this->_divs = array('wikiblog-summary' => array('wikitext', $this->_extractSummary()),
192 'wikitext' => array('wikitext', $this->_extractText())
196 function _extractSummary() {
197 return HTML(HTML::strong(array('class' => 'wikiblog-label'),
199 " ", $this->_summary);
204 * interWikiMapPageType formats a Wiki page as an InterWikiMap, with
205 * up to three sections:
207 * - interwikimap-header
209 * - interwikimap-footer
211 class interWikiMapPageType
214 function _defineSections() {
216 * section_id => ('css_class', $this->_section_function)
218 $this->_divs = array('interwikimap-header' => array('wikitext', $this->_extractStartText()),
219 'interwikimap' => array('wikitext', $this->_getMap()),
220 'interwikimap-footer' => array('wikitext', $this->_extractEndText()));
225 // let interwiki.php get the map
226 include_once("lib/interwiki.php");
227 $map = InterWikiMap::GetMap($request);
228 return $this->_arrayToTable($map->_map, $request);
231 function _arrayToTable ($array, &$request) {
232 $thead = HTML::thead();
233 $label[0] = _("Name");
234 $label[1] = _("InterWiki Address");
235 $thead->pushContent(HTML::tr(HTML::td($label[0]),
236 HTML::td($label[1])));
238 $tbody = HTML::tbody();
239 $dbi = $request->getDbh();
241 foreach ($array as $moniker => $interurl) {
242 if ($dbi->isWikiPage($moniker)) {
243 $moniker = WikiLink($moniker);
245 $moniker = HTML::td(array('class' => 'interwiki-moniker'),
247 $interurl = HTML::td(array('class' =>'interwiki-url'),
248 HTML::tt($interurl));
250 $tbody->pushContent(HTML::tr($moniker, $interurl));
253 $table = HTML::table();
254 $table->setAttr('class', 'interwiki-map');
255 $table->pushContent($thead);
256 $table->pushContent($tbody);
261 function _extractStartText() {
262 // get the start block of text
263 $v = strpos($this->_content, "<verbatim>");
265 list($wikitext, $cruft) = explode("<verbatim>", $this->_content);
267 $wikitext = $this->_content;
270 return TransformText($wikitext, $this->_markup);
275 function _extractEndText() {
276 // get the ending block of text
277 $v = strpos($this->_content, "</verbatim>");
279 list($cruft, $endtext) = explode("</verbatim>", $this->_content);
281 return TransformText($endtext, $this->_markup);
287 // $Log: not supported by cvs2svn $
288 // Revision 1.16 2003/01/31 22:53:39 carstenklapp
289 // Added hook/hack to allow plugins to provide their own or override a PageType.
291 // Revision 1.15 2003/01/06 01:46:31 carstenklapp
292 // Bugfix: Also identify any WikiBlogs which are subpages of subpages.
294 // Revision 1.14 2003/01/06 00:08:08 carstenklapp
295 // Added a basic WikiBlog page type, takes advantage of editpage summary field.
302 // c-hanging-comment-ender-p: nil
303 // indent-tabs-mode: nil