Merge branch 'master' of ssh://git.ikiwiki.info/srv/git/ikiwiki.info
[ikiwiki] / IkiWiki / Plugin / mirrorlist.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::mirrorlist;
3
4 use warnings;
5 use strict;
6 use IkiWiki 3.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                 plugin => {
16                         safe => 1,
17                         rebuild => 1,
18                 },
19                 mirrorlist => {
20                         type => "string",
21                         example => {},
22                         description => "list of mirrors",
23                         safe => 1,
24                         rebuild => 1,
25                 },
26 }
27
28 sub pagetemplate (@) {
29         my %params=@_;
30         my $template=$params{template};
31         
32         if ($template->query(name => "extrafooter") &&
33             keys %{$config{mirrorlist}} > 0) {
34                 my $value=$template->param("extrafooter");
35                 $value.=mirrorlist($params{page});
36                 $template->param(extrafooter => $value);
37         }
38 }
39
40 sub mirrorlist ($) {
41         my $page=shift;
42         return "<p>".
43                 (keys %{$config{mirrorlist}} > 1 ? gettext("Mirrors") : gettext("Mirror")).
44                 ": ".
45                 join(", ",
46                         map { 
47                                 qq{<a href="}.
48                                 $config{mirrorlist}->{$_}."/".urlto($page, "").
49                                 qq{">$_</a>}
50                         } keys %{$config{mirrorlist}}
51                 ).
52                 "</p>";
53 }
54
55 1