Update LintErrorPager to expression builder

Bug: T350977
Change-Id: Iee1726c93028219f9d360c5a485eb39f8c0a49ed
This commit is contained in:
Isabelle Hurbain-Palatin 2023-12-11 15:52:27 +01:00
parent d253d88d02
commit 3b3729ad4d

View file

@ -29,6 +29,9 @@ use MediaWiki\MediaWikiServices;
use MediaWiki\Title\Title; use MediaWiki\Title\Title;
use TablePager; use TablePager;
use TitleValue; use TitleValue;
use Wikimedia\Rdbms\IExpression;
use Wikimedia\Rdbms\LikeValue;
use Wikimedia\Rdbms\SelectQueryBuilder;
class LintErrorsPager extends TablePager { class LintErrorsPager extends TablePager {
@ -103,78 +106,59 @@ class LintErrorsPager extends TablePager {
$this->namespaces = $namespaces; $this->namespaces = $namespaces;
$this->exactMatch = $exactMatch; $this->exactMatch = $exactMatch;
$this->title = $title; $this->title = $title;
$this->throughTemplate = $throughTemplate; $this->throughTemplate = empty( $throughTemplate ) ? 'all' : $throughTemplate;
$this->tag = $tag; $this->tag = empty( $tag ) ? 'all' : $tag;
parent::__construct( $context ); parent::__construct( $context );
} }
/** @inheritDoc */ private function fillQueryBuilder( SelectQueryBuilder $queryBuilder ): void {
public function getQueryInfo() { $mainConfig = MediaWikiServices::getInstance()->getMainConfig();
$conds = []; $queryBuilder
->table( 'page' )->leftJoin( 'linter', null, 'page_id=linter_page' )
->fields( LinkCache::getSelectFields() )
->fields( [
'page_namespace', 'page_title',
'linter_id', 'linter_params',
'linter_start', 'linter_end',
'linter_cat'
] );
if ( $this->categoryId !== null ) { if ( $this->categoryId !== null ) {
$conds[ 'linter_cat' ] = $this->categoryId; $queryBuilder->where( [ 'linter_cat' => $this->categoryId ] );
} }
$mwServices = MediaWikiServices::getInstance();
$config = $mwServices->getMainConfig();
$dbMaintenance = $mwServices->getDBLoadBalancer()->getMaintenanceConnectionRef( DB_REPLICA );
if ( !empty( $this->namespaces ) ) { if ( !empty( $this->namespaces ) ) {
$enableUseNamespaceColumnStage = $config->get( 'LinterUseNamespaceColumnStage' ); $namespaceCol = $mainConfig->get( 'LinterUseNamespaceColumnStage' )
$fieldExists = $dbMaintenance->fieldExists( 'linter', 'linter_namespace', __METHOD__ ); ? "linter_namespace" : "page_namespace";
if ( !$enableUseNamespaceColumnStage || !$fieldExists ) { $queryBuilder->where( [ $namespaceCol => $this->namespaces ] );
$conds[ "page_namespace" ] = $this->namespaces;
} else {
$conds[ "linter_namespace" ] = $this->namespaces;
}
} }
if ( $this->exactMatch ) { if ( $this->exactMatch ) {
if ( $this->title !== '' ) { $queryBuilder->where( [ "page_title" => $this->title ] );
$conds[] = "page_title = " . $this->mDb->addQuotes( $this->title );
}
} else { } else {
$conds[] = 'page_title' . $this->mDb->buildLike( $this->title, $this->mDb->anyString() ); $queryBuilder->where( $this->mDb->expr(
'page_title', IExpression::LIKE, new LikeValue( $this->title, $this->mDb->anyString() )
)
);
} }
if ( $mainConfig->get( 'LinterUserInterfaceTagAndTemplateStage' ) ) {
$enableUserInterfaceTagAndTemplateStage = $config->get( 'LinterUserInterfaceTagAndTemplateStage' ); if ( $this->throughTemplate !== 'all' ) {
$fieldTagExists = $dbMaintenance->fieldExists( 'linter', 'linter_tag', __METHOD__ ); $op = ( $this->throughTemplate === 'with' ) ? '!=' : '=';
if ( $enableUserInterfaceTagAndTemplateStage && $fieldTagExists ) { $queryBuilder->where( $this->mDb->expr( 'linter_template', $op, '' ) );
switch ( $this->throughTemplate ) {
case 'with':
$conds[] = "linter_template != ''";
break;
case 'without':
$conds[] = "linter_template = ''";
break;
case 'all':
default:
break;
} }
switch ( $this->tag ) { if ( $this->tag !== 'all' && ( new HtmlTags( $this ) )->checkAllowedHTMLTags( $this->tag ) ) {
case 'all': $queryBuilder->where( [ 'linter_tag' => $this->tag ] );
break;
default:
$htmlTags = new HtmlTags( $this );
if ( $htmlTags->checkAllowedHTMLTags( $this->tag ) ) {
$conds[] = 'linter_tag = ' . $this->mDb->addQuotes( $this->tag );
}
} }
} }
}
return [ /**
'tables' => [ 'page', 'linter' ], * @inheritDoc
'fields' => array_merge( */
LinkCache::getSelectFields(), public function getQueryInfo() {
[ $queryBuilder = $this->mDb->newSelectQueryBuilder();
'page_namespace', 'page_title', $this->fillQueryBuilder( $queryBuilder );
'linter_id', 'linter_params', return $queryBuilder->getQueryInfo();
'linter_start', 'linter_end',
'linter_cat'
]
),
'conds' => $conds,
'join_conds' => [ 'page' => [ 'INNER JOIN', 'page_id=linter_page' ] ]
];
} }
protected function doBatchLookups() { protected function doBatchLookups() {