summaryrefslogtreecommitdiff
path: root/IkiWiki/UserInfo.pm
blob: ae63d80235af328a8197775fdde3f75ec8ba31e2 (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 get_banned_users () { #{{{
  56. my @ret;
  57. my $userinfo=userinfo_retrieve();
  58. foreach my $user (keys %{$userinfo}) {
  59. push @ret, $user if $userinfo->{$user}->{banned};
  60. }
  61. return @ret;
  62. } #}}}
  63. sub set_banned_users (@) { #{{{
  64. my %banned=map { $_ => 1 } @_;
  65. my $userinfo=userinfo_retrieve();
  66. foreach my $user (keys %{$userinfo}) {
  67. $userinfo->{$user}->{banned} = $banned{$user};
  68. }
  69. return userinfo_store($userinfo);
  70. } #}}}
  71. sub commit_notify_list ($@) { #{{{
  72. my $committer=shift;
  73. my @pages;
  74. foreach my $file (@_) {
  75. push @pages, grep { $pagesources{$_} eq $file } keys %pagesources;
  76. }
  77. my @ret;
  78. my $userinfo=userinfo_retrieve();
  79. foreach my $user (keys %{$userinfo}) {
  80. next if $user eq $committer;
  81. if (exists $userinfo->{$user}->{subscriptions} &&
  82. length $userinfo->{$user}->{subscriptions} &&
  83. exists $userinfo->{$user}->{email} &&
  84. length $userinfo->{$user}->{email} &&
  85. grep { pagespec_match($_, $userinfo->{$user}->{subscriptions}) } @pages) {
  86. push @ret, $userinfo->{$user}->{email};
  87. }
  88. }
  89. return @ret;
  90. } #}}}
  91. 1