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
20 * along with PhpWiki; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
32 return _("PluginManager");
35 function getDescription () {
36 return _("List of plugins on this wiki");
39 function getVersion() {
40 return preg_replace("/[Revision: $]/", '',
44 function getDefaultArguments() {
45 return array('info' => 'args');
48 function run($dbi, $argstr, &$request, $basepage) {
49 extract($this->getArgs($argstr, $request));
52 $this->_generatePageheader($info, $h);
54 if (! REQUIRE_ADMIN || $request->_user->isadmin()) {
55 $h->pushContent(HTML::h2(_("Plugins")));
57 $table = HTML::table(array('class' => "pagelist"));
58 $this->_generateColheadings($info, $table);
59 $this->_generateTableBody($info, $dbi, $request, $table);
60 $h->pushContent($table);
62 //$h->pushContent(HTML::h2(_("Disabled Plugins")));
65 $h->pushContent(fmt("You must be an administrator to %s.",
66 _("use this plugin")));
71 function _generatePageheader(&$info, &$html) {
72 $html->pushContent(HTML::p($this->getDescription()));
75 function _generateColheadings(&$info, &$table) {
78 $headings = array(_("Plugin"), _("Version"), _("Description"));
80 $headings []= _("Arguments");
81 foreach ($headings as $title) {
82 $tr->pushContent(HTML::th($title));
84 $table->pushContent(HTML::thead($tr));
87 function _generateTableBody(&$info, &$dbi, &$request, &$table) {
89 $plugin_dir = 'lib/plugin';
90 if (defined('PHPWIKI_DIR'))
91 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
92 $pd = new fileSet($plugin_dir, '*.php');
93 $plugins = $pd->getFiles();
98 $tbody = HTML::tbody();
101 $w = new WikiPluginLoader;
102 foreach ($plugins as $pluginName) {
103 // instantiate a plugin
104 $pluginName = str_replace(".php", "", $pluginName);
105 $temppluginclass = "<? plugin $pluginName ?>"; // hackish
106 $p = $w->getPlugin($pluginName, false); // second arg?
107 // trap php files which aren't WikiPlugin~s
108 if (!strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
109 // Security: Hide names of extraneous files within
110 // plugin dir from non-admins.
111 if ($request->_user->isAdmin())
112 trigger_error(sprintf(_("%s does not appear to be a WikiPlugin."),
113 $pluginName . ".php"));
114 continue; // skip this non WikiPlugin file
116 $desc = $p->getDescription();
117 $ver = $p->getVersion();
118 $arguments = $p->getArgumentsDescription();
119 unset($p); //done querying plugin object, release from memory
121 // This section was largely improved by Pierrick Meignen:
122 // make a link if an actionpage exists
123 $pluginNamelink = $pluginName;
124 $pluginDocPageName = _("Help")."/" . $pluginName . "Plugin";
125 if (defined('GFORGE') and GFORGE) {
126 $pluginDocPageName = _("Help").":" . $pluginName . "Plugin";
129 $pluginDocPageNamelink = false;
130 $localizedPluginName = '';
131 $localizedPluginDocPageName = '';
133 if($GLOBALS['LANG'] != "en"){
134 if (_($pluginName) != $pluginName)
135 $localizedPluginName = _($pluginName);
136 if($localizedPluginName && $dbi->isWikiPage($localizedPluginName))
137 $pluginDocPageNamelink = WikiLink($localizedPluginName,'if_known');
139 if (_($pluginDocPageName) != $pluginDocPageName)
140 $localizedPluginDocPageName = _($pluginDocPageName);
141 if($localizedPluginDocPageName &&
142 $dbi->isWikiPage($localizedPluginDocPageName))
143 $pluginDocPageNamelink =
144 WikiLink($localizedPluginDocPageName, 'if_known');
147 $pluginNamelink = WikiLink($pluginName, 'if_known');
149 if ($dbi->isWikiPage($pluginDocPageName))
150 $pluginDocPageNamelink = WikiLink($pluginDocPageName,'if_known');
153 if (defined('GFORGE') and GFORGE) {
154 $pluginDocPageNamelink = WikiLink($pluginDocPageName, 'known');
157 // highlight alternate rows
159 $group = (int)($row_no / 1); //_group_rows
160 $class = ($group % 2) ? 'evenrow' : 'oddrow';
161 // generate table row
162 $tr = HTML::tr(array('class' => $class));
163 if ($pluginDocPageNamelink) {
164 // plugin has a description page 'Help/' . 'PluginName' . 'Plugin'
165 $tr->pushContent(HTML::td($pluginNamelink, HTML::br(),
166 $pluginDocPageNamelink));
167 $pluginDocPageNamelink = false;
170 // plugin just has an actionpage
171 $tr->pushContent(HTML::td($pluginNamelink));
173 $tr->pushContent(HTML::td($ver), HTML::td($desc));
174 if ($info == 'args') {
175 // add Arguments column
176 $style = array('style'
177 => 'font-family:monospace;font-size:smaller');
178 $tr->pushContent(HTML::td($style, $arguments));
180 $tbody->pushContent($tr);
182 $table->pushContent($tbody);
190 // c-hanging-comment-ender-p: nil
191 // indent-tabs-mode: nil