]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PluginManager.php
just aesthetics
[SourceForge/phpwiki.git] / lib / plugin / PluginManager.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PluginManager.php,v 1.19 2005-10-12 06:15:25 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 // Set this to true if you don't want regular users to view this page.
24 // So far there are no known security issues.
25 define('REQUIRE_ADMIN', false);
26
27 class WikiPlugin_PluginManager
28 extends WikiPlugin
29 {
30     function getName () {
31         return _("PluginManager");
32     }
33
34     function getDescription () {
35         return _("Description: Provides a list of plugins on this wiki.");
36     }
37
38     function getVersion() {
39         return preg_replace("/[Revision: $]/", '',
40                             "\$Revision: 1.19 $");
41     }
42
43     function getDefaultArguments() {
44         return array('info' => 'args');
45     }
46
47     function run($dbi, $argstr, &$request, $basepage) {
48         extract($this->getArgs($argstr, $request));
49
50         $h = HTML();
51         $this->_generatePageheader($info, $h);
52
53         if (! REQUIRE_ADMIN || $request->_user->isadmin()) {
54             $h->pushContent(HTML::h2(_("Plugins")));
55
56             $table = HTML::table(array('class' => "pagelist"));
57             $this->_generateColgroups($info, $table);
58             $this->_generateColheadings($info, $table);
59             $this->_generateTableBody($info, $dbi, $request, $table);
60             $h->pushContent($table);
61
62             //$h->pushContent(HTML::h2(_("Disabled Plugins")));
63         }
64         else {
65             $h->pushContent(fmt("You must be an administrator to %s.",
66                                 _("use this plugin")));
67         }
68         return $h;
69     }
70
71     function _generatePageheader(&$info, &$html) {
72         $html->pushContent(HTML::p($this->getDescription()));
73     }
74
75     function _generateColgroups(&$info, &$table) {
76         // specify last two column widths
77         $colgroup = HTML::colgroup();
78         $colgroup->pushContent(HTML::col(array('width' => '0*')));
79         $colgroup->pushContent(HTML::col(array('width' => '0*',
80                                                'align' => 'right')));
81         $colgroup->pushContent(HTML::col(array('width' => '9*')));
82         if ($info == 'args')
83             $colgroup->pushContent(HTML::col(array('width' => '2*')));
84         $table->pushcontent($colgroup);
85     }
86
87     function _generateColheadings(&$info, &$table) {
88         // table headings
89         $tr = HTML::tr();
90         $headings = array(_("Plugin"), _("Version"), _("Description"));
91         if ($info == 'args')
92             $headings []= _("Arguments");
93         foreach ($headings as $title) {
94             $tr->pushContent(HTML::td($title));
95         }
96         $table->pushContent(HTML::thead($tr));
97     }
98
99     function _generateTableBody(&$info, &$dbi, &$request, &$table) {
100         $plugin_dir = 'lib/plugin';
101         if (defined('PHPWIKI_DIR'))
102             $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
103         $pd = new fileSet($plugin_dir, '*.php');
104         $plugins = $pd->getFiles();
105         unset($pd);
106         sort($plugins);
107
108         // table body
109         $tbody = HTML::tbody();
110         $row_no = 0;
111
112         $w = new WikiPluginLoader;
113         foreach ($plugins as $pluginName) {
114             // instantiate a plugin
115             $pluginName = str_replace(".php", "", $pluginName);
116             $temppluginclass = "<? plugin $pluginName ?>"; // hackish
117             $p = $w->getPlugin($pluginName, false); // second arg?
118             // trap php files which aren't WikiPlugin~s
119             if (!strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
120                 // Security: Hide names of extraneous files within
121                 // plugin dir from non-admins.
122                 if ($request->_user->isAdmin())
123                     trigger_error(sprintf(_("%s does not appear to be a WikiPlugin."),
124                                           $pluginName . ".php"));
125                 continue; // skip this non WikiPlugin file
126             }
127             $desc = $p->getDescription();
128             $ver = $p->getVersion();
129             $arguments = $p->getArgumentsDescription();
130             unset($p); //done querying plugin object, release from memory
131
132             // This section was largely improved by Pierrick Meignen:
133             // make a link if an actionpage exists
134             $pluginNamelink = $pluginName;
135             $pluginDocPageName = $pluginName . "Plugin";
136
137             $pluginDocPageNamelink = false;
138             $localizedPluginName = '';
139             $localizedPluginDocPageName = '';
140
141             if($GLOBALS['LANG'] != "en"){
142                 if (_($pluginName) != $pluginName)
143                     $localizedPluginName = _($pluginName);
144                 if($localizedPluginName && $dbi->isWikiPage($localizedPluginName))
145                     $pluginDocPageNamelink = WikiLink($localizedPluginName,'if_known');
146                 
147                 if (_($pluginDocPageName) != $pluginDocPageName)
148                     $localizedPluginDocPageName = _($pluginDocPageName);
149                 if($localizedPluginDocPageName && 
150                    $dbi->isWikiPage($localizedPluginDocPageName))
151                     $pluginDocPageNamelink = 
152                         WikiLink($localizedPluginDocPageName, 'if_known');
153             }
154             else {
155                 $pluginNamelink = WikiLink($pluginName, 'if_known');
156                 
157                 if ($dbi->isWikiPage($pluginDocPageName))
158                     $pluginDocPageNamelink = WikiLink($pluginDocPageName,'if_known');
159             }
160
161             // highlight alternate rows
162             $row_no++;
163             $group = (int)($row_no / 1); //_group_rows
164             $class = ($group % 2) ? 'evenrow' : 'oddrow';
165             // generate table row
166             $tr = HTML::tr(array('class' => $class));
167             if ($pluginDocPageNamelink) {
168                 // plugin has a description page 'PluginName' . 'Plugin'
169                 $tr->pushContent(HTML::td($pluginNamelink, HTML::br(),
170                                           $pluginDocPageNamelink));
171                 $pluginDocPageNamelink = false;
172             }
173             else {
174                 // plugin just has an actionpage
175                 $tr->pushContent(HTML::td($pluginNamelink));
176             }
177             $tr->pushContent(HTML::td($ver), HTML::td($desc));
178             if ($info == 'args') {
179                 // add Arguments column
180                 $style = array('style'
181                                => 'font-family:monospace;font-size:smaller');
182                 $tr->pushContent(HTML::td($style, $arguments));
183             }
184             $tbody->pushContent($tr);
185         }
186         $table->pushContent($tbody);
187     }
188 };
189
190 // $Log: not supported by cvs2svn $
191 // Revision 1.18  2005/09/26 06:38:00  rurban
192 // use the new method
193 //
194 // Revision 1.17  2005/01/25 06:58:22  rurban
195 // reformatting
196 //
197 // Revision 1.16  2004/06/04 20:32:54  rurban
198 // Several locale related improvements suggested by Pierrick Meignen
199 // LDAP fix by John Cole
200 // reanable admin check without ENABLE_PAGEPERM in the admin plugins
201 //
202 // Revision 1.15  2004/05/25 13:17:12  rurban
203 // fixed Fatal error: Call to a member function on a non-object in PluginManager.php on line 222
204 //
205 // Revision 1.14  2004/02/17 12:11:36  rurban
206 // 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, ...)
207 //
208 // Revision 1.13  2004/01/25 03:58:44  rurban
209 // use stdlib:isWikiWord()
210 //
211 // Revision 1.12  2004/01/04 18:14:49  wainstead
212 // Added "Description:" to the beginning of the description string, so
213 // the plugin plays nice with surrounding text.
214 //
215 // Revision 1.11  2003/12/10 01:01:24  carstenklapp
216 // New features: Also show plugin pages for localized variants.
217 // Gracefully handle broken plugins in the plugins folder (such as other
218 // lingering php files).
219 //
220 // Bugfix: Cleaned up Php warnings related to oddities of UserPreference
221 // plugin (whose default value contains an array).
222 //
223 // Internal changes: Gave GoodVariableNames to the nightmarish
224 // ones. Simplified some code with WikiLink 'if_known'.
225 //
226 // Revision 1.10  2003/11/30 18:23:48  carstenklapp
227 // Code housekeeping: PEAR coding standards reformatting only.
228 //
229 // Revision 1.9  2003/11/19 00:02:42  carstenklapp
230 // Include found locale-specific pages for the current (non-English)
231 // locale.
232 //
233 // Revision 1.8  2003/11/15 21:53:53  wainstead
234 // Minor change: list plugins in asciibetical order. It'd be better if
235 // they were alphabetical.
236 //
237 // Revision 1.7  2003/02/24 01:36:25  dairiki
238 // Don't use PHPWIKI_DIR unless it's defined.
239 // (Also typo/bugfix in SystemInfo plugin.)
240 //
241 // Revision 1.6  2003/02/24 00:56:53  carstenklapp
242 // Updated to work with recent changes to WikiLink function (fix
243 // "==Object(wikipagename)==" for unknown wiki links).
244 //
245 // Revision 1.5  2003/02/22 20:49:56  dairiki
246 // Fixes for "Call-time pass by reference has been deprecated" errors.
247 //
248 // Revision 1.4  2003/02/20 18:13:38  carstenklapp
249 // Workaround for recent changes to WikiPlugin->getPlugin.
250 // Made admin restriction for viewing this page optional.
251 // Now defaults to any user may view this page (mainly for PhpWiki Demo site).
252 // Minor code changes & reformatting.
253 //
254 // Revision 1.3  2003/01/04 02:30:12  carstenklapp
255 // Added 'info' argument to show / hide plugin "Arguments"
256 // column. Improved row highlighting and error message when viewed by
257 // non-admin user. Code refactored. Added copyleft.
258
259 // Local Variables:
260 // mode: php
261 // tab-width: 8
262 // c-basic-offset: 4
263 // c-hanging-comment-ender-p: nil
264 // indent-tabs-mode: nil
265 // End:
266 ?>