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'));
140 $b .= _('Browsing the SCM tree is not yet implemented for this SCM plugin.');
143 $b .= util_make_link ("/scm/?group_id=".$project->getID(),
144 _('Not implemented yet')
150 function getBrowserBlock ($project) {
152 $b = $HTML->boxMiddle(_('Repository Browser'));
154 $b .= _('Browsing the SCM tree is not yet implemented for this SCM plugin.');
159 function getStatsBlock ($project) {
161 $b = $HTML->boxMiddle(_('Repository Statistics'));
163 $b .= _('Not implemented for this SCM plugin yet.') ;
168 function printPage ($params) {
171 $project = $this->checkParams ($params) ;
176 if ($project->usesPlugin ($this->name)) {
178 // Table for summary info
179 print '<table width="100%"><tr valign="top"><td width="65%">' ;
180 print $this->getBlurb () ;
182 // Instructions for anonymous access
183 if ($project->enableAnonSCM()) {
184 print $this->getInstructionsForAnon ($project) ;
187 // Instructions for developer access
188 print $this->getInstructionsForRW ($project) ;
191 if ($this->browserDisplayable ($project)) {
192 print $this->getSnapshotPara ($project) ;
194 print '</td><td width="35%" valign="top">' ;
197 echo $HTML->boxTop(_('Repository History'));
198 echo _('Data about current and past states of the repository') ;
199 if ($this->browserDisplayable ($project)) {
200 echo $this->getStatsBlock($project) ;
201 echo $this->getBrowserLinkBlock ($project) ;
204 echo $HTML->boxBottom();
205 print '</td></tr></table>' ;
209 function printBrowserPage ($params) {
212 $project = $this->checkParams ($params) ;
217 if ($project->usesPlugin ($this->name)) {
218 if ($this->browserDisplayable ($project)) {
219 // print '<iframe src="'.util_make_url('/scm/browser.php?title='.$group->getUnixName()).'" frameborder="no" width=100% height=700></iframe>' ;
224 function printAdminPage ($params) {
225 $group = group_get_object($params['group_id']);
226 if ( $group->usesPlugin ( $this->name ) && $group->isPublic()) {
227 print '<p><input type="checkbox" name="scm_enable_anonymous" value="1" '.$this->c($group->enableAnonSCM()).' /><strong>'._('Enable Anonymous Access').'</strong></p>';
231 function adminUpdate ($params) {
232 $project = $this->checkParams ($params) ;
237 if ($project->usesPlugin ($this->name) ) {
238 if ($params['scm_enable_anonymous']) {
239 $project->SetUsesAnonSCM(true);
241 $project->SetUsesAnonSCM(false);
246 function checkParams ($params) {
247 $group_id = $params['group_id'] ;
248 $project = group_get_object($group_id);
249 if (!$project || !is_object($project)) {
251 } elseif ($project->isError()) {
260 return 'checked="checked"';
270 // c-file-style: "bsd"