MediaWiki  1.27.2
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 
84  // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
85  for ( $this->reset(); $this->current(); $this->next() ) {
86  // @codingStandardsIgnoreEnd
87  $item = $this->current();
88  if ( $item->getBits() & $bit ) {
89  return true;
90  }
91  }
92  return false;
93  }
94 
106  public function setVisibility( array $params ) {
107  $bitPars = $params['value'];
108  $comment = $params['comment'];
109  $perItemStatus = isset( $params['perItemStatus'] ) ? $params['perItemStatus'] : false;
110 
111  // CAS-style checks are done on the _deleted fields so the select
112  // does not need to use FOR UPDATE nor be in the atomic section
113  $dbw = wfGetDB( DB_MASTER );
114  $this->res = $this->doQuery( $dbw );
115 
116  $dbw->startAtomic( __METHOD__ );
117 
119  $missing = array_flip( $this->ids );
120  $this->clearFileOps();
121  $idsForLog = [];
122  $authorIds = $authorIPs = [];
123 
124  if ( $perItemStatus ) {
125  $status->itemStatuses = [];
126  }
127 
128  // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
129  for ( $this->reset(); $this->current(); $this->next() ) {
130  // @codingStandardsIgnoreEnd
132  $item = $this->current();
133  unset( $missing[$item->getId()] );
134 
135  if ( $perItemStatus ) {
136  $itemStatus = Status::newGood();
137  $status->itemStatuses[$item->getId()] = $itemStatus;
138  } else {
139  $itemStatus = $status;
140  }
141 
142  $oldBits = $item->getBits();
143  // Build the actual new rev_deleted bitfield
144  $newBits = RevisionDeleter::extractBitfield( $bitPars, $oldBits );
145 
146  if ( $oldBits == $newBits ) {
147  $itemStatus->warning( 'revdelete-no-change', $item->formatDate(), $item->formatTime() );
148  $status->failCount++;
149  continue;
150  } elseif ( $oldBits == 0 && $newBits != 0 ) {
151  $opType = 'hide';
152  } elseif ( $oldBits != 0 && $newBits == 0 ) {
153  $opType = 'show';
154  } else {
155  $opType = 'modify';
156  }
157 
158  if ( $item->isHideCurrentOp( $newBits ) ) {
159  // Cannot hide current version text
160  $itemStatus->error( 'revdelete-hide-current', $item->formatDate(), $item->formatTime() );
161  $status->failCount++;
162  continue;
163  }
164  if ( !$item->canView() ) {
165  // Cannot access this revision
166  $msg = ( $opType == 'show' ) ?
167  'revdelete-show-no-access' : 'revdelete-modify-no-access';
168  $itemStatus->error( $msg, $item->formatDate(), $item->formatTime() );
169  $status->failCount++;
170  continue;
171  }
172  // Cannot just "hide from Sysops" without hiding any fields
173  if ( $newBits == Revision::DELETED_RESTRICTED ) {
174  $itemStatus->warning( 'revdelete-only-restricted', $item->formatDate(), $item->formatTime() );
175  $status->failCount++;
176  continue;
177  }
178 
179  // Update the revision
180  $ok = $item->setBits( $newBits );
181 
182  if ( $ok ) {
183  $idsForLog[] = $item->getId();
184  $status->successCount++;
185  if ( $item->getAuthorId() > 0 ) {
186  $authorIds[] = $item->getAuthorId();
187  } elseif ( IP::isIPAddress( $item->getAuthorName() ) ) {
188  $authorIPs[] = $item->getAuthorName();
189  }
190  } else {
191  $itemStatus->error( 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
192  $status->failCount++;
193  }
194  }
195 
196  // Handle missing revisions
197  foreach ( $missing as $id => $unused ) {
198  if ( $perItemStatus ) {
199  $status->itemStatuses[$id] = Status::newFatal( 'revdelete-modify-missing', $id );
200  } else {
201  $status->error( 'revdelete-modify-missing', $id );
202  }
203  $status->failCount++;
204  }
205 
206  if ( $status->successCount == 0 ) {
207  $dbw->rollback( __METHOD__ );
208  return $status;
209  }
210 
211  // Save success count
212  $successCount = $status->successCount;
213 
214  // Move files, if there are any
215  $status->merge( $this->doPreCommitUpdates() );
216  if ( !$status->isOK() ) {
217  // Fatal error, such as no configured archive directory
218  $dbw->rollback( __METHOD__ );
219  return $status;
220  }
221 
222  // Log it
223  // @FIXME: $newBits/$oldBits set in for loop, makes IDE warnings too
224  $this->updateLog( [
225  'title' => $this->title,
226  'count' => $successCount,
227  'newBits' => $newBits,
228  'oldBits' => $oldBits,
229  'comment' => $comment,
230  'ids' => $idsForLog,
231  'authorIds' => $authorIds,
232  'authorIPs' => $authorIPs
233  ] );
234 
235  // Clear caches
236  $that = $this;
237  $dbw->onTransactionIdle( function() use ( $that ) {
238  $that->doPostCommitUpdates();
239  } );
240 
241  $dbw->endAtomic( __METHOD__ );
242 
243  return $status;
244  }
245 
250  function reloadFromMaster() {
251  $dbw = wfGetDB( DB_MASTER );
252  $this->res = $this->doQuery( $dbw );
253  }
254 
267  protected function updateLog( $params ) {
268  // Get the URL param's corresponding DB field
269  $field = RevisionDeleter::getRelationType( $this->getType() );
270  if ( !$field ) {
271  throw new MWException( "Bad log URL param type!" );
272  }
273  // Put things hidden from sysops in the suppression log
274  if ( ( $params['newBits'] | $params['oldBits'] ) & $this->getSuppressBit() ) {
275  $logType = 'suppress';
276  } else {
277  $logType = 'delete';
278  }
279  // Add params for affected page and ids
280  $logParams = $this->getLogParams( $params );
281  // Actually add the deletion log entry
282  $logEntry = new ManualLogEntry( $logType, $this->getLogAction() );
283  $logEntry->setTarget( $params['title'] );
284  $logEntry->setComment( $params['comment'] );
285  $logEntry->setParameters( $logParams );
286  $logEntry->setPerformer( $this->getUser() );
287  // Allow for easy searching of deletion log items for revision/log items
288  $logEntry->setRelations( [
289  $field => $params['ids'],
290  'target_author_id' => $params['authorIds'],
291  'target_author_ip' => $params['authorIPs'],
292  ] );
293  $logId = $logEntry->insert();
294  $logEntry->publish( $logId );
295  }
296 
301  public function getLogAction() {
302  return 'revision';
303  }
304 
310  public function getLogParams( $params ) {
311  return [
312  '4::type' => $this->getType(),
313  '5::ids' => $params['ids'],
314  '6::ofield' => $params['oldBits'],
315  '7::nfield' => $params['newBits'],
316  ];
317  }
318 
323  public function clearFileOps() {
324  }
325 
331  public function doPreCommitUpdates() {
332  return Status::newGood();
333  }
334 
340  public function doPostCommitUpdates() {
341  return Status::newGood();
342  }
343 
347  abstract public function getSuppressBit();
348 }
clearFileOps()
Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates() STUB...
Definition: RevDelList.php:323
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.
getType()
Get the internal type name of this list.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
reset()
Start iteration.
$comment
current()
Get the current list item, or false if we are at the end.
getLogParams($params)
Get log parameter array.
Definition: RevDelList.php:310
Represents a title within MediaWiki.
Definition: Title.php:34
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.
areAnySuppressed()
Indicate whether any item in this list is suppressed.
Definition: RevDelList.php:81
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:106
reloadFromMaster()
Reload the list data from the master DB.
Definition: RevDelList.php:250
getLogAction()
Get the log action for this list type.
Definition: RevDelList.php:301
__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
$params
static extractBitfield(array $bitPars, $oldfield)
Put together a rev_deleted bitfield.
title
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
updateLog($params)
Record a log entry on the action.
Definition: RevDelList.php:267
next()
Move the iteration pointer to the next list item, and return it.
doPreCommitUpdates()
A hook for setVisibility(): do batch updates pre-commit.
Definition: RevDelList.php:331
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
Class for creating log entries manually, to inject them into the database.
Definition: LogEntry.php:394
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:1004
const DB_MASTER
Definition: Defines.php:47
static getRelationType()
Get the DB field name associated with the ID list.
Definition: RevDelList.php:40
doPostCommitUpdates()
A hook for setVisibility(): do any necessary updates post-commit.
Definition: RevDelList.php:340
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