summaryrefslogtreecommitdiff
path: root/IkiWiki/UserInfo.pm
blob: 9a165dad17be8ae59049026f47a0fd2cb3a8ac34 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Storable;
  5. package IkiWiki;
  6. sub userinfo_retrieve () { #{{{
  7. my $userinfo=eval{ Storable::lock_retrieve("$config{wikistatedir}/userdb") };
  8. return $userinfo;
  9. } #}}}
  10. sub userinfo_store ($) { #{{{
  11. my $userinfo=shift;
  12. my $oldmask=umask(077);
  13. my $ret=Storable::lock_store($userinfo, "$config{wikistatedir}/userdb");
  14. umask($oldmask);
  15. return $ret;
  16. } #}}}
  17. sub userinfo_get ($$) { #{{{
  18. my $user=shift;
  19. my $field=shift;
  20. my $userinfo=userinfo_retrieve();
  21. if (! defined $userinfo ||
  22. ! exists $userinfo->{$user} || ! ref $userinfo->{$user} ||
  23. ! exists $userinfo->{$user}->{$field}) {
  24. return "";
  25. }
  26. return $userinfo->{$user}->{$field};
  27. } #}}}
  28. sub userinfo_set ($$$) { #{{{
  29. my $user=shift;
  30. my $field=shift;
  31. my $value=shift;
  32. my $userinfo=userinfo_retrieve();
  33. if (! defined $userinfo ||
  34. ! exists $userinfo->{$user} || ! ref $userinfo->{$user}) {
  35. return "";
  36. }
  37. $userinfo->{$user}->{$field}=$value;
  38. return userinfo_store($userinfo);
  39. } #}}}
  40. sub userinfo_setall ($$) { #{{{
  41. my $user=shift;
  42. my $info=shift;
  43. my $userinfo=userinfo_retrieve();
  44. if (! defined $userinfo) {
  45. $userinfo={};
  46. }
  47. $userinfo->{$user}=$info;
  48. return userinfo_store($userinfo);
  49. } #}}}
  50. sub is_admin ($) { #{{{
  51. my $user_name=shift;
  52. return grep { $_ eq $user_name } @{$config{adminuser}};
  53. } #}}}
  54. sub commit_notify_list ($@) { #{{{
  55. my $committer=shift;
  56. my @pages;
  57. foreach my $file (@_) {
  58. push @pages, grep { $pagesources{$_} eq $file } keys %pagesources;
  59. }
  60. my @ret;
  61. my $userinfo=userinfo_retrieve();
  62. foreach my $user (keys %{$userinfo}) {
  63. next if $user eq $committer;
  64. if (exists $userinfo->{$user}->{subscriptions} &&
  65. length $userinfo->{$user}->{subscriptions} &&
  66. exists $userinfo->{$user}->{email} &&
  67. length $userinfo->{$user}->{email} &&
  68. grep { globlist_match($_, $userinfo->{$user}->{subscriptions}) } @pages) {
  69. push @ret, $userinfo->{$user}->{email};
  70. }
  71. }
  72. return @ret;
  73. } #}}}
  74. 1