MediaWiki master
DefaultTextConstraint.php
Go to the documentation of this file.
1<?php
8
13
24
25 public function __construct(
26 private readonly ShadowPageLoader $shadowPageLoader,
27 private readonly PageReference $title,
28 private readonly bool $allowBlank,
29 private readonly string $userProvidedText,
30 private readonly MessageSpecifier $submitButtonLabel,
31 ) {
32 }
33
34 public function checkConstraint(): PageEditStatus {
35 $defaultContent = $this->shadowPageLoader->get( $this->title )?->getPreloadContent();
36 // TODO: check whether JSON reserialization causes a mismatch
37 $defaultText = $defaultContent?->serialize() ?? '';
38 if ( !$this->allowBlank && $this->userProvidedText === $defaultText ) {
39 return PageEditStatus::newGood( self::AS_BLANK_ARTICLE )
40 ->setOK( false )
41 ->warning( 'blankarticle', $this->submitButtonLabel );
42 }
43 return PageEditStatus::newGood();
44 }
45
46}
Don't save a new page if it's blank or if it's a page with shadow content equal to the default,...
__construct(private readonly ShadowPageLoader $shadowPageLoader, private readonly PageReference $title, private readonly bool $allowBlank, private readonly string $userProvidedText, private readonly MessageSpecifier $submitButtonLabel,)
Abstract class for all constraints that can prevent edits.
Status returned by edit constraints and other page editing checks.
A service which loads shadow content, which is content that is displayed on a nonexistent page with a...
setOK( $ok)
Change operation status.
Interface for objects (potentially) representing a page that can be viewable and linked to on a wiki.