]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PluginManager.php
Code housekeeping: PEAR coding standards reformatting only.
[SourceForge/phpwiki.git] / lib / plugin / PluginManager.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PluginManager.php,v 1.10 2003-11-30 18:23:48 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 // TODO:
24 // Some of this code can be simplified with the relatively new
25 // WikiLink($p, 'auto') function.
26
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);
30
31 class WikiPlugin_PluginManager
32 extends WikiPlugin
33 {
34     function getName () {
35         return _("PluginManager");
36     }
37
38     function getDescription () {
39         return _("Provides a list of plugins on this wiki.");
40     }
41
42     function getVersion() {
43         return preg_replace("/[Revision: $]/", '',
44                             "\$Revision: 1.10 $");
45     }
46
47     function getDefaultArguments() {
48         return array('info' => 'args');
49     }
50
51     function run($dbi, $argstr, $request) {
52         extract($this->getArgs($argstr, $request));
53
54         $h = HTML();
55         $this->_generatePageheader($info, $h);
56
57         if (! REQUIRE_ADMIN || $request->_user->isadmin()) {
58             $h->pushContent(HTML::h2(_("Plugins")));
59
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);
65
66             //$h->pushContent(HTML::h2(_("Disabled Plugins")));
67         }
68         else {
69             $h->pushContent(fmt("You must be an administrator to %s.",
70                                 _("use this plugin")));
71         }
72         return $h;
73     }
74
75     function _generatePageheader(&$info, &$html) {
76         $html->pushContent(HTML::p($this->getDescription()));
77     }
78
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*')));
86         if ($info == 'args')
87             $colgroup->pushContent(HTML::col(array('width' => '2*')));
88         $table->pushcontent($colgroup);
89     }
90
91     function _generateColheadings(&$info, &$table) {
92         // table headings
93         $tr = HTML::tr();
94         $headings = array(_("Plugin"), _("Version"), _("Description"));
95         if ($info == 'args')
96             $headings []= _("Arguments");
97         foreach ($headings as $title) {
98             $tr->pushContent(HTML::td($title));
99         }
100         $table->pushContent(HTML::thead($tr));
101     }
102
103     function _generateTableBody(&$info, &$dbi, &$request, &$table) {
104         $row_no = 0;
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();
110         sort($plugins);
111         // table body
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();
125             }
126             else {
127                 $ver = "--";
128             }
129             // obtain plugin's default arguments
130             $arguments = HTML();
131             $args = $p->getDefaultArguments();
132             
133             foreach ($args as $arg => $default) {
134                 if (stristr($default, ' '))
135                     $default = "'$default'";
136                 $arguments->pushcontent("$arg=$default", HTML::br());
137             }
138             // make a link if an actionpage exists
139             $pnamelink = $pname;
140             $plink = false;
141             // Also look for pages in the current locale
142             if (_($pname) != $pname) {
143                 $l1 = _($pname);
144             }
145             else
146                 $l1 = '';
147             if (preg_match("/^$WikiNameRegexp\$/", $pname)
148                 && $dbi->isWikiPage($pname)) {
149                 $pnamelink = HTML(WikiLink($pname));
150             }
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) {
155                 $l2 = _($ppname);
156             }
157             else
158                 $l2 = '';
159             if (preg_match("/^$WikiNameRegexp\$/", $ppname)
160                 && $dbi->isWikiPage($ppname)) {
161                 $plink = HTML(WikiLink($ppname));
162             }
163             else {
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?
168                     ) {
169                     // $plink = WikiLink($ppname, 'unknown');
170                     global $Theme;
171                     $plink = $Theme->linkUnknownWikiWord($ppname);
172                 }
173                 else
174                     $plink = false;
175             }
176             // insert any found locale-specific pages at the bottom of
177             // the td
178             if ($l1 || $l2) {
179                 // really this should all just be put into a new <p>
180                 $par = HTML::p();
181                 //$plink->pushContent(HTML::br());
182                 //$plink->pushContent(HTML::br());
183                 if ($l1) {
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'));
191                     }
192                     else {
193                         // probably incorrectly translated, so no page link
194                         $par->pushContent($l1, ' ' . _("(Not a WikiWord)"));
195                     }
196                 }
197                 if ($l1 && $l2)
198                     $par->pushContent(HTML::br());
199                 if ($l2) {
200                     if (preg_match("/^$WikiNameRegexp\$/", $l2) || $dbi->isWikiPage($l2)) {
201                         $par->pushContent(WikiLink($l2, 'auto'));
202                     }
203                     else {
204                         // probably incorrectly translated, so no page link
205                         $par->pushContent($l2, ' ' . _("(Not a WikiWord)"));
206                     }
207                 }
208                 $plink->pushContent($par);
209             }
210
211             // highlight alternate rows
212             $row_no++;
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));
217             if ($plink) {
218                 // plugin has a XxxYyyPlugin page
219                 $tr->pushContent(HTML::td($pnamelink, HTML::br(), $plink));
220                 $plink = false;
221                 //$row_no++;
222             }
223             else {
224                 // plugin just has an actionpage
225                 $tr->pushContent(HTML::td($pnamelink));
226             }
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));
233             }
234             $tbody->pushContent($tr);
235         }
236         $table->pushContent($tbody);
237     }
238 };
239
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)
243 // locale.
244 //
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.
248 //
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.)
252 //
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).
256 //
257 // Revision 1.5  2003/02/22 20:49:56  dairiki
258 // Fixes for "Call-time pass by reference has been deprecated" errors.
259 //
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.
265 //
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.
270
271 // Local Variables:
272 // mode: php
273 // tab-width: 8
274 // c-basic-offset: 4
275 // c-hanging-comment-ender-p: nil
276 // indent-tabs-mode: nil
277 // End:
278 ?>