Skip to content

Commit 17a403c

Browse files
committed
Merge branch 'jn/gitweb-split-header-html'
* jn/gitweb-split-header-html: gitweb: Refactor git_header_html
2 parents ff94409 + 6ee9033 commit 17a403c

File tree

1 file changed

+95
-77
lines changed

1 file changed

+95
-77
lines changed

gitweb/gitweb.perl

Lines changed: 95 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3680,6 +3680,20 @@ sub get_page_title {
36803680
return $title;
36813681
}
36823682

3683+
sub get_content_type_html {
3684+
# require explicit support from the UA if we are to send the page as
3685+
# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3686+
# we have to do this because MSIE sometimes globs '*/*', pretending to
3687+
# support xhtml+xml but choking when it gets what it asked for.
3688+
if (defined $cgi->http('HTTP_ACCEPT') &&
3689+
$cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
3690+
$cgi->Accept('application/xhtml+xml') != 0) {
3691+
return 'application/xhtml+xml';
3692+
} else {
3693+
return 'text/html';
3694+
}
3695+
}
3696+
36833697
sub print_feed_meta {
36843698
if (defined $project) {
36853699
my %href_params = get_feed_info();
@@ -3725,24 +3739,90 @@ sub print_feed_meta {
37253739
}
37263740
}
37273741

3742+
sub print_header_links {
3743+
my $status = shift;
3744+
3745+
# print out each stylesheet that exist, providing backwards capability
3746+
# for those people who defined $stylesheet in a config file
3747+
if (defined $stylesheet) {
3748+
print '<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";
3749+
} else {
3750+
foreach my $stylesheet (@stylesheets) {
3751+
next unless $stylesheet;
3752+
print '<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";
3753+
}
3754+
}
3755+
print_feed_meta()
3756+
if ($status eq '200 OK');
3757+
if (defined $favicon) {
3758+
print qq(<link rel="shortcut icon" href=").esc_url($favicon).qq(" type="image/png" />\n);
3759+
}
3760+
}
3761+
3762+
sub print_nav_breadcrumbs {
3763+
my %opts = @_;
3764+
3765+
print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
3766+
if (defined $project) {
3767+
print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
3768+
if (defined $action) {
3769+
my $action_print = $action ;
3770+
if (defined $opts{-action_extra}) {
3771+
$action_print = $cgi->a({-href => href(action=>$action)},
3772+
$action);
3773+
}
3774+
print " / $action_print";
3775+
}
3776+
if (defined $opts{-action_extra}) {
3777+
print " / $opts{-action_extra}";
3778+
}
3779+
print "\n";
3780+
}
3781+
}
3782+
3783+
sub print_search_form {
3784+
if (!defined $searchtext) {
3785+
$searchtext = "";
3786+
}
3787+
my $search_hash;
3788+
if (defined $hash_base) {
3789+
$search_hash = $hash_base;
3790+
} elsif (defined $hash) {
3791+
$search_hash = $hash;
3792+
} else {
3793+
$search_hash = "HEAD";
3794+
}
3795+
my $action = $my_uri;
3796+
my $use_pathinfo = gitweb_check_feature('pathinfo');
3797+
if ($use_pathinfo) {
3798+
$action .= "/".esc_url($project);
3799+
}
3800+
print $cgi->startform(-method => "get", -action => $action) .
3801+
"<div class=\"search\">\n" .
3802+
(!$use_pathinfo &&
3803+
$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) . "\n") .
3804+
$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) . "\n" .
3805+
$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) . "\n" .
3806+
$cgi->popup_menu(-name => 'st', -default => 'commit',
3807+
-values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3808+
$cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) .
3809+
" search:\n",
3810+
$cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
3811+
"<span title=\"Extended regular expression\">" .
3812+
$cgi->checkbox(-name => 'sr', -value => 1, -label => 're',
3813+
-checked => $search_use_regexp) .
3814+
"</span>" .
3815+
"</div>" .
3816+
$cgi->end_form() . "\n";
3817+
}
3818+
37283819
sub git_header_html {
37293820
my $status = shift || "200 OK";
37303821
my $expires = shift;
37313822
my %opts = @_;
37323823

37333824
my $title = get_page_title();
3734-
my $content_type;
3735-
# require explicit support from the UA if we are to send the page as
3736-
# 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3737-
# we have to do this because MSIE sometimes globs '*/*', pretending to
3738-
# support xhtml+xml but choking when it gets what it asked for.
3739-
if (defined $cgi->http('HTTP_ACCEPT') &&
3740-
$cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
3741-
$cgi->Accept('application/xhtml+xml') != 0) {
3742-
$content_type = 'application/xhtml+xml';
3743-
} else {
3744-
$content_type = 'text/html';
3745-
}
3825+
my $content_type = get_content_type_html();
37463826
print $cgi->header(-type=>$content_type, -charset => 'utf-8',
37473827
-status=> $status, -expires => $expires)
37483828
unless ($opts{'-no_http_header'});
@@ -3764,22 +3844,7 @@ sub git_header_html {
37643844
if ($ENV{'PATH_INFO'}) {
37653845
print "<base href=\"".esc_url($base_url)."\" />\n";
37663846
}
3767-
# print out each stylesheet that exist, providing backwards capability
3768-
# for those people who defined $stylesheet in a config file
3769-
if (defined $stylesheet) {
3770-
print '<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";
3771-
} else {
3772-
foreach my $stylesheet (@stylesheets) {
3773-
next unless $stylesheet;
3774-
print '<link rel="stylesheet" type="text/css" href="'.esc_url($stylesheet).'"/>'."\n";
3775-
}
3776-
}
3777-
print_feed_meta()
3778-
if ($status eq '200 OK');
3779-
if (defined $favicon) {
3780-
print qq(<link rel="shortcut icon" href=").esc_url($favicon).qq(" type="image/png" />\n);
3781-
}
3782-
3847+
print_header_links($status);
37833848
print "</head>\n" .
37843849
"<body>\n";
37853850

@@ -3796,59 +3861,12 @@ sub git_header_html {
37963861
-alt => "git",
37973862
-class => "logo"}));
37983863
}
3799-
print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
3800-
if (defined $project) {
3801-
print $cgi->a({-href => href(action=>"summary")}, esc_html($project));
3802-
if (defined $action) {
3803-
my $action_print = $action ;
3804-
if (defined $opts{-action_extra}) {
3805-
$action_print = $cgi->a({-href => href(action=>$action)},
3806-
$action);
3807-
}
3808-
print " / $action_print";
3809-
}
3810-
if (defined $opts{-action_extra}) {
3811-
print " / $opts{-action_extra}";
3812-
}
3813-
print "\n";
3814-
}
3864+
print_nav_breadcrumbs(%opts);
38153865
print "</div>\n";
38163866

