]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/_BackendInfo.php
Add private keyword for functions
[SourceForge/phpwiki.git] / lib / plugin / _BackendInfo.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__BackendInfo
27     extends WikiPlugin
28 {
29     function getName()
30     {
31         return _("DebugInfo");
32     }
33
34     function getDescription()
35     {
36         return sprintf(_("Get debugging information for %s."), '[pagename]');
37     }
38
39     function getDefaultArguments()
40     {
41         return array('page' => '[pagename]',
42             'notallversions' => 0);
43     }
44
45     function run($dbi, $argstr, &$request, $basepage)
46     {
47         $args = $this->getArgs($argstr, $request);
48         extract($args);
49         if (empty($page))
50             return $this->error("page missing");
51
52         $backend = &$dbi->_backend;
53         $this->chunk_split = true;
54         $this->readonly_pagemeta = array();
55         $this->hidden_pagemeta = array('_cached_html');
56
57         $html = HTML(HTML::h3(fmt("Querying backend directly for ā€œ%sā€",
58             $page)));
59
60         $table = HTML::table(array('border' => 1,
61             'cellpadding' => 2,
62             'cellspacing' => 0));
63         $pagedata = $backend->get_pagedata($page);
64         if (!$pagedata) {
65             // FIXME: invalid HTML
66             $html->pushContent(HTML::p(fmt("No pagedata for %s", $page)));
67         } else {
68             $this->_fixupData($pagedata);
69             $table->pushContent($this->_showhash("get_pagedata('$page')", $pagedata));
70         }
71         if (!$notallversions) {
72             $version = $backend->get_latest_version($page);
73             $vdata = $backend->get_versiondata($page, $version, true);
74             $this->_fixupData($vdata);
75             $table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
76             $table->pushContent($this->_showhash("get_versiondata('$page',$version)",
77                 $vdata));
78         } else {
79             for ($version = $backend->get_latest_version($page);
80                  $version;
81                  $version = $backend->get_previous_version($page, $version)) {
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      * also used in plugin/EditMetaData
110      */
111     private function _fixupData(&$data, $prefix = '')
112     {
113         if (!is_array($data)) return;
114
115         global $request;
116         $user = $request->getUser();
117         foreach ($data as $key => $val) {
118             $fullkey = $prefix . '[' . $key . ']';
119             if (is_integer($key)) {
120                 ;
121             } elseif ($key == 'passwd' and !$user->isAdmin()) {
122                 $data[$key] = $val ? _("<not displayed>") : _("<empty>");
123             } elseif ($key and $key == '_cached_html') {
124                 $val = TransformedText::unpack($val);
125                 ob_start();
126                 print_r($val);
127                 $data[$key] = HTML::pre(ob_get_contents());
128                 ob_end_clean();
129             } elseif (is_bool($val)) {
130                 $data[$key] = $this->_showvalue($key, $val ? "true" : "false", $prefix);
131             } elseif (is_string($val) && ((substr($val, 0, 2) == 'a:'
132                 or (substr($val, 0, 2) == 'O:')))
133             ) {
134                 // how to indent this table?
135                 $val = unserialize($val);
136                 $this->_fixupData($val, $fullkey);
137                 $data[$key] = HTML::table(array('border' => 1,
138                         'cellpadding' => 2,
139                         'cellspacing' => 0),
140                     $this->_showhash(false, $val, $fullkey));
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             } 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     /* also used in plugin/EditMetaData */
170     private function _showhash($heading, $hash, $prefix = '')
171     {
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     private function _showvalue($key, $val, $prefix = '')
198     {
199         return $val ? $val : HTML::raw('&nbsp;');
200     }
201
202 }
203
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: