r20488 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r20487‎ | r20488 | r20489 >
Date:14:35, 15 March 2007
Author:aaron
Status:old
Tags:
Comment:
*Add some IPv6 ranges (64,80,96,112)
Modified paths:
  • /trunk/phase3/includes/SpecialContributions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialContributions.php
@@ -71,12 +71,32 @@
7272 if ( $this->username == 'newbies' ) {
7373 $max = $this->dbr->selectField( 'user', 'max(user_id)', false, 'make_sql' );
7474 $condition = 'rev_user >' . (int)($max - $max / 100);
75 - } else if ( preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/(24|16)/", $this->username) ) {
 75+ } else if ( IP::isIPv4( $this->username ) && preg_match("/\/(24|16)$/", $this->username, $matches) ) {
7676 $abcd = explode( ".", $this->username );
77 - if( substr( $this->username, -2 ) == 24 ) $ipmask = $abcd[0] . '.' . $abcd[1] . '.' . $abcd[2] . '.%';
 77+ if( $matches[1] == 24 ) $ipmask = $abcd[0] . '.' . $abcd[1] . '.' . $abcd[2] . '.%';
7878 else $ipmask=$abcd[0] . '.' . $abcd[1] . '.%';
7979 $condition = 'rev_user_text LIKE ' . $this->dbr->addQuotes($ipmask);
80 - } else if ( IP::isIPv6( $this->username ) ) {
 80+ } else if ( IP::isIPv6( $this->username ) && preg_match("/^(64|80|96|112)$/", $this->username) ) {
 81+ $abcdefgh = explode( ":", IP::sanitizeIP($this->username) );
 82+ $abcd = implode( ":", array_slice($abcdefgh, 0, 4) );
 83+ switch( $matches[1] ) {
 84+ case '112':
 85+ $ipmask = $abcd . ':' . $abcd[4] . ':' . $abcd[5] . ':' . $abcd[6] . ':%';
 86+ break;
 87+ case '96':
 88+ $ipmask = $abcd . ':' . $abcd[4] . ':' . $abcd[5] . ':%';
 89+ break;
 90+ case '80':
 91+ $ipmask = $abcd . ':' . $abcd[4] . ':%';
 92+ break;
 93+ case '64':
 94+ $ipmask = $abcd . ':%';
 95+ break;
 96+ }
 97+ $condition = 'rev_user_text LIKE ' . $this->dbr->addQuotes($ipmask);
 98+ }
 99+
 100+ else if ( IP::isIPv6( $this->username ) ) {
81101 # All stored IPs should be sanitized from now on, check for exact matches for reverse compatibility
82102 $condition = '(rev_user_text=' . $this->dbr->addQuotes(IP::sanitizeIP($this->username)) . ' OR rev_user_text=' . $this->dbr->addQuotes($this->username) . ')';
83103 }