From 07ab99c6984cac0eb5b80b691df50d41ffa6c665 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 14 Nov 2003 09:13:23 +0000 Subject: [PATCH] Merging latest features from stable --- includes/DefaultSettings.php | 9 +++++++++ includes/SpecialContributions.php | 16 ++++++++-------- includes/User.php | 30 +++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 0c7f1d9bb2..27e63d6267 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -92,6 +92,15 @@ $wgSysopUserBans = false; # Allow sysops to ban logged-in users $wgIPBlockExpiration = 86400; # IP blocks expire after this many seconds, 0=infinite $wgUserBlockExpiration = 0; # As above, but for logged-in users +# User agent/range blocking +# Blocks all users using a particular user agent, possibly restricted to a +# set of IP ranges. Note: you can't block all user agents by leaving +# $wgBadUserAgents blank. That would block nothing. +$wgBadRanges = false; # e.g. array(array("1.2.3.0", "1.2.3.255")) +$wgBadUserAgents = false; # e.g. array("OfflineExplorer/1.0") +$wgRangeBlockUser = 0; # The block is attributed to this user ID +$wgRangeBlockReason = ""; # This reason is given (should be in wfMsg, obviously) + # Client-side caching: $wgCachePages = true; # Allow client-side caching of pages diff --git a/includes/SpecialContributions.php b/includes/SpecialContributions.php index d25a0ac037..32b8453ab3 100644 --- a/includes/SpecialContributions.php +++ b/includes/SpecialContributions.php @@ -16,6 +16,7 @@ function wfSpecialContributions( $par = "" ) return; } list( $limit, $offset ) = wfCheckLimits( 50, "" ); + $offlimit = $limit + $offset; $nt = Title::newFromURL( $target ); $nt->setNamespace( Namespace::getUser() ); @@ -48,20 +49,20 @@ function wfSpecialContributions( $par = "" ) if ( 0 == $id ) { $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment FROM cur " . "WHERE cur_user_text='" . wfStrencode( $nt->getText() ) . "' {$cmq} " . - "ORDER BY inverse_timestamp LIMIT {$offset}, {$limit}"; + "ORDER BY inverse_timestamp LIMIT {$offlimit}"; $res1 = wfQuery( $sql, DB_READ, $fname ); $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment FROM old " . "WHERE old_user_text='" . wfStrencode( $nt->getText() ) . "' {$omq} " . - "ORDER BY inverse_timestamp LIMIT {$offset}, {$limit}"; + "ORDER BY inverse_timestamp LIMIT {$offlimit}"; $res2 = wfQuery( $sql, DB_READ, $fname ); } else { $sql = "SELECT cur_namespace,cur_title,cur_timestamp,cur_comment FROM cur " . - "WHERE cur_user={$id} {$cmq} ORDER BY inverse_timestamp LIMIT {$offset}, {$limit}"; + "WHERE cur_user={$id} {$cmq} ORDER BY inverse_timestamp LIMIT {$offlimit}"; $res1 = wfQuery( $sql, DB_READ, $fname ); $sql = "SELECT old_namespace,old_title,old_timestamp,old_comment FROM old " . - "WHERE old_user={$id} {$omq} ORDER BY inverse_timestamp LIMIT {$offset}, {$limit}"; + "WHERE old_user={$id} {$omq} ORDER BY inverse_timestamp LIMIT {$offlimit}"; $res2 = wfQuery( $sql, DB_READ, $fname ); } $nCur = wfNumRows( $res1 ); @@ -76,7 +77,7 @@ function wfSpecialContributions( $par = "" ) if ( 0 != $nOld ) { $obj2 = wfFetchObject( $res2 ); } $wgOut->addHTML( "\n" ); } diff --git a/includes/User.php b/includes/User.php index ea9c0d58c8..714f45fad6 100644 --- a/includes/User.php +++ b/includes/User.php @@ -94,7 +94,35 @@ class User { /* private */ function getBlockedStatus() { + global $wgBadRanges, $wgBadUserAgents, $wgRangeBlockUser, $wgRangeBlockReason; + if ( -1 != $this->mBlockedby ) { return; } + + # Range/user-agent blocking + + $fBlock = false; # Mmmm, Hungarian + if ( ( !is_array( $wgBadUserAgents ) || + array_key_exists( getenv( "HTTP_USER_AGENT" ), $wgBadUserAgents ) ) && + is_array( $wgBadRanges ) ) + { + $iIp = ip2long( getenv( "REMOTE_ADDR" ) ); + foreach ( $wgBadRanges as $range ) { + $start = ip2long( $range[0] ); + $end = ip2long( $range[1] ); + if ( $iIp >= $start && $iIp <= $end ) { + $fBlock = true; + break; + } + } + } + + if ( $fBlock ) { + $this->mBlockedby = $wgRangeBlockUser; + $this->mBlockReason = $wgRangeBlockReason; + return; + } + + # User/IP blocking $block = new Block(); if ( !$block->load( getenv( "REMOTE_ADDR" ), $this->mId ) ) { @@ -102,7 +130,7 @@ class User { $this->mBlockedby = 0; return; } - + $this->mBlockedby = $block->mBy; $this->mBlockreason = $block->mReason; } -- 2.20.1