]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/_BackendInfo.php
rcs_id no longer makes sense with Subversion global version number
[SourceForge/phpwiki.git] / lib / plugin / _BackendInfo.php
1 <?php // -*-php-*-
2 // rcs_id('$Id$');
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
19  * along with PhpWiki; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 require_once('lib/Template.php');
24 /**
25  */
26 class WikiPlugin__BackendInfo
27 extends WikiPlugin
28 {
29     function getName () {
30         return _("DebugInfo");
31     }
32
33     function getDescription () {
34         return sprintf(_("Get debugging information for %s."), '[pagename]');
35     }
36
37     function getDefaultArguments() {
38         return array('page' => '[pagename]',
39                      'notallversions' => 0);
40     }
41
42     function run($dbi, $argstr, &$request, $basepage) {
43         $args = $this->getArgs($argstr, $request);
44         extract($args);
45         if (empty($page))
46             return $this->error("page missing");
47
48         $backend = &$dbi->_backend;
49         $this->chunk_split = true;
50         $this->readonly_pagemeta = array();
51         $this->hidden_pagemeta = array ('_cached_html');
52
53         $html = HTML(HTML::h3(fmt("Querying backend directly for '%s'",
54                                   $page)));
55
56         $table = HTML::table(array('border' => 1,
57                                    'cellpadding' => 2,
58                                    'cellspacing' => 0));
59         $pagedata = $backend->get_pagedata($page);
60         if (!$pagedata) {
61             // FIXME: invalid HTML
62             $html->pushContent(HTML::p(fmt("No pagedata for %s", $page)));
63         }
64         else {
65             $this->_fixupData($pagedata);
66             $table->pushContent($this->_showhash("get_pagedata('$page')", $pagedata));
67         }
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)",
74                                                  $vdata));
75         } else {
76             for ($version = $backend->get_latest_version($page);
77                  $version;
78                  $version = $backend->get_previous_version($page, $version))
79                 {
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)",
84                                                          $vdata));
85                 }
86         }
87
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));
96         }
97         $linkdata = $backend->get_links($page, true);
98         if ($linkdata->count())
99             $table->pushContent($this->_showhash("get_backlinks('$page')", $linkdata->asArray()));
100
101         $html->pushContent($table);
102         return $html;
103     }
104
105     /**
106      * Really should have a _fixupPagedata and _fixupVersiondata, but this works.
107      * also used in plugin/EditMetaData
108      */
109     function _fixupData(&$data, $prefix='') {
110         if (!is_array($data)) return;
111
112         global $request;
113         $user = $request->getUser();
114         foreach ($data as $key => $val) {
115             $fullkey = $prefix . '[' . $key . ']';
116             if (is_integer($key)) {
117                     ;
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);
122                 ob_start();
123                 print_r($val);
124                 $data[$key] = HTML::pre(ob_get_contents());
125                 ob_end_clean();
126             }
127             elseif (is_bool($val)) {
128                     $data[$key] = $this->_showvalue($key, $val ? "true" : "false", $prefix);
129             }
130             elseif (is_string($val) && ((substr($val, 0, 2) == 'a:'
131                                          or (substr($val, 0, 2) == 'O:'))))
132             {
133                 // how to indent this table?
134                 $val = unserialize($val);
135                 $this->_fixupData($val, $fullkey);
136                 $data[$key] = HTML::table(array('border' => 1,
137                                                 'cellpadding' => 2,
138                                                 'cellspacing' => 0),
139                                           $this->_showhash(false, $val, $fullkey));
140             }
141             elseif (is_array($val)) {
142                 // how to indent this table?
143                 $this->_fixupData($val, $fullkey);
144                 $data[$key] = HTML::table(array('border' => 1,
145                                                 'cellpadding' => 2,
146                                                 'cellspacing' => 0),
147                                           $this->_showhash(false, $val, $fullkey));
148             } elseif (is_object($val)) {
149                 // how to indent this table?
150                 ob_start();
151                 print_r($val);
152                 $val = HTML::pre(ob_get_contents());
153                 ob_end_clean();
154                 $data[$key] = HTML::table(array('border' => 1,
155                                                 'cellpadding' => 2,
156                                                 'cellspacing' => 0),
157                                           $this->_showhash(false, $val, $fullkey));
158             }
159             elseif ($key and $key == '%content') {
160                 if ($val === true)
161                     $val = '<true>';
162                 elseif (strlen($val) > 40)
163                     $val = substr($val,0,40) . " ...";
164                 $data[$key] = $val;
165             }
166         }
167         unset($data['%pagedata']); // problem in backend
168     }
169
170     /* also used in plugin/EditMetaData */
171     function _showhash ($heading, $hash, $prefix='') {
172         $rows = array();
173         if ($heading)
174             $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
175                                      'style' => 'color:#000000'),
176                                HTML::td(array('colspan' => 2,
177                                               'style' => 'color:#000000'),
178                                         $heading));
179         if (!is_array($hash)) return array();
180         ksort($hash);
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('&nbsp;'), $key,
187                                              HTML::raw('&nbsp;'))),
188                                HTML::td(array('bgcolor' => '#ffffff',
189                                               'style' => 'color:#000000'),
190                                         $this->_showvalue($key, $val, $prefix))
191                                );
192         }
193         return $rows;
194     }
195
196     /* also used in plugin/EditMetaData */
197     function _showvalue ($key, $val, $prefix='') {
198         return $val ? $val : HTML::raw('&nbsp;');
199     }
200
201 };
202
203 // (c-file-style: "gnu")
204 // Local Variables:
205 // mode: php
206 // tab-width: 8
207 // c-basic-offset: 4
208 // c-hanging-comment-ender-p: nil
209 // indent-tabs-mode: nil
210 // End:
211 ?>