archive.pl 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (C) 2007 Alex Schroeder <alex@emacswiki.org>
  2. #
  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 3 of the License, or
  6. # (at your option) any later version.
  7. #
  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.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. AddModuleDescription('archive.pl', 'Archive Extension');
  18. our ($q);
  19. *OldArchiveGetHeader = \&GetHeader;
  20. *GetHeader = \&NewArchiveGetHeader;
  21. # this assumes that *all* calls to GetHeader will print!
  22. sub NewArchiveGetHeader {
  23. my ($id) = @_;
  24. print OldArchiveGetHeader(@_);
  25. my %dates = ();
  26. for (AllPagesList()) {
  27. $dates{$1}++ if /^(\d\d\d\d-\d\d)-\d\d/;
  28. }
  29. print $q->div({-class=>'archive'},
  30. $q->p($q->span(T('Archive:')),
  31. map {
  32. my $key = $_;
  33. my ($year, $month) = split(/-/, $key);
  34. if (defined(&month_name)) {
  35. ScriptLink('action=collect;match=' . UrlEncode("^$year-$month"),
  36. month_name($month) . " $year ($dates{$key})");
  37. } else {
  38. ScriptLink('action=index;match=' . UrlEncode("^$year-$month"),
  39. "$year-$month ($dates{$key})");
  40. }
  41. } sort { $b <=> $a } keys %dates));
  42. return '';
  43. }