X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryUserContributions.php;h=181cddbeda0d8b135bbee7f41c1344955a5eebb0;hb=d5a7166771613dfe4ed9fb75fa5efeced6134bd1;hp=51e192325e7ed96caf3b2be00a02ca72204381f5;hpb=c5f68ec77aa526dd77c9daec8f88a3f63ef75948;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryUserContributions.php b/includes/api/ApiQueryUserContributions.php index 51e192325e..181cddbeda 100644 --- a/includes/api/ApiQueryUserContributions.php +++ b/includes/api/ApiQueryUserContributions.php @@ -57,32 +57,56 @@ class ApiQueryContributions extends ApiQueryBase { $this->fld_patrolled = isset( $prop['patrolled'] ); $this->fld_tags = isset( $prop['tags'] ); - // Most of this code will use the 'contributions' group DB, which can map to slaves + // Most of this code will use the 'contributions' group DB, which can map to replica DBs // with extra user based indexes or partioning by user. The additional metadata - // queries should use a regular slave since the lookup pattern is not all by user. - $dbSecondary = $this->getDB(); // any random slave + // queries should use a regular replica DB since the lookup pattern is not all by user. + $dbSecondary = $this->getDB(); // any random replica DB // TODO: if the query is going only against the revision table, should this be done? - $this->selectNamedDB( 'contributions', DB_SLAVE, 'contributions' ); + $this->selectNamedDB( 'contributions', DB_REPLICA, 'contributions' ); + + $this->requireOnlyOneParameter( $this->params, 'userprefix', 'userids', 'user' ); $this->idMode = false; if ( isset( $this->params['userprefix'] ) ) { $this->prefixMode = true; $this->multiUserMode = true; $this->userprefix = $this->params['userprefix']; + } elseif ( isset( $this->params['userids'] ) ) { + $this->userids = []; + + if ( !count( $this->params['userids'] ) ) { + $encParamName = $this->encodeParamName( 'userids' ); + $this->dieWithError( [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" ); + } + + foreach ( $this->params['userids'] as $uid ) { + if ( $uid <= 0 ) { + $this->dieWithError( [ 'apierror-invaliduserid', $uid ], 'invaliduserid' ); + } + + $this->userids[] = $uid; + } + + $this->prefixMode = false; + $this->multiUserMode = ( count( $this->params['userids'] ) > 1 ); + $this->idMode = true; } else { $anyIPs = false; $this->userids = []; $this->usernames = []; - if ( !is_array( $this->params['user'] ) ) { - $this->params['user'] = [ $this->params['user'] ]; - } if ( !count( $this->params['user'] ) ) { - $this->dieUsage( 'User parameter may not be empty.', 'param_user' ); + $encParamName = $this->encodeParamName( 'user' ); + $this->dieWithError( + [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" + ); } foreach ( $this->params['user'] as $u ) { - if ( is_null( $u ) || $u === '' ) { - $this->dieUsage( 'User parameter may not be empty', 'param_user' ); + if ( $u === '' ) { + $encParamName = $this->encodeParamName( 'user' ); + $this->dieWithError( + [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" + ); } if ( User::isIP( $u ) ) { @@ -91,7 +115,10 @@ class ApiQueryContributions extends ApiQueryBase { } else { $name = User::getCanonicalName( $u, 'valid' ); if ( $name === false ) { - $this->dieUsage( "User name {$u} is not valid", 'param_user' ); + $encParamName = $this->encodeParamName( 'user' ); + $this->dieWithError( + [ 'apierror-baduser', $encParamName, wfEscapeWikiText( $u ) ], "baduser_$encParamName" + ); } $this->usernames[] = $name; } @@ -111,8 +138,9 @@ class ApiQueryContributions extends ApiQueryBase { $this->prepareQuery(); + $hookData = []; // Do the actual query. - $res = $this->select( __METHOD__ ); + $res = $this->select( __METHOD__, [], $hookData ); if ( $this->fld_sizediff ) { $revIds = []; @@ -139,7 +167,8 @@ class ApiQueryContributions extends ApiQueryBase { } $vals = $this->extractRowInfo( $row ); - $fit = $this->getResult()->addValue( [ 'query', $this->getModuleName() ], null, $vals ); + $fit = $this->processRow( $row, $vals, $hookData ) && + $this->getResult()->addValue( [ 'query', $this->getModuleName() ], null, $vals ); if ( !$fit ) { $this->setContinueEnumParameter( 'continue', $this->continueStr( $row ) ); break; @@ -252,7 +281,7 @@ class ApiQueryContributions extends ApiQueryBase { || ( isset( $show['top'] ) && isset( $show['!top'] ) ) || ( isset( $show['new'] ) && isset( $show['!new'] ) ) ) { - $this->dieUsageMsg( 'show' ); + $this->dieWithError( 'apierror-show' ); } $this->addWhereIf( 'rev_minor_edit = 0', isset( $show['!minor'] ) ); @@ -283,10 +312,7 @@ class ApiQueryContributions extends ApiQueryBase { $this->fld_patrolled ) { if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) { - $this->dieUsage( - 'You need the patrol right to request the patrolled flag', - 'permissiondenied' - ); + $this->dieWithError( 'apierror-permissiondenied-patrolflag', 'permissiondenied' ); } // Use a redundant join condition on both @@ -487,6 +513,10 @@ class ApiQueryContributions extends ApiQueryBase { ApiBase::PARAM_TYPE => 'user', ApiBase::PARAM_ISMULTI => true ], + 'userids' => [ + ApiBase::PARAM_TYPE => 'integer', + ApiBase::PARAM_ISMULTI => true + ], 'userprefix' => null, 'dir' => [ ApiBase::PARAM_DFLT => 'older', @@ -552,6 +582,6 @@ class ApiQueryContributions extends ApiQueryBase { } public function getHelpUrls() { - return 'https://www.mediawiki.org/wiki/API:Usercontribs'; + return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs'; } }