4 * Abstract base class for a list of deletable items. The list class
5 * needs to be able to make a query from a set of identifiers to pull
6 * relevant rows, to return RevDel_Item subclasses wrapping them, and
7 * to wrap bulk update operations.
9 abstract class RevDel_List
extends RevisionListBase
{
10 function __construct( IContextSource
$context, Title
$title, array $ids ) {
11 parent
::__construct( $context, $title );
16 * Get the DB field name associated with the ID list.
17 * This used to populate the log_search table for finding log entries.
18 * Override this function.
21 public static function getRelationType() {
26 * Set the visibility for the revisions in this list. Logging and
27 * transactions are done here.
29 * @param $params array Associative array of parameters. Members are:
30 * value: The integer value to set the visibility to
31 * comment: The log comment.
34 public function setVisibility( $params ) {
35 $bitPars = $params['value'];
36 $comment = $params['comment'];
39 $dbw = wfGetDB( DB_MASTER
);
40 $this->doQuery( $dbw );
41 $dbw->begin( __METHOD__
);
42 $status = Status
::newGood();
43 $missing = array_flip( $this->ids
);
44 $this->clearFileOps();
46 $authorIds = $authorIPs = array();
48 for ( $this->reset(); $this->current(); $this->next() ) {
49 $item = $this->current();
50 unset( $missing[ $item->getId() ] );
52 $oldBits = $item->getBits();
53 // Build the actual new rev_deleted bitfield
54 $newBits = SpecialRevisionDelete
::extractBitfield( $bitPars, $oldBits );
56 if ( $oldBits == $newBits ) {
57 $status->warning( 'revdelete-no-change', $item->formatDate(), $item->formatTime() );
60 } elseif ( $oldBits == 0 && $newBits != 0 ) {
62 } elseif ( $oldBits != 0 && $newBits == 0 ) {
68 if ( $item->isHideCurrentOp( $newBits ) ) {
69 // Cannot hide current version text
70 $status->error( 'revdelete-hide-current', $item->formatDate(), $item->formatTime() );
74 if ( !$item->canView() ) {
75 // Cannot access this revision
76 $msg = ($opType == 'show') ?
77 'revdelete-show-no-access' : 'revdelete-modify-no-access';
78 $status->error( $msg, $item->formatDate(), $item->formatTime() );
82 // Cannot just "hide from Sysops" without hiding any fields
83 if( $newBits == Revision
::DELETED_RESTRICTED
) {
84 $status->warning( 'revdelete-only-restricted', $item->formatDate(), $item->formatTime() );
89 // Update the revision
90 $ok = $item->setBits( $newBits );
93 $idsForLog[] = $item->getId();
94 $status->successCount++
;
95 if( $item->getAuthorId() > 0 ) {
96 $authorIds[] = $item->getAuthorId();
97 } elseif( IP
::isIPAddress( $item->getAuthorName() ) ) {
98 $authorIPs[] = $item->getAuthorName();
101 $status->error( 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
102 $status->failCount++
;
106 // Handle missing revisions
107 foreach ( $missing as $id => $unused ) {
108 $status->error( 'revdelete-modify-missing', $id );
109 $status->failCount++
;
112 if ( $status->successCount
== 0 ) {
114 $dbw->rollback( __METHOD__
);
118 // Save success count
119 $successCount = $status->successCount
;
121 // Move files, if there are any
122 $status->merge( $this->doPreCommitUpdates() );
123 if ( !$status->isOK() ) {
124 // Fatal error, such as no configured archive directory
125 $dbw->rollback( __METHOD__
);
130 $this->updateLog( array(
131 'title' => $this->title
,
132 'count' => $successCount,
133 'newBits' => $newBits,
134 'oldBits' => $oldBits,
135 'comment' => $comment,
137 'authorIds' => $authorIds,
138 'authorIPs' => $authorIPs
140 $dbw->commit( __METHOD__
);
143 $status->merge( $this->doPostCommitUpdates() );
148 * Reload the list data from the master DB. This can be done after setVisibility()
149 * to allow $item->getHTML() to show the new data.
151 function reloadFromMaster() {
152 $dbw = wfGetDB( DB_MASTER
);
153 $this->res
= $this->doQuery( $dbw );
157 * Record a log entry on the action
158 * @param $params array Associative array of parameters:
159 * newBits: The new value of the *_deleted bitfield
160 * oldBits: The old value of the *_deleted bitfield.
161 * title: The target title
163 * comment: The log comment
164 * authorsIds: The array of the user IDs of the offenders
165 * authorsIPs: The array of the IP/anon user offenders
167 protected function updateLog( $params ) {
168 // Get the URL param's corresponding DB field
169 $field = RevisionDeleter
::getRelationType( $this->getType() );
171 throw new MWException( "Bad log URL param type!" );
173 // Put things hidden from sysops in the oversight log
174 if ( ( $params['newBits'] |
$params['oldBits'] ) & $this->getSuppressBit() ) {
175 $logType = 'suppress';
179 // Add params for effected page and ids
180 $logParams = $this->getLogParams( $params );
181 // Actually add the deletion log entry
182 $log = new LogPage( $logType );
183 $logid = $log->addEntry( $this->getLogAction(), $params['title'],
184 $params['comment'], $logParams );
185 // Allow for easy searching of deletion log items for revision/log items
186 $log->addRelations( $field, $params['ids'], $logid );
187 $log->addRelations( 'target_author_id', $params['authorIds'], $logid );
188 $log->addRelations( 'target_author_ip', $params['authorIPs'], $logid );
192 * Get the log action for this list type
195 public function getLogAction() {
200 * Get log parameter array.
201 * @param $params array Associative array of log parameters, same as updateLog()
204 public function getLogParams( $params ) {
207 implode( ',', $params['ids'] ),
208 "ofield={$params['oldBits']}",
209 "nfield={$params['newBits']}"
214 * Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates()
217 public function clearFileOps() {
221 * A hook for setVisibility(): do batch updates pre-commit.
225 public function doPreCommitUpdates() {
226 return Status
::newGood();
230 * A hook for setVisibility(): do any necessary updates post-commit.
234 public function doPostCommitUpdates() {
235 return Status
::newGood();
239 * Get the integer value of the flag used for suppression
241 abstract public function getSuppressBit();
245 * Abstract base class for deletable items
247 abstract class RevDel_Item
extends RevisionItemBase
{
249 * Returns true if the item is "current", and the operation to set the given
250 * bits can't be executed for that reason
254 public function isHideCurrentOp( $newBits ) {
259 * Get the current deletion bitfield value
261 abstract public function getBits();
264 * Set the visibility of the item. This should do any necessary DB queries.
266 * The DB update query should have a condition which forces it to only update
267 * if the value in the DB matches the value fetched earlier with the SELECT.
268 * If the update fails because it did not match, the function should return
269 * false. This prevents concurrency problems.
271 * @return boolean success
273 abstract public function setBits( $newBits );