4 * MediaWikiPlugin Class
7 * This file is part of FusionForge.
9 * FusionForge 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.
14 * FusionForge 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.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once 'plugins_utils.php';
25 if(is_dir("/usr/share/mediawiki")){
26 forge_define_config_item('src_path','mediawiki', "/usr/share/mediawiki");
27 forge_define_config_item('mwdata_path', 'mediawiki', '$core/data_path/plugins/mediawiki');
28 forge_define_config_item('projects_path', 'mediawiki', '$mediawiki/mwdata_path/projects');
29 forge_define_config_item('master_path', 'mediawiki', '$mediawiki/mwdata_path/master');
30 forge_define_config_item('enable_uploads', 'mediawiki', false);
31 forge_set_config_item_bool('enable_uploads', 'mediawiki');
32 forge_define_config_item('use_frame', 'mediawiki', false);
33 forge_set_config_item_bool('use_frame', 'mediawiki');
36 class MediaWikiPlugin extends Plugin {
37 function __construct ($id=0) {
39 $this->name = "mediawiki" ;
40 $this->text = "Mediawiki" ; // To show in the tabs, use...
41 $this->_addHook("groupmenu") ; // To put into the project tabs
42 $this->_addHook("groupisactivecheckbox") ; // The "use ..." checkbox in editgroupinfo
43 $this->_addHook("groupisactivecheckboxpost") ; //
44 $this->_addHook("project_public_area");
45 $this->_addHook("role_get");
46 $this->_addHook("role_normalize");
47 $this->_addHook("role_translate_strings");
48 $this->_addHook("role_has_permission");
49 $this->_addHook("role_get_setting");
50 $this->_addHook("list_roles_by_permission");
51 $this->_addHook("project_admin_plugins"); // to show up in the admin page for group
52 $this->_addHook("clone_project_from_template") ;
53 $this->_addHook("site_admin_option_hook");
57 echo '<h1>Mediawiki</h1>';
58 echo $this->getPluginInfo()->getpropVal('answer');
61 function &getPluginInfo() {
62 if (!is_a($this->pluginInfo, 'MediaWikiPluginInfo')) {
63 require_once('MediaWikiPluginInfo.class.php');
64 $this->pluginInfo = new MediaWikiPluginInfo($this);
66 return $this->pluginInfo;
69 function CallHook ($hookname, &$params) {
70 if (isset($params['group_id'])) {
71 $group_id=$params['group_id'];
72 } elseif (isset($params['group'])) {
73 $group_id=$params['group'];
77 if ($hookname == "groupmenu") {
78 $project = group_get_object($group_id);
79 if (!$project || !is_object($project)) {
82 if ($project->isError()) {
85 if (!$project->isProject()) {
88 if ( $project->usesPlugin ( $this->name ) ) {
89 $params['TITLES'][]=$this->text;
90 if (forge_get_config('use_frame', 'mediawiki')){
91 $params['DIRS'][]=util_make_url('/plugins/mediawiki/frame.php?group_id=' . $project->getID()) ;
93 $params['DIRS'][]=util_make_url('/plugins/mediawiki/wiki/'.$project->getUnixName().'/index.php');
95 $params['ADMIN'][]='';
96 $params['TOOLTIPS'][] = _('Mediawiki Space');
98 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
99 } elseif ($hookname == "groupisactivecheckbox") {
100 //Check if the group is active
101 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
102 $group = group_get_object($group_id);
105 echo ' <input type="checkbox" name="use_mediawikiplugin" value="1" ';
106 // checked or unchecked?
107 if ( $group->usesPlugin ( $this->name ) ) {
113 echo "<strong>Use ".$this->text." Plugin</strong>";
116 } elseif ($hookname == "groupisactivecheckboxpost") {
117 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
118 $group = group_get_object($group_id);
119 $use_mediawikiplugin = getStringFromRequest('use_mediawikiplugin');
120 if ( $use_mediawikiplugin == 1 ) {
121 $group->setPluginUse ( $this->name );
123 $group->setPluginUse ( $this->name, false );
125 } elseif ($hookname == "project_public_area") {
126 $project = group_get_object($group_id);
127 if (!$project || !is_object($project)) {
130 if ($project->isError()) {
133 if (!$project->isProject()) {
136 if ( $project->usesPlugin ( $this->name ) ) {
137 echo '<div class="public-area-box">';
138 print '<a href="'. util_make_url ('/plugins/mediawiki/wiki/'.$project->getUnixName().'/index.php').'">';
139 print html_abs_image(util_make_url ('/plugins/mediawiki/wiki/'.$project->getUnixName().'/skins/fusionforge/wiki.png'),'20','20',array('alt'=>'Mediawiki'));
144 } elseif ($hookname == "role_get") {
145 $role =& $params['role'] ;
148 $right = new PluginSpecificRoleSetting ($role,
149 'plugin_mediawiki_read') ;
150 $right->SetAllowedValues (array ('0', '1')) ;
151 $right->SetDefaultValues (array ('Admin' => '1',
152 'Senior Developer' => '1',
153 'Junior Developer' => '1',
155 'Support Tech' => '1')) ;
158 $right = new PluginSpecificRoleSetting ($role,
159 'plugin_mediawiki_edit') ;
160 $right->SetAllowedValues (array ('0', '1', '2', '3')) ;
161 $right->SetDefaultValues (array ('Admin' => '3',
162 'Senior Developer' => '2',
163 'Junior Developer' => '1',
165 'Support Tech' => '0')) ;
167 // File upload privileges
168 $right = new PluginSpecificRoleSetting ($role,
169 'plugin_mediawiki_upload') ;
170 $right->SetAllowedValues (array ('0', '1', '2')) ;
171 $right->SetDefaultValues (array ('Admin' => '2',
172 'Senior Developer' => '2',
173 'Junior Developer' => '1',
175 'Support Tech' => '0')) ;
177 // Administrative tasks
178 $right = new PluginSpecificRoleSetting ($role,
179 'plugin_mediawiki_admin') ;
180 $right->SetAllowedValues (array ('0', '1')) ;
181 $right->SetDefaultValues (array ('Admin' => '1',
182 'Senior Developer' => '0',
183 'Junior Developer' => '0',
185 'Support Tech' => '0')) ;
187 } elseif ($hookname == "role_normalize") {
188 $role =& $params['role'] ;
189 $new_sa =& $params['new_sa'] ;
190 $new_pa =& $params['new_pa'] ;
192 $projects = $role->getLinkedProjects() ;
193 foreach ($projects as $p) {
194 $role->normalizePermsForSection ($new_pa, 'plugin_mediawiki_read', $p->getID()) ;
195 $role->normalizePermsForSection ($new_pa, 'plugin_mediawiki_edit', $p->getID()) ;
196 $role->normalizePermsForSection ($new_pa, 'plugin_mediawiki_upload', $p->getID()) ;
197 $role->normalizePermsForSection ($new_pa, 'plugin_mediawiki_admin', $p->getID()) ;
199 } elseif ($hookname == "role_translate_strings") {
200 $right = new PluginSpecificRoleSetting ($role,
201 'plugin_mediawiki_read') ;
202 $right->setDescription (_('Mediawiki read access')) ;
203 $right->setValueDescriptions (array ('0' => _('No reading'),
204 '1' => _('Read access'))) ;
206 $right = new PluginSpecificRoleSetting ($role,
207 'plugin_mediawiki_edit') ;
208 $right->setDescription (_('Mediawiki write access')) ;
209 $right->setValueDescriptions (array ('0' => _('No editing'),
210 '1' => _('Edit existing pages only'),
211 '2' => _('Edit and create pages'),
212 '3' => _('Edit, create, move, delete pages'))) ;
214 $right = new PluginSpecificRoleSetting ($role,
215 'plugin_mediawiki_upload') ;
216 $right->setDescription (_('Mediawiki file upload')) ;
217 $right->setValueDescriptions (array ('0' => _('No uploading'),
218 '1' => _('Upload permitted'),
219 '2' => _('Upload and re-upload'))) ;
221 $right = new PluginSpecificRoleSetting ($role,
222 'plugin_mediawiki_admin') ;
223 $right->setDescription (_('Mediawiki administrative tasks')) ;
224 $right->setValueDescriptions (array ('0' => _('No administrative access'),
225 '1' => _('Edit interface, import XML dumps'))) ;
226 } elseif ($hookname == "role_get_setting") {
227 $role = $params['role'] ;
228 $reference = $params['reference'] ;
229 $value = $params['value'] ;
231 switch ($params['section']) {
232 case 'plugin_mediawiki_read':
233 if ($role->hasPermission('project_admin', $reference)) {
234 $params['result'] = 1 ;
236 $params['result'] = $value ;
239 case 'plugin_mediawiki_edit':
240 if ($role->hasPermission('project_admin', $reference)) {
241 $params['result'] = 3 ;
243 $params['result'] = $value ;
246 case 'plugin_mediawiki_upload':
247 if ($role->hasPermission('project_admin', $reference)) {
248 $params['result'] = 2 ;
250 $params['result'] = $value ;
253 case 'plugin_mediawiki_admin':
254 if ($role->hasPermission('project_admin', $reference)) {
255 $params['result'] = 1 ;
257 $params['result'] = $value ;
261 } elseif ($hookname == "role_has_permission") {
262 $value = $params['value'];
263 switch ($params['section']) {
264 case 'plugin_mediawiki_read':
265 switch ($params['action']) {
268 $params['result'] |= ($value >= 1) ;
272 case 'plugin_mediawiki_edit':
273 switch ($params['action']) {
275 $params['result'] |= ($value >= 1) ;
278 $params['result'] |= ($value >= 2) ;
281 $params['result'] |= ($value >= 3) ;
285 case 'plugin_mediawiki_upload':
286 switch ($params['action']) {
288 $params['result'] |= ($value >= 1) ;
291 $params['result'] |= ($value >= 2) ;
295 case 'plugin_mediawiki_admin':
296 switch ($params['action']) {
299 $params['result'] |= ($value >= 1) ;
304 } elseif ($hookname == "list_roles_by_permission") {
305 switch ($params['section']) {
306 case 'plugin_mediawiki_read':
307 switch ($params['action']) {
310 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
314 case 'plugin_mediawiki_edit':
315 switch ($params['action']) {
317 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
320 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 2') ;
323 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 3') ;
327 case 'plugin_mediawiki_upload':
328 switch ($params['action']) {
330 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
333 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 2') ;
337 case 'plugin_mediawiki_admin':
338 switch ($params['action']) {
341 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
346 } elseif ($hookname == "project_admin_plugins") {
347 $group_id = $params['group_id'];
348 $group = group_get_object($group_id);
349 if ($group->usesPlugin($this->name))
351 "/plugins/mediawiki/plugin_admin.php?group_id=" .
352 $group->getID(), _("MediaWiki Plugin admin")) .
354 } elseif ($hookname == "clone_project_from_template") {
355 $template = $params['template'] ;
356 $project = $params['project'] ;
357 $id_mappings = $params['id_mappings'] ;
359 $sections = array ('plugin_mediawiki_read', 'plugin_mediawiki_edit', 'plugin_mediawiki_upload', 'plugin_mediawiki_admin') ;
361 foreach ($template->getRoles() as $oldrole) {
362 $newrole = RBACEngine::getInstance()->getRoleById ($id_mappings['role'][$oldrole->getID()]) ;
363 $oldsettings = $oldrole->getSettingsForProject ($template) ;
365 foreach ($sections as $section) {
366 if (isset ($oldsettings[$section][$template->getID()])) {
367 $newrole->setSetting ($section, $project->getID(), $oldsettings[$section][$template->getID()]) ;
371 } elseif ($hookname == "site_admin_option_hook") {
372 echo '<li><a href="'.$this->getPluginPath().'/">' . _('Mediawiki plugin') . '</a></li>';
379 // c-file-style: "bsd"