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'][]='';
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'] ;
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()) ;
198 } elseif ($hookname == "role_translate_strings") {
199 $right = new PluginSpecificRoleSetting ($role,
200 'plugin_mediawiki_read') ;
201 $right->setDescription (_('Mediawiki read access')) ;
202 $right->setValueDescriptions (array ('0' => _('No reading'),
203 '1' => _('Read access'))) ;
205 $right = new PluginSpecificRoleSetting ($role,
206 'plugin_mediawiki_edit') ;
207 $right->setDescription (_('Mediawiki write access')) ;
208 $right->setValueDescriptions (array ('0' => _('No editing'),
209 '1' => _('Edit existing pages only'),
210 '2' => _('Edit and create pages'),
211 '3' => _('Edit, create, move, delete pages'))) ;
213 $right = new PluginSpecificRoleSetting ($role,
214 'plugin_mediawiki_upload') ;
215 $right->setDescription (_('Mediawiki file upload')) ;
216 $right->setValueDescriptions (array ('0' => _('No uploading'),
217 '1' => _('Upload permitted'),
218 '2' => _('Upload and re-upload'))) ;
220 $right = new PluginSpecificRoleSetting ($role,
221 'plugin_mediawiki_admin') ;
222 $right->setDescription (_('Mediawiki administrative tasks')) ;
223 $right->setValueDescriptions (array ('0' => _('No administrative access'),
224 '1' => _('Edit interface, import XML dumps'))) ;
225 } elseif ($hookname == "role_get_setting") {
226 $role = $params['role'] ;
227 $reference = $params['reference'] ;
228 $value = $params['value'] ;
230 switch ($params['section']) {
231 case 'plugin_mediawiki_read':
232 if ($role->hasPermission('project_admin', $reference)) {
233 $params['result'] = 1 ;
235 $params['result'] = $value ;
238 case 'plugin_mediawiki_edit':
239 if ($role->hasPermission('project_admin', $reference)) {
240 $params['result'] = 3 ;
242 $params['result'] = $value ;
245 case 'plugin_mediawiki_upload':
246 if ($role->hasPermission('project_admin', $reference)) {
247 $params['result'] = 2 ;
249 $params['result'] = $value ;
252 case 'plugin_mediawiki_admin':
253 if ($role->hasPermission('project_admin', $reference)) {
254 $params['result'] = 1 ;
256 $params['result'] = $value ;
260 } elseif ($hookname == "role_has_permission") {
261 $value = $params['value'];
262 switch ($params['section']) {
263 case 'plugin_mediawiki_read':
264 switch ($params['action']) {
267 $params['result'] |= ($value >= 1) ;
271 case 'plugin_mediawiki_edit':
272 switch ($params['action']) {
274 $params['result'] |= ($value >= 1) ;
277 $params['result'] |= ($value >= 2) ;
280 $params['result'] |= ($value >= 3) ;
284 case 'plugin_mediawiki_upload':
285 switch ($params['action']) {
287 $params['result'] |= ($value >= 1) ;
290 $params['result'] |= ($value >= 2) ;
294 case 'plugin_mediawiki_admin':
295 switch ($params['action']) {
298 $params['result'] |= ($value >= 1) ;
303 } elseif ($hookname == "list_roles_by_permission") {
304 switch ($params['section']) {
305 case 'plugin_mediawiki_read':
306 switch ($params['action']) {
309 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
313 case 'plugin_mediawiki_edit':
314 switch ($params['action']) {
316 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
319 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 2') ;
322 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 3') ;
326 case 'plugin_mediawiki_upload':
327 switch ($params['action']) {
329 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
332 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 2') ;
336 case 'plugin_mediawiki_admin':
337 switch ($params['action']) {
340 $params['qpa'] = db_construct_qpa ($params['qpa'], ' AND perm_val >= 1') ;
345 } elseif ($hookname == "project_admin_plugins") {
346 $group_id = $params['group_id'];
347 $group = group_get_object($group_id);
348 if ($group->usesPlugin($this->name))
350 "/plugins/mediawiki/plugin_admin.php?group_id=" .
351 $group->getID(), _("MediaWiki Plugin admin")) .
353 } elseif ($hookname == "clone_project_from_template") {
354 $template = $params['template'] ;
355 $project = $params['project'] ;
356 $id_mappings = $params['id_mappings'] ;
358 $sections = array ('plugin_mediawiki_read', 'plugin_mediawiki_edit', 'plugin_mediawiki_upload', 'plugin_mediawiki_admin') ;
360 foreach ($template->getRoles() as $oldrole) {
361 $newrole = RBACEngine::getInstance()->getRoleById ($id_mappings['role'][$oldrole->getID()]) ;
362 $oldsettings = $oldrole->getSettingsForProject ($template) ;
364 foreach ($sections as $section) {
365 if (isset ($oldsettings[$section][$template->getID()])) {
366 $newrole->setSetting ($section, $project->getID(), $oldsettings[$section][$template->getID()]) ;
370 } elseif ($hookname == "site_admin_option_hook") {
371 echo '<li><a href="'.$this->getPluginPath().'/">' . _('Mediawiki plugin') . '</a></li>';
378 // c-file-style: "bsd"