]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PluginManager.php
getName should not translate
[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 getDescription()
32     {
33         return _("List of plugins on this wiki.");
34     }
35
36     function getDefaultArguments()
37     {
38         return array('info' => 'args');
39     }
40
41     function run($dbi, $argstr, &$request, $basepage)
42     {
43         extract($this->getArgs($argstr, $request));
44
45         $h = HTML();
46         $this->_generatePageheader($info, $h);
47
48         if (!REQUIRE_ADMIN || $request->_user->isadmin()) {
49             $table = HTML::table(array('class' => "pagelist"));
50             $this->_generateColheadings($info, $table);
51             $this->_generateTableBody($info, $dbi, $request, $table);
52             $h->pushContent($table);
53         } else {
54             $h->pushContent(fmt("You must be an administrator to %s.",
55                 _("use this plugin")));
56         }
57         return $h;
58     }
59
60     private function _generatePageheader(&$info, &$html)
61     {
62         $html->pushContent(HTML::p($this->getDescription()));
63     }
64
65     private function _generateColheadings(&$info, &$table)
66     {
67         // table headings
68         $tr = HTML::tr();
69         $headings = array(_("Plugin"), _("Description"));
70         if ($info == 'args')
71             $headings [] = _("Arguments");
72         foreach ($headings as $title) {
73             $tr->pushContent(HTML::th($title));
74         }
75         $table->pushContent(HTML::thead($tr));
76     }
77
78     private function _generateTableBody(&$info, &$dbi, &$request, &$table)
79     {
80
81         global $AllAllowedPlugins;
82
83         $plugin_dir = 'lib/plugin';
84         if (defined('PHPWIKI_DIR'))
85             $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
86         $pd = new fileSet($plugin_dir, '*.php');
87         $plugins = $pd->getFiles();
88         unset($pd);
89         sort($plugins);
90
91         // table body
92         $tbody = HTML::tbody();
93         $row_no = 0;
94
95         $w = new WikiPluginLoader();
96         foreach ($plugins as $pluginName) {
97
98             $pluginName = str_replace(".php", "", $pluginName);
99             if (in_array($pluginName, $AllAllowedPlugins) === false) {
100                 continue;
101             }
102             // instantiate a plugin
103             $temppluginclass = '<' . "? plugin $pluginName ?>"; // hackish
104             $p = $w->getPlugin($pluginName, false); // second arg?
105             // trap php files which aren't WikiPlugin~s
106             if (!strtolower(substr(get_parent_class($p), 0, 10)) == 'wikiplugin') {
107                 // Security: Hide names of extraneous files within
108                 // plugin dir from non-admins.
109                 if ($request->_user->isAdmin())
110                     trigger_error(sprintf(_("%s does not appear to be a WikiPlugin."),
111                         $pluginName . ".php"));
112                 continue; // skip this non WikiPlugin file
113             }
114             $desc = $p->getDescription();
115             $arguments = $p->getArgumentsDescription();
116             unset($p); //done querying plugin object, release from memory
117
118             // This section was largely improved by Pierrick Meignen:
119             // make a link if an actionpage exists
120             $pluginNamelink = $pluginName;
121             $pluginDocPageName = "Help" . "/" . $pluginName . "Plugin";
122             if (defined('FUSIONFORGE') and FUSIONFORGE) {
123                 $pluginDocPageName = "Help" . ":" . $pluginName . "Plugin";
124             }
125
126             $pluginDocPageNamelink = false;
127             $localizedPluginName = '';
128             $localizedPluginDocPageName = '';
129
130             if ($GLOBALS['LANG'] != "en") {
131                 if (_($pluginName) != $pluginName)
132                     $localizedPluginName = _($pluginName);
133                 if ($localizedPluginName && $dbi->isWikiPage($localizedPluginName))
134                     $pluginDocPageNamelink = WikiLink($localizedPluginName, 'if_known');
135
136                 if (_($pluginDocPageName) != $pluginDocPageName)
137                     $localizedPluginDocPageName = _($pluginDocPageName);
138                 if ($localizedPluginDocPageName &&
139                     $dbi->isWikiPage($localizedPluginDocPageName)
140                 )
141                     $pluginDocPageNamelink =
142                         WikiLink($localizedPluginDocPageName, 'if_known');
143             } else {
144                 $pluginNamelink = WikiLink($pluginName, 'if_known');
145
146                 if ($dbi->isWikiPage($pluginDocPageName))
147                     $pluginDocPageNamelink = WikiLink($pluginDocPageName, 'if_known');
148             }
149
150             if (defined('FUSIONFORGE') and FUSIONFORGE) {
151                 $pluginDocPageNamelink = WikiLink($pluginDocPageName, 'known');
152             }
153
154             // highlight alternate rows
155             $row_no++;
156             $group = (int)($row_no / 1); //_group_rows
157             $class = ($group % 2) ? 'evenrow' : 'oddrow';
158             // generate table row
159             $tr = HTML::tr(array('class' => $class));
160             if ($pluginDocPageNamelink) {
161                 // plugin has a description page 'Help/' . 'PluginName' . 'Plugin'
162                 $tr->pushContent(HTML::td($pluginNamelink, HTML::br(),
163                     $pluginDocPageNamelink));
164                 $pluginDocPageNamelink = false;
165             } else {
166                 // plugin just has an actionpage
167                 $tr->pushContent(HTML::td($pluginNamelink));
168             }
169             $tr->pushContent(HTML::td($desc));
170             if ($info == 'args') {
171                 // add Arguments column
172                 $style = array('style'
173                 => 'font-family:monospace;font-size:smaller');
174                 $tr->pushContent(HTML::td($style, $arguments));
175             }
176             $tbody->pushContent($tr);
177         }
178         $table->pushContent($tbody);
179     }
180 }
181
182 // Local Variables:
183 // mode: php
184 // tab-width: 8
185 // c-basic-offset: 4
186 // c-hanging-comment-ender-p: nil
187 // indent-tabs-mode: nil
188 // End: