]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PluginManager.php
GFORGE --> FUSIONFORGE
[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 getDefaultArguments() {
40         return array('info' => 'args');
41     }
42
43     function run($dbi, $argstr, &$request, $basepage) {
44         extract($this->getArgs($argstr, $request));
45
46         $h = HTML();
47         $this->_generatePageheader($info, $h);
48
49         if (! REQUIRE_ADMIN || $request->_user->isadmin()) {
50             $h->pushContent(HTML::h2(_("Plugins")));
51
52             $table = HTML::table(array('class' => "pagelist"));
53             $this->_generateColheadings($info, $table);
54             $this->_generateTableBody($info, $dbi, $request, $table);
55             $h->pushContent($table);
56         }
57         else {
58             $h->pushContent(fmt("You must be an administrator to %s.",
59                                 _("use this plugin")));
60         }
61         return $h;
62     }
63
64     function _generatePageheader(&$info, &$html) {
65         $html->pushContent(HTML::p($this->getDescription()));
66     }
67
68     function _generateColheadings(&$info, &$table) {
69         // table headings
70         $tr = HTML::tr();
71         $headings = array(_("Plugin"), _("Description"));
72         if ($info == 'args')
73             $headings []= _("Arguments");
74         foreach ($headings as $title) {
75             $tr->pushContent(HTML::th($title));
76         }
77         $table->pushContent(HTML::thead($tr));
78     }
79
80     function _generateTableBody(&$info, &$dbi, &$request, &$table) {
81
82         global $AllAllowedPlugins;
83
84         $plugin_dir = 'lib/plugin';
85         if (defined('PHPWIKI_DIR'))
86             $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
87         $pd = new fileSet($plugin_dir, '*.php');
88         $plugins = $pd->getFiles();
89         unset($pd);
90         sort($plugins);
91
92         // table body
93         $tbody = HTML::tbody();
94         $row_no = 0;
95
96         $w = new WikiPluginLoader;
97         foreach ($plugins as $pluginName) {
98
99             $pluginName = str_replace(".php", "", $pluginName);
100             if (in_array($pluginName, $AllAllowedPlugins) === false) {
101                 continue;
102             }
103             // instantiate a plugin
104             $temppluginclass = "<? plugin $pluginName ?>"; // hackish
105             $p = $w->getPlugin($pluginName, false); // second arg?
106             // trap php files which aren't WikiPlugin~s
107             if (!strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
108                 // Security: Hide names of extraneous files within
109                 // plugin dir from non-admins.
110                 if ($request->_user->isAdmin())
111                     trigger_error(sprintf(_("%s does not appear to be a WikiPlugin."),
112                                           $pluginName . ".php"));
113                 continue; // skip this non WikiPlugin file
114             }
115             $desc = $p->getDescription();
116             $arguments = $p->getArgumentsDescription();
117             unset($p); //done querying plugin object, release from memory
118
119             // This section was largely improved by Pierrick Meignen:
120             // make a link if an actionpage exists
121             $pluginNamelink = $pluginName;
122             $pluginDocPageName = _("Help")."/" . $pluginName . "Plugin";
123             if (defined('FUSIONFORGE') and FUSIONFORGE) {
124                 $pluginDocPageName = _("Help").":" . $pluginName . "Plugin";
125             }
126
127             $pluginDocPageNamelink = false;
128             $localizedPluginName = '';
129             $localizedPluginDocPageName = '';
130
131             if($GLOBALS['LANG'] != "en"){
132                 if (_($pluginName) != $pluginName)
133                     $localizedPluginName = _($pluginName);
134                 if($localizedPluginName && $dbi->isWikiPage($localizedPluginName))
135                     $pluginDocPageNamelink = WikiLink($localizedPluginName,'if_known');
136
137                 if (_($pluginDocPageName) != $pluginDocPageName)
138                     $localizedPluginDocPageName = _($pluginDocPageName);
139                 if($localizedPluginDocPageName &&
140                    $dbi->isWikiPage($localizedPluginDocPageName))
141                     $pluginDocPageNamelink =
142                         WikiLink($localizedPluginDocPageName, 'if_known');
143             }
144             else {
145                 $pluginNamelink = WikiLink($pluginName, 'if_known');
146
147                 if ($dbi->isWikiPage($pluginDocPageName))
148                     $pluginDocPageNamelink = WikiLink($pluginDocPageName,'if_known');
149             }
150
151             if (defined('FUSIONFORGE') and FUSIONFORGE) {
152                 $pluginDocPageNamelink = WikiLink($pluginDocPageName, 'known');
153             }
154
155             // highlight alternate rows
156             $row_no++;
157             $group = (int)($row_no / 1); //_group_rows
158             $class = ($group % 2) ? 'evenrow' : 'oddrow';
159             // generate table row
160             $tr = HTML::tr(array('class' => $class));
161             if ($pluginDocPageNamelink) {
162                 // plugin has a description page 'Help/' . 'PluginName' . 'Plugin'
163                 $tr->pushContent(HTML::td($pluginNamelink, HTML::br(),
164                                           $pluginDocPageNamelink));
165                 $pluginDocPageNamelink = false;
166             }
167             else {
168                 // plugin just has an actionpage
169                 $tr->pushContent(HTML::td($pluginNamelink));
170             }
171             $tr->pushContent(HTML::td($desc));
172             if ($info == 'args') {
173                 // add Arguments column
174                 $style = array('style'
175                                => 'font-family:monospace;font-size:smaller');
176                 $tr->pushContent(HTML::td($style, $arguments));
177             }
178             $tbody->pushContent($tr);
179         }
180         $table->pushContent($tbody);
181     }
182 };
183
184 // Local Variables:
185 // mode: php
186 // tab-width: 8
187 // c-basic-offset: 4
188 // c-hanging-comment-ender-p: nil
189 // indent-tabs-mode: nil
190 // End:
191 ?>