]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/DebugBackendInfo.php
Use CSS
[SourceForge/phpwiki.git] / lib / plugin / DebugBackendInfo.php
1 <?php
2
3 /**
4  * Copyright 1999,2000,2001,2002,2006,2007 $ThePhpWikiProgrammingTeam
5  *
6  * This file is part of PhpWiki.
7  *
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.
12  *
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.
17  *
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.
21  */
22
23 require_once 'lib/Template.php';
24 /**
25  */
26 class WikiPlugin_DebugBackendInfo
27     extends WikiPlugin
28 {
29     function getDescription()
30     {
31         return sprintf(_("Get debugging information for %s."), '[pagename]');
32     }
33
34     function getDefaultArguments()
35     {
36         return array('page' => '[pagename]',
37             'notallversions' => 0);
38     }
39
40     function run($dbi, $argstr, &$request, $basepage)
41     {
42         $args = $this->getArgs($argstr, $request);
43         extract($args);
44         if (empty($page))
45             return $this->error("page missing");
46
47         $backend = &$dbi->_backend;
48         $this->chunk_split = true;
49         $this->readonly_pagemeta = array();
50         $this->hidden_pagemeta = array('_cached_html');
51
52         $html = HTML(HTML::h3(fmt("Querying backend directly for ā€œ%sā€",
53             $page)));
54
55         $table = HTML::table(array('class' => 'bordered'));
56         $pagedata = $backend->get_pagedata($page);
57         if (!$pagedata) {
58             // FIXME: invalid HTML
59             $html->pushContent(HTML::p(fmt("No pagedata for %s", $page)));
60         } else {
61             $this->_fixupData($pagedata);
62             $table->pushContent($this->_showhash("get_pagedata('$page')", $pagedata));
63         }
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)",
70                 $vdata));
71         } else {
72             for ($version = $backend->get_latest_version($page);
73                  $version;
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)",
79                     $vdata));
80             }
81         }
82
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));
91         }
92         $linkdata = $backend->get_links($page, true);
93         if ($linkdata->count())
94             $table->pushContent($this->_showhash("get_backlinks('$page')", $linkdata->asArray()));
95
96         $html->pushContent($table);
97         return $html;
98     }
99
100     /**
101      * Really should have a _fixupPagedata and _fixupVersiondata, but this works.
102      * also used in plugin/EditMetaData
103      */
104     protected function _fixupData(&$data, $prefix = '')
105     {
106         if (!is_array($data)) return;
107
108         global $request;
109         $user = $request->getUser();
110         foreach ($data as $key => $val) {
111             $fullkey = $prefix . '[' . $key . ']';
112             if (is_integer($key)) {
113                 ;
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);
118                 ob_start();
119                 print_r($val);
120                 $data[$key] = HTML::pre(ob_get_contents());
121                 ob_end_clean();
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:')))
126             ) {
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?
139                 ob_start();
140                 print_r($val);
141                 $val = HTML::pre(ob_get_contents());
142                 ob_end_clean();
143                 $data[$key] = HTML::table(array('class' => 'bordered'),
144                     $this->_showhash(false, $val, $fullkey));
145             } elseif ($key and $key == '%content') {
146                 if ($val === true)
147                     $val = '<true>';
148                 elseif (strlen($val) > 40)
149                     $val = substr($val, 0, 40) . " ...";
150                 $data[$key] = $val;
151             }
152         }
153         unset($data['%pagedata']); // problem in backend
154     }
155
156     /* also used in plugin/EditMetaData */
157     protected function _showhash($heading, $hash, $prefix = '')
158     {
159         $rows = array();
160         if ($heading)
161             $rows[] = HTML::tr(array(
162                     'style' => 'color:#000;background-color:#ffcccc'),
163                 HTML::td(array('colspan' => 2,
164                         'style' => 'color:#000'),
165                     $heading));
166         if (!is_array($hash)) return array();
167         ksort($hash);
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('&nbsp;'), $key,
173                         HTML::raw('&nbsp;'))),
174                 HTML::td(array(
175                         'style' => 'color:#000;background-color:#fff'),
176                     $this->_showvalue($key, $val, $prefix))
177             );
178         }
179         return $rows;
180     }
181
182     /* also used in plugin/EditMetaData */
183     protected function _showvalue($key, $val, $prefix = '')
184     {
185         return $val ? $val : HTML::raw('&nbsp;');
186     }
187
188 }
189
190 // Local Variables:
191 // mode: php
192 // tab-width: 8
193 // c-basic-offset: 4
194 // c-hanging-comment-ender-p: nil
195 // indent-tabs-mode: nil
196 // End: