From 661a77f0eb6683696abca531abdfcddeb9c85bf6 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Tue, 17 Dec 2019 16:06:44 +0100 Subject: [PATCH] Rename addStaticVars and related hook This code was introduced with Iba59fe8d190dd338ecc8cfd682205bce33c9738b and is unused since then. The name should highlight that those variables are not supposed to be "static", i.e. immutable. Examples are: timestamp, spam blacklist, site name, site language. These are not immutable, but rather "generic", and they're known even without an ongoing action. Also add an RC row param and update docs. Change-Id: I402f04585e9154059fc413e527e39dcb8e6b3d7c --- hooks.txt | 7 ++++--- includes/AbuseFilter.php | 10 +++++----- includes/AbuseFilterRunner.php | 2 +- includes/VariableGenerator/RCVariableGenerator.php | 2 +- includes/VariableGenerator/VariableGenerator.php | 8 +++++--- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/hooks.txt b/hooks.txt index 5870b710e..75166da33 100644 --- a/hooks.txt +++ b/hooks.txt @@ -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. diff --git a/includes/AbuseFilter.php b/includes/AbuseFilter.php index 662f1f625..fb4cdac2c 100644 --- a/includes/AbuseFilter.php +++ b/includes/AbuseFilter.php @@ -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 ); diff --git a/includes/AbuseFilterRunner.php b/includes/AbuseFilterRunner.php index 656b02e17..0aba118f2 100644 --- a/includes/AbuseFilterRunner.php +++ b/includes/AbuseFilterRunner.php @@ -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 ) ); diff --git a/includes/VariableGenerator/RCVariableGenerator.php b/includes/VariableGenerator/RCVariableGenerator.php index 5d081f46b..e2e7a82a7 100644 --- a/includes/VariableGenerator/RCVariableGenerator.php +++ b/includes/VariableGenerator/RCVariableGenerator.php @@ -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() ) diff --git a/includes/VariableGenerator/VariableGenerator.php b/includes/VariableGenerator/VariableGenerator.php index 5f53c63cd..655c3e4fa 100644 --- a/includes/VariableGenerator/VariableGenerator.php +++ b/includes/VariableGenerator/VariableGenerator.php @@ -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; }