From: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
To: git@vger.kernel.org, jnareb@gmail.com, chriscool@tuxfamily.org,
pasky@ucw.cz
Cc: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
Subject: [RFC/PATCH 2/4] gitweb: Create Gitweb::HTML::Link module
Date: Tue, 8 Jun 2010 02:20:42 +0530 [thread overview]
Message-ID: <1275943844-24991-2-git-send-email-pavan.sss1991@gmail.com> (raw)
In-Reply-To: <1275943844-24991-1-git-send-email-pavan.sss1991@gmail.com>
Create Gitweb::HTML::Link module in 'gitweb/lib/Gitweb/HTML/Link.pm'
to store the subroutines from the section 'action links' in the
previous gitweb.perl
Subroutines moved:
href
Update 'gitweb/Makefile' to install this module alongside gitweb.
Signed-off-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
---
gitweb/Makefile | 5 +-
gitweb/gitweb.perl | 123 +-----------------------------------
gitweb/lib/Gitweb/HTML/Link.pm | 137 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 142 insertions(+), 123 deletions(-)
create mode 100644 gitweb/lib/Gitweb/HTML/Link.pm
diff --git a/gitweb/Makefile b/gitweb/Makefile
index fcd4042..28f0858 100644
--- a/gitweb/Makefile
+++ b/gitweb/Makefile
@@ -116,6 +116,8 @@ GITWEB_LIB_GITWEB += lib/Gitweb/Config.pm
GITWEB_LIB_GITWEB += lib/Gitweb/Request.pm
GITWEB_LIB_GITWEB += lib/Gitweb/Escape.pm
GITWEB_LIB_GITWEB += lib/Gitweb/Git.pm
+# Files: gitweb/lib/Gitweb/HTML
+GITWEB_LIB_GITWEB_HTML += lib/Gitweb/HTML/Link.pm
GITWEB_REPLACE = \
-e 's|++GIT_VERSION++|$(GIT_VERSION)|g' \
@@ -157,8 +159,9 @@ install: all
$(INSTALL) -m 755 $(GITWEB_PROGRAMS) '$(DESTDIR_SQ)$(gitwebdir_SQ)'
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitwebstaticdir_SQ)'
$(INSTALL) -m 644 $(GITWEB_FILES) '$(DESTDIR_SQ)$(gitwebstaticdir_SQ)'
- $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitweblibdir_SQ)/Gitweb'
+ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitweblibdir_SQ)/Gitweb/HTML'
$(INSTALL) -m 644 $(GITWEB_LIB_GITWEB) '$(DESTDIR_SQ)$(gitweblibdir_SQ)/Gitweb'
+ $(INSTALL) -m 644 $(GITWEB_LIB_GITWEB_HTML) '$(DESTDIR_SQ)$(gitweblibdir_SQ)/Gitweb/HTML'
### Cleaning rules
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 3931064..bd11ae0 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -28,6 +28,7 @@ use Gitweb::Git;
use Gitweb::Config;
use Gitweb::Request;
use Gitweb::Escape;
+use Gitweb::HTML::Link;
BEGIN {
CGI->compile() if $ENV{'MOD_PERL'};
@@ -554,128 +555,6 @@ sub run {
run();
## ======================================================================
-## action links
-
-# possible values of extra options
-# -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)
-# -replay => 1 - start from a current view (replay with modifications)
-# -path_info => 0|1 - don't use/use path_info URL (if possible)
-sub href {
- my %params = @_;
- # default is to use -absolute url() i.e. $my_uri
- my $href = $params{-full} ? $my_url : $my_uri;
-
- $params{'project'} = $project unless exists $params{'project'};
-
- if ($params{-replay}) {
- while (my ($name, $symbol) = each %cgi_param_mapping) {
- if (!exists $params{$name}) {
- $params{$name} = $input_params{$name};
- }
- }
- }
-
- my $use_pathinfo = gitweb_check_feature('pathinfo');
- if (defined $params{'project'} &&
- (exists $params{-path_info} ? $params{-path_info} : $use_pathinfo)) {
- # try to put as many parameters as possible in PATH_INFO:
- # - project name
- # - action
- # - hash_parent or hash_parent_base:/file_parent
- # - hash or hash_base:/filename
- # - the snapshot_format as an appropriate suffix
-
- # When the script is the root DirectoryIndex for the domain,
- # $href here would be something like http://gitweb.example.com/
- # Thus, we strip any trailing / from $href, to spare us double
- # slashes in the final URL
- $href =~ s,/$,,;
-
- # Then add the project name, if present
- $href .= "/".esc_url($params{'project'});
- delete $params{'project'};
-
- # since we destructively absorb parameters, we keep this
- # boolean that remembers if we're handling a snapshot
- my $is_snapshot = $params{'action'} eq 'snapshot';
-
- # Summary just uses the project path URL, any other action is
- # added to the URL
- if (defined $params{'action'}) {
- $href .= "/".esc_url($params{'action'}) unless $params{'action'} eq 'summary';
- delete $params{'action'};
- }
-
- # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
- # stripping nonexistent or useless pieces
- $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
- || $params{'hash_parent'} || $params{'hash'});
- if (defined $params{'hash_base'}) {
- if (defined $params{'hash_parent_base'}) {
- $href .= esc_url($params{'hash_parent_base'});
- # skip the file_parent if it's the same as the file_name
- if (defined $params{'file_parent'}) {
- if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
- delete $params{'file_parent'};
- } elsif ($params{'file_parent'} !~ /\.\./) {
- $href .= ":/".esc_url($params{'file_parent'});
- delete $params{'file_parent'};
- }
- }
- $href .= "..";
- delete $params{'hash_parent'};
- delete $params{'hash_parent_base'};
- } elsif (defined $params{'hash_parent'}) {
- $href .= esc_url($params{'hash_parent'}). "..";
- delete $params{'hash_parent'};
- }
-
- $href .= esc_url($params{'hash_base'});
- if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
- $href .= ":/".esc_url($params{'file_name'});
- delete $params{'file_name'};
- }
- delete $params{'hash'};
- delete $params{'hash_base'};
- } elsif (defined $params{'hash'}) {
- $href .= esc_url($params{'hash'});
- delete $params{'hash'};
- }
-
- # If the action was a snapshot, we can absorb the
- # snapshot_format parameter too
- if ($is_snapshot) {
- my $fmt = $params{'snapshot_format'};
- # snapshot_format should always be defined when href()
- # is called, but just in case some code forgets, we
- # fall back to the default
- $fmt ||= $snapshot_fmts[0];
- $href .= $known_snapshot_formats{$fmt}{'suffix'};
- delete $params{'snapshot_format'};
- }
- }
-
- # now encode the parameters explicitly
- my @result = ();
- for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
- my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
- if (defined $params{$name}) {
- if (ref($params{$name}) eq "ARRAY") {
- foreach my $par (@{$params{$name}}) {
- push @result, $symbol . "=" . esc_param($par);
- }
- } else {
- push @result, $symbol . "=" . esc_param($params{$name});
- }
- }
- }
- $href .= "?" . join(';', @result) if scalar @result;
-
- return $href;
-}
-
-
-## ======================================================================
## validation, quoting/unquoting and escaping
sub validate_action {
diff --git a/gitweb/lib/Gitweb/HTML/Link.pm b/gitweb/lib/Gitweb/HTML/Link.pm
new file mode 100644
index 0000000..086809f
--- /dev/null
+++ b/gitweb/lib/Gitweb/HTML/Link.pm
@@ -0,0 +1,137 @@
+#!/usr/bin/perl
+#
+# Gitweb::HTML::Link -- gitweb's action links package
+#
+# This program is licensed under the GPLv2
+
+package Gitweb::HTML::Link;
+
+use strict;
+use warnings;
+use Exporter qw(import);
+
+our @EXPORT = qw(href);
+
+use Gitweb::Config qw(gitweb_check_feature %known_snapshot_formats @snapshot_fmts);
+use Gitweb::Request qw($project %cgi_param_mapping @cgi_param_mapping $my_url $my_uri %input_params);
+use Gitweb::Escape qw(esc_url esc_param);
+
+# possible values of extra options
+# -full => 0|1 - use absolute/full URL ($my_uri/$my_url as base)
+# -replay => 1 - start from a current view (replay with modifications)
+# -path_info => 0|1 - don't use/use path_info URL (if possible)
+sub href {
+ my %params = @_;
+ # default is to use -absolute url() i.e. $my_uri
+ my $href = $params{-full} ? $my_url : $my_uri;
+
+ $params{'project'} = $project unless exists $params{'project'};
+
+ if ($params{-replay}) {
+ while (my ($name, $symbol) = each %cgi_param_mapping) {
+ if (!exists $params{$name}) {
+ $params{$name} = $input_params{$name};
+ }
+ }
+ }
+
+ my $use_pathinfo = gitweb_check_feature('pathinfo');
+ if (defined $params{'project'} &&
+ (exists $params{-path_info} ? $params{-path_info} : $use_pathinfo)) {
+ # try to put as many parameters as possible in PATH_INFO:
+ # - project name
+ # - action
+ # - hash_parent or hash_parent_base:/file_parent
+ # - hash or hash_base:/filename
+ # - the snapshot_format as an appropriate suffix
+
+ # When the script is the root DirectoryIndex for the domain,
+ # $href here would be something like http://gitweb.example.com/
+ # Thus, we strip any trailing / from $href, to spare us double
+ # slashes in the final URL
+ $href =~ s,/$,,;
+
+ # Then add the project name, if present
+ $href .= "/".esc_url($params{'project'});
+ delete $params{'project'};
+
+ # since we destructively absorb parameters, we keep this
+ # boolean that remembers if we're handling a snapshot
+ my $is_snapshot = $params{'action'} eq 'snapshot';
+
+ # Summary just uses the project path URL, any other action is
+ # added to the URL
+ if (defined $params{'action'}) {
+ $href .= "/".esc_url($params{'action'}) unless $params{'action'} eq 'summary';
+ delete $params{'action'};
+ }
+
+ # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
+ # stripping nonexistent or useless pieces
+ $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
+ || $params{'hash_parent'} || $params{'hash'});
+ if (defined $params{'hash_base'}) {
+ if (defined $params{'hash_parent_base'}) {
+ $href .= esc_url($params{'hash_parent_base'});
+ # skip the file_parent if it's the same as the file_name
+ if (defined $params{'file_parent'}) {
+ if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
+ delete $params{'file_parent'};
+ } elsif ($params{'file_parent'} !~ /\.\./) {
+ $href .= ":/".esc_url($params{'file_parent'});
+ delete $params{'file_parent'};
+ }
+ }
+ $href .= "..";
+ delete $params{'hash_parent'};
+ delete $params{'hash_parent_base'};
+ } elsif (defined $params{'hash_parent'}) {
+ $href .= esc_url($params{'hash_parent'}). "..";
+ delete $params{'hash_parent'};
+ }
+
+ $href .= esc_url($params{'hash_base'});
+ if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
+ $href .= ":/".esc_url($params{'file_name'});
+ delete $params{'file_name'};
+ }
+ delete $params{'hash'};
+ delete $params{'hash_base'};
+ } elsif (defined $params{'hash'}) {
+ $href .= esc_url($params{'hash'});
+ delete $params{'hash'};
+ }
+
+ # If the action was a snapshot, we can absorb the
+ # snapshot_format parameter too
+ if ($is_snapshot) {
+ my $fmt = $params{'snapshot_format'};
+ # snapshot_format should always be defined when href()
+ # is called, but just in case some code forgets, we
+ # fall back to the default
+ $fmt ||= $snapshot_fmts[0];
+ $href .= $known_snapshot_formats{$fmt}{'suffix'};
+ delete $params{'snapshot_format'};
+ }
+ }
+
+ # now encode the parameters explicitly
+ my @result = ();
+ for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
+ my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
+ if (defined $params{$name}) {
+ if (ref($params{$name}) eq "ARRAY") {
+ foreach my $par (@{$params{$name}}) {
+ push @result, $symbol . "=" . esc_param($par);
+ }
+ } else {
+ push @result, $symbol . "=" . esc_param($params{$name});
+ }
+ }
+ }
+ $href .= "?" . join(';', @result) if scalar @result;
+
+ return $href;
+}
+
+1;
--
1.7.1.454.ga8c50c
next prev parent reply other threads:[~2010-06-07 20:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-07 20:50 [RFC/PATCH 1/4] gitweb: Move subroutines to Gitweb::Config module Pavan Kumar Sunkara
2010-06-07 20:50 ` Pavan Kumar Sunkara [this message]
2010-06-07 20:50 ` [RFC/PATCH 3/4] gitweb: Create Gitweb::HTML module Pavan Kumar Sunkara
2010-06-07 20:50 ` [RFC/PATCH 4/4] gitweb: Create Gitweb::HTML::String module Pavan Kumar Sunkara
2010-06-07 20:58 ` Pavan Kumar Sunkara
2010-06-08 12:46 ` [RFC/PATCH 1/4] gitweb: Move subroutines to Gitweb::Config module Jakub Narebski
2010-06-08 13:50 ` Ævar Arnfjörð Bjarmason
2010-06-12 1:01 ` Jakub Narebski
2010-06-12 1:22 ` Ævar Arnfjörð Bjarmason
2010-06-12 1:41 ` Jakub Narebski
2010-06-08 14:13 ` Petr Baudis
2010-06-08 19:22 ` Pavan Kumar Sunkara
2010-06-08 19:55 ` Petr Baudis
2010-06-08 20:24 ` Pavan Kumar Sunkara
2010-06-08 20:50 ` Petr Baudis
2010-06-08 23:38 ` Jakub Narebski
2010-06-09 13:13 ` Jakub Narebski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1275943844-24991-2-git-send-email-pavan.sss1991@gmail.com \
--to=pavan.sss1991@gmail.com \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=jnareb@gmail.com \
--cc=pasky@ucw.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).