]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PluginManager.php
Handle multiple wikis in Gforge
[SourceForge/phpwiki.git] / lib / plugin / PluginManager.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /**
4  Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5  Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
6
7  This file is part of PhpWiki.
8
9  PhpWiki is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13
14  PhpWiki is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with PhpWiki; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 // Set this to true if you don't want regular users to view this page.
25 // So far there are no known security issues.
26 define('REQUIRE_ADMIN', false);
27
28 class WikiPlugin_PluginManager
29 extends WikiPlugin
30 {
31     function getName () {
32         return _("PluginManager");
33     }
34
35     function getDescription () {
36         return _("List of plugins on this wiki");
37     }
38
39     function getVersion() {
40         return preg_replace("/[Revision: $]/", '',
41                             "\$Revision$");
42     }
43
44     function getDefaultArguments() {
45         return array('info' => 'args');
46     }
47
48     function run($dbi, $argstr, &$request, $basepage) {
49         extract($this->getArgs($argstr, $request));
50
51         $h = HTML();
52         $this->_generatePageheader($info, $h);
53
54         if (! REQUIRE_ADMIN || $request->_user->isadmin()) {
55             $h->pushContent(HTML::h2(_("Plugins")));
56
57             $table = HTML::table(array('class' => "pagelist"));
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 _generateColheadings(&$info, &$table) {
76         // table headings
77         $tr = HTML::tr();
78         $headings = array(_("Plugin"), _("Version"), _("Description"));
79         if ($info == 'args')
80             $headings []= _("Arguments");
81         foreach ($headings as $title) {
82             $tr->pushContent(HTML::th($title));
83         }
84         $table->pushContent(HTML::thead($tr));
85     }
86
87     function _generateTableBody(&$info, &$dbi, &$request, &$table) {
88
89         global $WikiTheme;
90
91         $plugin_dir = 'lib/plugin';
92         if (defined('PHPWIKI_DIR'))
93             $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
94         $pd = new fileSet($plugin_dir, '*.php');
95         $plugins = $pd->getFiles();
96         unset($pd);
97         sort($plugins);
98
99         // table body
100         $tbody = HTML::tbody();
101         $row_no = 0;
102
103         $w = new WikiPluginLoader;
104         foreach ($plugins as $pluginName) {
105             // instantiate a plugin
106             $pluginName = str_replace(".php", "", $pluginName);
107             $temppluginclass = "<? plugin $pluginName ?>"; // hackish
108             $p = $w->getPlugin($pluginName, false); // second arg?
109             // trap php files which aren't WikiPlugin~s
110             if (!strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
111                 // Security: Hide names of extraneous files within
112                 // plugin dir from non-admins.
113                 if ($request->_user->isAdmin())
114                     trigger_error(sprintf(_("%s does not appear to be a WikiPlugin."),
115                                           $pluginName . ".php"));
116                 continue; // skip this non WikiPlugin file
117             }
118             $desc = $p->getDescription();
119             $ver = $p->getVersion();
120             $arguments = $p->getArgumentsDescription();
121             unset($p); //done querying plugin object, release from memory
122
123             // This section was largely improved by Pierrick Meignen:
124             // make a link if an actionpage exists
125             $pluginNamelink = $pluginName;
126             $pluginDocPageName = _("Help")."/" . $pluginName . "Plugin";
127             if (isa($WikiTheme, 'WikiTheme_gforge')) {
128                 $pluginDocPageName = _("Help").":" . $pluginName . "Plugin";
129             }
130
131             $pluginDocPageNamelink = false;
132             $localizedPluginName = '';
133             $localizedPluginDocPageName = '';
134
135             if($GLOBALS['LANG'] != "en"){
136                 if (_($pluginName) != $pluginName)
137                     $localizedPluginName = _($pluginName);
138                 if($localizedPluginName && $dbi->isWikiPage($localizedPluginName))
139                     $pluginDocPageNamelink = WikiLink($localizedPluginName,'if_known');
140                 
141                 if (_($pluginDocPageName) != $pluginDocPageName)
142                     $localizedPluginDocPageName = _($pluginDocPageName);
143                 if($localizedPluginDocPageName && 
144                    $dbi->isWikiPage($localizedPluginDocPageName))
145                     $pluginDocPageNamelink = 
146                         WikiLink($localizedPluginDocPageName, 'if_known');
147             }
148             else {
149                 $pluginNamelink = WikiLink($pluginName, 'if_known');
150                 
151                 if ($dbi->isWikiPage($pluginDocPageName))
152                     $pluginDocPageNamelink = WikiLink($pluginDocPageName,'if_known');
153             }
154
155             if (isa($WikiTheme, 'WikiTheme_gforge')) {
156                 $pluginDocPageNamelink = WikiLink($pluginDocPageName, 'known');
157             }
158
159             // highlight alternate rows
160             $row_no++;
161             $group = (int)($row_no / 1); //_group_rows
162             $class = ($group % 2) ? 'evenrow' : 'oddrow';
163             // generate table row
164             $tr = HTML::tr(array('class' => $class));
165             if ($pluginDocPageNamelink) {
166                 // plugin has a description page 'Help/' . 'PluginName' . 'Plugin'
167                 $tr->pushContent(HTML::td($pluginNamelink, HTML::br(),
168                                           $pluginDocPageNamelink));
169                 $pluginDocPageNamelink = false;
170             }
171             else {
172                 // plugin just has an actionpage
173                 $tr->pushContent(HTML::td($pluginNamelink));
174             }
175             $tr->pushContent(HTML::td($ver), HTML::td($desc));
176             if ($info == 'args') {
177                 // add Arguments column
178                 $style = array('style'
179                                => 'font-family:monospace;font-size:smaller');
180                 $tr->pushContent(HTML::td($style, $arguments));
181             }
182             $tbody->pushContent($tr);
183         }
184         $table->pushContent($tbody);
185     }
186 };
187
188 // Local Variables:
189 // mode: php
190 // tab-width: 8
191 // c-basic-offset: 4
192 // c-hanging-comment-ender-p: nil
193 // indent-tabs-mode: nil
194 // End:
195 ?>