]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PluginManager.php
Workaround for recent changes to WikiPlugin->getPlugin.
[SourceForge/phpwiki.git] / lib / plugin / PluginManager.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PluginManager.php,v 1.4 2003-02-20 18:13:38 carstenklapp Exp $');
3 /**
4  Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
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.
12
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.
17
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
21  */
22
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);
26
27 class WikiPlugin_PluginManager
28 extends WikiPlugin
29 {
30     function getName () {
31         return _("PluginManager");
32     }
33
34     function getDescription () {
35         return _("Provides a list of plugins on this wiki.");
36     }
37
38     function getVersion() {
39         return preg_replace("/[Revision: $]/", '',
40                             "\$Revision: 1.4 $");
41     }
42
43     function getDefaultArguments() {
44         return array('info' => 'args');
45     }
46
47     function run($dbi, $argstr, $request) {
48         extract($this->getArgs($argstr, $request));
49
50         $h = HTML();
51         $this->_generatePageheader($info, &$h);
52
53         if (! REQUIRE_ADMIN || $request->_user->isadmin()) {
54             $h->pushContent(HTML::h2(_("Plugins")));
55
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);
61
62             //$h->pushContent(HTML::h2(_("Disabled Plugins")));
63         }
64         else {
65             $h->pushContent(fmt("You must be an administrator to %s.",
66                                 _("use this plugin")));
67         }
68         return $h;
69     }
70
71     function _generatePageheader(&$info, &$html) {
72         $html->pushContent(HTML::p($this->getDescription()));
73     }
74
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*')));
82         if ($info == 'args')
83             $colgroup->pushContent(HTML::col(array('width' => '2*')));
84         $table->pushcontent($colgroup);
85     }
86
87     function _generateColheadings(&$info, &$table) {
88         // table headings
89         $tr = HTML::tr();
90         $headings = array(_("Plugin"), _("Version"), _("Description"));
91         if ($info == 'args')
92             $headings []= _("Arguments");
93         foreach ($headings as $title) {
94             $tr->pushContent(HTML::td($title));
95         }
96         $table->pushContent(HTML::thead($tr));
97     }
98
99     function _generateTableBody(&$info, &$dbi, &$request, &$table) {
100         $row_no = 0;
101         $pd = new fileSet(PHPWIKI_DIR . '/lib/plugin', '*.php');
102         $plugins = $pd->getFiles();
103         // table body
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();
117             }
118             else {
119                 $ver = "--";
120             }
121             // obtain plugin's default arguments
122             $arguments = HTML();
123             $args = $p->getDefaultArguments();
124
125             foreach ($args as $arg => $default) {
126                 if (stristr($default, ' '))
127                     $default = "'$default'";
128                 $arguments->pushcontent("$arg=$default", HTML::br());
129             }
130             // make a link if an actionpage exists
131             $pnamelink = $pname;
132             $plink = false;
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);
141             else {
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
146                     )
147                     $plink = WikiLink($ppname, 'unknown');
148                 else
149                     $plink = false;
150             }
151             // highlight alternate rows
152             $row_no++;
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));
157             if ($plink) {
158                 // plugin has a XxxYyyPlugin page
159                 $tr->pushContent(HTML::td($pnamelink, HTML::br(), $plink));
160                 $plink = false;
161                 //$row_no++;
162             }
163             else {
164                 // plugin just has an actionpage
165                 $tr->pushContent(HTML::td($pnamelink));
166             }
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));
173             }
174             $tbody->pushContent($tr);
175         }
176         $table->pushContent($tbody);
177     }
178 };
179
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.
185
186 // Local Variables:
187 // mode: php
188 // tab-width: 8
189 // c-basic-offset: 4
190 // c-hanging-comment-ender-p: nil
191 // indent-tabs-mode: nil
192 // End:
193 ?>