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 ],
40 ],
41 'archive' => [
42 'class' => RevDelArchiveList::class,
43 'services' => [
44 'DBLoadBalancerFactory',
45 'HookContainer',
46 'HtmlCacheUpdater',
47 'RevisionStore',
48 'DomainEventDispatcher'
49 ],
50 ],
51 'oldimage' => [
52 'class' => RevDelFileList::class,
53 'services' => [
54 'DBLoadBalancerFactory',
55 'HtmlCacheUpdater',
56 'RepoGroup',
57 ],
58 ],
59 'filearchive' => [
60 'class' => RevDelArchivedFileList::class,
61 'services' => [
62 'DBLoadBalancerFactory',
63 'HtmlCacheUpdater',
64 'RepoGroup',
65 ],
66 ],
67 'logging' => [
68 'class' => RevDelLogList::class,
69 'services' => [
70 'DBLoadBalancerFactory',
71 'CommentStore',
72 'LogFormatterFactory',
73 ],
74 ],
75 ];
76
78 private const DEPRECATED_TYPE_MAP = [
79 'oldid' => 'revision',
80 'artimestamp' => 'archive',
81 'oldimage' => 'oldimage',
82 'fileid' => 'filearchive',
83 'logid' => 'logging',
84 ];
85
92 public static function getTypes() {
93 return array_keys( self::ALLOWED_TYPES );
94 }
95
103 public static function getCanonicalTypeName( $typeName ) {
104 if ( isset( self::DEPRECATED_TYPE_MAP[$typeName] ) ) {
105 $typeName = self::DEPRECATED_TYPE_MAP[$typeName];
106 }
107 return isset( self::ALLOWED_TYPES[$typeName] ) ? $typeName : null;
108 }
109
120 public static function createList( $typeName, IContextSource $context, PageIdentity $page, array $ids ) {
121 $typeName = self::getCanonicalTypeName( $typeName );
122 if ( !$typeName ) {
123 throw new InvalidArgumentException( __METHOD__ . ": Unknown RevDel type '$typeName'" );
124 }
125 $spec = self::ALLOWED_TYPES[$typeName];
126 $objectFactory = MediaWikiServices::getInstance()->getObjectFactory();
127
128 // ObjectFactory::createObject accepts an array, not just a callable (phan bug)
129 // @phan-suppress-next-line PhanTypeInvalidCallableArrayKey
130 return $objectFactory->createObject(
131 $spec,
132 [
133 'extraArgs' => [ $context, $page, $ids ],
134 'assertClass' => RevDelList::class,
135 ]
136 );
137 }
138
150 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
151 if ( $diff & $field ) {
152 $arr[( $new & $field ) ? 0 : 1][] = $desc;
153 }
154 }
155
174 public static function getChanges( $n, $o ) {
175 $diff = $n ^ $o;
176 $ret = [ 0 => [], 1 => [], 2 => [] ];
177 // Build bitfield changes in language
178 self::checkItem( 'revdelete-content',
179 RevisionRecord::DELETED_TEXT, $diff, $n, $ret );
180 self::checkItem( 'revdelete-summary',
181 RevisionRecord::DELETED_COMMENT, $diff, $n, $ret );
182 self::checkItem( 'revdelete-uname',
183 RevisionRecord::DELETED_USER, $diff, $n, $ret );
184 // Restriction application to sysops
185 if ( $diff & RevisionRecord::DELETED_RESTRICTED ) {
186 if ( $n & RevisionRecord::DELETED_RESTRICTED ) {
187 $ret[2][] = 'revdelete-restricted';
188 } else {
189 $ret[2][] = 'revdelete-unrestricted';
190 }
191 }
192 return $ret;
193 }
194
201 public static function getRelationType( $typeName ) {
202 $typeName = self::getCanonicalTypeName( $typeName );
203 if ( !$typeName ) {
204 return null;
205 }
206 $class = self::ALLOWED_TYPES[$typeName]['class'];
207 return $class::getRelationType();
208 }
209
216 public static function getRestriction( $typeName ) {
217 $typeName = self::getCanonicalTypeName( $typeName );
218 if ( !$typeName ) {
219 return null;
220 }
221 $class = self::ALLOWED_TYPES[$typeName]['class'];
222 return $class::getRestriction();
223 }
224
231 public static function getRevdelConstant( $typeName ) {
232 $typeName = self::getCanonicalTypeName( $typeName );
233 if ( !$typeName ) {
234 return null;
235 }
236 $class = self::ALLOWED_TYPES[$typeName]['class'];
237 return $class::getRevdelConstant();
238 }
239
248 public static function suggestTarget( $typeName, $target, array $ids ) {
249 $typeName = self::getCanonicalTypeName( $typeName );
250 if ( !$typeName ) {
251 return $target;
252 }
253 $class = self::ALLOWED_TYPES[$typeName]['class'];
254 return $class::suggestTarget(
255 $target,
256 $ids
257 );
258 }
259
272 public static function extractBitfield( array $bitPars, $oldfield ) {
273 // Build the actual new rev_deleted bitfield
274 $newBits = $oldfield;
275 foreach ( $bitPars as $const => $val ) {
276 // $const is the XXX_DELETED const
277
278 if ( $val == 1 ) {
279 $newBits |= $const; // set the bit
280 } elseif ( $val == 0 ) {
281 $newBits &= ~$const; // unset the bit
282 }
283 }
284 return $newBits;
285 }
286}
287
289class_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.