]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PluginManager.php
Don't use PHPWIKI_DIR unless it's defined.
[SourceForge/phpwiki.git] / lib / plugin / PluginManager.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PluginManager.php,v 1.7 2003-02-24 01:36:25 dairiki 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.7 $");
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         $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();
106         // table body
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();
120             }
121             else {
122                 $ver = "--";
123             }
124             // obtain plugin's default arguments
125             $arguments = HTML();
126             $args = $p->getDefaultArguments();
127
128             foreach ($args as $arg => $default) {
129                 if (stristr($default, ' '))
130                     $default = "'$default'";
131                 $arguments->pushcontent("$arg=$default", HTML::br());
132             }
133             // make a link if an actionpage exists
134             $pnamelink = $pname;
135             $plink = false;
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);
144             else {
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?
149                     ) {
150                         // $plink = WikiLink($ppname, 'unknown');
151                         global $Theme;
152                         $plink = $Theme->linkUnknownWikiWord($ppname);
153                     }
154                         else
155                             $plink = false;
156             }
157             // highlight alternate rows
158             $row_no++;
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));
163             if ($plink) {
164                 // plugin has a XxxYyyPlugin page
165                 $tr->pushContent(HTML::td($pnamelink, HTML::br(), $plink));
166                 $plink = false;
167                 //$row_no++;
168             }
169             else {
170                 // plugin just has an actionpage
171                 $tr->pushContent(HTML::td($pnamelink));
172             }
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));
179             }
180             $tbody->pushContent($tr);
181         }
182         $table->pushContent($tbody);
183     }
184 };
185
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).
189 //
190 // Revision 1.5  2003/02/22 20:49:56  dairiki
191 // Fixes for "Call-time pass by reference has been deprecated" errors.
192 //
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.
198 //
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.
203
204 // Local Variables:
205 // mode: php
206 // tab-width: 8
207 // c-basic-offset: 4
208 // c-hanging-comment-ender-p: nil
209 // indent-tabs-mode: nil
210 // End:
211 ?>