10 sub userinfo_retrieve () { #{{{
11 my $userinfo=eval{ Storable::lock_retrieve("$config{wikistatedir}/userdb") };
15 sub userinfo_store ($) { #{{{
18 my $newfile="$config{wikistatedir}/userdb.new";
19 my $oldmask=umask(077);
20 my $ret=Storable::lock_store($userinfo, $newfile);
22 if (defined $ret && $ret) {
23 if (! rename($newfile, "$config{wikistatedir}/userdb")) {
31 sub userinfo_get ($$) { #{{{
35 my $userinfo=userinfo_retrieve();
36 if (! defined $userinfo ||
37 ! exists $userinfo->{$user} || ! ref $userinfo->{$user} ||
38 ! exists $userinfo->{$user}->{$field}) {
41 return $userinfo->{$user}->{$field};
44 sub userinfo_set ($$$) { #{{{
49 my $userinfo=userinfo_retrieve();
50 if (! defined $userinfo ||
51 ! exists $userinfo->{$user} || ! ref $userinfo->{$user}) {
55 $userinfo->{$user}->{$field}=$value;
56 return userinfo_store($userinfo);
59 sub userinfo_setall ($$) { #{{{
63 my $userinfo=userinfo_retrieve();
64 if (! defined $userinfo) {
67 $userinfo->{$user}=$info;
68 return userinfo_store($userinfo);
71 sub is_admin ($) { #{{{
74 return grep { $_ eq $user_name } @{$config{adminuser}};
77 sub get_banned_users () { #{{{
79 my $userinfo=userinfo_retrieve();
80 foreach my $user (keys %{$userinfo}) {
81 push @ret, $user if $userinfo->{$user}->{banned};
86 sub set_banned_users (@) { #{{{
87 my %banned=map { $_ => 1 } @_;
88 my $userinfo=userinfo_retrieve();
89 foreach my $user (keys %{$userinfo}) {
90 $userinfo->{$user}->{banned} = $banned{$user};
92 return userinfo_store($userinfo);
95 sub commit_notify_list ($@) { #{{{
97 my @pages = map pagename($_), @_;
100 my $userinfo=userinfo_retrieve();
101 foreach my $user (keys %{$userinfo}) {
102 next if $user eq $committer;
103 if (exists $userinfo->{$user}->{subscriptions} &&
104 length $userinfo->{$user}->{subscriptions} &&
105 exists $userinfo->{$user}->{email} &&
106 length $userinfo->{$user}->{email} &&
107 grep { pagespec_match($_,
108 $userinfo->{$user}->{subscriptions},
109 user => $committer) }
110 map pagename($_), @_) {
111 push @ret, $userinfo->{$user}->{email};
117 sub send_commit_mails ($$$@) { #{{{
118 my $messagesub=shift;
121 my @changed_pages=@_;
123 return unless @changed_pages;
125 my @email_recipients=commit_notify_list($user, @changed_pages);
126 if (@email_recipients) {
127 # TODO: if a commit spans multiple pages, this will send
128 # subscribers a diff that might contain pages they did not
129 # sign up for. Should separate the diff per page and
130 # reassemble into one mail with just the pages subscribed to.
131 my $diff=$diffsub->();
132 my $message=$messagesub->();
135 if (@changed_pages > 2) {
136 $pagelist="$changed_pages[0] $changed_pages[1] ...";
139 $pagelist.=join(" ", @changed_pages);
141 #translators: The three variables are the name of the wiki,
142 #translators: A list of one or more pages that were changed,
143 #translators: And the name of the user making the change.
144 #translators: This is used as the subject of a commit email.
145 my $subject=sprintf(gettext("update of %s's %s by %s"),
146 $config{wikiname}, $pagelist, $user);
148 my $template=template("notifymail.tmpl");
150 wikiname => $config{wikiname},
156 # Daemonize, in case the mail sending takes a while.
157 defined(my $pid = fork) or error("Can't fork: $!");
159 setsid() or error("Can't start a new session: $!");
161 open STDIN, '/dev/null';
162 open STDOUT, '>/dev/null';
163 open STDERR, '>&STDOUT' or error("Can't dup stdout: $!");
165 unlockwiki(); # don't need to keep a lock on the wiki
167 eval q{use Mail::Sendmail};
169 foreach my $email (@email_recipients) {
172 From => "$config{wikiname} <$config{adminemail}>",
174 Message => $template->output,
178 exit 0; # daemon process done