Merge branch 'tova' into autoconfig
[ikiwiki.git] / IkiWiki / Plugin / mirrorlist.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::mirrorlist;
3
4 use warnings;
5 use strict;
6 use IkiWiki 2.00;
7
8 sub import { #{{{
9         hook(type => "getsetup", id => "mirrorlist", call => \&getsetup);
10         hook(type => "pagetemplate", id => "mirrorlist", call => \&pagetemplate);
11 } # }}}
12
13 sub getsetup () { #{{{
14         return
15                 mirrorlist => {
16                         type => "string",
17                         example => {},
18                         description => "list of mirrors",
19                         safe => 1,
20                         rebuild => 1,
21                 },
22 } #}}}
23
24 sub pagetemplate (@) { #{{{
25         my %params=@_;
26         my $template=$params{template};
27         
28         $template->param(extrafooter => mirrorlist($params{page}))
29                 if $template->query(name => "extrafooter");
30 } # }}}
31
32 sub mirrorlist ($) { #{{{
33         my $page=shift;
34         return "<p>".
35                 (keys %{$config{mirrorlist}} > 1 ? gettext("Mirrors") : gettext("Mirror")).
36                 ": ".
37                 join(", ",
38                         map { 
39                                 qq{<a href="}.
40                                 $config{mirrorlist}->{$_}."/".urlto($page, "").
41                                 qq{">$_</a>}
42                         } keys %{$config{mirrorlist}}
43                 ).
44                 "</p>";
45 } # }}}
46
47 1