MediaWiki master
AccidentalRecreationConstraint.php
Go to the documentation of this file.
1<?php
8
18
27
28 public function __construct(
29 private readonly IConnectionProvider $connectionProvider,
30 private readonly LogFormatterFactory $logFormatterFactory,
31 private readonly Title $title,
32 private readonly bool $allowRecreation,
33 private readonly ?string $startTime,
34 private readonly ?string $submitButtonLabel,
35 ) {
36 }
37
38 public function checkConstraint(): EditPageStatus {
39 if ( $this->allowRecreation ) {
41 }
42 $deletion = $this->getDeletionSinceLastEdit();
43 if ( $deletion ) {
44 if ( $this->submitButtonLabel ) {
45 $logFormatter = $this->logFormatterFactory->newFromEntry( $deletion );
46 $username = $deletion->isDeleted( LogPage::DELETED_USER )
47 ? MessageValue::new( 'rev-deleted-user' )
48 : $deletion->getPerformerIdentity()->getName();
49 $commentHtml = $logFormatter->getComment();
50
51 return EditPageStatus::newGood( self::AS_ARTICLE_WAS_DELETED )
52 ->setOK( false )
53 ->warning(
54 $commentHtml === ''
55 ? 'edit-constraint-confirmrecreate-noreason'
56 : 'edit-constraint-confirmrecreate',
57 $username,
58 Message::rawParam( $commentHtml ),
59 new MessageValue( $this->submitButtonLabel ),
60 );
61 } else {
62 return EditPageStatus::newGood( self::AS_ARTICLE_WAS_DELETED )
63 ->setOK( false )
64 ->warning( 'deletedwhileediting' );
65 }
66 }
68 }
69
74 private function getDeletionSinceLastEdit(): ?DatabaseLogEntry {
75 if ( !$this->title->exists() && $this->title->hasDeletedEdits() ) {
76 $lastDelete = $this->getLastDelete();
77 if ( $lastDelete && $lastDelete->getTimestamp() > $this->startTime ) {
78 return $lastDelete;
79 }
80 }
81 return null;
82 }
83
88 private function getLastDelete(): ?DatabaseLogEntry {
89 $dbr = $this->connectionProvider->getReplicaDatabase();
90 $row = DatabaseLogEntry::newSelectQueryBuilder( $dbr )
91 ->where( [
92 'log_namespace' => $this->title->getNamespace(),
93 'log_title' => $this->title->getDBkey(),
94 'log_type' => 'delete',
95 'log_action' => 'delete',
96 ] )
97 ->orderBy( [ 'log_timestamp', 'log_id' ], SelectQueryBuilder::SORT_DESC )
98 ->caller( __METHOD__ )
99 ->fetchRow();
100
101 return $row ? DatabaseLogEntry::newFromRow( $row ) : null;
102 }
103
104}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:69
Make sure user doesn't accidentally recreate a page deleted after they started editing.
__construct(private readonly IConnectionProvider $connectionProvider, private readonly LogFormatterFactory $logFormatterFactory, private readonly Title $title, private readonly bool $allowRecreation, private readonly ?string $startTime, private readonly ?string $submitButtonLabel,)
Abstract class for all constraints that can prevent edits.
Status returned by edit constraints and other page editing checks.
A value class to process existing log entries.
Class to simplify the use of log pages.
Definition LogPage.php:35
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:144
Represents a title within MediaWiki.
Definition Title.php:69
static newGood( $value=null)
Factory function for good results.
Value object representing a message for i18n.
Build SELECT queries with a fluent interface.
Provide primary and replica IDatabase connections.