MediaWiki master
RevisionDeletedConstraint.php
Go to the documentation of this file.
1<?php
2
4
12
21
22 public function __construct(
23 private readonly Article $article,
24 private readonly bool $ignoreWarning,
25 private readonly int $oldId,
26 private readonly string $section,
27 private readonly Title $title,
28 private readonly User $user,
29 private readonly ?MessageValue $warningMessageWrapper = null,
30 ) {
31 }
32
36 public function checkConstraint(): EditPageStatus {
37 if ( $this->section === 'new' ) {
39 }
40
41 $revRecord = $this->article->fetchRevisionRecord();
42 if ( $revRecord instanceof RevisionStoreRecord ) {
43 if ( !$revRecord->userCan( RevisionRecord::DELETED_TEXT, $this->user ) ) {
44 return EditPageStatus::newFatal( 'rev-deleted-text-permission', $this->title->getPrefixedURL() )
45 ->setValue( self::AS_REVISION_WAS_DELETED );
46 } elseif ( $revRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
47 // Let sysop know that this will make private content public if saved
48 $status = EditPageStatus::newGood( self::AS_REVISION_WAS_DELETED );
49 $warningMessage = MessageValue::new(
50 'rev-deleted-text-view',
51 [ $this->title->getPrefixedURL() ]
52 );
53 // When saving the edit, explain the user how to proceed by wrapping the warning in another message
54 if ( $this->warningMessageWrapper !== null ) {
55 $warningMessage = $this->warningMessageWrapper->params( $warningMessage );
56 }
57 return $status->warning( $warningMessage )->setOK( $this->ignoreWarning );
58 }
59 } elseif ( $this->title->exists() ) {
60 // Something went wrong, and the revision is missing
61 return EditPageStatus::newFatal( 'missing-revision', $this->oldId )
62 ->setValue( self::AS_REVISION_MISSING );
63 }
64
66 }
67}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:69
Abstract class for all constraints that can prevent edits.
This constraint is used to display an error if the user loses access to the revision while editing it...
checkConstraint()
EditPageStatus A status indicating failure or success. A status that is not OK indicates a failure an...
__construct(private readonly Article $article, private readonly bool $ignoreWarning, private readonly int $oldId, private readonly string $section, private readonly Title $title, private readonly User $user, private readonly ?MessageValue $warningMessageWrapper=null,)
Status returned by edit constraints and other page editing checks.
Legacy class representing an editable page and handling UI for some page actions.
Definition Article.php:65
Page revision base class.
A RevisionRecord representing an existing revision persisted in the revision table.
Represents a title within MediaWiki.
Definition Title.php:69
User class for the MediaWiki software.
Definition User.php:130
static newFatal( $message,... $parameters)
Factory function for fatal errors.
static newGood( $value=null)
Factory function for good results.
Value object representing a message for i18n.