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 forge_define_config_item('src_path','mediawiki', "/usr/share/mediawiki");
26 forge_define_config_item('mwdata_path', 'mediawiki', '$core/data_path/plugins/mediawiki');
27 forge_define_config_item('projects_path', 'mediawiki', '$mediawiki/mwdata_path/projects');
28 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'][]='';
97 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
98 } elseif ($hookname == "groupisactivecheckbox") {
99 //Check if the group is active
100 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
101 $group = group_get_object($group_id);
104 echo ' <input type="checkbox" name="use_mediawikiplugin" value="1" ';
105 // checked or unchecked?
106 if ( $group->usesPlugin ( $this->name ) ) {
112 echo "<strong>Use ".$this->text." Plugin</strong>";
115 } elseif ($hookname == "groupisactivecheckboxpost") {
116 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
117 $group = group_get_object($group_id);
118 $use_mediawikiplugin = getStringFromRequest('use_mediawikiplugin');
119 if ( $use_mediawikiplugin == 1 ) {
120 $group->setPluginUse ( $this->name );
122 $group->setPluginUse ( $this->name, false );
124 } elseif ($hookname == "project_public_area") {
125 $project = group_get_object($group_id);
126 if (!$project || !is_object($project)) {
129 if ($project->isError()) {
132 if (!$project->isProject()) {
135 if ( $project->usesPlugin ( $this->name ) ) {
136 echo '<div class="public-area-box">';
137 print '<a href="'. util_make_url ('/plugins/mediawiki/wiki/'.$project->getUnixName().'/index.php').'">';
138 print html_abs_image(util_make_url ('/plugins/mediawiki/wiki/'.$project->getUnixName().'/skins/fusionforge/wiki.png'),'20','20',array('alt'=>'Mediawiki'));
143 } elseif ($hookname == "role_get") {
144 $role =& $params['role'] ;
147 $right = new PluginSpecificRoleSetting ($role,
148 'plugin_mediawiki_read') ;
149 $right->SetAllowedValues (array ('0', '1')) ;
150 $right->SetDefaultValues (array ('Admin' => '1',
151 'Senior Developer' => '1',
152 'Junior Developer' => '1',
154 'Support Tech' => '1')) ;
157 $right = new PluginSpecificRoleSetting ($role,
158 'plugin_mediawiki_edit') ;
159 $right->SetAllowedValues (array ('0', '1', '2', '3')) ;
160 $right->SetDefaultValues (array ('Admin' => '3',
161 'Senior Developer' => '2',
162 'Junior Developer' => '1',
164 'Support Tech' => '0')) ;
166 // File upload privileges
167 $right = new PluginSpecificRoleSetting ($role,
168 'plugin_mediawiki_upload') ;
169 $right->SetAllowedValues (array ('0', '1', '2')) ;
170 $right->SetDefaultValues (array ('Admin' => '2',
171 'Senior Developer' => '2',
172 'Junior Developer' => '1',
174 'Support Tech' => '0')) ;
176 // Administrative tasks
177 $right = new PluginSpecificRoleSetting ($role,
178 'plugin_mediawiki_admin') ;
179 $right->SetAllowedValues (array ('0', '1')) ;
180 $right->SetDefaultValues (array ('Admin' => '1',
181 'Senior Developer' => '0',
182 'Junior Developer' => '0',
184 'Support Tech' => '0')) ;
186 } elseif ($hookname == "role_normalize") {
187 $role =& $params['role'] ;
188 $new_sa =& $params['new_sa'] ;
189 $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()) ;
200 $role->normalizeDataForSection ($new_sa, 'plugin_mediawiki_read') ;
201 $role->normalizeDataForSection ($new_sa, 'plugin_mediawiki_edit') ;
202 $role->normalizeDataForSection ($new_sa, 'plugin_mediawiki_upload') ;
203 $role->normalizeDataForSection ($new_sa, 'plugin_mediawiki_admin') ;
205 } elseif ($hookname == "role_translate_strings") {
206 $right = new PluginSpecificRoleSetting ($role,
207 'plugin_mediawiki_read') ;
208 $right->setDescription (_('Mediawiki read access')) ;
209 $right->setValueDescriptions (array ('0' => _('No reading'),
210 '1' => _('Read access'))) ;
212 $right = new PluginSpecificRoleSetting ($role,
213 'plugin_mediawiki_edit') ;
214 $right->setDescription (_('Mediawiki write access')) ;
215 $right->setValueDescriptions (array ('0' => _('No editing'),
216 '1' => _('Edit existing pages only'),
217 '2' => _('Edit and create pages'),
218 '3' => _('Edit, create, move, delete pages'))) ;
220 $right = new PluginSpecificRoleSetting ($role,
221 'plugin_mediawiki_upload') ;
222 $right->setDescription (_('Mediawiki file upload')) ;
223 $right->setValueDescriptions (array ('0' => _('No uploading'),
224 '1' => _('Upload permitted'),
225 '2' => _('Upload and re-upload'))) ;
227 $right = new PluginSpecificRoleSetting ($role,
228 'plugin_mediawiki_admin') ;
229 $right->setDescription (_('Mediawiki administrative tasks')) ;
230 $right->setValueDescriptions (array ('0' => _('No administrative access'),
231 '1' => _('Edit interface, import XML dumps'))) ;
232 } elseif ($hookname == "role_get_setting") {
233 $role = $params['role'] ;
234 $reference = $params['reference'] ;
235 $value = $params['value'] ;
237 switch ($params['section']) {
238 case 'plugin_mediawiki_read':
239 if ($role->hasPermission('project_admin', $reference)) {
240 $params['result'] = 1 ;
242 $params['result'] = $value ;
245 case 'plugin_mediawiki_edit':
246 if ($role->hasPermission('project_admin', $reference)) {
247 $params['result'] = 3 ;
249 $params['result'] = $value ;
252 case 'plugin_mediawiki_upload':
253 if ($role->hasPermission('project_admin', $reference)) {
254 $params['result'] = 2 ;
256 $params['result'] = $value ;
259 case 'plugin_mediawiki_admin':
260 if ($role->hasPermission('project_admin', $reference)) {
261 $params['result'] = 1 ;
263 $params['result'] = $value ;
267 } elseif ($hookname == "role_has_permission") {
268 $value = $params['value'];
269 switch ($params['section']) {
270 case 'plugin_mediawiki_read':
271 switch ($params['action']) {
274 $params['result'] |= ($value >= 1) ;
278 case 'plugin_mediawiki_edit':
279 switch ($params['action']) {
281 $params['result'] |= ($value >= 1) ;
284 $params['result'] |= ($value >= 2) ;
287 $params['result'] |= ($value >= 3) ;
291 case 'plugin_mediawiki_upload':
292 switch ($params['action']) {
294 $params['result'] |= ($value >= 1) ;
297 $params['result'] |= ($value >= 2) ;
301 case 'plugin_mediawiki_admin':
302 switch ($params['action']) {
305 $params['result'] |= ($value >= 1) ;
310 } elseif ($hookname == "list_roles_by_permission") {
311 switch ($params['section']) {
312 case 'plugin_mediawiki_read':
313 switch ($params['action']) {
316 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
320 case 'plugin_mediawiki_edit':
321 switch ($params['action']) {
323 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
326 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 2') ;
329 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 3') ;
333 case 'plugin_mediawiki_upload':
334 switch ($params['action']) {
336 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
339 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 2') ;
343 case 'plugin_mediawiki_admin':
344 switch ($params['action']) {
347 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
352 } elseif ($hookname == "project_admin_plugins") {
353 $group_id = $params['group_id'];
354 $group = group_get_object($group_id);
355 if ($group->usesPlugin($this->name))
357 "/plugins/mediawiki/plugin_admin.php?group_id=" .
358 $group->getID(), _("MediaWiki Plugin admin")) .
360 } elseif ($hookname == "clone_project_from_template") {
361 $template = $params['template'] ;
362 $project = $params['project'] ;
363 $id_mappings = $params['id_mappings'] ;
365 $sections = array ('plugin_mediawiki_read', 'plugin_mediawiki_edit', 'plugin_mediawiki_upload', 'plugin_mediawiki_admin') ;
367 foreach ($template->getRoles() as $oldrole) {
368 $newrole = RBACEngine::getInstance()->getRoleById ($id_mappings['role'][$oldrole->getID()]) ;
369 $oldsettings = $oldrole->getSettingsForProject ($template) ;
371 foreach ($sections as $section) {
372 if (isset ($oldsettings[$section][$template->getID()])) {
373 $newrole->setSetting ($section, $project->getID(), $oldsettings[$section][$template->getID()]) ;
377 } elseif ($hookname == "site_admin_option_hook") {
378 echo '<li><a href="'.$this->getPluginPath().'/">' . _('Mediawiki plugin') . '</a></li>';
385 // c-file-style: "bsd"