API: Use ct_tag_id in queries when applicable

Bug: T194162
Change-Id: I2146cd1f72b546277723102ab64c79567549ff5b
This commit is contained in:
Amir Sarabadani 2018-09-04 21:17:29 +02:00
parent 5061f291f3
commit 0841a0f79e
7 changed files with 102 additions and 8 deletions

View file

@ -24,6 +24,7 @@
*/
use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\NameTableAccessException;
use MediaWiki\Storage\RevisionRecord;
/**
@ -42,6 +43,8 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase {
* @return void
*/
protected function run( ApiPageSet $resultPageSet = null ) {
global $wgChangeTagsSchemaMigrationStage;
// Before doing anything at all, let's check permissions
$this->checkUserRightsAny( 'deletedhistory' );
@ -136,7 +139,17 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase {
$this->addJoinConds(
[ 'change_tag' => [ 'INNER JOIN', [ 'ar_rev_id=ct_rev_id' ] ] ]
);
$this->addWhereFld( 'ct_tag', $params['tag'] );
if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
$changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
try {
$this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
} catch ( NameTableAccessException $exception ) {
// Return nothing.
$this->addWhere( '1=0' );
}
} else {
$this->addWhereFld( 'ct_tag', $params['tag'] );
}
}
if ( $this->fetchContent ) {

View file

@ -24,6 +24,7 @@
*/
use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\NameTableAccessException;
use MediaWiki\Storage\RevisionRecord;
/**
@ -38,6 +39,8 @@ class ApiQueryDeletedRevisions extends ApiQueryRevisionsBase {
}
protected function run( ApiPageSet $resultPageSet = null ) {
global $wgChangeTagsSchemaMigrationStage;
$user = $this->getUser();
// Before doing anything at all, let's check permissions
$this->checkUserRightsAny( 'deletedhistory' );
@ -88,7 +91,17 @@ class ApiQueryDeletedRevisions extends ApiQueryRevisionsBase {
$this->addJoinConds(
[ 'change_tag' => [ 'INNER JOIN', [ 'ar_rev_id=ct_rev_id' ] ] ]
);
$this->addWhereFld( 'ct_tag', $params['tag'] );
if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
$changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
try {
$this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
} catch ( NameTableAccessException $exception ) {
// Return nothing.
$this->addWhere( '1=0' );
}
} else {
$this->addWhereFld( 'ct_tag', $params['tag'] );
}
}
if ( $this->fetchContent ) {

View file

@ -20,6 +20,9 @@
* @file
*/
use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\NameTableAccessException;
/**
* Query module to enumerate all deleted revisions.
*
@ -33,6 +36,8 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
}
public function execute() {
global $wgChangeTagsSchemaMigrationStage;
// Before doing anything at all, let's check permissions
$this->checkUserRightsAny( 'deletedhistory' );
@ -140,7 +145,17 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
$this->addJoinConds(
[ 'change_tag' => [ 'INNER JOIN', [ 'ar_rev_id=ct_rev_id' ] ] ]
);
$this->addWhereFld( 'ct_tag', $params['tag'] );
if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
$changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
try {
$this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
} catch ( NameTableAccessException $exception ) {
// Return nothing.
$this->addWhere( '1=0' );
}
} else {
$this->addWhereFld( 'ct_tag', $params['tag'] );
}
}
if ( $fld_content ) {

View file

@ -20,6 +20,9 @@
* @file
*/
use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\NameTableAccessException;
/**
* Query action to List the log events, with optional filtering by various parameters.
*
@ -39,6 +42,8 @@ class ApiQueryLogEvents extends ApiQueryBase {
$fld_details = false, $fld_tags = false;
public function execute() {
global $wgChangeTagsSchemaMigrationStage;
$params = $this->extractRequestParams();
$db = $this->getDB();
$this->commentStore = CommentStore::getStore();
@ -113,7 +118,17 @@ class ApiQueryLogEvents extends ApiQueryBase {
$this->addTables( 'change_tag' );
$this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN',
[ 'log_id=ct_log_id' ] ] ] );
$this->addWhereFld( 'ct_tag', $params['tag'] );
if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
$changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
try {
$this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
} catch ( NameTableAccessException $exception ) {
// Return nothing.
$this->addWhere( '1=0' );
}
} else {
$this->addWhereFld( 'ct_tag', $params['tag'] );
}
}
if ( !is_null( $params['action'] ) ) {

View file

@ -20,6 +20,8 @@
* @file
*/
use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\NameTableAccessException;
use MediaWiki\Storage\RevisionRecord;
/**
@ -141,6 +143,8 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
* @param ApiPageSet|null $resultPageSet
*/
public function run( $resultPageSet = null ) {
global $wgChangeTagsSchemaMigrationStage;
$user = $this->getUser();
/* Get the parameters of the request. */
$params = $this->extractRequestParams();
@ -361,7 +365,17 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
if ( !is_null( $params['tag'] ) ) {
$this->addTables( 'change_tag' );
$this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'rc_id=ct_rc_id' ] ] ] );
$this->addWhereFld( 'ct_tag', $params['tag'] );
if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
$changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
try {
$this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
} catch ( NameTableAccessException $exception ) {
// Return nothing.
$this->addWhere( '1=0' );
}
} else {
$this->addWhereFld( 'ct_tag', $params['tag'] );
}
}
// Paranoia: avoid brute force searches (T19342)

View file

@ -21,6 +21,7 @@
*/
use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\NameTableAccessException;
use MediaWiki\Storage\RevisionRecord;
/**
@ -83,6 +84,8 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
}
protected function run( ApiPageSet $resultPageSet = null ) {
global $wgChangeTagsSchemaMigrationStage;
$params = $this->extractRequestParams( false );
$revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
@ -170,7 +173,17 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
$this->addJoinConds(
[ 'change_tag' => [ 'INNER JOIN', [ 'rev_id=ct_rev_id' ] ] ]
);
$this->addWhereFld( 'ct_tag', $params['tag'] );
if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
$changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
try {
$this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
} catch ( NameTableAccessException $exception ) {
// Return nothing.
$this->addWhere( '1=0' );
}
} else {
$this->addWhereFld( 'ct_tag', $params['tag'] );
}
}
if ( $resultPageSet === null && $this->fetchContent ) {

View file

@ -21,6 +21,7 @@
*/
use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\NameTableAccessException;
use MediaWiki\Storage\RevisionRecord;
/**
@ -437,7 +438,7 @@ class ApiQueryUserContribs extends ApiQueryBase {
* @return bool
*/
private function prepareQuery( array $users, $limit, $which ) {
global $wgActorTableSchemaMigrationStage;
global $wgActorTableSchemaMigrationStage, $wgChangeTagsSchemaMigrationStage;
$this->resetQueryParams();
$db = $this->getDB();
@ -607,7 +608,17 @@ class ApiQueryUserContribs extends ApiQueryBase {
$this->addJoinConds(
[ 'change_tag' => [ 'INNER JOIN', [ $idField . ' = ct_rev_id' ] ] ]
);
$this->addWhereFld( 'ct_tag', $this->params['tag'] );
if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
$changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
try {
$this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $this->params['tag'] ) );
} catch ( NameTableAccessException $exception ) {
// Return nothing.
$this->addWhere( '1=0' );
}
} else {
$this->addWhereFld( 'ct_tag', $this->params['tag'] );
}
}
return true;