MediaWiki  master
MediaWiki\Permissions\RateLimiter Class Reference

Provides rate limiting for a set of actions based on several counter buckets. More...

Public Member Functions

 __construct (ServiceOptions $options, WRStatsFactory $wrstatsFactory, ?CentralIdLookup $centralIdLookup, UserFactory $userFactory, UserGroupManager $userGroupManager, HookContainer $hookContainer)
 
 isExempt (RateLimitSubject $subject)
 Is this user exempt from rate limiting? More...
 
 limit (RateLimitSubject $subject, string $action, int $incrBy=1)
 Implements simple rate limits: enforce maximum actions per time period to put a brake on flooding. More...
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 

Detailed Description

Provides rate limiting for a set of actions based on several counter buckets.

Since
1.39

Definition at line 42 of file RateLimiter.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Permissions\RateLimiter::__construct ( ServiceOptions  $options,
WRStatsFactory  $wrstatsFactory,
?CentralIdLookup  $centralIdLookup,
UserFactory  $userFactory,
UserGroupManager  $userGroupManager,
HookContainer  $hookContainer 
)
Parameters
ServiceOptions$options
WRStatsFactory$wrstatsFactory
CentralIdLookup | null$centralIdLookup
UserFactory$userFactory
UserGroupManager$userGroupManager
HookContainer$hookContainer

Definition at line 84 of file RateLimiter.php.

References MediaWiki\Config\ServiceOptions\assertRequiredOptions(), MediaWiki\Logger\LoggerFactory\getInstance(), and MediaWiki\MainConfigNames\RateLimits.

Member Function Documentation

◆ isExempt()

MediaWiki\Permissions\RateLimiter::isExempt ( RateLimitSubject  $subject)

Is this user exempt from rate limiting?

Parameters
RateLimitSubject$subjectThe subject of the rate limit, representing the client performing the action.
Returns
bool

Definition at line 113 of file RateLimiter.php.

References MediaWiki\Permissions\RateLimitSubject\getIP(), MediaWiki\Permissions\RateLimitSubject\is(), and MediaWiki\MainConfigNames\RateLimitsExcludedIPs.

Referenced by MediaWiki\Permissions\RateLimiter\limit().

◆ limit()

MediaWiki\Permissions\RateLimiter::limit ( RateLimitSubject  $subject,
string  $action,
int  $incrBy = 1 
)

Implements simple rate limits: enforce maximum actions per time period to put a brake on flooding.

Parameters
RateLimitSubject$subjectThe subject of the rate limit, representing the client performing the action.
string$actionAction to enforce
int$incrByPositive amount to increment counter by, 1 per default. Use 0 to check the limit without bumping the counter.
Returns
bool True if a rate limit was exceeded.

Definition at line 140 of file RateLimiter.php.

References $type, CentralIdLookup\AUDIENCE_RAW, MediaWiki\Permissions\RateLimitSubject\getIP(), MediaWiki\Permissions\RateLimitSubject\getUser(), MediaWiki\Permissions\RateLimitSubject\is(), and MediaWiki\Permissions\RateLimiter\isExempt().

Member Data Documentation

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\Permissions\RateLimiter::CONSTRUCTOR_OPTIONS
Initial value:
= [
]
const RateLimitsExcludedIPs
Name constant for the RateLimitsExcludedIPs setting, for use with Config::get()
const RateLimits
Name constant for the RateLimits setting, for use with Config::get()
Access: internal

Definition at line 71 of file RateLimiter.php.


The documentation for this class was generated from the following file: