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);
112 // Default is to use method named as the hook
113 $this->$hookname($params);
118 final function register() {
121 $scm_list[] = $this->name;
124 function browserDisplayable($project) {
125 if ($project->usesSCM() && $project->usesPlugin($this->name)) {
126 if ($project->enableAnonSCM() || forge_check_perm('scm', $project->getID(), 'read')) {
133 abstract function createOrUpdateRepo($params);
135 function printShortStats($params) {
136 $project = $this->checkParams($params);
141 if ($project->usesPlugin($this->name)) {
142 echo ' ('.$this->text.')' ;
146 function getBlurb () {
147 return '<p>' . _('Unimplemented SCM plugin.') . '</p>';
150 function getInstructionsForAnon ($project) {
151 return '<p>' . _('Instructions for anonymous access for unimplemented SCM plugin.') . '</p>';
154 function getInstructionsForRW ($project) {
155 return '<p>' . _('Instructions for read-write access for unimplemented SCM plugin.') . '</p>';
158 function getSnapshotPara ($project) {
159 return '<p>' . _('Instructions for snapshot access for unimplemented SCM plugin.') . '</p>';
162 function getBrowserLinkBlock($project) {
164 $b = $HTML->boxMiddle(_('Repository Browser'));
166 $b .= _('Browsing the SCM tree is not yet implemented for this SCM plugin.');
169 $b .= util_make_link ("/scm/?group_id=".$project->getID(),
170 _('Not implemented yet')
176 function getBrowserBlock($project) {
178 $b = $HTML->boxMiddle(_('Repository Browser'));
180 $b .= _('Browsing the SCM tree is not yet implemented for this SCM plugin.');
185 function getStatsBlock($project) {
187 $b = $HTML->boxMiddle(_('Repository Statistics'));
189 $b .= _('Not implemented for this SCM plugin yet.') ;
194 function printPage($params) {
197 $project = $this->checkParams($params);
202 if ($project->usesPlugin($this->name)) {
204 session_require_perm('scm', $project->getID(), 'read');
205 // Table for summary info
206 print '<table class="fullwidth"><tr class="top"><td style="width:65%">'."\n" ;
207 print $this->getBlurb()."\n";
209 // Instructions for anonymous access
210 if ($project->enableAnonSCM()) {
211 print $this->getInstructionsForAnon($project);
214 // Instructions for developer access
215 print $this->getInstructionsForRW($project);
217 if ($this->browserDisplayable($project)) {
218 echo $this->getBrowserLinkBlock($project);
222 if ($this->browserDisplayable($project)) {
223 print $this->getSnapshotPara($project);
225 print '</td>'."\n".'<td style="width:35%" class="top">'."\n";
228 echo $HTML->boxTop(_('Repository History'));
229 echo _('Data about current and past states of the repository');
230 if ($this->browserDisplayable($project)) {
231 echo $this->getStatsBlock($project);
234 echo $HTML->boxBottom();
235 print '</td></tr></table>' ;
239 function printBrowserPage($params) {
242 $project = $this->checkParams($params);
247 if ($project->usesPlugin ($this->name)) {
248 if ($this->browserDisplayable ($project)) {
249 // print '<iframe src="'.util_make_url('/scm/browser.php?title='.$group->getUnixName()).'" frameborder="0" width=100% height=700></iframe>' ;
254 function printAdminPage($params) {
255 $group = group_get_object($params['group_id']);
256 $ra = RoleAnonymous::getInstance() ;
258 if ( $group->usesPlugin ( $this->name ) && $ra->hasPermission('project_read', $group->getID())) {
259 print '<p><input type="checkbox" name="scm_enable_anonymous" value="1" '.$this->c($group->enableAnonSCM()).' /><strong>'._('Enable Anonymous Read Access').'</strong></p>';
263 function adminUpdate($params) {
264 $project = $this->checkParams($params);
269 if ($project->usesPlugin($this->name) ) {
270 if (isset($params['scm_enable_anonymous'])) {
271 if ($params['scm_enable_anonymous']) {
272 $project->SetUsesAnonSCM(true);
274 $project->SetUsesAnonSCM(false);
280 function getBoxForProject($project) {
281 $box = $project->getSCMBox();
283 $box = forge_get_config('default_server', $this->name);
286 $box = forge_get_config('web_host');
291 function scm_delete_repo(&$params) {
292 $project = $this->checkParams($params);
296 if (! $project->usesPlugin ($this->name)) {
300 if (!isset($params['repo_name'])) {
304 $result = db_query_params('SELECT count(*) AS count FROM scm_secondary_repos WHERE group_id=$1 AND repo_name = $2 AND plugin_id=$3',
305 array ($params['group_id'],
306 $params['repo_name'],
309 $params['error_msg'] = db_error();
312 if (db_result($result, 0, 'count') == 0) {
313 $params['error_msg'] = sprintf(_('No repository %s exists'), $params['repo_name']);
317 $result = db_query_params ('UPDATE scm_secondary_repos SET next_action = $1 WHERE group_id=$2 AND repo_name=$3 AND plugin_id=$4',
318 array (SCM_EXTRA_REPO_ACTION_DELETE,
320 $params['repo_name'],
323 $params['error_msg'] = db_error();
327 plugin_hook ("scm_admin_update", $params);
331 function scm_admin_buttons(&$params) {
332 $project = $this->checkParams($params);
336 if (! $project->usesPlugin ($this->name)) {
343 '/scm/admin/?group_id='.$params['group_id'].'&form_create_repo=1',
345 array('icon' => html_image('ic/scm_repo_add.png'))
349 function checkParams ($params) {
350 $group_id = $params['group_id'] ;
351 $project = group_get_object($group_id);
352 if (!$project || !is_object($project)) {
354 } elseif ($project->isError()) {
363 return 'checked="checked"';
373 // c-file-style: "bsd"