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
31 return _("DebugInfo");
34 function getDescription()
36 return sprintf(_("Get debugging information for %s."), '[pagename]');
39 function getDefaultArguments()
41 return array('page' => '[pagename]',
42 'notallversions' => 0);
45 function run($dbi, $argstr, &$request, $basepage)
47 $args = $this->getArgs($argstr, $request);
50 return $this->error("page missing");
52 $backend = &$dbi->_backend;
53 $this->chunk_split = true;
54 $this->readonly_pagemeta = array();
55 $this->hidden_pagemeta = array('_cached_html');
57 $html = HTML(HTML::h3(fmt("Querying backend directly for ā%sā",
60 $table = HTML::table(array('border' => 1,
63 $pagedata = $backend->get_pagedata($page);
65 // FIXME: invalid HTML
66 $html->pushContent(HTML::p(fmt("No pagedata for %s", $page)));
68 $this->_fixupData($pagedata);
69 $table->pushContent($this->_showhash("get_pagedata('$page')", $pagedata));
71 if (!$notallversions) {
72 $version = $backend->get_latest_version($page);
73 $vdata = $backend->get_versiondata($page, $version, true);
74 $this->_fixupData($vdata);
75 $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
76 $table->pushContent($this->_showhash("get_versiondata('$page',$version)",
79 for ($version = $backend->get_latest_version($page);
81 $version = $backend->get_previous_version($page, $version)) {
82 $vdata = $backend->get_versiondata($page, $version, true);
83 $this->_fixupData($vdata);
84 $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
85 $table->pushContent($this->_showhash("get_versiondata('$page',$version)",
90 $linkdata = $backend->get_links($page, false);
91 if ($linkdata->count())
92 $table->pushContent($this->_showhash("get_links('$page')", $linkdata->asArray()));
93 $relations = $backend->get_links($page, false, false, false, false, false, true);
94 if ($relations->count()) {
95 $table->pushContent($this->_showhash("get_relations('$page')", array()));
96 while ($rel = $relations->next())
97 $table->pushContent($this->_showhash(false, $rel));
99 $linkdata = $backend->get_links($page, true);
100 if ($linkdata->count())
101 $table->pushContent($this->_showhash("get_backlinks('$page')", $linkdata->asArray()));
103 $html->pushContent($table);
108 * Really should have a _fixupPagedata and _fixupVersiondata, but this works.
109 * also used in plugin/EditMetaData
111 function _fixupData(&$data, $prefix = '')
113 if (!is_array($data)) return;
116 $user = $request->getUser();
117 foreach ($data as $key => $val) {
118 $fullkey = $prefix . '[' . $key . ']';
119 if (is_integer($key)) {
121 } elseif ($key == 'passwd' and !$user->isAdmin()) {
122 $data[$key] = $val ? _("<not displayed>") : _("<empty>");
123 } elseif ($key and $key == '_cached_html') {
124 $val = TransformedText::unpack($val);
127 $data[$key] = HTML::pre(ob_get_contents());
129 } elseif (is_bool($val)) {
130 $data[$key] = $this->_showvalue($key, $val ? "true" : "false", $prefix);
131 } elseif (is_string($val) && ((substr($val, 0, 2) == 'a:'
132 or (substr($val, 0, 2) == 'O:')))
134 // how to indent this table?
135 $val = unserialize($val);
136 $this->_fixupData($val, $fullkey);
137 $data[$key] = HTML::table(array('border' => 1,
140 $this->_showhash(false, $val, $fullkey));
141 } elseif (is_array($val)) {
142 // how to indent this table?
143 $this->_fixupData($val, $fullkey);
144 $data[$key] = HTML::table(array('border' => 1,
147 $this->_showhash(false, $val, $fullkey));
148 } elseif (is_object($val)) {
149 // how to indent this table?
152 $val = HTML::pre(ob_get_contents());
154 $data[$key] = HTML::table(array('border' => 1,
157 $this->_showhash(false, $val, $fullkey));
158 } elseif ($key and $key == '%content') {
161 elseif (strlen($val) > 40)
162 $val = substr($val, 0, 40) . " ...";
166 unset($data['%pagedata']); // problem in backend
169 /* also used in plugin/EditMetaData */
170 function _showhash($heading, $hash, $prefix = '')
174 $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
175 'style' => 'color:#000000'),
176 HTML::td(array('colspan' => 2,
177 'style' => 'color:#000000'),
179 if (!is_array($hash)) return array();
181 foreach ($hash as $key => $val) {
182 if ($this->chunk_split and is_string($val)) $val = chunk_split($val);
183 $rows[] = HTML::tr(HTML::td(array('align' => 'right',
184 'bgcolor' => '#cccccc',
185 'style' => 'color:#000000'),
186 HTML(HTML::raw(' '), $key,
187 HTML::raw(' '))),
188 HTML::td(array('bgcolor' => '#ffffff',
189 'style' => 'color:#000000'),
190 $this->_showvalue($key, $val, $prefix))
196 /* also used in plugin/EditMetaData */
197 function _showvalue($key, $val, $prefix = '')
199 return $val ? $val : HTML::raw(' ');
208 // c-hanging-comment-ender-p: nil
209 // indent-tabs-mode: nil