aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/userlist.pm
blob: 2ebf6197884729d81188c27306348b964e25c30c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl
package IkiWiki::Plugin::userlist;

use warnings;
use strict;
use IkiWiki 3.00;

sub import {
	hook(type => "getsetup", id => "userlist", call => \&getsetup);
	hook(type => "sessioncgi", id => "userlist", call => \&sessioncgi);
	hook(type => "formbuilder_setup", id => "userlist",
		call => \&formbuilder_setup);
}

sub getsetup () {
        return
		plugin => {
			safe => 1,
			rebuild => 0,
			section => "web",
		},
}

sub sessioncgi ($$) {
	my $cgi=shift;
	my $session=shift;

	if ($cgi->param("do") eq "userlist") {
		showuserlist($cgi, $session);
		exit;
	}
}

sub formbuilder_setup (@) {
	my %params=@_;

	my $form=$params{form};
	if ($form->title eq "preferences" &&
	    IkiWiki::is_admin($params{session}->param("name"))) {
		push @{$params{buttons}}, "Users";
		if ($form->submitted && $form->submitted eq "Users") {
			showuserlist($params{cgi}, $params{session});
			exit;
		}
	}
}

sub showuserlist ($$) {
	my $q=shift;
	my $session=shift;

	IkiWiki::needsignin($q, $session);
	if (! defined $session->param("name") ||
	    ! IkiWiki::is_admin($session->param("name"))) {
		error(gettext("you are not logged in as an admin"));
	}

	my $h="<table border=\"1\">\n";
	$h.="<tr><th>".gettext("login")."</th><th>".gettext("email")."</th></tr>\n";
	my $info=IkiWiki::userinfo_retrieve();
	eval q{use HTML::Entities};
	if (ref $info) {
		foreach my $user (sort { $info->{$a}->{regdate} <=> $info->{$b}->{regdate} } keys %$info) {
			my %i=%{$info->{$user}};
			$h.="<tr><td>".encode_entities($user)."</td><td>".
				encode_entities(defined $i{email} ? $i{email} : "").
				"</td></tr>\n";
		}
	}
	$h.="</table>\n";

	IkiWiki::printheader($session);
	print IkiWiki::cgitemplate(undef, gettext("Users"), $h);
}

1