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 if(is_dir("/usr/share/mediawiki")){
25 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');
29 forge_define_config_item('enable_uploads', 'mediawiki', false);
30 forge_set_config_item_bool('enable_uploads', 'mediawiki');
31 forge_define_config_item('use_frame', 'mediawiki', false);
32 forge_set_config_item_bool('use_frame', 'mediawiki');
35 class MediaWikiPlugin extends Plugin {
36 function __construct ($id=0) {
38 $this->name = "mediawiki" ;
39 $this->text = "Mediawiki" ; // To show in the tabs, use...
40 $this->_addHook("groupmenu") ; // To put into the project tabs
41 $this->_addHook("groupisactivecheckbox") ; // The "use ..." checkbox in editgroupinfo
42 $this->_addHook("groupisactivecheckboxpost") ; //
43 $this->_addHook("project_public_area");
44 $this->_addHook("role_get");
45 $this->_addHook("role_normalize");
46 $this->_addHook("role_translate_strings");
47 $this->_addHook("role_has_permission");
48 $this->_addHook("role_get_setting");
49 $this->_addHook("list_roles_by_permission");
50 $this->_addHook("project_admin_plugins"); // to show up in the admin page for group
51 $this->_addHook("clone_project_from_template") ;
52 $this->_addHook("site_admin_option_hook");
56 echo '<h1>Mediawiki</h1>';
57 echo $this->getPluginInfo()->getpropVal('answer');
60 function &getPluginInfo() {
61 if (!is_a($this->pluginInfo, 'MediaWikiPluginInfo')) {
62 require_once('MediaWikiPluginInfo.class.php');
63 $this->pluginInfo =& new MediaWikiPluginInfo($this);
65 return $this->pluginInfo;
68 function CallHook ($hookname, &$params) {
69 if (isset($params['group_id'])) {
70 $group_id=$params['group_id'];
71 } elseif (isset($params['group'])) {
72 $group_id=$params['group'];
76 if ($hookname == "groupmenu") {
77 $project = group_get_object($group_id);
78 if (!$project || !is_object($project)) {
81 if ($project->isError()) {
84 if (!$project->isProject()) {
87 if ( $project->usesPlugin ( $this->name ) ) {
88 $params['TITLES'][]=$this->text;
89 if (forge_get_config('use_frame', 'mediawiki')){
90 $params['DIRS'][]=util_make_url ('/plugins/mediawiki/frame.php?group_id=' . $project->getID()) ;
92 $params['DIRS'][]=util_make_url('/plugins/mediawiki/wiki/'.$project->getUnixName().'/index.php');
94 $params['ADMIN'][]='';
96 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
97 } elseif ($hookname == "groupisactivecheckbox") {
98 //Check if the group is active
99 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
100 $group = group_get_object($group_id);
103 echo ' <input type="checkbox" name="use_mediawikiplugin" value="1" ';
104 // checked or unchecked?
105 if ( $group->usesPlugin ( $this->name ) ) {
111 echo "<strong>Use ".$this->text." Plugin</strong>";
114 } elseif ($hookname == "groupisactivecheckboxpost") {
115 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
116 $group = group_get_object($group_id);
117 $use_mediawikiplugin = getStringFromRequest('use_mediawikiplugin');
118 if ( $use_mediawikiplugin == 1 ) {
119 $group->setPluginUse ( $this->name );
121 $group->setPluginUse ( $this->name, false );
123 } elseif ($hookname == "project_public_area") {
124 $project = group_get_object($group_id);
125 if (!$project || !is_object($project)) {
128 if ($project->isError()) {
131 if (!$project->isProject()) {
134 if ( $project->usesPlugin ( $this->name ) ) {
135 echo '<div class="public-area-box">';
136 print '<a href="'. util_make_url ('/plugins/mediawiki/wiki/'.$project->getUnixName().'/index.php').'">';
137 print html_abs_image(util_make_url ('/plugins/mediawiki/wiki/'.$project->getUnixName().'/skins/fusionforge/wiki.png'),'20','20',array('alt'=>'Mediawiki'));
142 } elseif ($hookname == "role_get") {
143 $role =& $params['role'] ;
146 $right = new PluginSpecificRoleSetting ($role,
147 'plugin_mediawiki_read') ;
148 $right->SetAllowedValues (array ('0', '1')) ;
149 $right->SetDefaultValues (array ('Admin' => '1',
150 'Senior Developer' => '1',
151 'Junior Developer' => '1',
153 'Support Tech' => '1')) ;
156 $right = new PluginSpecificRoleSetting ($role,
157 'plugin_mediawiki_edit') ;
158 $right->SetAllowedValues (array ('0', '1', '2', '3')) ;
159 $right->SetDefaultValues (array ('Admin' => '3',
160 'Senior Developer' => '2',
161 'Junior Developer' => '1',
163 'Support Tech' => '0')) ;
165 // File upload privileges
166 $right = new PluginSpecificRoleSetting ($role,
167 'plugin_mediawiki_upload') ;
168 $right->SetAllowedValues (array ('0', '1', '2')) ;
169 $right->SetDefaultValues (array ('Admin' => '2',
170 'Senior Developer' => '2',
171 'Junior Developer' => '1',
173 'Support Tech' => '0')) ;
175 // Administrative tasks
176 $right = new PluginSpecificRoleSetting ($role,
177 'plugin_mediawiki_admin') ;
178 $right->SetAllowedValues (array ('0', '1')) ;
179 $right->SetDefaultValues (array ('Admin' => '1',
180 'Senior Developer' => '0',
181 'Junior Developer' => '0',
183 'Support Tech' => '0')) ;
185 } elseif ($hookname == "role_normalize") {
186 $role =& $params['role'] ;
187 $new_sa =& $params['new_sa'] ;
188 $new_pa =& $params['new_pa'] ;
191 $projects = $role->getLinkedProjects() ;
192 foreach ($projects as $p) {
193 $role->normalizePermsForSection ($new_pa, 'plugin_mediawiki_read', $p->getID()) ;
194 $role->normalizePermsForSection ($new_pa, 'plugin_mediawiki_edit', $p->getID()) ;
195 $role->normalizePermsForSection ($new_pa, 'plugin_mediawiki_upload', $p->getID()) ;
196 $role->normalizePermsForSection ($new_pa, 'plugin_mediawiki_admin', $p->getID()) ;
199 $role->normalizeDataForSection ($new_sa, 'plugin_mediawiki_read') ;
200 $role->normalizeDataForSection ($new_sa, 'plugin_mediawiki_edit') ;
201 $role->normalizeDataForSection ($new_sa, 'plugin_mediawiki_upload') ;
202 $role->normalizeDataForSection ($new_sa, 'plugin_mediawiki_admin') ;
204 } elseif ($hookname == "role_translate_strings") {
205 $right = new PluginSpecificRoleSetting ($role,
206 'plugin_mediawiki_read') ;
207 $right->setDescription (_('Mediawiki read access')) ;
208 $right->setValueDescriptions (array ('0' => _('No reading'),
209 '1' => _('Read access'))) ;
211 $right = new PluginSpecificRoleSetting ($role,
212 'plugin_mediawiki_edit') ;
213 $right->setDescription (_('Mediawiki write access')) ;
214 $right->setValueDescriptions (array ('0' => _('No editing'),
215 '1' => _('Edit existing pages only'),
216 '2' => _('Edit and create pages'),
217 '3' => _('Edit, create, move, delete pages'))) ;
219 $right = new PluginSpecificRoleSetting ($role,
220 'plugin_mediawiki_upload') ;
221 $right->setDescription (_('Mediawiki file upload')) ;
222 $right->setValueDescriptions (array ('0' => _('No uploading'),
223 '1' => _('Upload permitted'),
224 '2' => _('Upload and re-upload'))) ;
226 $right = new PluginSpecificRoleSetting ($role,
227 'plugin_mediawiki_admin') ;
228 $right->setDescription (_('Mediawiki administrative tasks')) ;
229 $right->setValueDescriptions (array ('0' => _('No administrative access'),
230 '1' => _('Edit interface, import XML dumps'))) ;
231 } elseif ($hookname == "role_get_setting") {
232 $role = $params['role'] ;
233 $reference = $params['reference'] ;
234 $value = $params['value'] ;
236 switch ($params['section']) {
237 case 'plugin_mediawiki_read':
238 if ($role->hasPermission('project_admin', $reference)) {
239 $params['result'] = 1 ;
241 $params['result'] = $value ;
244 case 'plugin_mediawiki_edit':
245 if ($role->hasPermission('project_admin', $reference)) {
246 $params['result'] = 3 ;
248 $params['result'] = $value ;
251 case 'plugin_mediawiki_upload':
252 if ($role->hasPermission('project_admin', $reference)) {
253 $params['result'] = 2 ;
255 $params['result'] = $value ;
258 case 'plugin_mediawiki_admin':
259 if ($role->hasPermission('project_admin', $reference)) {
260 $params['result'] = 1 ;
262 $params['result'] = $value ;
266 } elseif ($hookname == "role_has_permission") {
267 $value = $params['value'];
268 switch ($params['section']) {
269 case 'plugin_mediawiki_read':
270 switch ($params['action']) {
273 $params['result'] |= ($value >= 1) ;
277 case 'plugin_mediawiki_edit':
278 switch ($params['action']) {
280 $params['result'] |= ($value >= 1) ;
283 $params['result'] |= ($value >= 2) ;
286 $params['result'] |= ($value >= 3) ;
290 case 'plugin_mediawiki_upload':
291 switch ($params['action']) {
293 $params['result'] |= ($value >= 1) ;
296 $params['result'] |= ($value >= 2) ;
300 case 'plugin_mediawiki_admin':
301 switch ($params['action']) {
304 $params['result'] |= ($value >= 1) ;
309 } elseif ($hookname == "list_roles_by_permission") {
310 switch ($params['section']) {
311 case 'plugin_mediawiki_read':
312 switch ($params['action']) {
315 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
319 case 'plugin_mediawiki_edit':
320 switch ($params['action']) {
322 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
325 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 2') ;
328 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 3') ;
332 case 'plugin_mediawiki_upload':
333 switch ($params['action']) {
335 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
338 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 2') ;
342 case 'plugin_mediawiki_admin':
343 switch ($params['action']) {
346 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
351 } elseif ($hookname == "project_admin_plugins") {
352 $group_id = $params['group_id'];
353 $group = group_get_object($group_id);
354 if ($group->usesPlugin($this->name))
356 "/plugins/mediawiki/plugin_admin.php?group_id=" .
357 $group->getID(), _("MediaWiki Plugin admin")) .
359 } elseif ($hookname == "clone_project_from_template") {
360 $template = $params['template'] ;
361 $project = $params['project'] ;
362 $id_mappings = $params['id_mappings'] ;
364 $sections = array ('plugin_mediawiki_read', 'plugin_mediawiki_edit', 'plugin_mediawiki_upload', 'plugin_mediawiki_admin') ;
366 foreach ($template->getRoles() as $oldrole) {
367 $newrole = RBACEngine::getInstance()->getRoleById ($id_mappings['role'][$oldrole->getID()]) ;
368 $oldsettings = $oldrole->getSettingsForProject ($template) ;
370 foreach ($sections as $section) {
371 if (isset ($oldsettings[$section][$template->getID()])) {
372 $newrole->setSetting ($section, $project->getID(), $oldsettings[$section][$template->getID()]) ;
376 } elseif ($hookname == "site_admin_option_hook") {
377 echo '<li><a href="'.$this->getPluginPath().'/">' . _('Mediawiki plugin') . '</a></li>';
384 // c-file-style: "bsd"