1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- use strict;
- use v5.10;
- AddModuleDescription('banned-regexps.pl', 'Banning Regular Expressions');
- our (%AdminPages, %LockOnCreation, @MyInitVariables, %PlainTextPages, $BannedContent, $BannedFile,
- $FullUrlPattern);
- our ($BannedRegexps);
- $BannedRegexps = 'BannedRegexps';
- push(@MyInitVariables, sub {
- $AdminPages{$BannedRegexps} = 1;
- $LockOnCreation{$BannedRegexps} = 1;
- $PlainTextPages{$BannedRegexps} = 1;
- });
- *RegexpOldBannedContent = \&BannedContent;
- *BannedContent = \&RegexpNewBannedContent;
- sub RegexpNewBannedContent {
- my $str = shift;
-
- $str =~ s/$FullUrlPattern//g;
- my $rule = RegexpOldBannedContent($str, @_);
- if (not $rule) {
- foreach (split(/\n/, GetPageContent($BannedRegexps))) {
- next unless m/^\s*([^
- my ($regexp, $comment, $re) = ($1, $4, undef);
- eval { $re = qr/$regexp/i; };
- if (defined($re) && $str =~ $re) {
- my $group1 = $1;
- my $explanation = ($group1
- ? Tss('Regular expression "%1" matched "%2" on this page.', QuoteHtml($regexp), $group1)
- : Ts('Regular expression "%s" matched on this page.', QuoteHtml($regexp)));
- $rule = $explanation . ' '
- . ($comment ? Ts('Reason: %s.', $comment) : T('Reason unknown.')) . ' '
- . Ts('See %s for more information.', GetPageLink($BannedRegexps));
- last;
- }
- }
- }
- LogWrite($rule) if $rule and $BannedFile;
- return $rule if $rule;
- return 0;
- }
|