4 * Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5 * Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
7 * This file is part of PhpWiki.
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.
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.
19 * You should have received a copy of the GNU General Public License along
20 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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);
28 class WikiPlugin_PluginManager
33 return _("PluginManager");
36 function getDescription()
38 return _("List of plugins on this wiki.");
41 function getDefaultArguments()
43 return array('info' => 'args');
46 function run($dbi, $argstr, &$request, $basepage)
48 extract($this->getArgs($argstr, $request));
51 $this->_generatePageheader($info, $h);
53 if (!REQUIRE_ADMIN || $request->_user->isadmin()) {
54 $table = HTML::table(array('class' => "pagelist"));
55 $this->_generateColheadings($info, $table);
56 $this->_generateTableBody($info, $dbi, $request, $table);
57 $h->pushContent($table);
59 $h->pushContent(fmt("You must be an administrator to %s.",
60 _("use this plugin")));
65 function _generatePageheader(&$info, &$html)
67 $html->pushContent(HTML::p($this->getDescription()));
70 function _generateColheadings(&$info, &$table)
74 $headings = array(_("Plugin"), _("Description"));
76 $headings [] = _("Arguments");
77 foreach ($headings as $title) {
78 $tr->pushContent(HTML::th($title));
80 $table->pushContent(HTML::thead($tr));
83 function _generateTableBody(&$info, &$dbi, &$request, &$table)
86 global $AllAllowedPlugins;
88 $plugin_dir = 'lib/plugin';
89 if (defined('PHPWIKI_DIR'))
90 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
91 $pd = new fileSet($plugin_dir, '*.php');
92 $plugins = $pd->getFiles();
97 $tbody = HTML::tbody();
100 $w = new WikiPluginLoader;
101 foreach ($plugins as $pluginName) {
103 $pluginName = str_replace(".php", "", $pluginName);
104 if (in_array($pluginName, $AllAllowedPlugins) === false) {
107 // instantiate a plugin
108 $temppluginclass = '<' . "? plugin $pluginName ?>"; // hackish
109 $p = $w->getPlugin($pluginName, false); // second arg?
110 // trap php files which aren't WikiPlugin~s
111 if (!strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
112 // Security: Hide names of extraneous files within
113 // plugin dir from non-admins.
114 if ($request->_user->isAdmin())
115 trigger_error(sprintf(_("%s does not appear to be a WikiPlugin."),
116 $pluginName . ".php"));
117 continue; // skip this non WikiPlugin file
119 $desc = $p->getDescription();
120 $arguments = $p->getArgumentsDescription();
121 unset($p); //done querying plugin object, release from memory
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 (defined('FUSIONFORGE') and FUSIONFORGE) {
128 $pluginDocPageName = _("Help") . ":" . $pluginName . "Plugin";
131 $pluginDocPageNamelink = false;
132 $localizedPluginName = '';
133 $localizedPluginDocPageName = '';
135 if ($GLOBALS['LANG'] != "en") {
136 if (_($pluginName) != $pluginName)
137 $localizedPluginName = _($pluginName);
138 if ($localizedPluginName && $dbi->isWikiPage($localizedPluginName))
139 $pluginDocPageNamelink = WikiLink($localizedPluginName, 'if_known');
141 if (_($pluginDocPageName) != $pluginDocPageName)
142 $localizedPluginDocPageName = _($pluginDocPageName);
143 if ($localizedPluginDocPageName &&
144 $dbi->isWikiPage($localizedPluginDocPageName)
146 $pluginDocPageNamelink =
147 WikiLink($localizedPluginDocPageName, 'if_known');
149 $pluginNamelink = WikiLink($pluginName, 'if_known');
151 if ($dbi->isWikiPage($pluginDocPageName))
152 $pluginDocPageNamelink = WikiLink($pluginDocPageName, 'if_known');
155 if (defined('FUSIONFORGE') and FUSIONFORGE) {
156 $pluginDocPageNamelink = WikiLink($pluginDocPageName, 'known');
159 // highlight alternate rows
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;
171 // plugin just has an actionpage
172 $tr->pushContent(HTML::td($pluginNamelink));
174 $tr->pushContent(HTML::td($desc));
175 if ($info == 'args') {
176 // add Arguments column
177 $style = array('style'
178 => 'font-family:monospace;font-size:smaller');
179 $tr->pushContent(HTML::td($style, $arguments));
181 $tbody->pushContent($tr);
183 $table->pushContent($tbody);
191 // c-hanging-comment-ender-p: nil
192 // indent-tabs-mode: nil