From 24d8a8e50b17dfcb96c1161501c1d7b6aa0627a0 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 21 Jun 2004 07:41:53 +0000 Subject: [PATCH] new anti-bot code --- includes/DefaultSettings.php | 3 +++ includes/EditPage.php | 24 +++++++++++++----------- includes/User.php | 12 ++++++++++-- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 1e0e635f71..7a2dbb0064 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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; diff --git a/includes/EditPage.php b/includes/EditPage.php index 21dae85cc9..2d779ac70e 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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( "
".$wgSpamRegex."
" ); $wgOut->returnToMain( false ); } diff --git a/includes/User.php b/includes/User.php index 26fe182871..467fc2a0c9 100644 --- a/includes/User.php +++ b/includes/User.php @@ -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; } -- 2.20.1