wiki.pl: Port some fixes from upstream
[Orgmuse.git] / modules / headlines.pl
blob33e534fd6943f99e98f1155b6f12174a0e3efbc1
1 # Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
2 # Copyright (C) 2005 Ingo Belka <grimmen@mvnet.de>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the
16 # Free Software Foundation, Inc.
17 # 59 Temple Place, Suite 330
18 # Boston, MA 02111-1307 USA
20 use vars qw($HeadlineNumber);
22 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/headlines.pl">headlines.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Headlines_Extension">Headlines Extension</a></p>';
24 push(@MyRules, \&HeadlinesRule);
26 # Include this page on every page:
28 $HeadlineNumber = 20;
30 sub HeadlinesRule {
31 if (m/\G(\&lt;headlines(:(\d+))?\&gt;)/gci) {
32 if (($3) and ($3>0)) {$HeadlineNumber = $3;};
33 Clean(CloseHtmlEnvironments());
34 Dirty($1);
35 HeadlinesPrint();
36 return AddHtmlEnvironment('p');
38 return undef;
41 sub HeadlinesPrint {
42 my @pages = (grep(/^\d\d\d\d-\d\d-\d\d_.+/, AllPagesList()));
43 @pages = sort {$b cmp $a} @pages;
44 @pages = @pages[0 .. $HeadlineNumber - 1] if $#pages >= $HeadlineNumber;
45 my $current_date;
46 if (@pages) {
47 print '<dl class="headlines">';
48 foreach my $page (@pages) {
49 if ($page =~ /^(\d\d\d\d-\d\d-\d\d)_(.+)/) {
50 my ($date, $title) = ($1, $2);
51 $title =~ s/_/ /g;
52 print '<dt class="headlinesdate">' . $date . '</dt>' unless $date eq $current_date;
53 $current_date = $date;
54 print '<dd>' . ScriptLink($page, $title, 'headlineslink') . '</dd>';
57 print '</dl>';