Subject: Re: [PATCH] gitweb: allow extra breadcrumbs to prefix the trail

From: Jonathan Nieder <[email-masked]>
Date: Wed, 3 Jul 2013 14:59:30 -0700

(cc-ing Jakub, gitweb wrangler)

Tony Finch wrote:

> There are often parent pages logically above the gitweb projects
> list, e.g. home pages of the organization and department that host
> the gitweb server. This change allows you to include links to those
> pages in gitweb's breadcrumb trail.

Neat.

> Signed-off-by: Tony Finch <[email-masked]>
> ---
>  Documentation/gitweb.conf.txt | 8 ++++++++
>  gitweb/gitweb.perl            | 6 ++++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/Documentation/gitweb.conf.txt b/Documentation/gitweb.conf.txt
> index ea0526e..4579578 100644
> --- a/Documentation/gitweb.conf.txt
> +++ b/Documentation/gitweb.conf.txt
> @@ -339,6 +339,14 @@ $home_link_str::
>  	as this link leads to the list of projects.  Other popular choice it to
>  	set it to the name of site.
>  
> +@extra_breadcrumbs::
> +	Additional links to be added to the start of the breadcrumb trail,
> +	that are logically "above" the gitweb projects list. For example,
> +	links to the organization and department which host the gitweb
> +	server. Each element of the list is a reference to an array,
> +	in which element 0 is the link text and element 1 is the
> +	target URL.

Is arbitrary HTML permitted in the link text?

I think it makes sense to permit it for consistency with $home_link_str,
but it might be worth mentioning in the manpage so the administrator
knows not to set it to something user-controlled --- e.g.:

	The link text can contain arbitrary HTML --- to escape link
	text generated programatically, use esc_html($text).

For what it's worth, with or without such a change,
Reviewed-by: Jonathan Nieder <[email-masked]>

(Patch left unsnipped for reference.)
> +
>  $logo_url::
>  $logo_label::
>  	URI and label (title) for the Git logo link (or your site logo,
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 8d69ada..436f17a 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -85,6 +85,9 @@ our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
>  # string of the home link on top of all pages
>  our $home_link_str = "++GITWEB_HOME_LINK_STR++";
>  
> +# extra breadcrumbs preceding the home link
> +our @extra_breadcrumbs = ();
> +
>  # name of your site or organization to appear in page titles
>  # replace this with something more descriptive for clearer bookmarks
>  our $site_name = "++GITWEB_SITENAME++"
> @@ -3982,6 +3985,9 @@ sub print_nav_breadcrumbs_path {
>  sub print_nav_breadcrumbs {
>  	my %opts = @_;
>  
> +	for my $crumb (@extra_breadcrumbs) {
> +		print $cgi->a({-href => esc_url($crumb->[1])}, $crumb->[0]) . " / ";
> +	}
>  	print $cgi->a({-href => esc_url($home_link)}, $home_link_str) . " / ";
>  	if (defined $project) {
>  		my @dirname = split '/', $project;
> --