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) {
53 $scm_plugins=& $params['scm_plugins'];
54 $scm_plugins[]=$this->name;
58 $this->printPage($params);
61 case 'scm_browser_page': {
62 $this->printBrowserPage($params);
65 case 'scm_admin_page': {
66 $this->printAdminPage($params);
69 case 'scm_admin_update': {
70 $this->adminUpdate($params);
74 $this->printShortStats($params);
77 case 'scm_create_repo': {
79 $this->createOrUpdateRepo($params);
82 case 'scm_update_repolist': {
84 $this->updateRepositoryList($params);
87 case 'scm_generate_snapshots': { // Optional
89 $this->generateSnapshots($params);
92 case 'scm_gather_stats': { // Optional
94 $this->gatherStats($params);
97 case "widgets": { // Optional
98 $this->widgets($params);
101 case "widget_instance": { // Optional
102 $this->myPageBox($params);
105 case "activity": { //Optional
106 $this->activity($params);
110 // Default is to use method named as the hook
111 $this->$hookname($params);
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) {
238 $project = $this->checkParams($params);
243 if ($project->usesPlugin ($this->name)) {
244 if ($this->browserDisplayable ($project)) {
245 // print '<iframe src="'.util_make_url('/scm/browser.php?title='.$group->getUnixName()).'" frameborder="0" width=100% height=700></iframe>' ;
250 function printAdminPage($params) {
251 $group = group_get_object($params['group_id']);
252 $ra = RoleAnonymous::getInstance() ;
254 if ( $group->usesPlugin ( $this->name ) && $ra->hasPermission('project_read', $group->getID())) {
255 print '<p><input type="checkbox" name="scm_enable_anonymous" value="1" '.$this->c($group->enableAnonSCM()).' /><strong>'._('Enable Anonymous Read Access').'</strong></p>';
259 function adminUpdate($params) {
260 $project = $this->checkParams($params);
265 if ($project->usesPlugin($this->name) ) {
266 if (isset($params['scm_enable_anonymous'])) {
267 if ($params['scm_enable_anonymous']) {
268 $project->SetUsesAnonSCM(true);
270 $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 scm_delete_repo(&$params) {
288 $project = $this->checkParams($params);
292 if (! $project->usesPlugin ($this->name)) {
296 if (!isset($params['repo_name'])) {
300 $result = db_query_params('SELECT count(*) AS count FROM scm_secondary_repos WHERE group_id=$1 AND repo_name = $2 AND plugin_id=$3',
301 array ($params['group_id'],
302 $params['repo_name'],
305 $params['error_msg'] = db_error();
308 if (db_result($result, 0, 'count') == 0) {
309 $params['error_msg'] = sprintf(_('No repository %s exists'), $params['repo_name']);
313 $result = db_query_params ('UPDATE scm_secondary_repos SET next_action = $1 WHERE group_id=$2 AND repo_name=$3 AND plugin_id=$4',
314 array (SCM_EXTRA_REPO_ACTION_DELETE,
316 $params['repo_name'],
319 $params['error_msg'] = db_error();
323 plugin_hook ("scm_admin_update", $params);
327 function scm_admin_buttons(&$params) {
328 $project = $this->checkParams($params);
332 if (! $project->usesPlugin ($this->name)) {
339 '/scm/admin/?group_id='.$params['group_id'].'&form_create_repo=1',
341 array('icon' => html_image('ic/scm_repo_add.png'))
345 function checkParams ($params) {
346 $group_id = $params['group_id'] ;
347 $project = group_get_object($group_id);
348 if (!$project || !is_object($project)) {
350 } elseif ($project->isError()) {
359 return 'checked="checked"';
368 // c-file-style: "bsd"