MediaWiki  master
RevDelList.php
Go to the documentation of this file.
1 <?php
28 abstract class RevDelList extends RevisionListBase {
30  parent::__construct( $context, $title );
31  $this->ids = $ids;
32  }
33 
40  public static function getRelationType() {
41  return null;
42  }
43 
50  public static function getRestriction() {
51  return null;
52  }
53 
60  public static function getRevdelConstant() {
61  return null;
62  }
63 
72  public static function suggestTarget( $target, array $ids ) {
73  return $target;
74  }
75 
81  public function areAnySuppressed() {
82  $bit = $this->getSuppressBit();
83 
85  foreach ( $this as $item ) {
86  if ( $item->getBits() & $bit ) {
87  return true;
88  }
89  }
90 
91  return false;
92  }
93 
105  public function setVisibility( array $params ) {
107 
108  $bitPars = $params['value'];
109  $comment = $params['comment'];
110  $perItemStatus = isset( $params['perItemStatus'] ) ? $params['perItemStatus'] : false;
111 
112  // CAS-style checks are done on the _deleted fields so the select
113  // does not need to use FOR UPDATE nor be in the atomic section
114  $dbw = wfGetDB( DB_MASTER );
115  $this->res = $this->doQuery( $dbw );
116 
117  $status->merge( $this->acquireItemLocks() );
118  if ( !$status->isGood() ) {
119  return $status;
120  }
121 
122  $dbw->startAtomic( __METHOD__ );
123  $dbw->onTransactionResolution( function () {
124  // Release locks on commit or error
125  $this->releaseItemLocks();
126  } );
127 
128  $missing = array_flip( $this->ids );
129  $this->clearFileOps();
130  $idsForLog = [];
131  $authorIds = $authorIPs = [];
132 
133  if ( $perItemStatus ) {
134  $status->itemStatuses = [];
135  }
136 
137  // For multi-item deletions, set the old/new bitfields in log_params such that "hid X"
138  // shows in logs if field X was hidden from ANY item and likewise for "unhid Y". Note the
139  // form does not let the same field get hidden and unhidden in different items at once.
140  $virtualOldBits = 0;
141  $virtualNewBits = 0;
142  $logType = 'delete';
143 
144  // Will be filled with id => [old, new bits] information and
145  // passed to doPostCommitUpdates().
146  $visibilityChangeMap = [];
147 
149  foreach ( $this as $item ) {
150  unset( $missing[$item->getId()] );
151 
152  if ( $perItemStatus ) {
153  $itemStatus = Status::newGood();
154  $status->itemStatuses[$item->getId()] = $itemStatus;
155  } else {
156  $itemStatus = $status;
157  }
158 
159  $oldBits = $item->getBits();
160  // Build the actual new rev_deleted bitfield
161  $newBits = RevisionDeleter::extractBitfield( $bitPars, $oldBits );
162 
163  if ( $oldBits == $newBits ) {
164  $itemStatus->warning(
165  'revdelete-no-change', $item->formatDate(), $item->formatTime() );
166  $status->failCount++;
167  continue;
168  } elseif ( $oldBits == 0 && $newBits != 0 ) {
169  $opType = 'hide';
170  } elseif ( $oldBits != 0 && $newBits == 0 ) {
171  $opType = 'show';
172  } else {
173  $opType = 'modify';
174  }
175 
176  if ( $item->isHideCurrentOp( $newBits ) ) {
177  // Cannot hide current version text
178  $itemStatus->error(
179  'revdelete-hide-current', $item->formatDate(), $item->formatTime() );
180  $status->failCount++;
181  continue;
182  } elseif ( !$item->canView() ) {
183  // Cannot access this revision
184  $msg = ( $opType == 'show' ) ?
185  'revdelete-show-no-access' : 'revdelete-modify-no-access';
186  $itemStatus->error( $msg, $item->formatDate(), $item->formatTime() );
187  $status->failCount++;
188  continue;
189  // Cannot just "hide from Sysops" without hiding any fields
190  } elseif ( $newBits == Revision::DELETED_RESTRICTED ) {
191  $itemStatus->warning(
192  'revdelete-only-restricted', $item->formatDate(), $item->formatTime() );
193  $status->failCount++;
194  continue;
195  }
196 
197  // Update the revision
198  $ok = $item->setBits( $newBits );
199 
200  if ( $ok ) {
201  $idsForLog[] = $item->getId();
202  // If any item field was suppressed or unsupressed
203  if ( ( $oldBits | $newBits ) & $this->getSuppressBit() ) {
204  $logType = 'suppress';
205  }
206  // Track which fields where (un)hidden for each item
207  $addedBits = ( $oldBits ^ $newBits ) & $newBits;
208  $removedBits = ( $oldBits ^ $newBits ) & $oldBits;
209  $virtualNewBits |= $addedBits;
210  $virtualOldBits |= $removedBits;
211 
212  $status->successCount++;
213  if ( $item->getAuthorId() > 0 ) {
214  $authorIds[] = $item->getAuthorId();
215  } elseif ( IP::isIPAddress( $item->getAuthorName() ) ) {
216  $authorIPs[] = $item->getAuthorName();
217  }
218 
219  // Save the old and new bits in $visibilityChangeMap for
220  // later use.
221  $visibilityChangeMap[$item->getId()] = [
222  'oldBits' => $oldBits,
223  'newBits' => $newBits,
224  ];
225  } else {
226  $itemStatus->error(
227  'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
228  $status->failCount++;
229  }
230  }
231 
232  // Handle missing revisions
233  foreach ( $missing as $id => $unused ) {
234  if ( $perItemStatus ) {
235  $status->itemStatuses[$id] = Status::newFatal( 'revdelete-modify-missing', $id );
236  } else {
237  $status->error( 'revdelete-modify-missing', $id );
238  }
239  $status->failCount++;
240  }
241 
242  if ( $status->successCount == 0 ) {
243  $dbw->endAtomic( __METHOD__ );
244  return $status;
245  }
246 
247  // Save success count
248  $successCount = $status->successCount;
249 
250  // Move files, if there are any
251  $status->merge( $this->doPreCommitUpdates() );
252  if ( !$status->isOK() ) {
253  // Fatal error, such as no configured archive directory or I/O failures
254  wfGetLBFactory()->rollbackMasterChanges( __METHOD__ );
255  return $status;
256  }
257 
258  // Log it
259  $this->updateLog(
260  $logType,
261  [
262  'title' => $this->title,
263  'count' => $successCount,
264  'newBits' => $virtualNewBits,
265  'oldBits' => $virtualOldBits,
266  'comment' => $comment,
267  'ids' => $idsForLog,
268  'authorIds' => $authorIds,
269  'authorIPs' => $authorIPs
270  ]
271  );
272 
273  // Clear caches after commit
275  function () use ( $visibilityChangeMap ) {
276  $this->doPostCommitUpdates( $visibilityChangeMap );
277  },
279  );
280 
281  $dbw->endAtomic( __METHOD__ );
282 
283  return $status;
284  }
285 
286  final protected function acquireItemLocks() {
289  foreach ( $this as $item ) {
290  $status->merge( $item->lock() );
291  }
292 
293  return $status;
294  }
295 
296  final protected function releaseItemLocks() {
299  foreach ( $this as $item ) {
300  $status->merge( $item->unlock() );
301  }
302 
303  return $status;
304  }
305 
310  function reloadFromMaster() {
311  $dbw = wfGetDB( DB_MASTER );
312  $this->res = $this->doQuery( $dbw );
313  }
314 
328  private function updateLog( $logType, $params ) {
329  // Get the URL param's corresponding DB field
330  $field = RevisionDeleter::getRelationType( $this->getType() );
331  if ( !$field ) {
332  throw new MWException( "Bad log URL param type!" );
333  }
334  // Add params for affected page and ids
335  $logParams = $this->getLogParams( $params );
336  // Actually add the deletion log entry
337  $logEntry = new ManualLogEntry( $logType, $this->getLogAction() );
338  $logEntry->setTarget( $params['title'] );
339  $logEntry->setComment( $params['comment'] );
340  $logEntry->setParameters( $logParams );
341  $logEntry->setPerformer( $this->getUser() );
342  // Allow for easy searching of deletion log items for revision/log items
343  $logEntry->setRelations( [
344  $field => $params['ids'],
345  'target_author_id' => $params['authorIds'],
346  'target_author_ip' => $params['authorIPs'],
347  ] );
348  $logId = $logEntry->insert();
349  $logEntry->publish( $logId );
350  }
351 
356  public function getLogAction() {
357  return 'revision';
358  }
359 
365  public function getLogParams( $params ) {
366  return [
367  '4::type' => $this->getType(),
368  '5::ids' => $params['ids'],
369  '6::ofield' => $params['oldBits'],
370  '7::nfield' => $params['newBits'],
371  ];
372  }
373 
378  public function clearFileOps() {
379  }
380 
386  public function doPreCommitUpdates() {
387  return Status::newGood();
388  }
389 
396  public function doPostCommitUpdates( array $visibilityChangeMap ) {
397  return Status::newGood();
398  }
399 
403  abstract public function getSuppressBit();
404 }
clearFileOps()
Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates() STUB...
Definition: RevDelList.php:378
Abstract base class for a list of deletable items.
Definition: RevDelList.php:28
Interface for objects which can provide a MediaWiki context on request.
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
the array() calling protocol came about after MediaWiki 1.4rc1.
updateLog($logType, $params)
Record a log entry on the action.
Definition: RevDelList.php:328
getType()
Get the internal type name of this list.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$comment
getLogParams($params)
Get log parameter array.
Definition: RevDelList.php:365
Represents a title within MediaWiki.
Definition: Title.php:36
static suggestTarget($target, array $ids)
Suggest a target for the revision deletion Optionally override this function.
Definition: RevDelList.php:72
static newFatal($message)
Factory function for fatal errors.
Definition: Status.php:89
IContextSource $context
static isIPAddress($ip)
Determine if a string is as valid IP address or network (CIDR prefix).
Definition: IP.php:79
List for revision table items for a single page.
static addCallableUpdate($callable, $type=self::POSTSEND)
Add a callable update.
areAnySuppressed()
Indicate whether any item in this list is suppressed.
Definition: RevDelList.php:81
releaseItemLocks()
Definition: RevDelList.php:296
getSuppressBit()
Get the integer value of the flag used for suppression.
setVisibility(array $params)
Set the visibility for the revisions in this list.
Definition: RevDelList.php:105
reloadFromMaster()
Reload the list data from the master DB.
Definition: RevDelList.php:310
getLogAction()
Get the log action for this list type.
Definition: RevDelList.php:356
__construct(IContextSource $context, Title $title, array $ids)
Definition: RevDelList.php:29
static getRevdelConstant()
Get the revision deletion constant for this list type Override this function.
Definition: RevDelList.php:60
MediaWiki exception.
Definition: MWException.php:26
$params
static extractBitfield(array $bitPars, $oldfield)
Put together a rev_deleted bitfield.
doPostCommitUpdates(array $visibilityChangeMap)
A hook for setVisibility(): do any necessary updates post-commit.
Definition: RevDelList.php:396
const DELETED_RESTRICTED
Definition: Revision.php:79
static getRelationType($typeName)
Get DB field name for URL param...
static getRestriction()
Get the user right required for this list type Override this function.
Definition: RevDelList.php:50
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
doPreCommitUpdates()
A hook for setVisibility(): do batch updates pre-commit.
Definition: RevDelList.php:386
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
wfGetLBFactory()
Get the load balancer factory object.
Class for creating log entries manually, to inject them into the database.
Definition: LogEntry.php:394
to move a page</td >< td > &*You are moving the page across *A non empty talk page already exists under the new or *You uncheck the box below In those you will have to move or merge the page manually if desired</td >< td > be sure to &You are responsible for making sure that links continue to point where they are supposed to go Note that the page will &a page at the new title
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1020
const DB_MASTER
Definition: Defines.php:47
acquireItemLocks()
Definition: RevDelList.php:286
static getRelationType()
Get the DB field name associated with the ID list.
Definition: RevDelList.php:40
getUser()
Get the User object.
doQuery($db)
Do the DB query to iterate through the objects.
static newGood($value=null)
Factory function for good results.
Definition: Status.php:101