api: Replace ApiPageSet::getGoodTitles where PageIdentity is not used

Change-Id: I6097c3e2e75715d40e067b6913849e930f40c876
This commit is contained in:
Umherirrender 2021-06-28 22:56:37 +02:00
parent 4fbdce2725
commit 19753b0d45
8 changed files with 29 additions and 23 deletions

View file

@ -51,7 +51,8 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
* @param ApiPageSet|null $resultPageSet
*/
private function run( $resultPageSet = null ) {
if ( $this->getPageSet()->getGoodTitleCount() == 0 ) {
$pages = $this->getPageSet()->getGoodPages();
if ( $pages === [] ) {
return; // nothing to do
}
@ -68,7 +69,7 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
$this->addFieldsIf( 'cl_timestamp', isset( $prop['timestamp'] ) );
$this->addTables( 'categorylinks' );
$this->addWhereFld( 'cl_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
$this->addWhereFld( 'cl_from', array_keys( $pages ) );
if ( $params['categories'] ) {
$cats = [];
foreach ( $params['categories'] as $cat ) {
@ -123,7 +124,7 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
$sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
// Don't order by cl_from if it's constant in the WHERE clause
if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) {
if ( count( $pages ) === 1 ) {
$this->addOption( 'ORDER BY', 'cl_to' . $sort );
} else {
$this->addOption( 'ORDER BY', [

View file

@ -84,7 +84,7 @@ class ApiQueryContributors extends ApiQueryBase {
$this->requireMaxOneParameter( $params, 'group', 'excludegroup', 'rights', 'excluderights' );
// Only operate on existing pages
$pages = array_keys( $this->getPageSet()->getGoodTitles() );
$pages = array_keys( $this->getPageSet()->getGoodPages() );
// Filter out already-processed pages
if ( $params['continue'] !== null ) {

View file

@ -32,7 +32,8 @@ class ApiQueryExternalLinks extends ApiQueryBase {
}
public function execute() {
if ( $this->getPageSet()->getGoodTitleCount() == 0 ) {
$pages = $this->getPageSet()->getGoodPages();
if ( $pages === [] ) {
return;
}
@ -48,12 +49,12 @@ class ApiQueryExternalLinks extends ApiQueryBase {
] );
$this->addTables( 'externallinks' );
$this->addWhereFld( 'el_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
$this->addWhereFld( 'el_from', array_keys( $pages ) );
$orderBy = [];
// Don't order by el_from if it's constant in the WHERE clause
if ( count( $this->getPageSet()->getGoodTitles() ) != 1 ) {
if ( count( $pages ) !== 1 ) {
$orderBy[] = 'el_from';
}

View file

@ -35,7 +35,8 @@ class ApiQueryIWLinks extends ApiQueryBase {
}
public function execute() {
if ( $this->getPageSet()->getGoodTitleCount() == 0 ) {
$pages = $this->getPageSet()->getGoodPages();
if ( $pages === [] ) {
return;
}
@ -66,7 +67,7 @@ class ApiQueryIWLinks extends ApiQueryBase {
] );
$this->addTables( 'iwlinks' );
$this->addWhereFld( 'iwl_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
$this->addWhereFld( 'iwl_from', array_keys( $pages ) );
if ( $params['continue'] !== null ) {
$cont = explode( '|', $params['continue'] );
@ -99,7 +100,7 @@ class ApiQueryIWLinks extends ApiQueryBase {
}
} else {
// Don't order by iwl_from if it's constant in the WHERE clause
if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) {
if ( count( $pages ) === 1 ) {
$this->addOption( 'ORDER BY', 'iwl_prefix' . $sort );
} else {
$this->addOption( 'ORDER BY', [

View file

@ -48,7 +48,8 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
* @param ApiPageSet|null $resultPageSet
*/
private function run( $resultPageSet = null ) {
if ( $this->getPageSet()->getGoodTitleCount() == 0 ) {
$pages = $this->getPageSet()->getGoodPages();
if ( $pages === [] ) {
return; // nothing to do
}
@ -59,7 +60,7 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
] );
$this->addTables( 'imagelinks' );
$this->addWhereFld( 'il_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
$this->addWhereFld( 'il_from', array_keys( $pages ) );
if ( $params['continue'] !== null ) {
$cont = explode( '|', $params['continue'] );
$this->dieContinueUsageIf( count( $cont ) != 2 );
@ -75,7 +76,7 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
$sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
// Don't order by il_from if it's constant in the WHERE clause
if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) {
if ( count( $pages ) === 1 ) {
$this->addOption( 'ORDER BY', 'il_to' . $sort );
} else {
$this->addOption( 'ORDER BY', [

View file

@ -47,7 +47,8 @@ class ApiQueryLangLinks extends ApiQueryBase {
}
public function execute() {
if ( $this->getPageSet()->getGoodTitleCount() == 0 ) {
$pages = $this->getPageSet()->getGoodPages();
if ( $pages === [] ) {
return;
}
@ -78,7 +79,7 @@ class ApiQueryLangLinks extends ApiQueryBase {
] );
$this->addTables( 'langlinks' );
$this->addWhereFld( 'll_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
$this->addWhereFld( 'll_from', array_keys( $pages ) );
if ( $params['continue'] !== null ) {
$cont = explode( '|', $params['continue'] );
$this->dieContinueUsageIf( count( $cont ) != 2 );
@ -107,7 +108,7 @@ class ApiQueryLangLinks extends ApiQueryBase {
$this->addOption( 'ORDER BY', 'll_from' . $sort );
} else {
// Don't order by ll_from if it's constant in the WHERE clause
if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) {
if ( count( $pages ) === 1 ) {
$this->addOption( 'ORDER BY', 'll_lang' . $sort );
} else {
$this->addOption( 'ORDER BY', [

View file

@ -84,7 +84,8 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
* @param ApiPageSet|null $resultPageSet
*/
private function run( $resultPageSet = null ) {
if ( $this->getPageSet()->getGoodTitleCount() == 0 ) {
$pages = $this->getPageSet()->getGoodPages();
if ( $pages === [] ) {
return; // nothing to do
}
@ -97,7 +98,7 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
] );
$this->addTables( $this->table );
$this->addWhereFld( $this->prefix . '_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
$this->addWhereFld( $this->prefix . '_from', array_keys( $pages ) );
$multiNS = true;
$multiTitle = true;
@ -151,7 +152,7 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
// already. To work around this, we drop constant fields in the WHERE
// clause from the ORDER BY clause
$order = [];
if ( count( $this->getPageSet()->getGoodTitles() ) != 1 ) {
if ( count( $pages ) !== 1 ) {
$order[] = $this->prefix . '_from' . $sort;
}
if ( $multiNS ) {

View file

@ -320,7 +320,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
$this->addOption( 'ORDER BY', [ "rev_timestamp $sort", "rev_id $sort" ] );
// There is only one ID, use it
$ids = array_keys( $pageSet->getGoodTitles() );
$ids = array_keys( $pageSet->getGoodPages() );
$this->addWhereFld( $pageField, reset( $ids ) );
if ( $params['user'] !== null ) {
@ -374,16 +374,16 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
} elseif ( $pageCount > 0 ) {
// Always targets the rev_page_id index
$titles = $pageSet->getGoodTitles();
$pageids = array_keys( $pageSet->getGoodPages() );
// When working in multi-page non-enumeration mode,
// limit to the latest revision only
$this->addWhere( 'page_latest=rev_id' );
// Get all page IDs
$this->addWhereFld( 'page_id', array_keys( $titles ) );
$this->addWhereFld( 'page_id', $pageids );
// Every time someone relies on equality propagation, god kills a kitten :)
$this->addWhereFld( 'rev_page', array_keys( $titles ) );
$this->addWhereFld( 'rev_page', $pageids );
if ( $params['continue'] !== null ) {
$cont = explode( '|', $params['continue'] );