Merging latest features from stable
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 14 Nov 2003 09:13:23 +0000 (09:13 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 14 Nov 2003 09:13:23 +0000 (09:13 +0000)
includes/DefaultSettings.php
includes/SpecialContributions.php
includes/User.php

index 0c7f1d9..27e63d6 100644 (file)
@@ -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
 
index d25a0ac..32b8453 100644 (file)
@@ -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( "<ul>\n" );
-       while ( $limit ) {
+       for( $n = 0; $n < $offlimit; $n++ ) {
                if ( 0 == $nCur && 0 == $nOld ) { break; }
 
                if ( ( 0 == $nOld ) ||
@@ -100,9 +101,8 @@ function wfSpecialContributions( $par = "" )
                        $topmark = false;
                        --$nOld;
                }
-               ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment );
-
-               --$limit;
+               if( $n >= $offset )
+                       ucListEdit( $sk, $ns, $t, $ts, $topmark, $comment );
        }
        $wgOut->addHTML( "</ul>\n" );
 }
index ea9c0d5..714f45f 100644 (file)
@@ -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;
        }