3 * FusionForge source control management
5 * Copyright 2004-2009, Roland Mas
6 * Copyright (C) 2011-2012 Alain Peyrat - Alcatel-Lucent
7 * Copyright 2012, Franck Villaume - TrivialDev
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once $gfcommon.'include/scm.php';
27 abstract class SCMPlugin extends Plugin {
29 * SCMPlugin() - constructor
32 function SCMPlugin() {
34 $this->_addHook('scm_plugin');
35 $this->_addHook('scm_page');
36 $this->_addHook('scm_admin_page');
37 $this->_addHook('scm_admin_update');
38 $this->_addHook('scm_stats');
39 $this->_addHook('scm_create_repo');
41 # Other common hooks that can be enabled per plugin:
42 # scm_generate_snapshots
47 $this->provides['scm'] = true;
50 function CallHook($hookname, &$params) {
55 $scm_plugins=& $params['scm_plugins'];
56 $scm_plugins[]=$this->name;
60 $this->printPage($params);
63 case 'scm_browser_page': {
64 $this->printBrowserPage($params);
67 case 'scm_admin_page': {
68 $this->printAdminPage($params);
71 case 'scm_admin_update': {
72 $this->adminUpdate($params);
76 $this->printShortStats($params);
79 case 'scm_create_repo': {
81 $this->createOrUpdateRepo($params);
84 case 'scm_update_repolist': {
86 $this->updateRepositoryList($params);
89 case 'scm_generate_snapshots': { // Optional
91 $this->generateSnapshots($params);
94 case 'scm_gather_stats': { // Optional
96 $this->gatherStats($params);
99 case "widgets": { // Optional
100 $this->widgets($params);
103 case "widget_instance": { // Optional
104 $this->myPageBox($params);
107 case "activity": { //Optional
108 $this->activity($params);
111 default: { // Forgot something
116 final function register() {
119 $scm_list[] = $this->name;
122 function browserDisplayable($project) {
123 if ($project->usesSCM() && $project->usesPlugin($this->name)) {
124 if ($project->enableAnonSCM() || forge_check_perm('scm', $project->getID(), 'read')) {
131 abstract function createOrUpdateRepo($params);
133 function printShortStats($params) {
134 $project = $this->checkParams($params);
139 if ($project->usesPlugin($this->name)) {
140 echo ' ('.$this->text.')' ;
144 function getBlurb () {
145 return '<p>' . _('Unimplemented SCM plugin.') . '</p>';
148 function getInstructionsForAnon ($project) {
149 return '<p>' . _('Instructions for anonymous access for unimplemented SCM plugin.') . '</p>';
152 function getInstructionsForRW ($project) {
153 return '<p>' . _('Instructions for read-write access for unimplemented SCM plugin.') . '</p>';
156 function getSnapshotPara ($project) {
157 return '<p>' . _('Instructions for snapshot access for unimplemented SCM plugin.') . '</p>';
160 function getBrowserLinkBlock($project) {
162 $b = $HTML->boxMiddle(_('Repository Browser'));
164 $b .= _('Browsing the SCM tree is not yet implemented for this SCM plugin.');
167 $b .= util_make_link ("/scm/?group_id=".$project->getID(),
168 _('Not implemented yet')
174 function getBrowserBlock($project) {
176 $b = $HTML->boxMiddle(_('Repository Browser'));
178 $b .= _('Browsing the SCM tree is not yet implemented for this SCM plugin.');
183 function getStatsBlock($project) {
185 $b = $HTML->boxMiddle(_('Repository Statistics'));
187 $b .= _('Not implemented for this SCM plugin yet.') ;
192 function printPage($params) {
195 $project = $this->checkParams($params);
200 if ($project->usesPlugin($this->name)) {
202 session_require_perm('scm', $project->getID(), 'read');
203 // Table for summary info
204 print '<table class="fullwidth"><tr class="top"><td style="width:65%">'."\n" ;
205 print $this->getBlurb()."\n";
207 // Instructions for anonymous access
208 if ($project->enableAnonSCM()) {
209 print $this->getInstructionsForAnon($project);
212 // Instructions for developer access
213 print $this->getInstructionsForRW($project);
215 if ($this->browserDisplayable($project)) {
216 echo $this->getBrowserLinkBlock($project);
220 if ($this->browserDisplayable($project)) {
221 print $this->getSnapshotPara($project);
223 print '</td>'."\n".'<td style="width:35%" class="top">'."\n";
226 echo $HTML->boxTop(_('Repository History'));
227 echo _('Data about current and past states of the repository');
228 if ($this->browserDisplayable($project)) {
229 echo $this->getStatsBlock($project);
232 echo $HTML->boxBottom();
233 print '</td></tr></table>' ;
237 function printBrowserPage($params) {
240 $project = $this->checkParams($params);
245 if ($project->usesPlugin ($this->name)) {
246 if ($this->browserDisplayable ($project)) {
247 // print '<iframe src="'.util_make_url('/scm/browser.php?title='.$group->getUnixName()).'" frameborder="0" width=100% height=700></iframe>' ;
252 function printAdminPage($params) {
253 $group = group_get_object($params['group_id']);
254 $ra = RoleAnonymous::getInstance() ;
256 if ( $group->usesPlugin ( $this->name ) && $ra->hasPermission('project_read', $group->getID())) {
257 print '<p><input type="checkbox" name="scm_enable_anonymous" value="1" '.$this->c($group->enableAnonSCM()).' /><strong>'._('Enable Anonymous Read Access').'</strong></p>';
261 function adminUpdate($params) {
262 $project = $this->checkParams($params);
267 if ($project->usesPlugin($this->name) ) {
268 if (isset($params['scm_enable_anonymous']) && $params['scm_enable_anonymous']) {
269 $project->SetUsesAnonSCM(true);
271 $project->SetUsesAnonSCM(false);
276 function getBoxForProject($project) {
277 $box = $project->getSCMBox();
279 $box = forge_get_config('default_server', $this->name);
282 $box = forge_get_config('web_host');
287 function checkParams ($params) {
288 $group_id = $params['group_id'] ;
289 $project = group_get_object($group_id);
290 if (!$project || !is_object($project)) {
292 } elseif ($project->isError()) {
301 return 'checked="checked"';
311 // c-file-style: "bsd"