]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/mirrorlist.pm
Merge commit 'upstream/master' into prv/po
[git.ikiwiki.info.git] / IkiWiki / Plugin / mirrorlist.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::mirrorlist;
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
8 sub import {
9         hook(type => "getsetup", id => "mirrorlist", call => \&getsetup);
10         hook(type => "pagetemplate", id => "mirrorlist", call => \&pagetemplate);
11 }
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 }
28 sub pagetemplate (@) {
29         my %params=@_;
30         my $template=$params{template};
31         
32         if ($template->query(name => "extrafooter")) {
33                 my $value=$template->param("extrafooter");
34                 $value.=mirrorlist($params{page});
35                 $template->param(extrafooter => $value);
36         }
37 }
39 sub mirrorlist ($) {
40         my $page=shift;
41         return "<p>".
42                 (keys %{$config{mirrorlist}} > 1 ? gettext("Mirrors") : gettext("Mirror")).
43                 ": ".
44                 join(", ",
45                         map { 
46                                 qq{<a href="}.
47                                 $config{mirrorlist}->{$_}."/".urlto($page, "").
48                                 qq{">$_</a>}
49                         } keys %{$config{mirrorlist}}
50                 ).
51                 "</p>";
52 }
54 1