subscriberc.pl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. AddModuleDescription('subscriberc.pl', 'Subscribed Recent Changes');
  18. our ($bol, @MyRules, $LinkPattern, $FreeLinkPattern);
  19. push(@MyRules, \&SubscribedRecentChangesRule);
  20. sub SubscribedRecentChangesRule {
  21. if ($bol) {
  22. if (m/\GMy\s+subscribed\s+pages:\s*((?:(?:$LinkPattern|\[\[$FreeLinkPattern\]\]),\s*)+)categories:\s*((?:(?:$LinkPattern|\[\[$FreeLinkPattern\]\]),\s*)*(?:$LinkPattern|\[\[$FreeLinkPattern\]\]))/cg) {
  23. return Subscribe($1, $4);
  24. } elsif (m/\GMy\s+subscribed\s+pages:\s*((?:(?:$LinkPattern|\[\[$FreeLinkPattern\]\]),\s*)*(?:$LinkPattern|\[\[$FreeLinkPattern\]\]))/cg) {
  25. return Subscribe($1, '');
  26. } elsif (m/\GMy\s+subscribed\s+categories:\s*((?:(?:$LinkPattern|\[\[$FreeLinkPattern\]\]),\s*)*(?:$LinkPattern|\[\[$FreeLinkPattern\]\]))/cg) {
  27. return Subscribe('', $1);
  28. }
  29. }
  30. return;
  31. }
  32. sub Subscribe {
  33. my ($pages, $categories) = @_;
  34. my $oldpos = pos;
  35. my @pageslist = map {
  36. if (/\[\[$FreeLinkPattern\]\]/) {
  37. FreeToNormal($1);
  38. } else {
  39. $_;
  40. }
  41. } split(/\s*,\s*/, $pages);
  42. my @catlist = map {
  43. if (/\[\[$FreeLinkPattern\]\]/) {
  44. FreeToNormal($1);
  45. } else {
  46. $_;
  47. }
  48. } split(/\s*,\s*/, $categories);
  49. my $regexp;
  50. $regexp .= '^(' . join('|', @pageslist) . ")\$" if @pageslist;
  51. $regexp .= '|' if @pageslist and @catlist;
  52. $regexp .= '(' . join('|', @catlist) . ')' if @catlist;
  53. pos = $oldpos;
  54. my $html = 'My subscribed ';
  55. return $html unless @pageslist or @catlist;
  56. $html .= 'pages: ' . join(', ', map { my $x = $_; $x =~ s/_/ /g; $x; } @pageslist)
  57. if @pageslist;
  58. $html .= ', ' if @pageslist and @catlist;
  59. $html .= 'categories: ' . join(', ', map { my $x = $_; $x =~ s/_/ /g; $x; } @catlist)
  60. if @catlist;
  61. return ScriptLink('action=rc;rcfilteronly=' . $regexp, $html);
  62. }