3 * FusionForge source control management
5 * Copyright 2004-2009, Roland Mas
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
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FusionForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 require_once $gfcommon.'include/scm.php';
27 abstract class SCMPlugin extends Plugin {
29 * SCMPlugin() - constructor
32 function SCMPlugin () {
34 $this->hooks[] = 'scm_plugin';
35 $this->hooks[] = 'scm_page';
36 $this->hooks[] = 'scm_admin_page';
37 $this->hooks[] = 'scm_admin_update';
38 $this->hooks[] = 'scm_stats';
39 $this->hooks[] = 'scm_create_repo';
40 # Other common hooks that can be enabled per plugin:
41 # scm_generate_snapshots
47 function CallHook ($hookname, $params) {
52 $scm_plugins=& $params['scm_plugins'];
53 $scm_plugins[]=$this->name;
56 $this->printPage ($params) ;
58 case 'scm_browser_page':
59 $this->printBrowserPage ($params) ;
61 case 'scm_admin_page':
62 $this->printAdminPage ($params) ;
64 case 'scm_admin_update':
65 $this->adminUpdate ($params) ;
68 $this->printShortStats ($params) ;
70 case 'scm_create_repo':
71 session_set_admin () ;
72 $this->createOrUpdateRepo ($params) ;
74 case 'scm_update_repolist':
75 session_set_admin () ;
76 $this->updateRepositoryList ($params) ;
78 case 'scm_generate_snapshots': // Optional
79 session_set_admin () ;
80 $this->generateSnapshots ($params) ;
82 case 'scm_gather_stats': // Optional
83 session_set_admin () ;
84 $this->gatherStats ($params) ;
91 final function register () {
94 $scm_list[] = $this->name ;
97 function browserDisplayable ($project) {
98 if ($project->usesSCM ()
99 && $project->usesPlugin($this->name)
100 && $project->enableAnonSCM()) {
107 abstract function createOrUpdateRepo ($params) ;
109 function printShortStats ($params) {
110 $project = $this->checkParams ($params) ;
115 if ($project->usesPlugin ($this->name)) {
116 echo ' ('.$this->text.')' ;
120 function getBlurb () {
121 return _('<p>Unimplemented SCM plugin.</p>');
124 function getInstructionsForAnon ($project) {
125 return _('<p>Instructions for anonymous access for unimplemented SCM plugin.</p>');
128 function getInstructionsForRW ($project) {
129 return _('<p>Instructions for read-write access for unimplemented SCM plugin.</p>');
132 function getSnapshotPara ($project) {
133 return _('<p>Instructions for snapshot access for unimplemented SCM plugin.</p>');
136 function getBrowserLinkBlock ($project) {
138 $b = $HTML->boxMiddle(_('Repository Browser'));
139 $b .= _('<p>Browsing the SCM tree is not yet implemented for this SCM plugin.</p>');
141 $b .= util_make_link ("/scm/?group_id=".$project->getID(),
142 _('Not implemented yet')
148 function getBrowserBlock ($project) {
150 $b = $HTML->boxMiddle(_('Repository Browser'));
151 $b .= _('<p>Browsing the SCM tree is not yet implemented for this SCM plugin.</p>');
155 function getStatsBlock ($project) {
157 $b = $HTML->boxMiddle(_('Repository Statistics'));
158 $b .= _('<p>Not implemented for this SCM plugin yet.</p>') ;
162 function printPage ($params) {
163 global $HTML, $sys_scm_snapshots_path;
165 $project = $this->checkParams ($params) ;
170 if ($project->usesPlugin ($this->name)) {
172 // Table for summary info
173 print '<table width="100%"><tr valign="top"><td width="65%">' ;
174 print $this->getBlurb () ;
176 // Instructions for anonymous access
177 if ($project->enableAnonSCM()) {
178 print $this->getInstructionsForAnon ($project) ;
181 // Instructions for developer access
182 print $this->getInstructionsForRW ($project) ;
185 if ($this->browserDisplayable ($project)) {
186 print $this->getSnapshotPara ($project) ;
188 print '</td><td width="35%" valign="top">' ;
191 echo $HTML->boxTop(_('Repository History'));
192 echo _('Data about current and past states of the repository') ;
193 if ($this->browserDisplayable ($project)) {
194 echo $this->getStatsBlock($project) ;
195 echo $this->getBrowserLinkBlock ($project) ;
198 echo $HTML->boxBottom();
199 print '</td></tr></table>' ;
203 function printBrowserPage ($params) {
206 $project = $this->checkParams ($params) ;
211 if ($project->usesPlugin ($this->name)) {
212 if ($this->browserDisplayable ($project)) {
213 // print '<iframe src="'.util_make_url('/scm/browser.php?title='.$group->getUnixName()).'" frameborder="no" width=100% height=700></iframe>' ;
218 function printAdminPage ($params) {
219 $group =& group_get_object($params['group_id']);
220 if ( $group->usesPlugin ( $this->name ) && $group->isPublic()) {
221 print '<p><input type="checkbox" name="scm_enable_anonymous" value="1" '.$this->c($group->enableAnonSCM()).' /><strong>'._('Enable Anonymous Access').'</strong></p>';
225 function adminUpdate ($params) {
226 $project = $this->checkParams ($params) ;
231 if ($project->usesPlugin ($this->name) ) {
232 if ($params['scm_enable_anonymous']) {
233 $project->SetUsesAnonSCM(true);
235 $project->SetUsesAnonSCM(false);
240 function checkParams ($params) {
241 $group_id = $params['group_id'] ;
242 $project =& group_get_object($group_id);
243 if (!$project || !is_object($project)) {
245 } elseif ($project->isError()) {
254 return 'checked="checked"';
264 // c-file-style: "bsd"