]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/DebugBackendInfo.php
private --> protected
[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('border' => 1,
56             'cellpadding' => 2,
57             'cellspacing' => 0));
58         $pagedata = $backend->get_pagedata($page);
59         if (!$pagedata) {
60             // FIXME: invalid HTML
61             $html->pushContent(HTML::p(fmt("No pagedata for %s", $page)));
62         } else {
63             $this->_fixupData($pagedata);
64             $table->pushContent($this->_showhash("get_pagedata('$page')", $pagedata));
65         }
66         if (!$notallversions) {
67             $version = $backend->get_latest_version($page);
68             $vdata = $backend->get_versiondata($page, $version, true);
69             $this->_fixupData($vdata);
70             $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
71             $table->pushContent($this->_showhash("get_versiondata('$page',$version)",
72                 $vdata));
73         } else {
74             for ($version = $backend->get_latest_version($page);
75                  $version;
76                  $version = $backend->get_previous_version($page, $version)) {
77                 $vdata = $backend->get_versiondata($page, $version, true);
78                 $this->_fixupData($vdata);
79                 $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
80                 $table->pushContent($this->_showhash("get_versiondata('$page',$version)",
81                     $vdata));
82             }
83         }
84
85         $linkdata = $backend->get_links($page, false);
86         if ($linkdata->count())
87             $table->pushContent($this->_showhash("get_links('$page')", $linkdata->asArray()));
88         $relations = $backend->get_links($page, false, false, false, false, false, true);
89         if ($relations->count()) {
90             $table->pushContent($this->_showhash("get_relations('$page')", array()));
91             while ($rel = $relations->next())
92                 $table->pushContent($this->_showhash(false, $rel));
93         }
94         $linkdata = $backend->get_links($page, true);
95         if ($linkdata->count())
96             $table->pushContent($this->_showhash("get_backlinks('$page')", $linkdata->asArray()));
97
98         $html->pushContent($table);
99         return $html;
100     }
101
102     /**
103      * Really should have a _fixupPagedata and _fixupVersiondata, but this works.
104      * also used in plugin/EditMetaData
105      */
106     protected function _fixupData(&$data, $prefix = '')
107     {
108         if (!is_array($data)) return;
109
110         global $request;
111         $user = $request->getUser();
112         foreach ($data as $key => $val) {
113             $fullkey = $prefix . '[' . $key . ']';
114             if (is_integer($key)) {
115                 ;
116             } elseif ($key == 'passwd' and !$user->isAdmin()) {
117                 $data[$key] = $val ? _("<not displayed>") : _("<empty>");
118             } elseif ($key and $key == '_cached_html') {
119                 $val = TransformedText::unpack($val);
120                 ob_start();
121                 print_r($val);
122                 $data[$key] = HTML::pre(ob_get_contents());
123                 ob_end_clean();
124             } elseif (is_bool($val)) {
125                 $data[$key] = $this->_showvalue($key, $val ? "true" : "false", $prefix);
126             } elseif (is_string($val) && ((substr($val, 0, 2) == 'a:'
127                 or (substr($val, 0, 2) == 'O:')))
128             ) {
129                 // how to indent this table?
130                 $val = unserialize($val);
131                 $this->_fixupData($val, $fullkey);
132                 $data[$key] = HTML::table(array('border' => 1,
133                         'cellpadding' => 2,
134                         'cellspacing' => 0),
135                     $this->_showhash(false, $val, $fullkey));
136             } elseif (is_array($val)) {
137                 // how to indent this table?
138                 $this->_fixupData($val, $fullkey);
139                 $data[$key] = HTML::table(array('border' => 1,
140                         'cellpadding' => 2,
141                         'cellspacing' => 0),
142                     $this->_showhash(false, $val, $fullkey));
143             } elseif (is_object($val)) {
144                 // how to indent this table?
145                 ob_start();
146                 print_r($val);
147                 $val = HTML::pre(ob_get_contents());
148                 ob_end_clean();
149                 $data[$key] = HTML::table(array('border' => 1,
150                         'cellpadding' => 2,
151                         'cellspacing' => 0),
152                     $this->_showhash(false, $val, $fullkey));
153             } elseif ($key and $key == '%content') {
154                 if ($val === true)
155                     $val = '<true>';
156                 elseif (strlen($val) > 40)
157                     $val = substr($val, 0, 40) . " ...";
158                 $data[$key] = $val;
159             }
160         }
161         unset($data['%pagedata']); // problem in backend
162     }
163
164     /* also used in plugin/EditMetaData */
165     protected function _showhash($heading, $hash, $prefix = '')
166     {
167         $rows = array();
168         if ($heading)
169             $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
170                     'style' => 'color:#000000'),
171                 HTML::td(array('colspan' => 2,
172                         'style' => 'color:#000000'),
173                     $heading));
174         if (!is_array($hash)) return array();
175         ksort($hash);
176         foreach ($hash as $key => $val) {
177             if ($this->chunk_split and is_string($val)) $val = chunk_split($val);
178             $rows[] = HTML::tr(HTML::td(array('align' => 'right',
179                         'bgcolor' => '#cccccc',
180                         'style' => 'color:#000000'),
181                     HTML(HTML::raw('&nbsp;'), $key,
182                         HTML::raw('&nbsp;'))),
183                 HTML::td(array('bgcolor' => '#ffffff',
184                         'style' => 'color:#000000'),
185                     $this->_showvalue($key, $val, $prefix))
186             );
187         }
188         return $rows;
189     }
190
191     /* also used in plugin/EditMetaData */
192     protected function _showvalue($key, $val, $prefix = '')
193     {
194         return $val ? $val : HTML::raw('&nbsp;');
195     }
196
197 }
198
199 // Local Variables:
200 // mode: php
201 // tab-width: 8
202 // c-basic-offset: 4
203 // c-hanging-comment-ender-p: nil
204 // indent-tabs-mode: nil
205 // End: