3 * FusionForge source control management
5 * Copyright 2004-2009, Roland Mas
6 * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
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 FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once $gfcommon.'include/scm.php';
26 abstract class SCMPlugin extends Plugin {
28 * SCMPlugin() - constructor
31 function SCMPlugin () {
33 $this->hooks[] = 'scm_plugin';
34 $this->hooks[] = 'scm_page';
35 $this->hooks[] = 'scm_admin_page';
36 $this->hooks[] = 'scm_admin_update';
37 $this->hooks[] = 'scm_stats';
38 $this->hooks[] = 'scm_create_repo';
39 # Other common hooks that can be enabled per plugin:
40 # scm_generate_snapshots
46 function CallHook ($hookname, &$params) {
51 $scm_plugins=& $params['scm_plugins'];
52 $scm_plugins[]=$this->name;
55 $this->printPage ($params) ;
57 case 'scm_browser_page':
58 $this->printBrowserPage ($params) ;
60 case 'scm_admin_page':
61 $this->printAdminPage ($params) ;
63 case 'scm_admin_update':
64 $this->adminUpdate($params);
67 $this->printShortStats ($params) ;
69 case 'scm_create_repo':
70 session_set_admin () ;
71 $this->createOrUpdateRepo ($params) ;
73 case 'scm_update_repolist':
74 session_set_admin () ;
75 $this->updateRepositoryList ($params) ;
77 case 'scm_generate_snapshots': // Optional
78 session_set_admin () ;
79 $this->generateSnapshots ($params) ;
81 case 'scm_gather_stats': // Optional
82 session_set_admin () ;
83 $this->gatherStats ($params) ;
90 final function register () {
93 $scm_list[] = $this->name ;
96 function browserDisplayable($project) {
97 if ($project->usesSCM()
98 && $project->usesPlugin($this->name)
99 && $project->enableAnonSCM()) {
106 abstract function createOrUpdateRepo ($params) ;
108 function printShortStats ($params) {
109 $project = $this->checkParams ($params) ;
114 if ($project->usesPlugin ($this->name)) {
115 echo ' ('.$this->text.')' ;
119 function getBlurb () {
120 return '<p>' . _('Unimplemented SCM plugin.') . '</p>';
123 function getInstructionsForAnon ($project) {
124 return '<p>' . _('Instructions for anonymous access for unimplemented SCM plugin.') . '</p>';
127 function getInstructionsForRW ($project) {
128 return '<p>' . _('Instructions for read-write access for unimplemented SCM plugin.') . '</p>';
131 function getSnapshotPara ($project) {
132 return '<p>' . _('Instructions for snapshot access for unimplemented SCM plugin.') . '</p>';
135 function getBrowserLinkBlock ($project) {
137 $b = $HTML->boxMiddle(_('Repository Browser'));
139 $b .= _('Browsing the SCM tree is not yet implemented for this SCM plugin.');
142 $b .= util_make_link ("/scm/?group_id=".$project->getID(),
143 _('Not implemented yet')
149 function getBrowserBlock ($project) {
151 $b = $HTML->boxMiddle(_('Repository Browser'));
153 $b .= _('Browsing the SCM tree is not yet implemented for this SCM plugin.');
158 function getStatsBlock ($project) {
160 $b = $HTML->boxMiddle(_('Repository Statistics'));
162 $b .= _('Not implemented for this SCM plugin yet.') ;
167 function printPage ($params) {
170 $project = $this->checkParams ($params) ;
175 if ($project->usesPlugin ($this->name)) {
177 // Table for summary info
178 print '<table width="100%"><tr valign="top"><td width="65%">'."\n" ;
179 print $this->getBlurb ()."\n" ;
181 // Instructions for anonymous access
182 if ($project->enableAnonSCM()) {
183 print $this->getInstructionsForAnon ($project) ;
186 // Instructions for developer access
187 print $this->getInstructionsForRW ($project) ;
190 if ($this->browserDisplayable ($project)) {
191 print $this->getSnapshotPara ($project) ;
193 print '</td>'."\n".'<td width="35%" valign="top">'."\n" ;
196 echo $HTML->boxTop(_('Repository History'));
197 echo _('Data about current and past states of the repository') ;
198 if ($this->browserDisplayable($project)) {
199 echo $this->getStatsBlock($project);
200 echo $this->getBrowserLinkBlock($project);
203 echo $HTML->boxBottom();
204 print '</td></tr></table>' ;
208 function printBrowserPage($params) {
211 $project = $this->checkParams ($params) ;
216 if ($project->usesPlugin ($this->name)) {
217 if ($this->browserDisplayable ($project)) {
218 // print '<iframe src="'.util_make_url('/scm/browser.php?title='.$group->getUnixName()).'" frameborder="0" width=100% height=700></iframe>' ;
223 function printAdminPage($params) {
224 $group = group_get_object($params['group_id']);
225 $ra = RoleAnonymous::getInstance() ;
227 if ( $group->usesPlugin ( $this->name ) && $ra->hasPermission('project_read', $group->getID())) {
228 print '<p><input type="checkbox" name="scm_enable_anonymous" value="1" '.$this->c($group->enableAnonSCM()).' /><strong>'._('Enable Anonymous Read Access').'</strong></p>';
232 function adminUpdate($params) {
233 $project = $this->checkParams($params);
238 if ($project->usesPlugin($this->name) ) {
239 if (isset($params['scm_enable_anonymous']) && $params['scm_enable_anonymous']) {
240 $project->SetUsesAnonSCM(true);
242 $project->SetUsesAnonSCM(false);
247 function checkParams ($params) {
248 $group_id = $params['group_id'] ;
249 $project = group_get_object($group_id);
250 if (!$project || !is_object($project)) {
252 } elseif ($project->isError()) {
261 return 'checked="checked"';
271 // c-file-style: "bsd"