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?
 
 isLimitable ( $action)
 Checks whether the given action may be limited.
 
 limit (RateLimitSubject $subject, string $action, int $incrBy=1)
 Implements simple rate limits: enforce maximum actions per time period to put a brake on flooding.
 
 setStats (StatsdDataFactoryInterface $stats)
 

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 44 of file RateLimiter.php.

Constructor & Destructor Documentation

◆ __construct()

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

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 125 of file RateLimiter.php.

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

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

◆ isLimitable()

MediaWiki\Permissions\RateLimiter::isLimitable ( $action)

Checks whether the given action may be limited.

Can be used for optimization, to avoid calling limit() if we can know in advance that no limit will apply.

Parameters
string$action
Returns
bool

Definition at line 148 of file RateLimiter.php.

◆ 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.

Note
This method will always return false for any action listed in $this->nonLimitableActions. This allows rate limit checks to be bypassed for certain actions to avoid overhead and improve performance.
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 by default. Use 0 to check the limit without bumping the counter.
Returns
bool True if a rate limit was exceeded.

Definition at line 183 of file RateLimiter.php.

References MediaWiki\Permissions\RateLimitSubject\getIP(), MediaWiki\Permissions\RateLimitSubject\getUser(), MediaWiki\Permissions\RateLimitSubject\is(), and MediaWiki\Permissions\RateLimiter\isExempt().

◆ setStats()

MediaWiki\Permissions\RateLimiter::setStats ( StatsdDataFactoryInterface $stats)

Definition at line 109 of file RateLimiter.php.

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 81 of file RateLimiter.php.


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