MediaWiki master
RevisionDeletedConstraint.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\EditPage\Constraint;
4
5use MediaWiki\PageEdit\PageEditAttemptState;
6use MediaWiki\PageEdit\PageEditStatus;
7use MediaWiki\Permissions\Authority;
8use MediaWiki\Revision\RevisionRecord;
9use MediaWiki\Revision\RevisionStoreRecord;
10use MediaWiki\Title\Title;
11
20
21 public function __construct(
22 private readonly PageEditAttemptState $editAttemptState,
23 private readonly int $oldId,
24 private readonly ?RevisionRecord $revisionRecord,
25 private readonly string $section,
26 private readonly Title $title,
27 private readonly Authority $authority,
28 ) {
29 }
30
34 public function checkConstraint(): PageEditStatus {
35 if ( $this->section === 'new' ) {
36 return PageEditStatus::newGood();
37 }
38
39 if ( $this->revisionRecord instanceof RevisionStoreRecord ) {
40 if ( !$this->revisionRecord->userCan( RevisionRecord::DELETED_TEXT, $this->authority ) ) {
41 return PageEditStatus::newFatal( 'rev-deleted-text-permission', $this->title->getPrefixedURL() )
42 ->setValue( self::AS_REVISION_WAS_DELETED );
43 } elseif ( $this->revisionRecord->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
44 // Let sysop know that this will make private content public if saved
45 $status = PageEditStatus::newGood( self::AS_REVISION_WAS_DELETED )
46 ->setOK( $this->editAttemptState->shouldIgnoreRevisionDeletedWarning() );
47 $this->editAttemptState->setIgnoreRevisionDeletedWarning( true );
48 return $status
49 ->warning( 'rev-deleted-text-view', $this->title->getPrefixedURL() )
50 ->setCanResubmit( true );
51 }
52 } elseif ( $this->title->exists() ) {
53 // Something went wrong, and the revision is missing
54 return PageEditStatus::newFatal( 'missing-revision', $this->oldId )
55 ->setValue( self::AS_REVISION_MISSING );
56 }
57
58 return PageEditStatus::newGood();
59 }
60}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:72
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()
PageEditStatus A status indicating failure or success. A status that is not OK indicates a failure an...
__construct(private readonly PageEditAttemptState $editAttemptState, private readonly int $oldId, private readonly ?RevisionRecord $revisionRecord, private readonly string $section, private readonly Title $title, private readonly Authority $authority,)
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.
Page revision base class.
A RevisionRecord representing an existing revision persisted in the revision table.
Represents a title within MediaWiki.
Definition Title.php:69
This interface represents the authority associated with the current execution context,...
Definition Authority.php:23