2020-06-03 00:43:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\AbuseFilter\Hooks;
|
|
|
|
|
|
|
|
use Content;
|
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;
|
|
|
|
use RecentChange;
|
|
|
|
use Title;
|
|
|
|
use User;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
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
|
|
|
*/
|
|
|
|
public function onAbuseFilterBuilder( array &$realValues ) {
|
|
|
|
return $this->hookContainer->run(
|
|
|
|
'AbuseFilter-builder',
|
|
|
|
[ &$realValues ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-02 14:03:15 +00:00
|
|
|
* @inheritDoc
|
2020-06-03 00:43:22 +00:00
|
|
|
*/
|
|
|
|
public function onAbuseFilterDeprecatedVariables( array &$deprecatedVariables ) {
|
|
|
|
return $this->hookContainer->run(
|
|
|
|
'AbuseFilter-deprecatedVariables',
|
|
|
|
[ &$deprecatedVariables ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-02 14:03:15 +00:00
|
|
|
* @inheritDoc
|
2020-06-03 00:43:22 +00:00
|
|
|
*/
|
|
|
|
public function onAbuseFilterComputeVariable(
|
|
|
|
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
|
|
|
*/
|
|
|
|
public function onAbuseFilterContentToString(
|
|
|
|
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
|
|
|
*/
|
|
|
|
public function onAbuseFilterFilterAction(
|
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
|
|
|
*/
|
|
|
|
public function onAbuseFilterGenerateTitleVars(
|
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
|
|
|
*/
|
|
|
|
public function onAbuseFilterGenerateUserVars(
|
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
|
|
|
*/
|
|
|
|
public function onAbuseFilterGenerateGenericVars(
|
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-02 14:03:15 +00:00
|
|
|
* @inheritDoc
|
2020-06-03 00:43:22 +00:00
|
|
|
*/
|
|
|
|
public function onAbuseFilterInterceptVariable(
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
public function onAbuseFilterGetDangerousActions( array &$actions ) : void {
|
|
|
|
$this->hookContainer->run(
|
|
|
|
'AbuseFilterGetDangerousActions',
|
|
|
|
[ &$actions ],
|
|
|
|
[ 'abortable' => false ]
|
|
|
|
);
|
|
|
|
}
|
2020-11-29 22:20:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function onAbuseFilterCustomActions( array &$actions ) : void {
|
|
|
|
$this->hookContainer->run(
|
|
|
|
'AbuseFilterCustomActions',
|
|
|
|
[ &$actions ],
|
|
|
|
[ 'abortable' => false ]
|
|
|
|
);
|
|
|
|
}
|
2020-06-03 00:43:22 +00:00
|
|
|
}
|