]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/_BackendInfo.php
added missing 4th basepage arg at plugin->run() to almost all plugins. This caused...
[SourceForge/phpwiki.git] / lib / plugin / _BackendInfo.php
1 <?php // -*-php-*-
2 rcs_id('$Id: _BackendInfo.php,v 1.22 2004-02-17 12:11:36 rurban Exp $');
3 /**
4  Copyright 1999, 2000, 2001, 2002 $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.22 $");
40     }
41
42     function getDefaultArguments() {
43         return array('page' => '[pagename]');
44     }
45
46     function run($dbi, $argstr, &$request, $basepage) {
47         $args = $this->getArgs($argstr, $request);
48         extract($args);
49         if (empty($page))
50             return '';
51
52         $backend = &$dbi->_backend;
53
54         $html = HTML(HTML::h3(fmt("Querying backend directly for '%s'",
55                                   $page)));
56
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
71         for ($version = $backend->get_latest_version($page);
72              $version;
73              $version = $backend->get_previous_version($page, $version))
74             {
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         $html->pushContent($table);
83         return $html;
84     }
85
86     /**
87      * Really should have a _fixupPagedata and _fixupVersiondata, but this works.
88      */
89     function _fixupData(&$data) {
90         global $request;
91         $user = $request->getUser();
92
93         foreach ($data as $key => $val) {
94             if ($key == 'passwd' and !$user->isAdmin())
95                 $data[$key] = $val ? _("<not displayed>") : _("<empty>");
96             elseif ($key == '_cached_html') {
97                 $val = TransformedText::unpack($val);
98                 ob_start();
99                 print_r($val);
100                 $data[$key] = HTML::pre(ob_get_contents());
101                 ob_end_clean();
102             }
103             elseif (is_string($val) && (substr($val, 0, 2) == 'a:')) {
104                 // how to indent this table?
105                 $val = unserialize($val);
106                 $this->_fixupData($val);
107                 $data[$key] = HTML::table(array('border' => 1,
108                                                 'cellpadding' => 2,
109                                                 'cellspacing' => 0),
110                                           $this->_showhash(false, $val));
111             }
112             elseif (is_array($val)) {
113                 // how to indent this table?
114                 $this->_fixupData($val);
115                 $data[$key] = HTML::table(array('border' => 1,
116                                                 'cellpadding' => 2,
117                                                 'cellspacing' => 0),
118                                           $this->_showhash(false, $val));
119             }
120             elseif ($key == '%content') {
121                 if ($val === true)
122                     $val = '<true>';
123                 elseif (strlen($val) > 40)
124                     $val = substr($val,0,40) . " ...";
125                 $data[$key] = $val;
126             }
127         }
128         unset($data['%pagedata']); // problem in backend
129     }
130
131             
132     function _showhash ($heading, $hash, $pagename = '') {
133         $rows = array();
134         if ($heading)
135             $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
136                                      'style' => 'color:#000000'),
137                                HTML::td(array('colspan' => 2,
138                                               'style' => 'color:#000000'),
139                                         $heading));
140         ksort($hash);
141         foreach ($hash as $key => $val) {
142             $rows[] = HTML::tr(HTML::td(array('align' => 'right',
143                                               'bgcolor' => '#cccccc',
144                                               'style' => 'color:#000000'),
145                                         HTML(HTML::raw('&nbsp;'), $key,
146                                              HTML::raw('&nbsp;'))),
147                                HTML::td(array('bgcolor' => '#ffffff',
148                                               'style' => 'color:#000000'),
149                                         $val ? $val : HTML::raw('&nbsp;'))
150                                );
151         }
152         return $rows;
153     }
154 };
155
156 // $Log: not supported by cvs2svn $
157 // Revision 1.21  2003/02/21 04:22:28  dairiki
158 // Make this work for array-valued data.  Make display of cached markup
159 // readable.  Some code cleanups.  (This still needs more work.)
160 //
161 // Revision 1.20  2003/01/18 21:19:24  carstenklapp
162 // Code cleanup:
163 // Reformatting; added copyleft, getVersion, getDescription
164 //
165
166 // (c-file-style: "gnu")
167 // Local Variables:
168 // mode: php
169 // tab-width: 8
170 // c-basic-offset: 4
171 // c-hanging-comment-ender-p: nil
172 // indent-tabs-mode: nil
173 // End:
174 ?>