]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PluginManager.php
Include found locale-specific pages for the current (non-English)
[SourceForge/phpwiki.git] / lib / plugin / PluginManager.php
1 <?php // -*-php-*-
2 rcs_id('$Id: PluginManager.php,v 1.9 2003-11-19 00:02:42 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.9 $");
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             } else
145                 $l1 = '';
146             if (preg_match("/^$WikiNameRegexp\$/", $pname)
147                 && $dbi->isWikiPage($pname)) {
148                 $pnamelink = HTML(WikiLink($pname));
149             }
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) {
154                 $l2 = _($ppname);
155             } else
156                 $l2 = '';
157             if (preg_match("/^$WikiNameRegexp\$/", $ppname)
158                 && $dbi->isWikiPage($ppname)) {
159                 $plink = HTML(WikiLink($ppname));
160             }
161             else {
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?
166                     ) {
167                         // $plink = WikiLink($ppname, 'unknown');
168                         global $Theme;
169                         $plink = $Theme->linkUnknownWikiWord($ppname);
170                     }
171                         else
172                             $plink = false;
173             }
174             // insert any found locale-specific pages at the bottom of the td
175             if ($l1 || $l2) {
176                 // really this should all just be put into a new <p>
177                 $par = HTML::p();
178                 //$plink->pushContent(HTML::br());
179                 //$plink->pushContent(HTML::br());
180                                 if ($l1) {
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'));
186                     } else {
187                         // probably incorrectly translated, so no page link
188                                                 $par->pushContent($l1, ' ' . _("(Not a WikiWord)"));
189                     }
190                 }
191                 if ($l1 && $l2)
192                     $par->pushContent(HTML::br());
193                                 if ($l2) {
194                             if (preg_match("/^$WikiNameRegexp\$/", $l2) || $dbi->isWikiPage($l2)) {
195                                                 $par->pushContent(WikiLink($l2, 'auto'));
196                     } else {
197                         // probably incorrectly translated, so no page link
198                                                 $par->pushContent($l2, ' ' . _("(Not a WikiWord)"));
199                     }
200                 }
201
202                 $plink->pushContent($par);
203             }
204
205             // highlight alternate rows
206             $row_no++;
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));
211             if ($plink) {
212                 // plugin has a XxxYyyPlugin page
213                 $tr->pushContent(HTML::td($pnamelink, HTML::br(), $plink));
214                 $plink = false;
215                 //$row_no++;
216             }
217             else {
218                 // plugin just has an actionpage
219                 $tr->pushContent(HTML::td($pnamelink));
220             }
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));
227             }
228             $tbody->pushContent($tr);
229         }
230         $table->pushContent($tbody);
231     }
232 };
233
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.
238 //
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.)
242 //
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).
245 //
246 // Revision 1.5  2003/02/22 20:49:56  dairiki
247 // Fixes for "Call-time pass by reference has been deprecated" errors.
248 //
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.
254 //
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.
259
260 // Local Variables:
261 // mode: php
262 // tab-width: 8
263 // c-basic-offset: 4
264 // c-hanging-comment-ender-p: nil
265 // indent-tabs-mode: nil
266 // End:
267 ?>