mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Nuke
synced 2024-11-24 00:05:33 +00:00
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:
parent
60d12bb79b
commit
80bdcd3004
|
@ -24,8 +24,6 @@ use PermissionsError;
|
|||
use RepoGroup;
|
||||
use UserBlockedError;
|
||||
use Wikimedia\Rdbms\IConnectionProvider;
|
||||
use Wikimedia\Rdbms\IExpression;
|
||||
use Wikimedia\Rdbms\LikeValue;
|
||||
use Wikimedia\Rdbms\SelectQueryBuilder;
|
||||
use Xml;
|
||||
|
||||
|
@ -374,9 +372,9 @@ class SpecialNuke extends SpecialPage {
|
|||
|
||||
$pattern = $this->getRequest()->getText( 'pattern' );
|
||||
if ( $pattern !== null && trim( $pattern ) !== '' ) {
|
||||
// $pattern is a SQL pattern supporting wildcards, so buildLike
|
||||
// will not work.
|
||||
$queryBuilder->andWhere( $dbr->expr( 'rc_title', IExpression::LIKE, new LikeValue( $pattern ) ) );
|
||||
// $pattern is a SQL pattern supporting wildcards, so buildLike() will not work.
|
||||
// Wildcards are escaped using '\', so LikeValue/LikeMatch will not work either.
|
||||
$queryBuilder->andWhere( 'rc_title LIKE ' . $dbr->addQuotes( $pattern ) );
|
||||
}
|
||||
|
||||
$result = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
|
||||
|
|
51
tests/phpunit/SpecialNukeTest.php
Normal file
51
tests/phpunit/SpecialNukeTest.php
Normal 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 );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue