Restore support for matching 'LIKE' patterns/wildcards

Follow-up to 910ce4c870.

Add a test so that we don't break this again.

Bug: T355478
Change-Id: I98620dd66a3c3a6913f999d6f96eef0ef69271d1
This commit is contained in:
Bartosz Dziewoński 2024-01-22 11:56:39 +01:00
parent 60d12bb79b
commit 80bdcd3004
2 changed files with 54 additions and 5 deletions

View file

@ -24,8 +24,6 @@ use PermissionsError;
use RepoGroup; use RepoGroup;
use UserBlockedError; use UserBlockedError;
use Wikimedia\Rdbms\IConnectionProvider; use Wikimedia\Rdbms\IConnectionProvider;
use Wikimedia\Rdbms\IExpression;
use Wikimedia\Rdbms\LikeValue;
use Wikimedia\Rdbms\SelectQueryBuilder; use Wikimedia\Rdbms\SelectQueryBuilder;
use Xml; use Xml;
@ -374,9 +372,9 @@ class SpecialNuke extends SpecialPage {
$pattern = $this->getRequest()->getText( 'pattern' ); $pattern = $this->getRequest()->getText( 'pattern' );
if ( $pattern !== null && trim( $pattern ) !== '' ) { if ( $pattern !== null && trim( $pattern ) !== '' ) {
// $pattern is a SQL pattern supporting wildcards, so buildLike // $pattern is a SQL pattern supporting wildcards, so buildLike() will not work.
// will not work. // Wildcards are escaped using '\', so LikeValue/LikeMatch will not work either.
$queryBuilder->andWhere( $dbr->expr( 'rc_title', IExpression::LIKE, new LikeValue( $pattern ) ) ); $queryBuilder->andWhere( 'rc_title LIKE ' . $dbr->addQuotes( $pattern ) );
} }
$result = $queryBuilder->caller( __METHOD__ )->fetchResultSet(); $result = $queryBuilder->caller( __METHOD__ )->fetchResultSet();

View file

@ -0,0 +1,51 @@
<?php
namespace MediaWiki\Extension\Nuke\Tests;
use MediaWiki\Extension\Nuke\SpecialNuke;
use MediaWiki\Permissions\UltimateAuthority;
use MediaWiki\Request\FauxRequest;
use SpecialPageTestBase;
/**
* @group Database
* @covers \MediaWiki\Extension\Nuke\SpecialNuke
*/
class SpecialNukeTest extends SpecialPageTestBase {
protected function newSpecialPage(): SpecialNuke {
$services = $this->getServiceContainer();
return new SpecialNuke(
$services->getJobQueueGroup(),
$services->getDBLoadBalancerFactory(),
$services->getPermissionManager(),
$services->getRepoGroup(),
$services->getUserFactory(),
$services->getUserNamePrefixSearch(),
$services->getUserNameUtils()
);
}
public function testExecutePattern() {
// Test that matching wildcards works, and that escaping wildcards works as documented
// at https://www.mediawiki.org/wiki/Help:Extension:Nuke
$this->editPage( '%PositiveNukeTest123', 'test' );
$this->editPage( 'NegativeNukeTest123', 'test' );
$user = $this->getTestSysop()->getUser();
$request = new FauxRequest( [
'action' => 'submit',
'pattern' => '\\%PositiveNukeTest%',
'wpFormIdentifier' => 'massdelete',
'wpEditToken' => $user->getEditToken(),
], true );
$performer = new UltimateAuthority( $user );
[ $html ] = $this->executeSpecialPage( '', $request, 'qqx', $performer );
$this->assertStringContainsString( 'PositiveNukeTest123', $html );
$this->assertStringNotContainsString( 'NegativeNukeTest123', $html );
}
}