3 * FusionForge source control management
5 * Copyright 2004-2009, Roland Mas
6 * Copyright (C) 2011 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
48 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);
109 default: { // Forgot something
114 final function register() {
117 $scm_list[] = $this->name;
120 function browserDisplayable($project) {
121 if ($project->usesSCM() && $project->usesPlugin($this->name)) {
122 if ($project->enableAnonSCM() || forge_check_perm('scm', $project->getID(), 'read')) {
129 abstract function createOrUpdateRepo($params);
131 function printShortStats($params) {
132 $project = $this->checkParams($params);
137 if ($project->usesPlugin($this->name)) {
138 echo ' ('.$this->text.')' ;
142 function getBlurb () {
143 return '<p>' . _('Unimplemented SCM plugin.') . '</p>';
146 function getInstructionsForAnon ($project) {
147 return '<p>' . _('Instructions for anonymous access for unimplemented SCM plugin.') . '</p>';
150 function getInstructionsForRW ($project) {
151 return '<p>' . _('Instructions for read-write access for unimplemented SCM plugin.') . '</p>';
154 function getSnapshotPara ($project) {
155 return '<p>' . _('Instructions for snapshot access for unimplemented SCM plugin.') . '</p>';
158 function getBrowserLinkBlock($project) {
160 $b = $HTML->boxMiddle(_('Repository Browser'));
162 $b .= _('Browsing the SCM tree is not yet implemented for this SCM plugin.');
165 $b .= util_make_link ("/scm/?group_id=".$project->getID(),
166 _('Not implemented yet')
172 function getBrowserBlock($project) {
174 $b = $HTML->boxMiddle(_('Repository Browser'));
176 $b .= _('Browsing the SCM tree is not yet implemented for this SCM plugin.');
181 function getStatsBlock($project) {
183 $b = $HTML->boxMiddle(_('Repository Statistics'));
185 $b .= _('Not implemented for this SCM plugin yet.') ;
190 function printPage($params) {
193 $project = $this->checkParams($params);
198 if ($project->usesPlugin($this->name)) {
200 session_require_perm('scm', $project->getID(), 'read');
201 // Table for summary info
202 print '<table class="fullwidth"><tr valign="top"><td style="width:65%">'."\n";
203 print $this->getBlurb()."\n";
205 // Instructions for anonymous access
206 if ($project->enableAnonSCM()) {
207 print $this->getInstructionsForAnon($project);
210 // Instructions for developer access
211 print $this->getInstructionsForRW($project);
213 if ($this->browserDisplayable($project)) {
214 echo $this->getBrowserLinkBlock($project);
218 if ($this->browserDisplayable($project)) {
219 print $this->getSnapshotPara($project);
221 print '</td>'."\n".'<td style="width:35%" class="top">'."\n";
224 echo $HTML->boxTop(_('Repository History'));
225 echo _('Data about current and past states of the repository');
226 if ($this->browserDisplayable($project)) {
227 echo $this->getStatsBlock($project);
230 echo $HTML->boxBottom();
231 print '</td></tr></table>' ;
235 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']) && $params['scm_enable_anonymous']) {
267 $project->SetUsesAnonSCM(true);
269 $project->SetUsesAnonSCM(false);
274 function getBoxForProject($project) {
275 $box = $project->getSCMBox();
277 $box = forge_get_config('default_server', $this->name);
280 $box = forge_get_config('web_host');
285 function checkParams ($params) {
286 $group_id = $params['group_id'] ;
287 $project = group_get_object($group_id);
288 if (!$project || !is_object($project)) {
290 } elseif ($project->isError()) {
299 return 'checked="checked"';
309 // c-file-style: "bsd"