2006-12-23 02:07:11 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
package IkiWiki::Plugin::mirrorlist;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2006-12-23 02:07:11 +01:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-07-26 00:05:55 +02:00
|
|
|
hook(type => "getsetup", id => "mirrorlist", call => \&getsetup);
|
2006-12-23 02:07:11 +01:00
|
|
|
hook(type => "pagetemplate", id => "mirrorlist", call => \&pagetemplate);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-12-23 02:07:11 +01:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup () {
|
2008-07-26 00:05:55 +02:00
|
|
|
return
|
2008-08-03 22:40:12 +02:00
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => 1,
|
2010-02-12 10:22:15 +01:00
|
|
|
section => "web",
|
2008-08-03 22:40:12 +02:00
|
|
|
},
|
2008-07-26 00:05:55 +02:00
|
|
|
mirrorlist => {
|
|
|
|
type => "string",
|
2008-07-27 03:07:15 +02:00
|
|
|
example => {},
|
2008-07-26 00:05:55 +02:00
|
|
|
description => "list of mirrors",
|
|
|
|
safe => 1,
|
|
|
|
rebuild => 1,
|
|
|
|
},
|
2010-12-20 15:21:49 +01:00
|
|
|
mirrorlist_use_cgi => {
|
|
|
|
type => 'boolean',
|
|
|
|
example => 1,
|
|
|
|
description => "generate links that point to the mirrors' ikiwiki CGI",
|
|
|
|
safe => 1,
|
|
|
|
rebuild => 1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
sub checkconfig () {
|
|
|
|
if (! defined $config{mirrorlist_use_cgi}) {
|
|
|
|
$config{mirrorlist_use_cgi}=0;
|
|
|
|
}
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-07-26 00:05:55 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub pagetemplate (@) {
|
2006-12-23 02:07:11 +01:00
|
|
|
my %params=@_;
|
|
|
|
my $template=$params{template};
|
|
|
|
|
2009-10-02 18:37:53 +02:00
|
|
|
if ($template->query(name => "extrafooter") &&
|
|
|
|
keys %{$config{mirrorlist}} > 0) {
|
2008-08-27 00:04:45 +02:00
|
|
|
my $value=$template->param("extrafooter");
|
|
|
|
$value.=mirrorlist($params{page});
|
|
|
|
$template->param(extrafooter => $value);
|
|
|
|
}
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-12-23 02:07:11 +01:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub mirrorlist ($) {
|
2006-12-23 02:07:11 +01:00
|
|
|
my $page=shift;
|
2010-05-02 20:41:20 +02:00
|
|
|
return ($config{html5} ? '<nav id="mirrorlist">' : '<div>').
|
2006-12-29 05:38:40 +01:00
|
|
|
(keys %{$config{mirrorlist}} > 1 ? gettext("Mirrors") : gettext("Mirror")).
|
2006-12-23 02:07:11 +01:00
|
|
|
": ".
|
|
|
|
join(", ",
|
|
|
|
map {
|
|
|
|
qq{<a href="}.
|
2010-12-20 15:21:49 +01:00
|
|
|
( $config{mirrorlist_use_cgi} ?
|
|
|
|
$config{mirrorlist}->{$_}."?do=goto&page=$page" :
|
|
|
|
$config{mirrorlist}->{$_}."/".urlto($page, "") ).
|
2006-12-23 02:07:11 +01:00
|
|
|
qq{">$_</a>}
|
|
|
|
} keys %{$config{mirrorlist}}
|
|
|
|
).
|
2010-05-02 20:41:20 +02:00
|
|
|
($config{html5} ? '</nav>' : '</div>');
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-12-23 02:07:11 +01:00
|
|
|
|
|
|
|
1
|