cca3d2f633679974da51626b87eb2020a901ae7b
3 * Special page allowing users with the appropriate permissions to view
4 * and hide revisions. Log items can also be hidden.
10 class SpecialRevisionDelete
extends UnlistedSpecialPage
{
14 /** True if the submit button was clicked, and the form was posted */
20 /** Archive name, for reviewing deleted files */
23 /** Edit token for securing image views against XSS */
26 /** Title object for target parameter */
29 /** Deletion type, may be revision, archive, oldimage, filearchive, logging. */
32 /** Array of checkbox specs (message, name, deletion bits) */
35 /** Information about the current type */
38 /** The RevDel_List object, storing the list of items to be deleted/undeleted */
42 * Assorted information about each type, needed by the special page.
43 * TODO Move some of this to the list class
45 static $allowedTypes = array(
47 'check-label' => 'revdelete-hide-text',
48 'deletion-bits' => Revision
::DELETED_TEXT
,
49 'success' => 'revdelete-success',
50 'failure' => 'revdelete-failure',
51 'list-class' => 'RevDel_RevisionList',
54 'check-label' => 'revdelete-hide-text',
55 'deletion-bits' => Revision
::DELETED_TEXT
,
56 'success' => 'revdelete-success',
57 'failure' => 'revdelete-failure',
58 'list-class' => 'RevDel_ArchiveList',
61 'check-label' => 'revdelete-hide-image',
62 'deletion-bits' => File
::DELETED_FILE
,
63 'success' => 'revdelete-success',
64 'failure' => 'revdelete-failure',
65 'list-class' => 'RevDel_FileList',
67 'filearchive' => array(
68 'check-label' => 'revdelete-hide-image',
69 'deletion-bits' => File
::DELETED_FILE
,
70 'success' => 'revdelete-success',
71 'failure' => 'revdelete-failure',
72 'list-class' => 'RevDel_ArchivedFileList',
75 'check-label' => 'revdelete-hide-name',
76 'deletion-bits' => LogPage
::DELETED_ACTION
,
77 'success' => 'logdelete-success',
78 'failure' => 'logdelete-failure',
79 'list-class' => 'RevDel_LogList',
83 /** Type map to support old log entries */
84 static $deprecatedTypeMap = array(
85 'oldid' => 'revision',
86 'artimestamp' => 'archive',
87 'oldimage' => 'oldimage',
88 'fileid' => 'filearchive',
92 public function __construct() {
93 parent
::__construct( 'Revisiondelete', 'deletedhistory' );
96 public function execute( $par ) {
97 global $wgOut, $wgUser, $wgRequest;
98 if( !$wgUser->isAllowed( 'deletedhistory' ) ) {
99 $wgOut->permissionRequired( 'deletedhistory' );
101 } else if( wfReadOnly() ) {
102 $wgOut->readOnlyPage();
105 $this->mIsAllowed
= $wgUser->isAllowed('deleterevision'); // for changes
106 $this->skin
= $wgUser->getSkin();
108 $this->outputHeader();
109 $this->submitClicked
= $wgRequest->wasPosted() && $wgRequest->getBool( 'wpSubmit' );
110 # Handle our many different possible input types.
111 $ids = $wgRequest->getVal( 'ids' );
112 if ( !is_null( $ids ) ) {
113 # Allow CSV, for backwards compatibility, or a single ID for show/hide links
114 $this->ids
= explode( ',', $ids );
117 $this->ids
= array_keys( $wgRequest->getArray('ids',array()) );
119 // $this->ids = array_map( 'intval', $this->ids );
120 $this->ids
= array_unique( array_filter( $this->ids
) );
122 if ( $wgRequest->getVal( 'action' ) == 'historysubmit' ) {
123 # For show/hide form submission from history page
124 $this->targetObj
= $GLOBALS['wgTitle'];
125 $this->typeName
= 'revision';
127 $this->typeName
= $wgRequest->getVal( 'type' );
128 $this->targetObj
= Title
::newFromText( $wgRequest->getText( 'target' ) );
131 # For reviewing deleted files...
132 $this->archiveName
= $wgRequest->getVal( 'file' );
133 $this->token
= $wgRequest->getVal( 'token' );
134 if ( $this->archiveName
&& $this->targetObj
) {
135 $this->tryShowFile( $this->archiveName
);
139 if ( isset( self
::$deprecatedTypeMap[$this->typeName
] ) ) {
140 $this->typeName
= self
::$deprecatedTypeMap[$this->typeName
];
144 if( !isset( self
::$allowedTypes[$this->typeName
] ) ||
count( $this->ids
) == 0 ) {
145 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
148 $this->typeInfo
= self
::$allowedTypes[$this->typeName
];
150 # If we have revisions, get the title from the first one
151 # since they should all be from the same page. This allows
152 # for more flexibility with page moves...
153 if( $this->typeName
== 'revision' ) {
154 $rev = Revision
::newFromId( $this->ids
[0] );
155 $this->targetObj
= $rev ?
$rev->getTitle() : $this->targetObj
;
158 $this->otherReason
= $wgRequest->getVal( 'wpReason' );
159 # We need a target page!
160 if( is_null($this->targetObj
) ) {
161 $wgOut->addWikiMsg( 'undelete-header' );
164 # Give a link to the logs/hist for this page
165 $this->showConvenienceLinks();
167 # Initialise checkboxes
168 $this->checks
= array(
169 array( $this->typeInfo
['check-label'], 'wpHidePrimary', $this->typeInfo
['deletion-bits'] ),
170 array( 'revdelete-hide-comment', 'wpHideComment', Revision
::DELETED_COMMENT
),
171 array( 'revdelete-hide-user', 'wpHideUser', Revision
::DELETED_USER
)
173 if( $wgUser->isAllowed('suppressrevision') ) {
174 $this->checks
[] = array( 'revdelete-hide-restricted',
175 'wpHideRestricted', Revision
::DELETED_RESTRICTED
);
178 # Either submit or create our form
179 if( $this->mIsAllowed
&& $this->submitClicked
) {
180 $this->submit( $wgRequest );
185 $qc = $this->getLogQueryCond();
186 # Show relevant lines from the deletion log
187 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'delete' ) ) . "</h2>\n" );
188 LogEventsList
::showLogExtract( $wgOut, 'delete',
189 $this->targetObj
->getPrefixedText(), '', array( 'lim' => 25, 'conds' => $qc ) );
190 # Show relevant lines from the suppression log
191 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
192 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'suppress' ) ) . "</h2>\n" );
193 LogEventsList
::showLogExtract( $wgOut, 'suppress',
194 $this->targetObj
->getPrefixedText(), '', array( 'lim' => 25, 'conds' => $qc ) );
199 * Show some useful links in the subtitle
201 protected function showConvenienceLinks() {
202 global $wgOut, $wgUser, $wgLang;
203 # Give a link to the logs/hist for this page
204 if( $this->targetObj
) {
206 $links[] = $this->skin
->linkKnown(
207 SpecialPage
::getTitleFor( 'Log' ),
208 wfMsgHtml( 'viewpagelogs' ),
210 array( 'page' => $this->targetObj
->getPrefixedText() )
212 if ( $this->targetObj
->getNamespace() != NS_SPECIAL
) {
213 # Give a link to the page history
214 $links[] = $this->skin
->linkKnown(
216 wfMsgHtml( 'pagehist' ),
218 array( 'action' => 'history' )
220 # Link to deleted edits
221 if( $wgUser->isAllowed('undelete') ) {
222 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
223 $links[] = $this->skin
->linkKnown(
225 wfMsgHtml( 'deletedhist' ),
227 array( 'target' => $this->targetObj
->getPrefixedDBkey() )
231 # Logs themselves don't have histories or archived revisions
232 $wgOut->setSubtitle( '<p>' . $wgLang->pipeList( $links ) . '</p>' );
237 * Get the condition used for fetching log snippets
239 protected function getLogQueryCond() {
241 // Revision delete logs for these item
242 $conds['log_type'] = array('delete','suppress');
243 $conds['log_action'] = $this->getList()->getLogAction();
244 $conds['ls_field'] = RevisionDeleter
::getRelationType( $this->typeName
);
245 $conds['ls_value'] = $this->ids
;
250 * Show a deleted file version requested by the visitor.
251 * TODO Mostly copied from Special:Undelete. Refactor.
253 protected function tryShowFile( $archiveName ) {
254 global $wgOut, $wgRequest, $wgUser, $wgLang;
256 $repo = RepoGroup
::singleton()->getLocalRepo();
257 $oimage = $repo->newFromArchiveName( $this->targetObj
, $archiveName );
259 // Check if user is allowed to see this file
260 if ( !$oimage->exists() ) {
261 $wgOut->addWikiMsg( 'revdelete-no-file' );
264 if( !$oimage->userCan(File
::DELETED_FILE
) ) {
265 if( $oimage->isDeleted( File
::DELETED_RESTRICTED
) ) {
266 $wgOut->permissionRequired( 'suppressrevision' );
268 $wgOut->permissionRequired( 'deletedtext' );
272 if ( !$wgUser->matchEditToken( $this->token
, $archiveName ) ) {
273 $wgOut->addWikiMsg( 'revdelete-show-file-confirm',
274 $this->targetObj
->getText(),
275 $wgLang->date( $oimage->getTimestamp() ),
276 $wgLang->time( $oimage->getTimestamp() ) );
278 Xml
::openElement( 'form', array(
280 'action' => $this->getTitle()->getLocalUrl(
281 'target=' . urlencode( $oimage->getName() ) .
282 '&file=' . urlencode( $archiveName ) .
283 '&token=' . urlencode( $wgUser->editToken( $archiveName ) ) )
286 Xml
::submitButton( wfMsg( 'revdelete-show-file-submit' ) ) .
292 # We mustn't allow the output to be Squid cached, otherwise
293 # if an admin previews a deleted image, and it's cached, then
294 # a user without appropriate permissions can toddle off and
295 # nab the image, and Squid will serve it
296 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
297 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
298 $wgRequest->response()->header( 'Pragma: no-cache' );
300 # Stream the file to the client
302 require_once( "$IP/includes/StreamFile.php" );
303 $key = $oimage->getStorageKey();
304 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
305 wfStreamFile( $path );
309 * Get the list object for this request
311 protected function getList() {
312 if ( is_null( $this->list ) ) {
313 $class = $this->typeInfo
['list-class'];
314 $this->list = new $class( $this, $this->targetObj
, $this->ids
);
320 * Show a list of items that we will operate on, and show a form with checkboxes
321 * which will allow the user to choose new visibility settings.
323 protected function showForm() {
324 global $wgOut, $wgUser, $wgLang;
327 if ( $this->typeName
== 'logging' ) {
328 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->ids
) ) );
330 $wgOut->addWikiMsg( 'revdelete-selected',
331 $this->targetObj
->getPrefixedText(), count( $this->ids
) );
334 $wgOut->addHTML( "<ul>" );
336 $where = $revObjs = array();
340 $list = $this->getList();
341 for ( $list->reset(); $list->current(); $list->next() ) {
342 $item = $list->current();
343 if ( !$item->canView() ) {
344 if( !$this->submitClicked
) {
345 $wgOut->permissionRequired( 'suppressrevision' );
348 $UserAllowed = false;
351 $wgOut->addHTML( $item->getHTML() );
354 if( !$numRevisions ) {
355 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
359 $wgOut->addHTML( "</ul>" );
361 $this->addUsageText();
363 // Normal sysops can always see what they did, but can't always change it
364 if( !$UserAllowed ) return;
366 // Show form if the user can submit
367 if( $this->mIsAllowed
) {
368 $out = Xml
::openElement( 'form', array( 'method' => 'post',
369 'action' => $this->getTitle()->getLocalUrl( array( 'action' => 'submit' ) ),
370 'id' => 'mw-revdel-form-revisions' ) ) .
371 Xml
::fieldset( wfMsg( 'revdelete-legend' ) ) .
372 $this->buildCheckBoxes() .
373 Xml
::openElement( 'table' ) .
375 '<td class="mw-label">' .
376 Xml
::label( wfMsg( 'revdelete-log' ), 'wpRevDeleteReasonList' ) .
378 '<td class="mw-input">' .
379 Xml
::listDropDown( 'wpRevDeleteReasonList',
380 wfMsgForContent( 'revdelete-reason-dropdown' ),
381 wfMsgForContent( 'revdelete-reasonotherlist' ), '', 'wpReasonDropDown', 1
385 '<td class="mw-label">' .
386 Xml
::label( wfMsg( 'revdelete-otherreason' ), 'wpReason' ) .
388 '<td class="mw-input">' .
389 Xml
::input( 'wpReason', 60, $this->otherReason
, array( 'id' => 'wpReason' ) ) .
393 '<td class="mw-submit">' .
394 Xml
::submitButton( wfMsgExt('revdelete-submit','parsemag',$numRevisions),
395 array( 'name' => 'wpSubmit' ) ) .
398 Xml
::closeElement( 'table' ) .
399 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ) .
400 Xml
::hidden( 'target', $this->targetObj
->getPrefixedText() ) .
401 Xml
::hidden( 'type', $this->typeName
) .
402 Xml
::hidden( 'ids', implode( ',', $this->ids
) ) .
403 Xml
::closeElement( 'fieldset' ) . "\n";
407 if( $this->mIsAllowed
) {
408 $out .= Xml
::closeElement( 'form' ) . "\n";
409 // Show link to edit the dropdown reasons
410 if( $wgUser->isAllowed( 'editinterface' ) ) {
411 $title = Title
::makeTitle( NS_MEDIAWIKI
, 'revdelete-reason-dropdown' );
412 $link = $wgUser->getSkin()->link(
414 wfMsgHtml( 'revdelete-edit-reasonlist' ),
416 array( 'action' => 'edit' )
418 $out .= Xml
::tags( 'p', array( 'class' => 'mw-revdel-editreasons' ), $link ) . "\n";
421 $wgOut->addHTML( $out );
425 * Show some introductory text
426 * FIXME Wikimedia-specific policy text
428 protected function addUsageText() {
429 global $wgOut, $wgUser;
430 $wgOut->addWikiMsg( 'revdelete-text' );
431 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
432 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
434 if( $this->mIsAllowed
) {
435 $wgOut->addWikiMsg( 'revdelete-confirm' );
440 * @return String: HTML
442 protected function buildCheckBoxes() {
446 // If there is just one item, use checkboxes
447 $list = $this->getList();
448 if( $list->length() == 1 ) {
450 $bitfield = $list->current()->getBits(); // existing field
451 if( $this->submitClicked
) {
452 $bitfield = $this->extractBitfield( $this->extractBitParams($wgRequest), $bitfield );
454 foreach( $this->checks
as $item ) {
455 list( $message, $name, $field ) = $item;
456 $innerHTML = Xml
::checkLabel( wfMsg($message), $name, $name, $bitfield & $field );
457 if( $field == Revision
::DELETED_RESTRICTED
)
458 $innerHTML = "<b>$innerHTML</b>";
459 $line = Xml
::tags( 'td', array( 'class' => 'mw-input' ), $innerHTML );
460 $html .= "<tr>$line</tr>\n";
462 // Otherwise, use tri-state radios
465 $html .= '<th class="mw-revdel-checkbox">'.wfMsgHtml('revdelete-radio-same').'</th>';
466 $html .= '<th class="mw-revdel-checkbox">'.wfMsgHtml('revdelete-radio-unset').'</th>';
467 $html .= '<th class="mw-revdel-checkbox">'.wfMsgHtml('revdelete-radio-set').'</th>';
468 $html .= "<th></th></tr>\n";
469 foreach( $this->checks
as $item ) {
470 list( $message, $name, $field ) = $item;
471 // If there are several items, use third state by default...
472 if( $this->submitClicked
) {
473 $selected = $wgRequest->getInt( $name, 0 /* unchecked */ );
475 $selected = -1; // use existing field
477 $line = '<td class="mw-revdel-checkbox">' . Xml
::radio( $name, -1, $selected == -1 ) . '</td>';
478 $line .= '<td class="mw-revdel-checkbox">' . Xml
::radio( $name, 0, $selected == 0 ) . '</td>';
479 $line .= '<td class="mw-revdel-checkbox">' . Xml
::radio( $name, 1, $selected == 1 ) . '</td>';
480 $label = wfMsgHtml($message);
481 if( $field == Revision
::DELETED_RESTRICTED
) {
482 $label = "<b>$label</b>";
484 $line .= "<td>$label</td>";
485 $html .= "<tr>$line</tr>\n";
494 * UI entry point for form submission.
495 * @param $request WebRequest
497 protected function submit( $request ) {
498 global $wgUser, $wgOut;
499 # Check edit token on submission
500 if( $this->submitClicked
&& !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
501 $wgOut->addWikiMsg( 'sessionfailure' );
504 $bitParams = $this->extractBitParams( $request );
505 $listReason = $request->getText( 'wpRevDeleteReasonList', 'other' ); // from dropdown
506 $comment = $listReason;
507 if( $comment != 'other' && $this->otherReason
!= '' ) {
508 // Entry from drop down menu + additional comment
509 $comment .= wfMsgForContent( 'colon-separator' ) . $this->otherReason
;
510 } elseif( $comment == 'other' ) {
511 $comment = $this->otherReason
;
513 # Can the user set this field?
514 if( $bitParams[Revision
::DELETED_RESTRICTED
]==1 && !$wgUser->isAllowed('suppressrevision') ) {
515 $wgOut->permissionRequired( 'suppressrevision' );
518 # If the save went through, go to success message...
519 $status = $this->save( $bitParams, $comment, $this->targetObj
);
520 if ( $status->isGood() ) {
523 # ...otherwise, bounce back to form...
525 $this->failure( $status );
531 * Report that the submit operation succeeded
533 protected function success() {
535 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
536 $wgOut->wrapWikiMsg( '<span class="success">$1</span>', $this->typeInfo
['success'] );
537 $this->list->reloadFromMaster();
542 * Report that the submit operation failed
544 protected function failure( $status ) {
546 $wgOut->setPagetitle( wfMsg( 'actionfailed' ) );
547 $wgOut->addWikiText( $status->getWikiText( $this->typeInfo
['failure'] ) );
552 * Put together an array that contains -1, 0, or the *_deleted const for each bit
553 * @param $request WebRequest
556 protected function extractBitParams( $request ) {
558 foreach( $this->checks
as $item ) {
559 list( /* message */ , $name, $field ) = $item;
560 $val = $request->getInt( $name, 0 /* unchecked */ );
561 if( $val < -1 ||
$val > 1) {
562 $val = -1; // -1 for existing value
564 $bitfield[$field] = $val;
566 if( !isset($bitfield[Revision
::DELETED_RESTRICTED
]) ) {
567 $bitfield[Revision
::DELETED_RESTRICTED
] = 0;
573 * Put together a rev_deleted bitfield
574 * @param $bitPars array extractBitParams() params
575 * @param $oldfield int current bitfield
578 public static function extractBitfield( $bitPars, $oldfield ) {
579 // Build the actual new rev_deleted bitfield
581 foreach( $bitPars as $const => $val ) {
583 $newBits |
= $const; // $const is the *_deleted const
584 } else if( $val == -1 ) {
585 $newBits |
= ($oldfield & $const); // use existing
592 * Do the write operations. Simple wrapper for RevDel_*List::setVisibility().
594 protected function save( $bitfield, $reason, $title ) {
595 return $this->getList()->setVisibility(
596 array( 'value' => $bitfield, 'comment' => $reason )
602 * Temporary b/c interface, collection of static functions.
603 * @ingroup SpecialPage
605 class RevisionDeleter
{
607 * Checks for a change in the bitfield for a certain option and updates the
608 * provided array accordingly.
610 * @param $desc String: description to add to the array if the option was
611 * enabled / disabled.
612 * @param $field Integer: the bitmask describing the single option.
613 * @param $diff Integer: the xor of the old and new bitfields.
614 * @param $new Integer: the new bitfield
615 * @param $arr Array: the array to update.
617 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
618 if( $diff & $field ) {
619 $arr[ ( $new & $field ) ?
0 : 1 ][] = $desc;
624 * Gets an array of message keys describing the changes made to the visibility
625 * of the revision. If the resulting array is $arr, then $arr[0] will contain an
626 * array of strings describing the items that were hidden, $arr[2] will contain
627 * an array of strings describing the items that were unhidden, and $arr[3] will
628 * contain an array with a single string, which can be one of "applied
629 * restrictions to sysops", "removed restrictions from sysops", or null.
631 * @param $n Integer: the new bitfield.
632 * @param $o Integer: the old bitfield.
633 * @return An array as described above.
635 protected static function getChanges( $n, $o ) {
637 $ret = array( 0 => array(), 1 => array(), 2 => array() );
638 // Build bitfield changes in language
639 self
::checkItem( 'revdelete-content',
640 Revision
::DELETED_TEXT
, $diff, $n, $ret );
641 self
::checkItem( 'revdelete-summary',
642 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
643 self
::checkItem( 'revdelete-uname',
644 Revision
::DELETED_USER
, $diff, $n, $ret );
645 // Restriction application to sysops
646 if( $diff & Revision
::DELETED_RESTRICTED
) {
647 if( $n & Revision
::DELETED_RESTRICTED
)
648 $ret[2][] = 'revdelete-restricted';
650 $ret[2][] = 'revdelete-unrestricted';
656 * Gets a log message to describe the given revision visibility change. This
657 * message will be of the form "[hid {content, edit summary, username}];
658 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
660 * @param $count Integer: The number of effected revisions.
661 * @param $nbitfield Integer: The new bitfield for the revision.
662 * @param $obitfield Integer: The old bitfield for the revision.
663 * @param $isForLog Boolean
664 * @param $forContent Boolean
666 public static function getLogMessage( $count, $nbitfield, $obitfield, $isForLog = false, $forContent = false ) {
667 global $wgLang, $wgContLang;
669 $lang = $forContent ?
$wgContLang : $wgLang;
670 $msgFunc = $forContent ?
"wfMsgForContent" : "wfMsg";
673 $changes = self
::getChanges( $nbitfield, $obitfield );
674 array_walk($changes, 'RevisionDeleter::expandMessageArray', $forContent);
676 $changesText = array();
678 if( count( $changes[0] ) ) {
679 $changesText[] = $msgFunc( 'revdelete-hid', $lang->commaList( $changes[0] ) );
681 if( count( $changes[1] ) ) {
682 $changesText[] = $msgFunc( 'revdelete-unhid', $lang->commaList( $changes[1] ) );
685 $s = $lang->semicolonList( $changesText );
686 if( count( $changes[2] ) ) {
687 $s .= $s ?
' (' . $changes[2][0] . ')' : ' ' . $changes[2][0];
690 $msg = $isForLog ?
'logdelete-log-message' : 'revdelete-log-message';
691 return wfMsgExt( $msg, $forContent ?
array( 'parsemag', 'content' ) : array( 'parsemag' ), $s, $lang->formatNum($count) );
694 private static function expandMessageArray(& $msg, $key, $forContent) {
695 if ( is_array ($msg) ) {
696 array_walk($msg, 'RevisionDeleter::expandMessageArray', $forContent);
699 $msg = wfMsgForContent($msg);
706 // Get DB field name for URL param...
707 // Future code for other things may also track
708 // other types of revision-specific changes.
709 // @returns string One of log_id/rev_id/fa_id/ar_timestamp/oi_archive_name
710 public static function getRelationType( $typeName ) {
711 if ( isset( SpecialRevisionDelete
::$deprecatedTypeMap[$typeName] ) ) {
712 $typeName = SpecialRevisionDelete
::$deprecatedTypeMap[$typeName];
714 if ( isset( SpecialRevisionDelete
::$allowedTypes[$typeName] ) ) {
715 $class = SpecialRevisionDelete
::$allowedTypes[$typeName]['list-class'];
716 $list = new $class( null, null, null );
717 return $list->getIdField();
723 // Checks if a revision still exists in the revision table.
724 // If it doesn't, returns the corresponding ar_timestamp field
725 // so that this key can be used instead.
726 public static function checkRevisionExistence( $title, $revid ) {
727 $dbr = wfGetDB( DB_SLAVE
);
728 $exists = $dbr->selectField( 'revision', '1',
729 array( 'rev_id' => $revid ), __METHOD__
);
735 $timestamp = $dbr->selectField( 'archive', 'ar_timestamp',
736 array( 'ar_namespace' => $title->getNamespace(),
737 'ar_title' => $title->getDBkey(),
738 'ar_rev_id' => $revid ), __METHOD__
);
743 // Creates utility links for log entries.
744 public static function getLogLinks( $title, $paramArray, $skin, $messages ) {
747 if( count($paramArray) >= 2 ) {
748 // Different revision types use different URL params...
749 $originalKey = $key = $paramArray[0];
750 // $paramArray[1] is a CSV of the IDs
751 $Ids = explode( ',', $paramArray[1] );
752 $query = $paramArray[1];
755 // For if undeleted revisions are found amidst deleted ones.
756 $undeletedRevisions = array();
758 // This is not going to work if some revs are deleted and some
760 if ($key == 'revision') {
761 foreach( $Ids as $k => $id ) {
763 self
::checkRevisionExistence( $title, $id );
765 if ($existResult !== true) {
767 $Ids[$k] = $existResult;
768 } elseif ($key != $originalKey) {
769 // Undeleted revision amidst deleted ones
771 $undeletedRevisions[] = $id;
776 // Diff link for single rev deletions
777 if( count($Ids) == 1 && !count($undeletedRevisions) ) {
778 // Live revision diffs...
779 if( in_array( $key, array( 'oldid', 'revision' ) ) ) {
780 $revert[] = $skin->link(
785 'diff' => intval( $Ids[0] ),
788 array( 'known', 'noclasses' )
790 // Deleted revision diffs...
791 } else if( in_array( $key, array( 'artimestamp','archive' ) ) ) {
792 $revert[] = $skin->link(
793 SpecialPage
::getTitleFor( 'Undelete' ),
797 'target' => $title->getPrefixedDBKey(),
799 'timestamp' => $Ids[0]
801 array( 'known', 'noclasses' )
806 // View/modify link...
807 if ( count($undeletedRevisions) ) {
808 // FIXME THIS IS A HORRIBLE HORRIBLE HACK AND SHOULD DIE
809 // It's not possible to pass a list of both deleted and
810 // undeleted revisions to SpecialRevisionDelete, so we're
811 // stuck with two links. See bug 23363.
812 $restoreLinks = array();
814 $restoreLinks[] = $skin->link(
815 SpecialPage
::getTitleFor( 'Revisiondelete' ),
816 $messages['revdel-restore-visible'],
819 'target' => $title->getPrefixedText(),
820 'type' => $originalKey,
821 'ids' => implode(',', $undeletedRevisions),
823 array( 'known', 'noclasses' )
826 $restoreLinks[] = $skin->link(
827 SpecialPage
::getTitleFor( 'Revisiondelete' ),
828 $messages['revdel-restore-deleted'],
831 'target' => $title->getPrefixedText(),
833 'ids' => implode(',', $Ids),
835 array( 'known', 'noclasses' )
838 $revert[] = $messages['revdel-restore'] . ' [' .
839 $wgLang->pipeList( $restoreLinks ) . ']';
841 $revert[] = $skin->link(
842 SpecialPage
::getTitleFor( 'Revisiondelete' ),
843 $messages['revdel-restore'],
846 'target' => $title->getPrefixedText(),
848 'ids' => implode(',', $Ids),
850 array( 'known', 'noclasses' )
855 $revert = wfMsg( 'parentheses', $wgLang->pipeList( $revert ) );
862 * Abstract base class for a list of deletable items
864 abstract class RevDel_List
{
865 var $special, $title, $ids, $res, $current;
866 var $type = null; // override this
867 var $idField = null; // override this
868 var $dateField = false; // override this
869 var $authorIdField = false; // override this
870 var $authorNameField = false; // override this
873 * @param $special The parent SpecialPage
874 * @param $title The target title
875 * @param $ids Array of IDs
877 public function __construct( $special, $title, $ids ) {
878 $this->special
= $special;
879 $this->title
= $title;
884 * Get the internal type name of this list. Equal to the table name.
886 public function getType() {
891 * Get the DB field name associated with the ID list
893 public function getIdField() {
894 return $this->idField
;
898 * Get the DB field name storing timestamps
900 public function getTimestampField() {
901 return $this->dateField
;
905 * Get the DB field name storing user ids
907 public function getAuthorIdField() {
908 return $this->authorIdField
;
912 * Get the DB field name storing user names
914 public function getAuthorNameField() {
915 return $this->authorNameField
;
918 * Set the visibility for the revisions in this list. Logging and
919 * transactions are done here.
921 * @param $params Associative array of parameters. Members are:
922 * value: The integer value to set the visibility to
923 * comment: The log comment.
926 public function setVisibility( $params ) {
927 $bitPars = $params['value'];
928 $comment = $params['comment'];
931 $dbw = wfGetDB( DB_MASTER
);
932 $this->doQuery( $dbw );
934 $status = Status
::newGood();
935 $missing = array_flip( $this->ids
);
936 $this->clearFileOps();
937 $idsForLog = array();
938 $authorIds = $authorIPs = array();
940 for ( $this->reset(); $this->current(); $this->next() ) {
941 $item = $this->current();
942 unset( $missing[ $item->getId() ] );
944 $oldBits = $item->getBits();
945 // Build the actual new rev_deleted bitfield
946 $newBits = SpecialRevisionDelete
::extractBitfield( $bitPars, $oldBits );
948 if ( $oldBits == $newBits ) {
949 $status->warning( 'revdelete-no-change', $item->formatDate(), $item->formatTime() );
950 $status->failCount++
;
952 } elseif ( $oldBits == 0 && $newBits != 0 ) {
954 } elseif ( $oldBits != 0 && $newBits == 0 ) {
960 if ( $item->isHideCurrentOp( $newBits ) ) {
961 // Cannot hide current version text
962 $status->error( 'revdelete-hide-current', $item->formatDate(), $item->formatTime() );
963 $status->failCount++
;
966 if ( !$item->canView() ) {
967 // Cannot access this revision
968 $msg = ($opType == 'show') ?
969 'revdelete-show-no-access' : 'revdelete-modify-no-access';
970 $status->error( $msg, $item->formatDate(), $item->formatTime() );
971 $status->failCount++
;
974 // Cannot just "hide from Sysops" without hiding any fields
975 if( $newBits == Revision
::DELETED_RESTRICTED
) {
976 $status->warning( 'revdelete-only-restricted', $item->formatDate(), $item->formatTime() );
977 $status->failCount++
;
981 // Update the revision
982 $ok = $item->setBits( $newBits );
985 $idsForLog[] = $item->getId();
986 $status->successCount++
;
987 if( $item->getAuthorId() > 0 ) {
988 $authorIds[] = $item->getAuthorId();
989 } else if( IP
::isIPAddress( $item->getAuthorName() ) ) {
990 $authorIPs[] = $item->getAuthorName();
993 $status->error( 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
994 $status->failCount++
;
998 // Handle missing revisions
999 foreach ( $missing as $id => $unused ) {
1000 $status->error( 'revdelete-modify-missing', $id );
1001 $status->failCount++
;
1004 if ( $status->successCount
== 0 ) {
1005 $status->ok
= false;
1010 // Save success count
1011 $successCount = $status->successCount
;
1013 // Move files, if there are any
1014 $status->merge( $this->doPreCommitUpdates() );
1015 if ( !$status->isOK() ) {
1016 // Fatal error, such as no configured archive directory
1022 $this->updateLog( array(
1023 'title' => $this->title
,
1024 'count' => $successCount,
1025 'newBits' => $newBits,
1026 'oldBits' => $oldBits,
1027 'comment' => $comment,
1028 'ids' => $idsForLog,
1029 'authorIds' => $authorIds,
1030 'authorIPs' => $authorIPs
1035 $status->merge( $this->doPostCommitUpdates() );
1040 * Reload the list data from the master DB. This can be done after setVisibility()
1041 * to allow $item->getHTML() to show the new data.
1043 function reloadFromMaster() {
1044 $dbw = wfGetDB( DB_MASTER
);
1045 $this->res
= $this->doQuery( $dbw );
1049 * Record a log entry on the action
1050 * @param $params Associative array of parameters:
1051 * newBits: The new value of the *_deleted bitfield
1052 * oldBits: The old value of the *_deleted bitfield.
1053 * title: The target title
1055 * comment: The log comment
1056 * authorsIds: The array of the user IDs of the offenders
1057 * authorsIPs: The array of the IP/anon user offenders
1059 protected function updateLog( $params ) {
1060 // Get the URL param's corresponding DB field
1061 $field = RevisionDeleter
::getRelationType( $this->getType() );
1063 throw new MWException( "Bad log URL param type!" );
1065 // Put things hidden from sysops in the oversight log
1066 if ( ( $params['newBits'] |
$params['oldBits'] ) & $this->getSuppressBit() ) {
1067 $logType = 'suppress';
1069 $logType = 'delete';
1071 // Add params for effected page and ids
1072 $logParams = $this->getLogParams( $params );
1073 // Actually add the deletion log entry
1074 $log = new LogPage( $logType );
1075 $logid = $log->addEntry( $this->getLogAction(), $params['title'],
1076 $params['comment'], $logParams );
1077 // Allow for easy searching of deletion log items for revision/log items
1078 $log->addRelations( $field, $params['ids'], $logid );
1079 $log->addRelations( 'target_author_id', $params['authorIds'], $logid );
1080 $log->addRelations( 'target_author_ip', $params['authorIPs'], $logid );
1084 * Get the log action for this list type
1086 public function getLogAction() {
1091 * Get log parameter array.
1092 * @param $params Associative array of log parameters, same as updateLog()
1095 public function getLogParams( $params ) {
1098 implode( ',', $params['ids'] ),
1099 "ofield={$params['oldBits']}",
1100 "nfield={$params['newBits']}"
1105 * Initialise the current iteration pointer
1107 protected function initCurrent() {
1108 $row = $this->res
->current();
1110 $this->current
= $this->newItem( $row );
1112 $this->current
= false;
1117 * Start iteration. This must be called before current() or next().
1118 * @return First list item
1120 public function reset() {
1121 if ( !$this->res
) {
1122 $this->res
= $this->doQuery( wfGetDB( DB_SLAVE
) );
1124 $this->res
->rewind();
1126 $this->initCurrent();
1127 return $this->current
;
1131 * Get the current list item, or false if we are at the end
1133 public function current() {
1134 return $this->current
;
1138 * Move the iteration pointer to the next list item, and return it.
1140 public function next() {
1142 $this->initCurrent();
1143 return $this->current
;
1147 * Get the number of items in the list.
1149 public function length() {
1153 return $this->res
->numRows();
1158 * Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates()
1161 public function clearFileOps() {
1165 * A hook for setVisibility(): do batch updates pre-commit.
1169 public function doPreCommitUpdates() {
1170 return Status
::newGood();
1174 * A hook for setVisibility(): do any necessary updates post-commit.
1178 public function doPostCommitUpdates() {
1179 return Status
::newGood();
1183 * Create an item object from a DB result row
1184 * @param $row stdclass
1186 abstract public function newItem( $row );
1189 * Do the DB query to iterate through the objects.
1190 * @param $db Database object to use for the query
1192 abstract public function doQuery( $db );
1195 * Get the integer value of the flag used for suppression
1197 abstract public function getSuppressBit();
1201 * Abstract base class for deletable items
1203 abstract class RevDel_Item
{
1204 /** The parent SpecialPage */
1207 /** The parent RevDel_List */
1210 /** The DB result row */
1214 * @param $list RevDel_List
1215 * @param $row DB result row
1217 public function __construct( $list, $row ) {
1218 $this->special
= $list->special
;
1219 $this->list = $list;
1224 * Get the ID, as it would appear in the ids URL parameter
1226 public function getId() {
1227 $field = $this->list->getIdField();
1228 return $this->row
->$field;
1232 * Get the date, formatted with $wgLang
1234 public function formatDate() {
1236 return $wgLang->date( $this->getTimestamp() );
1240 * Get the time, formatted with $wgLang
1242 public function formatTime() {
1244 return $wgLang->time( $this->getTimestamp() );
1248 * Get the timestamp in MW 14-char form
1250 public function getTimestamp() {
1251 $field = $this->list->getTimestampField();
1252 return wfTimestamp( TS_MW
, $this->row
->$field );
1256 * Get the author user ID
1258 public function getAuthorId() {
1259 $field = $this->list->getAuthorIdField();
1260 return intval( $this->row
->$field );
1264 * Get the author user name
1266 public function getAuthorName() {
1267 $field = $this->list->getAuthorNameField();
1268 return strval( $this->row
->$field );
1272 * Returns true if the item is "current", and the operation to set the given
1273 * bits can't be executed for that reason
1276 public function isHideCurrentOp( $newBits ) {
1281 * Returns true if the current user can view the item
1283 abstract public function canView();
1286 * Returns true if the current user can view the item text/file
1288 abstract public function canViewContent();
1291 * Get the current deletion bitfield value
1293 abstract public function getBits();
1296 * Get the HTML of the list item. Should be include <li></li> tags.
1297 * This is used to show the list in HTML form, by the special page.
1299 abstract public function getHTML();
1302 * Set the visibility of the item. This should do any necessary DB queries.
1304 * The DB update query should have a condition which forces it to only update
1305 * if the value in the DB matches the value fetched earlier with the SELECT.
1306 * If the update fails because it did not match, the function should return
1307 * false. This prevents concurrency problems.
1309 * @return boolean success
1311 abstract public function setBits( $newBits );
1315 * List for revision table items
1317 class RevDel_RevisionList
extends RevDel_List
{
1319 var $type = 'revision';
1320 var $idField = 'rev_id';
1321 var $dateField = 'rev_timestamp';
1322 var $authorIdField = 'rev_user';
1323 var $authorNameField = 'rev_user_text';
1325 public function doQuery( $db ) {
1326 $ids = array_map( 'intval', $this->ids
);
1327 return $db->select( array('revision','page'), '*',
1329 'rev_page' => $this->title
->getArticleID(),
1331 'rev_page = page_id'
1334 array( 'ORDER BY' => 'rev_id DESC' )
1338 public function newItem( $row ) {
1339 return new RevDel_RevisionItem( $this, $row );
1342 public function getCurrent() {
1343 if ( is_null( $this->currentRevId
) ) {
1344 $dbw = wfGetDB( DB_MASTER
);
1345 $this->currentRevId
= $dbw->selectField(
1346 'page', 'page_latest', $this->title
->pageCond(), __METHOD__
);
1348 return $this->currentRevId
;
1351 public function getSuppressBit() {
1352 return Revision
::DELETED_RESTRICTED
;
1355 public function doPreCommitUpdates() {
1356 $this->title
->invalidateCache();
1357 return Status
::newGood();
1360 public function doPostCommitUpdates() {
1361 $this->title
->purgeSquid();
1362 // Extensions that require referencing previous revisions may need this
1363 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$this->title
) );
1364 return Status
::newGood();
1369 * Item class for a revision table row
1371 class RevDel_RevisionItem
extends RevDel_Item
{
1374 public function __construct( $list, $row ) {
1375 parent
::__construct( $list, $row );
1376 $this->revision
= new Revision( $row );
1379 public function canView() {
1380 return $this->revision
->userCan( Revision
::DELETED_RESTRICTED
);
1383 public function canViewContent() {
1384 return $this->revision
->userCan( Revision
::DELETED_TEXT
);
1387 public function getBits() {
1388 return $this->revision
->mDeleted
;
1391 public function setBits( $bits ) {
1392 $dbw = wfGetDB( DB_MASTER
);
1393 // Update revision table
1394 $dbw->update( 'revision',
1395 array( 'rev_deleted' => $bits ),
1397 'rev_id' => $this->revision
->getId(),
1398 'rev_page' => $this->revision
->getPage(),
1399 'rev_deleted' => $this->getBits()
1403 if ( !$dbw->affectedRows() ) {
1407 // Update recentchanges table
1408 $dbw->update( 'recentchanges',
1410 'rc_deleted' => $bits,
1414 'rc_this_oldid' => $this->revision
->getId(), // condition
1415 // non-unique timestamp index
1416 'rc_timestamp' => $dbw->timestamp( $this->revision
->getTimestamp() ),
1423 public function isDeleted() {
1424 return $this->revision
->isDeleted( Revision
::DELETED_TEXT
);
1427 public function isHideCurrentOp( $newBits ) {
1428 return ( $newBits & Revision
::DELETED_TEXT
)
1429 && $this->list->getCurrent() == $this->getId();
1433 * Get the HTML link to the revision text.
1434 * Overridden by RevDel_ArchiveItem.
1436 protected function getRevisionLink() {
1438 $date = $wgLang->timeanddate( $this->revision
->getTimestamp(), true );
1439 if ( $this->isDeleted() && !$this->canViewContent() ) {
1442 return $this->special
->skin
->link(
1447 'oldid' => $this->revision
->getId(),
1454 * Get the HTML link to the diff.
1455 * Overridden by RevDel_ArchiveItem
1457 protected function getDiffLink() {
1458 if ( $this->isDeleted() && !$this->canViewContent() ) {
1459 return wfMsgHtml('diff');
1462 $this->special
->skin
->link(
1467 'diff' => $this->revision
->getId(),
1479 public function getHTML() {
1480 $difflink = $this->getDiffLink();
1481 $revlink = $this->getRevisionLink();
1482 $userlink = $this->special
->skin
->revUserLink( $this->revision
);
1483 $comment = $this->special
->skin
->revComment( $this->revision
);
1484 if ( $this->isDeleted() ) {
1485 $revlink = "<span class=\"history-deleted\">$revlink</span>";
1487 return "<li>($difflink) $revlink $userlink $comment</li>";
1492 * List for archive table items, i.e. revisions deleted via action=delete
1494 class RevDel_ArchiveList
extends RevDel_RevisionList
{
1495 var $type = 'archive';
1496 var $idField = 'ar_timestamp';
1497 var $dateField = 'ar_timestamp';
1498 var $authorIdField = 'ar_user';
1499 var $authorNameField = 'ar_user_text';
1501 public function doQuery( $db ) {
1502 $timestamps = array();
1503 foreach ( $this->ids
as $id ) {
1504 $timestamps[] = $db->timestamp( $id );
1506 return $db->select( 'archive', '*',
1508 'ar_namespace' => $this->title
->getNamespace(),
1509 'ar_title' => $this->title
->getDBkey(),
1510 'ar_timestamp' => $timestamps
1513 array( 'ORDER BY' => 'ar_timestamp DESC' )
1517 public function newItem( $row ) {
1518 return new RevDel_ArchiveItem( $this, $row );
1521 public function doPreCommitUpdates() {
1522 return Status
::newGood();
1525 public function doPostCommitUpdates() {
1526 return Status
::newGood();
1531 * Item class for a archive table row
1533 class RevDel_ArchiveItem
extends RevDel_RevisionItem
{
1534 public function __construct( $list, $row ) {
1535 RevDel_Item
::__construct( $list, $row );
1536 $this->revision
= Revision
::newFromArchiveRow( $row,
1537 array( 'page' => $this->list->title
->getArticleId() ) );
1540 public function getId() {
1541 # Convert DB timestamp to MW timestamp
1542 return $this->revision
->getTimestamp();
1545 public function setBits( $bits ) {
1546 $dbw = wfGetDB( DB_MASTER
);
1547 $dbw->update( 'archive',
1548 array( 'ar_deleted' => $bits ),
1549 array( 'ar_namespace' => $this->list->title
->getNamespace(),
1550 'ar_title' => $this->list->title
->getDBkey(),
1551 // use timestamp for index
1552 'ar_timestamp' => $this->row
->ar_timestamp
,
1553 'ar_rev_id' => $this->row
->ar_rev_id
,
1554 'ar_deleted' => $this->getBits()
1557 return (bool)$dbw->affectedRows();
1560 protected function getRevisionLink() {
1562 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
1563 $date = $wgLang->timeanddate( $this->revision
->getTimestamp(), true );
1564 if ( $this->isDeleted() && !$this->canViewContent() ) {
1567 return $this->special
->skin
->link( $undelete, $date, array(),
1569 'target' => $this->list->title
->getPrefixedText(),
1570 'timestamp' => $this->revision
->getTimestamp()
1574 protected function getDiffLink() {
1575 if ( $this->isDeleted() && !$this->canViewContent() ) {
1576 return wfMsgHtml( 'diff' );
1578 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
1579 return $this->special
->skin
->link( $undelete, wfMsgHtml('diff'), array(),
1581 'target' => $this->list->title
->getPrefixedText(),
1583 'timestamp' => $this->revision
->getTimestamp()
1589 * List for oldimage table items
1591 class RevDel_FileList
extends RevDel_List
{
1592 var $type = 'oldimage';
1593 var $idField = 'oi_archive_name';
1594 var $dateField = 'oi_timestamp';
1595 var $authorIdField = 'oi_user';
1596 var $authorNameField = 'oi_user_text';
1597 var $storeBatch, $deleteBatch, $cleanupBatch;
1599 public function doQuery( $db ) {
1600 $archiveName = array();
1601 foreach( $this->ids
as $timestamp ) {
1602 $archiveNames[] = $timestamp . '!' . $this->title
->getDBkey();
1604 return $db->select( 'oldimage', '*',
1606 'oi_name' => $this->title
->getDBkey(),
1607 'oi_archive_name' => $archiveNames
1610 array( 'ORDER BY' => 'oi_timestamp DESC' )
1614 public function newItem( $row ) {
1615 return new RevDel_FileItem( $this, $row );
1618 public function clearFileOps() {
1619 $this->deleteBatch
= array();
1620 $this->storeBatch
= array();
1621 $this->cleanupBatch
= array();
1624 public function doPreCommitUpdates() {
1625 $status = Status
::newGood();
1626 $repo = RepoGroup
::singleton()->getLocalRepo();
1627 if ( $this->storeBatch
) {
1628 $status->merge( $repo->storeBatch( $this->storeBatch
, FileRepo
::OVERWRITE_SAME
) );
1630 if ( !$status->isOK() ) {
1633 if ( $this->deleteBatch
) {
1634 $status->merge( $repo->deleteBatch( $this->deleteBatch
) );
1636 if ( !$status->isOK() ) {
1637 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
1638 // modified (but destined for rollback) causes data loss
1641 if ( $this->cleanupBatch
) {
1642 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch
) );
1647 public function doPostCommitUpdates() {
1648 $file = wfLocalFile( $this->title
);
1649 $file->purgeCache();
1650 $file->purgeDescription();
1651 return Status
::newGood();
1654 public function getSuppressBit() {
1655 return File
::DELETED_RESTRICTED
;
1660 * Item class for an oldimage table row
1662 class RevDel_FileItem
extends RevDel_Item
{
1665 public function __construct( $list, $row ) {
1666 parent
::__construct( $list, $row );
1667 $this->file
= RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
1670 public function getId() {
1671 $parts = explode( '!', $this->row
->oi_archive_name
);
1675 public function canView() {
1676 return $this->file
->userCan( File
::DELETED_RESTRICTED
);
1679 public function canViewContent() {
1680 return $this->file
->userCan( File
::DELETED_FILE
);
1683 public function getBits() {
1684 return $this->file
->getVisibility();
1687 public function setBits( $bits ) {
1689 # FIXME: move to LocalFile.php
1690 if ( $this->isDeleted() ) {
1691 if ( $bits & File
::DELETED_FILE
) {
1695 $key = $this->file
->getStorageKey();
1696 $srcRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
1697 $this->list->storeBatch
[] = array(
1698 $this->file
->repo
->getVirtualUrl( 'deleted' ) . '/' . $srcRel,
1700 $this->file
->getRel()
1702 $this->list->cleanupBatch
[] = $key;
1704 } elseif ( $bits & File
::DELETED_FILE
) {
1706 $key = $this->file
->getStorageKey();
1707 $dstRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
1708 $this->list->deleteBatch
[] = array( $this->file
->getRel(), $dstRel );
1711 # Do the database operations
1712 $dbw = wfGetDB( DB_MASTER
);
1713 $dbw->update( 'oldimage',
1714 array( 'oi_deleted' => $bits ),
1716 'oi_name' => $this->row
->oi_name
,
1717 'oi_timestamp' => $this->row
->oi_timestamp
,
1718 'oi_deleted' => $this->getBits()
1722 return (bool)$dbw->affectedRows();
1725 public function isDeleted() {
1726 return $this->file
->isDeleted( File
::DELETED_FILE
);
1730 * Get the link to the file.
1731 * Overridden by RevDel_ArchivedFileItem.
1733 protected function getLink() {
1734 global $wgLang, $wgUser;
1735 $date = $wgLang->timeanddate( $this->file
->getTimestamp(), true );
1736 if ( $this->isDeleted() ) {
1738 if ( !$this->canViewContent() ) {
1741 $link = $this->special
->skin
->link(
1742 $this->special
->getTitle(),
1745 'target' => $this->list->title
->getPrefixedText(),
1746 'file' => $this->file
->getArchiveName(),
1747 'token' => $wgUser->editToken( $this->file
->getArchiveName() )
1751 return '<span class="history-deleted">' . $link . '</span>';
1754 $url = $this->file
->getUrl();
1755 return Xml
::element( 'a', array( 'href' => $this->file
->getUrl() ), $date );
1759 * Generate a user tool link cluster if the current user is allowed to view it
1760 * @return string HTML
1762 protected function getUserTools() {
1763 if( $this->file
->userCan( Revision
::DELETED_USER
) ) {
1764 $link = $this->special
->skin
->userLink( $this->file
->user
, $this->file
->user_text
) .
1765 $this->special
->skin
->userToolLinks( $this->file
->user
, $this->file
->user_text
);
1767 $link = wfMsgHtml( 'rev-deleted-user' );
1769 if( $this->file
->isDeleted( Revision
::DELETED_USER
) ) {
1770 return '<span class="history-deleted">' . $link . '</span>';
1776 * Wrap and format the file's comment block, if the current
1777 * user is allowed to view it.
1779 * @return string HTML
1781 protected function getComment() {
1782 if( $this->file
->userCan( File
::DELETED_COMMENT
) ) {
1783 $block = $this->special
->skin
->commentBlock( $this->file
->description
);
1785 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
1787 if( $this->file
->isDeleted( File
::DELETED_COMMENT
) ) {
1788 return "<span class=\"history-deleted\">$block</span>";
1793 public function getHTML() {
1798 $wgLang->formatNum( $this->file
->getWidth() ),
1799 $wgLang->formatNum( $this->file
->getHeight() )
1802 wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $this->file
->getSize() ) ) .
1804 $pageLink = $this->getLink();
1806 return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' .
1807 $data . ' ' . $this->getComment(). '</li>';
1812 * List for filearchive table items
1814 class RevDel_ArchivedFileList
extends RevDel_FileList
{
1815 var $type = 'filearchive';
1816 var $idField = 'fa_id';
1817 var $dateField = 'fa_timestamp';
1818 var $authorIdField = 'fa_user';
1819 var $authorNameField = 'fa_user_text';
1821 public function doQuery( $db ) {
1822 $ids = array_map( 'intval', $this->ids
);
1823 return $db->select( 'filearchive', '*',
1825 'fa_name' => $this->title
->getDBkey(),
1829 array( 'ORDER BY' => 'fa_id DESC' )
1833 public function newItem( $row ) {
1834 return new RevDel_ArchivedFileItem( $this, $row );
1839 * Item class for a filearchive table row
1841 class RevDel_ArchivedFileItem
extends RevDel_FileItem
{
1842 public function __construct( $list, $row ) {
1843 RevDel_Item
::__construct( $list, $row );
1844 $this->file
= ArchivedFile
::newFromRow( $row );
1847 public function getId() {
1848 return $this->row
->fa_id
;
1851 public function setBits( $bits ) {
1852 $dbw = wfGetDB( DB_MASTER
);
1853 $dbw->update( 'filearchive',
1854 array( 'fa_deleted' => $bits ),
1856 'fa_id' => $this->row
->fa_id
,
1857 'fa_deleted' => $this->getBits(),
1861 return (bool)$dbw->affectedRows();
1864 protected function getLink() {
1865 global $wgLang, $wgUser;
1866 $date = $wgLang->timeanddate( $this->file
->getTimestamp(), true );
1867 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
1868 $key = $this->file
->getKey();
1870 if( !$this->canViewContent() ) {
1873 $link = $this->special
->skin
->link( $undelete, $date, array(),
1875 'target' => $this->list->title
->getPrefixedText(),
1877 'token' => $wgUser->editToken( $key )
1881 if( $this->isDeleted() ) {
1882 $link = '<span class="history-deleted">' . $link . '</span>';
1889 * List for logging table items
1891 class RevDel_LogList
extends RevDel_List
{
1892 var $type = 'logging';
1893 var $idField = 'log_id';
1894 var $dateField = 'log_timestamp';
1895 var $authorIdField = 'log_user';
1896 var $authorNameField = 'log_user_text';
1898 public function doQuery( $db ) {
1899 global $wgMessageCache;
1900 $wgMessageCache->loadAllMessages();
1901 $ids = array_map( 'intval', $this->ids
);
1902 return $db->select( 'logging', '*',
1903 array( 'log_id' => $ids ),
1905 array( 'ORDER BY' => 'log_id DESC' )
1909 public function newItem( $row ) {
1910 return new RevDel_LogItem( $this, $row );
1913 public function getSuppressBit() {
1914 return Revision
::DELETED_RESTRICTED
;
1917 public function getLogAction() {
1921 public function getLogParams( $params ) {
1923 implode( ',', $params['ids'] ),
1924 "ofield={$params['oldBits']}",
1925 "nfield={$params['newBits']}"
1931 * Item class for a logging table row
1933 class RevDel_LogItem
extends RevDel_Item
{
1934 public function canView() {
1935 return LogEventsList
::userCan( $this->row
, Revision
::DELETED_RESTRICTED
);
1938 public function canViewContent() {
1939 return true; // none
1942 public function getBits() {
1943 return $this->row
->log_deleted
;
1946 public function setBits( $bits ) {
1947 $dbw = wfGetDB( DB_MASTER
);
1948 $dbw->update( 'recentchanges',
1950 'rc_deleted' => $bits,
1954 'rc_logid' => $this->row
->log_id
,
1955 'rc_timestamp' => $this->row
->log_timestamp
// index
1959 $dbw->update( 'logging',
1960 array( 'log_deleted' => $bits ),
1962 'log_id' => $this->row
->log_id
,
1963 'log_deleted' => $this->getBits()
1967 return (bool)$dbw->affectedRows();
1970 public function getHTML() {
1973 $date = htmlspecialchars( $wgLang->timeanddate( $this->row
->log_timestamp
) );
1974 $paramArray = LogPage
::extractParams( $this->row
->log_params
);
1975 $title = Title
::makeTitle( $this->row
->log_namespace
, $this->row
->log_title
);
1977 // Log link for this page
1978 $loglink = $this->special
->skin
->link(
1979 SpecialPage
::getTitleFor( 'Log' ),
1982 array( 'page' => $title->getPrefixedText() )
1985 if( !$this->canView() ) {
1986 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1988 $action = LogPage
::actionText( $this->row
->log_type
, $this->row
->log_action
, $title,
1989 $this->special
->skin
, $paramArray, true, true );
1990 if( $this->row
->log_deleted
& LogPage
::DELETED_ACTION
)
1991 $action = '<span class="history-deleted">' . $action . '</span>';
1994 $userLink = $this->special
->skin
->userLink( $this->row
->log_user
,
1995 User
::WhoIs( $this->row
->log_user
) );
1996 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_USER
) ) {
1997 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
2000 $comment = $wgLang->getDirMark() . $this->special
->skin
->commentBlock( $this->row
->log_comment
);
2001 if( LogEventsList
::isDeleted($this->row
,LogPage
::DELETED_COMMENT
) ) {
2002 $comment = '<span class="history-deleted">' . $comment . '</span>';
2004 return "<li>($loglink) $date $userLink $action $comment</li>";