38173867
my $have_search = gitweb_check_feature('search');
38183868
if (defined $project && $have_search) {
3819-
if (!defined $searchtext) {
3820-
$searchtext = "";
3821-
}
3822-
my $search_hash;
3823-
if (defined $hash_base) {
3824-
$search_hash = $hash_base;
3825-
} elsif (defined $hash) {
3826-
$search_hash = $hash;
3827-
} else {
3828-
$search_hash = "HEAD";
3829-
}
3830-
my $action = $my_uri;
3831-
my $use_pathinfo = gitweb_check_feature('pathinfo');
3832-
if ($use_pathinfo) {
3833-
$action .= "/".esc_url($project);
3834-
}
3835-
print $cgi->startform(-method => "get", -action => $action) .
3836-
"<div class=\"search\">\n" .
3837-
(!$use_pathinfo &&
3838-
$cgi->input({-name=>"p", -value=>$project, -type=>"hidden"}) . "\n") .
3839-
$cgi->input({-name=>"a", -value=>"search", -type=>"hidden"}) . "\n" .
3840-
$cgi->input({-name=>"h", -value=>$search_hash, -type=>"hidden"}) . "\n" .
3841-
$cgi->popup_menu(-name => 'st', -default => 'commit',
3842-
-values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3843-
$cgi->sup($cgi->a({-href => href(action=>"search_help")}, "?")) .
3844-
" search:\n",
3845-
$cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
3846-
"<span title=\"Extended regular expression\">" .
3847-
$cgi->checkbox(-name => 'sr', -value => 1, -label => 're',
3848-
-checked => $search_use_regexp) .
3849-
"</span>" .
3850-
"</div>" .
3851-
$cgi->end_form() . "\n";
3869+
print_search_form();
38523870
}
38533871
}
38543872

0 commit comments

Comments
 (0)