MediaWiki  1.23.2
RevisionDeleter.php
Go to the documentation of this file.
1 <?php
31  private static $allowedTypes = array(
32  'revision' => 'RevDel_RevisionList',
33  'archive' => 'RevDel_ArchiveList',
34  'oldimage' => 'RevDel_FileList',
35  'filearchive' => 'RevDel_ArchivedFileList',
36  'logging' => 'RevDel_LogList',
37  );
38 
40  private static $deprecatedTypeMap = array(
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 
82  public static function createList( $typeName, IContextSource $context, Title $title, array $ids ) {
83  $typeName = self::getCanonicalTypeName( $typeName );
84  if ( !$typeName ) {
85  throw new MWException( __METHOD__ . ": Unknown RevDel type '$typeName'" );
86  }
87  return new self::$allowedTypes[$typeName]( $context, $title, $ids );
88  }
89 
101  protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
102  if ( $diff & $field ) {
103  $arr[( $new & $field ) ? 0 : 1][] = $desc;
104  }
105  }
106 
125  public static function getChanges( $n, $o ) {
126  $diff = $n ^ $o;
127  $ret = array( 0 => array(), 1 => array(), 2 => array() );
128  // Build bitfield changes in language
129  self::checkItem( 'revdelete-content',
130  Revision::DELETED_TEXT, $diff, $n, $ret );
131  self::checkItem( 'revdelete-summary',
132  Revision::DELETED_COMMENT, $diff, $n, $ret );
133  self::checkItem( 'revdelete-uname',
134  Revision::DELETED_USER, $diff, $n, $ret );
135  // Restriction application to sysops
136  if ( $diff & Revision::DELETED_RESTRICTED ) {
138  $ret[2][] = 'revdelete-restricted';
139  } else {
140  $ret[2][] = 'revdelete-unrestricted';
141  }
142  }
143  return $ret;
144  }
145 
152  public static function getRelationType( $typeName ) {
153  $typeName = self::getCanonicalTypeName( $typeName );
154  if ( !$typeName ) {
155  return null;
156  }
157  return call_user_func( array( self::$allowedTypes[$typeName], 'getRelationType' ) );
158  }
159 
166  public static function getRestriction( $typeName ) {
167  $typeName = self::getCanonicalTypeName( $typeName );
168  if ( !$typeName ) {
169  return null;
170  }
171  return call_user_func( array( self::$allowedTypes[$typeName], 'getRestriction' ) );
172  }
173 
180  public static function getRevdelConstant( $typeName ) {
181  $typeName = self::getCanonicalTypeName( $typeName );
182  if ( !$typeName ) {
183  return null;
184  }
185  return call_user_func( array( self::$allowedTypes[$typeName], 'getRevdelConstant' ) );
186  }
187 
196  public static function suggestTarget( $typeName, $target, array $ids ) {
197  $typeName = self::getCanonicalTypeName( $typeName );
198  if ( !$typeName ) {
199  return $target;
200  }
201  return call_user_func( array( self::$allowedTypes[$typeName], 'suggestTarget' ), $target, $ids );
202  }
203 
213  public static function checkRevisionExistence( $title, $revid ) {
214  $dbr = wfGetDB( DB_SLAVE );
215  $exists = $dbr->selectField( 'revision', '1',
216  array( 'rev_id' => $revid ), __METHOD__ );
217 
218  if ( $exists ) {
219  return true;
220  }
221 
222  $timestamp = $dbr->selectField( 'archive', 'ar_timestamp',
223  array( 'ar_namespace' => $title->getNamespace(),
224  'ar_title' => $title->getDBkey(),
225  'ar_rev_id' => $revid ), __METHOD__ );
226 
227  return $timestamp;
228  }
229 
237  public static function extractBitfield( $bitPars, $oldfield ) {
238  // Build the actual new rev_deleted bitfield
239  $newBits = 0;
240  foreach ( $bitPars as $const => $val ) {
241  if ( $val == 1 ) {
242  $newBits |= $const; // $const is the *_deleted const
243  } elseif ( $val == -1 ) {
244  $newBits |= ( $oldfield & $const ); // use existing
245  }
246  }
247  return $newBits;
248  }
249 }
Revision\DELETED_USER
const DELETED_USER
Definition: Revision.php:67
Revision\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: Revision.php:68
Revision\DELETED_COMMENT
const DELETED_COMMENT
Definition: Revision.php:66
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3650
$timestamp
if( $limit) $timestamp
Definition: importImages.php:104
RevisionDeleter
General controller for RevDel, used by both SpecialRevisiondelete and ApiRevisionDelete.
Definition: RevisionDeleter.php:29
RevisionDeleter\$allowedTypes
static $allowedTypes
List of known revdel types, with their corresponding list classes.
Definition: RevisionDeleter.php:31
$n
$n
Definition: RandomTest.php:76
$ret
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:1530
RevisionDeleter\checkRevisionExistence
static checkRevisionExistence( $title, $revid)
Checks if a revision still exists in the revision table.
Definition: RevisionDeleter.php:213
$dbr
$dbr
Definition: testCompression.php:48
MWException
MediaWiki exception.
Definition: MWException.php:26
RevisionDeleter\getTypes
static getTypes()
Lists the valid possible types for revision deletion.
Definition: RevisionDeleter.php:54
RevisionDeleter\extractBitfield
static extractBitfield( $bitPars, $oldfield)
Put together a rev_deleted bitfield.
Definition: RevisionDeleter.php:237
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
RevisionDeleter\$deprecatedTypeMap
static $deprecatedTypeMap
Type map to support old log entries.
Definition: RevisionDeleter.php:40
RevisionDeleter\createList
static createList( $typeName, IContextSource $context, Title $title, array $ids)
Instantiate the appropriate list class for a given list of IDs.
Definition: RevisionDeleter.php:82
RevisionDeleter\checkItem
static checkItem( $desc, $field, $diff, $new, &$arr)
Checks for a change in the bitfield for a certain option and updates the provided array accordingly.
Definition: RevisionDeleter.php:101
RevisionDeleter\getRevdelConstant
static getRevdelConstant( $typeName)
Get the revision deletion constant for the RevDel type.
Definition: RevisionDeleter.php:180
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
RevisionDeleter\getChanges
static getChanges( $n, $o)
Gets an array of message keys describing the changes made to the visibility of the revision.
Definition: RevisionDeleter.php:125
IContextSource
Interface for objects which can provide a context on request.
Definition: IContextSource.php:29
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
Title
Represents a title within MediaWiki.
Definition: Title.php:35
RevisionDeleter\getRelationType
static getRelationType( $typeName)
Get DB field name for URL param...
Definition: RevisionDeleter.php:152
as
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
RevisionDeleter\getCanonicalTypeName
static getCanonicalTypeName( $typeName)
Gets the canonical type name, if any.
Definition: RevisionDeleter.php:65
RevisionDeleter\suggestTarget
static suggestTarget( $typeName, $target, array $ids)
Suggest a target for the revision deletion.
Definition: RevisionDeleter.php:196
RevisionDeleter\getRestriction
static getRestriction( $typeName)
Get the user right required for the RevDel type.
Definition: RevisionDeleter.php:166
Revision\DELETED_TEXT
const DELETED_TEXT
Definition: Revision.php:65