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);
42 * @param string $argstr
43 * @param WikiRequest $request
44 * @param string $basepage
47 function run($dbi, $argstr, &$request, $basepage)
49 $args = $this->getArgs($argstr, $request);
51 if (empty($userid) or $userid == $request->_user->UserName()) {
52 $user = $request->_user;
53 $userid = $user->UserName();
55 $user = WikiUser($userid);
57 if (!$user->isAdmin() and !(DEBUG && _DEBUG_LOGIN)) {
58 $request->_notAuthorized(WIKIAUTH_ADMIN);
59 $this->disabled("! user->isAdmin");
62 return $this->error("page missing");
64 $backend = &$dbi->_backend;
65 $this->chunk_split = true;
66 $this->readonly_pagemeta = array();
67 $this->hidden_pagemeta = array('_cached_html');
69 $html = HTML(HTML::h2(fmt("Querying backend directly for ā%sā",
72 $table = HTML::table(array('class' => 'bordered'));
73 $pagedata = $backend->get_pagedata($page);
75 // FIXME: invalid HTML
76 $html->pushContent(HTML::p(fmt("No pagedata for %s", $page)));
78 $this->_fixupData($pagedata);
79 $table->pushContent($this->_showhash("get_pagedata('$page')", $pagedata));
81 if (!$notallversions) {
82 $version = $backend->get_latest_version($page);
83 $vdata = $backend->get_versiondata($page, $version, true);
84 $this->_fixupData($vdata);
85 $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
86 $table->pushContent($this->_showhash("get_versiondata('$page',$version)",
89 for ($version = $backend->get_latest_version($page);
91 $version = $backend->get_previous_version($page, $version)) {
92 $vdata = $backend->get_versiondata($page, $version, true);
93 $this->_fixupData($vdata);
94 $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
95 $table->pushContent($this->_showhash("get_versiondata('$page',$version)",
100 $linkdata = $backend->get_links($page, false);
101 if ($linkdata->count())
102 $table->pushContent($this->_showhash("get_links('$page')", $linkdata->asArray()));
103 $relations = $backend->get_links($page, false, false, false, false, false, true);
104 if ($relations->count()) {
105 $table->pushContent($this->_showhash("get_relations('$page')", array()));
106 while ($rel = $relations->next())
107 $table->pushContent($this->_showhash(false, $rel));
109 $linkdata = $backend->get_links($page, true);
110 if ($linkdata->count())
111 $table->pushContent($this->_showhash("get_backlinks('$page')", $linkdata->asArray()));
113 $html->pushContent($table);
118 * Really should have a _fixupPagedata and _fixupVersiondata, but this works.
119 * also used in plugin/EditMetaData
121 protected function _fixupData(&$data, $prefix = '')
123 if (!is_array($data)) return;
126 $user = $request->getUser();
127 foreach ($data as $key => $val) {
128 $fullkey = $prefix . '[' . $key . ']';
129 if (is_integer($key)) {
131 } elseif ($key == 'passwd' and !$user->isAdmin()) {
132 $data[$key] = $val ? _("<not displayed>") : _("<empty>");
133 } elseif ($key and $key == '_cached_html') {
134 $val = TransformedText::unpack($val);
137 $data[$key] = HTML::pre(ob_get_contents());
139 } elseif (is_bool($val)) {
140 $data[$key] = $this->_showvalue($key, $val ? "true" : "false", $prefix);
141 } elseif (is_string($val) && ((substr($val, 0, 2) == 'a:'
142 or (substr($val, 0, 2) == 'O:')))
144 // how to indent this table?
145 $val = unserialize($val);
146 $this->_fixupData($val, $fullkey);
147 $data[$key] = HTML::table(array('class' => 'bordered'),
148 $this->_showhash(false, $val, $fullkey));
149 } elseif (is_array($val)) {
150 // how to indent this table?
151 $this->_fixupData($val, $fullkey);
152 $data[$key] = HTML::table(array('class' => 'bordered'),
153 $this->_showhash(false, $val, $fullkey));
154 } elseif (is_object($val)) {
155 // how to indent this table?
158 $val = HTML::pre(ob_get_contents());
160 $data[$key] = HTML::table(array('class' => 'bordered'),
161 $this->_showhash(false, $val, $fullkey));
162 } elseif ($key and $key == '%content') {
165 elseif (strlen($val) > 40)
166 $val = substr($val, 0, 40) . " ...";
170 unset($data['%pagedata']); // problem in backend
173 /* also used in plugin/EditMetaData */
174 protected function _showhash($heading, $hash, $prefix = '')
178 $rows[] = HTML::tr(array(
179 'style' => 'color:black; background-color:#ffcccc'),
180 HTML::td(array('colspan' => 2,
181 'style' => 'color:black'),
183 if (!is_array($hash)) return array();
185 foreach ($hash as $key => $val) {
186 if ($this->chunk_split and is_string($val)) $val = chunk_split($val);
187 $rows[] = HTML::tr(HTML::td(array('class' => 'align-right',
188 'style' => 'color:black; background-color:#ccc'),
189 HTML(HTML::raw(' '), $key,
190 HTML::raw(' '))),
192 'style' => 'color:black; background-color:white'),
193 $this->_showvalue($key, $val, $prefix))
199 /* also used in plugin/EditMetaData */
200 protected function _showvalue($key, $val, $prefix = '')
202 return $val ? $val : HTML::raw(' ');
211 // c-hanging-comment-ender-p: nil
212 // indent-tabs-mode: nil