Add direct links to each source file

Message ID 20170212161331.6414-1-jannehess@gmail.com
State Changes Requested, archived
Headers show

Commit Message

Lukas Fleischer via aur-dev Feb. 12, 2017, 4:13 p.m. UTC
Currently, each source file which is an external link (http://,
https://, ...) is a clickable link.
This commit extends the behaviour by making files from the repository
clickable as well. The link brings the user to the corresponding cgit
page.

Also, the link to the PKGBUILD is altered to make the configuration
more consistent.

Signed-off-by: Janne Heß <jannehess@gmail.com>
---
 conf/config.proto            | 2 +-
 web/lib/pkgfuncs.inc.php     | 6 ++++--
 web/template/pkg_details.php | 3 ++-
 3 files changed, 7 insertions(+), 4 deletions(-)

Comments

Lukas Fleischer Feb. 12, 2017, 4:25 p.m. UTC | #1
On Sun, 12 Feb 2017 at 17:13:31, Janne Heß via aur-dev wrote:
> Currently, each source file which is an external link (http://,
> https://, ...) is a clickable link.
> This commit extends the behaviour by making files from the repository
> clickable as well. The link brings the user to the corresponding cgit
> page.
> 
> Also, the link to the PKGBUILD is altered to make the configuration
> more consistent.
> 
> Signed-off-by: Janne Heß <jannehess@gmail.com>
> ---
>  conf/config.proto            | 2 +-
>  web/lib/pkgfuncs.inc.php     | 6 ++++--
>  web/template/pkg_details.php | 3 ++-
>  3 files changed, 7 insertions(+), 4 deletions(-)
> [...]
> diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php
> index 3269394..2fbdabf 100644
> --- a/web/template/pkg_details.php
> +++ b/web/template/pkg_details.php
> @@ -1,6 +1,6 @@
>  <?php
>  
> -$pkgbuild_uri = sprintf(config_get('options', 'pkgbuild_uri'), urlencode($row['BaseName']));
> +$pkgbuild_uri = sprintf(config_get('options', 'source_file_uri'), 'PKGBUILD', urlencode($row['BaseName']));
>  $log_uri = sprintf(config_get('options', 'log_uri'), urlencode($row['BaseName']));
>  $snapshot_uri = sprintf(config_get('options', 'snapshot_uri'), urlencode($row['BaseName']));
>  $git_clone_uri_anon = sprintf(config_get('options', 'git_clone_uri_anon'), htmlspecialchars($row['BaseName']));
> @@ -300,6 +300,7 @@ endif;
>                         <ul id="pkgsrcslist">
>                                         <?php while (list($k, $src) = each($sources)): ?>
>                                         <li><?= pkg_source_link($src[0], $src[1]) ?></li>

Looks like a spoke too soon. The line that is added below should
actually replace the line above, right?

> +                                       <li><?= pkg_source_link($src[0], $src[1], urlencode($row['BaseName'])) ?></li>
>                                         <?php endwhile; ?>
>                         </ul>
>                 </div>
> -- 
> 2.11.1
Lukas Fleischer via aur-dev Feb. 12, 2017, 4:35 p.m. UTC | #2
I'm really sorry. This happened while rewriting the patch after it
didn't apply anymore (I'm currently unable to access the repo where I
made the work in the first place).
I'll resubmit in a few minutes...

On 02/12/2017 05:25 PM, Lukas Fleischer wrote:
> On Sun, 12 Feb 2017 at 17:13:31, Janne Heß via aur-dev wrote:
>> Currently, each source file which is an external link (http://,
>> https://, ...) is a clickable link.
>> This commit extends the behaviour by making files from the repository
>> clickable as well. The link brings the user to the corresponding cgit
>> page.
>>
>> Also, the link to the PKGBUILD is altered to make the configuration
>> more consistent.
>>
>> Signed-off-by: Janne Heß <jannehess@gmail.com>
>> ---
>>  conf/config.proto            | 2 +-
>>  web/lib/pkgfuncs.inc.php     | 6 ++++--
>>  web/template/pkg_details.php | 3 ++-
>>  3 files changed, 7 insertions(+), 4 deletions(-)
>> [...]
>> diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php
>> index 3269394..2fbdabf 100644
>> --- a/web/template/pkg_details.php
>> +++ b/web/template/pkg_details.php
>> @@ -1,6 +1,6 @@
>>  <?php
>>  
>> -$pkgbuild_uri = sprintf(config_get('options', 'pkgbuild_uri'), urlencode($row['BaseName']));
>> +$pkgbuild_uri = sprintf(config_get('options', 'source_file_uri'), 'PKGBUILD', urlencode($row['BaseName']));
>>  $log_uri = sprintf(config_get('options', 'log_uri'), urlencode($row['BaseName']));
>>  $snapshot_uri = sprintf(config_get('options', 'snapshot_uri'), urlencode($row['BaseName']));
>>  $git_clone_uri_anon = sprintf(config_get('options', 'git_clone_uri_anon'), htmlspecialchars($row['BaseName']));
>> @@ -300,6 +300,7 @@ endif;
>>                         <ul id="pkgsrcslist">
>>                                         <?php while (list($k, $src) = each($sources)): ?>
>>                                         <li><?= pkg_source_link($src[0], $src[1]) ?></li>
> 
> Looks like a spoke too soon. The line that is added below should
> actually replace the line above, right?
> 
>> +                                       <li><?= pkg_source_link($src[0], $src[1], urlencode($row['BaseName'])) ?></li>
>>                                         <?php endwhile; ?>
>>                         </ul>
>>                 </div>
>> -- 
>> 2.11.1

Patch

diff --git a/conf/config.proto b/conf/config.proto
index c1be281..01a907a 100644
--- a/conf/config.proto
+++ b/conf/config.proto
@@ -27,7 +27,7 @@  aur_request_ml = aur-requests@archlinux.org
 request_idle_time = 1209600
 auto_orphan_age = 15552000
 auto_delete_age = 86400
-pkgbuild_uri = https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=%s
+source_file_uri =  https://aur.archlinux.org/cgit/aur.git/tree/%s?h=%s
 log_uri = https://aur.archlinux.org/cgit/aur.git/log/?h=%s
 snapshot_uri = /cgit/aur.git/snapshot/%s.tar.gz
 enable-maintenance = 1
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index 8ca8835..dce0721 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -481,17 +481,19 @@  function pkg_rel_html($name, $cond, $arch) {
  *
  * @param string $url The URL of the source
  * @param string $arch The source architecture
+ * @param string $package The name of the package
  *
  * @return string The HTML code of the label to display
  */
-function pkg_source_link($url, $arch) {
+function pkg_source_link($url, $arch, $package) {
 	$url = explode('::', $url);
 	$parsed_url = parse_url($url[0]);
 
 	if (isset($parsed_url['scheme']) || isset($url[1])) {
 		$link = '<a href="' .  htmlspecialchars((isset($url[1]) ? $url[1] : $url[0]), ENT_QUOTES) . '">' . htmlspecialchars($url[0]) . '</a>';
 	} else {
-		$link = htmlspecialchars($url[0]);
+		$file_url = sprintf(config_get('options', 'source_file_uri'), htmlspecialchars($url[0]), $package);
+		$link = '<a href="' . $file_url . '">' . htmlspecialchars($url[0]) . '</a>';
 	}
 
 	if ($arch) {
diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php
index 3269394..2fbdabf 100644
--- a/web/template/pkg_details.php
+++ b/web/template/pkg_details.php
@@ -1,6 +1,6 @@ 
 <?php
 
-$pkgbuild_uri = sprintf(config_get('options', 'pkgbuild_uri'), urlencode($row['BaseName']));
+$pkgbuild_uri = sprintf(config_get('options', 'source_file_uri'), 'PKGBUILD', urlencode($row['BaseName']));
 $log_uri = sprintf(config_get('options', 'log_uri'), urlencode($row['BaseName']));
 $snapshot_uri = sprintf(config_get('options', 'snapshot_uri'), urlencode($row['BaseName']));
 $git_clone_uri_anon = sprintf(config_get('options', 'git_clone_uri_anon'), htmlspecialchars($row['BaseName']));
@@ -300,6 +300,7 @@  endif;
 			<ul id="pkgsrcslist">
 					<?php while (list($k, $src) = each($sources)): ?>
 					<li><?= pkg_source_link($src[0], $src[1]) ?></li>
+					<li><?= pkg_source_link($src[0], $src[1], urlencode($row['BaseName'])) ?></li>
 					<?php endwhile; ?>
 			</ul>
 		</div>