]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PluginManager.php
Update getDescription
[SourceForge/phpwiki.git] / lib / plugin / PluginManager.php
1 <?php
2
3 /**
4  * Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5  * Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
6  *
7  * This file is part of PhpWiki.
8  *
9  * PhpWiki is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * PhpWiki is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 // Set this to true if you don't want regular users to view this page.
25 // So far there are no known security issues.
26 define('REQUIRE_ADMIN', false);
27
28 class WikiPlugin_PluginManager
29     extends WikiPlugin
30 {
31     function getName()
32     {
33         return _("PluginManager");
34     }
35
36     function getDescription()
37     {
38         return _("List of plugins on this wiki.");
39     }
40
41     function getDefaultArguments()
42     {
43         return array('info' => 'args');
44     }
45
46     function run($dbi, $argstr, &$request, $basepage)
47     {
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->_generateColheadings($info, $table);
58             $this->_generateTableBody($info, $dbi, $request, $table);
59             $h->pushContent($table);
60         } else {
61             $h->pushContent(fmt("You must be an administrator to %s.",
62                 _("use this plugin")));
63         }
64         return $h;
65     }
66
67     function _generatePageheader(&$info, &$html)
68     {
69         $html->pushContent(HTML::p($this->getDescription()));
70     }
71
72     function _generateColheadings(&$info, &$table)
73     {
74         // table headings
75         $tr = HTML::tr();
76         $headings = array(_("Plugin"), _("Description"));
77         if ($info == 'args')
78             $headings [] = _("Arguments");
79         foreach ($headings as $title) {
80             $tr->pushContent(HTML::th($title));
81         }
82         $table->pushContent(HTML::thead($tr));
83     }
84
85     function _generateTableBody(&$info, &$dbi, &$request, &$table)
86     {
87
88         global $AllAllowedPlugins;
89
90         $plugin_dir = 'lib/plugin';
91         if (defined('PHPWIKI_DIR'))
92             $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
93         $pd = new fileSet($plugin_dir, '*.php');
94         $plugins = $pd->getFiles();
95         unset($pd);
96         sort($plugins);
97
98         // table body
99         $tbody = HTML::tbody();
100         $row_no = 0;
101
102         $w = new WikiPluginLoader;
103         foreach ($plugins as $pluginName) {
104
105             $pluginName = str_replace(".php", "", $pluginName);
106             if (in_array($pluginName, $AllAllowedPlugins) === false) {
107                 continue;
108             }
109             // instantiate a plugin
110             $temppluginclass = '<' . "? plugin $pluginName ?>"; // hackish
111             $p = $w->getPlugin($pluginName, false); // second arg?
112             // trap php files which aren't WikiPlugin~s
113             if (!strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
114                 // Security: Hide names of extraneous files within
115                 // plugin dir from non-admins.
116                 if ($request->_user->isAdmin())
117                     trigger_error(sprintf(_("%s does not appear to be a WikiPlugin."),
118                         $pluginName . ".php"));
119                 continue; // skip this non WikiPlugin file
120             }
121             $desc = $p->getDescription();
122             $arguments = $p->getArgumentsDescription();
123             unset($p); //done querying plugin object, release from memory
124
125             // This section was largely improved by Pierrick Meignen:
126             // make a link if an actionpage exists
127             $pluginNamelink = $pluginName;
128             $pluginDocPageName = _("Help") . "/" . $pluginName . "Plugin";
129             if (defined('FUSIONFORGE') and FUSIONFORGE) {
130                 $pluginDocPageName = _("Help") . ":" . $pluginName . "Plugin";
131             }
132
133             $pluginDocPageNamelink = false;
134             $localizedPluginName = '';
135             $localizedPluginDocPageName = '';
136
137             if ($GLOBALS['LANG'] != "en") {
138                 if (_($pluginName) != $pluginName)
139                     $localizedPluginName = _($pluginName);
140                 if ($localizedPluginName && $dbi->isWikiPage($localizedPluginName))
141                     $pluginDocPageNamelink = WikiLink($localizedPluginName, 'if_known');
142
143                 if (_($pluginDocPageName) != $pluginDocPageName)
144                     $localizedPluginDocPageName = _($pluginDocPageName);
145                 if ($localizedPluginDocPageName &&
146                     $dbi->isWikiPage($localizedPluginDocPageName)
147                 )
148                     $pluginDocPageNamelink =
149                         WikiLink($localizedPluginDocPageName, 'if_known');
150             } else {
151                 $pluginNamelink = WikiLink($pluginName, 'if_known');
152
153                 if ($dbi->isWikiPage($pluginDocPageName))
154                     $pluginDocPageNamelink = WikiLink($pluginDocPageName, 'if_known');
155             }
156
157             if (defined('FUSIONFORGE') and FUSIONFORGE) {
158                 $pluginDocPageNamelink = WikiLink($pluginDocPageName, 'known');
159             }
160
161             // highlight alternate rows
162             $row_no++;
163             $group = (int)($row_no / 1); //_group_rows
164             $class = ($group % 2) ? 'evenrow' : 'oddrow';
165             // generate table row
166             $tr = HTML::tr(array('class' => $class));
167             if ($pluginDocPageNamelink) {
168                 // plugin has a description page 'Help/' . 'PluginName' . 'Plugin'
169                 $tr->pushContent(HTML::td($pluginNamelink, HTML::br(),
170                     $pluginDocPageNamelink));
171                 $pluginDocPageNamelink = false;
172             } else {
173                 // plugin just has an actionpage
174                 $tr->pushContent(HTML::td($pluginNamelink));
175             }
176             $tr->pushContent(HTML::td($desc));
177             if ($info == 'args') {
178                 // add Arguments column
179                 $style = array('style'
180                 => 'font-family:monospace;font-size:smaller');
181                 $tr->pushContent(HTML::td($style, $arguments));
182             }
183             $tbody->pushContent($tr);
184         }
185         $table->pushContent($tbody);
186     }
187 }
188
189 // Local Variables:
190 // mode: php
191 // tab-width: 8
192 // c-basic-offset: 4
193 // c-hanging-comment-ender-p: nil
194 // indent-tabs-mode: nil
195 // End: