mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-13 17:27:20 +00:00
a04a601240
This service allows linking the EditFilterMergedContent and PageSaveComplete hooks for the same edit, so we can update rev IDs in the abuse_filter_log table. Having such a services also avoids two hacky static props, and should allow separating the hook handlers easily. Change-Id: I622d15225ee3af202cb5730a7112652aef8ca71a
97 lines
2.9 KiB
PHP
97 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\AbuseFilter;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Variables\VariableHolder;
|
|
use MediaWiki\Revision\RevisionRecord;
|
|
use RequestContext;
|
|
use Status;
|
|
use Title;
|
|
use User;
|
|
|
|
/**
|
|
* This class contains most of the business logic of AbuseFilter. It consists of
|
|
* static functions for generic use (mostly utility functions).
|
|
*/
|
|
class AbuseFilter {
|
|
|
|
/**
|
|
* @deprecated
|
|
* @todo Phase out
|
|
*/
|
|
public const HISTORY_MAPPINGS = [
|
|
'af_pattern' => 'afh_pattern',
|
|
'af_user' => 'afh_user',
|
|
'af_user_text' => 'afh_user_text',
|
|
'af_timestamp' => 'afh_timestamp',
|
|
'af_comments' => 'afh_comments',
|
|
'af_public_comments' => 'afh_public_comments',
|
|
'af_deleted' => 'afh_deleted',
|
|
'af_id' => 'afh_filter',
|
|
'af_group' => 'afh_group',
|
|
];
|
|
|
|
/**
|
|
* Returns an associative array of filters which were tripped
|
|
*
|
|
* @param VariableHolder $vars
|
|
* @param Title $title
|
|
* @param string $group The filter's group (as defined in $wgAbuseFilterValidGroups)
|
|
* @param string $mode 'execute' for edits and logs, 'stash' for cached matches
|
|
* @return bool[] Map of (integer filter ID => bool)
|
|
* @deprecated Since 1.34 This was meant to be internal!
|
|
* @codeCoverageIgnore Deprecated method
|
|
*/
|
|
public static function checkAllFilters(
|
|
VariableHolder $vars,
|
|
Title $title,
|
|
$group = 'default',
|
|
$mode = 'execute'
|
|
) {
|
|
$parser = AbuseFilterServices::getParserFactory()->newParser( $vars );
|
|
$user = RequestContext::getMain()->getUser();
|
|
$runnerFactory = AbuseFilterServices::getFilterRunnerFactory();
|
|
$runner = $runnerFactory->newRunner( $user, $title, $vars, $group );
|
|
$runner->parser = $parser;
|
|
return $runner->checkAllFilters();
|
|
}
|
|
|
|
/**
|
|
* @param VariableHolder $vars
|
|
* @param Title $title
|
|
* @param string $group The filter's group (as defined in $wgAbuseFilterValidGroups)
|
|
* @param User $user The user performing the action
|
|
* @return Status
|
|
* @deprecated Since 1.34 Get a FilterRunner instance and call run() on that, if you really need to.
|
|
* Or consider resolving the problem at its root, because you shouldn't need to call this manually.
|
|
* @codeCoverageIgnore Deprecated method
|
|
*/
|
|
public static function filterAction(
|
|
VariableHolder $vars, Title $title, $group, User $user
|
|
) {
|
|
$runnerFactory = AbuseFilterServices::getFilterRunnerFactory();
|
|
$runner = $runnerFactory->newRunner( $user, $title, $vars, $group );
|
|
return $runner->run();
|
|
}
|
|
|
|
/**
|
|
* Shortcut for checking whether $user can view the given revision, with mask
|
|
* SUPPRESSED_ALL.
|
|
*
|
|
* @note This assumes that a revision with the given ID exists
|
|
*
|
|
* @param RevisionRecord $revRec
|
|
* @param User $user
|
|
* @return bool
|
|
*/
|
|
public static function userCanViewRev( RevisionRecord $revRec, User $user ) : bool {
|
|
return $revRec->audienceCan(
|
|
RevisionRecord::SUPPRESSED_ALL,
|
|
RevisionRecord::FOR_THIS_USER,
|
|
$user
|
|
);
|
|
}
|
|
}
|
|
|
|
class_alias( AbuseFilter::class, 'AbuseFilter' );
|