MediaWiki REL1_32
RevisionDeleter.php
Go to the documentation of this file.
1<?php
31 private static $allowedTypes = [
32 'revision' => RevDelRevisionList::class,
33 'archive' => RevDelArchiveList::class,
34 'oldimage' => RevDelFileList::class,
35 'filearchive' => RevDelArchivedFileList::class,
36 'logging' => RevDelLogList::class,
37 ];
38
40 private static $deprecatedTypeMap = [
41 'oldid' => 'revision',
42 'artimestamp' => 'archive',
43 'oldimage' => 'oldimage',
44 'fileid' => 'filearchive',
45 'logid' => 'logging',
46 ];
47
54 public static function getTypes() {
55 return array_keys( self::$allowedTypes );
56 }
57
65 public static function getCanonicalTypeName( $typeName ) {
66 if ( isset( self::$deprecatedTypeMap[$typeName] ) ) {
67 $typeName = self::$deprecatedTypeMap[$typeName];
68 }
69 return isset( self::$allowedTypes[$typeName] ) ? $typeName : null;
70 }
71
83 public static function createList( $typeName, IContextSource $context, Title $title, array $ids ) {
84 $typeName = self::getCanonicalTypeName( $typeName );
85 if ( !$typeName ) {
86 throw new MWException( __METHOD__ . ": Unknown RevDel type '$typeName'" );
87 }
88 $class = self::$allowedTypes[$typeName];
89 return new $class( $context, $title, $ids );
90 }
91
103 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
104 if ( $diff & $field ) {
105 $arr[( $new & $field ) ? 0 : 1][] = $desc;
106 }
107 }
108
127 public static function getChanges( $n, $o ) {
128 $diff = $n ^ $o;
129 $ret = [ 0 => [], 1 => [], 2 => [] ];
130 // Build bitfield changes in language
131 self::checkItem( 'revdelete-content',
132 Revision::DELETED_TEXT, $diff, $n, $ret );
133 self::checkItem( 'revdelete-summary',
134 Revision::DELETED_COMMENT, $diff, $n, $ret );
135 self::checkItem( 'revdelete-uname',
136 Revision::DELETED_USER, $diff, $n, $ret );
137 // Restriction application to sysops
138 if ( $diff & Revision::DELETED_RESTRICTED ) {
139 if ( $n & Revision::DELETED_RESTRICTED ) {
140 $ret[2][] = 'revdelete-restricted';
141 } else {
142 $ret[2][] = 'revdelete-unrestricted';
143 }
144 }
145 return $ret;
146 }
147
154 public static function getRelationType( $typeName ) {
155 $typeName = self::getCanonicalTypeName( $typeName );
156 if ( !$typeName ) {
157 return null;
158 }
159 return call_user_func( [ self::$allowedTypes[$typeName], 'getRelationType' ] );
160 }
161
168 public static function getRestriction( $typeName ) {
169 $typeName = self::getCanonicalTypeName( $typeName );
170 if ( !$typeName ) {
171 return null;
172 }
173 return call_user_func( [ self::$allowedTypes[$typeName], 'getRestriction' ] );
174 }
175
182 public static function getRevdelConstant( $typeName ) {
183 $typeName = self::getCanonicalTypeName( $typeName );
184 if ( !$typeName ) {
185 return null;
186 }
187 return call_user_func( [ self::$allowedTypes[$typeName], 'getRevdelConstant' ] );
188 }
189
198 public static function suggestTarget( $typeName, $target, array $ids ) {
199 $typeName = self::getCanonicalTypeName( $typeName );
200 if ( !$typeName ) {
201 return $target;
202 }
203 return call_user_func( [ self::$allowedTypes[$typeName], 'suggestTarget' ], $target, $ids );
204 }
205
215 public static function checkRevisionExistence( $title, $revid ) {
217 $exists = $dbr->selectField( 'revision', '1',
218 [ 'rev_id' => $revid ], __METHOD__ );
219
220 if ( $exists ) {
221 return true;
222 }
223
224 $timestamp = $dbr->selectField( 'archive', 'ar_timestamp',
225 [ 'ar_namespace' => $title->getNamespace(),
226 'ar_title' => $title->getDBkey(),
227 'ar_rev_id' => $revid ], __METHOD__ );
228
229 return $timestamp;
230 }
231
239 public static function extractBitfield( array $bitPars, $oldfield ) {
240 // Build the actual new rev_deleted bitfield
241 $newBits = 0;
242 foreach ( $bitPars as $const => $val ) {
243 if ( $val == 1 ) {
244 $newBits |= $const; // $const is the *_deleted const
245 } elseif ( $val == -1 ) {
246 $newBits |= ( $oldfield & $const ); // use existing
247 }
248 }
249 return $newBits;
250 }
251}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
MediaWiki exception.
General controller for RevDel, used by both SpecialRevisiondelete and ApiRevisionDelete.
static getCanonicalTypeName( $typeName)
Gets the canonical type name, if any.
static createList( $typeName, IContextSource $context, Title $title, array $ids)
Instantiate the appropriate list class for a given list of IDs.
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 $allowedTypes
List of known revdel types, with their corresponding list classes.
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 checkRevisionExistence( $title, $revid)
Checks if a revision still exists in the revision table.
static $deprecatedTypeMap
Type map to support old log entries.
const DELETED_USER
Definition Revision.php:49
const DELETED_TEXT
Definition Revision.php:47
const DELETED_RESTRICTED
Definition Revision.php:50
const DELETED_COMMENT
Definition Revision.php:48
Represents a title within MediaWiki.
Definition Title.php:39
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2885
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition hooks.txt:2054
Interface for objects which can provide a MediaWiki context on request.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
const DB_REPLICA
Definition defines.php:25