1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
namespace MediaWiki\Page\Event;
use MediaWiki\DomainEvent\DomainEvent;
use MediaWiki\Page\ProperPageIdentity;
use MediaWiki\User\UserIdentity;
use Wikimedia\Assert\Assert;
use Wikimedia\Timestamp\ConvertibleTimestamp;
/**
* Base class for domain events representing changes to page state.
*
* Page state events include life cycle changes to the page (e.g. create, move,
* delete) as well as changing a page's latest revision. They do not include
* changes to the page's revision history (except for changes to the latest
* revision).
*
* @unstable until 1.45
*/
abstract class PageStateEvent extends DomainEvent {
public const TYPE = 'PageState';
/**
* @var string This is a reconciliation event, triggered in order to give
* listeners an opportunity to catch up on missed events or recreate
* corrupted data. Can be triggered by a user action such as a null
* edit, or by a maintenance script.
*/
public const FLAG_RECONCILIATION_REQUEST = 'reconciliation';
private string $cause;
private ProperPageIdentity $page;
private UserIdentity $performer;
/** @var array<string,bool> */
private array $flags;
/** @var array<string> */
private array $tags;
/**
* @param string $cause See the self::CAUSE_XXX constants.
* @param ProperPageIdentity $page The page affected by the update.
* @param UserIdentity $performer The user performing the update.
* @param array<string> $tags Applicable tags, see ChangeTags.
* @param array<string,bool> $flags See the self::FLAG_XXX constants.
* @param string|ConvertibleTimestamp|false $timestamp
*/
public function __construct(
string $cause,
ProperPageIdentity $page,
UserIdentity $performer,
array $tags = [],
array $flags = [],
$timestamp = false
) {
parent::__construct(
$timestamp,
$flags[ self::FLAG_RECONCILIATION_REQUEST ] ?? false
);
$this->declareEventType( self::TYPE );
Assert::parameterElementType( 'string', $tags, '$tags' );
Assert::parameterKeyType( 'integer', $tags, '$tags' );
Assert::parameterElementType( 'boolean', $flags, '$flags' );
Assert::parameterKeyType( 'string', $flags, '$flags' );
$this->cause = $cause;
$this->page = $page;
$this->performer = $performer;
$this->tags = $tags;
$this->flags = $flags;
}
/**
* Returns the page that was edited.
*/
public function getPage(): ProperPageIdentity {
return $this->page;
}
/**
* Returns the user that performed the update.
* For an edit, this will be the same as the user returned by getAuthor().
* However, it may be a different user for update events caused e.g. by
* undeletion or imports.
*/
public function getPerformer(): UserIdentity {
return $this->performer;
}
/**
* Checks flags describing the page update.
* Use with FLAG_XXX constants declared by subclasses.
*/
protected function hasFlag( string $name ): bool {
return $this->flags[$name] ?? false;
}
/**
* Indicates the cause of the update.
* See the self::CAUSE_XXX constants.
* @return string
*/
public function getCause(): string {
return $this->cause;
}
/**
* Checks whether the update had the given cause.
*
* @see self::CAUSE_XXX constants
*/
public function hasCause( string $cause ): bool {
return $this->cause === $cause;
}
/**
* Returns any tags applied to the edit.
* @see ChangeTags
*/
public function getTags(): array {
return $this->tags;
}
/**
* Checks for a tag associated the page update.
*
* @see ChangeTags
*/
public function hasTag( string $name ): bool {
return in_array( $name, $this->tags );
}
}
|