new anti-bot code
authorTim Starling <tstarling@users.mediawiki.org>
Mon, 21 Jun 2004 07:41:53 +0000 (07:41 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Mon, 21 Jun 2004 07:41:53 +0000 (07:41 +0000)
includes/DefaultSettings.php
includes/EditPage.php
includes/User.php

index 1e0e635..7a2dbb0 100644 (file)
@@ -181,6 +181,7 @@ $wgProxyPorts = array( 80, 81, 1080, 3128, 6588, 8000, 8080, 8888, 65506 );
 $wgProxyScriptPath = "$IP/proxy_check.php";
 $wgProxyMemcExpiry = 86400;
 $wgProxyKey = 'W1svekXc5u6lZllTZOwnzEk1nbs';
+$wgProxyList = array();  # big list of banned IP addresses, in the keys not the values
 
 # Client-side caching:
 $wgCachePages       = true; # Allow client-side caching of pages
@@ -371,6 +372,8 @@ $wgMaxCredits = 0;
 # Text matching this regular expression will be recognised as spam
 # See http://en.wikipedia.org/wiki/Regular_expression
 $wgSpamRegex = false; 
+# Similarly if this function returns true
+$wgFilterCallback = false;
 
 # Go button goes straight to the edit screen if the article doesn't exist
 $wgGoToEdit = false;
index 21dae85..2d779ac 100644 (file)
@@ -114,7 +114,7 @@ class EditPage {
                global $wgLang, $wgParser, $wgTitle;
                global $wgAllowAnonymousMinor;
                global $wgWhitelistEdit;
-               global $wgSpamRegex;
+               global $wgSpamRegex, $wgFilterCallback;
 
                $sk = $wgUser->getSkin();
                $isConflict = false;
@@ -137,13 +137,12 @@ class EditPage {
                if ( "save" == $formtype ) {
                        # Check for spam
                        if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1 ) ) {
-                                       if ( $wgUser->isSysop() ) {
-                                               $this->spamPage();
-                                       } else {
-                                               sleep(10);
-                                               $wgOut->redirect( $this->mTitle->getFullURL() );
-                                       }
-                                       return;
+                               $this->spamPage();
+                               return;
+                       }
+                       if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section ) ) {
+                               # Error messages or other handling should be performed by the filter function
+                               return;
                        }
                        if ( $wgUser->isBlocked() ) {
                                $this->blockedIPpage();
@@ -467,7 +466,11 @@ htmlspecialchars( $wgLang->recodeForEdit( $this->textbox1 ) ) .
                $reason = $wgUser->blockedFor();
                 $ip = $wgIP;
                
-                $name = User::whoIs( $id );
+               if ( is_string( $id ) ) {
+                       $name = $id;
+               } else {
+                       $name = User::whoIs( $id );
+               }
                $link = "[[" . $wgLang->getNsText( Namespace::getUser() ) .
                  ":{$name}|{$name}]]";
 
@@ -491,13 +494,12 @@ htmlspecialchars( $wgLang->recodeForEdit( $this->textbox1 ) ) .
 
        function spamPage()
        {
-               global $wgOut, $wgSpamRegex;
+               global $wgOut;
                $wgOut->setPageTitle( wfMsg( "spamprotectiontitle" ) );
                $wgOut->setRobotpolicy( "noindex,nofollow" );
                $wgOut->setArticleRelated( false );
 
                $wgOut->addWikiText( wfMsg( "spamprotectiontext" ) );
-               $wgOut->addWikiText( "<pre>".$wgSpamRegex."</pre>" );
                $wgOut->returnToMain( false );
        }
 
index 26fe182..467fc2a 100644 (file)
@@ -99,7 +99,7 @@ class User {
 
        /* private */ function getBlockedStatus()
        {
-               global $wgIP, $wgBlockCache;
+               global $wgIP, $wgBlockCache, $wgProxyList;
 
                if ( -1 != $this->mBlockedby ) { return; }
        
@@ -122,12 +122,20 @@ class User {
                                $this->mBlockreason = $block->mReason;
                        }
                }
+
+               # Proxy blocking
+               if ( !$this->mBlockedby ) {
+                       if ( array_key_exists( $wgIP, $wgProxyList ) ) {
+                               $this->mBlockreason = wfMsg( 'proxyblockreason' );
+                               $this->mBlockedby = "Proxy blocker";
+                       }
+               }
        }
 
        function isBlocked()
        {
                $this->getBlockedStatus();
-               if ( 0 == $this->mBlockedby ) { return false; }
+               if ( 0 === $this->mBlockedby ) { return false; }
                return true;
        }