-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathSourceViewVC.php
211 lines (175 loc) · 5.45 KB
/
SourceViewVC.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
# Copyright (c) 2015 John Bailey
# Copyright (c) 2012 John Reese
# Licensed under the MIT license
if ( false === include_once( config_get( 'plugin_path' ) . 'SourceSVN/SourceSVN.php' ) ) {
return;
}
class SourceViewVCPlugin extends SourceSVNPlugin {
const PLUGIN_VERSION = '2.1.2';
const FRAMEWORK_VERSION_REQUIRED = '2.5.0';
const SOURCESVN_VERSION_REQUIRED = '2.4.0';
public $type = 'viewvc';
public function register() {
parent::register();
$this->requires['SourceSVN'] = self::SOURCESVN_VERSION_REQUIRED;
$this->author = 'John Bailey';
$this->contact = 'dev@brightsilence.com';
}
public function show_type() {
return lang_get( 'plugin_SourceViewVC_svn' );
}
public function get_viewvc_url( $p_repo ) {
return isset( $p_repo->info['viewvc_url'] )
? $p_repo->info['viewvc_url']
: '';
}
public function get_viewvc_name( $p_repo ) {
return isset( $p_repo->info['viewvc_name'] )
? $p_repo->info['viewvc_name']
: '';
}
public function get_viewvc_use_checkout( $p_repo ) {
return isset( $p_repo->info['viewvc_use_checkout'] )
? $p_repo->info['viewvc_use_checkout']
: false;
}
public function get_viewvc_root_as_url( $p_repo ) {
return isset( $p_repo->info['viewvc_root_as_url'] )
? $p_repo->info['viewvc_root_as_url']
: false;
}
/**
* Builds the ViewVC URL base string
* @param object $p_repo repository
* @param string $p_file optional filename (as absolute path from root)
* @param array $p_opts optional additional ViewVC URL parameters
* @return string ViewVC URL
*/
protected function url_base( $p_repo, $p_file = '', $p_opts=array() ) {
$t_name = urlencode( $this->get_viewvc_name( $p_repo ) );
$t_root_as_url = $this->get_viewvc_root_as_url( $p_repo );
$t_url = rtrim( $this->get_viewvc_url( $p_repo ), '/' );
if( $t_root_as_url ) {
$t_url_name = '/'.$t_name;
} else {
$t_url_name = '';
$p_opts['root']=$t_name;
}
return $t_url . $t_url_name . $p_file . '?' . http_build_query( $p_opts );
}
public function url_repo( $p_repo, $p_changeset=null ) {
$t_opts = array();
if ( !is_null( $p_changeset ) ) {
$t_opts['revision'] = $p_changeset->revision;
}
return $this->url_base( $p_repo, '', $t_opts);
}
public function url_changeset( $p_repo, $p_changeset ) {
$t_rev = $p_changeset->revision;
$t_opts = array();
$t_opts['view'] = 'revision';
$t_opts['revision'] = $t_rev;
return $this->url_base( $p_repo, '', $t_opts );
}
public function url_file( $p_repo, $p_changeset, $p_file ) {
# if the file has been removed, it doesn't exist in current revision
# so we generate a link to (current revision - 1)
$t_revision = ($p_file->action == SourceFile::DELETED)
? $p_changeset->revision - 1
: $p_changeset->revision;
$t_use_checkout = $this->get_viewvc_use_checkout( $p_repo );
$t_opts = array();
$t_opts['revision'] = $t_revision;
$t_opts['pathrev'] = $t_revision;
if( !$t_use_checkout )
{
$t_opts['view'] = 'markup';
}
return $this->url_base( $p_repo, $p_file->filename, $t_opts );
}
public function url_diff( $p_repo, $p_changeset, $p_file ) {
if ( $p_file->action == SourceFile::DELETED || $p_file->action == SourceFile::ADDED ) {
return '';
}
$t_opts = array();
$t_opts['r1'] = $p_changeset->revision;
$t_opts['r2'] = $p_changeset->revision - 1;
$t_opts['pathrev'] = $p_changeset->revision;
return $this->url_base( $p_repo, $p_file->filename, $t_opts );
}
public function update_repo_form( $p_repo ) {
$t_url = $this->get_viewvc_url( $p_repo );
$t_name = $this->get_viewvc_name( $p_repo );
$t_use_checkout = $this->get_viewvc_use_checkout( $p_repo );
$t_root_as_url = $this->get_viewvc_root_as_url( $p_repo );
?>
<tr>
<th class="category">
<label for="viewvc_url">
<?php echo lang_get( 'plugin_SourceViewVC_viewvc_url' ) ?>
</label>
</th>
<td>
<input id="viewvc_url" name="viewvc_url"
type="text" maxlength="250" size="40"
value="<?php echo string_attribute( $t_url ) ?>"
/>
</td>
</tr>
<tr>
<th class="category">
<label for="viewvc_name">
<?php echo lang_get( 'plugin_SourceViewVC_viewvc_name' ) ?>
</label>
</th>
<td>
<input id="viewvc_name" name="viewvc_name"
type="text" maxlength="250" size="40"
value="<?php echo string_attribute( $t_name ) ?>"
/>
</td>
</tr>
<tr>
<th class="category">
<label for="viewvc_root_as_url">
<?php echo lang_get( 'plugin_SourceViewVC_viewvc_root_as_url' ) ?>
</label>
</th>
<td>
<label>
<input id="viewvc_root_as_url" name="viewvc_root_as_url"
type="checkbox" class="ace"
<?php echo ($t_root_as_url ? 'checked="checked"' : '') ?>
/>
<span class="lbl"></span>
</label>
</td>
</tr>
<tr>
<th class="category">
<label for="viewvc_use_checkout">
<?php echo lang_get( 'plugin_SourceViewVC_viewvc_use_checkout' ) ?>
</label>
</th>
<td>
<label>
<input id="viewvc_use_checkout" name="viewvc_use_checkout"
type="checkbox" class="ace"
<?php echo ($t_use_checkout ? 'checked="checked"' : '') ?>
/>
<span class="lbl"></span>
</label>
</td>
</tr>
<?php
parent::update_repo_form( $p_repo );
}
public function update_repo( $p_repo ) {
$p_repo->info['viewvc_url'] = gpc_get_string( 'viewvc_url' );
$p_repo->info['viewvc_name'] = gpc_get_string( 'viewvc_name' );
$p_repo->info['viewvc_use_checkout'] = gpc_get_bool( 'viewvc_use_checkout', false );
$p_repo->info['viewvc_root_as_url'] = gpc_get_bool( 'viewvc_root_as_url', false );
parent::update_repo( $p_repo );
}
}