mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CategoryTree
synced 2024-11-30 11:06:55 +00:00
Migrate to IReadableDatabase::newSelectQueryBuilder
RIGHT JOIN is unsupported by SelectQueryBuilder, swapped to LEFT JOIN Bug: T312395 Change-Id: Idd646422dc6c984d7ceab23743e53e64bccb987c
This commit is contained in:
parent
6648cf4a27
commit
d8f77953a1
|
@ -136,13 +136,15 @@ class ApiCategoryTree extends ApiBase {
|
||||||
if ( $condition === 'last-modified' ) {
|
if ( $condition === 'last-modified' ) {
|
||||||
$params = $this->extractRequestParams();
|
$params = $this->extractRequestParams();
|
||||||
$title = CategoryTree::makeTitle( $params['category'] );
|
$title = CategoryTree::makeTitle( $params['category'] );
|
||||||
return $this->dbProvider->getReplicaDatabase()->selectField( 'page', 'page_touched',
|
return $this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder()
|
||||||
[
|
->select( 'page_touched' )
|
||||||
|
->from( 'page' )
|
||||||
|
->where( [
|
||||||
'page_namespace' => NS_CATEGORY,
|
'page_namespace' => NS_CATEGORY,
|
||||||
'page_title' => $title->getDBkey(),
|
'page_title' => $title->getDBkey(),
|
||||||
],
|
] )
|
||||||
__METHOD__
|
->caller( __METHOD__ )
|
||||||
);
|
->fetchField();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -163,37 +163,39 @@ class CategoryTree {
|
||||||
$mode = $this->optionManager->getOption( 'mode' );
|
$mode = $this->optionManager->getOption( 'mode' );
|
||||||
$namespaces = $this->optionManager->getOption( 'namespaces' );
|
$namespaces = $this->optionManager->getOption( 'namespaces' );
|
||||||
|
|
||||||
$tables = [ 'page', 'categorylinks' ];
|
$queryBuilder = $dbr->newSelectQueryBuilder()
|
||||||
$fields = [ 'page_id', 'page_namespace', 'page_title',
|
->select( [
|
||||||
'page_is_redirect', 'page_len', 'page_latest', 'cl_to',
|
'page_id', 'page_namespace', 'page_title',
|
||||||
'cl_from' ];
|
'page_is_redirect', 'page_len', 'page_latest', 'cl_to', 'cl_from'
|
||||||
$where = [];
|
] )
|
||||||
$joins = [];
|
->orderBy( [ 'cl_type', 'cl_sortkey' ] )
|
||||||
$options = [
|
->limit( $this->config->get( 'CategoryTreeMaxChildren' ) )
|
||||||
'ORDER BY' => 'cl_type, cl_sortkey',
|
->caller( __METHOD__ );
|
||||||
'LIMIT' => $this->config->get( 'CategoryTreeMaxChildren' )
|
|
||||||
];
|
|
||||||
|
|
||||||
if ( $inverse ) {
|
if ( $inverse ) {
|
||||||
$joins['categorylinks'] = [ 'RIGHT JOIN', [
|
$queryBuilder
|
||||||
'cl_to = page_title', 'page_namespace' => NS_CATEGORY
|
->from( 'categorylinks' )
|
||||||
] ];
|
->leftJoin( 'page', null, [
|
||||||
$where['cl_from'] = $title->getArticleID();
|
'cl_to = page_title', 'page_namespace' => NS_CATEGORY
|
||||||
|
] )
|
||||||
|
->where( [ 'cl_from' => $title->getArticleID() ] );
|
||||||
} else {
|
} else {
|
||||||
$joins['categorylinks'] = [ 'JOIN', 'cl_from = page_id' ];
|
$queryBuilder
|
||||||
$where['cl_to'] = $title->getDBkey();
|
->from( 'page' )
|
||||||
$options['USE INDEX']['categorylinks'] = 'cl_sortkey';
|
->join( 'categorylinks', null, 'cl_from = page_id' )
|
||||||
|
->where( [ 'cl_to' => $title->getDBkey() ] )
|
||||||
|
->useIndex( 'cl_sortkey' );
|
||||||
|
|
||||||
# namespace filter.
|
# namespace filter.
|
||||||
if ( $namespaces ) {
|
if ( $namespaces ) {
|
||||||
// NOTE: we assume that the $namespaces array contains only integers!
|
// NOTE: we assume that the $namespaces array contains only integers!
|
||||||
// decodeNamepsaces makes it so.
|
// decodeNamepsaces makes it so.
|
||||||
$where['page_namespace'] = $namespaces;
|
$queryBuilder->where( [ 'page_namespace' => $namespaces ] );
|
||||||
} elseif ( $mode !== CategoryTreeMode::ALL ) {
|
} elseif ( $mode !== CategoryTreeMode::ALL ) {
|
||||||
if ( $mode === CategoryTreeMode::PAGES ) {
|
if ( $mode === CategoryTreeMode::PAGES ) {
|
||||||
$where['cl_type'] = [ 'page', 'subcat' ];
|
$queryBuilder->where( [ 'cl_type' => [ 'page', 'subcat' ] ] );
|
||||||
} else {
|
} else {
|
||||||
$where['cl_type'] = 'subcat';
|
$queryBuilder->where( [ 'cl_type' => 'subcat' ] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,16 +204,12 @@ class CategoryTree {
|
||||||
$doCount = !$inverse && $this->config->get( 'CategoryTreeUseCategoryTable' );
|
$doCount = !$inverse && $this->config->get( 'CategoryTreeUseCategoryTable' );
|
||||||
|
|
||||||
if ( $doCount ) {
|
if ( $doCount ) {
|
||||||
$tables = array_merge( $tables, [ 'category' ] );
|
$queryBuilder
|
||||||
$fields = array_merge( $fields, [
|
->leftJoin( 'category', null, [ 'cat_title = page_title', 'page_namespace' => NS_CATEGORY ] )
|
||||||
'cat_id', 'cat_title', 'cat_subcats', 'cat_pages', 'cat_files'
|
->fields( [ 'cat_id', 'cat_title', 'cat_subcats', 'cat_pages', 'cat_files' ] );
|
||||||
] );
|
|
||||||
$joins['category'] = [ 'LEFT JOIN', [
|
|
||||||
'cat_title = page_title', 'page_namespace' => NS_CATEGORY ]
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = $dbr->select( $tables, $fields, $where, __METHOD__, $options, $joins );
|
$res = $queryBuilder->fetchResultSet();
|
||||||
|
|
||||||
# collect categories separately from other pages
|
# collect categories separately from other pages
|
||||||
$categories = '';
|
$categories = '';
|
||||||
|
@ -281,16 +279,14 @@ class CategoryTree {
|
||||||
public function renderParents( Title $title ) {
|
public function renderParents( Title $title ) {
|
||||||
$dbr = $this->dbProvider->getReplicaDatabase();
|
$dbr = $this->dbProvider->getReplicaDatabase();
|
||||||
|
|
||||||
$res = $dbr->select(
|
$res = $dbr->newSelectQueryBuilder()
|
||||||
'categorylinks',
|
->select( 'cl_to' )
|
||||||
[ 'cl_to' ],
|
->from( 'categorylinks' )
|
||||||
[ 'cl_from' => $title->getArticleID() ],
|
->where( [ 'cl_from' => $title->getArticleID() ] )
|
||||||
__METHOD__,
|
->limit( $this->config->get( 'CategoryTreeMaxChildren' ) )
|
||||||
[
|
->orderBy( 'cl_to' )
|
||||||
'LIMIT' => $this->config->get( 'CategoryTreeMaxChildren' ),
|
->caller( __METHOD__ )
|
||||||
'ORDER BY' => 'cl_to'
|
->fetchResultSet();
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$special = SpecialPage::getTitleFor( 'CategoryTree' );
|
$special = SpecialPage::getTitleFor( 'CategoryTree' );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue