2 /** Subversion plugin for Gforge
3 * Copyright 2003 Roland Mas <lolando@debian.org>
4 * Copyright 2004 Roland Mas <roland@gnurandal.com>
5 * The Gforge Group, LLC <http://gforgegroup.com/>
6 * Based on the CVS plugin, which was derived from Gforge, which was
7 * derived from Sourceforge
9 * This file is not part of Gforge
11 * This plugin, like Gforge, is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * GForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US
26 class SVNPlugin extends SCM {
27 function SVNPlugin () {
29 $this->name = 'scmsvn';
31 $this->hooks[] = 'scm_page';
32 $this->hooks[] = 'scm_admin_update';
33 $this->hooks[] = 'scm_admin_page';
35 $this->hooks[] = 'scm_stats';
36 $this->hooks[] = 'scm_plugin';
38 require_once $gfconfig.'plugins/scmsvn/config.php' ;
40 $this->default_svn_server = $default_svn_server ;
41 $this->enabled_by_default = $enabled_by_default ;
42 $this->use_ssh = $use_ssh;
43 $this->use_dav = $use_dav;
44 $this->use_ssl = $use_ssl;
45 $this->svn_root = $svn_root;
50 function getDefaultServer() {
51 return $this->default_svn_server ;
54 function CallHook ($hookname, $params) {
59 $group_id = $params['group_id'] ;
60 $this->getPage ($group_id) ;
62 case 'scm_admin_update':
63 $this->AdminUpdate ($params) ;
65 case 'scm_admin_page':
66 $this->getAdminPage ($params) ;
69 $this->getStats ($params) ;
72 $scm_plugins=& $params['scm_plugins'];
73 $scm_plugins[]=$this->name;
80 function getPage ($group_id) {
81 global $HTML, $sys_scm_snapshots_path;
83 $project =& group_get_object($group_id);
84 if (!$project || !is_object($project)) {
86 } elseif ($project->isError()) {
90 if ($project->usesPlugin ($this->name)) {
92 // SVN browser links must be displayed if
93 // project enables anon SVN or if logged-in
94 // user is a member of the group
95 $displaySvnBrowser = $project->enableAnonSCM();
96 if(session_loggedin()) {
97 $perm =& $project->getPermission(session_get_user());
98 if ($perm && is_object($perm) && !$perm->isError() && $perm->isMember()) {
99 $displaySvnBrowser = true;
103 // ######################## Table for summary info
109 print _('<p>Documentation for Subversion (sometimes referred to as "SVN") is available <a href="http://svnbook.red-bean.com/">here</a>.</p>');
111 // ######################## Anonymous SVN Instructions
112 if ($project->enableAnonSCM()) {
113 print _('<p><b>Anonymous Subversion Access</b></p><p>This project\'s SVN repository can be checked out through anonymous access with the following command(s).</p>');
115 if ($this->use_ssh) {
116 print '<tt>svn checkout svn://'.$project->getSCMBox().'/'.$this->svn_root.'/'.$project->getUnixName().'</tt><br />';
118 if ($this->use_dav) {
119 print '<tt>svn checkout --username anonsvn http'.(($this->use_ssl) ? 's' : '').'://' . $project->getSCMBox(). '/' . $this->svn_root .'/'. $project->getUnixName() .'</tt><br/><br/>';
120 print _('The password is \'anonsvn\'').'<br/>';
125 // ######################## Developer Access
126 if ($this->use_ssh) {
127 echo _('<p><b>Developer Subversion Access via SSH</b></p><p>Only project developers can access the SVN tree via this method. SSH must be installed on your client machine. Substitute <i>developername</i> with the proper values. Enter your site password when prompted.</p>');
128 print '<p><tt>svn checkout svn+ssh://<i>'._('developername').'</i>@' . $project->getSCMBox() . '/'. $this->svn_root .'/'. $project->getUnixName().'</tt></p>' ;
130 if ($this->use_dav) {
131 echo _('<p><b>Developer Subversion Access via DAV</b></p><p>Only project developers can access the SVN tree via this method. Substitute <i>developername</i> with the proper values. Enter your site password when prompted.</p>');
132 print '<p><tt>svn checkout --username <i>'._('developername').'</i> http'.(($this->use_ssl) ? 's' : '').'://'. $project->getSCMBox() .'/'. $this->svn_root .'/'.$project->getUnixName().'</tt></p>' ;
135 // ######################## SVN Snapshot
136 if ($displaySvnBrowser) {
137 $filename=$project->getUnixName().'-scm-latest.tar.gz';
138 if (file_exists($sys_scm_snapshots_path.'/'.$filename)) {
139 print '<p>[<a href="/snapshots.php?group_id='.$group_id.'">'
140 ._('Download The Nightly SVN Tree Snapshot').
147 <td width="35%" valign="top">
149 // ######################## SVN Browsing
150 echo $HTML->boxTop(_('Repository History'));
151 echo $this->getDetailedStats(array('group_id'=>$group_id)).'<p>';
152 if ($displaySvnBrowser) {
153 echo _('<b>Browse the Subversion Tree</b><p>Browsing the SVN tree gives you a great view into the current status of this project\'s code. You may also view the complete histories of any file in the repository.</p>');
154 echo '<p>[<a href="/scm/viewvc.php/?root='.$project->getUnixName().'">'._('Browse Subversion Repository').'</a>]</p>' ;
157 echo $HTML->boxBottom();
166 function AdminUpdate ($params) {
167 $group =& group_get_object($params['group_id']);
168 if (!$group || !is_object($group)) {
170 } elseif ($group->isError()) {
174 if ( $group->usesPlugin ( $this->name ) ) {
175 if ($params['scmsvn_enable_anon_svn']) {
176 $group->SetUsesAnonSCM(true);
178 $group->SetUsesAnonSCM(false);
183 // This function is used to render checkboxes below
186 return 'checked="checked"';
192 function getAdminPage ($params) {
193 $group =& group_get_object($params['group_id']);
194 if ( $group->usesPlugin ( $this->name ) && $group->isPublic()) {
196 <p><input type="checkbox" name="scmsvn_enable_anon_svn" value="1" <?php echo $this->c($group->enableAnonSCM()); ?> /><strong><?php echo _('Enable Anonymous Access') ?></strong></p>
201 function getStats ($params) {
202 $group_id = $params['group_id'] ;
203 $project =& group_get_object($group_id);
204 if (!$project || !is_object($project)) {
206 } elseif ($project->isError()) {
210 if ($project->usesPlugin ($this->name)) {
211 list($commit_num, $add_num) = $this->getTotalStats($group_id);
212 echo ' (SVN: '.sprintf(_('<strong>%1$s</strong> updates, <strong>%2$s</strong> adds'), number_format($commit_num, 0), number_format($add_num, 0)).')';
216 // Get the total stats for a group
217 function getTotalStats($group_id) {
219 SELECT SUM(commits) AS commits, SUM(adds) AS adds
221 WHERE group_id='$group_id'");
222 $commit_num = db_result($result,0,0);
223 $add_num = db_result($result,0,1);
230 return array($commit_num, $add_num);
233 function getDetailedStats ($params) {
235 $group_id = $params['group_id'] ;
238 SELECT u.realname, u.user_name, sum(commits) as commits, sum(adds) as adds, sum(adds+commits) as combined
239 FROM stats_cvs_user s, users u
240 WHERE group_id=\''.$group_id.'\' AND s.user_id=u.user_id AND (commits>0 OR adds >0)
241 GROUP BY group_id, realname, user_name
242 ORDER BY combined DESC, realname;
245 if (db_numrows($result) > 0) {
246 $tableHeaders = array(
251 echo $HTML->listTableTop($tableHeaders);
254 $total = array('adds' => 0, 'commits' => 0);
256 while($data = db_fetch_array($result)) {
257 echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
258 echo '<td width="50%">' .
259 '<a href="/users/'.$data['user_name'].'/">'.$data['realname'].'</a>' .
260 '</td><td width="25%" align="right">'.$data['adds']. '</td>'.
261 '<td width="25%" align="right">'.$data['commits'].'</td></tr>';
262 $total['adds'] += $data['adds'];
263 $total['commits'] += $data['commits'];
266 list($commit_num, $add_num) = $this->getTotalStats($group_id);
267 if ($commit_num > $total['commits'] ||
268 $add_num > $total['adds']) {
269 echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
270 echo '<td width="50%">' .
272 '</td><td width="25%" align="right">'.
273 ($add_num - $total['adds']) . '</td>'.
274 '<td width="25%" align="right">'.
275 ($commit_num - $total['commits']) .
279 echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
280 echo '<td width="50%"><strong>'._('Total').':</strong></td>'.
281 '<td width="25%" align="right"><strong>'.$add_num. '</strong></td>'.
282 '<td width="25%" align="right"><strong>'.$commit_num.'</strong></td>';
284 echo $HTML->listTableBottom();
285 echo '<hr size="1" />';
292 // c-file-style: "bsd"