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_DebugBackendInfo
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('class' => 'bordered'));
56 $pagedata = $backend->get_pagedata($page);
58 // FIXME: invalid HTML
59 $html->pushContent(HTML::p(fmt("No pagedata for %s", $page)));
61 $this->_fixupData($pagedata);
62 $table->pushContent($this->_showhash("get_pagedata('$page')", $pagedata));
64 if (!$notallversions) {
65 $version = $backend->get_latest_version($page);
66 $vdata = $backend->get_versiondata($page, $version, true);
67 $this->_fixupData($vdata);
68 $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
69 $table->pushContent($this->_showhash("get_versiondata('$page',$version)",
72 for ($version = $backend->get_latest_version($page);
74 $version = $backend->get_previous_version($page, $version)) {
75 $vdata = $backend->get_versiondata($page, $version, true);
76 $this->_fixupData($vdata);
77 $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
78 $table->pushContent($this->_showhash("get_versiondata('$page',$version)",
83 $linkdata = $backend->get_links($page, false);
84 if ($linkdata->count())
85 $table->pushContent($this->_showhash("get_links('$page')", $linkdata->asArray()));
86 $relations = $backend->get_links($page, false, false, false, false, false, true);
87 if ($relations->count()) {
88 $table->pushContent($this->_showhash("get_relations('$page')", array()));
89 while ($rel = $relations->next())
90 $table->pushContent($this->_showhash(false, $rel));
92 $linkdata = $backend->get_links($page, true);
93 if ($linkdata->count())
94 $table->pushContent($this->_showhash("get_backlinks('$page')", $linkdata->asArray()));
96 $html->pushContent($table);
101 * Really should have a _fixupPagedata and _fixupVersiondata, but this works.
102 * also used in plugin/EditMetaData
104 protected function _fixupData(&$data, $prefix = '')
106 if (!is_array($data)) return;
109 $user = $request->getUser();
110 foreach ($data as $key => $val) {
111 $fullkey = $prefix . '[' . $key . ']';
112 if (is_integer($key)) {
114 } elseif ($key == 'passwd' and !$user->isAdmin()) {
115 $data[$key] = $val ? _("<not displayed>") : _("<empty>");
116 } elseif ($key and $key == '_cached_html') {
117 $val = TransformedText::unpack($val);
120 $data[$key] = HTML::pre(ob_get_contents());
122 } elseif (is_bool($val)) {
123 $data[$key] = $this->_showvalue($key, $val ? "true" : "false", $prefix);
124 } elseif (is_string($val) && ((substr($val, 0, 2) == 'a:'
125 or (substr($val, 0, 2) == 'O:')))
127 // how to indent this table?
128 $val = unserialize($val);
129 $this->_fixupData($val, $fullkey);
130 $data[$key] = HTML::table(array('class' => 'bordered'),
131 $this->_showhash(false, $val, $fullkey));
132 } elseif (is_array($val)) {
133 // how to indent this table?
134 $this->_fixupData($val, $fullkey);
135 $data[$key] = HTML::table(array('class' => 'bordered'),
136 $this->_showhash(false, $val, $fullkey));
137 } elseif (is_object($val)) {
138 // how to indent this table?
141 $val = HTML::pre(ob_get_contents());
143 $data[$key] = HTML::table(array('class' => 'bordered'),
144 $this->_showhash(false, $val, $fullkey));
145 } elseif ($key and $key == '%content') {
148 elseif (strlen($val) > 40)
149 $val = substr($val, 0, 40) . " ...";
153 unset($data['%pagedata']); // problem in backend
156 /* also used in plugin/EditMetaData */
157 protected function _showhash($heading, $hash, $prefix = '')
161 $rows[] = HTML::tr(array(
162 'style' => 'color:#000;background-color:#ffcccc'),
163 HTML::td(array('colspan' => 2,
164 'style' => 'color:#000'),
166 if (!is_array($hash)) return array();
168 foreach ($hash as $key => $val) {
169 if ($this->chunk_split and is_string($val)) $val = chunk_split($val);
170 $rows[] = HTML::tr(HTML::td(array('class' => 'align-right',
171 'style' => 'color:#000;background-color:#ccc'),
172 HTML(HTML::raw(' '), $key,
173 HTML::raw(' '))),
175 'style' => 'color:#000;background-color:#fff'),
176 $this->_showvalue($key, $val, $prefix))
182 /* also used in plugin/EditMetaData */
183 protected function _showvalue($key, $val, $prefix = '')
185 return $val ? $val : HTML::raw(' ');
194 // c-hanging-comment-ender-p: nil
195 // indent-tabs-mode: nil