MediaWiki  master
RevisionDeleter.php
Go to the documentation of this file.
1 <?php
25 
33  private static $allowedTypes = [
34  'revision' => RevDelRevisionList::class,
35  'archive' => RevDelArchiveList::class,
36  'oldimage' => RevDelFileList::class,
37  'filearchive' => RevDelArchivedFileList::class,
38  'logging' => RevDelLogList::class,
39  ];
40 
42  private static $deprecatedTypeMap = [
43  'oldid' => 'revision',
44  'artimestamp' => 'archive',
45  'oldimage' => 'oldimage',
46  'fileid' => 'filearchive',
47  'logid' => 'logging',
48  ];
49 
56  public static function getTypes() {
57  return array_keys( self::$allowedTypes );
58  }
59 
67  public static function getCanonicalTypeName( $typeName ) {
68  if ( isset( self::$deprecatedTypeMap[$typeName] ) ) {
69  $typeName = self::$deprecatedTypeMap[$typeName];
70  }
71  return isset( self::$allowedTypes[$typeName] ) ? $typeName : null;
72  }
73 
85  public static function createList( $typeName, IContextSource $context, Title $title, array $ids ) {
86  $typeName = self::getCanonicalTypeName( $typeName );
87  if ( !$typeName ) {
88  throw new MWException( __METHOD__ . ": Unknown RevDel type '$typeName'" );
89  }
90  $class = self::$allowedTypes[$typeName];
91  return new $class( $context, $title, $ids );
92  }
93 
105  protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
106  if ( $diff & $field ) {
107  $arr[( $new & $field ) ? 0 : 1][] = $desc;
108  }
109  }
110 
129  public static function getChanges( $n, $o ) {
130  $diff = $n ^ $o;
131  $ret = [ 0 => [], 1 => [], 2 => [] ];
132  // Build bitfield changes in language
133  self::checkItem( 'revdelete-content',
134  RevisionRecord::DELETED_TEXT, $diff, $n, $ret );
135  self::checkItem( 'revdelete-summary',
136  RevisionRecord::DELETED_COMMENT, $diff, $n, $ret );
137  self::checkItem( 'revdelete-uname',
138  RevisionRecord::DELETED_USER, $diff, $n, $ret );
139  // Restriction application to sysops
140  if ( $diff & RevisionRecord::DELETED_RESTRICTED ) {
141  if ( $n & RevisionRecord::DELETED_RESTRICTED ) {
142  $ret[2][] = 'revdelete-restricted';
143  } else {
144  $ret[2][] = 'revdelete-unrestricted';
145  }
146  }
147  return $ret;
148  }
149 
156  public static function getRelationType( $typeName ) {
157  $typeName = self::getCanonicalTypeName( $typeName );
158  if ( !$typeName ) {
159  return null;
160  }
161  return call_user_func( [ self::$allowedTypes[$typeName], 'getRelationType' ] );
162  }
163 
170  public static function getRestriction( $typeName ) {
171  $typeName = self::getCanonicalTypeName( $typeName );
172  if ( !$typeName ) {
173  return null;
174  }
175  return call_user_func( [ self::$allowedTypes[$typeName], 'getRestriction' ] );
176  }
177 
184  public static function getRevdelConstant( $typeName ) {
185  $typeName = self::getCanonicalTypeName( $typeName );
186  if ( !$typeName ) {
187  return null;
188  }
189  return call_user_func( [ self::$allowedTypes[$typeName], 'getRevdelConstant' ] );
190  }
191 
200  public static function suggestTarget( $typeName, $target, array $ids ) {
201  $typeName = self::getCanonicalTypeName( $typeName );
202  if ( !$typeName ) {
203  return $target;
204  }
205  return call_user_func( [ self::$allowedTypes[$typeName], 'suggestTarget' ], $target, $ids );
206  }
207 
217  public static function checkRevisionExistence( $title, $revid ) {
218  $dbr = wfGetDB( DB_REPLICA );
219  $exists = $dbr->selectField( 'revision', '1',
220  [ 'rev_id' => $revid ], __METHOD__ );
221 
222  if ( $exists ) {
223  return true;
224  }
225 
226  $timestamp = $dbr->selectField( 'archive', 'ar_timestamp',
227  [ 'ar_namespace' => $title->getNamespace(),
228  'ar_title' => $title->getDBkey(),
229  'ar_rev_id' => $revid ], __METHOD__ );
230 
231  return $timestamp;
232  }
233 
241  public static function extractBitfield( array $bitPars, $oldfield ) {
242  // Build the actual new rev_deleted bitfield
243  $newBits = 0;
244  foreach ( $bitPars as $const => $val ) {
245  if ( $val == 1 ) {
246  $newBits |= $const; // $const is the *_deleted const
247  } elseif ( $val == -1 ) {
248  $newBits |= ( $oldfield & $const ); // use existing
249  }
250  }
251  return $newBits;
252  }
253 }
static getRelationType( $typeName)
Get DB field name for URL param...
static getRestriction( $typeName)
Get the user right required for the RevDel type.
static getCanonicalTypeName( $typeName)
Gets the canonical type name, if any.
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:1972
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
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 getChanges( $n, $o)
Gets an array of message keys describing the changes made to the visibility of the revision...
static $allowedTypes
List of known revdel types, with their corresponding list classes.
static static $deprecatedTypeMap
Type map to support old log entries.
static createList( $typeName, IContextSource $context, Title $title, array $ids)
Instantiate the appropriate list class for a given list of IDs.
static extractBitfield(array $bitPars, $oldfield)
Put together a rev_deleted bitfield.
static getRevdelConstant( $typeName)
Get the revision deletion constant for the RevDel type.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
static suggestTarget( $typeName, $target, array $ids)
Suggest a target for the revision deletion.
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
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:2621
const DB_REPLICA
Definition: defines.php:25
static checkRevisionExistence( $title, $revid)
Checks if a revision still exists in the revision table.
static static static getTypes()
Lists the valid possible types for revision deletion.