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('wiki_data_path','moinmoin', '$core/data_path/plugins/moinmoin/wikidata');
25 forge_define_config_item('use_frame', 'moinmoin', false);
26 forge_set_config_item_bool('use_frame', 'moinmoin');
28 class MoinMoinPlugin extends Plugin {
29 function MoinMoinPlugin () {
31 $this->name = "moinmoin" ;
32 $this->text = "MoinMoinWiki" ; // To show in the tabs, use...
33 $this->hooks[] = "groupmenu" ; // To put into the project tabs
34 $this->hooks[] = "groupisactivecheckbox" ; // The "use ..." checkbox in editgroupinfo
35 $this->hooks[] = "groupisactivecheckboxpost" ; //
36 $this->hooks[] = "project_public_area";
37 $this->hooks[] = "role_get";
38 $this->hooks[] = "role_normalize";
39 $this->hooks[] = "role_translate_strings";
40 $this->hooks[] = "role_get_setting";
41 $this->hooks[] = "project_admin_plugins"; // to show up in the admin page for group
42 $this->hooks[] = "clone_project_from_template" ;
45 function getWikiUrl ($project) {
46 if (forge_get_config('use_frame', 'moinmoin')){
47 return util_make_uri('/plugins/moinmoin/frame.php?group_id=' . $project->getID()) ;
49 return util_make_uri('/plugins/moinmoin/'.$project->getUnixName().'/FrontPage');
53 function CallHook ($hookname, &$params) {
54 if (isset($params['group_id'])) {
55 $group_id=$params['group_id'];
56 } elseif (isset($params['group'])) {
57 $group_id=$params['group'];
61 if ($hookname == "groupmenu") {
62 $project = group_get_object($group_id);
63 if (!$project || !is_object($project)) {
66 if ($project->isError()) {
69 if (!$project->isProject()) {
72 if ( $project->usesPlugin ( $this->name ) ) {
73 $params['TITLES'][]=$this->text;
74 $params['DIRS'][]=$this->getWikiUrl($project);
76 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
77 } elseif ($hookname == "groupisactivecheckbox") {
78 //Check if the group is active
79 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
80 $group = group_get_object($group_id);
83 echo ' <input type="checkbox" name="use_moinmoinplugin" value="1" ';
84 // checked or unchecked?
85 if ( $group->usesPlugin ( $this->name ) ) {
91 echo "<strong>Use ".$this->text." Plugin</strong>";
94 } elseif ($hookname == "groupisactivecheckboxpost") {
95 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
96 $group = group_get_object($group_id);
97 $use_moinmoinplugin = getStringFromRequest('use_moinmoinplugin');
98 if ( $use_moinmoinplugin == 1 ) {
99 $group->setPluginUse ( $this->name );
101 $group->setPluginUse ( $this->name, false );
103 } elseif ($hookname == "project_public_area") {
104 $project = group_get_object($group_id);
105 if (!$project || !is_object($project)) {
108 if ($project->isError()) {
111 if (!$project->isProject()) {
114 if ( $project->usesPlugin ( $this->name ) ) {
115 echo '<div class="public-area-box">';
116 print '<a href="'. $this->getWikiUrl($project).'">';
121 } elseif ($hookname == "role_get") {
122 $role =& $params['role'] ;
129 $right = new PluginSpecificRoleSetting ($role,
130 'plugin_moinmoin_access') ;
131 $right->SetAllowedValues (array ('0', '1', '2', '3')) ;
132 $right->SetDefaultValues (array ('Admin' => '3',
133 'Senior Developer' => '2',
134 'Junior Developer' => '2',
136 'Support Tech' => '1')) ;
138 } elseif ($hookname == "role_normalize") {
139 $role =& $params['role'] ;
140 $new_sa =& $params['new_sa'] ;
141 $new_pa =& $params['new_pa'] ;
144 $projects = $role->getLinkedProjects() ;
145 foreach ($projects as $p) {
146 $role->normalizePermsForSection ($new_pa, 'plugin_moinmoin_access', $p->getID()) ;
149 $role->normalizeDataForSection ($new_sa, 'plugin_moinmoin_access') ;
151 } elseif ($hookname == "role_translate_strings") {
152 $right = new PluginSpecificRoleSetting ($role,
153 'plugin_moinmoin_access') ;
154 $right->setDescription (_('MoinMoin Wiki access')) ;
155 $right->setValueDescriptions (array ('0' => _('No access'),
156 '1' => _('Read access'),
157 '2' => _('Write access'),
158 '3' => _('Admin access'))) ;
160 } elseif ($hookname == "role_get_setting") {
161 $role = $params['role'] ;
162 $reference = $params['reference'] ;
163 $value = $params['value'] ;
165 switch ($params['section']) {
166 case 'plugin_moinmoin_access':
167 if ($role->hasPermission('project_admin', $reference)) {
168 $params['result'] = 3 ;
170 $params['result'] = $value ;
180 // c-file-style: "bsd"