MediaWiki REL1_28
RevDelList.php
Go to the documentation of this file.
1<?php
28abstract 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 ) {
106 $status = Status::newGood();
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(
124 function () {
125 // Release locks on commit or error
126 $this->releaseItemLocks();
127 },
128 __METHOD__
129 );
130
131 $missing = array_flip( $this->ids );
132 $this->clearFileOps();
133 $idsForLog = [];
134 $authorIds = $authorIPs = [];
135
136 if ( $perItemStatus ) {
137 $status->itemStatuses = [];
138 }
139
140 // For multi-item deletions, set the old/new bitfields in log_params such that "hid X"
141 // shows in logs if field X was hidden from ANY item and likewise for "unhid Y". Note the
142 // form does not let the same field get hidden and unhidden in different items at once.
143 $virtualOldBits = 0;
144 $virtualNewBits = 0;
145 $logType = 'delete';
146
147 // Will be filled with id => [old, new bits] information and
148 // passed to doPostCommitUpdates().
149 $visibilityChangeMap = [];
150
152 foreach ( $this as $item ) {
153 unset( $missing[$item->getId()] );
154
155 if ( $perItemStatus ) {
156 $itemStatus = Status::newGood();
157 $status->itemStatuses[$item->getId()] = $itemStatus;
158 } else {
159 $itemStatus = $status;
160 }
161
162 $oldBits = $item->getBits();
163 // Build the actual new rev_deleted bitfield
164 $newBits = RevisionDeleter::extractBitfield( $bitPars, $oldBits );
165
166 if ( $oldBits == $newBits ) {
167 $itemStatus->warning(
168 'revdelete-no-change', $item->formatDate(), $item->formatTime() );
169 $status->failCount++;
170 continue;
171 } elseif ( $oldBits == 0 && $newBits != 0 ) {
172 $opType = 'hide';
173 } elseif ( $oldBits != 0 && $newBits == 0 ) {
174 $opType = 'show';
175 } else {
176 $opType = 'modify';
177 }
178
179 if ( $item->isHideCurrentOp( $newBits ) ) {
180 // Cannot hide current version text
181 $itemStatus->error(
182 'revdelete-hide-current', $item->formatDate(), $item->formatTime() );
183 $status->failCount++;
184 continue;
185 } elseif ( !$item->canView() ) {
186 // Cannot access this revision
187 $msg = ( $opType == 'show' ) ?
188 'revdelete-show-no-access' : 'revdelete-modify-no-access';
189 $itemStatus->error( $msg, $item->formatDate(), $item->formatTime() );
190 $status->failCount++;
191 continue;
192 // Cannot just "hide from Sysops" without hiding any fields
193 } elseif ( $newBits == Revision::DELETED_RESTRICTED ) {
194 $itemStatus->warning(
195 'revdelete-only-restricted', $item->formatDate(), $item->formatTime() );
196 $status->failCount++;
197 continue;
198 }
199
200 // Update the revision
201 $ok = $item->setBits( $newBits );
202
203 if ( $ok ) {
204 $idsForLog[] = $item->getId();
205 // If any item field was suppressed or unsupressed
206 if ( ( $oldBits | $newBits ) & $this->getSuppressBit() ) {
207 $logType = 'suppress';
208 }
209 // Track which fields where (un)hidden for each item
210 $addedBits = ( $oldBits ^ $newBits ) & $newBits;
211 $removedBits = ( $oldBits ^ $newBits ) & $oldBits;
212 $virtualNewBits |= $addedBits;
213 $virtualOldBits |= $removedBits;
214
215 $status->successCount++;
216 if ( $item->getAuthorId() > 0 ) {
217 $authorIds[] = $item->getAuthorId();
218 } elseif ( IP::isIPAddress( $item->getAuthorName() ) ) {
219 $authorIPs[] = $item->getAuthorName();
220 }
221
222 // Save the old and new bits in $visibilityChangeMap for
223 // later use.
224 $visibilityChangeMap[$item->getId()] = [
225 'oldBits' => $oldBits,
226 'newBits' => $newBits,
227 ];
228 } else {
229 $itemStatus->error(
230 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
231 $status->failCount++;
232 }
233 }
234
235 // Handle missing revisions
236 foreach ( $missing as $id => $unused ) {
237 if ( $perItemStatus ) {
238 $status->itemStatuses[$id] = Status::newFatal( 'revdelete-modify-missing', $id );
239 } else {
240 $status->error( 'revdelete-modify-missing', $id );
241 }
242 $status->failCount++;
243 }
244
245 if ( $status->successCount == 0 ) {
246 $dbw->endAtomic( __METHOD__ );
247 return $status;
248 }
249
250 // Save success count
251 $successCount = $status->successCount;
252
253 // Move files, if there are any
254 $status->merge( $this->doPreCommitUpdates() );
255 if ( !$status->isOK() ) {
256 // Fatal error, such as no configured archive directory or I/O failures
257 wfGetLBFactory()->rollbackMasterChanges( __METHOD__ );
258 return $status;
259 }
260
261 // Log it
262 $this->updateLog(
263 $logType,
264 [
265 'title' => $this->title,
266 'count' => $successCount,
267 'newBits' => $virtualNewBits,
268 'oldBits' => $virtualOldBits,
269 'comment' => $comment,
270 'ids' => $idsForLog,
271 'authorIds' => $authorIds,
272 'authorIPs' => $authorIPs
273 ]
274 );
275
276 // Clear caches after commit
277 DeferredUpdates::addCallableUpdate(
278 function () use ( $visibilityChangeMap ) {
279 $this->doPostCommitUpdates( $visibilityChangeMap );
280 },
281 DeferredUpdates::PRESEND,
282 $dbw
283 );
284
285 $dbw->endAtomic( __METHOD__ );
286
287 return $status;
288 }
289
290 final protected function acquireItemLocks() {
291 $status = Status::newGood();
293 foreach ( $this as $item ) {
294 $status->merge( $item->lock() );
295 }
296
297 return $status;
298 }
299
300 final protected function releaseItemLocks() {
301 $status = Status::newGood();
303 foreach ( $this as $item ) {
304 $status->merge( $item->unlock() );
305 }
306
307 return $status;
308 }
309
314 function reloadFromMaster() {
315 $dbw = wfGetDB( DB_MASTER );
316 $this->res = $this->doQuery( $dbw );
317 }
318
332 private function updateLog( $logType, $params ) {
333 // Get the URL param's corresponding DB field
334 $field = RevisionDeleter::getRelationType( $this->getType() );
335 if ( !$field ) {
336 throw new MWException( "Bad log URL param type!" );
337 }
338 // Add params for affected page and ids
339 $logParams = $this->getLogParams( $params );
340 // Actually add the deletion log entry
341 $logEntry = new ManualLogEntry( $logType, $this->getLogAction() );
342 $logEntry->setTarget( $params['title'] );
343 $logEntry->setComment( $params['comment'] );
344 $logEntry->setParameters( $logParams );
345 $logEntry->setPerformer( $this->getUser() );
346 // Allow for easy searching of deletion log items for revision/log items
347 $logEntry->setRelations( [
348 $field => $params['ids'],
349 'target_author_id' => $params['authorIds'],
350 'target_author_ip' => $params['authorIPs'],
351 ] );
352 $logId = $logEntry->insert();
353 $logEntry->publish( $logId );
354 }
355
360 public function getLogAction() {
361 return 'revision';
362 }
363
369 public function getLogParams( $params ) {
370 return [
371 '4::type' => $this->getType(),
372 '5::ids' => $params['ids'],
373 '6::ofield' => $params['oldBits'],
374 '7::nfield' => $params['newBits'],
375 ];
376 }
377
382 public function clearFileOps() {
383 }
384
390 public function doPreCommitUpdates() {
391 return Status::newGood();
392 }
393
400 public function doPostCommitUpdates( array $visibilityChangeMap ) {
401 return Status::newGood();
402 }
403
407 abstract public function getSuppressBit();
408}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfGetLBFactory()
Get the load balancer factory object.
getUser()
Get the User object.
IContextSource $context
static isIPAddress( $ip)
Determine if a string is as valid IP address or network (CIDR prefix).
Definition IP.php:79
MediaWiki exception.
Class for creating log entries manually, to inject them into the database.
Definition LogEntry.php:394
Abstract base class for a list of deletable items.
setVisibility(array $params)
Set the visibility for the revisions in this list.
areAnySuppressed()
Indicate whether any item in this list is suppressed.
static suggestTarget( $target, array $ids)
Suggest a target for the revision deletion Optionally override this function.
doPreCommitUpdates()
A hook for setVisibility(): do batch updates pre-commit.
__construct(IContextSource $context, Title $title, array $ids)
static getRestriction()
Get the user right required for this list type Override this function.
getLogAction()
Get the log action for this list type.
clearFileOps()
Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates() STUB.
static getRelationType()
Get the DB field name associated with the ID list.
doPostCommitUpdates(array $visibilityChangeMap)
A hook for setVisibility(): do any necessary updates post-commit.
getSuppressBit()
Get the integer value of the flag used for suppression.
getLogParams( $params)
Get log parameter array.
static getRevdelConstant()
Get the revision deletion constant for this list type Override this function.
updateLog( $logType, $params)
Record a log entry on the action.
reloadFromMaster()
Reload the list data from the master DB.
static getRelationType( $typeName)
Get DB field name for URL param... Future code for other things may also track other types of revisio...
static extractBitfield(array $bitPars, $oldfield)
Put together a rev_deleted bitfield.
List for revision table items for a single page.
getType()
Get the internal type name of this list.
doQuery( $db)
Do the DB query to iterate through the objects.
const DELETED_RESTRICTED
Definition Revision.php:88
Represents a title within MediaWiki.
Definition Title.php:36
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
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:1049
the array() calling protocol came about after MediaWiki 1.4rc1.
$comment
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:37
Interface for objects which can provide a MediaWiki context on request.
title
const DB_MASTER
Definition defines.php:23
$params