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 );
17 public function execute( $par ) {
18 global $wgOut, $wgUser, $wgRequest;
20 $wgOut->readOnlyPage();
23 if( !$wgUser->isAllowed( 'deleterevision' ) ) {
24 $wgOut->permissionRequired( 'deleterevision' );
27 $this->skin
=& $wgUser->getSkin();
29 $this->outputHeader();
30 $this->wasPosted
= $wgRequest->wasPosted();
32 $this->target
= $wgRequest->getText( 'target' );
33 # Handle our many different possible input types.
34 # Use CVS, since the cgi handling will break on arrays.
35 $this->oldids
= array_filter( explode( ',', $wgRequest->getVal('oldid') ) );
36 $this->artimestamps
= array_filter( explode( ',', $wgRequest->getVal('artimestamp') ) );
37 $this->logids
= array_filter( explode( ',', $wgRequest->getVal('logid') ) );
38 $this->oldimgs
= array_filter( explode( ',', $wgRequest->getVal('oldimage') ) );
39 $this->fileids
= array_filter( explode( ',', $wgRequest->getVal('fileid') ) );
40 # For reviewing deleted files...
41 $this->file
= $wgRequest->getVal( 'file' );
42 # Only one target set at a time please!
43 $i = (bool)$this->file +
(bool)$this->oldids +
(bool)$this->logids
44 +
(bool)$this->artimestamps +
(bool)$this->fileids +
(bool)$this->oldimgs
;
47 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
52 $wgOut->showErrorPage( 'revdelete-toomanytargets-title', 'revdelete-toomanytargets-text' );
55 $this->page
= Title
::newFromUrl( $this->target
);
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 $wgOut->addWikiMsg( 'undelete-header' );
68 # Logs must have a type given
69 if( $this->logids
&& !strpos($this->page
->getDBKey(),'/') ) {
70 $wgOut->showErrorPage( 'revdelete-nologtype-title', 'revdelete-nologtype-text' );
73 # For reviewing deleted files...show it now if allowed
75 $oimage = RepoGroup
::singleton()->getLocalRepo()->newFromArchiveName( $this->page
, $this->file
);
77 // Check if user is allowed to see this file
78 if( !$oimage->userCan(File
::DELETED_FILE
) ) {
79 $wgOut->permissionRequired( 'suppressrevision' );
81 $this->showFile( $this->file
);
85 # Give a link to the logs/hist for this page
86 if( !is_null($this->page
) && $this->page
->getNamespace() > -1 ) {
89 $logtitle = SpecialPage
::getTitleFor( 'Log' );
90 $links[] = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
91 wfArrayToCGI( array( 'page' => $this->page
->getPrefixedUrl() ) ) );
92 # Give a link to the page history
93 $links[] = $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml( 'pagehist' ),
94 wfArrayToCGI( array( 'action' => 'history' ) ) );
95 # Link to deleted edits
96 if( $wgUser->isAllowed('undelete') ) {
97 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
98 $links[] = $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
99 wfArrayToCGI( array( 'target' => $this->page
->getPrefixedDBkey() ) ) );
101 # Logs themselves don't have histories or archived revisions
102 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
104 # Lock the operation and the form context
105 $this->secureOperation();
106 # Either submit or create our form
107 if( $this->wasPosted
) {
108 $this->submit( $wgRequest );
109 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
111 } else if( $this->deleteKey
== 'fileid' ||
$this->deleteKey
== 'oldimage' ) {
113 } else if( $this->deleteKey
== 'logid' ) {
114 $this->showLogItems();
116 $qc = $this->getLogQueryCond();
117 # Show relevant lines from the deletion log
118 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'delete' ) ) . "</h2>\n" );
119 LogEventsList
::showLogExtract( $wgOut, 'delete', $this->page
->getPrefixedText(), '', 25, $qc );
120 # Show relevant lines from the suppression log
121 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
122 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'suppress' ) ) . "</h2>\n" );
123 LogEventsList
::showLogExtract( $wgOut, 'suppress', $this->page
->getPrefixedText(), '', 25, $qc );
127 private function getLogQueryCond() {
128 $ids = $safeIds = array();
129 $action = 'revision';
130 switch( $this->deleteKey
) {
132 $ids = $this->oldids
;
135 $ids = $this->artimestamps
;
138 $ids = $this->oldimgs
;
141 $ids = $this->fileids
;
144 $ids = $this->logids
;
148 // Revision delete logs
149 $conds = array( 'log_action' => $action );
150 // Just get the whole log if there are a lot if items
151 if( count($ids) > 20 ) return $conds;
153 foreach( $ids as $id ) {
154 if( preg_match( '/^\d+$/', $id, $m ) ) {
158 // Format is <id1,id2,i3...>
159 if( count($safeIds) ) {
160 $conds[] = "log_params RLIKE '(^|\n|,)(".implode('|',$safeIds).")(,|$)'";
165 private function secureOperation() {
167 $this->deleteKey
= '';
168 // At this point, we should only have one of these
169 if( $this->oldids
) {
170 $this->revisions
= $this->oldids
;
171 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
172 $this->deleteKey
= 'oldid';
173 } else if( $this->artimestamps
) {
174 $this->archrevs
= $this->artimestamps
;
175 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
176 $this->deleteKey
= 'artimestamp';
177 } else if( $this->oldimgs
) {
178 $this->ofiles
= $this->oldimgs
;
179 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
180 $this->deleteKey
= 'oldimage';
181 } else if( $this->fileids
) {
182 $this->afiles
= $this->fileids
;
183 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
184 $this->deleteKey
= 'fileid';
185 } else if( $this->logids
) {
186 $this->events
= $this->logids
;
187 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage
::DELETED_ACTION
);
188 $this->deleteKey
= 'logid';
190 // Our checkbox messages depends one what we are doing,
191 // e.g. we don't hide "text" for logs or images
192 $this->checks
= array(
194 array( 'revdelete-hide-comment', 'wpHideComment', Revision
::DELETED_COMMENT
),
195 array( 'revdelete-hide-user', 'wpHideUser', Revision
::DELETED_USER
)
197 if( $wgUser->isAllowed('suppressrevision') ) {
198 $this->checks
[] = array( 'revdelete-hide-restricted',
199 'wpHideRestricted', Revision
::DELETED_RESTRICTED
);
204 * Show a deleted file version requested by the visitor.
206 private function showFile( $key ) {
207 global $wgOut, $wgRequest;
210 # We mustn't allow the output to be Squid cached, otherwise
211 # if an admin previews a deleted image, and it's cached, then
212 # a user without appropriate permissions can toddle off and
213 # nab the image, and Squid will serve it
214 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
215 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
216 $wgRequest->response()->header( 'Pragma: no-cache' );
218 $store = FileStore
::get( 'deleted' );
219 $store->stream( $key );
223 * This lets a user set restrictions for live and archived revisions
225 private function showRevs() {
226 global $wgOut, $wgUser;
229 $count = ($this->deleteKey
=='oldid') ?
230 count($this->revisions
) : count($this->archrevs
);
231 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(), $count );
234 $wgOut->addHTML( "<ul>" );
236 $where = $revObjs = array();
237 $dbr = wfGetDB( DB_MASTER
);
241 if( $this->deleteKey
=='oldid' ) {
242 // Run through and pull all our data in one query
243 foreach( $this->revisions
as $revid ) {
244 $where[] = intval($revid);
246 $result = $dbr->select( array('revision','page'), '*',
248 'rev_page' => $this->page
->getArticleID(),
250 'rev_page = page_id' ),
252 while( $row = $dbr->fetchObject( $result ) ) {
253 $revObjs[$row->rev_id
] = new Revision( $row );
255 foreach( $this->revisions
as $revid ) {
256 // Hiding top revisison is bad
257 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
259 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
260 // If a rev is hidden from sysops
261 if( !$this->wasPosted
) {
262 $wgOut->permissionRequired( 'suppressrevision' );
265 $UserAllowed = false;
268 $wgOut->addHTML( $this->historyLine( $revObjs[$revid] ) );
269 $bitfields |
= $revObjs[$revid]->mDeleted
;
273 // Run through and pull all our data in one query
274 foreach( $this->archrevs
as $timestamp ) {
275 $where[] = $dbr->timestamp( $timestamp );
277 $result = $dbr->select( 'archive', '*',
279 'ar_namespace' => $this->page
->getNamespace(),
280 'ar_title' => $this->page
->getDBKey(),
281 'ar_timestamp' => $where ),
283 while( $row = $dbr->fetchObject( $result ) ) {
284 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
285 $revObjs[$timestamp] = new Revision( array(
286 'page' => $this->page
->getArticleId(),
287 'id' => $row->ar_rev_id
,
288 'text' => $row->ar_text_id
,
289 'comment' => $row->ar_comment
,
290 'user' => $row->ar_user
,
291 'user_text' => $row->ar_user_text
,
292 'timestamp' => $timestamp,
293 'minor_edit' => $row->ar_minor_edit
,
294 'text_id' => $row->ar_text_id
,
295 'deleted' => $row->ar_deleted
,
296 'len' => $row->ar_len
) );
298 foreach( $this->archrevs
as $timestamp ) {
299 if( !isset($revObjs[$timestamp]) ) {
301 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
302 // If a rev is hidden from sysops
303 if( !$this->wasPosted
) {
304 $wgOut->permissionRequired( 'suppressrevision' );
307 $UserAllowed = false;
310 $wgOut->addHTML( $this->historyLine( $revObjs[$timestamp] ) );
311 $bitfields |
= $revObjs[$timestamp]->mDeleted
;
315 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
319 $wgOut->addHTML( "</ul>" );
321 $this->addUsageText();
323 // Normal sysops can always see what they did, but can't always change it
324 if( !$UserAllowed ) return;
327 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
328 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
331 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
332 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
333 Xml
::hidden( 'type', $this->deleteKey
)
335 if( $this->deleteKey
=='oldid' ) {
336 $hidden[] = Xml
::hidden( 'oldid', implode(',',$this->oldids
) );
338 $hidden[] = Xml
::hidden( 'artimestamp', implode(',',$this->artimestamps
) );
340 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
342 Xml
::openElement( 'form', array( 'method' => 'post',
343 'action' => $special->getLocalUrl( 'action=submit' ),
344 'id' => 'mw-revdel-form-revisions' ) ) .
345 Xml
::openElement( 'fieldset' ) .
346 xml
::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
349 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
350 foreach( $items as $item ) {
351 $wgOut->addHTML( Xml
::tags( 'p', null, $item ) );
353 foreach( $hidden as $item ) {
354 $wgOut->addHTML( $item );
357 Xml
::closeElement( 'fieldset' ) .
358 Xml
::closeElement( 'form' ) . "\n"
363 * This lets a user set restrictions for archived images
365 private function showImages() {
366 global $wgOut, $wgUser, $wgLang;
369 $count = ($this->deleteKey
=='oldimage') ?
count($this->ofiles
) : count($this->afiles
);
370 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(),
371 $wgLang->formatNum($count) );
374 $wgOut->addHTML( "<ul>" );
376 $where = $filesObjs = array();
377 $dbr = wfGetDB( DB_MASTER
);
378 // Live old revisions...
380 if( $this->deleteKey
=='oldimage' ) {
381 // Run through and pull all our data in one query
382 foreach( $this->ofiles
as $timestamp ) {
383 $where[] = $timestamp.'!'.$this->page
->getDBKey();
385 $result = $dbr->select( 'oldimage', '*',
387 'oi_name' => $this->page
->getDBKey(),
388 'oi_archive_name' => $where ),
390 while( $row = $dbr->fetchObject( $result ) ) {
391 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
392 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
393 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
395 // Check through our images
396 foreach( $this->ofiles
as $timestamp ) {
397 $archivename = $timestamp.'!'.$this->page
->getDBKey();
398 if( !isset($filesObjs[$archivename]) ) {
400 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
401 // If a rev is hidden from sysops
402 if( !$this->wasPosted
) {
403 $wgOut->permissionRequired( 'suppressrevision' );
406 $UserAllowed = false;
409 // Inject history info
410 $wgOut->addHTML( $this->fileLine( $filesObjs[$archivename] ) );
411 $bitfields |
= $filesObjs[$archivename]->deleted
;
415 // Run through and pull all our data in one query
416 foreach( $this->afiles
as $id ) {
417 $where[] = intval($id);
419 $result = $dbr->select( 'filearchive', '*',
421 'fa_name' => $this->page
->getDBKey(),
424 while( $row = $dbr->fetchObject( $result ) ) {
425 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
428 foreach( $this->afiles
as $fileid ) {
429 if( !isset($filesObjs[$fileid]) ) {
431 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
432 // If a rev is hidden from sysops
433 if( !$this->wasPosted
) {
434 $wgOut->permissionRequired( 'suppressrevision' );
437 $UserAllowed = false;
440 // Inject history info
441 $wgOut->addHTML( $this->archivedfileLine( $filesObjs[$fileid] ) );
442 $bitfields |
= $filesObjs[$fileid]->deleted
;
446 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
450 $wgOut->addHTML( "</ul>" );
452 $this->addUsageText();
453 // Normal sysops can always see what they did, but can't always change it
454 if( !$UserAllowed ) return;
457 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
458 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
461 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
462 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
463 Xml
::hidden( 'type', $this->deleteKey
)
465 if( $this->deleteKey
=='oldimage' ) {
466 $hidden[] = Xml
::hidden( 'oldimage', implode(',',$this->oldimgs
) );
468 $hidden[] = Xml
::hidden( 'fileid', implode(',',$this->fileids
) );
470 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
472 Xml
::openElement( 'form', array( 'method' => 'post',
473 'action' => $special->getLocalUrl( 'action=submit' ),
474 'id' => 'mw-revdel-form-filerevisions' )
476 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
479 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
480 foreach( $items as $item ) {
481 $wgOut->addHTML( "<p>$item</p>" );
483 foreach( $hidden as $item ) {
484 $wgOut->addHTML( $item );
488 Xml
::closeElement( 'fieldset' ) .
489 Xml
::closeElement( 'form' ) . "\n"
494 * This lets a user set restrictions for log items
496 private function showLogItems() {
497 global $wgOut, $wgUser, $wgMessageCache, $wgLang;
500 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->events
) ) );
503 $wgOut->addHTML( "<ul>" );
505 $where = $logRows = array();
506 $dbr = wfGetDB( DB_MASTER
);
507 // Run through and pull all our data in one query
509 foreach( $this->events
as $logid ) {
510 $where[] = intval($logid);
512 list($log,$logtype) = explode( '/',$this->page
->getDBKey(), 2 );
513 $result = $dbr->select( 'logging', '*',
515 'log_type' => $logtype,
516 'log_id' => $where ),
518 while( $row = $dbr->fetchObject( $result ) ) {
519 $logRows[$row->log_id
] = $row;
521 $wgMessageCache->loadAllMessages();
522 foreach( $this->events
as $logid ) {
523 // Don't hide from oversight log!!!
524 if( !isset( $logRows[$logid] ) ||
$logRows[$logid]->log_type
=='suppress' ) {
526 } else if( !LogEventsList
::userCan( $logRows[$logid],Revision
::DELETED_RESTRICTED
) ) {
527 // If an event is hidden from sysops
528 if( !$this->wasPosted
) {
529 $wgOut->permissionRequired( 'suppressrevision' );
532 $UserAllowed = false;
535 $wgOut->addHTML( $this->logLine( $logRows[$logid] ) );
536 $bitfields |
= $logRows[$logid]->log_deleted
;
539 $wgOut->showErrorPage( 'revdelete-nologid-title', 'revdelete-nologid-text' );
543 $wgOut->addHTML( "</ul>" );
545 $this->addUsageText();
546 // Normal sysops can always see what they did, but can't always change it
547 if( !$UserAllowed ) return;
550 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
551 Xml
::submitButton( wfMsg( 'revdelete-submit' ) ) );
553 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
554 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
555 Xml
::hidden( 'type', $this->deleteKey
),
556 Xml
::hidden( 'logid', implode(',',$this->logids
) )
559 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
561 Xml
::openElement( 'form', array( 'method' => 'post',
562 'action' => $special->getLocalUrl( 'action=submit' ), 'id' => 'mw-revdel-form-logs' ) ) .
563 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
566 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
567 foreach( $items as $item ) {
568 $wgOut->addHTML( "<p>$item</p>" );
570 foreach( $hidden as $item ) {
571 $wgOut->addHTML( $item );
575 Xml
::closeElement( 'fieldset' ) .
576 Xml
::closeElement( 'form' ) . "\n"
580 private function addUsageText() {
581 global $wgOut, $wgUser;
582 $wgOut->addWikiMsg( 'revdelete-text' );
583 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
584 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
589 * @param int $bitfields, aggregate bitfield of all the bitfields
590 * @returns string HTML
592 private function buildCheckBoxes( $bitfields ) {
594 // FIXME: all items checked for just one rev are checked, even if not set for the others
595 foreach( $this->checks
as $item ) {
596 list( $message, $name, $field ) = $item;
597 $line = Xml
::tags( 'div', null, Xml
::checkLabel( wfMsg($message), $name, $name,
598 $bitfields & $field ) );
599 if( $field == Revision
::DELETED_RESTRICTED
) $line = "<b>$line</b>";
606 * @param Revision $rev
609 private function historyLine( $rev ) {
610 global $wgLang, $wgUser;
612 $date = $wgLang->timeanddate( $rev->getTimestamp() );
613 $difflink = $del = '';
615 if( $this->deleteKey
=='oldid' ) {
616 $tokenParams = '&unhide=1&token='.urlencode( $wgUser->editToken( $rev->getId() ) );
617 $revlink = $this->skin
->makeLinkObj( $this->page
, $date, 'oldid='.$rev->getId() . $tokenParams );
618 $difflink = '(' . $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml('diff'),
619 'diff=' . $rev->getId() . '&oldid=prev' . $tokenParams ) . ')';
620 // Archived revisions
622 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
623 $target = $this->page
->getPrefixedText();
624 $revlink = $this->skin
->makeLinkObj( $undelete, $date,
625 "target=$target×tamp=" . $rev->getTimestamp() );
626 $difflink = '(' . $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml('diff'),
627 "target=$target&diff=prev×tamp=" . $rev->getTimestamp() ) . ')';
629 // Check permissions; items may be "suppressed"
630 if( $rev->isDeleted(Revision
::DELETED_TEXT
) ) {
631 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
632 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
633 if( !$rev->userCan(Revision
::DELETED_TEXT
) ) {
634 $revlink = '<span class="history-deleted">'.$date.'</span>';
635 $difflink = '(' . wfMsgHtml('diff') . ')';
638 $userlink = $this->skin
->revUserLink( $rev );
639 $comment = $this->skin
->revComment( $rev );
641 return "<li>$difflink $revlink $userlink $comment{$del}</li>";
648 private function fileLine( $file ) {
649 global $wgLang, $wgTitle;
651 $target = $this->page
->getPrefixedText();
652 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
656 if( $file->isDeleted(File
::DELETED_FILE
) ) {
657 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
658 if( !$file->userCan(File
::DELETED_FILE
) ) {
661 $pageLink = $this->skin
->makeKnownLinkObj( $wgTitle, $date,
662 "target=$target&file=$file->sha1.".$file->getExtension() );
664 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
667 $url = $file->getUrlRel();
668 $pageLink = "<a href=\"{$url}\">{$date}</a>";
671 $data = wfMsg( 'widthheight',
672 $wgLang->formatNum( $file->getWidth() ),
673 $wgLang->formatNum( $file->getHeight() ) ) .
674 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
675 $data = htmlspecialchars( $data );
677 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
681 * @param ArchivedFile $file
684 private function archivedfileLine( $file ) {
687 $target = $this->page
->getPrefixedText();
688 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
690 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
691 $pageLink = $this->skin
->makeKnownLinkObj( $undelete, $date, "target=$target&file={$file->getKey()}" );
694 if( $file->isDeleted(File
::DELETED_FILE
) ) {
695 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
698 $data = wfMsg( 'widthheight',
699 $wgLang->formatNum( $file->getWidth() ),
700 $wgLang->formatNum( $file->getHeight() ) ) .
701 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
702 $data = htmlspecialchars( $data );
704 return "<li> $pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
708 * @param Array $row row
711 private function logLine( $row ) {
714 $date = $wgLang->timeanddate( $row->log_timestamp
);
715 $paramArray = LogPage
::extractParams( $row->log_params
);
716 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
718 $logtitle = SpecialPage
::getTitleFor( 'Log' );
719 $loglink = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
720 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
722 if( !LogEventsList
::userCan($row,LogPage
::DELETED_ACTION
) ) {
723 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
725 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
726 $this->skin
, $paramArray, true, true );
727 if( $row->log_deleted
& LogPage
::DELETED_ACTION
)
728 $action = '<span class="history-deleted">' . $action . '</span>';
731 $userLink = $this->skin
->userLink( $row->log_user
, User
::WhoIs($row->log_user
) );
732 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_USER
) ) {
733 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
736 $comment = $wgLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
737 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
738 $comment = '<span class="history-deleted">' . $comment . '</span>';
740 return "<li>($loglink) $date $userLink $action $comment</li>";
744 * Generate a user tool link cluster if the current user is allowed to view it
745 * @param ArchivedFile $file
746 * @return string HTML
748 private function fileUserTools( $file ) {
749 if( $file->userCan( Revision
::DELETED_USER
) ) {
750 $link = $this->skin
->userLink( $file->user
, $file->user_text
) .
751 $this->skin
->userToolLinks( $file->user
, $file->user_text
);
753 $link = wfMsgHtml( 'rev-deleted-user' );
755 if( $file->isDeleted( Revision
::DELETED_USER
) ) {
756 return '<span class="history-deleted">' . $link . '</span>';
762 * Wrap and format the given file's comment block, if the current
763 * user is allowed to view it.
765 * @param ArchivedFile $file
766 * @return string HTML
768 private function fileComment( $file ) {
769 if( $file->userCan( File
::DELETED_COMMENT
) ) {
770 $block = $this->skin
->commentBlock( $file->description
);
772 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
774 if( $file->isDeleted( File
::DELETED_COMMENT
) ) {
775 return "<span class=\"history-deleted\">$block</span>";
781 * @param WebRequest $request
783 private function submit( $request ) {
784 global $wgUser, $wgOut;
785 # Check edit token on submission
786 if( $this->wasPosted
&& !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
787 $wgOut->addWikiMsg( 'sessionfailure' );
790 $bitfield = $this->extractBitfield( $request );
791 $comment = $request->getText( 'wpReason' );
792 # Can the user set this field?
793 if( $bitfield & Revision
::DELETED_RESTRICTED
&& !$wgUser->isAllowed('suppressrevision') ) {
794 $wgOut->permissionRequired( 'suppressrevision' );
797 # If the save went through, go to success message. Otherwise
798 # bounce back to form...
799 if( $this->save( $bitfield, $comment, $this->page
) ) {
801 } else if( $request->getCheck( 'oldid' ) ||
$request->getCheck( 'artimestamp' ) ) {
802 return $this->showRevs();
803 } else if( $request->getCheck( 'logid' ) ) {
804 return $this->showLogs();
805 } else if( $request->getCheck( 'oldimage' ) ||
$request->getCheck( 'fileid' ) ) {
806 return $this->showImages();
810 private function success() {
813 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
815 $wrap = '<span class="success">$1</span>';
817 if( $this->deleteKey
=='logid' ) {
818 $wgOut->wrapWikiMsg( $wrap, 'logdelete-success' );
819 $this->showLogItems();
820 } else if( $this->deleteKey
=='oldid' ||
$this->deleteKey
=='artimestamp' ) {
821 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
823 } else if( $this->deleteKey
=='fileid' ) {
824 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
826 } else if( $this->deleteKey
=='oldimage' ) {
827 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
833 * Put together a rev_deleted bitfield from the submitted checkboxes
834 * @param WebRequest $request
837 private function extractBitfield( $request ) {
839 foreach( $this->checks
as $item ) {
840 list( /* message */ , $name, $field ) = $item;
841 if( $request->getCheck( $name ) ) {
848 private function save( $bitfield, $reason, $title ) {
849 $dbw = wfGetDB( DB_MASTER
);
850 // Don't allow simply locking the interface for no reason
851 if( $bitfield == Revision
::DELETED_RESTRICTED
) {
854 $deleter = new RevisionDeleter( $dbw );
855 // By this point, only one of the below should be set
856 if( isset($this->revisions
) ) {
857 return $deleter->setRevVisibility( $title, $this->revisions
, $bitfield, $reason );
858 } else if( isset($this->archrevs
) ) {
859 return $deleter->setArchiveVisibility( $title, $this->archrevs
, $bitfield, $reason );
860 } else if( isset($this->ofiles
) ) {
861 return $deleter->setOldImgVisibility( $title, $this->ofiles
, $bitfield, $reason );
862 } else if( isset($this->afiles
) ) {
863 return $deleter->setArchFileVisibility( $title, $this->afiles
, $bitfield, $reason );
864 } else if( isset($this->events
) ) {
865 return $deleter->setEventVisibility( $title, $this->events
, $bitfield, $reason );
871 * Implements the actions for Revision Deletion.
872 * @ingroup SpecialPage
874 class RevisionDeleter
{
875 function __construct( $db ) {
880 * @param $title, the page these events apply to
881 * @param array $items list of revision ID numbers
882 * @param int $bitfield new rev_deleted value
883 * @param string $comment Comment for log records
885 function setRevVisibility( $title, $items, $bitfield, $comment ) {
888 $userAllowedAll = $success = true;
891 // Run through and pull all our data in one query
892 foreach( $items as $revid ) {
893 $where[] = intval($revid);
895 $result = $this->dbw
->select( 'revision', '*',
897 'rev_page' => $title->getArticleID(),
898 'rev_id' => $where ),
900 while( $row = $this->dbw
->fetchObject( $result ) ) {
901 $revObjs[$row->rev_id
] = new Revision( $row );
904 foreach( $items as $revid ) {
905 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
907 continue; // Must exist
908 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
909 $userAllowedAll=false;
912 // For logging, maintain a count of revisions
913 if( $revObjs[$revid]->mDeleted
!= $bitfield ) {
917 $this->updateRevision( $revObjs[$revid], $bitfield );
918 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
922 // Don't log or touch if nothing changed
923 if( $revCount > 0 ) {
924 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted
,
925 $comment, $title, 'oldid', $revIDs );
926 $this->updatePage( $title );
928 // Where all revs allowed to be set?
929 if( !$userAllowedAll ) {
930 //FIXME: still might be confusing???
931 $wgOut->permissionRequired( 'suppressrevision' );
939 * @param $title, the page these events apply to
940 * @param array $items list of revision ID numbers
941 * @param int $bitfield new rev_deleted value
942 * @param string $comment Comment for log records
944 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
947 $userAllowedAll = $success = true;
950 // Run through and pull all our data in one query
951 foreach( $items as $timestamp ) {
952 $where[] = $this->dbw
->timestamp( $timestamp );
954 $result = $this->dbw
->select( 'archive', '*',
956 'ar_namespace' => $title->getNamespace(),
957 'ar_title' => $title->getDBKey(),
958 'ar_timestamp' => $where ),
960 while( $row = $this->dbw
->fetchObject( $result ) ) {
961 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
962 $revObjs[$timestamp] = new Revision( array(
963 'page' => $title->getArticleId(),
964 'id' => $row->ar_rev_id
,
965 'text' => $row->ar_text_id
,
966 'comment' => $row->ar_comment
,
967 'user' => $row->ar_user
,
968 'user_text' => $row->ar_user_text
,
969 'timestamp' => $timestamp,
970 'minor_edit' => $row->ar_minor_edit
,
971 'text_id' => $row->ar_text_id
,
972 'deleted' => $row->ar_deleted
,
973 'len' => $row->ar_len
) );
976 foreach( $items as $timestamp ) {
977 // This will only select the first revision with this timestamp.
978 // Since they are all selected/deleted at once, we can just check the
979 // permissions of one. UPDATE is done via timestamp, so all revs are set.
980 if( !is_object($revObjs[$timestamp]) ) {
982 continue; // Must exist
983 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
984 $userAllowedAll=false;
987 // Which revisions did we change anything about?
988 if( $revObjs[$timestamp]->mDeleted
!= $bitfield ) {
989 $Id_set[]=$timestamp;
992 $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
995 // For logging, maintain a count of revisions
997 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted
,
998 $comment, $title, 'artimestamp', $Id_set );
1000 // Where all revs allowed to be set?
1001 if( !$userAllowedAll ) {
1002 $wgOut->permissionRequired( 'suppressrevision' );
1010 * @param $title, the page these events apply to
1011 * @param array $items list of revision ID numbers
1012 * @param int $bitfield new rev_deleted value
1013 * @param string $comment Comment for log records
1015 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
1018 $userAllowedAll = $success = true;
1021 // Run through and pull all our data in one query
1022 foreach( $items as $timestamp ) {
1023 $where[] = $timestamp.'!'.$title->getDBKey();
1025 $result = $this->dbw
->select( 'oldimage', '*',
1027 'oi_name' => $title->getDBKey(),
1028 'oi_archive_name' => $where ),
1030 while( $row = $this->dbw
->fetchObject( $result ) ) {
1031 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
1032 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
1033 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
1036 foreach( $items as $timestamp ) {
1037 $archivename = $timestamp.'!'.$title->getDBKey();
1038 if( !isset($filesObjs[$archivename]) ) {
1040 continue; // Must exist
1041 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
1042 $userAllowedAll=false;
1046 $transaction = true;
1047 // Which revisions did we change anything about?
1048 if( $filesObjs[$archivename]->deleted
!= $bitfield ) {
1051 $this->dbw
->begin();
1052 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
1053 // If this image is currently hidden...
1054 if( $filesObjs[$archivename]->deleted
& File
::DELETED_FILE
) {
1055 if( $bitfield & File
::DELETED_FILE
) {
1056 # Leave it alone if we are not changing this...
1058 $transaction = true;
1060 # We are moving this out
1061 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
1062 $set[]=$transaction;
1064 // Is it just now becoming hidden?
1065 } else if( $bitfield & File
::DELETED_FILE
) {
1066 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
1067 $set[]=$transaction;
1071 // If our file operations fail, then revert back the db
1072 if( $transaction==false ) {
1073 $this->dbw
->rollback();
1076 $this->dbw
->commit();
1080 // Log if something was changed
1082 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted
,
1083 $comment, $title, 'oldimage', $set );
1084 # Purge page/history
1085 $file = wfLocalFile( $title );
1086 $file->purgeCache();
1087 $file->purgeHistory();
1088 # Invalidate cache for all pages using this file
1089 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
1090 $update->doUpdate();
1092 // Where all revs allowed to be set?
1093 if( !$userAllowedAll ) {
1094 $wgOut->permissionRequired( 'suppressrevision' );
1102 * @param $title, the page these events apply to
1103 * @param array $items list of revision ID numbers
1104 * @param int $bitfield new rev_deleted value
1105 * @param string $comment Comment for log records
1107 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
1110 $userAllowedAll = $success = true;
1114 // Run through and pull all our data in one query
1115 foreach( $items as $id ) {
1116 $where[] = intval($id);
1118 $result = $this->dbw
->select( 'filearchive', '*',
1119 array( 'fa_name' => $title->getDBKey(),
1120 'fa_id' => $where ),
1122 while( $row = $this->dbw
->fetchObject( $result ) ) {
1123 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
1126 foreach( $items as $fileid ) {
1127 if( !isset($filesObjs[$fileid]) ) {
1129 continue; // Must exist
1130 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
1131 $userAllowedAll=false;
1134 // Which revisions did we change anything about?
1135 if( $filesObjs[$fileid]->deleted
!= $bitfield ) {
1139 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1142 // Log if something was changed
1144 $this->updateLog( $title, $count, $bitfield, $comment,
1145 $filesObjs[$fileid]->deleted
, $title, 'fileid', $Id_set );
1147 // Where all revs allowed to be set?
1148 if( !$userAllowedAll ) {
1149 $wgOut->permissionRequired( 'suppressrevision' );
1157 * @param $title, the log page these events apply to
1158 * @param array $items list of log ID numbers
1159 * @param int $bitfield new log_deleted value
1160 * @param string $comment Comment for log records
1162 function setEventVisibility( $title, $items, $bitfield, $comment ) {
1165 $userAllowedAll = $success = true;
1169 // Run through and pull all our data in one query
1170 foreach( $items as $logid ) {
1171 $where[] = intval($logid);
1173 list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
1174 $result = $this->dbw
->select( 'logging', '*',
1176 'log_type' => $logtype,
1177 'log_id' => $where ),
1179 while( $row = $this->dbw
->fetchObject( $result ) ) {
1180 $logRows[$row->log_id
] = $row;
1183 foreach( $items as $logid ) {
1184 if( !isset($logRows[$logid]) ) {
1186 continue; // Must exist
1187 } else if( !LogEventsList
::userCan($logRows[$logid], LogPage
::DELETED_RESTRICTED
)
1188 ||
$logRows[$logid]->log_type
== 'suppress' ) {
1189 // Don't hide from oversight log!!!
1190 $userAllowedAll=false;
1193 // Which logs did we change anything about?
1194 if( $logRows[$logid]->log_deleted
!= $bitfield ) {
1198 $this->updateLogs( $logRows[$logid], $bitfield );
1199 $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
1202 // Don't log or touch if nothing changed
1204 $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted
,
1205 $comment, $title, 'logid', $log_Ids );
1207 // Were all revs allowed to be set?
1208 if( !$userAllowedAll ) {
1209 $wgOut->permissionRequired( 'suppressrevision' );
1217 * Moves an image to a safe private location
1218 * Caller is responsible for clearing caches
1219 * @param File $oimage
1220 * @returns mixed, timestamp string on success, false on failure
1222 function makeOldImagePrivate( $oimage ) {
1223 $transaction = new FSTransaction();
1224 if( !FileStore
::lock() ) {
1225 wfDebug( __METHOD__
.": failed to acquire file store lock, aborting\n" );
1228 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1229 // Dupe the file into the file store
1230 if( file_exists( $oldpath ) ) {
1231 // Is our directory configured?
1232 if( $store = FileStore
::get( 'deleted' ) ) {
1233 if( !$oimage->sha1
) {
1234 $oimage->upgradeRow(); // sha1 may be missing
1236 $key = $oimage->sha1
. '.' . $oimage->getExtension();
1237 $transaction->add( $store->insert( $key, $oldpath, FileStore
::DELETE_ORIGINAL
) );
1241 $transaction = false; // Return an error and do nothing
1244 wfDebug( __METHOD__
." deleting already-missing '$oldpath'; moving on to database\n" );
1247 $transaction = new FSTransaction(); // empty
1250 if( $transaction === false ) {
1252 wfDebug( __METHOD__
.": import to file store failed, aborting\n" );
1253 throw new MWException( "Could not archive and delete file $oldpath" );
1257 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1258 $transaction->commit();
1259 FileStore
::unlock();
1261 $m = explode('!',$oimage->archive_name
,2);
1268 * Moves an image from a safe private location
1269 * Caller is responsible for clearing caches
1270 * @param File $oimage
1271 * @returns mixed, string timestamp on success, false on failure
1273 function makeOldImagePublic( $oimage ) {
1274 $transaction = new FSTransaction();
1275 if( !FileStore
::lock() ) {
1276 wfDebug( __METHOD__
." could not acquire filestore lock\n" );
1280 $store = FileStore
::get( 'deleted' );
1282 wfDebug( __METHOD__
.": skipping row with no file.\n" );
1286 $key = $oimage->sha1
.'.'.$oimage->getExtension();
1287 $destDir = $oimage->getArchivePath();
1288 if( !is_dir( $destDir ) ) {
1289 wfMkdirParents( $destDir );
1291 $destPath = $destDir . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1292 // Check if any other stored revisions use this file;
1293 // if so, we shouldn't remove the file from the hidden
1294 // archives so they will still work. Check hidden files first.
1295 $useCount = $this->dbw
->selectField( 'oldimage', '1',
1296 array( 'oi_sha1' => $oimage->sha1
,
1297 'oi_deleted & '.File
::DELETED_FILE
=> File
::DELETED_FILE
),
1298 __METHOD__
, array( 'FOR UPDATE' ) );
1299 // Check the rest of the deleted archives too.
1300 // (these are the ones that don't show in the image history)
1302 $useCount = $this->dbw
->selectField( 'filearchive', '1',
1303 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1304 __METHOD__
, array( 'FOR UPDATE' ) );
1307 if( $useCount == 0 ) {
1308 wfDebug( __METHOD__
.": nothing else using {$oimage->sha1}, will deleting after\n" );
1309 $flags = FileStore
::DELETE_ORIGINAL
;
1313 $transaction->add( $store->export( $key, $destPath, $flags ) );
1315 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1316 $transaction->commit();
1317 FileStore
::unlock();
1319 $m = explode('!',$oimage->archive_name
,2);
1326 * Update the revision's rev_deleted field
1327 * @param Revision $rev
1328 * @param int $bitfield new rev_deleted bitfield value
1330 function updateRevision( $rev, $bitfield ) {
1331 $this->dbw
->update( 'revision',
1332 array( 'rev_deleted' => $bitfield ),
1333 array( 'rev_id' => $rev->getId(),
1334 'rev_page' => $rev->getPage() ),
1339 * Update the revision's rev_deleted field
1340 * @param Revision $rev
1341 * @param Title $title
1342 * @param int $bitfield new rev_deleted bitfield value
1344 function updateArchive( $rev, $title, $bitfield ) {
1345 $this->dbw
->update( 'archive',
1346 array( 'ar_deleted' => $bitfield ),
1347 array( 'ar_namespace' => $title->getNamespace(),
1348 'ar_title' => $title->getDBKey(),
1349 'ar_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ),
1350 'ar_rev_id' => $rev->getId() ),
1355 * Update the images's oi_deleted field
1357 * @param int $bitfield new rev_deleted bitfield value
1359 function updateOldFiles( $file, $bitfield ) {
1360 $this->dbw
->update( 'oldimage',
1361 array( 'oi_deleted' => $bitfield ),
1362 array( 'oi_name' => $file->getName(),
1363 'oi_timestamp' => $this->dbw
->timestamp( $file->getTimestamp() ) ),
1368 * Update the images's fa_deleted field
1369 * @param ArchivedFile $file
1370 * @param int $bitfield new rev_deleted bitfield value
1372 function updateArchFiles( $file, $bitfield ) {
1373 $this->dbw
->update( 'filearchive',
1374 array( 'fa_deleted' => $bitfield ),
1375 array( 'fa_id' => $file->getId() ),
1380 * Update the logging log_deleted field
1382 * @param int $bitfield new rev_deleted bitfield value
1384 function updateLogs( $row, $bitfield ) {
1385 $this->dbw
->update( 'logging',
1386 array( 'log_deleted' => $bitfield ),
1387 array( 'log_id' => $row->log_id
),
1392 * Update the revision's recentchanges record if fields have been hidden
1393 * @param Revision $rev
1394 * @param int $bitfield new rev_deleted bitfield value
1396 function updateRecentChangesEdits( $rev, $bitfield ) {
1397 $this->dbw
->update( 'recentchanges',
1398 array( 'rc_deleted' => $bitfield,
1399 'rc_patrolled' => 1 ),
1400 array( 'rc_this_oldid' => $rev->getId(),
1401 'rc_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ) ),
1406 * Update the revision's recentchanges record if fields have been hidden
1408 * @param int $bitfield new rev_deleted bitfield value
1410 function updateRecentChangesLog( $row, $bitfield ) {
1411 $this->dbw
->update( 'recentchanges',
1412 array( 'rc_deleted' => $bitfield,
1413 'rc_patrolled' => 1 ),
1414 array( 'rc_logid' => $row->log_id
,
1415 'rc_timestamp' => $row->log_timestamp
),
1420 * Touch the page's cache invalidation timestamp; this forces cached
1421 * history views to refresh, so any newly hidden or shown fields will
1423 * @param Title $title
1425 function updatePage( $title ) {
1426 $title->invalidateCache();
1427 $title->purgeSquid();
1428 $title->touchLinks();
1429 // Extensions that require referencing previous revisions may need this
1430 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1434 * Checks for a change in the bitfield for a certain option and updates the
1435 * provided array accordingly.
1437 * @param String $desc Description to add to the array if the option was
1438 * enabled / disabled.
1439 * @param int $field The bitmask describing the single option.
1440 * @param int $diff The xor of the old and new bitfields.
1441 * @param array $arr The array to update.
1443 function checkItem ( $desc, $field, $diff, $new, &$arr ) {
1444 if ( $diff & $field ) {
1445 $arr [ ( $new & $field ) ?
0 : 1 ][] = $desc;
1450 * Gets an array describing the changes made to the visibilit of the revision.
1451 * If the resulting array is $arr, then $arr[0] will contain an array of strings
1452 * describing the items that were hidden, $arr[2] will contain an array of strings
1453 * describing the items that were unhidden, and $arr[3] will contain an array with
1454 * a single string, which can be one of "applied restrictions to sysops",
1455 * "removed restrictions from sysops", or null.
1457 * @param int $n The new bitfield.
1458 * @param int $o The old bitfield.
1459 * @return An array as described above.
1461 function getChanges ( $n, $o ) {
1463 $ret = array ( 0 => array(), 1 => array(), 2 => array() );
1465 $this->checkItem ( wfMsgForContent ( 'revdelete-content' ),
1466 Revision
::DELETED_TEXT
, $diff, $n, $ret );
1467 $this->checkItem ( wfMsgForContent ( 'revdelete-summary' ),
1468 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
1469 $this->checkItem ( wfMsgForContent ( 'revdelete-uname' ),
1470 Revision
::DELETED_USER
, $diff, $n, $ret );
1472 // Restriction application to sysops
1473 if ( $diff & Revision
::DELETED_RESTRICTED
) {
1474 if ( $n & Revision
::DELETED_RESTRICTED
)
1475 $ret[2][] = wfMsgForContent ( 'revdelete-restricted' );
1477 $ret[2][] = wfMsgForContent ( 'revdelete-unrestricted' );
1484 * Gets a log message to describe the given revision visibility change. This
1485 * message will be of the form "[hid {content, edit summary, username}];
1486 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
1488 * @param int $count The number of effected revisions.
1489 * @param int $nbitfield The new bitfield for the revision.
1490 * @param int $obitfield The old bitfield for the revision.
1491 * @param string $comment The comment associated with the change.
1492 * @param bool $isForLog
1494 function getLogMessage ( $count, $nbitfield, $obitfield, $comment, $isForLog = false ) {
1498 $changes = $this->getChanges( $nbitfield, $obitfield );
1500 if ( count ( $changes[0] ) ) {
1501 $s .= wfMsgForContent ( 'revdelete-hid', implode ( ', ', $changes[0] ) );
1504 if ( count ( $changes[1] ) ) {
1507 $s .= wfMsgForContent ( 'revdelete-unhid', implode ( ', ', $changes[1] ) );
1510 if ( count ( $changes[2] )) {
1512 $s .= ' (' . $changes[2][0] . ')';
1514 $s = $changes[2][0];
1517 $msg = $isForLog ?
'logdelete-log-message' : 'revdelete-log-message';
1518 $ret = wfMsgExt ( $msg, array( 'parsemag', 'content' ),
1519 $s, $wgContLang->formatNum( $count ) );
1522 $ret .= ": $comment";
1529 * Record a log entry on the action
1530 * @param Title $title, page where item was removed from
1531 * @param int $count the number of revisions altered for this page
1532 * @param int $nbitfield the new _deleted value
1533 * @param int $obitfield the old _deleted value
1534 * @param string $comment
1535 * @param Title $target, the relevant page
1536 * @param string $param, URL param
1537 * @param Array $items
1539 function updateLog( $title, $count, $nbitfield, $obitfield, $comment,
1540 $target, $param, $items = array() )
1542 // Put things hidden from sysops in the oversight log
1543 $logtype = ( ($nbitfield |
$obitfield) & Revision
::DELETED_RESTRICTED
) ?
'suppress' : 'delete';
1544 $log = new LogPage( $logtype );
1546 $reason = $this->getLogMessage( $count, $nbitfield, $obitfield, $comment, $param == 'logid' );
1548 if( $param == 'logid' ) {
1549 $params = array( implode( ',', $items) );
1550 $log->addEntry( 'event', $title, $reason, $params );
1552 // Add params for effected page and ids
1553 $params = array( $param, implode( ',', $items) );
1554 $log->addEntry( 'revision', $title, $reason, $params );