MediaWiki master
ExistingSectionEditConstraint.php
Go to the documentation of this file.
1<?php
6
7namespace MediaWiki\EditPage\Constraint;
8
9use MediaWiki\Content\Content;
10use MediaWiki\PageEdit\PageEditAttemptState;
11use MediaWiki\PageEdit\PageEditStatus;
12
36
37 public function __construct(
38 private readonly string $section,
39 private readonly string $userSummary,
40 private readonly string $autoSummary,
41 private readonly bool $forceEditSummary,
42 private readonly Content $newContent,
43 private readonly ?Content $originalContent,
44 private readonly PageEditAttemptState $editAttemptState,
45 ) {
46 }
47
48 public function checkConstraint(): PageEditStatus {
49 if ( $this->section === 'new' ) {
50 // Constraint is not applicable
51 return PageEditStatus::newGood();
52 }
53
54 if (
55 $this->forceEditSummary &&
56 !$this->editAttemptState->shouldAllowBlankSummary() &&
57 !$this->newContent->equals( $this->originalContent ) &&
58 !$this->newContent->isRedirect() &&
59 md5( $this->userSummary ) === $this->autoSummary
60 ) {
61 $this->editAttemptState->setAllowBlankSummary( true );
62 return PageEditStatus::newGood()
63 ->setResult( false, self::AS_SUMMARY_NEEDED )
64 ->setCanResubmit( true )
65 ->warning( 'edit-constraint-missingsummary-warning' );
66 }
67
68 return PageEditStatus::newGood();
69 }
70
71}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:72
Abstract class for all constraints that can prevent edits.
To simplify the logic in EditPage, this constraint may be created even if the section being edited do...
__construct(private readonly string $section, private readonly string $userSummary, private readonly string $autoSummary, private readonly bool $forceEditSummary, private readonly Content $newContent, private readonly ?Content $originalContent, private readonly PageEditAttemptState $editAttemptState,)
Data returned by an edit attempt that can be passed to the next one to allow bypassing certain warnin...
Status returned by edit constraints and other page editing checks.
Content objects represent page content, e.g.
Definition Content.php:28