2 rcs_id('$Id: PluginManager.php,v 1.10 2003-11-30 18:23:48 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
24 // Some of this code can be simplified with the relatively new
25 // WikiLink($p, 'auto') function.
27 // Set this to true if you don't want regular users to view this page.
28 // So far there are no known security issues.
29 define('REQUIRE_ADMIN', false);
31 class WikiPlugin_PluginManager
35 return _("PluginManager");
38 function getDescription () {
39 return _("Provides a list of plugins on this wiki.");
42 function getVersion() {
43 return preg_replace("/[Revision: $]/", '',
44 "\$Revision: 1.10 $");
47 function getDefaultArguments() {
48 return array('info' => 'args');
51 function run($dbi, $argstr, $request) {
52 extract($this->getArgs($argstr, $request));
55 $this->_generatePageheader($info, $h);
57 if (! REQUIRE_ADMIN || $request->_user->isadmin()) {
58 $h->pushContent(HTML::h2(_("Plugins")));
60 $table = HTML::table(array('class' => "pagelist"));
61 $this->_generateColgroups($info, $table);
62 $this->_generateColheadings($info, $table);
63 $this->_generateTableBody($info, $dbi, $request, $table);
64 $h->pushContent($table);
66 //$h->pushContent(HTML::h2(_("Disabled Plugins")));
69 $h->pushContent(fmt("You must be an administrator to %s.",
70 _("use this plugin")));
75 function _generatePageheader(&$info, &$html) {
76 $html->pushContent(HTML::p($this->getDescription()));
79 function _generateColgroups(&$info, &$table) {
80 // specify last two column widths
81 $colgroup = HTML::colgroup();
82 $colgroup->pushContent(HTML::col(array('width' => '0*')));
83 $colgroup->pushContent(HTML::col(array('width' => '0*',
84 'align' => 'right')));
85 $colgroup->pushContent(HTML::col(array('width' => '9*')));
87 $colgroup->pushContent(HTML::col(array('width' => '2*')));
88 $table->pushcontent($colgroup);
91 function _generateColheadings(&$info, &$table) {
94 $headings = array(_("Plugin"), _("Version"), _("Description"));
96 $headings []= _("Arguments");
97 foreach ($headings as $title) {
98 $tr->pushContent(HTML::td($title));
100 $table->pushContent(HTML::thead($tr));
103 function _generateTableBody(&$info, &$dbi, &$request, &$table) {
105 $plugin_dir = 'lib/plugin';
106 if (defined('PHPWIKI_DIR'))
107 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
108 $pd = new fileSet($plugin_dir, '*.php');
109 $plugins = $pd->getFiles();
112 $tbody = HTML::tbody();
113 global $WikiNameRegexp;
114 foreach($plugins as $pname) {
115 // instantiate a plugin
116 $pname = str_replace(".php", "", $pname);
117 $temppluginclass = "<? plugin $pname ?>"; // hackish
118 $w = new WikiPluginLoader;
119 // obtain plugin name & description
120 $p = $w->getPlugin($pname, false); // second arg?
121 $desc = $p->getDescription();
122 // obtain plugin version
123 if (method_exists($p, 'getVersion')) {
124 $ver = $p->getVersion();
129 // obtain plugin's default arguments
131 $args = $p->getDefaultArguments();
133 foreach ($args as $arg => $default) {
134 if (stristr($default, ' '))
135 $default = "'$default'";
136 $arguments->pushcontent("$arg=$default", HTML::br());
138 // make a link if an actionpage exists
141 // Also look for pages in the current locale
142 if (_($pname) != $pname) {
147 if (preg_match("/^$WikiNameRegexp\$/", $pname)
148 && $dbi->isWikiPage($pname)) {
149 $pnamelink = HTML(WikiLink($pname));
151 // make another link if an XxxYyyPlugin page exists
152 $ppname = $pname . "Plugin";
153 // Also look for pages in the current locale
154 if (_($ppname) != $ppname) {
159 if (preg_match("/^$WikiNameRegexp\$/", $ppname)
160 && $dbi->isWikiPage($ppname)) {
161 $plink = HTML(WikiLink($ppname));
164 // don't link to actionpages and plugins starting with
165 // an _ from page list
166 if (!preg_match("/^_/", $pname)
167 //&& !(@$request->isActionPage($pname)) //FIXME?
169 // $plink = WikiLink($ppname, 'unknown');
171 $plink = $Theme->linkUnknownWikiWord($ppname);
176 // insert any found locale-specific pages at the bottom of
179 // really this should all just be put into a new <p>
181 //$plink->pushContent(HTML::br());
182 //$plink->pushContent(HTML::br());
184 // Don't offer to create a link to a non-wikiword
185 // localized plugin page but show those that
186 // already exist (Calendar, Comment, etc.) (Non
187 // non-wikiword plugins are okay, they just can't
188 // become actionPages.)
189 if (preg_match("/^$WikiNameRegexp\$/", $l1) || $dbi->isWikiPage($l1)) {
190 $par->pushContent(WikiLink($l1, 'auto'));
193 // probably incorrectly translated, so no page link
194 $par->pushContent($l1, ' ' . _("(Not a WikiWord)"));
198 $par->pushContent(HTML::br());
200 if (preg_match("/^$WikiNameRegexp\$/", $l2) || $dbi->isWikiPage($l2)) {
201 $par->pushContent(WikiLink($l2, 'auto'));
204 // probably incorrectly translated, so no page link
205 $par->pushContent($l2, ' ' . _("(Not a WikiWord)"));
208 $plink->pushContent($par);
211 // highlight alternate rows
213 $group = (int)($row_no / 1); //_group_rows
214 $class = ($group % 2) ? 'evenrow' : 'oddrow';
215 // generate table row
216 $tr = HTML::tr(array('class' => $class));
218 // plugin has a XxxYyyPlugin page
219 $tr->pushContent(HTML::td($pnamelink, HTML::br(), $plink));
224 // plugin just has an actionpage
225 $tr->pushContent(HTML::td($pnamelink));
227 $tr->pushContent(HTML::td($ver), HTML::td($desc));
228 if ($info == 'args') {
229 // add Arguments column
230 $style = array('style'
231 => 'font-family:monospace;font-size:smaller');
232 $tr->pushContent(HTML::td($style, $arguments));
234 $tbody->pushContent($tr);
236 $table->pushContent($tbody);
240 // $Log: not supported by cvs2svn $
241 // Revision 1.9 2003/11/19 00:02:42 carstenklapp
242 // Include found locale-specific pages for the current (non-English)
245 // Revision 1.8 2003/11/15 21:53:53 wainstead
246 // Minor change: list plugins in asciibetical order. It'd be better if
247 // they were alphabetical.
249 // Revision 1.7 2003/02/24 01:36:25 dairiki
250 // Don't use PHPWIKI_DIR unless it's defined.
251 // (Also typo/bugfix in SystemInfo plugin.)
253 // Revision 1.6 2003/02/24 00:56:53 carstenklapp
254 // Updated to work with recent changes to WikiLink function (fix
255 // "==Object(wikipagename)==" for unknown wiki links).
257 // Revision 1.5 2003/02/22 20:49:56 dairiki
258 // Fixes for "Call-time pass by reference has been deprecated" errors.
260 // Revision 1.4 2003/02/20 18:13:38 carstenklapp
261 // Workaround for recent changes to WikiPlugin->getPlugin.
262 // Made admin restriction for viewing this page optional.
263 // Now defaults to any user may view this page (mainly for PhpWiki Demo site).
264 // Minor code changes & reformatting.
266 // Revision 1.3 2003/01/04 02:30:12 carstenklapp
267 // Added 'info' argument to show / hide plugin "Arguments"
268 // column. Improved row highlighting and error message when viewed by
269 // non-admin user. Code refactored. Added copyleft.
275 // c-hanging-comment-ender-p: nil
276 // indent-tabs-mode: nil