3 * MediaWikiPlugin Class
5 * Copyright 2000-2011, Fusionforge Team
6 * Copyright 2012,2014 Franck Villaume - TrivialDev
7 * http://fusionforge.org
9 * This file is part of FusionForge.
11 * FusionForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once 'plugins_utils.php';
27 if(is_dir("/usr/share/mediawiki")){
28 forge_define_config_item('src_path','mediawiki', "/usr/share/mediawiki");
29 forge_define_config_item('mwdata_path', 'mediawiki', '$core/data_path/plugins/mediawiki');
30 forge_define_config_item('projects_path', 'mediawiki', '$mediawiki/mwdata_path/projects');
31 forge_define_config_item('master_path', 'mediawiki', '$mediawiki/mwdata_path/master');
32 forge_define_config_item('enable_uploads', 'mediawiki', false);
33 forge_set_config_item_bool('enable_uploads', 'mediawiki');
35 require_once $gfcommon.'include/SysTasksQ.class.php';
37 class MediaWikiPlugin extends Plugin {
38 public $systask_types = array(
39 'MEDIAWIKI_CREATE_WIKI' => 'create-wikis.php',
40 'MEDIAWIKI_CREATE_IMAGEDIR' => 'create-imagedirs.php'
43 function __construct ($id=0) {
45 $this->name = "mediawiki" ;
46 $this->text = _("Mediawiki") ; // To show in the tabs, use...
48 _("This plugin allows each project to embed Mediawiki under a tab.");
49 $this->_addHook("groupmenu") ; // To put into the project tabs
50 $this->_addHook("groupisactivecheckbox") ; // The "use ..." checkbox in editgroupinfo
51 $this->_addHook("groupisactivecheckboxpost") ; //
52 $this->_addHook("project_public_area");
53 $this->_addHook("role_get");
54 $this->_addHook("role_normalize");
55 $this->_addHook("role_unlink_project");
56 $this->_addHook("role_translate_strings");
57 $this->_addHook("role_has_permission");
58 $this->_addHook("role_get_setting");
59 $this->_addHook("list_roles_by_permission");
60 $this->_addHook("project_admin_plugins"); // to show up in the admin page for group
61 $this->_addHook("clone_project_from_template") ;
62 $this->_addHook('group_delete');
66 echo '<h1>Mediawiki</h1>';
67 echo $this->getPluginInfo()->getpropVal('answer');
70 function &getPluginInfo() {
71 if (!is_a($this->pluginInfo, 'MediaWikiPluginInfo')) {
72 require_once 'MediaWikiPluginInfo.class.php';
73 $this->pluginInfo = new MediaWikiPluginInfo($this);
75 return $this->pluginInfo;
78 function CallHook ($hookname, &$params) {
79 if (isset($params['group_id'])) {
80 $group_id=$params['group_id'];
81 } elseif (isset($params['group'])) {
82 $group_id=$params['group'];
86 if ($hookname == "groupmenu") {
87 $project = group_get_object($group_id);
88 if (!$project || !is_object($project)) {
91 if ($project->isError()) {
94 if (!$project->isProject()) {
97 if ( $project->usesPlugin ( $this->name ) ) {
98 $params['TITLES'][]=$this->text;
99 $params['DIRS'][]=util_make_url('/plugins/mediawiki/wiki/'.$project->getUnixName().'/index.php');
100 $params['ADMIN'][] = util_make_url('/plugins/mediawiki/plugin_admin.php?group_id='.$project->getID());
101 $params['TOOLTIPS'][] = _('Mediawiki Space');
103 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
104 } elseif ($hookname == "project_public_area") {
105 $project = group_get_object($group_id);
106 if (!$project || !is_object($project)) {
109 if ($project->isError()) {
112 if (!$project->isProject()) {
115 if ( $project->usesPlugin ( $this->name ) ) {
116 echo '<div class="public-area-box">';
117 print '<a href="'. util_make_url ('/plugins/mediawiki/wiki/'.$project->getUnixName().'/index.php').'">';
118 print html_abs_image(util_make_url ('/plugins/mediawiki/wiki/'.$project->getUnixName().'/skins/monobook/wiki.png'),'20','20',array('alt'=>'Mediawiki'));
123 } elseif ($hookname == "role_get") {
124 $role =& $params['role'] ;
127 $right = new PluginSpecificRoleSetting ($role,
128 'plugin_mediawiki_read') ;
129 $right->SetAllowedValues (array ('0', '1')) ;
130 $right->SetDefaultValues (array ('Admin' => '1',
131 'Senior Developer' => '1',
132 'Junior Developer' => '1',
134 'Support Tech' => '1')) ;
137 $right = new PluginSpecificRoleSetting ($role,
138 'plugin_mediawiki_edit') ;
139 $right->SetAllowedValues (array ('0', '1', '2', '3')) ;
140 $right->SetDefaultValues (array ('Admin' => '3',
141 'Senior Developer' => '2',
142 'Junior Developer' => '1',
144 'Support Tech' => '0')) ;
146 // File upload privileges
147 $right = new PluginSpecificRoleSetting ($role,
148 'plugin_mediawiki_upload') ;
149 $right->SetAllowedValues (array ('0', '1', '2')) ;
150 $right->SetDefaultValues (array ('Admin' => '2',
151 'Senior Developer' => '2',
152 'Junior Developer' => '1',
154 'Support Tech' => '0')) ;
156 // Administrative tasks
157 $right = new PluginSpecificRoleSetting ($role,
158 'plugin_mediawiki_admin') ;
159 $right->SetAllowedValues (array ('0', '1')) ;
160 $right->SetDefaultValues (array ('Admin' => '1',
161 'Senior Developer' => '0',
162 'Junior Developer' => '0',
164 'Support Tech' => '0')) ;
166 } elseif ($hookname == "role_normalize") {
167 $role =& $params['role'] ;
168 $new_pa =& $params['new_pa'] ;
170 $projects = $role->getLinkedProjects() ;
171 foreach ($projects as $p) {
172 $role->normalizePermsForSection ($new_pa, 'plugin_mediawiki_read', $p->getID()) ;
173 $role->normalizePermsForSection ($new_pa, 'plugin_mediawiki_edit', $p->getID()) ;
174 $role->normalizePermsForSection ($new_pa, 'plugin_mediawiki_upload', $p->getID()) ;
175 $role->normalizePermsForSection ($new_pa, 'plugin_mediawiki_admin', $p->getID()) ;
177 } elseif ($hookname == "role_unlink_project") {
178 $role =& $params['role'] ;
179 $project =& $params['project'] ;
181 $settings = array('plugin_mediawiki_read', 'plugin_mediawiki_edit', 'plugin_mediawiki_upload', 'plugin_mediawiki_admin');
183 foreach ($settings as $s) {
184 db_query_params('DELETE FROM pfo_role_setting WHERE role_id=$1 AND section_name=$2 AND ref_id=$3',
185 array($role->getID(),
189 } elseif ($hookname == "role_translate_strings") {
190 $right = new PluginSpecificRoleSetting ($role,
191 'plugin_mediawiki_read') ;
192 $right->setDescription (_('Mediawiki read access')) ;
193 $right->setValueDescriptions (array ('0' => _('No reading'),
194 '1' => _('Read access'))) ;
196 $right = new PluginSpecificRoleSetting ($role,
197 'plugin_mediawiki_edit') ;
198 $right->setDescription (_('Mediawiki write access')) ;
199 $right->setValueDescriptions (array ('0' => _('No editing'),
200 '1' => _('Edit existing pages only'),
201 '2' => _('Edit and create pages'),
202 '3' => _('Edit, create, move, delete pages'))) ;
204 $right = new PluginSpecificRoleSetting ($role,
205 'plugin_mediawiki_upload') ;
206 $right->setDescription (_('Mediawiki file upload')) ;
207 $right->setValueDescriptions (array ('0' => _('No uploading'),
208 '1' => _('Upload permitted'),
209 '2' => _('Upload and re-upload'))) ;
211 $right = new PluginSpecificRoleSetting ($role,
212 'plugin_mediawiki_admin') ;
213 $right->setDescription (_('Mediawiki administrative tasks')) ;
214 $right->setValueDescriptions (array ('0' => _('No administrative access'),
215 '1' => _('Edit interface, import XML dumps'))) ;
216 } elseif ($hookname == "role_get_setting") {
217 $role = $params['role'] ;
218 $reference = $params['reference'] ;
219 $value = $params['value'] ;
221 switch ($params['section']) {
222 case 'plugin_mediawiki_read':
223 if ($role->hasPermission('project_admin', $reference)) {
224 $params['result'] = 1 ;
226 $params['result'] = $value ;
229 case 'plugin_mediawiki_edit':
230 if ($role->hasPermission('project_admin', $reference)) {
231 $params['result'] = 3 ;
233 $params['result'] = $value ;
236 case 'plugin_mediawiki_upload':
237 if ($role->hasPermission('project_admin', $reference)) {
238 $params['result'] = 2 ;
240 $params['result'] = $value ;
243 case 'plugin_mediawiki_admin':
244 if ($role->hasPermission('project_admin', $reference)) {
245 $params['result'] = 1 ;
247 $params['result'] = $value ;
251 } elseif ($hookname == "role_has_permission") {
252 $value = $params['value'];
253 switch ($params['section']) {
254 case 'plugin_mediawiki_read':
255 switch ($params['action']) {
258 $params['result'] |= ($value >= 1) ;
262 case 'plugin_mediawiki_edit':
263 switch ($params['action']) {
265 $params['result'] |= ($value >= 1) ;
268 $params['result'] |= ($value >= 2) ;
271 $params['result'] |= ($value >= 3) ;
275 case 'plugin_mediawiki_upload':
276 switch ($params['action']) {
278 $params['result'] |= ($value >= 1) ;
281 $params['result'] |= ($value >= 2) ;
285 case 'plugin_mediawiki_admin':
286 switch ($params['action']) {
289 $params['result'] |= ($value >= 1) ;
294 } elseif ($hookname == "list_roles_by_permission") {
295 switch ($params['section']) {
296 case 'plugin_mediawiki_read':
297 switch ($params['action']) {
300 $params['qpa'] = db_construct_qpa($params['qpa'], ' AND perm_val >= 1') ;
304 case 'plugin_mediawiki_edit':
305 switch ($params['action']) {
307 $params['qpa'] = db_construct_qpa($params['qpa'], ' AND perm_val >= 1') ;
310 $params['qpa'] = db_construct_qpa($params['qpa'], ' AND perm_val >= 2') ;
313 $params['qpa'] = db_construct_qpa($params['qpa'], ' AND perm_val >= 3') ;
317 case 'plugin_mediawiki_upload':
318 switch ($params['action']) {
320 $params['qpa'] = db_construct_qpa($params['qpa'], ' AND perm_val >= 1') ;
323 $params['qpa'] = db_construct_qpa($params['qpa'], ' AND perm_val >= 2') ;
327 case 'plugin_mediawiki_admin':
328 switch ($params['action']) {
331 $params['qpa'] = db_construct_qpa($params['qpa'], ' AND perm_val >= 1') ;
336 } elseif ($hookname == "project_admin_plugins") {
337 $group_id = $params['group_id'];
338 $group = group_get_object($group_id);
339 if ($group->usesPlugin($this->name))
341 "/plugins/mediawiki/plugin_admin.php?group_id=" .
342 $group->getID(), _("MediaWiki Plugin admin")) .
344 } elseif ($hookname == "clone_project_from_template") {
345 $template = $params['template'] ;
346 $project = $params['project'] ;
347 $id_mappings = $params['id_mappings'] ;
349 $sections = array ('plugin_mediawiki_read', 'plugin_mediawiki_edit', 'plugin_mediawiki_upload', 'plugin_mediawiki_admin') ;
351 foreach ($template->getRoles() as $oldrole) {
352 $newrole = RBACEngine::getInstance()->getRoleById ($id_mappings['role'][$oldrole->getID()]) ;
353 $oldsettings = $oldrole->getSettingsForProject ($template) ;
355 foreach ($sections as $section) {
356 if (isset ($oldsettings[$section][$template->getID()])) {
357 $newrole->setSetting ($section, $project->getID(), $oldsettings[$section][$template->getID()]) ;
361 } elseif ($hookname == 'group_delete') {
362 $projectId = $params['group_id'];
363 $projectObject = group_get_object($projectId);
364 if ($projectObject->usesPlugin($this->name)) {
365 //delete the files and db schema
366 $schema = 'plugin_mediawiki_'.$projectObject->getUnixName();
367 // Sanitize schema name
368 $schema = strtr($schema, "-", "_");
369 db_query_params('drop schema $1 cascade', array($schema));
370 exec('/bin/rm -rf '.forge_get_config('projects_path', 'mediawiki').'/'.$projectObject->getUnixName());
375 function groupisactivecheckboxpost(&$params) {
376 if (!parent::groupisactivecheckboxpost($params))
378 if (getIntFromRequest('use_mediawiki') == 1) {
379 $systasksq = new SystasksQ();
380 $group_id = $params['group'];
381 $systasksq->add($this->getID(), 'MEDIAWIKI_CREATE_WIKI', $group_id);
382 $systasksq->add($this->getID(), 'MEDIAWIKI_CREATE_IMAGEDIR', $group_id);
390 // c-file-style: "bsd"