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
{
12 public function __construct() {
13 parent
::__construct( 'Revisiondelete', 'deleterevision' );
14 $this->includable( false ); // paranoia
17 public function execute( $par ) {
18 global $wgOut, $wgUser, $wgRequest;
19 if( !$wgUser->isAllowed( 'deleterevision' ) ) {
20 return $wgOut->permissionRequired( 'deleterevision' );
21 } else if( wfReadOnly() ) {
22 return $wgOut->readOnlyPage();
24 $this->skin
=& $wgUser->getSkin();
26 $this->outputHeader();
27 $this->wasPosted
= $wgRequest->wasPosted();
29 $this->target
= $wgRequest->getText( 'target' );
30 # Handle our many different possible input types.
31 # Use CVS, since the cgi handling will break on arrays.
32 $this->oldids
= explode( ',', $wgRequest->getVal('oldid') );
33 $this->oldids
= array_unique( array_filter($this->oldids
) );
34 $this->artimestamps
= explode( ',', $wgRequest->getVal('artimestamp') );
35 $this->artimestamps
= array_unique( array_filter($this->artimestamps
) );
36 $this->logids
= explode( ',', $wgRequest->getVal('logid') );
37 $this->logids
= array_unique( array_filter($this->logids
) );
38 $this->oldimgs
= explode( ',', $wgRequest->getVal('oldimage') );
39 $this->oldimgs
= array_unique( array_filter($this->oldimgs
) );
40 $this->fileids
= explode( ',', $wgRequest->getVal('fileid') );
41 $this->fileids
= array_unique( array_filter($this->fileids
) );
42 # For reviewing deleted files...
43 $this->file
= $wgRequest->getVal( 'file' );
44 # Only one target set at a time please!
45 $types = (bool)$this->file +
(bool)$this->oldids +
(bool)$this->logids
46 +
(bool)$this->artimestamps +
(bool)$this->fileids +
(bool)$this->oldimgs
;
49 return $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
51 } else if( $types > 1 ) {
52 return $wgOut->showErrorPage( 'revdelete-toomanytargets-title', 'revdelete-toomanytargets-text' );
54 $this->page
= Title
::newFromUrl( $this->target
);
55 $this->contextPage
= Title
::newFromUrl( $wgRequest->getText( 'page' ) );
56 # If we have revisions, get the title from the first one
57 # since they should all be from the same page. This allows
58 # for more flexibility with page moves...
59 if( count($this->oldids
) > 0 ) {
60 $rev = Revision
::newFromId( $this->oldids
[0] );
61 $this->page
= $rev ?
$rev->getTitle() : $this->page
;
63 # We need a target page!
64 if( is_null($this->page
) ) {
65 return $wgOut->addWikiMsg( 'undelete-header' );
67 # For reviewing deleted files...show it now if allowed
69 return $this->tryShowFile( $this->file
);
71 # Logs must have a type given
72 if( $this->logids
&& !strpos($this->page
->getDBKey(),'/') ) {
73 return $wgOut->showErrorPage( 'revdelete-nologtype-title', 'revdelete-nologtype-text' );
75 # Give a link to the logs/hist for this page
76 $this->showConvenienceLinks();
77 # Lock the operation and the form context
78 $this->secureOperation();
79 # Either submit or create our form
80 if( $this->wasPosted
) {
81 $this->submit( $wgRequest );
82 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
84 } else if( $this->deleteKey
== 'fileid' ||
$this->deleteKey
== 'oldimage' ) {
86 } else if( $this->deleteKey
== 'logid' ) {
87 $this->showLogItems();
89 $qc = $this->getLogQueryCond();
90 # Show relevant lines from the deletion log
91 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'delete' ) ) . "</h2>\n" );
92 LogEventsList
::showLogExtract( $wgOut, 'delete', $this->page
->getPrefixedText(), '', 25, $qc );
93 # Show relevant lines from the suppression log
94 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
95 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'suppress' ) ) . "</h2>\n" );
96 LogEventsList
::showLogExtract( $wgOut, 'suppress', $this->page
->getPrefixedText(), '', 25, $qc );
100 private function showConvenienceLinks() {
101 global $wgOut, $wgUser;
102 # Give a link to the logs/hist for this page
103 if( !is_null($this->page
) && $this->page
->getNamespace() > -1 ) {
105 $logtitle = SpecialPage
::getTitleFor( 'Log' );
106 $links[] = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
107 wfArrayToCGI( array( 'page' => $this->page
->getPrefixedUrl() ) ) );
108 # Give a link to the page history
109 $links[] = $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml( 'pagehist' ),
110 wfArrayToCGI( array( 'action' => 'history' ) ) );
111 # Link to deleted edits
112 if( $wgUser->isAllowed('undelete') ) {
113 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
114 $links[] = $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
115 wfArrayToCGI( array( 'target' => $this->page
->getPrefixedDBkey() ) ) );
117 # Logs themselves don't have histories or archived revisions
118 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
122 private function getLogQueryCond() {
123 $logAction = 'revision';
124 switch( $this->deleteKey
) {
126 $ids = $this->oldids
;
129 $ids = $this->artimestamps
;
132 $ids = $this->oldimgs
;
135 $ids = $this->fileids
;
138 $ids = $this->logids
;
139 $logAction = 'event';
141 default: // bad type?
144 // Revision delete logs for these item
145 $conds = array( 'log_action' => $logAction );
146 $conds['ls_field'] = RevisionDeleter
::getRelationType( $this->deleteKey
);
147 $conds['ls_value'] = $ids;
148 $conds[] = 'log_id = ls_log_id';
152 private function secureOperation() {
154 $this->deleteKey
= '';
155 // At this point, we should only have one of these
156 if( $this->oldids
) {
157 $this->revisions
= $this->oldids
;
158 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
159 $this->deleteKey
= 'oldid';
160 } else if( $this->artimestamps
) {
161 $this->archrevs
= $this->artimestamps
;
162 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
163 $this->deleteKey
= 'artimestamp';
164 } else if( $this->oldimgs
) {
165 $this->ofiles
= $this->oldimgs
;
166 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
167 $this->deleteKey
= 'oldimage';
168 } else if( $this->fileids
) {
169 $this->afiles
= $this->fileids
;
170 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
171 $this->deleteKey
= 'fileid';
172 } else if( $this->logids
) {
173 $this->events
= $this->logids
;
174 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage
::DELETED_ACTION
);
175 $this->deleteKey
= 'logid';
177 // Our checkbox messages depends one what we are doing,
178 // e.g. we don't hide "text" for logs or images
179 $this->checks
= array(
181 array( 'revdelete-hide-comment', 'wpHideComment', Revision
::DELETED_COMMENT
),
182 array( 'revdelete-hide-user', 'wpHideUser', Revision
::DELETED_USER
)
184 if( $wgUser->isAllowed('suppressrevision') ) {
185 $this->checks
[] = array( 'revdelete-hide-restricted',
186 'wpHideRestricted', Revision
::DELETED_RESTRICTED
);
191 * Show a deleted file version requested by the visitor.
193 private function tryShowFile( $key ) {
194 global $wgOut, $wgRequest;
195 $oimage = RepoGroup
::singleton()->getLocalRepo()->newFromArchiveName( $this->page
, $key );
197 // Check if user is allowed to see this file
198 if( !$oimage->userCan(File
::DELETED_FILE
) ) {
199 $wgOut->permissionRequired( 'suppressrevision' );
202 # We mustn't allow the output to be Squid cached, otherwise
203 # if an admin previews a deleted image, and it's cached, then
204 # a user without appropriate permissions can toddle off and
205 # nab the image, and Squid will serve it
206 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
207 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
208 $wgRequest->response()->header( 'Pragma: no-cache' );
209 # Stream the file to the client
210 $store = FileStore
::get( 'deleted' );
211 $store->stream( $key );
216 * This lets a user set restrictions for live and archived revisions
218 private function showRevs() {
219 global $wgOut, $wgUser;
222 $count = ($this->deleteKey
== 'oldid') ?
223 count($this->revisions
) : count($this->archrevs
);
224 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(), $count );
227 $wgOut->addHTML( "<ul>" );
229 $where = $revObjs = array();
230 $dbr = wfGetDB( DB_MASTER
);
234 if( $this->deleteKey
== 'oldid' ) {
235 // Run through and pull all our data in one query
236 foreach( $this->revisions
as $revid ) {
237 $where[] = intval($revid);
239 $result = $dbr->select( array('revision','page'), '*',
241 'rev_page' => $this->page
->getArticleID(),
247 while( $row = $dbr->fetchObject( $result ) ) {
248 $revObjs[$row->rev_id
] = new Revision( $row );
250 foreach( $this->revisions
as $revid ) {
251 if( !isset($revObjs[$revid]) ) continue; // Must exist
252 // Check if the revision was Oversighted
253 if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
254 if( !$this->wasPosted
) {
255 return $wgOut->permissionRequired( 'suppressrevision' );
257 $UserAllowed = false;
260 $wgOut->addHTML( $this->historyLine( $revObjs[$revid] ) );
261 $bitfields |
= $revObjs[$revid]->mDeleted
;
265 // Run through and pull all our data in one query
266 foreach( $this->archrevs
as $timestamp ) {
267 $where[] = $dbr->timestamp( $timestamp );
269 $result = $dbr->select( 'archive', '*',
271 'ar_namespace' => $this->page
->getNamespace(),
272 'ar_title' => $this->page
->getDBKey(),
273 'ar_timestamp' => $where
277 while( $row = $dbr->fetchObject( $result ) ) {
278 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
279 $revObjs[$timestamp] = new Revision( array(
280 'page' => $this->page
->getArticleId(),
281 'id' => $row->ar_rev_id
,
282 'text' => $row->ar_text_id
,
283 'comment' => $row->ar_comment
,
284 'user' => $row->ar_user
,
285 'user_text' => $row->ar_user_text
,
286 'timestamp' => $timestamp,
287 'minor_edit' => $row->ar_minor_edit
,
288 'text_id' => $row->ar_text_id
,
289 'deleted' => $row->ar_deleted
,
290 'len' => $row->ar_len
) );
292 foreach( $this->archrevs
as $timestamp ) {
293 if( !isset($revObjs[$timestamp]) ) {
295 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
296 // If a rev is hidden from sysops
297 if( !$this->wasPosted
) {
298 return $wgOut->permissionRequired( 'suppressrevision' );
300 $UserAllowed = false;
303 $wgOut->addHTML( $this->historyLine( $revObjs[$timestamp] ) );
304 $bitfields |
= $revObjs[$timestamp]->mDeleted
;
308 return $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
311 $wgOut->addHTML( "</ul>" );
313 $this->addUsageText();
315 // Normal sysops can always see what they did, but can't always change it
316 if( !$UserAllowed ) return;
319 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
320 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
323 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
324 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
325 Xml
::hidden( 'type', $this->deleteKey
)
327 if( $this->deleteKey
== 'oldid' ) {
328 $hidden[] = Xml
::hidden( 'oldid', implode(',',$this->oldids
) );
330 $hidden[] = Xml
::hidden( 'artimestamp', implode(',',$this->artimestamps
) );
333 Xml
::openElement( 'form', array( 'method' => 'post',
334 'action' => $this->getTitle()->getLocalUrl( 'action=submit' ),
335 'id' => 'mw-revdel-form-revisions' ) ) .
336 Xml
::openElement( 'fieldset' ) .
337 xml
::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
340 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
341 foreach( $items as $item ) {
342 $wgOut->addHTML( Xml
::tags( 'p', null, $item ) );
344 foreach( $hidden as $item ) {
345 $wgOut->addHTML( $item );
348 Xml
::closeElement( 'fieldset' ) .
349 Xml
::closeElement( 'form' ) . "\n"
354 * This lets a user set restrictions for archived images
356 private function showImages() {
357 global $wgOut, $wgUser, $wgLang;
360 $count = ($this->deleteKey
== 'oldimage') ?
count($this->ofiles
) : count($this->afiles
);
361 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(),
362 $wgLang->formatNum($count) );
365 $wgOut->addHTML( "<ul>" );
367 $where = $filesObjs = array();
368 $dbr = wfGetDB( DB_MASTER
);
369 // Live old revisions...
371 if( $this->deleteKey
== 'oldimage' ) {
372 // Run through and pull all our data in one query
373 foreach( $this->ofiles
as $timestamp ) {
374 $where[] = $timestamp.'!'.$this->page
->getDBKey();
376 $result = $dbr->select( 'oldimage', '*',
378 'oi_name' => $this->page
->getDBKey(),
379 'oi_archive_name' => $where
383 while( $row = $dbr->fetchObject( $result ) ) {
384 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
385 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
386 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
388 // Check through our images
389 foreach( $this->ofiles
as $timestamp ) {
390 $archivename = $timestamp.'!'.$this->page
->getDBKey();
391 if( !isset($filesObjs[$archivename]) ) {
393 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
394 // If a rev is hidden from sysops
395 if( !$this->wasPosted
) {
396 return $wgOut->permissionRequired( 'suppressrevision' );
398 $UserAllowed = false;
401 // Inject history info
402 $wgOut->addHTML( $this->fileLine( $filesObjs[$archivename] ) );
403 $bitfields |
= $filesObjs[$archivename]->deleted
;
407 // Run through and pull all our data in one query
408 foreach( $this->afiles
as $id ) {
409 $where[] = intval($id);
411 $result = $dbr->select( 'filearchive', '*',
413 'fa_name' => $this->page
->getDBKey(),
418 while( $row = $dbr->fetchObject( $result ) ) {
419 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
422 foreach( $this->afiles
as $fileid ) {
423 if( !isset($filesObjs[$fileid]) ) {
425 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
426 // If a rev is hidden from sysops
427 if( !$this->wasPosted
) {
428 return $wgOut->permissionRequired( 'suppressrevision' );
430 $UserAllowed = false;
433 // Inject history info
434 $wgOut->addHTML( $this->archivedfileLine( $filesObjs[$fileid] ) );
435 $bitfields |
= $filesObjs[$fileid]->deleted
;
439 return $wgOut->showErrorPage( 'revdelete-nooldid-title','revdelete-nooldid-text' );
442 $wgOut->addHTML( "</ul>" );
444 $this->addUsageText();
445 // Normal sysops can always see what they did, but can't always change it
446 if( !$UserAllowed ) return;
449 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
450 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
453 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
454 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
455 Xml
::hidden( 'type', $this->deleteKey
)
457 if( $this->deleteKey
== 'oldimage' ) {
458 $hidden[] = Xml
::hidden( 'oldimage', implode(',',$this->oldimgs
) );
460 $hidden[] = Xml
::hidden( 'fileid', implode(',',$this->fileids
) );
463 Xml
::openElement( 'form', array( 'method' => 'post',
464 'action' => $this->getTitle()->getLocalUrl( 'action=submit' ),
465 'id' => 'mw-revdel-form-filerevisions' )
467 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
470 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
471 foreach( $items as $item ) {
472 $wgOut->addHTML( "<p>$item</p>" );
474 foreach( $hidden as $item ) {
475 $wgOut->addHTML( $item );
479 Xml
::closeElement( 'fieldset' ) .
480 Xml
::closeElement( 'form' ) . "\n"
485 * This lets a user set restrictions for log items
487 private function showLogItems() {
488 global $wgOut, $wgUser, $wgMessageCache, $wgLang;
491 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->events
) ) );
494 $wgOut->addHTML( "<ul>" );
496 $where = $logRows = array();
497 $dbr = wfGetDB( DB_MASTER
);
498 // Run through and pull all our data in one query
500 foreach( $this->events
as $logid ) {
501 $where[] = intval($logid);
503 list($log,$logtype) = explode( '/',$this->page
->getDBKey(), 2 );
504 $result = $dbr->select( 'logging', '*',
505 array( 'log_type' => $logtype, 'log_id' => $where ),
508 while( $row = $dbr->fetchObject( $result ) ) {
509 $logRows[$row->log_id
] = $row;
511 $wgMessageCache->loadAllMessages();
512 foreach( $this->events
as $logid ) {
513 // Don't hide from oversight log!!!
514 if( !isset( $logRows[$logid] ) ||
$logRows[$logid]->log_type
=='suppress' ) {
516 } else if( !LogEventsList
::userCan( $logRows[$logid],Revision
::DELETED_RESTRICTED
) ) {
517 // If an event is hidden from sysops
518 if( !$this->wasPosted
) {
519 return $wgOut->permissionRequired( 'suppressrevision' );
521 $UserAllowed = false;
524 $wgOut->addHTML( $this->logLine( $logRows[$logid] ) );
525 $bitfields |
= $logRows[$logid]->log_deleted
;
528 return $wgOut->showErrorPage( 'revdelete-nologid-title', 'revdelete-nologid-text' );
531 $wgOut->addHTML( "</ul>" );
533 $this->addUsageText();
534 // Normal sysops can always see what they did, but can't always change it
535 if( !$UserAllowed ) return;
538 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
539 Xml
::submitButton( wfMsg( 'revdelete-submit' ) ) );
541 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
542 Xml
::hidden( 'target', $this->page
->getPrefixedDBKey() ),
543 Xml
::hidden( 'page', $this->contextPage ?
$this->contextPage
->getPrefixedDBKey() : '' ),
544 Xml
::hidden( 'type', $this->deleteKey
),
545 Xml
::hidden( 'logid', implode(',',$this->logids
) )
549 Xml
::openElement( 'form', array( 'method' => 'post',
550 'action' => $this->getTitle()->getLocalUrl( 'action=submit' ), 'id' => 'mw-revdel-form-logs' ) ) .
551 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
554 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
555 foreach( $items as $item ) {
556 $wgOut->addHTML( "<p>$item</p>" );
558 foreach( $hidden as $item ) {
559 $wgOut->addHTML( $item );
563 Xml
::closeElement( 'fieldset' ) .
564 Xml
::closeElement( 'form' ) . "\n"
568 private function addUsageText() {
569 global $wgOut, $wgUser;
570 $wgOut->addWikiMsg( 'revdelete-text' );
571 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
572 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
577 * @param int $bitfields, aggregate bitfield of all the bitfields
578 * @returns string HTML
580 private function buildCheckBoxes( $bitfields ) {
582 // FIXME: all items checked for just one rev are checked, even if not set for the others
583 foreach( $this->checks
as $item ) {
584 list( $message, $name, $field ) = $item;
585 $line = Xml
::tags( 'div', null, Xml
::checkLabel( wfMsg($message), $name, $name,
586 $bitfields & $field ) );
587 if( $field == Revision
::DELETED_RESTRICTED
) $line = "<b>$line</b>";
594 * @param Revision $rev
597 private function historyLine( $rev ) {
598 global $wgLang, $wgUser;
600 $date = $wgLang->timeanddate( $rev->getTimestamp() );
601 $difflink = $del = '';
603 if( $this->deleteKey
== 'oldid' ) {
604 $tokenParams = '&unhide=1&token='.urlencode( $wgUser->editToken( $rev->getId() ) );
605 $revlink = $this->skin
->makeLinkObj( $this->page
, $date, 'oldid='.$rev->getId() . $tokenParams );
606 $difflink = '(' . $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml('diff'),
607 'diff=' . $rev->getId() . '&oldid=prev' . $tokenParams ) . ')';
608 // Archived revisions
610 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
611 $target = $this->page
->getPrefixedText();
612 $revlink = $this->skin
->makeLinkObj( $undelete, $date,
613 "target=$target×tamp=" . $rev->getTimestamp() );
614 $difflink = '(' . $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml('diff'),
615 "target=$target&diff=prev×tamp=" . $rev->getTimestamp() ) . ')';
617 // Check permissions; items may be "suppressed"
618 if( $rev->isDeleted(Revision
::DELETED_TEXT
) ) {
619 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
620 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
621 if( !$rev->userCan(Revision
::DELETED_TEXT
) ) {
622 $revlink = '<span class="history-deleted">'.$date.'</span>';
623 $difflink = '(' . wfMsgHtml('diff') . ')';
626 $userlink = $this->skin
->revUserLink( $rev );
627 $comment = $this->skin
->revComment( $rev );
629 return "<li>$difflink $revlink $userlink $comment{$del}</li>";
636 private function fileLine( $file ) {
639 $target = $this->page
->getPrefixedText();
640 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
644 if( $file->isDeleted(File
::DELETED_FILE
) ) {
645 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
646 if( !$file->userCan(File
::DELETED_FILE
) ) {
649 $pageLink = $this->skin
->makeKnownLinkObj( $this->getTitle(), $date,
650 "target=$target&file=$file->sha1.".$file->getExtension() );
652 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
655 $url = $file->getUrlRel();
656 $pageLink = "<a href=\"{$url}\">{$date}</a>";
659 $data = wfMsg( 'widthheight', $wgLang->formatNum( $file->getWidth() ),
660 $wgLang->formatNum( $file->getHeight() ) ) .
661 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
662 $data = htmlspecialchars( $data );
664 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".
665 $this->fileComment( $file )."$del</li>";
669 * @param ArchivedFile $file
672 private function archivedfileLine( $file ) {
675 $target = $this->page
->getPrefixedText();
676 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
678 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
679 $pageLink = $this->skin
->makeKnownLinkObj( $undelete, $date,
680 "target=$target&file={$file->getKey()}" );
683 if( $file->isDeleted(File
::DELETED_FILE
) ) {
684 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
687 $data = wfMsg( 'widthheight', $wgLang->formatNum( $file->getWidth() ),
688 $wgLang->formatNum( $file->getHeight() ) ) .
689 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
690 $data = htmlspecialchars( $data );
692 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".
693 $this->fileComment( $file )."$del</li>";
697 * @param Array $row row
700 private function logLine( $row ) {
703 $date = $wgLang->timeanddate( $row->log_timestamp
);
704 $paramArray = LogPage
::extractParams( $row->log_params
);
705 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
707 $logtitle = SpecialPage
::getTitleFor( 'Log' );
708 $loglink = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
709 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
711 if( !LogEventsList
::userCan($row,LogPage
::DELETED_ACTION
) ) {
712 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
714 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
715 $this->skin
, $paramArray, true, true );
716 if( $row->log_deleted
& LogPage
::DELETED_ACTION
)
717 $action = '<span class="history-deleted">' . $action . '</span>';
720 $userLink = $this->skin
->userLink( $row->log_user
, User
::WhoIs($row->log_user
) );
721 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_USER
) ) {
722 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
725 $comment = $wgLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
726 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
727 $comment = '<span class="history-deleted">' . $comment . '</span>';
729 return "<li>($loglink) $date $userLink $action $comment</li>";
733 * Generate a user tool link cluster if the current user is allowed to view it
734 * @param ArchivedFile $file
735 * @return string HTML
737 private function fileUserTools( $file ) {
738 if( $file->userCan( Revision
::DELETED_USER
) ) {
739 $link = $this->skin
->userLink( $file->user
, $file->user_text
) .
740 $this->skin
->userToolLinks( $file->user
, $file->user_text
);
742 $link = wfMsgHtml( 'rev-deleted-user' );
744 if( $file->isDeleted( Revision
::DELETED_USER
) ) {
745 return '<span class="history-deleted">' . $link . '</span>';
751 * Wrap and format the given file's comment block, if the current
752 * user is allowed to view it.
754 * @param ArchivedFile $file
755 * @return string HTML
757 private function fileComment( $file ) {
758 if( $file->userCan( File
::DELETED_COMMENT
) ) {
759 $block = $this->skin
->commentBlock( $file->description
);
761 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
763 if( $file->isDeleted( File
::DELETED_COMMENT
) ) {
764 return "<span class=\"history-deleted\">$block</span>";
770 * @param WebRequest $request
772 private function submit( $request ) {
773 global $wgUser, $wgOut;
774 # Check edit token on submission
775 if( $this->wasPosted
&& !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
776 $wgOut->addWikiMsg( 'sessionfailure' );
779 $bitfield = $this->extractBitfield( $request );
780 $comment = $request->getText( 'wpReason' );
781 # Can the user set this field?
782 if( $bitfield & Revision
::DELETED_RESTRICTED
&& !$wgUser->isAllowed('suppressrevision') ) {
783 $wgOut->permissionRequired( 'suppressrevision' );
786 # If the save went through, go to success message...
787 if( $this->save( $bitfield, $comment, $this->page
) ) {
790 # ...otherwise, bounce back to form...
797 private function success() {
799 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
800 $wrap = '<span class="success">$1</span>';
801 if( $this->deleteKey
== 'logid' ) {
802 $wgOut->wrapWikiMsg( $wrap, 'logdelete-success' );
803 $this->showLogItems();
804 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
805 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
807 } else if( $this->deleteKey
== 'fileid' ) {
808 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
810 } else if( $this->deleteKey
== 'oldimage' ) {
811 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
816 private function failure() {
818 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
819 $wrap = '<span class="error">$1</span>';
820 if( $this->deleteKey
== 'logid' ) {
821 $this->showLogItems();
822 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
823 $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
825 } else if( $this->deleteKey
== 'fileid' ) {
826 $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
828 } else if( $this->deleteKey
== 'oldimage' ) {
829 $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
835 * Put together a rev_deleted bitfield from the submitted checkboxes
836 * @param WebRequest $request
839 private function extractBitfield( $request ) {
841 foreach( $this->checks
as $item ) {
842 list( /* message */ , $name, $field ) = $item;
843 if( $request->getCheck( $name ) ) {
850 private function save( $bitfield, $reason, $title ) {
851 $dbw = wfGetDB( DB_MASTER
);
852 // Don't allow simply locking the interface for no reason
853 if( $bitfield == Revision
::DELETED_RESTRICTED
) {
856 $deleter = new RevisionDeleter( $dbw );
857 // By this point, only one of the below should be set
858 if( isset($this->revisions
) ) {
859 return $deleter->setRevVisibility( $title, $this->revisions
, $bitfield, $reason );
860 } else if( isset($this->archrevs
) ) {
861 return $deleter->setArchiveVisibility( $title, $this->archrevs
, $bitfield, $reason );
862 } else if( isset($this->ofiles
) ) {
863 return $deleter->setOldImgVisibility( $title, $this->ofiles
, $bitfield, $reason );
864 } else if( isset($this->afiles
) ) {
865 return $deleter->setArchFileVisibility( $title, $this->afiles
, $bitfield, $reason );
866 } else if( isset($this->events
) ) {
867 return $deleter->setEventVisibility( $title, $this->events
, $bitfield, $reason );
874 * Implements the actions for Revision Deletion.
875 * @ingroup SpecialPage
877 class RevisionDeleter
{
878 function __construct( $db ) {
883 * @param $title, the page these events apply to
884 * @param array $items list of revision ID numbers
885 * @param int $bitfield new rev_deleted value
886 * @param string $comment Comment for log records
888 function setRevVisibility( $title, $items, $bitfield, $comment ) {
891 $userAllowedAll = $success = true;
894 // Run through and pull all our data in one query
895 foreach( $items as $revid ) {
896 $where[] = intval($revid);
898 $result = $this->dbw
->select( array('revision','page'), '*',
899 array( 'rev_page' => $title->getArticleID(),
900 'rev_id' => $where, 'rev_page = page_id' ),
903 while( $row = $this->dbw
->fetchObject( $result ) ) {
904 $revObjs[$row->rev_id
] = new Revision( $row );
907 foreach( $items as $revid ) {
908 if( !isset($revObjs[$revid]) ) {
910 continue; // Must exist
911 } else if( $revObjs[$revid]->isCurrent() && ($bitfield & Revision
::DELETED_TEXT
) ) {
913 continue; // Cannot hide current version text
914 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
915 $userAllowedAll = false;
918 // For logging, maintain a count of revisions
919 if( $revObjs[$revid]->mDeleted
!= $bitfield ) {
921 $this->updateRevision( $revObjs[$revid], $bitfield );
922 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
927 // Don't log or touch if nothing changed
928 if( $revCount > 0 ) {
929 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted
,
930 $comment, $title, 'oldid', $revIDs );
931 $this->updatePage( $title );
933 // Where all revs allowed to be set?
934 if( !$userAllowedAll ) {
935 //FIXME: still might be confusing???
936 $wgOut->permissionRequired( 'suppressrevision' );
944 * @param $title, the page these events apply to
945 * @param array $items list of revision ID numbers
946 * @param int $bitfield new rev_deleted value
947 * @param string $comment Comment for log records
949 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
952 $userAllowedAll = $success = true;
955 // Run through and pull all our data in one query
956 foreach( $items as $timestamp ) {
957 $where[] = $this->dbw
->timestamp( $timestamp );
959 $result = $this->dbw
->select( 'archive', '*',
961 'ar_namespace' => $title->getNamespace(),
962 'ar_title' => $title->getDBKey(),
963 'ar_timestamp' => $where
966 while( $row = $this->dbw
->fetchObject( $result ) ) {
967 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
968 $revObjs[$timestamp] = new Revision( array(
969 'page' => $title->getArticleId(),
970 'id' => $row->ar_rev_id
,
971 'text' => $row->ar_text_id
,
972 'comment' => $row->ar_comment
,
973 'user' => $row->ar_user
,
974 'user_text' => $row->ar_user_text
,
975 'timestamp' => $timestamp,
976 'minor_edit' => $row->ar_minor_edit
,
977 'text_id' => $row->ar_text_id
,
978 'deleted' => $row->ar_deleted
,
979 'len' => $row->ar_len
) );
982 foreach( $items as $timestamp ) {
983 // This will only select the first revision with this timestamp.
984 // Since they are all selected/deleted at once, we can just check the
985 // permissions of one. UPDATE is done via timestamp, so all revs are set.
986 if( !is_object($revObjs[$timestamp]) ) {
988 continue; // Must exist
989 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
990 $userAllowedAll=false;
993 // Which revisions did we change anything about?
994 if( $revObjs[$timestamp]->mDeleted
!= $bitfield ) {
995 $Id_set[] = $timestamp;
996 $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
1000 // For logging, maintain a count of revisions
1002 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted
,
1003 $comment, $title, 'artimestamp', $Id_set );
1005 // Where all revs allowed to be set?
1006 if( !$userAllowedAll ) {
1007 $wgOut->permissionRequired( 'suppressrevision' );
1015 * @param $title, the page these events apply to
1016 * @param array $items list of revision ID numbers
1017 * @param int $bitfield new rev_deleted value
1018 * @param string $comment Comment for log records
1020 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
1023 $userAllowedAll = $success = true;
1026 // Run through and pull all our data in one query
1027 foreach( $items as $timestamp ) {
1028 $where[] = $timestamp.'!'.$title->getDBKey();
1030 $result = $this->dbw
->select( 'oldimage', '*',
1031 array( 'oi_name' => $title->getDBKey(), 'oi_archive_name' => $where ),
1034 while( $row = $this->dbw
->fetchObject( $result ) ) {
1035 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
1036 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
1037 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
1040 foreach( $items as $timestamp ) {
1041 $archivename = $timestamp.'!'.$title->getDBKey();
1042 if( !isset($filesObjs[$archivename]) ) {
1044 continue; // Must exist
1045 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
1046 $userAllowedAll=false;
1050 $transaction = true;
1051 // Which revisions did we change anything about?
1052 if( $filesObjs[$archivename]->deleted
!= $bitfield ) {
1055 $this->dbw
->begin();
1056 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
1057 // If this image is currently hidden...
1058 if( $filesObjs[$archivename]->deleted
& File
::DELETED_FILE
) {
1059 if( $bitfield & File
::DELETED_FILE
) {
1060 # Leave it alone if we are not changing this...
1062 $transaction = true;
1064 # We are moving this out
1065 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
1066 $set[]=$transaction;
1068 // Is it just now becoming hidden?
1069 } else if( $bitfield & File
::DELETED_FILE
) {
1070 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
1071 $set[]=$transaction;
1075 // If our file operations fail, then revert back the db
1076 if( $transaction==false ) {
1077 $this->dbw
->rollback();
1080 $this->dbw
->commit();
1084 // Log if something was changed
1086 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted
,
1087 $comment, $title, 'oldimage', $set );
1088 # Purge page/history
1089 $file = wfLocalFile( $title );
1090 $file->purgeCache();
1091 $file->purgeHistory();
1092 # Invalidate cache for all pages using this file
1093 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
1094 $update->doUpdate();
1096 // Where all revs allowed to be set?
1097 if( !$userAllowedAll ) {
1098 $wgOut->permissionRequired( 'suppressrevision' );
1106 * @param $title, the page these events apply to
1107 * @param array $items list of revision ID numbers
1108 * @param int $bitfield new rev_deleted value
1109 * @param string $comment Comment for log records
1111 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
1114 $userAllowedAll = $success = true;
1118 // Run through and pull all our data in one query
1119 foreach( $items as $id ) {
1120 $where[] = intval($id);
1122 $result = $this->dbw
->select( 'filearchive', '*',
1123 array( 'fa_name' => $title->getDBKey(),
1124 'fa_id' => $where ),
1126 while( $row = $this->dbw
->fetchObject( $result ) ) {
1127 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
1130 foreach( $items as $fileid ) {
1131 if( !isset($filesObjs[$fileid]) ) {
1133 continue; // Must exist
1134 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
1135 $userAllowedAll=false;
1138 // Which revisions did we change anything about?
1139 if( $filesObjs[$fileid]->deleted
!= $bitfield ) {
1143 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1146 // Log if something was changed
1148 $this->updateLog( $title, $count, $bitfield, $comment,
1149 $filesObjs[$fileid]->deleted
, $title, 'fileid', $Id_set );
1151 // Where all revs allowed to be set?
1152 if( !$userAllowedAll ) {
1153 $wgOut->permissionRequired( 'suppressrevision' );
1161 * @param $title, the log page these events apply to
1162 * @param array $items list of log ID numbers
1163 * @param int $bitfield new log_deleted value
1164 * @param string $comment Comment for log records
1166 function setEventVisibility( $title, $items, $bitfield, $comment ) {
1169 $userAllowedAll = $success = true;
1173 // Run through and pull all our data in one query
1174 foreach( $items as $logid ) {
1175 $where[] = intval($logid);
1177 list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
1178 $result = $this->dbw
->select( 'logging', '*',
1179 array( 'log_type' => $logtype, 'log_id' => $where ),
1182 while( $row = $this->dbw
->fetchObject( $result ) ) {
1183 $logRows[$row->log_id
] = $row;
1186 foreach( $items as $logid ) {
1187 if( !isset($logRows[$logid]) ) {
1189 continue; // Must exist
1190 } else if( !LogEventsList
::userCan($logRows[$logid], LogPage
::DELETED_RESTRICTED
)
1191 ||
$logRows[$logid]->log_type
== 'suppress' )
1193 $userAllowedAll=false; // Don't hide from oversight log!!!
1196 // Which logs did we change anything about?
1197 if( $logRows[$logid]->log_deleted
!= $bitfield ) {
1198 $log_Ids[] = $logid;
1199 $this->updateLogs( $logRows[$logid], $bitfield );
1200 $this->updateRecentChangesLog( $logRows[$logid], $bitfield );
1204 // Don't log or touch if nothing changed
1206 $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted
,
1207 $comment, $title, 'logid', $log_Ids );
1209 // Were all revs allowed to be set?
1210 if( !$userAllowedAll ) {
1211 $wgOut->permissionRequired( 'suppressrevision' );
1219 * Moves an image to a safe private location
1220 * Caller is responsible for clearing caches
1221 * @param File $oimage
1222 * @returns mixed, timestamp string on success, false on failure
1224 function makeOldImagePrivate( $oimage ) {
1225 $transaction = new FSTransaction();
1226 if( !FileStore
::lock() ) {
1227 wfDebug( __METHOD__
.": failed to acquire file store lock, aborting\n" );
1230 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1231 // Dupe the file into the file store
1232 if( file_exists( $oldpath ) ) {
1233 // Is our directory configured?
1234 if( $store = FileStore
::get( 'deleted' ) ) {
1235 if( !$oimage->sha1
) {
1236 $oimage->upgradeRow(); // sha1 may be missing
1238 $key = $oimage->sha1
. '.' . $oimage->getExtension();
1239 $transaction->add( $store->insert( $key, $oldpath, FileStore
::DELETE_ORIGINAL
) );
1243 $transaction = false; // Return an error and do nothing
1246 wfDebug( __METHOD__
." deleting already-missing '$oldpath'; moving on to database\n" );
1249 $transaction = new FSTransaction(); // empty
1252 if( $transaction === false ) {
1254 wfDebug( __METHOD__
.": import to file store failed, aborting\n" );
1255 throw new MWException( "Could not archive and delete file $oldpath" );
1259 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1260 $transaction->commit();
1261 FileStore
::unlock();
1263 $m = explode('!',$oimage->archive_name
,2);
1270 * Moves an image from a safe private location
1271 * Caller is responsible for clearing caches
1272 * @param File $oimage
1273 * @returns mixed, string timestamp on success, false on failure
1275 function makeOldImagePublic( $oimage ) {
1276 $transaction = new FSTransaction();
1277 if( !FileStore
::lock() ) {
1278 wfDebug( __METHOD__
." could not acquire filestore lock\n" );
1282 $store = FileStore
::get( 'deleted' );
1284 wfDebug( __METHOD__
.": skipping row with no file.\n" );
1288 $key = $oimage->sha1
.'.'.$oimage->getExtension();
1289 $destDir = $oimage->getArchivePath();
1290 if( !is_dir( $destDir ) ) {
1291 wfMkdirParents( $destDir );
1293 $destPath = $destDir . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1294 // Check if any other stored revisions use this file;
1295 // if so, we shouldn't remove the file from the hidden
1296 // archives so they will still work. Check hidden files first.
1297 $useCount = $this->dbw
->selectField( 'oldimage', '1',
1298 array( 'oi_sha1' => $oimage->sha1
,
1299 'oi_deleted & '.File
::DELETED_FILE
=> File
::DELETED_FILE
),
1300 __METHOD__
, array( 'FOR UPDATE' ) );
1301 // Check the rest of the deleted archives too.
1302 // (these are the ones that don't show in the image history)
1304 $useCount = $this->dbw
->selectField( 'filearchive', '1',
1305 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1306 __METHOD__
, array( 'FOR UPDATE' ) );
1309 if( $useCount == 0 ) {
1310 wfDebug( __METHOD__
.": nothing else using {$oimage->sha1}, will deleting after\n" );
1311 $flags = FileStore
::DELETE_ORIGINAL
;
1315 $transaction->add( $store->export( $key, $destPath, $flags ) );
1317 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1318 $transaction->commit();
1319 FileStore
::unlock();
1321 $m = explode('!',$oimage->archive_name
,2);
1328 * Update the revision's rev_deleted field
1329 * @param Revision $rev
1330 * @param int $bitfield new rev_deleted bitfield value
1332 function updateRevision( $rev, $bitfield ) {
1333 $this->dbw
->update( 'revision',
1334 array( 'rev_deleted' => $bitfield ),
1335 array( 'rev_id' => $rev->getId(), 'rev_page' => $rev->getPage() ),
1341 * Update the revision's rev_deleted field
1342 * @param Revision $rev
1343 * @param Title $title
1344 * @param int $bitfield new rev_deleted bitfield value
1346 function updateArchive( $rev, $title, $bitfield ) {
1347 $this->dbw
->update( 'archive',
1348 array( 'ar_deleted' => $bitfield ),
1349 array( 'ar_namespace' => $title->getNamespace(),
1350 'ar_title' => $title->getDBKey(),
1351 // use timestamp for index
1352 'ar_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ),
1353 'ar_rev_id' => $rev->getId()
1359 * Update the images's oi_deleted field
1361 * @param int $bitfield new rev_deleted bitfield value
1363 function updateOldFiles( $file, $bitfield ) {
1364 $this->dbw
->update( 'oldimage',
1365 array( 'oi_deleted' => $bitfield ),
1366 array( 'oi_name' => $file->getName(),
1367 'oi_timestamp' => $this->dbw
->timestamp( $file->getTimestamp() ) ),
1373 * Update the images's fa_deleted field
1374 * @param ArchivedFile $file
1375 * @param int $bitfield new rev_deleted bitfield value
1377 function updateArchFiles( $file, $bitfield ) {
1378 $this->dbw
->update( 'filearchive',
1379 array( 'fa_deleted' => $bitfield ),
1380 array( 'fa_id' => $file->getId() ),
1386 * Update the logging log_deleted field
1388 * @param int $bitfield new rev_deleted bitfield value
1390 function updateLogs( $row, $bitfield ) {
1391 $this->dbw
->update( 'logging',
1392 array( 'log_deleted' => $bitfield ),
1393 array( 'log_id' => $row->log_id
),
1399 * Update the revision's recentchanges record if fields have been hidden
1400 * @param Revision $rev
1401 * @param int $bitfield new rev_deleted bitfield value
1403 function updateRecentChangesEdits( $rev, $bitfield ) {
1404 $this->dbw
->update( 'recentchanges',
1405 array( 'rc_deleted' => $bitfield,
1406 'rc_patrolled' => 1 ),
1407 array( 'rc_this_oldid' => $rev->getId(),
1408 'rc_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ) ),
1414 * Update the revision's recentchanges record if fields have been hidden
1416 * @param int $bitfield new rev_deleted bitfield value
1418 function updateRecentChangesLog( $row, $bitfield ) {
1419 $this->dbw
->update( 'recentchanges',
1420 array( 'rc_deleted' => $bitfield,
1421 'rc_patrolled' => 1 ),
1422 array( 'rc_logid' => $row->log_id
,
1423 'rc_timestamp' => $row->log_timestamp
),
1429 * Touch the page's cache invalidation timestamp; this forces cached
1430 * history views to refresh, so any newly hidden or shown fields will
1432 * @param Title $title
1434 function updatePage( $title ) {
1435 $title->invalidateCache();
1436 $this->dbw
->commit(); // Commit the transaction before the purge is sent
1437 $title->purgeSquid();
1438 $title->touchLinks();
1439 // Extensions that require referencing previous revisions may need this
1440 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1444 * Checks for a change in the bitfield for a certain option and updates the
1445 * provided array accordingly.
1447 * @param String $desc Description to add to the array if the option was
1448 * enabled / disabled.
1449 * @param int $field The bitmask describing the single option.
1450 * @param int $diff The xor of the old and new bitfields.
1451 * @param array $arr The array to update.
1453 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
1454 if( $diff & $field ) {
1455 $arr[ ( $new & $field ) ?
0 : 1 ][] = $desc;
1460 * Gets an array describing the changes made to the visibilit of the revision.
1461 * If the resulting array is $arr, then $arr[0] will contain an array of strings
1462 * describing the items that were hidden, $arr[2] will contain an array of strings
1463 * describing the items that were unhidden, and $arr[3] will contain an array with
1464 * a single string, which can be one of "applied restrictions to sysops",
1465 * "removed restrictions from sysops", or null.
1467 * @param int $n The new bitfield.
1468 * @param int $o The old bitfield.
1469 * @return An array as described above.
1471 protected static function getChanges( $n, $o ) {
1473 $ret = array( 0 => array(), 1 => array(), 2 => array() );
1474 // Build bitfield changes in language
1475 self
::checkItem( wfMsgForContent( 'revdelete-content' ),
1476 Revision
::DELETED_TEXT
, $diff, $n, $ret );
1477 self
::checkItem( wfMsgForContent( 'revdelete-summary' ),
1478 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
1479 self
::checkItem( wfMsgForContent( 'revdelete-uname' ),
1480 Revision
::DELETED_USER
, $diff, $n, $ret );
1481 // Restriction application to sysops
1482 if( $diff & Revision
::DELETED_RESTRICTED
) {
1483 if( $n & Revision
::DELETED_RESTRICTED
)
1484 $ret[2][] = wfMsgForContent( 'revdelete-restricted' );
1486 $ret[2][] = wfMsgForContent( 'revdelete-unrestricted' );
1492 * Gets a log message to describe the given revision visibility change. This
1493 * message will be of the form "[hid {content, edit summary, username}];
1494 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
1496 * @param int $count The number of effected revisions.
1497 * @param int $nbitfield The new bitfield for the revision.
1498 * @param int $obitfield The old bitfield for the revision.
1499 * @param bool $isForLog
1501 public static function getLogMessage( $count, $nbitfield, $obitfield, $isForLog = false ) {
1504 $changes = self
::getChanges( $nbitfield, $obitfield );
1505 if( count( $changes[0] ) ) {
1506 $s .= wfMsgForContent( 'revdelete-hid', implode( ', ', $changes[0] ) );
1508 if( count( $changes[1] ) ) {
1510 $s .= wfMsgForContent( 'revdelete-unhid', implode( ', ', $changes[1] ) );
1512 if( count( $changes[2] ) ) {
1513 $s .= $s ?
' (' . $changes[2][0] . ')' : $changes[2][0];
1515 $msg = $isForLog ?
'logdelete-log-message' : 'revdelete-log-message';
1516 return wfMsgExt( $msg, array( 'parsemag', 'content' ), $s, $wgLang->formatNum($count) );
1521 * Record a log entry on the action
1522 * @param Title $title, page where item was removed from
1523 * @param int $count the number of revisions altered for this page
1524 * @param int $nbitfield the new _deleted value
1525 * @param int $obitfield the old _deleted value
1526 * @param string $comment
1527 * @param Title $target, the relevant page
1528 * @param string $param, URL param
1529 * @param Array $items
1531 function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target,
1532 $param, $items = array() )
1534 // Put things hidden from sysops in the oversight log
1535 $logType = ( ($nbitfield |
$obitfield) & Revision
::DELETED_RESTRICTED
) ?
1536 'suppress' : 'delete';
1537 // Log deletions show with a difference action message
1538 $logAction = ( $param == 'logid' ) ?
'event' : 'revision';
1539 // Track what items changed here
1540 $itemCSV = implode(',',$items);
1541 // Add params for effected page and ids
1542 if( $param == 'logid' ) {
1543 $params = array( $itemCSV, "ofield={$obitfield}", "nfield={$nbitfield}" );
1545 $params = array( $param, $itemCSV, "ofield={$obitfield}", "nfield={$nbitfield}" );
1547 // Actually add the deletion log entry
1548 $log = new LogPage( $logType );
1549 $logid = $log->addEntry( $logAction, $title, $comment, $params );
1550 // Allow for easy searching of deletion log items for revision/log items
1551 $log->addRelations( self
::getRelationType($param), $items, $logid );
1554 // Get DB field name for URL param...
1555 // Future code for other things may also track
1556 // other types of revision-specific changes.
1557 public static function getRelationType( $param ) {
1562 return 'rev_timestamp';
1564 return 'oi_timestamp';
1570 throw new MWException( "Bad log URL param type!" );