aboutsummaryrefslogtreecommitdiffstats
path: root/includes/editpage/Constraint/UserRateLimitConstraint.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/editpage/Constraint/UserRateLimitConstraint.php')
-rw-r--r--includes/editpage/Constraint/UserRateLimitConstraint.php46
1 files changed, 21 insertions, 25 deletions
diff --git a/includes/editpage/Constraint/UserRateLimitConstraint.php b/includes/editpage/Constraint/UserRateLimitConstraint.php
index db064f067920..d21409a95a84 100644
--- a/includes/editpage/Constraint/UserRateLimitConstraint.php
+++ b/includes/editpage/Constraint/UserRateLimitConstraint.php
@@ -20,8 +20,8 @@
namespace MediaWiki\EditPage\Constraint;
-use MediaWiki\Title\Title;
-use MediaWiki\User\User;
+use MediaWiki\Permissions\RateLimiter;
+use MediaWiki\Permissions\RateLimitSubject;
use StatusValue;
/**
@@ -33,43 +33,39 @@ use StatusValue;
*/
class UserRateLimitConstraint implements IEditConstraint {
- /** @var User */
- private $user;
+ private RateLimitSubject $subject;
+ private string $oldContentModel;
+ private string $newContentModel;
+ private RateLimiter $limiter;
- /** @var Title */
- private $title;
+ private string $result;
- /** @var string */
- private $newContentModel;
-
- /** @var string|null */
- private $result;
-
- /**
- * @param User $user
- * @param Title $title
- * @param string $newContentModel
- */
public function __construct(
- User $user,
- Title $title,
+ RateLimiter $limiter,
+ RateLimitSubject $subject,
+ string $oldContentModel,
string $newContentModel
) {
- $this->user = $user;
- $this->title = $title;
+ $this->limiter = $limiter;
+ $this->subject = $subject;
+ $this->oldContentModel = $oldContentModel;
$this->newContentModel = $newContentModel;
}
+ private function limit( string $action, int $inc = 1 ) {
+ return $this->limiter->limit( $this->subject, $action, $inc );
+ }
+
public function checkConstraint(): string {
// Need to check for rate limits on `editcontentmodel` if it is changing
- $contentModelChange = ( $this->newContentModel !== $this->title->getContentModel() );
+ $contentModelChange = ( $this->newContentModel !== $this->oldContentModel );
// TODO inject and use a ThrottleStore once available, see T261744
// Checking if the user is rate limited increments the counts, so we cannot perform
// the check again when getting the status; thus, store the result
- if ( $this->user->pingLimiter()
- || $this->user->pingLimiter( 'linkpurge', 0 ) // only counted after the fact
- || ( $contentModelChange && $this->user->pingLimiter( 'editcontentmodel' ) )
+ if ( $this->limit( 'edit' )
+ || $this->limit( 'linkpurge', 0 ) // only counted after the fact
+ || ( $contentModelChange && $this->limit( 'editcontentmodel' ) )
) {
$this->result = self::CONSTRAINT_FAILED;
} else {