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