]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/_BackendInfo.php
Replace tabs by spaces; remove EOL spaces
[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 getVersion() {
38         return preg_replace("/[Revision: $]/", '',
39                             "\$Revision$");
40     }
41
42     function getDefaultArguments() {
43         return array('page' => '[pagename]',
44                      'notallversions' => 0);
45     }
46
47     function run($dbi, $argstr, &$request, $basepage) {
48         $args = $this->getArgs($argstr, $request);
49         extract($args);
50         if (empty($page))
51             return $this->error("page missing");
52
53         $backend = &$dbi->_backend;
54         $this->chunk_split = true;
55         $this->readonly_pagemeta = array();
56         $this->hidden_pagemeta = array ('_cached_html');
57
58         $html = HTML(HTML::h3(fmt("Querying backend directly for '%s'",
59                                   $page)));
60
61         $table = HTML::table(array('border' => 1,
62                                    'cellpadding' => 2,
63                                    'cellspacing' => 0));
64         $pagedata = $backend->get_pagedata($page);
65         if (!$pagedata) {
66             // FIXME: invalid HTML
67             $html->pushContent(HTML::p(fmt("No pagedata for %s", $page)));
68         }
69         else {
70             $this->_fixupData($pagedata);
71             $table->pushContent($this->_showhash("get_pagedata('$page')", $pagedata));
72         }
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)",
79                                                  $vdata));
80         } else {
81             for ($version = $backend->get_latest_version($page);
82                  $version;
83                  $version = $backend->get_previous_version($page, $version))
84                 {
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)",
89                                                          $vdata));
90                 }
91         }
92
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));
101         }
102         $linkdata = $backend->get_links($page, true);
103         if ($linkdata->count())
104             $table->pushContent($this->_showhash("get_backlinks('$page')", $linkdata->asArray()));
105
106         $html->pushContent($table);
107         return $html;
108     }
109
110     /**
111      * Really should have a _fixupPagedata and _fixupVersiondata, but this works.
112      * also used in plugin/EditMetaData
113      */
114     function _fixupData(&$data, $prefix='') {
115         if (!is_array($data)) return;
116
117         global $request;
118         $user = $request->getUser();
119         foreach ($data as $key => $val) {
120             $fullkey = $prefix . '[' . $key . ']';
121             if (is_integer($key)) {
122                     ;
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);
127                 ob_start();
128                 print_r($val);
129                 $data[$key] = HTML::pre(ob_get_contents());
130                 ob_end_clean();
131             }
132             elseif (is_bool($val)) {
133                     $data[$key] = $this->_showvalue($key, $val ? "true" : "false", $prefix);
134             }
135             elseif (is_string($val) && ((substr($val, 0, 2) == 'a:'
136                                          or (substr($val, 0, 2) == 'O:'))))
137             {
138                 // how to indent this table?
139                 $val = unserialize($val);
140                 $this->_fixupData($val, $fullkey);
141                 $data[$key] = HTML::table(array('border' => 1,
142                                                 'cellpadding' => 2,
143                                                 'cellspacing' => 0),
144                                           $this->_showhash(false, $val, $fullkey));
145             }
146             elseif (is_array($val)) {
147                 // how to indent this table?
148                 $this->_fixupData($val, $fullkey);
149                 $data[$key] = HTML::table(array('border' => 1,
150                                                 'cellpadding' => 2,
151                                                 'cellspacing' => 0),
152                                           $this->_showhash(false, $val, $fullkey));
153             } elseif (is_object($val)) {
154                 // how to indent this table?
155                 ob_start();
156                 print_r($val);
157                 $val = HTML::pre(ob_get_contents());
158                 ob_end_clean();
159                 $data[$key] = HTML::table(array('border' => 1,
160                                                 'cellpadding' => 2,
161                                                 'cellspacing' => 0),
162                                           $this->_showhash(false, $val, $fullkey));
163             }
164             elseif ($key and $key == '%content') {
165                 if ($val === true)
166                     $val = '<true>';
167                 elseif (strlen($val) > 40)
168                     $val = substr($val,0,40) . " ...";
169                 $data[$key] = $val;
170             }
171         }
172         unset($data['%pagedata']); // problem in backend
173     }
174
175     /* also used in plugin/EditMetaData */
176     function _showhash ($heading, $hash, $prefix='') {
177         $rows = array();
178         if ($heading)
179             $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
180                                      'style' => 'color:#000000'),
181                                HTML::td(array('colspan' => 2,
182                                               'style' => 'color:#000000'),
183                                         $heading));
184         if (!is_array($hash)) return array();
185         ksort($hash);
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('&nbsp;'), $key,
192                                              HTML::raw('&nbsp;'))),
193                                HTML::td(array('bgcolor' => '#ffffff',
194                                               'style' => 'color:#000000'),
195                                         $this->_showvalue($key, $val, $prefix))
196                                );
197         }
198         return $rows;
199     }
200
201     /* also used in plugin/EditMetaData */
202     function _showvalue ($key, $val, $prefix='') {
203         return $val ? $val : HTML::raw('&nbsp;');
204     }
205
206 };
207
208 // (c-file-style: "gnu")
209 // Local Variables:
210 // mode: php
211 // tab-width: 8
212 // c-basic-offset: 4
213 // c-hanging-comment-ender-p: nil
214 // indent-tabs-mode: nil
215 // End:
216 ?>