]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/_BackendInfo.php
Add notallversion argument. Support more types: objects, serialized objects. split...
[SourceForge/phpwiki.git] / lib / plugin / _BackendInfo.php
1 <?php // -*-php-*-
2 rcs_id('$Id: _BackendInfo.php,v 1.26 2007-01-07 18:44:47 rurban Exp $');
3 /**
4  Copyright 1999,2000,2001,2002,2006 $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: 1.26 $");
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 '';
52
53         $backend = &$dbi->_backend;
54
55         $html = HTML(HTML::h3(fmt("Querying backend directly for '%s'",
56                                   $page)));
57
58         $table = HTML::table(array('border' => 1,
59                                    'cellpadding' => 2,
60                                    'cellspacing' => 0));
61         $pagedata = $backend->get_pagedata($page);
62         if (!$pagedata) {
63             // FIXME: invalid HTML
64             $html->pushContent(HTML::p(fmt("No pagedata for %s", $page)));
65         }
66         else {
67             $this->_fixupData($pagedata);
68             $table->pushContent($this->_showhash("get_pagedata('$page')", $pagedata));
69         }
70         if (!$notallversions) {
71             $version = $backend->get_latest_version($page);
72             $vdata = $backend->get_versiondata($page, $version, true);
73             $this->_fixupData($vdata);
74             $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
75             $table->pushContent($this->_showhash("get_versiondata('$page',$version)",
76                                                  $vdata));
77         } else {
78             for ($version = $backend->get_latest_version($page);
79                  $version;
80                  $version = $backend->get_previous_version($page, $version))
81                 {
82                     $vdata = $backend->get_versiondata($page, $version, true);
83                     $this->_fixupData($vdata);
84                     $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
85                     $table->pushContent($this->_showhash("get_versiondata('$page',$version)",
86                                                          $vdata));
87                 }
88         }
89
90         $linkdata = $backend->get_links($page, false);
91         if ($linkdata->count())
92             $table->pushContent($this->_showhash("get_links('$page')", $linkdata->asArray()));
93         $relations = $backend->get_links($page, false, false, false, false, false, true);
94         if ($relations->count()) {
95             $table->pushContent($this->_showhash("get_relations('$page')", array()));
96             while ($rel = $relations->next())
97                 $table->pushContent($this->_showhash(false, $rel));
98         }
99         $linkdata = $backend->get_links($page, true);
100         if ($linkdata->count())
101             $table->pushContent($this->_showhash("get_backlinks('$page')", $linkdata->asArray()));
102
103         $html->pushContent($table);
104         return $html;
105     }
106
107     /**
108      * Really should have a _fixupPagedata and _fixupVersiondata, but this works.
109      */
110     function _fixupData(&$data) {
111         global $request;
112         $user = $request->getUser();
113
114         foreach ($data as $key => $val) {
115             if (is_integer($key)) {
116                 ;
117             } elseif ($key == 'passwd' and !$user->isAdmin()) {
118                 $data[$key] = $val ? _("<not displayed>") : _("<empty>");
119             } elseif ($key and $key == '_cached_html') {
120                 $val = TransformedText::unpack($val);
121                 ob_start();
122                 print_r($val);
123                 $data[$key] = HTML::pre(ob_get_contents());
124                 ob_end_clean();
125             }
126             elseif (is_bool($val)) {
127                 $data[$key] = $val ? "<true>" : "<false>";
128             }
129             elseif (is_string($val) && ((substr($val, 0, 2) == 'a:' 
130                                          or (substr($val, 0, 2) == 'O:')))) 
131             {
132                 // how to indent this table?
133                 $val = unserialize($val);
134                 $this->_fixupData($val);
135                 $data[$key] = HTML::table(array('border' => 1,
136                                                 'cellpadding' => 2,
137                                                 'cellspacing' => 0),
138                                           $this->_showhash(false, $val));
139             }
140             elseif (is_array($val)) {
141                 // how to indent this table?
142                 $this->_fixupData($val);
143                 $data[$key] = HTML::table(array('border' => 1,
144                                                 'cellpadding' => 2,
145                                                 'cellspacing' => 0),
146                                           $this->_showhash(false, $val));
147             } elseif (is_object($val)) {
148                 // how to indent this table?
149                 ob_start();
150                 print_r($val);
151                 $val = HTML::pre(ob_get_contents());
152                 ob_end_clean();
153                 $data[$key] = HTML::table(array('border' => 1,
154                                                 'cellpadding' => 2,
155                                                 'cellspacing' => 0),
156                                           $this->_showhash(false, $val));
157             }
158             elseif ($key and $key == '%content') {
159                 if ($val === true)
160                     $val = '<true>';
161                 elseif (strlen($val) > 40)
162                     $val = substr($val,0,40) . " ...";
163                 $data[$key] = $val;
164             }
165         }
166         unset($data['%pagedata']); // problem in backend
167     }
168             
169     function _showhash ($heading, $hash, $pagename = '') {
170         $rows = array();
171         if ($heading)
172             $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
173                                      'style' => 'color:#000000'),
174                                HTML::td(array('colspan' => 2,
175                                               'style' => 'color:#000000'),
176                                         $heading));
177         ksort($hash);
178         foreach ($hash as $key => $val) {
179             if (is_string($val)) $val = chunk_split($val);      
180             $rows[] = HTML::tr(HTML::td(array('align' => 'right',
181                                               'bgcolor' => '#cccccc',
182                                               'style' => 'color:#000000'),
183                                         HTML(HTML::raw('&nbsp;'), $key,
184                                              HTML::raw('&nbsp;'))),
185                                HTML::td(array('bgcolor' => '#ffffff',
186                                               'style' => 'color:#000000'),
187                                         $val ? $val : HTML::raw('&nbsp;'))
188                                );
189         }
190         return $rows;
191     }
192 };
193
194 // $Log: not supported by cvs2svn $
195 // Revision 1.25  2006/09/06 06:02:36  rurban
196 // print linkinfo also
197 //
198 // Revision 1.24  2005/01/29 19:47:43  rurban
199 // support bool
200 //
201 // Revision 1.23  2005/01/21 14:13:23  rurban
202 // stabilize on numeric keys (strange php problem)
203 //
204 // Revision 1.22  2004/02/17 12:11:36  rurban
205 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
206 //
207 // Revision 1.21  2003/02/21 04:22:28  dairiki
208 // Make this work for array-valued data.  Make display of cached markup
209 // readable.  Some code cleanups.  (This still needs more work.)
210 //
211 // Revision 1.20  2003/01/18 21:19:24  carstenklapp
212 // Code cleanup:
213 // Reformatting; added copyleft, getVersion, getDescription
214 //
215
216 // (c-file-style: "gnu")
217 // Local Variables:
218 // mode: php
219 // tab-width: 8
220 // c-basic-offset: 4
221 // c-hanging-comment-ender-p: nil
222 // indent-tabs-mode: nil
223 // End:
224 ?>