10 sub userinfo_retrieve () { #{{{
11 my $userinfo=eval{ Storable::lock_retrieve("$config{wikistatedir}/userdb") };
15 sub userinfo_store ($) { #{{{
18 my $oldmask=umask(077);
19 my $ret=Storable::lock_store($userinfo, "$config{wikistatedir}/userdb");
24 sub userinfo_get ($$) { #{{{
28 my $userinfo=userinfo_retrieve();
29 if (! defined $userinfo ||
30 ! exists $userinfo->{$user} || ! ref $userinfo->{$user} ||
31 ! exists $userinfo->{$user}->{$field}) {
34 return $userinfo->{$user}->{$field};
37 sub userinfo_set ($$$) { #{{{
42 my $userinfo=userinfo_retrieve();
43 if (! defined $userinfo ||
44 ! exists $userinfo->{$user} || ! ref $userinfo->{$user}) {
48 $userinfo->{$user}->{$field}=$value;
49 return userinfo_store($userinfo);
52 sub userinfo_setall ($$) { #{{{
56 my $userinfo=userinfo_retrieve();
57 if (! defined $userinfo) {
60 $userinfo->{$user}=$info;
61 return userinfo_store($userinfo);
64 sub is_admin ($) { #{{{
67 return grep { $_ eq $user_name } @{$config{adminuser}};
70 sub get_banned_users () { #{{{
72 my $userinfo=userinfo_retrieve();
73 foreach my $user (keys %{$userinfo}) {
74 push @ret, $user if $userinfo->{$user}->{banned};
79 sub set_banned_users (@) { #{{{
80 my %banned=map { $_ => 1 } @_;
81 my $userinfo=userinfo_retrieve();
82 foreach my $user (keys %{$userinfo}) {
83 $userinfo->{$user}->{banned} = $banned{$user};
85 return userinfo_store($userinfo);
88 sub commit_notify_list ($@) { #{{{
92 foreach my $file (@_) {
93 push @pages, grep { $pagesources{$_} eq $file } keys %pagesources;
97 my $userinfo=userinfo_retrieve();
98 foreach my $user (keys %{$userinfo}) {
99 next if $user eq $committer;
100 if (exists $userinfo->{$user}->{subscriptions} &&
101 length $userinfo->{$user}->{subscriptions} &&
102 exists $userinfo->{$user}->{email} &&
103 length $userinfo->{$user}->{email} &&
104 grep { pagespec_match($_, $userinfo->{$user}->{subscriptions}, "") } @pages) {
105 push @ret, $userinfo->{$user}->{email};
111 sub send_commit_mails ($$$@) { #{{{
112 my $messagesub=shift;
115 my @changed_pages=@_;
117 return unless @changed_pages;
119 my @email_recipients=commit_notify_list($user, @changed_pages);
120 if (@email_recipients) {
121 # TODO: if a commit spans multiple pages, this will send
122 # subscribers a diff that might contain pages they did not
123 # sign up for. Should separate the diff per page and
124 # reassemble into one mail with just the pages subscribed to.
125 my $diff=$diffsub->();
126 my $message=$messagesub->();
129 if (@changed_pages > 2) {
130 $pagelist="$changed_pages[0] $changed_pages[1] ...";
133 $pagelist.=join(" ", @changed_pages);
135 #translators: The three variables are the name of the wiki,
136 #translators: A list of one or more pages that were changed,
137 #translators: And the name of the user making the change.
138 #translators: This is used as the subject of a commit email.
139 my $subject=sprintf(gettext("update of %s's %s by %s"),
140 $config{wikiname}, $pagelist, $user);
142 my $template=template("notifymail.tmpl");
144 wikiname => $config{wikiname},
150 # Daemonize, in case the mail sending takes a while.
151 defined(my $pid = fork) or error("Can't fork: $!");
153 setsid() or error("Can't start a new session: $!");
154 eval q{use POSIX 'setsid'};
156 open STDIN, '/dev/null';
157 open STDOUT, '>/dev/null';
158 open STDERR, '>&STDOUT' or error("Can't dup stdout: $!");
160 unlockwiki(); # don't need to keep a lock on the wiki
162 eval q{use Mail::Sendmail};
164 foreach my $email (@email_recipients) {
167 From => "$config{wikiname} <$config{adminemail}>",
169 Message => $template->output,
173 exit 0; # daemon process done