4 * Copyright 1999,2000,2001,2002,2006,2007 $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 along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 require_once 'lib/Template.php';
26 class WikiPlugin__BackendInfo
29 function getDescription()
31 return sprintf(_("Get debugging information for %s."), '[pagename]');
34 function getDefaultArguments()
36 return array('page' => '[pagename]',
37 'notallversions' => 0);
40 function run($dbi, $argstr, &$request, $basepage)
42 $args = $this->getArgs($argstr, $request);
45 return $this->error("page missing");
47 $backend = &$dbi->_backend;
48 $this->chunk_split = true;
49 $this->readonly_pagemeta = array();
50 $this->hidden_pagemeta = array('_cached_html');
52 $html = HTML(HTML::h3(fmt("Querying backend directly for ā%sā",
55 $table = HTML::table(array('border' => 1,
58 $pagedata = $backend->get_pagedata($page);
60 // FIXME: invalid HTML
61 $html->pushContent(HTML::p(fmt("No pagedata for %s", $page)));
63 $this->_fixupData($pagedata);
64 $table->pushContent($this->_showhash("get_pagedata('$page')", $pagedata));
66 if (!$notallversions) {
67 $version = $backend->get_latest_version($page);
68 $vdata = $backend->get_versiondata($page, $version, true);
69 $this->_fixupData($vdata);
70 $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
71 $table->pushContent($this->_showhash("get_versiondata('$page',$version)",
74 for ($version = $backend->get_latest_version($page);
76 $version = $backend->get_previous_version($page, $version)) {
77 $vdata = $backend->get_versiondata($page, $version, true);
78 $this->_fixupData($vdata);
79 $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
80 $table->pushContent($this->_showhash("get_versiondata('$page',$version)",
85 $linkdata = $backend->get_links($page, false);
86 if ($linkdata->count())
87 $table->pushContent($this->_showhash("get_links('$page')", $linkdata->asArray()));
88 $relations = $backend->get_links($page, false, false, false, false, false, true);
89 if ($relations->count()) {
90 $table->pushContent($this->_showhash("get_relations('$page')", array()));
91 while ($rel = $relations->next())
92 $table->pushContent($this->_showhash(false, $rel));
94 $linkdata = $backend->get_links($page, true);
95 if ($linkdata->count())
96 $table->pushContent($this->_showhash("get_backlinks('$page')", $linkdata->asArray()));
98 $html->pushContent($table);
103 * Really should have a _fixupPagedata and _fixupVersiondata, but this works.
104 * also used in plugin/EditMetaData
106 private function _fixupData(&$data, $prefix = '')
108 if (!is_array($data)) return;
111 $user = $request->getUser();
112 foreach ($data as $key => $val) {
113 $fullkey = $prefix . '[' . $key . ']';
114 if (is_integer($key)) {
116 } elseif ($key == 'passwd' and !$user->isAdmin()) {
117 $data[$key] = $val ? _("<not displayed>") : _("<empty>");
118 } elseif ($key and $key == '_cached_html') {
119 $val = TransformedText::unpack($val);
122 $data[$key] = HTML::pre(ob_get_contents());
124 } elseif (is_bool($val)) {
125 $data[$key] = $this->_showvalue($key, $val ? "true" : "false", $prefix);
126 } elseif (is_string($val) && ((substr($val, 0, 2) == 'a:'
127 or (substr($val, 0, 2) == 'O:')))
129 // how to indent this table?
130 $val = unserialize($val);
131 $this->_fixupData($val, $fullkey);
132 $data[$key] = HTML::table(array('border' => 1,
135 $this->_showhash(false, $val, $fullkey));
136 } elseif (is_array($val)) {
137 // how to indent this table?
138 $this->_fixupData($val, $fullkey);
139 $data[$key] = HTML::table(array('border' => 1,
142 $this->_showhash(false, $val, $fullkey));
143 } elseif (is_object($val)) {
144 // how to indent this table?
147 $val = HTML::pre(ob_get_contents());
149 $data[$key] = HTML::table(array('border' => 1,
152 $this->_showhash(false, $val, $fullkey));
153 } elseif ($key and $key == '%content') {
156 elseif (strlen($val) > 40)
157 $val = substr($val, 0, 40) . " ...";
161 unset($data['%pagedata']); // problem in backend
164 /* also used in plugin/EditMetaData */
165 private function _showhash($heading, $hash, $prefix = '')
169 $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
170 'style' => 'color:#000000'),
171 HTML::td(array('colspan' => 2,
172 'style' => 'color:#000000'),
174 if (!is_array($hash)) return array();
176 foreach ($hash as $key => $val) {
177 if ($this->chunk_split and is_string($val)) $val = chunk_split($val);
178 $rows[] = HTML::tr(HTML::td(array('align' => 'right',
179 'bgcolor' => '#cccccc',
180 'style' => 'color:#000000'),
181 HTML(HTML::raw(' '), $key,
182 HTML::raw(' '))),
183 HTML::td(array('bgcolor' => '#ffffff',
184 'style' => 'color:#000000'),
185 $this->_showvalue($key, $val, $prefix))
191 /* also used in plugin/EditMetaData */
192 private function _showvalue($key, $val, $prefix = '')
194 return $val ? $val : HTML::raw(' ');
203 // c-hanging-comment-ender-p: nil
204 // indent-tabs-mode: nil