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
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 getVersion() {
38 return preg_replace("/[Revision: $]/", '',
42 function getDefaultArguments() {
43 return array('page' => '[pagename]',
44 'notallversions' => 0);
47 function run($dbi, $argstr, &$request, $basepage) {
48 $args = $this->getArgs($argstr, $request);
53 $backend = &$dbi->_backend;
54 $this->chunk_split = true;
55 $this->readonly_pagemeta = array();
56 $this->hidden_pagemeta = array ('_cached_html');
58 $html = HTML(HTML::h3(fmt("Querying backend directly for '%s'",
61 $table = HTML::table(array('border' => 1,
64 $pagedata = $backend->get_pagedata($page);
66 // FIXME: invalid HTML
67 $html->pushContent(HTML::p(fmt("No pagedata for %s", $page)));
70 $this->_fixupData($pagedata);
71 $table->pushContent($this->_showhash("get_pagedata('$page')", $pagedata));
73 if (!$notallversions) {
74 $version = $backend->get_latest_version($page);
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)",
81 for ($version = $backend->get_latest_version($page);
83 $version = $backend->get_previous_version($page, $version))
85 $vdata = $backend->get_versiondata($page, $version, true);
86 $this->_fixupData($vdata);
87 $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
88 $table->pushContent($this->_showhash("get_versiondata('$page',$version)",
93 $linkdata = $backend->get_links($page, false);
94 if ($linkdata->count())
95 $table->pushContent($this->_showhash("get_links('$page')", $linkdata->asArray()));
96 $relations = $backend->get_links($page, false, false, false, false, false, true);
97 if ($relations->count()) {
98 $table->pushContent($this->_showhash("get_relations('$page')", array()));
99 while ($rel = $relations->next())
100 $table->pushContent($this->_showhash(false, $rel));
102 $linkdata = $backend->get_links($page, true);
103 if ($linkdata->count())
104 $table->pushContent($this->_showhash("get_backlinks('$page')", $linkdata->asArray()));
106 $html->pushContent($table);
111 * Really should have a _fixupPagedata and _fixupVersiondata, but this works.
112 * also used in plugin/EditMetaData
114 function _fixupData(&$data, $prefix='') {
115 if (!is_array($data)) return;
118 $user = $request->getUser();
119 foreach ($data as $key => $val) {
120 $fullkey = $prefix . '[' . $key . ']';
121 if (is_integer($key)) {
123 } elseif ($key == 'passwd' and !$user->isAdmin()) {
124 $data[$key] = $val ? _("<not displayed>") : _("<empty>");
125 } elseif ($key and $key == '_cached_html') {
126 $val = TransformedText::unpack($val);
129 $data[$key] = HTML::pre(ob_get_contents());
132 elseif (is_bool($val)) {
133 $data[$key] = $this->_showvalue($key, $val ? "true" : "false", $prefix);
135 elseif (is_string($val) && ((substr($val, 0, 2) == 'a:'
136 or (substr($val, 0, 2) == 'O:'))))
138 // how to indent this table?
139 $val = unserialize($val);
140 $this->_fixupData($val, $fullkey);
141 $data[$key] = HTML::table(array('border' => 1,
144 $this->_showhash(false, $val, $fullkey));
146 elseif (is_array($val)) {
147 // how to indent this table?
148 $this->_fixupData($val, $fullkey);
149 $data[$key] = HTML::table(array('border' => 1,
152 $this->_showhash(false, $val, $fullkey));
153 } elseif (is_object($val)) {
154 // how to indent this table?
157 $val = HTML::pre(ob_get_contents());
159 $data[$key] = HTML::table(array('border' => 1,
162 $this->_showhash(false, $val, $fullkey));
164 elseif ($key and $key == '%content') {
167 elseif (strlen($val) > 40)
168 $val = substr($val,0,40) . " ...";
172 unset($data['%pagedata']); // problem in backend
175 /* also used in plugin/EditMetaData */
176 function _showhash ($heading, $hash, $prefix='') {
179 $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
180 'style' => 'color:#000000'),
181 HTML::td(array('colspan' => 2,
182 'style' => 'color:#000000'),
184 if (!is_array($hash)) return array();
186 foreach ($hash as $key => $val) {
187 if ($this->chunk_split and is_string($val)) $val = chunk_split($val);
188 $rows[] = HTML::tr(HTML::td(array('align' => 'right',
189 'bgcolor' => '#cccccc',
190 'style' => 'color:#000000'),
191 HTML(HTML::raw(' '), $key,
192 HTML::raw(' '))),
193 HTML::td(array('bgcolor' => '#ffffff',
194 'style' => 'color:#000000'),
195 $this->_showvalue($key, $val, $prefix))
201 /* also used in plugin/EditMetaData */
202 function _showvalue ($key, $val, $prefix='') {
203 return $val ? $val : HTML::raw(' ');
208 // (c-file-style: "gnu")
213 // c-hanging-comment-ender-p: nil
214 // indent-tabs-mode: nil