2020-06-03 00:43:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\AbuseFilter\Hooks;
|
|
|
|
|
2024-10-19 19:55:40 +00:00
|
|
|
use MediaWiki\Content\Content;
|
2021-01-31 16:27:36 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\VariableGenerator\RCVariableGenerator;
|
2021-01-02 14:01:00 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\Variables\VariableHolder;
|
2020-06-03 00:43:22 +00:00
|
|
|
use MediaWiki\HookContainer\HookContainer;
|
2023-08-19 17:49:36 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-12-10 19:03:19 +00:00
|
|
|
use MediaWiki\User\User;
|
2020-06-03 00:43:22 +00:00
|
|
|
use RecentChange;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle running AbuseFilter's hooks
|
|
|
|
* @author DannyS712
|
|
|
|
*/
|
|
|
|
class AbuseFilterHookRunner implements
|
|
|
|
AbuseFilterAlterVariablesHook,
|
|
|
|
AbuseFilterBuilderHook,
|
|
|
|
AbuseFilterComputeVariableHook,
|
|
|
|
AbuseFilterContentToStringHook,
|
2020-11-29 22:20:32 +00:00
|
|
|
AbuseFilterCustomActionsHook,
|
2020-06-03 00:43:22 +00:00
|
|
|
AbuseFilterDeprecatedVariablesHook,
|
|
|
|
AbuseFilterFilterActionHook,
|
|
|
|
AbuseFilterGenerateGenericVarsHook,
|
|
|
|
AbuseFilterGenerateTitleVarsHook,
|
|
|
|
AbuseFilterGenerateUserVarsHook,
|
2021-01-31 16:27:36 +00:00
|
|
|
AbuseFilterGenerateVarsForRecentChangeHook,
|
2020-06-03 00:43:22 +00:00
|
|
|
AbuseFilterInterceptVariableHook,
|
2018-09-22 10:18:50 +00:00
|
|
|
AbuseFilterShouldFilterActionHook,
|
|
|
|
AbuseFilterGetDangerousActionsHook
|
2020-06-03 00:43:22 +00:00
|
|
|
{
|
2021-01-09 13:40:10 +00:00
|
|
|
public const SERVICE_NAME = 'AbuseFilterHookRunner';
|
2020-06-03 00:43:22 +00:00
|
|
|
|
|
|
|
/** @var HookContainer */
|
|
|
|
private $hookContainer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param HookContainer $hookContainer
|
|
|
|
*/
|
|
|
|
public function __construct( HookContainer $hookContainer ) {
|
|
|
|
$this->hookContainer = $hookContainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-02 14:03:15 +00:00
|
|
|
* @inheritDoc
|
2020-06-03 00:43:22 +00:00
|
|
|
*/
|
2021-03-06 17:18:07 +00:00
|
|
|
public function onAbuseFilter_builder( array &$realValues ) {
|
2020-06-03 00:43:22 +00:00
|
|
|
return $this->hookContainer->run(
|
|
|
|
'AbuseFilter-builder',
|
|
|
|
[ &$realValues ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-02 14:03:15 +00:00
|
|
|
* @inheritDoc
|
2020-06-03 00:43:22 +00:00
|
|
|
*/
|
2021-03-06 17:18:07 +00:00
|
|
|
public function onAbuseFilter_deprecatedVariables( array &$deprecatedVariables ) {
|
2020-06-03 00:43:22 +00:00
|
|
|
return $this->hookContainer->run(
|
|
|
|
'AbuseFilter-deprecatedVariables',
|
|
|
|
[ &$deprecatedVariables ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-02 14:03:15 +00:00
|
|
|
* @inheritDoc
|
2020-06-03 00:43:22 +00:00
|
|
|
*/
|
2021-03-06 17:18:07 +00:00
|
|
|
public function onAbuseFilter_computeVariable(
|
2020-06-03 00:43:22 +00:00
|
|
|
string $method,
|
2021-01-02 14:01:00 +00:00
|
|
|
VariableHolder $vars,
|
2020-06-03 00:43:22 +00:00
|
|
|
array $parameters,
|
|
|
|
?string &$result
|
|
|
|
) {
|
|
|
|
return $this->hookContainer->run(
|
|
|
|
'AbuseFilter-computeVariable',
|
|
|
|
[ $method, $vars, $parameters, &$result ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-02 14:03:15 +00:00
|
|
|
* @inheritDoc
|
2020-06-03 00:43:22 +00:00
|
|
|
*/
|
2021-03-06 17:18:07 +00:00
|
|
|
public function onAbuseFilter_contentToString(
|
2020-06-03 00:43:22 +00:00
|
|
|
Content $content,
|
|
|
|
?string &$text
|
|
|
|
) {
|
|
|
|
return $this->hookContainer->run(
|
|
|
|
'AbuseFilter-contentToString',
|
|
|
|
[ $content, &$text ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-02 14:03:15 +00:00
|
|
|
* @inheritDoc
|
2020-06-03 00:43:22 +00:00
|
|
|
*/
|
2021-03-06 17:18:07 +00:00
|
|
|
public function onAbuseFilter_filterAction(
|
2021-01-02 14:01:00 +00:00
|
|
|
VariableHolder &$vars,
|
2020-06-03 00:43:22 +00:00
|
|
|
Title $title
|
|
|
|
) {
|
|
|
|
return $this->hookContainer->run(
|
|
|
|
'AbuseFilter-filterAction',
|
|
|
|
[ &$vars, $title ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-02 14:03:15 +00:00
|
|
|
* @inheritDoc
|
2020-06-03 00:43:22 +00:00
|
|
|
*/
|
|
|
|
public function onAbuseFilterAlterVariables(
|
2021-01-02 14:01:00 +00:00
|
|
|
VariableHolder &$vars,
|
2020-06-03 00:43:22 +00:00
|
|
|
Title $title,
|
|
|
|
User $user
|
|
|
|
) {
|
|
|
|
return $this->hookContainer->run(
|
|
|
|
'AbuseFilterAlterVariables',
|
|
|
|
[ &$vars, $title, $user ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-02 14:03:15 +00:00
|
|
|
* @inheritDoc
|
2020-06-03 00:43:22 +00:00
|
|
|
*/
|
2021-03-06 17:18:07 +00:00
|
|
|
public function onAbuseFilter_generateTitleVars(
|
2021-01-02 14:01:00 +00:00
|
|
|
VariableHolder $vars,
|
2020-06-03 00:43:22 +00:00
|
|
|
Title $title,
|
|
|
|
string $prefix,
|
|
|
|
?RecentChange $rc
|
|
|
|
) {
|
|
|
|
return $this->hookContainer->run(
|
|
|
|
'AbuseFilter-generateTitleVars',
|
|
|
|
[ $vars, $title, $prefix, $rc ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-02 14:03:15 +00:00
|
|
|
* @inheritDoc
|
2020-06-03 00:43:22 +00:00
|
|
|
*/
|
2021-03-06 17:18:07 +00:00
|
|
|
public function onAbuseFilter_generateUserVars(
|
2021-01-02 14:01:00 +00:00
|
|
|
VariableHolder $vars,
|
2020-06-03 00:43:22 +00:00
|
|
|
User $user,
|
|
|
|
?RecentChange $rc
|
|
|
|
) {
|
|
|
|
return $this->hookContainer->run(
|
2020-09-24 14:40:03 +00:00
|
|
|
'AbuseFilter-generateUserVars',
|
2020-06-03 00:43:22 +00:00
|
|
|
[ $vars, $user, $rc ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-02 14:03:15 +00:00
|
|
|
* @inheritDoc
|
2020-06-03 00:43:22 +00:00
|
|
|
*/
|
2021-03-06 17:18:07 +00:00
|
|
|
public function onAbuseFilter_generateGenericVars(
|
2021-01-02 14:01:00 +00:00
|
|
|
VariableHolder $vars,
|
2020-06-03 00:43:22 +00:00
|
|
|
?RecentChange $rc
|
|
|
|
) {
|
|
|
|
return $this->hookContainer->run(
|
|
|
|
'AbuseFilter-generateGenericVars',
|
|
|
|
[ $vars, $rc ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-31 16:27:36 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function onAbuseFilterGenerateVarsForRecentChange(
|
|
|
|
RCVariableGenerator $generator,
|
|
|
|
RecentChange $rc,
|
|
|
|
VariableHolder $vars,
|
|
|
|
User $contextUser
|
|
|
|
) {
|
|
|
|
return $this->hookContainer->run(
|
2021-03-06 16:12:04 +00:00
|
|
|
'AbuseFilterGenerateVarsForRecentChange',
|
2021-01-31 16:27:36 +00:00
|
|
|
[ $generator, $rc, $vars, $contextUser ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-06-03 00:43:22 +00:00
|
|
|
/**
|
2021-01-02 14:03:15 +00:00
|
|
|
* @inheritDoc
|
2020-06-03 00:43:22 +00:00
|
|
|
*/
|
2021-03-06 17:18:07 +00:00
|
|
|
public function onAbuseFilter_interceptVariable(
|
2020-06-03 00:43:22 +00:00
|
|
|
string $method,
|
2021-01-02 14:01:00 +00:00
|
|
|
VariableHolder $vars,
|
2020-06-03 00:43:22 +00:00
|
|
|
array $parameters,
|
|
|
|
&$result
|
|
|
|
) {
|
|
|
|
return $this->hookContainer->run(
|
|
|
|
'AbuseFilter-interceptVariable',
|
|
|
|
[ $method, $vars, $parameters, &$result ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-02 14:03:15 +00:00
|
|
|
* @inheritDoc
|
2020-06-03 00:43:22 +00:00
|
|
|
*/
|
|
|
|
public function onAbuseFilterShouldFilterAction(
|
2021-01-02 14:01:00 +00:00
|
|
|
VariableHolder $vars,
|
2020-06-03 00:43:22 +00:00
|
|
|
Title $title,
|
|
|
|
User $user,
|
|
|
|
array &$skipReasons
|
|
|
|
) {
|
|
|
|
return $this->hookContainer->run(
|
|
|
|
'AbuseFilterShouldFilterAction',
|
|
|
|
[ $vars, $title, $user, &$skipReasons ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-22 10:18:50 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2021-07-21 18:51:12 +00:00
|
|
|
public function onAbuseFilterGetDangerousActions( array &$actions ): void {
|
2018-09-22 10:18:50 +00:00
|
|
|
$this->hookContainer->run(
|
|
|
|
'AbuseFilterGetDangerousActions',
|
|
|
|
[ &$actions ],
|
|
|
|
[ 'abortable' => false ]
|
|
|
|
);
|
|
|
|
}
|
2020-11-29 22:20:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2021-07-21 18:51:12 +00:00
|
|
|
public function onAbuseFilterCustomActions( array &$actions ): void {
|
2020-11-29 22:20:32 +00:00
|
|
|
$this->hookContainer->run(
|
|
|
|
'AbuseFilterCustomActions',
|
|
|
|
[ &$actions ],
|
|
|
|
[ 'abortable' => false ]
|
|
|
|
);
|
|
|
|
}
|
2020-06-03 00:43:22 +00:00
|
|
|
}
|