MaxSem has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/394447 )

Change subject: WIP: IP ranges in prop=usercontribs
......................................................................

WIP: IP ranges in prop=usercontribs

Change-Id: I0a0c752e7430dbf97a29c8526af8c033d2c182fa
---
M includes/api/ApiQueryUserContributions.php
M includes/specials/pagers/ContribsPager.php
2 files changed, 29 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/47/394447/1

diff --git a/includes/api/ApiQueryUserContributions.php 
b/includes/api/ApiQueryUserContributions.php
index bb0f335..1326306 100644
--- a/includes/api/ApiQueryUserContributions.php
+++ b/includes/api/ApiQueryUserContributions.php
@@ -36,7 +36,7 @@
        }
 
        private $params, $prefixMode, $userprefix, $multiUserMode, $idMode, 
$usernames, $userids,
-               $parentLens, $commentStore;
+               $parentLens, $commentStore, $ipRange;
        private $fld_ids = false, $fld_title = false, $fld_timestamp = false,
                $fld_comment = false, $fld_parsedcomment = false, $fld_flags = 
false,
                $fld_patrolled = false, $fld_tags = false, $fld_size = false, 
$fld_sizediff = false;
@@ -67,7 +67,7 @@
                // TODO: if the query is going only against the revision table, 
should this be done?
                $this->selectNamedDB( 'contributions', DB_REPLICA, 
'contributions' );
 
-               $this->requireOnlyOneParameter( $this->params, 'userprefix', 
'userids', 'user' );
+               $this->requireOnlyOneParameter( $this->params, 'userprefix', 
'userids', 'iprange', 'user' );
 
                $this->idMode = false;
                if ( isset( $this->params['userprefix'] ) ) {
@@ -93,6 +93,17 @@
                        $this->prefixMode = false;
                        $this->multiUserMode = ( count( 
$this->params['userids'] ) > 1 );
                        $this->idMode = true;
+               } elseif ( isset( $this->params['iprange'] ) ) {
+                       $this->ipRange = $this->params['iprange'];
+                       $encParamName = $this->encodeParamName( 'iprange' );
+                       if ( !IP::isValidRange( $this->ipRange ) ) {
+                               $this->dieWithError( [ 'apierror-invalidrange', 
$encParamName ], "invalidrange_$encParamName" );
+                       }
+                       if ( !ContribsPager::isQueryableRange( $this->ipRange ) 
) {
+                               $this->dieWithError( [ 
'apierror-rangeoutofrange', $encParamName ], "invalidrange_$encParamName" );
+                       }
+
+                       $this->multiUserMode = true;
                } else {
                        $anyIPs = false;
                        $this->userids = [];
@@ -246,6 +257,14 @@
                }
                if ( $bitmask ) {
                        $this->addWhere( $this->getDB()->bitAnd( 'rev_deleted', 
$bitmask ) . " != $bitmask" );
+               }
+
+               if ( $this->ipRange ) {
+                       $this->addTables( 'ip_changes' );
+                       $this->addJoinConds( [
+                               'ip_changes' => [ 'LEFT JOIN', [ 'ipc_rev_id = 
rev_id' ] ]
+                       ] );
+                       $this->addWhere( ContribsPager::getIpRangeConds( 
$this->getDB(), $this->ipRange ) );
                }
 
                // We only want pages by the specified users.
@@ -527,6 +546,7 @@
                                ApiBase::PARAM_ISMULTI => true
                        ],
                        'userprefix' => null,
+                       'iprange' => null,
                        'dir' => [
                                ApiBase::PARAM_DFLT => 'older',
                                ApiBase::PARAM_TYPE => [
diff --git a/includes/specials/pagers/ContribsPager.php 
b/includes/specials/pagers/ContribsPager.php
index 85faddc..a606961 100644
--- a/includes/specials/pagers/ContribsPager.php
+++ b/includes/specials/pagers/ContribsPager.php
@@ -213,7 +213,7 @@
                                $queryInfo['conds']['rev_user'] = $uid;
                                $queryInfo['options']['USE INDEX']['revision'] 
= 'user_timestamp';
                        } else {
-                               $ipRangeConds = $this->getIpRangeConds( 
$this->mDb, $this->target );
+                               $ipRangeConds = self::getIpRangeConds( 
$this->mDb, $this->target );
 
                                if ( $ipRangeConds ) {
                                        $queryInfo['tables'][] = 'ip_changes';
@@ -307,9 +307,9 @@
         * @param string         $ip The IP address or CIDR
         * @return string|false  SQL for valid IP ranges, false if invalid
         */
-       private function getIpRangeConds( $db, $ip ) {
+       public static function getIpRangeConds( IDatabase $db, $ip ) {
                // First make sure it is a valid range and they are not outside 
the CIDR limit
-               if ( !$this->isQueryableRange( $ip ) ) {
+               if ( !self::isQueryableRange( $ip ) ) {
                        return false;
                }
 
@@ -325,14 +325,14 @@
         * @return bool True if it is valid
         * @since 1.30
         */
-       public function isQueryableRange( $ipRange ) {
-               $limits = $this->getConfig()->get( 
'RangeContributionsCIDRLimit' );
+       public static function isQueryableRange( $ipRange ) {
+               global $wgRangeContributionsCIDRLimit;
 
                $bits = IP::parseCIDR( $ipRange )[1];
                if (
                        ( $bits === false ) ||
-                       ( IP::isIPv4( $ipRange ) && $bits < $limits['IPv4'] ) ||
-                       ( IP::isIPv6( $ipRange ) && $bits < $limits['IPv6'] )
+                       ( IP::isIPv4( $ipRange ) && $bits < 
$wgRangeContributionsCIDRLimit['IPv4'] ) ||
+                       ( IP::isIPv6( $ipRange ) && $bits < 
$wgRangeContributionsCIDRLimit['IPv6'] )
                ) {
                        return false;
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/394447
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0a0c752e7430dbf97a29c8526af8c033d2c182fa
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to