mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-15 02:03:53 +00:00
6e27a9ddb3
Change-Id: I20a7fe1a40255043ed0d125dee61ea6052dda69c
225 lines
4.3 KiB
PHP
225 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\AbuseFilter\Hooks;
|
|
|
|
use Content;
|
|
use MediaWiki\Extension\AbuseFilter\Variables\VariableHolder;
|
|
use MediaWiki\HookContainer\HookContainer;
|
|
use MediaWiki\MediaWikiServices;
|
|
use RecentChange;
|
|
use Title;
|
|
use User;
|
|
|
|
/**
|
|
* Handle running AbuseFilter's hooks
|
|
* @author DannyS712
|
|
*/
|
|
class AbuseFilterHookRunner implements
|
|
AbuseFilterAlterVariablesHook,
|
|
AbuseFilterBuilderHook,
|
|
AbuseFilterComputeVariableHook,
|
|
AbuseFilterContentToStringHook,
|
|
AbuseFilterCustomActionsHook,
|
|
AbuseFilterDeprecatedVariablesHook,
|
|
AbuseFilterFilterActionHook,
|
|
AbuseFilterGenerateGenericVarsHook,
|
|
AbuseFilterGenerateTitleVarsHook,
|
|
AbuseFilterGenerateUserVarsHook,
|
|
AbuseFilterInterceptVariableHook,
|
|
AbuseFilterShouldFilterActionHook,
|
|
AbuseFilterGetDangerousActionsHook
|
|
{
|
|
|
|
/** @var HookContainer */
|
|
private $hookContainer;
|
|
|
|
/**
|
|
* @param HookContainer $hookContainer
|
|
*/
|
|
public function __construct( HookContainer $hookContainer ) {
|
|
$this->hookContainer = $hookContainer;
|
|
}
|
|
|
|
/**
|
|
* Convenience getter for static contexts
|
|
*
|
|
* See also core's Hooks::runner
|
|
*
|
|
* @return AbuseFilterHookRunner
|
|
*/
|
|
public static function getRunner() : AbuseFilterHookRunner {
|
|
return new AbuseFilterHookRunner(
|
|
MediaWikiServices::getInstance()->getHookContainer()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function onAbuseFilterBuilder( array &$realValues ) {
|
|
return $this->hookContainer->run(
|
|
'AbuseFilter-builder',
|
|
[ &$realValues ]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function onAbuseFilterDeprecatedVariables( array &$deprecatedVariables ) {
|
|
return $this->hookContainer->run(
|
|
'AbuseFilter-deprecatedVariables',
|
|
[ &$deprecatedVariables ]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function onAbuseFilterComputeVariable(
|
|
string $method,
|
|
VariableHolder $vars,
|
|
array $parameters,
|
|
?string &$result
|
|
) {
|
|
return $this->hookContainer->run(
|
|
'AbuseFilter-computeVariable',
|
|
[ $method, $vars, $parameters, &$result ]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function onAbuseFilterContentToString(
|
|
Content $content,
|
|
?string &$text
|
|
) {
|
|
return $this->hookContainer->run(
|
|
'AbuseFilter-contentToString',
|
|
[ $content, &$text ]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function onAbuseFilterFilterAction(
|
|
VariableHolder &$vars,
|
|
Title $title
|
|
) {
|
|
return $this->hookContainer->run(
|
|
'AbuseFilter-filterAction',
|
|
[ &$vars, $title ]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function onAbuseFilterAlterVariables(
|
|
VariableHolder &$vars,
|
|
Title $title,
|
|
User $user
|
|
) {
|
|
return $this->hookContainer->run(
|
|
'AbuseFilterAlterVariables',
|
|
[ &$vars, $title, $user ]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function onAbuseFilterGenerateTitleVars(
|
|
VariableHolder $vars,
|
|
Title $title,
|
|
string $prefix,
|
|
?RecentChange $rc
|
|
) {
|
|
return $this->hookContainer->run(
|
|
'AbuseFilter-generateTitleVars',
|
|
[ $vars, $title, $prefix, $rc ]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function onAbuseFilterGenerateUserVars(
|
|
VariableHolder $vars,
|
|
User $user,
|
|
?RecentChange $rc
|
|
) {
|
|
return $this->hookContainer->run(
|
|
'AbuseFilter-generateUserVars',
|
|
[ $vars, $user, $rc ]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function onAbuseFilterGenerateGenericVars(
|
|
VariableHolder $vars,
|
|
?RecentChange $rc
|
|
) {
|
|
return $this->hookContainer->run(
|
|
'AbuseFilter-generateGenericVars',
|
|
[ $vars, $rc ]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function onAbuseFilterInterceptVariable(
|
|
string $method,
|
|
VariableHolder $vars,
|
|
array $parameters,
|
|
&$result
|
|
) {
|
|
return $this->hookContainer->run(
|
|
'AbuseFilter-interceptVariable',
|
|
[ $method, $vars, $parameters, &$result ]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function onAbuseFilterShouldFilterAction(
|
|
VariableHolder $vars,
|
|
Title $title,
|
|
User $user,
|
|
array &$skipReasons
|
|
) {
|
|
return $this->hookContainer->run(
|
|
'AbuseFilterShouldFilterAction',
|
|
[ $vars, $title, $user, &$skipReasons ]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function onAbuseFilterGetDangerousActions( array &$actions ) : void {
|
|
$this->hookContainer->run(
|
|
'AbuseFilterGetDangerousActions',
|
|
[ &$actions ],
|
|
[ 'abortable' => false ]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function onAbuseFilterCustomActions( array &$actions ) : void {
|
|
$this->hookContainer->run(
|
|
'AbuseFilterCustomActions',
|
|
[ &$actions ],
|
|
[ 'abortable' => false ]
|
|
);
|
|
}
|
|
}
|