2 rcs_id('$Id: PluginManager.php,v 1.4 2003-02-20 18:13:38 carstenklapp Exp $');
4 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
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.
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.
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
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);
27 class WikiPlugin_PluginManager
31 return _("PluginManager");
34 function getDescription () {
35 return _("Provides a list of plugins on this wiki.");
38 function getVersion() {
39 return preg_replace("/[Revision: $]/", '',
43 function getDefaultArguments() {
44 return array('info' => 'args');
47 function run($dbi, $argstr, $request) {
48 extract($this->getArgs($argstr, $request));
51 $this->_generatePageheader($info, &$h);
53 if (! REQUIRE_ADMIN || $request->_user->isadmin()) {
54 $h->pushContent(HTML::h2(_("Plugins")));
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);
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 _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*')));
83 $colgroup->pushContent(HTML::col(array('width' => '2*')));
84 $table->pushcontent($colgroup);
87 function _generateColheadings(&$info, &$table) {
90 $headings = array(_("Plugin"), _("Version"), _("Description"));
92 $headings []= _("Arguments");
93 foreach ($headings as $title) {
94 $tr->pushContent(HTML::td($title));
96 $table->pushContent(HTML::thead($tr));
99 function _generateTableBody(&$info, &$dbi, &$request, &$table) {
101 $pd = new fileSet(PHPWIKI_DIR . '/lib/plugin', '*.php');
102 $plugins = $pd->getFiles();
104 $tbody = HTML::tbody();
105 global $WikiNameRegexp;
106 foreach($plugins as $pname) {
107 // instantiate a plugin
108 $pname = str_replace(".php", "", $pname);
109 $temppluginclass = "<? plugin $pname ?>"; // hackish
110 $w = new WikiPluginLoader;
111 // obtain plugin name & description
112 $p = $w->getPlugin($pname, false); // second arg?
113 $desc = $p->getDescription();
114 // obtain plugin version
115 if (method_exists($p, 'getVersion')) {
116 $ver = $p->getVersion();
121 // obtain plugin's default arguments
123 $args = $p->getDefaultArguments();
125 foreach ($args as $arg => $default) {
126 if (stristr($default, ' '))
127 $default = "'$default'";
128 $arguments->pushcontent("$arg=$default", HTML::br());
130 // make a link if an actionpage exists
133 if (preg_match("/^$WikiNameRegexp\$/", $pname)
134 && $dbi->isWikiPage($pname))
135 $pnamelink = WikiLink($pname);
136 // make another link if an XxxYyyPlugin page exists
137 $ppname = $pname . "Plugin";
138 if (preg_match("/^$WikiNameRegexp\$/", $ppname)
139 && $dbi->isWikiPage($ppname))
140 $plink = WikiLink($ppname);
142 // don't link to actionpages and plugins starting with
143 // an _ from page list
144 if ( !preg_match("/^_/", $pname)
145 //&& !(@$request->isActionPage($pname)) //FIXME
147 $plink = WikiLink($ppname, 'unknown');
151 // highlight alternate rows
153 $group = (int)($row_no / 1); //_group_rows
154 $class = ($group % 2) ? 'evenrow' : 'oddrow';
155 // generate table row
156 $tr = HTML::tr(array('class' => $class));
158 // plugin has a XxxYyyPlugin page
159 $tr->pushContent(HTML::td($pnamelink, HTML::br(), $plink));
164 // plugin just has an actionpage
165 $tr->pushContent(HTML::td($pnamelink));
167 $tr->pushContent(HTML::td($ver), HTML::td($desc));
168 if ($info == 'args') {
169 // add Arguments column
170 $style = array('style'
171 => 'font-family:monospace;font-size:smaller');
172 $tr->pushContent(HTML::td($style, $arguments));
174 $tbody->pushContent($tr);
176 $table->pushContent($tbody);
180 // $Log: not supported by cvs2svn $
181 // Revision 1.3 2003/01/04 02:30:12 carstenklapp
182 // Added 'info' argument to show / hide plugin "Arguments"
183 // column. Improved row highlighting and error message when viewed by
184 // non-admin user. Code refactored. Added copyleft.
190 // c-hanging-comment-ender-p: nil
191 // indent-tabs-mode: nil