3 * Temporary b/c interface, collection of static functions.
6 class RevisionDeleter
{
8 * Checks for a change in the bitfield for a certain option and updates the
9 * provided array accordingly.
11 * @param $desc String: description to add to the array if the option was
13 * @param $field Integer: the bitmask describing the single option.
14 * @param $diff Integer: the xor of the old and new bitfields.
15 * @param $new Integer: the new bitfield
16 * @param $arr Array: the array to update.
18 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
19 if( $diff & $field ) {
20 $arr[ ( $new & $field ) ?
0 : 1 ][] = $desc;
25 * Gets an array of message keys describing the changes made to the visibility
26 * of the revision. If the resulting array is $arr, then $arr[0] will contain an
27 * array of strings describing the items that were hidden, $arr[2] will contain
28 * an array of strings describing the items that were unhidden, and $arr[3] will
29 * contain an array with a single string, which can be one of "applied
30 * restrictions to sysops", "removed restrictions from sysops", or null.
32 * @param $n Integer: the new bitfield.
33 * @param $o Integer: the old bitfield.
34 * @return An array as described above.
36 protected static function getChanges( $n, $o ) {
38 $ret = array( 0 => array(), 1 => array(), 2 => array() );
39 // Build bitfield changes in language
40 self
::checkItem( 'revdelete-content',
41 Revision
::DELETED_TEXT
, $diff, $n, $ret );
42 self
::checkItem( 'revdelete-summary',
43 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
44 self
::checkItem( 'revdelete-uname',
45 Revision
::DELETED_USER
, $diff, $n, $ret );
46 // Restriction application to sysops
47 if( $diff & Revision
::DELETED_RESTRICTED
) {
48 if( $n & Revision
::DELETED_RESTRICTED
)
49 $ret[2][] = 'revdelete-restricted';
51 $ret[2][] = 'revdelete-unrestricted';
57 * Gets a log message to describe the given revision visibility change. This
58 * message will be of the form "[hid {content, edit summary, username}];
59 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
61 * @param $count Integer: The number of effected revisions.
62 * @param $nbitfield Integer: The new bitfield for the revision.
63 * @param $obitfield Integer: The old bitfield for the revision.
64 * @param $isForLog Boolean
65 * @param $forContent Boolean
67 public static function getLogMessage( $count, $nbitfield, $obitfield, $isForLog = false, $forContent = false ) {
68 global $wgLang, $wgContLang;
70 $lang = $forContent ?
$wgContLang : $wgLang;
71 $msgFunc = $forContent ?
"wfMsgForContent" : "wfMsg";
74 $changes = self
::getChanges( $nbitfield, $obitfield );
75 array_walk($changes, 'RevisionDeleter::expandMessageArray', $forContent);
77 $changesText = array();
79 if( count( $changes[0] ) ) {
80 $changesText[] = $msgFunc( 'revdelete-hid', $lang->commaList( $changes[0] ) );
82 if( count( $changes[1] ) ) {
83 $changesText[] = $msgFunc( 'revdelete-unhid', $lang->commaList( $changes[1] ) );
86 $s = $lang->semicolonList( $changesText );
87 if( count( $changes[2] ) ) {
88 $s .= $s ?
' (' . $changes[2][0] . ')' : ' ' . $changes[2][0];
91 $msg = $isForLog ?
'logdelete-log-message' : 'revdelete-log-message';
92 return wfMsgExt( $msg, $forContent ?
array( 'parsemag', 'content' ) : array( 'parsemag' ), $s, $lang->formatNum($count) );
95 private static function expandMessageArray(& $msg, $key, $forContent) {
96 if ( is_array ($msg) ) {
97 array_walk($msg, 'RevisionDeleter::expandMessageArray', $forContent);
100 $msg = wfMsgForContent($msg);
107 // Get DB field name for URL param...
108 // Future code for other things may also track
109 // other types of revision-specific changes.
110 // @returns string One of log_id/rev_id/fa_id/ar_timestamp/oi_archive_name
111 public static function getRelationType( $typeName ) {
112 if ( isset( SpecialRevisionDelete
::$deprecatedTypeMap[$typeName] ) ) {
113 $typeName = SpecialRevisionDelete
::$deprecatedTypeMap[$typeName];
115 if ( isset( SpecialRevisionDelete
::$allowedTypes[$typeName] ) ) {
116 $class = SpecialRevisionDelete
::$allowedTypes[$typeName]['list-class'];
117 $list = new $class( null, null, null );
118 return $list->getIdField();
124 // Checks if a revision still exists in the revision table.
125 // If it doesn't, returns the corresponding ar_timestamp field
126 // so that this key can be used instead.
127 public static function checkRevisionExistence( $title, $revid ) {
128 $dbr = wfGetDB( DB_SLAVE
);
129 $exists = $dbr->selectField( 'revision', '1',
130 array( 'rev_id' => $revid ), __METHOD__
);
136 $timestamp = $dbr->selectField( 'archive', 'ar_timestamp',
137 array( 'ar_namespace' => $title->getNamespace(),
138 'ar_title' => $title->getDBkey(),
139 'ar_rev_id' => $revid ), __METHOD__
);
144 // Creates utility links for log entries.
145 public static function getLogLinks( $title, $paramArray, $skin, $messages ) {
148 if( count($paramArray) >= 2 ) {
149 // Different revision types use different URL params...
150 $originalKey = $key = $paramArray[0];
151 // $paramArray[1] is a CSV of the IDs
152 $Ids = explode( ',', $paramArray[1] );
153 $query = $paramArray[1];
156 // For if undeleted revisions are found amidst deleted ones.
157 $undeletedRevisions = array();
159 // This is not going to work if some revs are deleted and some
161 if ($key == 'revision') {
162 foreach( $Ids as $k => $id ) {
164 self
::checkRevisionExistence( $title, $id );
166 if ($existResult !== true) {
168 $Ids[$k] = $existResult;
170 // Undeleted revision amidst deleted ones
172 $undeletedRevisions[] = $id;
176 if ( $key == $originalKey ) {
177 $Ids = $undeletedRevisions;
178 $undeletedRevisions = array();
182 // Diff link for single rev deletions
183 if( count($Ids) == 1 && !count($undeletedRevisions) ) {
184 // Live revision diffs...
185 if( in_array( $key, array( 'oldid', 'revision' ) ) ) {
186 $revert[] = $skin->link(
191 'diff' => intval( $Ids[0] ),
194 array( 'known', 'noclasses' )
196 // Deleted revision diffs...
197 } else if( in_array( $key, array( 'artimestamp','archive' ) ) ) {
198 $revert[] = $skin->link(
199 SpecialPage
::getTitleFor( 'Undelete' ),
203 'target' => $title->getPrefixedDBKey(),
205 'timestamp' => $Ids[0]
207 array( 'known', 'noclasses' )
212 // View/modify link...
213 if ( count($undeletedRevisions) ) {
214 // FIXME THIS IS A HORRIBLE HORRIBLE HACK AND SHOULD DIE
215 // It's not possible to pass a list of both deleted and
216 // undeleted revisions to SpecialRevisionDelete, so we're
217 // stuck with two links. See bug 23363.
218 $restoreLinks = array();
220 $restoreLinks[] = $skin->link(
221 SpecialPage
::getTitleFor( 'Revisiondelete' ),
222 $messages['revdel-restore-visible'],
225 'target' => $title->getPrefixedText(),
226 'type' => $originalKey,
227 'ids' => implode(',', $undeletedRevisions),
229 array( 'known', 'noclasses' )
232 $restoreLinks[] = $skin->link(
233 SpecialPage
::getTitleFor( 'Revisiondelete' ),
234 $messages['revdel-restore-deleted'],
237 'target' => $title->getPrefixedText(),
239 'ids' => implode(',', $Ids),
241 array( 'known', 'noclasses' )
244 $revert[] = $messages['revdel-restore'] . ' [' .
245 $wgLang->pipeList( $restoreLinks ) . ']';
247 $revert[] = $skin->link(
248 SpecialPage
::getTitleFor( 'Revisiondelete' ),
249 $messages['revdel-restore'],
252 'target' => $title->getPrefixedText(),
254 'ids' => implode(',', $Ids),
256 array( 'known', 'noclasses' )
261 $revert = wfMsg( 'parentheses', $wgLang->pipeList( $revert ) );
268 * Abstract base class for a list of deletable items
270 abstract class RevDel_List
{
271 var $special, $title, $ids, $res, $current;
272 var $type = null; // override this
273 var $idField = null; // override this
274 var $dateField = false; // override this
275 var $authorIdField = false; // override this
276 var $authorNameField = false; // override this
279 * @param $special The parent SpecialPage
280 * @param $title The target title
281 * @param $ids Array of IDs
283 public function __construct( $special, $title, $ids ) {
284 $this->special
= $special;
285 $this->title
= $title;
290 * Get the internal type name of this list. Equal to the table name.
292 public function getType() {
297 * Get the DB field name associated with the ID list
299 public function getIdField() {
300 return $this->idField
;
304 * Get the DB field name storing timestamps
306 public function getTimestampField() {
307 return $this->dateField
;
311 * Get the DB field name storing user ids
313 public function getAuthorIdField() {
314 return $this->authorIdField
;
318 * Get the DB field name storing user names
320 public function getAuthorNameField() {
321 return $this->authorNameField
;
324 * Set the visibility for the revisions in this list. Logging and
325 * transactions are done here.
327 * @param $params Associative array of parameters. Members are:
328 * value: The integer value to set the visibility to
329 * comment: The log comment.
332 public function setVisibility( $params ) {
333 $bitPars = $params['value'];
334 $comment = $params['comment'];
337 $dbw = wfGetDB( DB_MASTER
);
338 $this->doQuery( $dbw );
340 $status = Status
::newGood();
341 $missing = array_flip( $this->ids
);
342 $this->clearFileOps();
343 $idsForLog = array();
344 $authorIds = $authorIPs = array();
346 for ( $this->reset(); $this->current(); $this->next() ) {
347 $item = $this->current();
348 unset( $missing[ $item->getId() ] );
350 $oldBits = $item->getBits();
351 // Build the actual new rev_deleted bitfield
352 $newBits = SpecialRevisionDelete
::extractBitfield( $bitPars, $oldBits );
354 if ( $oldBits == $newBits ) {
355 $status->warning( 'revdelete-no-change', $item->formatDate(), $item->formatTime() );
356 $status->failCount++
;
358 } elseif ( $oldBits == 0 && $newBits != 0 ) {
360 } elseif ( $oldBits != 0 && $newBits == 0 ) {
366 if ( $item->isHideCurrentOp( $newBits ) ) {
367 // Cannot hide current version text
368 $status->error( 'revdelete-hide-current', $item->formatDate(), $item->formatTime() );
369 $status->failCount++
;
372 if ( !$item->canView() ) {
373 // Cannot access this revision
374 $msg = ($opType == 'show') ?
375 'revdelete-show-no-access' : 'revdelete-modify-no-access';
376 $status->error( $msg, $item->formatDate(), $item->formatTime() );
377 $status->failCount++
;
380 // Cannot just "hide from Sysops" without hiding any fields
381 if( $newBits == Revision
::DELETED_RESTRICTED
) {
382 $status->warning( 'revdelete-only-restricted', $item->formatDate(), $item->formatTime() );
383 $status->failCount++
;
387 // Update the revision
388 $ok = $item->setBits( $newBits );
391 $idsForLog[] = $item->getId();
392 $status->successCount++
;
393 if( $item->getAuthorId() > 0 ) {
394 $authorIds[] = $item->getAuthorId();
395 } else if( IP
::isIPAddress( $item->getAuthorName() ) ) {
396 $authorIPs[] = $item->getAuthorName();
399 $status->error( 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
400 $status->failCount++
;
404 // Handle missing revisions
405 foreach ( $missing as $id => $unused ) {
406 $status->error( 'revdelete-modify-missing', $id );
407 $status->failCount++
;
410 if ( $status->successCount
== 0 ) {
416 // Save success count
417 $successCount = $status->successCount
;
419 // Move files, if there are any
420 $status->merge( $this->doPreCommitUpdates() );
421 if ( !$status->isOK() ) {
422 // Fatal error, such as no configured archive directory
428 $this->updateLog( array(
429 'title' => $this->title
,
430 'count' => $successCount,
431 'newBits' => $newBits,
432 'oldBits' => $oldBits,
433 'comment' => $comment,
435 'authorIds' => $authorIds,
436 'authorIPs' => $authorIPs
441 $status->merge( $this->doPostCommitUpdates() );
446 * Reload the list data from the master DB. This can be done after setVisibility()
447 * to allow $item->getHTML() to show the new data.
449 function reloadFromMaster() {
450 $dbw = wfGetDB( DB_MASTER
);
451 $this->res
= $this->doQuery( $dbw );
455 * Record a log entry on the action
456 * @param $params Associative array of parameters:
457 * newBits: The new value of the *_deleted bitfield
458 * oldBits: The old value of the *_deleted bitfield.
459 * title: The target title
461 * comment: The log comment
462 * authorsIds: The array of the user IDs of the offenders
463 * authorsIPs: The array of the IP/anon user offenders
465 protected function updateLog( $params ) {
466 // Get the URL param's corresponding DB field
467 $field = RevisionDeleter
::getRelationType( $this->getType() );
469 throw new MWException( "Bad log URL param type!" );
471 // Put things hidden from sysops in the oversight log
472 if ( ( $params['newBits'] |
$params['oldBits'] ) & $this->getSuppressBit() ) {
473 $logType = 'suppress';
477 // Add params for effected page and ids
478 $logParams = $this->getLogParams( $params );
479 // Actually add the deletion log entry
480 $log = new LogPage( $logType );
481 $logid = $log->addEntry( $this->getLogAction(), $params['title'],
482 $params['comment'], $logParams );
483 // Allow for easy searching of deletion log items for revision/log items
484 $log->addRelations( $field, $params['ids'], $logid );
485 $log->addRelations( 'target_author_id', $params['authorIds'], $logid );
486 $log->addRelations( 'target_author_ip', $params['authorIPs'], $logid );
490 * Get the log action for this list type
492 public function getLogAction() {
497 * Get log parameter array.
498 * @param $params Associative array of log parameters, same as updateLog()
501 public function getLogParams( $params ) {
504 implode( ',', $params['ids'] ),
505 "ofield={$params['oldBits']}",
506 "nfield={$params['newBits']}"
511 * Initialise the current iteration pointer
513 protected function initCurrent() {
514 $row = $this->res
->current();
516 $this->current
= $this->newItem( $row );
518 $this->current
= false;
523 * Start iteration. This must be called before current() or next().
524 * @return First list item
526 public function reset() {
528 $this->res
= $this->doQuery( wfGetDB( DB_SLAVE
) );
530 $this->res
->rewind();
532 $this->initCurrent();
533 return $this->current
;
537 * Get the current list item, or false if we are at the end
539 public function current() {
540 return $this->current
;
544 * Move the iteration pointer to the next list item, and return it.
546 public function next() {
548 $this->initCurrent();
549 return $this->current
;
553 * Get the number of items in the list.
555 public function length() {
559 return $this->res
->numRows();
564 * Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates()
567 public function clearFileOps() {
571 * A hook for setVisibility(): do batch updates pre-commit.
575 public function doPreCommitUpdates() {
576 return Status
::newGood();
580 * A hook for setVisibility(): do any necessary updates post-commit.
584 public function doPostCommitUpdates() {
585 return Status
::newGood();
589 * Create an item object from a DB result row
590 * @param $row stdclass
592 abstract public function newItem( $row );
595 * Do the DB query to iterate through the objects.
596 * @param $db Database object to use for the query
598 abstract public function doQuery( $db );
601 * Get the integer value of the flag used for suppression
603 abstract public function getSuppressBit();
607 * Abstract base class for deletable items
609 abstract class RevDel_Item
{
610 /** The parent SpecialPage */
613 /** The parent RevDel_List */
616 /** The DB result row */
620 * @param $list RevDel_List
621 * @param $row DB result row
623 public function __construct( $list, $row ) {
624 $this->special
= $list->special
;
630 * Get the ID, as it would appear in the ids URL parameter
632 public function getId() {
633 $field = $this->list->getIdField();
634 return $this->row
->$field;
638 * Get the date, formatted with $wgLang
640 public function formatDate() {
642 return $wgLang->date( $this->getTimestamp() );
646 * Get the time, formatted with $wgLang
648 public function formatTime() {
650 return $wgLang->time( $this->getTimestamp() );
654 * Get the timestamp in MW 14-char form
656 public function getTimestamp() {
657 $field = $this->list->getTimestampField();
658 return wfTimestamp( TS_MW
, $this->row
->$field );
662 * Get the author user ID
664 public function getAuthorId() {
665 $field = $this->list->getAuthorIdField();
666 return intval( $this->row
->$field );
670 * Get the author user name
672 public function getAuthorName() {
673 $field = $this->list->getAuthorNameField();
674 return strval( $this->row
->$field );
678 * Returns true if the item is "current", and the operation to set the given
679 * bits can't be executed for that reason
682 public function isHideCurrentOp( $newBits ) {
687 * Returns true if the current user can view the item
689 abstract public function canView();
692 * Returns true if the current user can view the item text/file
694 abstract public function canViewContent();
697 * Get the current deletion bitfield value
699 abstract public function getBits();
702 * Get the HTML of the list item. Should be include <li></li> tags.
703 * This is used to show the list in HTML form, by the special page.
705 abstract public function getHTML();
708 * Set the visibility of the item. This should do any necessary DB queries.
710 * The DB update query should have a condition which forces it to only update
711 * if the value in the DB matches the value fetched earlier with the SELECT.
712 * If the update fails because it did not match, the function should return
713 * false. This prevents concurrency problems.
715 * @return boolean success
717 abstract public function setBits( $newBits );
721 * List for revision table items
723 class RevDel_RevisionList
extends RevDel_List
{
725 var $type = 'revision';
726 var $idField = 'rev_id';
727 var $dateField = 'rev_timestamp';
728 var $authorIdField = 'rev_user';
729 var $authorNameField = 'rev_user_text';
731 public function doQuery( $db ) {
732 $ids = array_map( 'intval', $this->ids
);
733 return $db->select( array('revision','page'), '*',
735 'rev_page' => $this->title
->getArticleID(),
740 array( 'ORDER BY' => 'rev_id DESC' )
744 public function newItem( $row ) {
745 return new RevDel_RevisionItem( $this, $row );
748 public function getCurrent() {
749 if ( is_null( $this->currentRevId
) ) {
750 $dbw = wfGetDB( DB_MASTER
);
751 $this->currentRevId
= $dbw->selectField(
752 'page', 'page_latest', $this->title
->pageCond(), __METHOD__
);
754 return $this->currentRevId
;
757 public function getSuppressBit() {
758 return Revision
::DELETED_RESTRICTED
;
761 public function doPreCommitUpdates() {
762 $this->title
->invalidateCache();
763 return Status
::newGood();
766 public function doPostCommitUpdates() {
767 $this->title
->purgeSquid();
768 // Extensions that require referencing previous revisions may need this
769 wfRunHooks( 'ArticleRevisionVisibilitySet', array( &$this->title
) );
770 return Status
::newGood();
775 * Item class for a revision table row
777 class RevDel_RevisionItem
extends RevDel_Item
{
780 public function __construct( $list, $row ) {
781 parent
::__construct( $list, $row );
782 $this->revision
= new Revision( $row );
785 public function canView() {
786 return $this->revision
->userCan( Revision
::DELETED_RESTRICTED
);
789 public function canViewContent() {
790 return $this->revision
->userCan( Revision
::DELETED_TEXT
);
793 public function getBits() {
794 return $this->revision
->mDeleted
;
797 public function setBits( $bits ) {
798 $dbw = wfGetDB( DB_MASTER
);
799 // Update revision table
800 $dbw->update( 'revision',
801 array( 'rev_deleted' => $bits ),
803 'rev_id' => $this->revision
->getId(),
804 'rev_page' => $this->revision
->getPage(),
805 'rev_deleted' => $this->getBits()
809 if ( !$dbw->affectedRows() ) {
813 // Update recentchanges table
814 $dbw->update( 'recentchanges',
816 'rc_deleted' => $bits,
820 'rc_this_oldid' => $this->revision
->getId(), // condition
821 // non-unique timestamp index
822 'rc_timestamp' => $dbw->timestamp( $this->revision
->getTimestamp() ),
829 public function isDeleted() {
830 return $this->revision
->isDeleted( Revision
::DELETED_TEXT
);
833 public function isHideCurrentOp( $newBits ) {
834 return ( $newBits & Revision
::DELETED_TEXT
)
835 && $this->list->getCurrent() == $this->getId();
839 * Get the HTML link to the revision text.
840 * Overridden by RevDel_ArchiveItem.
842 protected function getRevisionLink() {
844 $date = $wgLang->timeanddate( $this->revision
->getTimestamp(), true );
845 if ( $this->isDeleted() && !$this->canViewContent() ) {
848 return $this->special
->skin
->link(
853 'oldid' => $this->revision
->getId(),
860 * Get the HTML link to the diff.
861 * Overridden by RevDel_ArchiveItem
863 protected function getDiffLink() {
864 if ( $this->isDeleted() && !$this->canViewContent() ) {
865 return wfMsgHtml('diff');
868 $this->special
->skin
->link(
873 'diff' => $this->revision
->getId(),
885 public function getHTML() {
886 $difflink = $this->getDiffLink();
887 $revlink = $this->getRevisionLink();
888 $userlink = $this->special
->skin
->revUserLink( $this->revision
);
889 $comment = $this->special
->skin
->revComment( $this->revision
);
890 if ( $this->isDeleted() ) {
891 $revlink = "<span class=\"history-deleted\">$revlink</span>";
893 return "<li>($difflink) $revlink $userlink $comment</li>";
898 * List for archive table items, i.e. revisions deleted via action=delete
900 class RevDel_ArchiveList
extends RevDel_RevisionList
{
901 var $type = 'archive';
902 var $idField = 'ar_timestamp';
903 var $dateField = 'ar_timestamp';
904 var $authorIdField = 'ar_user';
905 var $authorNameField = 'ar_user_text';
907 public function doQuery( $db ) {
908 $timestamps = array();
909 foreach ( $this->ids
as $id ) {
910 $timestamps[] = $db->timestamp( $id );
912 return $db->select( 'archive', '*',
914 'ar_namespace' => $this->title
->getNamespace(),
915 'ar_title' => $this->title
->getDBkey(),
916 'ar_timestamp' => $timestamps
919 array( 'ORDER BY' => 'ar_timestamp DESC' )
923 public function newItem( $row ) {
924 return new RevDel_ArchiveItem( $this, $row );
927 public function doPreCommitUpdates() {
928 return Status
::newGood();
931 public function doPostCommitUpdates() {
932 return Status
::newGood();
937 * Item class for a archive table row
939 class RevDel_ArchiveItem
extends RevDel_RevisionItem
{
940 public function __construct( $list, $row ) {
941 RevDel_Item
::__construct( $list, $row );
942 $this->revision
= Revision
::newFromArchiveRow( $row,
943 array( 'page' => $this->list->title
->getArticleId() ) );
946 public function getId() {
947 # Convert DB timestamp to MW timestamp
948 return $this->revision
->getTimestamp();
951 public function setBits( $bits ) {
952 $dbw = wfGetDB( DB_MASTER
);
953 $dbw->update( 'archive',
954 array( 'ar_deleted' => $bits ),
955 array( 'ar_namespace' => $this->list->title
->getNamespace(),
956 'ar_title' => $this->list->title
->getDBkey(),
957 // use timestamp for index
958 'ar_timestamp' => $this->row
->ar_timestamp
,
959 'ar_rev_id' => $this->row
->ar_rev_id
,
960 'ar_deleted' => $this->getBits()
963 return (bool)$dbw->affectedRows();
966 protected function getRevisionLink() {
968 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
969 $date = $wgLang->timeanddate( $this->revision
->getTimestamp(), true );
970 if ( $this->isDeleted() && !$this->canViewContent() ) {
973 return $this->special
->skin
->link( $undelete, $date, array(),
975 'target' => $this->list->title
->getPrefixedText(),
976 'timestamp' => $this->revision
->getTimestamp()
980 protected function getDiffLink() {
981 if ( $this->isDeleted() && !$this->canViewContent() ) {
982 return wfMsgHtml( 'diff' );
984 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
985 return $this->special
->skin
->link( $undelete, wfMsgHtml('diff'), array(),
987 'target' => $this->list->title
->getPrefixedText(),
989 'timestamp' => $this->revision
->getTimestamp()
995 * List for oldimage table items
997 class RevDel_FileList
extends RevDel_List
{
998 var $type = 'oldimage';
999 var $idField = 'oi_archive_name';
1000 var $dateField = 'oi_timestamp';
1001 var $authorIdField = 'oi_user';
1002 var $authorNameField = 'oi_user_text';
1003 var $storeBatch, $deleteBatch, $cleanupBatch;
1005 public function doQuery( $db ) {
1006 $archiveName = array();
1007 foreach( $this->ids
as $timestamp ) {
1008 $archiveNames[] = $timestamp . '!' . $this->title
->getDBkey();
1010 return $db->select( 'oldimage', '*',
1012 'oi_name' => $this->title
->getDBkey(),
1013 'oi_archive_name' => $archiveNames
1016 array( 'ORDER BY' => 'oi_timestamp DESC' )
1020 public function newItem( $row ) {
1021 return new RevDel_FileItem( $this, $row );
1024 public function clearFileOps() {
1025 $this->deleteBatch
= array();
1026 $this->storeBatch
= array();
1027 $this->cleanupBatch
= array();
1030 public function doPreCommitUpdates() {
1031 $status = Status
::newGood();
1032 $repo = RepoGroup
::singleton()->getLocalRepo();
1033 if ( $this->storeBatch
) {
1034 $status->merge( $repo->storeBatch( $this->storeBatch
, FileRepo
::OVERWRITE_SAME
) );
1036 if ( !$status->isOK() ) {
1039 if ( $this->deleteBatch
) {
1040 $status->merge( $repo->deleteBatch( $this->deleteBatch
) );
1042 if ( !$status->isOK() ) {
1043 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
1044 // modified (but destined for rollback) causes data loss
1047 if ( $this->cleanupBatch
) {
1048 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch
) );
1053 public function doPostCommitUpdates() {
1054 $file = wfLocalFile( $this->title
);
1055 $file->purgeCache();
1056 $file->purgeDescription();
1057 return Status
::newGood();
1060 public function getSuppressBit() {
1061 return File
::DELETED_RESTRICTED
;
1066 * Item class for an oldimage table row
1068 class RevDel_FileItem
extends RevDel_Item
{
1071 public function __construct( $list, $row ) {
1072 parent
::__construct( $list, $row );
1073 $this->file
= RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
1076 public function getId() {
1077 $parts = explode( '!', $this->row
->oi_archive_name
);
1081 public function canView() {
1082 return $this->file
->userCan( File
::DELETED_RESTRICTED
);
1085 public function canViewContent() {
1086 return $this->file
->userCan( File
::DELETED_FILE
);
1089 public function getBits() {
1090 return $this->file
->getVisibility();
1093 public function setBits( $bits ) {
1095 # FIXME: move to LocalFile.php
1096 if ( $this->isDeleted() ) {
1097 if ( $bits & File
::DELETED_FILE
) {
1101 $key = $this->file
->getStorageKey();
1102 $srcRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
1103 $this->list->storeBatch
[] = array(
1104 $this->file
->repo
->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
1106 $this->file
->getRel()
1108 $this->list->cleanupBatch
[] = $key;
1110 } elseif ( $bits & File
::DELETED_FILE
) {
1112 $key = $this->file
->getStorageKey();
1113 $dstRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
1114 $this->list->deleteBatch
[] = array( $this->file
->getRel(), $dstRel );
1117 # Do the database operations
1118 $dbw = wfGetDB( DB_MASTER
);
1119 $dbw->update( 'oldimage',
1120 array( 'oi_deleted' => $bits ),
1122 'oi_name' => $this->row
->oi_name
,
1123 'oi_timestamp' => $this->row
->oi_timestamp
,
1124 'oi_deleted' => $this->getBits()
1128 return (bool)$dbw->affectedRows();
1131 public function isDeleted() {
1132 return $this->file
->isDeleted( File
::DELETED_FILE
);
1136 * Get the link to the file.
1137 * Overridden by RevDel_ArchivedFileItem.
1139 protected function getLink() {
1140 global $wgLang, $wgUser;
1141 $date = $wgLang->timeanddate( $this->file
->getTimestamp(), true );
1142 if ( $this->isDeleted() ) {
1144 if ( !$this->canViewContent() ) {
1147 $link = $this->special
->skin
->link(
1148 $this->special
->getTitle(),
1151 'target' => $this->list->title
->getPrefixedText(),
1152 'file' => $this->file
->getArchiveName(),
1153 'token' => $wgUser->editToken( $this->file
->getArchiveName() )
1157 return '<span class="history-deleted">' . $link . '</span>';
1160 $url = $this->file
->getUrl();
1161 return Xml
::element( 'a', array( 'href' => $this->file
->getUrl() ), $date );
1165 * Generate a user tool link cluster if the current user is allowed to view it
1166 * @return string HTML
1168 protected function getUserTools() {
1169 if( $this->file
->userCan( Revision
::DELETED_USER
) ) {
1170 $link = $this->special
->skin
->userLink( $this->file
->user
, $this->file
->user_text
) .
1171 $this->special
->skin
->userToolLinks( $this->file
->user
, $this->file
->user_text
);
1173 $link = wfMsgHtml( 'rev-deleted-user' );
1175 if( $this->file
->isDeleted( Revision
::DELETED_USER
) ) {
1176 return '<span class="history-deleted">' . $link . '</span>';
1182 * Wrap and format the file's comment block, if the current
1183 * user is allowed to view it.
1185 * @return string HTML
1187 protected function getComment() {
1188 if( $this->file
->userCan( File
::DELETED_COMMENT
) ) {
1189 $block = $this->special
->skin
->commentBlock( $this->file
->description
);
1191 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
1193 if( $this->file
->isDeleted( File
::DELETED_COMMENT
) ) {
1194 return "<span class=\"history-deleted\">$block</span>";
1199 public function getHTML() {
1204 $wgLang->formatNum( $this->file
->getWidth() ),
1205 $wgLang->formatNum( $this->file
->getHeight() )
1208 wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $this->file
->getSize() ) ) .
1210 $pageLink = $this->getLink();
1212 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
1213 $data . ' ' . $this->getComment(). '</li>';
1218 * List for filearchive table items
1220 class RevDel_ArchivedFileList
extends RevDel_FileList
{
1221 var $type = 'filearchive';
1222 var $idField = 'fa_id';
1223 var $dateField = 'fa_timestamp';
1224 var $authorIdField = 'fa_user';
1225 var $authorNameField = 'fa_user_text';
1227 public function doQuery( $db ) {
1228 $ids = array_map( 'intval', $this->ids
);
1229 return $db->select( 'filearchive', '*',
1231 'fa_name' => $this->title
->getDBkey(),
1235 array( 'ORDER BY' => 'fa_id DESC' )
1239 public function newItem( $row ) {
1240 return new RevDel_ArchivedFileItem( $this, $row );
1245 * Item class for a filearchive table row
1247 class RevDel_ArchivedFileItem
extends RevDel_FileItem
{
1248 public function __construct( $list, $row ) {
1249 RevDel_Item
::__construct( $list, $row );
1250 $this->file
= ArchivedFile
::newFromRow( $row );
1253 public function getId() {
1254 return $this->row
->fa_id
;
1257 public function setBits( $bits ) {
1258 $dbw = wfGetDB( DB_MASTER
);
1259 $dbw->update( 'filearchive',
1260 array( 'fa_deleted' => $bits ),
1262 'fa_id' => $this->row
->fa_id
,
1263 'fa_deleted' => $this->getBits(),
1267 return (bool)$dbw->affectedRows();
1270 protected function getLink() {
1271 global $wgLang, $wgUser;
1272 $date = $wgLang->timeanddate( $this->file
->getTimestamp(), true );
1273 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
1274 $key = $this->file
->getKey();
1276 if( !$this->canViewContent() ) {
1279 $link = $this->special
->skin
->link( $undelete, $date, array(),
1281 'target' => $this->list->title
->getPrefixedText(),
1283 'token' => $wgUser->editToken( $key )
1287 if( $this->isDeleted() ) {
1288 $link = '<span class="history-deleted">' . $link . '</span>';
1295 * List for logging table items
1297 class RevDel_LogList
extends RevDel_List
{
1298 var $type = 'logging';
1299 var $idField = 'log_id';
1300 var $dateField = 'log_timestamp';
1301 var $authorIdField = 'log_user';
1302 var $authorNameField = 'log_user_text';
1304 public function doQuery( $db ) {
1305 global $wgMessageCache;
1306 $wgMessageCache->loadAllMessages();
1307 $ids = array_map( 'intval', $this->ids
);
1308 return $db->select( 'logging', '*',
1309 array( 'log_id' => $ids ),
1311 array( 'ORDER BY' => 'log_id DESC' )
1315 public function newItem( $row ) {
1316 return new RevDel_LogItem( $this, $row );
1319 public function getSuppressBit() {
1320 return Revision
::DELETED_RESTRICTED
;
1323 public function getLogAction() {
1327 public function getLogParams( $params ) {
1329 implode( ',', $params['ids'] ),
1330 "ofield={$params['oldBits']}",
1331 "nfield={$params['newBits']}"
1337 * Item class for a logging table row
1339 class RevDel_LogItem
extends RevDel_Item
{
1340 public function canView() {
1341 return LogEventsList
::userCan( $this->row
, Revision
::DELETED_RESTRICTED
);
1344 public function canViewContent() {
1345 return true; // none
1348 public function getBits() {
1349 return $this->row
->log_deleted
;
1352 public function setBits( $bits ) {
1353 $dbw = wfGetDB( DB_MASTER
);
1354 $dbw->update( 'recentchanges',
1356 'rc_deleted' => $bits,
1360 'rc_logid' => $this->row
->log_id
,
1361 'rc_timestamp' => $this->row
->log_timestamp
// index
1365 $dbw->update( 'logging',
1366 array( 'log_deleted' => $bits ),
1368 'log_id' => $this->row
->log_id
,
1369 'log_deleted' => $this->getBits()
1373 return (bool)$dbw->affectedRows();
1376 public function getHTML() {
1379 $date = htmlspecialchars( $wgLang->timeanddate( $this->row
->log_timestamp
) );
1380 $paramArray = LogPage
::extractParams( $this->row
->log_params
);
1381 $title = Title
::makeTitle( $this->row
->log_namespace
, $this->row
->log_title
);
1383 // Log link for this page
1384 $loglink = $this->special
->skin
->link(
1385 SpecialPage
::getTitleFor( 'Log' ),
1388 array( 'page' => $title->getPrefixedText() )
1391 if( !$this->canView() ) {
1392 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1394 $action = LogPage
::actionText( $this->row
->log_type
, $this->row
->log_action
, $title,
1395 $this->special
->skin
, $paramArray, true, true );
1396 if( $this->row
->log_deleted
& LogPage
::DELETED_ACTION
)
1397 $action = '<span class="history-deleted">' . $action . '</span>';
1400 $userLink = $this->special
->skin
->userLink( $this->row
->log_user
,
1401 User
::WhoIs( $this->row
->log_user
) );
1402 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_USER
) ) {
1403 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
1406 $comment = $wgLang->getDirMark() . $this->special
->skin
->commentBlock( $this->row
->log_comment
);
1407 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_COMMENT
) ) {
1408 $comment = '<span class="history-deleted">' . $comment . '</span>';
1410 return "<li>($loglink) $date $userLink $action $comment</li>";