MediaWiki REL1_40
RevisionDeleter.php
Go to the documentation of this file.
1<?php
28
40 private const ALLOWED_TYPES = [
41 'revision' => [
42 'class' => RevDelRevisionList::class,
43 'services' => [
44 'DBLoadBalancerFactory',
45 'HookContainer',
46 'HtmlCacheUpdater',
47 'RevisionStore',
48 ],
49 ],
50 'archive' => [
51 'class' => RevDelArchiveList::class,
52 'services' => [
53 'DBLoadBalancerFactory',
54 'HookContainer',
55 'HtmlCacheUpdater',
56 'RevisionStore',
57 ],
58 ],
59 'oldimage' => [
60 'class' => RevDelFileList::class,
61 'services' => [
62 'DBLoadBalancerFactory',
63 'HtmlCacheUpdater',
64 'RepoGroup',
65 ],
66 ],
67 'filearchive' => [
68 'class' => RevDelArchivedFileList::class,
69 'services' => [
70 'DBLoadBalancerFactory',
71 'HtmlCacheUpdater',
72 'RepoGroup',
73 ],
74 ],
75 'logging' => [
76 'class' => RevDelLogList::class,
77 'services' => [
78 'DBLoadBalancerFactory',
79 'CommentStore',
80 ],
81 ],
82 ];
83
85 private const DEPRECATED_TYPE_MAP = [
86 'oldid' => 'revision',
87 'artimestamp' => 'archive',
88 'oldimage' => 'oldimage',
89 'fileid' => 'filearchive',
90 'logid' => 'logging',
91 ];
92
99 public static function getTypes() {
100 return array_keys( self::ALLOWED_TYPES );
101 }
102
110 public static function getCanonicalTypeName( $typeName ) {
111 if ( isset( self::DEPRECATED_TYPE_MAP[$typeName] ) ) {
112 $typeName = self::DEPRECATED_TYPE_MAP[$typeName];
113 }
114 return isset( self::ALLOWED_TYPES[$typeName] ) ? $typeName : null;
115 }
116
128 public static function createList( $typeName, IContextSource $context, PageIdentity $page, array $ids ) {
129 $typeName = self::getCanonicalTypeName( $typeName );
130 if ( !$typeName ) {
131 throw new MWException( __METHOD__ . ": Unknown RevDel type '$typeName'" );
132 }
133 $spec = self::ALLOWED_TYPES[$typeName];
134 $objectFactory = MediaWikiServices::getInstance()->getObjectFactory();
135
136 // ObjectFactory::createObject accepts an array, not just a callable (phan bug)
137 // @phan-suppress-next-line PhanTypeInvalidCallableArrayKey
138 return $objectFactory->createObject(
139 $spec,
140 [
141 'extraArgs' => [ $context, $page, $ids ],
142 'assertClass' => RevDelList::class,
143 ]
144 );
145 }
146
158 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
159 if ( $diff & $field ) {
160 $arr[( $new & $field ) ? 0 : 1][] = $desc;
161 }
162 }
163
182 public static function getChanges( $n, $o ) {
183 $diff = $n ^ $o;
184 $ret = [ 0 => [], 1 => [], 2 => [] ];
185 // Build bitfield changes in language
186 self::checkItem( 'revdelete-content',
187 RevisionRecord::DELETED_TEXT, $diff, $n, $ret );
188 self::checkItem( 'revdelete-summary',
189 RevisionRecord::DELETED_COMMENT, $diff, $n, $ret );
190 self::checkItem( 'revdelete-uname',
191 RevisionRecord::DELETED_USER, $diff, $n, $ret );
192 // Restriction application to sysops
193 if ( $diff & RevisionRecord::DELETED_RESTRICTED ) {
194 if ( $n & RevisionRecord::DELETED_RESTRICTED ) {
195 $ret[2][] = 'revdelete-restricted';
196 } else {
197 $ret[2][] = 'revdelete-unrestricted';
198 }
199 }
200 return $ret;
201 }
202
209 public static function getRelationType( $typeName ) {
210 $typeName = self::getCanonicalTypeName( $typeName );
211 if ( !$typeName ) {
212 return null;
213 }
214 return call_user_func( [ self::ALLOWED_TYPES[$typeName]['class'], 'getRelationType' ] );
215 }
216
223 public static function getRestriction( $typeName ) {
224 $typeName = self::getCanonicalTypeName( $typeName );
225 if ( !$typeName ) {
226 return null;
227 }
228 return call_user_func( [ self::ALLOWED_TYPES[$typeName]['class'], 'getRestriction' ] );
229 }
230
237 public static function getRevdelConstant( $typeName ) {
238 $typeName = self::getCanonicalTypeName( $typeName );
239 if ( !$typeName ) {
240 return null;
241 }
242 return call_user_func( [ self::ALLOWED_TYPES[$typeName]['class'], 'getRevdelConstant' ] );
243 }
244
253 public static function suggestTarget( $typeName, $target, array $ids ) {
254 $typeName = self::getCanonicalTypeName( $typeName );
255 if ( !$typeName ) {
256 return $target;
257 }
258 return call_user_func(
259 [ self::ALLOWED_TYPES[$typeName]['class'], 'suggestTarget' ],
260 $target,
261 $ids
262 );
263 }
264
272 public static function extractBitfield( array $bitPars, $oldfield ) {
273 // Build the actual new rev_deleted bitfield
274 $newBits = 0;
275 foreach ( $bitPars as $const => $val ) {
276 if ( $val == 1 ) {
277 $newBits |= $const; // $const is the *_deleted const
278 } elseif ( $val == -1 ) {
279 $newBits |= ( $oldfield & $const ); // use existing
280 }
281 }
282 return $newBits;
283 }
284}
MediaWiki exception.
Service locator for MediaWiki core services.
Page revision base class.
Represents a title within MediaWiki.
Definition Title.php:82
General controller for RevDel, used by both SpecialRevisiondelete and ApiRevisionDelete.
static getCanonicalTypeName( $typeName)
Gets the canonical type name, if any.
static getTypes()
Lists the valid possible types for revision deletion.
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 getRelationType( $typeName)
Get DB field name for URL param... Future code for other things may also track other types of revisio...
static getChanges( $n, $o)
Gets an array of message keys describing the changes made to the visibility of the revision.
static suggestTarget( $typeName, $target, array $ids)
Suggest a target for the revision deletion.
static extractBitfield(array $bitPars, $oldfield)
Put together a rev_deleted bitfield.
static getRevdelConstant( $typeName)
Get the revision deletion constant for the RevDel type.
static getRestriction( $typeName)
Get the user right required for the RevDel type.
static createList( $typeName, IContextSource $context, PageIdentity $page, array $ids)
Instantiate the appropriate list class for a given list of IDs.
Interface for objects which can provide a MediaWiki context on request.
Interface for objects (potentially) representing an editable wiki page.