MediaWiki master
RevisionDeleter.php
Go to the documentation of this file.
1<?php
11
12use InvalidArgumentException;
18
30 private const ALLOWED_TYPES = [
31 'revision' => [
32 'class' => RevDelRevisionList::class,
33 'services' => [
34 'DBLoadBalancerFactory',
35 'HookContainer',
36 'HTMLCacheUpdater',
37 'RevisionStore',
38 'DomainEventDispatcher',
39 'ChangeTagsFormatter',
40 ],
41 ],
42 'archive' => [
43 'class' => RevDelArchiveList::class,
44 'services' => [
45 'DBLoadBalancerFactory',
46 'HookContainer',
47 'HTMLCacheUpdater',
48 'RevisionStore',
49 'DomainEventDispatcher',
50 'ChangeTagsFormatter',
51 ],
52 ],
53 'oldimage' => [
54 'class' => RevDelFileList::class,
55 'services' => [
56 'DBLoadBalancerFactory',
57 'HTMLCacheUpdater',
58 'RepoGroup',
59 ],
60 ],
61 'filearchive' => [
62 'class' => RevDelArchivedFileList::class,
63 'services' => [
64 'DBLoadBalancerFactory',
65 'HTMLCacheUpdater',
66 'RepoGroup',
67 ],
68 ],
69 'logging' => [
70 'class' => RevDelLogList::class,
71 'services' => [
72 'DBLoadBalancerFactory',
73 'CommentStore',
74 'LogFormatterFactory',
75 'ChangeTagsFormatter',
76 ],
77 ],
78 ];
79
81 private const DEPRECATED_TYPE_MAP = [
82 'oldid' => 'revision',
83 'artimestamp' => 'archive',
84 'oldimage' => 'oldimage',
85 'fileid' => 'filearchive',
86 'logid' => 'logging',
87 ];
88
95 public static function getTypes() {
96 return array_keys( self::ALLOWED_TYPES );
97 }
98
106 public static function getCanonicalTypeName( $typeName ) {
107 if ( isset( self::DEPRECATED_TYPE_MAP[$typeName] ) ) {
108 $typeName = self::DEPRECATED_TYPE_MAP[$typeName];
109 }
110 return isset( self::ALLOWED_TYPES[$typeName] ) ? $typeName : null;
111 }
112
123 public static function createList( $typeName, IContextSource $context, PageIdentity $page, array $ids ) {
124 $typeName = self::getCanonicalTypeName( $typeName );
125 if ( !$typeName ) {
126 throw new InvalidArgumentException( __METHOD__ . ": Unknown RevDel type '$typeName'" );
127 }
128 $spec = self::ALLOWED_TYPES[$typeName];
129 $objectFactory = MediaWikiServices::getInstance()->getObjectFactory();
130
131 return $objectFactory->createObject(
132 $spec,
133 [
134 'extraArgs' => [ $context, $page, $ids ],
135 'assertClass' => RevDelList::class,
136 ]
137 );
138 }
139
151 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
152 if ( $diff & $field ) {
153 $arr[( $new & $field ) ? 0 : 1][] = $desc;
154 }
155 }
156
175 public static function getChanges( $n, $o ) {
176 $diff = $n ^ $o;
177 $ret = [ 0 => [], 1 => [], 2 => [] ];
178 // Build bitfield changes in language
179 self::checkItem( 'revdelete-content',
180 RevisionRecord::DELETED_TEXT, $diff, $n, $ret );
181 self::checkItem( 'revdelete-summary',
182 RevisionRecord::DELETED_COMMENT, $diff, $n, $ret );
183 self::checkItem( 'revdelete-uname',
184 RevisionRecord::DELETED_USER, $diff, $n, $ret );
185 // Restriction application to sysops
186 if ( $diff & RevisionRecord::DELETED_RESTRICTED ) {
187 if ( $n & RevisionRecord::DELETED_RESTRICTED ) {
188 $ret[2][] = 'revdelete-restricted';
189 } else {
190 $ret[2][] = 'revdelete-unrestricted';
191 }
192 }
193 return $ret;
194 }
195
202 public static function getRelationType( $typeName ) {
203 $typeName = self::getCanonicalTypeName( $typeName );
204 if ( !$typeName ) {
205 return null;
206 }
207 $class = self::ALLOWED_TYPES[$typeName]['class'];
208 return $class::getRelationType();
209 }
210
217 public static function getRestriction( $typeName ) {
218 $typeName = self::getCanonicalTypeName( $typeName );
219 if ( !$typeName ) {
220 return null;
221 }
222 $class = self::ALLOWED_TYPES[$typeName]['class'];
223 return $class::getRestriction();
224 }
225
232 public static function getRevdelConstant( $typeName ) {
233 $typeName = self::getCanonicalTypeName( $typeName );
234 if ( !$typeName ) {
235 return null;
236 }
237 $class = self::ALLOWED_TYPES[$typeName]['class'];
238 return $class::getRevdelConstant();
239 }
240
249 public static function suggestTarget( $typeName, $target, array $ids ) {
250 $typeName = self::getCanonicalTypeName( $typeName );
251 if ( !$typeName ) {
252 return $target;
253 }
254 $class = self::ALLOWED_TYPES[$typeName]['class'];
255 return $class::suggestTarget(
256 $target,
257 $ids
258 );
259 }
260
273 public static function extractBitfield( array $bitPars, $oldfield ) {
274 // Build the actual new rev_deleted bitfield
275 $newBits = $oldfield;
276 foreach ( $bitPars as $const => $val ) {
277 // $const is the XXX_DELETED const
278
279 if ( $val == 1 ) {
280 $newBits |= $const; // set the bit
281 } elseif ( $val == 0 ) {
282 $newBits &= ~$const; // unset the bit
283 }
284 }
285 return $newBits;
286 }
287}
288
290class_alias( RevisionDeleter::class, 'RevisionDeleter' );
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
General controller for RevDel, used by both SpecialRevisiondelete and ApiRevisionDelete.
static getCanonicalTypeName( $typeName)
Gets the canonical type name, if any.
static checkItem( $desc, $field, $diff, $new, &$arr)
Checks for a change in the bitfield for a certain option and updates the provided array accordingly.
static extractBitfield(array $bitPars, $oldfield)
Put together a rev_deleted bitfield.
static getChanges( $n, $o)
Gets an array of message keys describing the changes made to the visibility of the revision.
static getRelationType( $typeName)
Get DB field name for URL param... Future code for other things may also track other types of revisio...
static getTypes()
Lists the valid possible types for revision deletion.
static suggestTarget( $typeName, $target, array $ids)
Suggest a target for the revision deletion.
static getRestriction( $typeName)
Get the user right required for the RevDel type.
static getRevdelConstant( $typeName)
Get the revision deletion constant for the RevDel type.
static createList( $typeName, IContextSource $context, PageIdentity $page, array $ids)
Instantiate the appropriate list class for a given list of IDs.
Page revision base class.
Represents a title within MediaWiki.
Definition Title.php:69
Interface for objects which can provide a MediaWiki context on request.
Interface for objects (potentially) representing an editable wiki page.