3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
19 * @ingroup RevisionDelete
23 * Abstract base class for a list of deletable items. The list class
24 * needs to be able to make a query from a set of identifiers to pull
25 * relevant rows, to return RevDelItem subclasses wrapping them, and
26 * to wrap bulk update operations.
28 abstract class RevDelList
extends RevisionListBase
{
29 function __construct( IContextSource
$context, Title
$title, array $ids ) {
30 parent
::__construct( $context, $title );
35 * Get the DB field name associated with the ID list.
36 * This used to populate the log_search table for finding log entries.
37 * Override this function.
40 public static function getRelationType() {
45 * Get the user right required for this list type
46 * Override this function.
50 public static function getRestriction() {
55 * Get the revision deletion constant for this list type
56 * Override this function.
60 public static function getRevdelConstant() {
65 * Suggest a target for the revision deletion
66 * Optionally override this function.
68 * @param Title|null $target User-supplied target
72 public static function suggestTarget( $target, array $ids ) {
77 * Set the visibility for the revisions in this list. Logging and
78 * transactions are done here.
80 * @param array $params Associative array of parameters. Members are:
81 * value: The integer value to set the visibility to
82 * comment: The log comment.
83 * perItemStatus: Set if you want per-item status reports
85 * @since 1.23 Added 'perItemStatus' param
87 public function setVisibility( $params ) {
88 $bitPars = $params['value'];
89 $comment = $params['comment'];
90 $perItemStatus = isset( $params['perItemStatus'] ) ?
$params['perItemStatus'] : false;
92 // CAS-style checks are done on the _deleted fields so the select
93 // does not need to use FOR UPDATE nor be in the atomic section
94 $dbw = wfGetDB( DB_MASTER
);
95 $this->res
= $this->doQuery( $dbw );
97 $dbw->startAtomic( __METHOD__
);
99 $status = Status
::newGood();
100 $missing = array_flip( $this->ids
);
101 $this->clearFileOps();
102 $idsForLog = array();
103 $authorIds = $authorIPs = array();
105 if ( $perItemStatus ) {
106 $status->itemStatuses
= array();
109 // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
110 for ( $this->reset(); $this->current(); $this->next() ) {
111 // @codingStandardsIgnoreEnd
112 $item = $this->current();
113 unset( $missing[$item->getId()] );
115 if ( $perItemStatus ) {
116 $itemStatus = Status
::newGood();
117 $status->itemStatuses
[$item->getId()] = $itemStatus;
119 $itemStatus = $status;
122 $oldBits = $item->getBits();
123 // Build the actual new rev_deleted bitfield
124 $newBits = RevisionDeleter
::extractBitfield( $bitPars, $oldBits );
126 if ( $oldBits == $newBits ) {
127 $itemStatus->warning( 'revdelete-no-change', $item->formatDate(), $item->formatTime() );
128 $status->failCount++
;
130 } elseif ( $oldBits == 0 && $newBits != 0 ) {
132 } elseif ( $oldBits != 0 && $newBits == 0 ) {
138 if ( $item->isHideCurrentOp( $newBits ) ) {
139 // Cannot hide current version text
140 $itemStatus->error( 'revdelete-hide-current', $item->formatDate(), $item->formatTime() );
141 $status->failCount++
;
144 if ( !$item->canView() ) {
145 // Cannot access this revision
146 $msg = ( $opType == 'show' ) ?
147 'revdelete-show-no-access' : 'revdelete-modify-no-access';
148 $itemStatus->error( $msg, $item->formatDate(), $item->formatTime() );
149 $status->failCount++
;
152 // Cannot just "hide from Sysops" without hiding any fields
153 if ( $newBits == Revision
::DELETED_RESTRICTED
) {
154 $itemStatus->warning( 'revdelete-only-restricted', $item->formatDate(), $item->formatTime() );
155 $status->failCount++
;
159 // Update the revision
160 $ok = $item->setBits( $newBits );
163 $idsForLog[] = $item->getId();
164 $status->successCount++
;
165 if ( $item->getAuthorId() > 0 ) {
166 $authorIds[] = $item->getAuthorId();
167 } elseif ( IP
::isIPAddress( $item->getAuthorName() ) ) {
168 $authorIPs[] = $item->getAuthorName();
171 $itemStatus->error( 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
172 $status->failCount++
;
176 // Handle missing revisions
177 foreach ( $missing as $id => $unused ) {
178 if ( $perItemStatus ) {
179 $status->itemStatuses
[$id] = Status
::newFatal( 'revdelete-modify-missing', $id );
181 $status->error( 'revdelete-modify-missing', $id );
183 $status->failCount++
;
186 if ( $status->successCount
== 0 ) {
187 $dbw->rollback( __METHOD__
);
191 // Save success count
192 $successCount = $status->successCount
;
194 // Move files, if there are any
195 $status->merge( $this->doPreCommitUpdates() );
196 if ( !$status->isOK() ) {
197 // Fatal error, such as no configured archive directory
198 $dbw->rollback( __METHOD__
);
203 $this->updateLog( array(
204 'title' => $this->title
,
205 'count' => $successCount,
206 'newBits' => $newBits,
207 'oldBits' => $oldBits,
208 'comment' => $comment,
210 'authorIds' => $authorIds,
211 'authorIPs' => $authorIPs
216 $dbw->onTransactionIdle( function() use ( $that ) {
217 $that->doPostCommitUpdates();
220 $dbw->endAtomic( __METHOD__
);
226 * Reload the list data from the master DB. This can be done after setVisibility()
227 * to allow $item->getHTML() to show the new data.
229 function reloadFromMaster() {
230 $dbw = wfGetDB( DB_MASTER
);
231 $this->res
= $this->doQuery( $dbw );
235 * Record a log entry on the action
236 * @param array $params Associative array of parameters:
237 * newBits: The new value of the *_deleted bitfield
238 * oldBits: The old value of the *_deleted bitfield.
239 * title: The target title
241 * comment: The log comment
242 * authorsIds: The array of the user IDs of the offenders
243 * authorsIPs: The array of the IP/anon user offenders
244 * @throws MWException
246 protected function updateLog( $params ) {
247 // Get the URL param's corresponding DB field
248 $field = RevisionDeleter
::getRelationType( $this->getType() );
250 throw new MWException( "Bad log URL param type!" );
252 // Put things hidden from sysops in the oversight log
253 if ( ( $params['newBits'] |
$params['oldBits'] ) & $this->getSuppressBit() ) {
254 $logType = 'suppress';
258 // Add params for affected page and ids
259 $logParams = $this->getLogParams( $params );
260 // Actually add the deletion log entry
261 $logEntry = new ManualLogEntry( $logType, $this->getLogAction() );
262 $logEntry->setTarget( $params['title'] );
263 $logEntry->setComment( $params['comment'] );
264 $logEntry->setParameters( $logParams );
265 $logEntry->setPerformer( $this->getUser() );
266 // Allow for easy searching of deletion log items for revision/log items
267 $logEntry->setRelations( array(
268 $field => $params['ids'],
269 'target_author_id' => $params['authorIds'],
270 'target_author_ip' => $params['authorIPs'],
272 $logId = $logEntry->insert();
273 $logEntry->publish( $logId );
277 * Get the log action for this list type
280 public function getLogAction() {
285 * Get log parameter array.
286 * @param array $params Associative array of log parameters, same as updateLog()
289 public function getLogParams( $params ) {
291 '4::type' => $this->getType(),
292 '5::ids' => $params['ids'],
293 '6::ofield' => $params['oldBits'],
294 '7::nfield' => $params['newBits'],
299 * Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates()
302 public function clearFileOps() {
306 * A hook for setVisibility(): do batch updates pre-commit.
310 public function doPreCommitUpdates() {
311 return Status
::newGood();
315 * A hook for setVisibility(): do any necessary updates post-commit.
319 public function doPostCommitUpdates() {
320 return Status
::newGood();
324 * Get the integer value of the flag used for suppression
326 abstract public function getSuppressBit();