]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/mirrorlist.pm
(no commit message)
[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 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                         section => "web",
19                 },
20                 mirrorlist => {
21                         type => "string",
22                         example => {},
23                         description => "list of mirrors",
24                         safe => 1,
25                         rebuild => 1,
26                 },
27                 mirrorlist_use_cgi => {
28                         type => 'boolean',
29                         example => 1,
30                         description => "generate links that point to the mirrors' ikiwiki CGI",
31                         safe => 1,
32                         rebuild => 1,
33                 },
34 }
35
36 sub checkconfig () {
37         if (! defined $config{mirrorlist_use_cgi}) {
38                 $config{mirrorlist_use_cgi}=0;
39         }
40 }
41
42 sub pagetemplate (@) {
43         my %params=@_;
44         my $template=$params{template};
45         
46         if ($template->query(name => "extrafooter") &&
47             keys %{$config{mirrorlist}} > 0) {
48                 my $value=$template->param("extrafooter");
49                 $value.=mirrorlist($params{page});
50                 $template->param(extrafooter => $value);
51         }
52 }
53
54 sub mirrorlist ($) {
55         my $page=shift;
56         return ($config{html5} ? '<nav id="mirrorlist">' : '<div>').
57                 (keys %{$config{mirrorlist}} > 1 ? gettext("Mirrors") : gettext("Mirror")).
58                 ": ".
59                 join(", ",
60                         map { 
61                                 qq{<a href="}.
62                                 ( $config{mirrorlist_use_cgi} ?
63                                   $config{mirrorlist}->{$_}."?do=goto&page=$page" :
64                                   $config{mirrorlist}->{$_}."/".urlto($page, "") ).
65                                 qq{">$_</a>}
66                         } keys %{$config{mirrorlist}}
67                 ).
68                 ($config{html5} ? '</nav>' : '</div>');
69 }
70
71 1