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','moinmoin', "/usr/share/moin");
25 forge_define_config_item('wiki_data_path','moinmoin', '$core/data_path/plugins/moinmoin/wikidata');
26 forge_define_config_item('use_frame', 'moinmoin', false);
27 forge_set_config_item_bool('use_frame', 'moinmoin');
29 class MoinMoinPlugin extends Plugin {
30 function MoinMoinPlugin () {
32 $this->name = "moinmoin" ;
33 $this->text = "MoinMoinWiki" ; // To show in the tabs, use...
34 $this->hooks[] = "groupmenu" ; // To put into the project tabs
35 $this->hooks[] = "groupisactivecheckbox" ; // The "use ..." checkbox in editgroupinfo
36 $this->hooks[] = "groupisactivecheckboxpost" ; //
37 $this->hooks[] = "project_public_area";
38 $this->hooks[] = "role_get";
39 $this->hooks[] = "role_normalize";
40 $this->hooks[] = "role_translate_strings";
41 $this->hooks[] = "role_get_setting";
42 $this->hooks[] = "project_admin_plugins"; // to show up in the admin page for group
43 $this->hooks[] = "clone_project_from_template" ;
46 function getWikiUrl ($project) {
47 if (forge_get_config('use_frame', 'moinmoin')){
48 return util_make_uri('/plugins/moinmoin/frame.php?group_id=' . $project->getID()) ;
50 return util_make_uri('/plugins/moinmoin/'.$project->getUnixName().'/FrontPage');
54 function CallHook ($hookname, &$params) {
55 if (isset($params['group_id'])) {
56 $group_id=$params['group_id'];
57 } elseif (isset($params['group'])) {
58 $group_id=$params['group'];
62 if ($hookname == "groupmenu") {
63 $project = group_get_object($group_id);
64 if (!$project || !is_object($project)) {
67 if ($project->isError()) {
70 if (!$project->isProject()) {
73 if ( $project->usesPlugin ( $this->name ) ) {
74 $params['TITLES'][]=$this->text;
75 $params['DIRS'][]=$this->getWikiUrl($project);
77 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
78 } elseif ($hookname == "groupisactivecheckbox") {
79 //Check if the group is active
80 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
81 $group = group_get_object($group_id);
84 echo ' <input type="checkbox" name="use_moinmoinplugin" value="1" ';
85 // checked or unchecked?
86 if ( $group->usesPlugin ( $this->name ) ) {
92 echo "<strong>Use ".$this->text." Plugin</strong>";
95 } elseif ($hookname == "groupisactivecheckboxpost") {
96 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
97 $group = group_get_object($group_id);
98 $use_moinmoinplugin = getStringFromRequest('use_moinmoinplugin');
99 if ( $use_moinmoinplugin == 1 ) {
100 $group->setPluginUse ( $this->name );
102 $group->setPluginUse ( $this->name, false );
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="'. $this->getWikiUrl($project).'">';
122 } elseif ($hookname == "role_get") {
123 $role =& $params['role'] ;
130 $right = new PluginSpecificRoleSetting ($role,
131 'plugin_moinmoin_access') ;
132 $right->SetAllowedValues (array ('0', '1', '2', '3')) ;
133 $right->SetDefaultValues (array ('Admin' => '3',
134 'Senior Developer' => '2',
135 'Junior Developer' => '2',
137 'Support Tech' => '1')) ;
139 } elseif ($hookname == "role_normalize") {
140 $role =& $params['role'] ;
141 $new_sa =& $params['new_sa'] ;
142 $new_pa =& $params['new_pa'] ;
145 $projects = $role->getLinkedProjects() ;
146 foreach ($projects as $p) {
147 $role->normalizePermsForSection ($new_pa, 'plugin_moinmoin_access', $p->getID()) ;
150 $role->normalizeDataForSection ($new_sa, 'plugin_moinmoin_access') ;
152 } elseif ($hookname == "role_translate_strings") {
153 $right = new PluginSpecificRoleSetting ($role,
154 'plugin_moinmoin_access') ;
155 $right->setDescription (_('MoinMoin Wiki access')) ;
156 $right->setValueDescriptions (array ('0' => _('No access'),
157 '1' => _('Read access'),
158 '2' => _('Write access'),
159 '3' => _('Admin access'))) ;
161 } elseif ($hookname == "role_get_setting") {
162 $role = $params['role'] ;
163 $reference = $params['reference'] ;
164 $value = $params['value'] ;
166 switch ($params['section']) {
167 case 'plugin_moinmoin_access':
168 if ($role->hasPermission('project_admin', $reference)) {
169 $params['result'] = 3 ;
171 $params['result'] = $value ;
181 // c-file-style: "bsd"