Merge SimpleAntiSpam extension into core
authorKunal Mehta <legoktm@gmail.com>
Thu, 17 Oct 2013 06:48:48 +0000 (23:48 -0700)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 24 Oct 2013 18:56:11 +0000 (20:56 +0200)
Adds an empty, hidden input field to the edit interface, and will
reject any edit if that field is filled in. This will protect
against the simplest form of spambots.

Localized messages will be imported separately.

Bug: 52063
Change-Id: I185b6a1e232299f496244a23f4bf0dc6ea22b6c9

RELEASE-NOTES-1.22
includes/EditPage.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc

index d6a75ba..091a04a 100644 (file)
@@ -256,6 +256,9 @@ production.
 * Added a hook, SpecialWatchlistGetNonRevisionTypes, to allow extensions
   with custom recentchanges entries to hook into the Watchlist without 
   clobbering each other.
+* A hidden, empty input field was added to the edit form, and any edit that fills
+  it in will be rejected. This prevents against the simplest form of spambots.
+  Previously in the "SimpleAntiSpam" extension by Ryan Schmidt.
 
 === Bug fixes in 1.22 ===
 * Disable Special:PasswordReset when $wgEnableEmail is false. Previously one
index d7b2b5e..530e267 100644 (file)
@@ -1381,6 +1381,24 @@ class EditPage {
                        return $status;
                }
 
+               $spam = $wgRequest->getText( 'wpAntispam' );
+               if ( $spam !== '' ) {
+                       wfDebugLog(
+                               'SimpleAntiSpam',
+                               $wgUser->getName() .
+                               ' editing "' .
+                               $this->mTitle->getPrefixedText() .
+                               '" submitted bogus field "' .
+                               $spam .
+                               '"'
+                       );
+                       $status->fatal( 'spamprotectionmatch', false );
+                       $status->value = self::AS_SPAM_ERROR;
+                       wfProfileOut( __METHOD__ . '-checks' );
+                       wfProfileOut( __METHOD__ );
+                       return $status;
+               }
+
                try {
                        # Construct Content object
                        $textbox_content = $this->toEditContent( $this->textbox1 );
@@ -2190,6 +2208,14 @@ class EditPage {
                        call_user_func_array( $formCallback, array( &$wgOut ) );
                }
 
+               // Add an empty field to trip up spambots
+               $wgOut->addHTML(
+                       Xml::openElement( 'div', array( 'id' => 'antispam-container', 'style' => 'display: none;' ) )
+                       . Html::rawElement( 'label', array( 'for' => 'wpAntiSpam' ), wfMessage( 'simpleantispam-label' )->parse() )
+                       . Xml::element( 'input', array( 'type' => 'text', 'name' => 'wpAntispam', 'id' => 'wpAntispam', 'value' => '' ) )
+                       . Xml::closeElement( 'div' )
+               );
+
                wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
 
                // Put these up at the top to ensure they aren't lost on early form submission
index 2cefeb8..0c1b560 100644 (file)
@@ -3851,6 +3851,8 @@ This is probably caused by a link to a blacklisted external site.',
 'spam_reverting'      => 'Reverting to last revision not containing links to $1',
 'spam_blanking'       => 'All revisions contained links to $1, blanking',
 'spam_deleting'       => 'All revisions contained links to $1, deleting',
+'simpleantispam-label' => "Anti-spam check.
+Do '''NOT''' fill this in!",
 
 # Info page
 'pageinfo-header'                 => '-', # do not translate or duplicate this message to other languages
index a94b6d5..a4fc922 100644 (file)
@@ -2776,6 +2776,7 @@ $wgMessageStructure = array(
                'spam_reverting',
                'spam_blanking',
                'spam_deleting',
+               'simpleantispam-label',
        ),
        'info' => array(
                'pageinfo-header',