Merge "Rename addStaticVars and related hook"

This commit is contained in:
jenkins-bot 2020-02-10 19:03:34 +00:00 committed by Gerrit Code Review
commit b6ca1402d0
5 changed files with 16 additions and 13 deletions

View file

@ -30,13 +30,13 @@ $content: The Content object
'AbuseFilter-filterAction': DEPRECATED! Use AbuseFilterAlterVariables instead.
Allows overwriting of abusefilter variables in AbuseFilter::filterAction just before they're
checked against filters. Note that you may specify custom variables in a saner way using other hooks:
AbuseFilter-generateTitleVars, AbuseFilter-generateUserVars and AbuseFilter-generateStaticVars.
AbuseFilter-generateTitleVars, AbuseFilter-generateUserVars and AbuseFilter-generateGenericVars.
$vars: AbuseFilterVariableHolder with variables
$title: Title object
'AbuseFilterAlterVariables': Allows overwriting of abusefilter variables just before they're
checked against filters. Note that you may specify custom variables in a saner way using other hooks:
AbuseFilter-generateTitleVars, AbuseFilter-generateUserVars and AbuseFilter-generateStaticVars.
AbuseFilter-generateTitleVars, AbuseFilter-generateUserVars and AbuseFilter-generateGenericVars.
$vars: AbuseFilterVariableHolder with variables
$title: Title object target of the action
$user: User object performer of the action
@ -52,8 +52,9 @@ $vars: AbuseFilterVariableHolder
$user: User object
$rc: RCDatabaseLogEntry|null If the variables should be generated for an RC entry, this is the entry. Null if it's for the current action being filtered.
'AbuseFilter-generateStaticVars': Allows altering static variables, i.e. independent from page and user
'AbuseFilter-generateGenericVars': Allows altering generic variables, i.e. independent from page and user
$vars: AbuseFilterVariableHolder
$rcRow: If the variables should be generated for an RC row, this is the row. Null if it's for the current action being filtered.
'AbuseFilter-interceptVariable': Called before a variable is set in AFComputedVariable::compute to be able to set
it before the core code runs. Return false to make the function return right after.

View file

@ -330,13 +330,13 @@ class AbuseFilter {
}
/**
* @deprecated Use VariableGenerator::addStaticVars
* @deprecated Use VariableGenerator::addGenericVars
* @return AbuseFilterVariableHolder
*/
public static function generateStaticVars() {
public static function generateGenericVars() {
$vars = new AbuseFilterVariableHolder();
$generator = new VariableGenerator( $vars );
return $generator->addStaticVars()->getVariableHolder();
return $generator->addGenericVars()->getVariableHolder();
}
/**
@ -363,9 +363,9 @@ class AbuseFilter {
}
$vars = new AbuseFilterVariableHolder();
// Static vars are the only ones available
// Generic vars are the only ones available
$generator = new VariableGenerator( $vars );
$vars = $generator->addStaticVars()->getVariableHolder();
$vars = $generator->addGenericVars()->getVariableHolder();
$vars->setVar( 'timestamp', wfTimestamp( TS_UNIX ) );
$parser = self::getDefaultParser( $vars );

View file

@ -86,7 +86,7 @@ class AbuseFilterRunner {
Hooks::run( 'AbuseFilter-filterAction', [ &$this->vars, $this->title ] );
Hooks::run( 'AbuseFilterAlterVariables', [ &$this->vars, $this->title, $this->user ] );
$generator = new VariableGenerator( $this->vars );
$this->vars = $generator->addStaticVars()->getVariableHolder();
$this->vars = $generator->addGenericVars()->getVariableHolder();
$this->vars->forFilter = true;
$this->vars->setVar( 'timestamp', (int)wfTimestamp( TS_UNIX ) );

View file

@ -86,7 +86,7 @@ class RCVariableGenerator extends VariableGenerator {
return null;
}
$this->addStaticVars();
$this->addGenericVars();
$this->vars->setVar(
'timestamp',
MWTimestamp::convert( TS_UNIX, $this->entry->getTimestamp() )

View file

@ -34,14 +34,16 @@ class VariableGenerator {
}
/**
* Computes all variables unrelated to title and user. In general, these variables are known
* Computes all variables unrelated to title and user. In general, these variables may be known
* even without an ongoing action.
*
* @param RCDatabaseLogEntry|null $entry If the variables should be generated for an RC entry,
* this is the entry. Null if it's for the current action being filtered.
* @return $this For chaining
*/
public function addStaticVars() : self {
public function addGenericVars( RCDatabaseLogEntry $entry = null ) : self {
// For now, we don't have variables to add; other extensions could.
Hooks::run( 'AbuseFilter-generateStaticVars', [ $this->vars ] );
Hooks::run( 'AbuseFilter-generateGenericVars', [ $this->vars, $entry ] );
return $this;
}