* $wgRestrictDisplayTitle controls if the use of the {{DISPLAYTITLE}} magic
word is restricted to titles equivalent to the actual page title. This
is true per default, but can be set to false to allow any title.
+* $wgSpamRegex may now be an array of multiple regular expressions.
=== New features in 1.14 ===
* Avoid recursive crazy expansions in section edit comments for pages which
contain '/*' in the title
* Fix excessive memory usage when parsing pages with lots of links
+* $wgSpamRegex now matches the edit summary and page move descriptions in
+ addition to body text.
+
=== API changes in 1.14 ===
$wgExportAllowListContributors = false ;
-/** Text matching this regular expression will be recognised as spam
- * See http://en.wikipedia.org/wiki/Regular_expression */
-$wgSpamRegex = false;
+/**
+ * Edits matching these regular expressions in body text or edit summary
+ * will be recognised as spam and rejected automatically.
+ *
+ * There's no administrator override on-wiki, so be careful what you set. :)
+ * May be an array of regexes or a single string for backwards compatibility.
+ *
+ * See http://en.wikipedia.org/wiki/Regular_expression
+ */
+$wgSpamRegex = array();
+
/** Similarly you can get a function to do the job. The function will be given
* the following args:
* - a Title object for the article the edit is made on
* @return one of the constants describing the result
*/
function internalAttemptSave( &$result, $bot = false ) {
- global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut, $wgParser;
+ global $wgFilterCallback, $wgUser, $wgOut, $wgParser;
global $wgMaxArticleSize;
$fname = 'EditPage::attemptSave';
$this->mMetaData = '' ;
# Check for spam
- $matches = array();
- if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1, $matches ) ) {
- $result['spam'] = $matches[0];
+ $match = self::matchSpamRegex( $this->summary );
+ if( $match === false ) {
+ $match = self::matchSpamRegex( $this->textbox1 );
+ }
+ if( $match !== false ) {
+ $result['spam'] = $match;
$ip = wfGetIP();
$pdbk = $this->mTitle->getPrefixedDBkey();
- $match = str_replace( "\n", '', $matches[0] );
+ $match = str_replace( "\n", '', $match );
wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
wfProfileOut( "$fname-checks" );
wfProfileOut( $fname );
wfProfileOut( $fname );
return self::AS_END;
}
+
+ /**
+ * Check given input text against $wgSpamRegex, and return the text of the first match.
+ * @return mixed -- matching string or false
+ */
+ public static function matchSpamRegex( $text ) {
+ global $wgSpamRegex;
+ if( $wgSpamRegex ) {
+ // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
+ $regexes = (array)$wgSpamRegex;
+ foreach( $regexes as $regex ) {
+ $matches = array();
+ if ( preg_match( $regex, $text, $matches ) ) {
+ return $matches[0];
+ }
+ }
+ }
+ return false;
+ }
/**
* Initialise form fields in the object
$nt->getUserPermissionsErrors('edit', $wgUser));
}
+ $match = EditPage::matchSpamRegex( $reason );
+ if( $match !== false ) {
+ // This is kind of lame, won't display nice
+ $errors[] = array('spamprotectiontext');
+ }
+
global $wgUser;
$err = null;
if( !wfRunHooks( 'AbortMove', array( $this, $nt, $wgUser, &$err, $reason ) ) ) {