2 rcs_id('$Id: PluginManager.php,v 1.7 2003-02-24 01:36:25 dairiki 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 $plugin_dir = 'lib/plugin';
102 if (defined('PHPWIKI_DIR'))
103 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
104 $pd = new fileSet($plugin_dir, '*.php');
105 $plugins = $pd->getFiles();
107 $tbody = HTML::tbody();
108 global $WikiNameRegexp;
109 foreach($plugins as $pname) {
110 // instantiate a plugin
111 $pname = str_replace(".php", "", $pname);
112 $temppluginclass = "<? plugin $pname ?>"; // hackish
113 $w = new WikiPluginLoader;
114 // obtain plugin name & description
115 $p = $w->getPlugin($pname, false); // second arg?
116 $desc = $p->getDescription();
117 // obtain plugin version
118 if (method_exists($p, 'getVersion')) {
119 $ver = $p->getVersion();
124 // obtain plugin's default arguments
126 $args = $p->getDefaultArguments();
128 foreach ($args as $arg => $default) {
129 if (stristr($default, ' '))
130 $default = "'$default'";
131 $arguments->pushcontent("$arg=$default", HTML::br());
133 // make a link if an actionpage exists
136 if (preg_match("/^$WikiNameRegexp\$/", $pname)
137 && $dbi->isWikiPage($pname))
138 $pnamelink = WikiLink($pname);
139 // make another link if an XxxYyyPlugin page exists
140 $ppname = $pname . "Plugin";
141 if (preg_match("/^$WikiNameRegexp\$/", $ppname)
142 && $dbi->isWikiPage($ppname))
143 $plink = WikiLink($ppname);
145 // don't link to actionpages and plugins starting with
146 // an _ from page list
147 if ( !preg_match("/^_/", $pname)
148 //&& !(@$request->isActionPage($pname)) //FIXME?
150 // $plink = WikiLink($ppname, 'unknown');
152 $plink = $Theme->linkUnknownWikiWord($ppname);
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));
164 // plugin has a XxxYyyPlugin page
165 $tr->pushContent(HTML::td($pnamelink, HTML::br(), $plink));
170 // plugin just has an actionpage
171 $tr->pushContent(HTML::td($pnamelink));
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);
186 // $Log: not supported by cvs2svn $
187 // Revision 1.6 2003/02/24 00:56:53 carstenklapp
188 // Updated to work with recent changes to WikiLink function (fix "==Object(wikipagename)==" for unknown wiki links).
190 // Revision 1.5 2003/02/22 20:49:56 dairiki
191 // Fixes for "Call-time pass by reference has been deprecated" errors.
193 // Revision 1.4 2003/02/20 18:13:38 carstenklapp
194 // Workaround for recent changes to WikiPlugin->getPlugin.
195 // Made admin restriction for viewing this page optional.
196 // Now defaults to any user may view this page (mainly for PhpWiki Demo site).
197 // Minor code changes & reformatting.
199 // Revision 1.3 2003/01/04 02:30:12 carstenklapp
200 // Added 'info' argument to show / hide plugin "Arguments"
201 // column. Improved row highlighting and error message when viewed by
202 // non-admin user. Code refactored. Added copyleft.
208 // c-hanging-comment-ender-p: nil
209 // indent-tabs-mode: nil