Merge "Split VariableGenerator::addEditVars"

This commit is contained in:
jenkins-bot 2023-07-17 23:26:53 +00:00 committed by Gerrit Code Review
commit 78c7334d6a
3 changed files with 24 additions and 14 deletions

View file

@ -172,20 +172,7 @@ class VariableGenerator {
return $this;
}
/**
* @param WikiPage $page
* @param UserIdentity $userIdentity The current user
* @param bool $forFilter Whether the variables should be computed for an ongoing action
* being filtered
* @param PreparedUpdate|null $update
* @return $this For chaining
*/
public function addEditVars(
WikiPage $page,
UserIdentity $userIdentity,
bool $forFilter = true,
PreparedUpdate $update = null
): self {
public function addDerivedEditVars(): self {
$this->vars->setLazyLoadVar( 'edit_diff', 'diff',
[ 'oldtext-var' => 'old_wikitext', 'newtext-var' => 'new_wikitext' ] );
$this->vars->setLazyLoadVar( 'edit_diff_pst', 'diff',
@ -208,9 +195,30 @@ class VariableGenerator {
[ 'oldlink-var' => 'old_links', 'newlink-var' => 'all_links' ] );
$this->vars->setLazyLoadVar( 'removed_links', 'link-diff-removed',
[ 'oldlink-var' => 'old_links', 'newlink-var' => 'all_links' ] );
// Text
$this->vars->setLazyLoadVar( 'new_text', 'strip-html',
[ 'html-var' => 'new_html' ] );
return $this;
}
/**
* @param WikiPage $page
* @param UserIdentity $userIdentity The current user
* @param bool $forFilter Whether the variables should be computed for an ongoing action
* being filtered
* @param PreparedUpdate|null $update
* @return $this For chaining
*/
public function addEditVars(
WikiPage $page,
UserIdentity $userIdentity,
bool $forFilter = true,
PreparedUpdate $update = null
): self {
$this->addDerivedEditVars();
if ( $forFilter && $update ) {
$this->vars->setLazyLoadVar( 'all_links', 'links-from-update',
[ 'update' => $update ] );

View file

@ -200,6 +200,7 @@ class RCVariableGeneratorTest extends MediaWikiIntegrationTestCase {
/**
* @covers ::addEditVars
* @covers ::addDerivedEditVars
* @covers ::addEditVarsForRow
* @covers ::addGenericVars
* @covers \MediaWiki\Extension\AbuseFilter\Variables\LazyVariableComputer

View file

@ -159,6 +159,7 @@ class VariableGeneratorTest extends MediaWikiUnitTestCase {
/**
* @covers ::addEditVars
* @covers ::addDerivedEditVars
* @dataProvider provideForFilter
*/
public function testAddEditVars( bool $forFilter ) {