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( RequestContext
$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.
20 public static function getRelationType() {
25 * Set the visibility for the revisions in this list. Logging and
26 * transactions are done here.
28 * @param $params Associative array of parameters. Members are:
29 * value: The integer value to set the visibility to
30 * comment: The log comment.
33 public function setVisibility( $params ) {
34 $bitPars = $params['value'];
35 $comment = $params['comment'];
38 $dbw = wfGetDB( DB_MASTER
);
39 $this->doQuery( $dbw );
41 $status = Status
::newGood();
42 $missing = array_flip( $this->ids
);
43 $this->clearFileOps();
45 $authorIds = $authorIPs = array();
47 for ( $this->reset(); $this->current(); $this->next() ) {
48 $item = $this->current();
49 unset( $missing[ $item->getId() ] );
51 $oldBits = $item->getBits();
52 // Build the actual new rev_deleted bitfield
53 $newBits = SpecialRevisionDelete
::extractBitfield( $bitPars, $oldBits );
55 if ( $oldBits == $newBits ) {
56 $status->warning( 'revdelete-no-change', $item->formatDate(), $item->formatTime() );
59 } elseif ( $oldBits == 0 && $newBits != 0 ) {
61 } elseif ( $oldBits != 0 && $newBits == 0 ) {
67 if ( $item->isHideCurrentOp( $newBits ) ) {
68 // Cannot hide current version text
69 $status->error( 'revdelete-hide-current', $item->formatDate(), $item->formatTime() );
73 if ( !$item->canView() ) {
74 // Cannot access this revision
75 $msg = ($opType == 'show') ?
76 'revdelete-show-no-access' : 'revdelete-modify-no-access';
77 $status->error( $msg, $item->formatDate(), $item->formatTime() );
81 // Cannot just "hide from Sysops" without hiding any fields
82 if( $newBits == Revision
::DELETED_RESTRICTED
) {
83 $status->warning( 'revdelete-only-restricted', $item->formatDate(), $item->formatTime() );
88 // Update the revision
89 $ok = $item->setBits( $newBits );
92 $idsForLog[] = $item->getId();
93 $status->successCount++
;
94 if( $item->getAuthorId() > 0 ) {
95 $authorIds[] = $item->getAuthorId();
96 } elseif( IP
::isIPAddress( $item->getAuthorName() ) ) {
97 $authorIPs[] = $item->getAuthorName();
100 $status->error( 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
101 $status->failCount++
;
105 // Handle missing revisions
106 foreach ( $missing as $id => $unused ) {
107 $status->error( 'revdelete-modify-missing', $id );
108 $status->failCount++
;
111 if ( $status->successCount
== 0 ) {
117 // Save success count
118 $successCount = $status->successCount
;
120 // Move files, if there are any
121 $status->merge( $this->doPreCommitUpdates() );
122 if ( !$status->isOK() ) {
123 // Fatal error, such as no configured archive directory
129 $this->updateLog( array(
130 'title' => $this->title
,
131 'count' => $successCount,
132 'newBits' => $newBits,
133 'oldBits' => $oldBits,
134 'comment' => $comment,
136 'authorIds' => $authorIds,
137 'authorIPs' => $authorIPs
142 $status->merge( $this->doPostCommitUpdates() );
147 * Reload the list data from the master DB. This can be done after setVisibility()
148 * to allow $item->getHTML() to show the new data.
150 function reloadFromMaster() {
151 $dbw = wfGetDB( DB_MASTER
);
152 $this->res
= $this->doQuery( $dbw );
156 * Record a log entry on the action
157 * @param $params Associative array of parameters:
158 * newBits: The new value of the *_deleted bitfield
159 * oldBits: The old value of the *_deleted bitfield.
160 * title: The target title
162 * comment: The log comment
163 * authorsIds: The array of the user IDs of the offenders
164 * authorsIPs: The array of the IP/anon user offenders
166 protected function updateLog( $params ) {
167 // Get the URL param's corresponding DB field
168 $field = RevisionDeleter
::getRelationType( $this->getType() );
170 throw new MWException( "Bad log URL param type!" );
172 // Put things hidden from sysops in the oversight log
173 if ( ( $params['newBits'] |
$params['oldBits'] ) & $this->getSuppressBit() ) {
174 $logType = 'suppress';
178 // Add params for effected page and ids
179 $logParams = $this->getLogParams( $params );
180 // Actually add the deletion log entry
181 $log = new LogPage( $logType );
182 $logid = $log->addEntry( $this->getLogAction(), $params['title'],
183 $params['comment'], $logParams );
184 // Allow for easy searching of deletion log items for revision/log items
185 $log->addRelations( $field, $params['ids'], $logid );
186 $log->addRelations( 'target_author_id', $params['authorIds'], $logid );
187 $log->addRelations( 'target_author_ip', $params['authorIPs'], $logid );
191 * Get the log action for this list type
193 public function getLogAction() {
198 * Get log parameter array.
199 * @param $params Associative array of log parameters, same as updateLog()
202 public function getLogParams( $params ) {
205 implode( ',', $params['ids'] ),
206 "ofield={$params['oldBits']}",
207 "nfield={$params['newBits']}"
212 * Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates()
215 public function clearFileOps() {
219 * A hook for setVisibility(): do batch updates pre-commit.
223 public function doPreCommitUpdates() {
224 return Status
::newGood();
228 * A hook for setVisibility(): do any necessary updates post-commit.
232 public function doPostCommitUpdates() {
233 return Status
::newGood();
237 * Get the integer value of the flag used for suppression
239 abstract public function getSuppressBit();
243 * Abstract base class for deletable items
245 abstract class RevDel_Item
extends RevisionItemBase
{
247 * Returns true if the item is "current", and the operation to set the given
248 * bits can't be executed for that reason
251 public function isHideCurrentOp( $newBits ) {
256 * Get the current deletion bitfield value
258 abstract public function getBits();
261 * Set the visibility of the item. This should do any necessary DB queries.
263 * The DB update query should have a condition which forces it to only update
264 * if the value in the DB matches the value fetched earlier with the SELECT.
265 * If the update fails because it did not match, the function should return
266 * false. This prevents concurrency problems.
268 * @return boolean success
270 abstract public function setBits( $newBits );