From aa94548c71fbd285941ddc3b209387d02a1978a8 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Mon, 3 Oct 2016 19:36:37 +0200 Subject: [PATCH] Don't substr() section names in man page URLs And improve man page lookup on "/man.section". If "man.section" itself is a man page, then we display that. If it's not, we look for a man page named "man" in section "section". (And if that section isn't available we just show whatever the preferred version is for "man"). This fixes some occasional 404 links from the search results. --- www/index.pl | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/www/index.pl b/www/index.pl index 523a6f7..1129927 100755 --- a/www/index.pl +++ b/www/index.pl @@ -264,7 +264,7 @@ sub browsesearch { my $q = $self->reqGet('q')||''; my $man = $self->dbSearch($q, 150); - return $self->resRedirect("/$man->[0]{name}.".substr($man->[0]{section},0,1), 'temp') if @$man == 1; + return $self->resRedirect("/$man->[0]{name}.$man->[0]{section}", 'temp') if @$man == 1; $self->htmlHeader(title => 'Search results for '.$q); h1 'Search results for '.$q; @@ -273,7 +273,7 @@ sub browsesearch { ul id => 'searchres'; for(@$man) { li; - a href => "/$_->{name}.".substr($_->{section},0,1), $_->{name}; + a href => "/$_->{name}.$_->{section}", $_->{name}; i " $_->{section}"; end; } @@ -464,13 +464,20 @@ sub manjslist { # Given the name and optionally the hash of a man page, check with a list of # man pages with the same name to select the right one for display. sub getman { - my($self, $name, $hash, $list) = @_; + my($self, $name, $hash) = @_; - my $sect = $name =~ /\.([0-9n])$/ ? $1 : undef; + # Fetch all files with $name and split off the section part if $name has one + my $list = $self->dbManInfo(name => $name); + my $sect; + if(!@$list && $name =~ s/\.([^\.]+)$//) { + $sect = $1; + $list = $self->dbManInfo(name => $name); + } + return (undef, undef) if !@$list; # If we already have a shorthash, just get the full hash if($hash) { - $_->{hash} =~ /^$hash/ && return $_ for (@$list); + $_->{hash} =~ /^$hash/ && return ($_, $list) for (@$list); } # If that failed, use some heuristics @@ -506,7 +513,7 @@ sub getman { my $winner = $list->[0]; $cmp->($winner, $_) > 0 and ($winner = $_) for (@$list); - return $winner; + ($winner, $list); } @@ -517,9 +524,8 @@ sub man { $name =~ s/%5b/[/ig; $name =~ s/%5d/]/ig; - my $m = $self->dbManInfo(name => $name); - return $self->resNotFound() if !@$m; - my $man = getman($self, $name, $hash, $m); + my($man, $m) = getman($self, $name, $hash); + return $self->resNotFound() if !$man; my $view = $self->formValidate({get => 'v', regex => qr/^[a-z2-7]+$/}); $view = $view->{_err} ? '' : $view->{v}; @@ -697,9 +703,8 @@ sub dbManInfo { my $s = shift; my %o = @_; - (my $oname = $o{name}||'') =~ s/\.([0-9nk]|kde3)$//; my %where = ( - $o{name} ? ('m.name IN(!l)' => [[ $o{name}, $oname ne $o{name} ? $oname : () ]]) : (), + $o{name} ? ('m.name = ?' => $o{name}) : (), $o{package} ? ('m.package = ?' => $o{package}) : (), $o{section} ? ('m.section = ?' => $o{section}) : (), $o{shorthash} ? (q{substring(m.hash from 1 for 4) = decode(?, 'hex')} => $o{shorthash}) : (),