wiki.pl: Port some fixes from upstream
[Orgmuse.git] / modules / strange-spam.pl
blobdfcef5adb472b3b0b78e2bd3abf6e7968a92ab5d
1 # Copyright (C) 2006, 2007 Alex Schroeder <alex@emacswiki.org>
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 2 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the
15 # Free Software Foundation, Inc.
16 # 59 Temple Place, Suite 330
17 # Boston, MA 02111-1307 USA
19 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/strange-spam.pl">strange-spam.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/StrangeBannedContent">StrangeBannedContent</a></p>';
21 use vars qw($StrangeBannedContent);
23 $StrangeBannedContent = 'StrangeBannedContent';
25 *StrangeOldBannedContent = *BannedContent;
26 *BannedContent = *StrangeNewBannedContent;
27 $BannedContent = $StrangeOldBannedContent;
29 push(@MyInitVariables, \&StrangeBannedContentInit);
31 sub StrangeBannedContentInit {
32 $LockOnCreation{$StrangeBannedContent} = 1;
33 $AdminPages{$StrangeBannedContent} = 1;
34 $PlainTextPages{$StrangeBannedContent} = 1;
37 sub StrangeNewBannedContent {
38 my $str = shift;
39 my $rule = StrangeOldBannedContent($str, @_);
40 return $rule if $rule;
41 # changes here have effects on despam.pl!
42 foreach (split(/\n/, GetPageContent($StrangeBannedContent))) {
43 next unless m/^\s*([^#]+?)\s*(#\s*(\d\d\d\d-\d\d-\d\d\s*)?(.*))?$/;
44 my ($regexp, $comment) = ($1, $4);
45 if ($str =~ /($regexp)/ or $OpenPageName =~ /($regexp)/) {
46 my $match = $1;
47 $match =~ s/\n/ /g;
48 return Tss('Rule "%1" matched "%2" on this page.', QuoteHtml($regexp),
49 QuoteHtml($match)) . ' '
50 . ($comment
51 ? Ts('Reason: %s.', $comment)
52 : T('Reason unknown.')) . ' '
53 . Ts('See %s for more information.',
54 GetPageLink($StrangeBannedContent));
57 return 0;