Page MenuHomePhabricator

SpamBlacklist_body.php.diff

Authored By
bzimport
Nov 21 2014, 9:16 PM
Size
1 KB
Referenced Files
None
Subscribers
None

SpamBlacklist_body.php.diff

--- SpamBlacklist_body.php (revision 14772)
+++ SpamBlacklist_body.php (working copy)
@@ -96,8 +96,8 @@
}
}
- # Strip comments and whitespace, then remove blanks
- $lines = array_filter( array_map( 'trim', preg_replace( '/#.*$/', '', $lines ) ) );
+ # Filter limited entries, strip comments and whitespace, then remove blanks
+ $lines = array_filter( array_map( 'trim', preg_replace( '/#.*$/', '', array_filter ( $lines, array ( $this, 'checkLimitedEntry' ) ) ) ) );
# No lines, don't make a regex which will match everything
if ( count( $lines ) == 0 ) {
@@ -207,6 +207,30 @@
}
return $text;
}
+
+ # tests whether an entry is a global one, or a limited entry relevant for this site
+ # limited entries are marked with a comment beginning with an exclamation mark:
+ # format:
+ # filteringregexp #!* siteregexp # optional comment
+ # where:
+ # filteringregexp is the spam filtering regular expression
+ # * is either + or -, meaning:
+ # +: this filter is applied ONLY to sites matching siteregexp
+ # -: this filter is applied to all sites EXCEPT those matching siteregexp
+ # siteregexp is a regular expression matched against $wgServerName
+ # examples:
+ # spammer1\.example\.org #!+ wikipedia.org$ # this spammer is blacklisted only on *.wikipedia.org
+ # spammer2\.example\.org #!- ^cs.wikipedia.org$ # this spammer is blacklisted everywhere except cs.wikipedia.org
+ function checkLimitedEntry( $entry ) {
+ global $wgServerName;
+
+ if ( !preg_match( '/#!([+-])\s*([^#\s]*)\s*(#.*)?$/', $entry, $matches ) ) {
+ return true;
+ }
+ $excludeThis = $matches[1] == '-';
+
+ return preg_match( '/' . $matches[2] . '/', $wgServerName ) xor $excludeThis;
+ }
}

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2488
Default Alt Text
SpamBlacklist_body.php.diff (1 KB)

Event Timeline