1 <?php rcs_id('$Id: PageType.php,v 1.11 2002-08-20 08:37:41 rurban Exp $');
3 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5 This file is part of PhpWiki.
7 PhpWiki is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 PhpWiki is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with PhpWiki; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 include_once('lib/BlockParser.php');
31 * require_once('lib/PageType.php');
32 * $transformedContent = PageType($pagerevisionhandle, $pagename, $markup);
34 * The pagename and markup args are only required when displaying the content
35 * for an edit preview, otherwise they will be extracted from the page $revision
38 * See http://phpwiki.sourceforge.net/phpwiki/PageType
40 function PageType(&$rev, $pagename = false, $markup = false) {
42 if (isa($rev, 'WikiDB_PageRevision')) {
43 $text = $rev->getPackedContent();
44 $pagename = $rev->_pagename; //is this _ok?
45 $markup = $rev->get('markup');
48 // Hopefully only an edit preview gets us here, else we might be screwed.
49 if ($pagename == false) {
50 $error_text = "DEBUG: \$rev was not a 'WikiDB_PageRevision'. (Are you not previewing a page edit?)"; //debugging message only
51 trigger_error($error_text, E_USER_NOTICE);
56 // PageType currently only works with InterWikiMap.
57 // Once a contentType field has been implemented in the
58 // database then that can be used instead of this pagename check.
59 $i = _("InterWikiMap");
62 $ContentTemplateName = 'interwikimap';
65 $ContentTemplateName = 'wikitext';
68 $_ContentTemplates = array('wikitext' => new PageType($text, $markup),
69 'interwikimap' => new interWikiMapPageType($text, $markup));
71 // Start making the actual content
72 $content_template = $_ContentTemplates[$ContentTemplateName];
73 return $content_template->getContent();
82 * This is a simple WikiPage
88 function PageType (&$content, $markup) {
89 $this->_content = $content;
90 $this->_markup = $markup;
91 $this->_html = HTML();
93 $this->_defineSections();
94 $this->_populateSections();
97 function _defineSections() {
99 * ... section_id => ('css_class', $this->_section_function)
101 $this->_divs = array('wikitext' => array('wikitext', $this->_extractText()));
104 function _populateSections() {
105 foreach ($this->_divs as $section => $data) {
106 list($class, $function) = $data;
107 if (!empty($function))
108 $this->_html->pushContent(HTML::div(array('class' => $class), $function));
112 function _extractText() {
114 * Custom text extractions might want to check if the section
115 * contains any text using trim() before returning any
116 * transformed text, to avoid displaying blank boxes.
117 * See interWikiMapPageType->_extractStartText()
118 * and interWikiMapPageType->_extractEndText() for examples.
120 return TransformText($this->_content, $this->_markup);
123 function getContent() {
129 class interWikiMapPageType extends PageType {
131 function _defineSections() {
133 * section_id => ('css_class', $this->_section_function)
135 $this->_divs = array('interwikimap-header' => array('wikitext', $this->_extractStartText()),
136 'interwikimap' => array('wikitext', $this->_getMap()),
137 'interwikimap-footer' => array('wikitext', $this->_extractEndText()));
142 // let interwiki.php get the map
143 include_once("lib/interwiki.php");
144 $map = InterWikiMap::GetMap($request);
145 return $this->_arrayToTable($map->_map, $request);
148 function _arrayToTable ($array, &$request) {
149 $thead = HTML::thead();
150 $label[0] = _("Name");
151 $label[1] = _("InterWiki Address");
152 $thead->pushContent(HTML::tr(HTML::td($label[0]),
153 HTML::td($label[1])));
155 $tbody = HTML::tbody();
156 $dbi = $request->getDbh();
158 foreach ($array as $moniker => $interurl) {
159 if ($dbi->isWikiPage($moniker)) {
160 $moniker = WikiLink($moniker);
162 $moniker = HTML::td(array('class' => 'interwiki-moniker'), $moniker);
163 $interurl = HTML::td(array('class' =>'interwiki-url'), HTML::tt($interurl));
165 $tbody->pushContent(HTML::tr($moniker, $interurl));
168 $table = HTML::table();
169 $table->setAttr('class', 'interwiki-map');
170 $table->pushContent($thead);
171 $table->pushContent($tbody);
176 function _extractStartText() {
177 // get the start block of text
178 $v = strpos($this->_content, "<verbatim>");
180 list($wikitext, $cruft) = explode("<verbatim>", $this->_content);
182 $wikitext = $this->_content;
185 return TransformText($wikitext, $this->_markup);
190 function _extractEndText() {
191 // get the ending block of text
192 $v = strpos($this->_content, "</verbatim>");
194 list($cruft, $endtext) = explode("</verbatim>", $this->_content);
196 return TransformText($endtext, $this->_markup);
208 // c-hanging-comment-ender-p: nil
209 // indent-tabs-mode: nil