MediaWiki REL1_39
UserRateLimitConstraint.php
Go to the documentation of this file.
1<?php
22
23use StatusValue;
24use Title;
25use User;
26
35
37 private $user;
38
40 private $title;
41
43 private $newContentModel;
44
46 private $result;
47
53 public function __construct(
54 User $user,
55 Title $title,
56 string $newContentModel
57 ) {
58 $this->user = $user;
59 $this->title = $title;
60 $this->newContentModel = $newContentModel;
61 }
62
63 public function checkConstraint(): string {
64 // Need to check for rate limits on `editcontentmodel` if it is changing
65 $contentModelChange = ( $this->newContentModel !== $this->title->getContentModel() );
66
67 // TODO inject and use a ThrottleStore once available, see T261744
68 // Checking if the user is rate limited increments the counts, so we cannot perform
69 // the check again when getting the status; thus, store the result
70 if ( $this->user->pingLimiter()
71 || $this->user->pingLimiter( 'linkpurge', 0 ) // only counted after the fact
72 || ( $contentModelChange && $this->user->pingLimiter( 'editcontentmodel' ) )
73 ) {
74 $this->result = self::CONSTRAINT_FAILED;
75 } else {
76 $this->result = self::CONSTRAINT_PASSED;
77 }
78
79 return $this->result;
80 }
81
82 public function getLegacyStatus(): StatusValue {
83 $statusValue = StatusValue::newGood();
84
85 if ( $this->result === self::CONSTRAINT_FAILED ) {
86 $statusValue->fatal( 'actionthrottledtext' );
87 $statusValue->value = self::AS_RATE_LIMITED;
88 }
89
90 return $statusValue;
91 }
92
93}
getLegacyStatus()
Get the legacy status for failure (or success)
__construct(User $user, Title $title, string $newContentModel)
Generic operation result class Has warning/error list, boolean status and arbitrary value.
fatal( $message,... $parameters)
Add an error and set OK to false, indicating that the operation as a whole was fatal.
Represents a title within MediaWiki.
Definition Title.php:49
internal since 1.36
Definition User.php:70
Interface for all constraints that can prevent edits.