2 rcs_id('$Id: PluginManager.php,v 1.9 2003-11-19 00:02:42 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: $]/", '',
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) {
146 if (preg_match("/^$WikiNameRegexp\$/", $pname)
147 && $dbi->isWikiPage($pname)) {
148 $pnamelink = HTML(WikiLink($pname));
150 // make another link if an XxxYyyPlugin page exists
151 $ppname = $pname . "Plugin";
152 // Also look for pages in the current locale
153 if (_($ppname) != $ppname) {
157 if (preg_match("/^$WikiNameRegexp\$/", $ppname)
158 && $dbi->isWikiPage($ppname)) {
159 $plink = HTML(WikiLink($ppname));
162 // don't link to actionpages and plugins starting with
163 // an _ from page list
164 if ( !preg_match("/^_/", $pname)
165 //&& !(@$request->isActionPage($pname)) //FIXME?
167 // $plink = WikiLink($ppname, 'unknown');
169 $plink = $Theme->linkUnknownWikiWord($ppname);
174 // insert any found locale-specific pages at the bottom of the td
176 // really this should all just be put into a new <p>
178 //$plink->pushContent(HTML::br());
179 //$plink->pushContent(HTML::br());
181 // Don't offer to create a link to a non-wikiword localized plugin page
182 // but show those that already exist (Calendar, Comment, etc.)
183 // (Non non-wikiword plugins are okay, they just can't become actionPages.)
184 if (preg_match("/^$WikiNameRegexp\$/", $l1) || $dbi->isWikiPage($l1)) {
185 $par->pushContent(WikiLink($l1, 'auto'));
187 // probably incorrectly translated, so no page link
188 $par->pushContent($l1, ' ' . _("(Not a WikiWord)"));
192 $par->pushContent(HTML::br());
194 if (preg_match("/^$WikiNameRegexp\$/", $l2) || $dbi->isWikiPage($l2)) {
195 $par->pushContent(WikiLink($l2, 'auto'));
197 // probably incorrectly translated, so no page link
198 $par->pushContent($l2, ' ' . _("(Not a WikiWord)"));
202 $plink->pushContent($par);
205 // highlight alternate rows
207 $group = (int)($row_no / 1); //_group_rows
208 $class = ($group % 2) ? 'evenrow' : 'oddrow';
209 // generate table row
210 $tr = HTML::tr(array('class' => $class));
212 // plugin has a XxxYyyPlugin page
213 $tr->pushContent(HTML::td($pnamelink, HTML::br(), $plink));
218 // plugin just has an actionpage
219 $tr->pushContent(HTML::td($pnamelink));
221 $tr->pushContent(HTML::td($ver), HTML::td($desc));
222 if ($info == 'args') {
223 // add Arguments column
224 $style = array('style'
225 => 'font-family:monospace;font-size:smaller');
226 $tr->pushContent(HTML::td($style, $arguments));
228 $tbody->pushContent($tr);
230 $table->pushContent($tbody);
234 // $Log: not supported by cvs2svn $
235 // Revision 1.8 2003/11/15 21:53:53 wainstead
236 // Minor change: list plugins in asciibetical order. It'd be better if
237 // they were alphabetical.
239 // Revision 1.7 2003/02/24 01:36:25 dairiki
240 // Don't use PHPWIKI_DIR unless it's defined.
241 // (Also typo/bugfix in SystemInfo plugin.)
243 // Revision 1.6 2003/02/24 00:56:53 carstenklapp
244 // Updated to work with recent changes to WikiLink function (fix "==Object(wikipagename)==" for unknown wiki links).
246 // Revision 1.5 2003/02/22 20:49:56 dairiki
247 // Fixes for "Call-time pass by reference has been deprecated" errors.
249 // Revision 1.4 2003/02/20 18:13:38 carstenklapp
250 // Workaround for recent changes to WikiPlugin->getPlugin.
251 // Made admin restriction for viewing this page optional.
252 // Now defaults to any user may view this page (mainly for PhpWiki Demo site).
253 // Minor code changes & reformatting.
255 // Revision 1.3 2003/01/04 02:30:12 carstenklapp
256 // Added 'info' argument to show / hide plugin "Arguments"
257 // column. Improved row highlighting and error message when viewed by
258 // non-admin user. Code refactored. Added copyleft.
264 // c-hanging-comment-ender-p: nil
265 // indent-tabs-mode: nil