diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 3fbba6e..3e8844d --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ * **SourceSFSVN**: SVN repositories hosted on [SourceForge](http://sourceforge.net/). * **SourceSVN**: SVN repositories locally accessible by the SVN binaries. +* **SourceViewVC**: SVN repositories accessible via a + [ViewVC](http://www.viewvc.org/) web frontend installation. * **SourceWebSVN**: SVN repositories accessible via a [WebSVN](http://www.websvn.info/) web frontend installation. @@ -88,6 +90,7 @@ relevant plugin extension: * [SourceGithub](docs/CONFIGURING.SourceGithub.md) + * [SourceViewVC](docs/CONFIGURING.SourceViewVC.md) 9. Once configured, click the "Return to Repository" link and click either the "Import Everything" or "Import Newest Data" button to perform initial diff --git a/SourceViewVC/LICENSE b/SourceViewVC/LICENSE new file mode 100755 index 0000000..9c6c2e6 --- /dev/null +++ b/SourceViewVC/LICENSE @@ -0,0 +1,23 @@ +Copyright (c) 2015 John Bailey + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + diff --git a/SourceViewVC/SourceViewVC.php b/SourceViewVC/SourceViewVC.php new file mode 100755 index 0000000..06ae715 --- /dev/null +++ b/SourceViewVC/SourceViewVC.php @@ -0,0 +1,169 @@ +name = lang_get( 'plugin_SourceViewVC_title' ); + $this->description = lang_get( 'plugin_SourceViewVC_description' ); + + $this->version = '0.1'; + $this->requires = array( + 'MantisCore' => '1.2.0', + 'Source' => '0.16', + 'SourceSVN' => '0.16', + ); + + $this->author = 'John Bailey'; + $this->contact = 'dev@brightsilence.com'; + $this->url = 'https://github.com/mantisbt-plugins/source-integration'; + } + + public $type = 'viewvc'; + + 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 == 'rm') + ? $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; + + 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 == 'rm' || $p_file->action == 'add' ) { + return ''; + } + + $t_opts = array(); + $t_opts['r1'] = $p_changeset->revision; + $t_opts['r2'] = $p_changeset->revision - 1; + + 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 ); + +?> +