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
30 return _("DebugInfo");
33 function getDescription () {
34 return sprintf(_("Get debugging information for %s."), '[pagename]');
37 function getDefaultArguments() {
38 return array('page' => '[pagename]',
39 'notallversions' => 0);
42 function run($dbi, $argstr, &$request, $basepage) {
43 $args = $this->getArgs($argstr, $request);
46 return $this->error("page missing");
48 $backend = &$dbi->_backend;
49 $this->chunk_split = true;
50 $this->readonly_pagemeta = array();
51 $this->hidden_pagemeta = array ('_cached_html');
53 $html = HTML(HTML::h3(fmt("Querying backend directly for '%s'",
56 $table = HTML::table(array('border' => 1,
59 $pagedata = $backend->get_pagedata($page);
61 // FIXME: invalid HTML
62 $html->pushContent(HTML::p(fmt("No pagedata for %s", $page)));
65 $this->_fixupData($pagedata);
66 $table->pushContent($this->_showhash("get_pagedata('$page')", $pagedata));
68 if (!$notallversions) {
69 $version = $backend->get_latest_version($page);
70 $vdata = $backend->get_versiondata($page, $version, true);
71 $this->_fixupData($vdata);
72 $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
73 $table->pushContent($this->_showhash("get_versiondata('$page',$version)",
76 for ($version = $backend->get_latest_version($page);
78 $version = $backend->get_previous_version($page, $version))
80 $vdata = $backend->get_versiondata($page, $version, true);
81 $this->_fixupData($vdata);
82 $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
83 $table->pushContent($this->_showhash("get_versiondata('$page',$version)",
88 $linkdata = $backend->get_links($page, false);
89 if ($linkdata->count())
90 $table->pushContent($this->_showhash("get_links('$page')", $linkdata->asArray()));
91 $relations = $backend->get_links($page, false, false, false, false, false, true);
92 if ($relations->count()) {
93 $table->pushContent($this->_showhash("get_relations('$page')", array()));
94 while ($rel = $relations->next())
95 $table->pushContent($this->_showhash(false, $rel));
97 $linkdata = $backend->get_links($page, true);
98 if ($linkdata->count())
99 $table->pushContent($this->_showhash("get_backlinks('$page')", $linkdata->asArray()));
101 $html->pushContent($table);
106 * Really should have a _fixupPagedata and _fixupVersiondata, but this works.
107 * also used in plugin/EditMetaData
109 function _fixupData(&$data, $prefix='') {
110 if (!is_array($data)) return;
113 $user = $request->getUser();
114 foreach ($data as $key => $val) {
115 $fullkey = $prefix . '[' . $key . ']';
116 if (is_integer($key)) {
118 } elseif ($key == 'passwd' and !$user->isAdmin()) {
119 $data[$key] = $val ? _("<not displayed>") : _("<empty>");
120 } elseif ($key and $key == '_cached_html') {
121 $val = TransformedText::unpack($val);
124 $data[$key] = HTML::pre(ob_get_contents());
127 elseif (is_bool($val)) {
128 $data[$key] = $this->_showvalue($key, $val ? "true" : "false", $prefix);
130 elseif (is_string($val) && ((substr($val, 0, 2) == 'a:'
131 or (substr($val, 0, 2) == 'O:'))))
133 // how to indent this table?
134 $val = unserialize($val);
135 $this->_fixupData($val, $fullkey);
136 $data[$key] = HTML::table(array('border' => 1,
139 $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));
159 elseif ($key and $key == '%content') {
162 elseif (strlen($val) > 40)
163 $val = substr($val,0,40) . " ...";
167 unset($data['%pagedata']); // problem in backend
170 /* also used in plugin/EditMetaData */
171 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='') {
198 return $val ? $val : HTML::raw(' ');
207 // c-hanging-comment-ender-p: nil
208 // indent-tabs-mode: nil