24 use Psr\Log\LoggerInterface;
25 use Wikimedia\Assert\Assert;
46 private $constraints = [];
53 private $failedConstraint =
false;
75 $this->constraints[] = $constraint;
87 foreach ( $this->constraints as $constraint ) {
89 if ( $result !== IEditConstraint::CONSTRAINT_PASSED ) {
92 'Checked {name}, got result: {result}',
94 'name' => $this->getConstraintName( $constraint ),
99 $this->failedConstraint = $constraint;
104 $this->logger->debug(
105 'Checked {name}, got result: {result}',
107 'name' => $this->getConstraintName( $constraint ),
119 private function getConstraintName(
IEditConstraint $constraint ): string {
121 $fullClassName = explode(
'\\', get_class( $constraint ) );
122 $constraintName = end( $fullClassName );
128 $constraintName .=
' ' . $constraint->getType();
130 return $constraintName;
139 Assert::precondition(
140 $this->failedConstraint !== false,
141 'getFailedConstraint called with no failed constraint'
143 return $this->failedConstraint;
Back end to process the edit constraints.
addConstraint(IEditConstraint $constraint)
Add a constraint to check.
getFailedConstraint()
Get the constraint that failed.
checkConstraints()
Run constraint checks.
__construct()
Create a new runner.
Verify the page isn't larger than the maximum.
Interface for all constraints that can prevent edits.