wiki.pl: Port some fixes from upstream
[Orgmuse.git] / modules / page-trail.pl
blobc22339366c4a0822e2957763e93491d457b8377c
1 # Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the
15 # Free Software Foundation, Inc.
16 # 59 Temple Place, Suite 330
17 # Boston, MA 02111-1307 USA
19 use vars qw($PageTrailLength);
21 $PageTrailLength = 10;
23 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/page-trail.pl">page-trail.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Page_Trail_Extension">Page Trail Extension</a></p>';
25 $CookieParameters{trail} = '';
26 $InvisibleCookieParameters{trail} = 1;
27 my @PageTrail;
29 *OldPageTrailBrowsePage = *BrowsePage;
30 *BrowsePage = *NewPageTrailBrowsePage;
32 sub NewPageTrailBrowsePage {
33 my ($id, @rest) = @_;
34 UpdatePageTrail($id);
35 OldPageTrailBrowsePage($id, @rest);
38 sub UpdatePageTrail {
39 my $id = shift;
40 my @trail = ($id);
41 foreach my $page (split(/ /, GetParam('trail', ''))) {
42 push(@trail, $page) unless $page eq $id;
44 @trail = @trail[0..$PageTrailLength-1] if $trail[$PageTrailLength];
45 $q->param('trail', join(' ', @trail));
46 @PageTrail = @trail;
49 *OldPageTrailGetGotoBar = *GetGotoBar;
50 *GetGotoBar = *NewPageTrailGetGotoBar;
52 sub NewPageTrailGetGotoBar {
53 my $bar = OldPageTrailGetGotoBar(@_);
54 $bar .= $q->span({-class=>'trail'}, $q->br(), T('Trail: '),
55 map { GetPageLink($_) } reverse(@PageTrail))
56 if @PageTrail;
57 return $bar;