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();
30 $this->outputHeader();
31 $this->wasPosted
= $wgRequest->wasPosted();
32 # Handle our many different possible input types
33 $this->target
= $wgRequest->getText( 'target' );
34 $this->oldids
= $wgRequest->getArray( 'oldid' );
35 $this->artimestamps
= $wgRequest->getArray( 'artimestamp' );
36 $this->logids
= $wgRequest->getArray( 'logid' );
37 $this->oldimgs
= $wgRequest->getArray( 'oldimage' );
38 $this->fileids
= $wgRequest->getArray( 'fileid' );
39 # For reviewing deleted files...
40 $this->file
= $wgRequest->getVal( 'file' );
41 # Only one target set at a time please!
42 $i = (bool)$this->file +
(bool)$this->oldids +
(bool)$this->logids
43 +
(bool)$this->artimestamps +
(bool)$this->fileids +
(bool)$this->oldimgs
;
45 $wgOut->showErrorPage( 'revdelete-toomanytargets-title', 'revdelete-toomanytargets-text' );
48 $this->page
= Title
::newFromUrl( $this->target
);
49 # If this is just one revision, get the title from it.
50 # This allows for more flexibility with page moves...
51 if( count($this->oldids
) === 1 ) {
52 $rev = Revision
::newFromId( $this->oldids
[0] );
53 $this->page
= $rev ?
$rev->getTitle() : $this->page
;
55 # We need a target page!
56 if( is_null($this->page
) ) {
57 $wgOut->addWikiMsg( 'undelete-header' );
60 # Logs must have a type given
61 if( $this->logids
&& !strpos($this->page
->getDBKey(),'/') ) {
62 $wgOut->showErrorPage( 'revdelete-nologtype-title', 'revdelete-nologtype-text' );
65 # Check edit token on submission
66 if( $this->wasPosted
&& !$wgUser->matchEditToken( $wgRequest->getVal('wpEditToken') ) ) {
67 $wgOut->addWikiMsg( 'sessionfailure' );
70 # For reviewing deleted files...show it now if allowed
72 $oimage = RepoGroup
::singleton()->getLocalRepo()->newFromArchiveName( $this->page
, $this->file
);
74 // Check if user is allowed to see this file
75 if( !$oimage->userCan(File
::DELETED_FILE
) ) {
76 $wgOut->permissionRequired( 'suppressrevision' );
78 $this->showFile( $this->file
);
82 # Give a link to the logs/hist for this page
83 if( !is_null($this->page
) && $this->page
->getNamespace() > -1 ) {
86 $logtitle = SpecialPage
::getTitleFor( 'Log' );
87 $links[] = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
88 wfArrayToCGI( array( 'page' => $this->page
->getPrefixedUrl() ) ) );
89 # Give a link to the page history
90 $links[] = $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml( 'pagehist' ),
91 wfArrayToCGI( array( 'action' => 'history' ) ) );
92 # Link to deleted edits
93 if( $wgUser->isAllowed('undelete') ) {
94 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
95 $links[] = $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
96 wfArrayToCGI( array( 'target' => $this->page
->getPrefixedDBkey() ) ) );
98 # Logs themselves don't have histories or archived revisions
99 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
101 # Lock the operation and the form context
102 $this->secureOperation();
103 # Either submit or create our form
104 if( $this->wasPosted
) {
105 $this->submit( $wgRequest );
106 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
108 } else if( $this->deleteKey
== 'fileid' ||
$this->deleteKey
== 'oldimage' ) {
110 } else if( $this->deleteKey
== 'logid' ) {
111 $this->showLogItems();
113 # Show relevant lines from the deletion log. This will show even if said ID
114 # does not exist...might be helpful
115 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'delete' ) ) . "</h2>\n" );
116 LogEventsList
::showLogExtract( $wgOut, 'delete', $this->page
->getPrefixedText() );
117 if( $wgUser->isAllowed( 'suppressionlog' ) ){
118 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'suppress' ) ) . "</h2>\n" );
119 LogEventsList
::showLogExtract( $wgOut, 'suppress', $this->page
->getPrefixedText() );
123 private function secureOperation() {
125 $this->deleteKey
= '';
126 // At this point, we should only have one of these
127 if( $this->oldids
) {
128 $this->revisions
= $this->oldids
;
129 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
130 $this->deleteKey
= 'oldid';
131 } else if( $this->artimestamps
) {
132 $this->archrevs
= $this->artimestamps
;
133 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
134 $this->deleteKey
= 'artimestamp';
135 } else if( $this->oldimgs
) {
136 $this->ofiles
= $this->oldimgs
;
137 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
138 $this->deleteKey
= 'oldimage';
139 } else if( $this->fileids
) {
140 $this->afiles
= $this->fileids
;
141 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
142 $this->deleteKey
= 'fileid';
143 } else if( $this->logids
) {
144 $this->events
= $this->logids
;
145 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage
::DELETED_ACTION
);
146 $this->deleteKey
= 'logid';
148 // Our checkbox messages depends one what we are doing,
149 // e.g. we don't hide "text" for logs or images
150 $this->checks
= array(
152 array( 'revdelete-hide-comment', 'wpHideComment', Revision
::DELETED_COMMENT
),
153 array( 'revdelete-hide-user', 'wpHideUser', Revision
::DELETED_USER
)
155 if( $wgUser->isAllowed('suppressrevision') ) {
156 $this->checks
[] = array( 'revdelete-hide-restricted', 'wpHideRestricted', Revision
::DELETED_RESTRICTED
);
161 * Show a deleted file version requested by the visitor.
163 private function showFile( $key ) {
164 global $wgOut, $wgRequest;
167 # We mustn't allow the output to be Squid cached, otherwise
168 # if an admin previews a deleted image, and it's cached, then
169 # a user without appropriate permissions can toddle off and
170 # nab the image, and Squid will serve it
171 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
172 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
173 $wgRequest->response()->header( 'Pragma: no-cache' );
175 $store = FileStore
::get( 'deleted' );
176 $store->stream( $key );
180 * This lets a user set restrictions for live and archived revisions
182 private function showRevs() {
183 global $wgOut, $wgUser;
186 $count = ($this->deleteKey
=='oldid') ?
187 count($this->revisions
) : count($this->archrevs
);
188 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(), $count );
191 $wgOut->addHTML( "<ul>" );
193 $where = $revObjs = array();
194 $dbr = wfGetDB( DB_MASTER
);
198 if( $this->deleteKey
=='oldid' ) {
199 // Run through and pull all our data in one query
200 foreach( $this->revisions
as $revid ) {
201 $where[] = intval($revid);
203 $result = $dbr->select( array('revision','page'), '*',
205 'rev_page' => $this->page
->getArticleID(),
207 'rev_page = page_id' ),
209 while( $row = $dbr->fetchObject( $result ) ) {
210 $revObjs[$row->rev_id
] = new Revision( $row );
212 foreach( $this->revisions
as $revid ) {
213 // Hiding top revisison is bad
214 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
216 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
217 // If a rev is hidden from sysops
218 if( !$this->wasPosted
) {
219 $wgOut->permissionRequired( 'suppressrevision' );
222 $UserAllowed = false;
225 $wgOut->addHTML( $this->historyLine( $revObjs[$revid] ) );
226 $bitfields |
= $revObjs[$revid]->mDeleted
;
230 // Run through and pull all our data in one query
231 foreach( $this->archrevs
as $timestamp ) {
232 $where[] = $dbr->timestamp( $timestamp );
234 $result = $dbr->select( 'archive', '*',
236 'ar_namespace' => $this->page
->getNamespace(),
237 'ar_title' => $this->page
->getDBKey(),
238 'ar_timestamp' => $where ),
240 while( $row = $dbr->fetchObject( $result ) ) {
241 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
242 $revObjs[$timestamp] = new Revision( array(
243 'page' => $this->page
->getArticleId(),
244 'id' => $row->ar_rev_id
,
245 'text' => $row->ar_text_id
,
246 'comment' => $row->ar_comment
,
247 'user' => $row->ar_user
,
248 'user_text' => $row->ar_user_text
,
249 'timestamp' => $timestamp,
250 'minor_edit' => $row->ar_minor_edit
,
251 'text_id' => $row->ar_text_id
,
252 'deleted' => $row->ar_deleted
,
253 'len' => $row->ar_len
) );
255 foreach( $this->archrevs
as $timestamp ) {
256 if( !isset($revObjs[$timestamp]) ) {
258 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
259 // If a rev is hidden from sysops
260 if( !$this->wasPosted
) {
261 $wgOut->permissionRequired( 'suppressrevision' );
264 $UserAllowed = false;
267 $wgOut->addHTML( $this->historyLine( $revObjs[$timestamp] ) );
268 $bitfields |
= $revObjs[$timestamp]->mDeleted
;
272 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
276 $wgOut->addHTML( "</ul>" );
278 $this->addUsageText();
280 // Normal sysops can always see what they did, but can't always change it
281 if( !$UserAllowed ) return;
284 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
285 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
288 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
289 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
290 Xml
::hidden( 'type', $this->deleteKey
)
292 if( $this->deleteKey
=='oldid' ) {
293 foreach( $revObjs as $rev )
294 $hidden[] = Xml
::hidden( 'oldid[]', $rev->getId() );
296 foreach( $revObjs as $rev )
297 $hidden[] = Xml
::hidden( 'artimestamp[]', $rev->getTimestamp() );
299 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
301 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
302 'id' => 'mw-revdel-form-revisions' ) ) .
303 Xml
::openElement( 'fieldset' ) .
304 xml
::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
307 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
308 foreach( $items as $item ) {
309 $wgOut->addHTML( Xml
::tags( 'p', null, $item ) );
311 foreach( $hidden as $item ) {
312 $wgOut->addHTML( $item );
315 Xml
::closeElement( 'fieldset' ) .
316 Xml
::closeElement( 'form' ) . "\n"
321 * This lets a user set restrictions for archived images
323 private function showImages() {
324 global $wgOut, $wgUser, $wgLang;
327 $count = ($this->deleteKey
=='oldimage') ?
count($this->ofiles
) : count($this->afiles
);
328 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(),
329 $wgLang->formatNum($count) );
332 $wgOut->addHTML( "<ul>" );
334 $where = $filesObjs = array();
335 $dbr = wfGetDB( DB_MASTER
);
336 // Live old revisions...
338 if( $this->deleteKey
=='oldimage' ) {
339 // Run through and pull all our data in one query
340 foreach( $this->ofiles
as $timestamp ) {
341 $where[] = $timestamp.'!'.$this->page
->getDBKey();
343 $result = $dbr->select( 'oldimage', '*',
345 'oi_name' => $this->page
->getDBKey(),
346 'oi_archive_name' => $where ),
348 while( $row = $dbr->fetchObject( $result ) ) {
349 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
350 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
351 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
353 // Check through our images
354 foreach( $this->ofiles
as $timestamp ) {
355 $archivename = $timestamp.'!'.$this->page
->getDBKey();
356 if( !isset($filesObjs[$archivename]) ) {
358 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
359 // If a rev is hidden from sysops
360 if( !$this->wasPosted
) {
361 $wgOut->permissionRequired( 'suppressrevision' );
364 $UserAllowed = false;
367 // Inject history info
368 $wgOut->addHTML( $this->fileLine( $filesObjs[$archivename] ) );
369 $bitfields |
= $filesObjs[$archivename]->deleted
;
373 // Run through and pull all our data in one query
374 foreach( $this->afiles
as $id ) {
375 $where[] = intval($id);
377 $result = $dbr->select( 'filearchive', '*',
379 'fa_name' => $this->page
->getDBKey(),
382 while( $row = $dbr->fetchObject( $result ) ) {
383 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
386 foreach( $this->afiles
as $fileid ) {
387 if( !isset($filesObjs[$fileid]) ) {
389 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
390 // If a rev is hidden from sysops
391 if( !$this->wasPosted
) {
392 $wgOut->permissionRequired( 'suppressrevision' );
395 $UserAllowed = false;
398 // Inject history info
399 $wgOut->addHTML( $this->archivedfileLine( $filesObjs[$fileid] ) );
400 $bitfields |
= $filesObjs[$fileid]->deleted
;
404 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
408 $wgOut->addHTML( "</ul>" );
410 $this->addUsageText();
411 // Normal sysops can always see what they did, but can't always change it
412 if( !$UserAllowed ) return;
415 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
416 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
419 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
420 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
421 Xml
::hidden( 'type', $this->deleteKey
)
423 if( $this->deleteKey
=='oldimage' ) {
424 foreach( $this->ofiles
as $filename )
425 $hidden[] = Xml
::hidden( 'oldimage[]', $filename );
427 foreach( $this->afiles
as $fileid )
428 $hidden[] = Xml
::hidden( 'fileid[]', $fileid );
430 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
432 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
433 'id' => 'mw-revdel-form-filerevisions' ) ) .
434 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
437 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
438 foreach( $items as $item ) {
439 $wgOut->addHTML( "<p>$item</p>" );
441 foreach( $hidden as $item ) {
442 $wgOut->addHTML( $item );
446 Xml
::closeElement( 'fieldset' ) .
447 Xml
::closeElement( 'form' ) . "\n"
452 * This lets a user set restrictions for log items
454 private function showLogItems() {
455 global $wgOut, $wgUser, $wgMessageCache, $wgLang;
458 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->events
) ) );
461 $wgOut->addHTML( "<ul>" );
463 $where = $logRows = array();
464 $dbr = wfGetDB( DB_MASTER
);
465 // Run through and pull all our data in one query
467 foreach( $this->events
as $logid ) {
468 $where[] = intval($logid);
470 list($log,$logtype) = explode( '/',$this->page
->getDBKey(), 2 );
471 $result = $dbr->select( 'logging', '*',
473 'log_type' => $logtype,
474 'log_id' => $where ),
476 while( $row = $dbr->fetchObject( $result ) ) {
477 $logRows[$row->log_id
] = $row;
479 $wgMessageCache->loadAllMessages();
480 foreach( $this->events
as $logid ) {
481 // Don't hide from oversight log!!!
482 if( !isset( $logRows[$logid] ) ||
$logRows[$logid]->log_type
=='suppress' ) {
484 } else if( !LogEventsList
::userCan( $logRows[$logid],Revision
::DELETED_RESTRICTED
) ) {
485 // If an event is hidden from sysops
486 if( !$this->wasPosted
) {
487 $wgOut->permissionRequired( 'suppressrevision' );
490 $UserAllowed = false;
493 $wgOut->addHTML( $this->logLine( $logRows[$logid] ) );
494 $bitfields |
= $logRows[$logid]->log_deleted
;
497 $wgOut->showErrorPage( 'revdelete-nologid-title', 'revdelete-nologid-text' );
501 $wgOut->addHTML( "</ul>" );
503 $this->addUsageText();
504 // Normal sysops can always see what they did, but can't always change it
505 if( !$UserAllowed ) return;
508 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
509 Xml
::submitButton( wfMsg( 'revdelete-submit' ) ) );
511 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
512 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
513 Xml
::hidden( 'type', $this->deleteKey
) );
514 foreach( $this->events
as $logid ) {
515 $hidden[] = Xml
::hidden( 'logid[]', $logid );
518 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
520 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
521 'id' => 'mw-revdel-form-logs' ) ) .
522 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
525 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
526 foreach( $items as $item ) {
527 $wgOut->addHTML( "<p>$item</p>" );
529 foreach( $hidden as $item ) {
530 $wgOut->addHTML( $item );
534 Xml
::closeElement( 'fieldset' ) .
535 Xml
::closeElement( 'form' ) . "\n"
539 private function addUsageText() {
540 global $wgOut, $wgUser;
541 $wgOut->addWikiMsg( 'revdelete-text' );
542 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
543 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
548 * @param int $bitfields, aggregate bitfield of all the bitfields
549 * @returns string HTML
551 private function buildCheckBoxes( $bitfields ) {
553 // FIXME: all items checked for just one rev are checked, even if not set for the others
554 foreach( $this->checks
as $item ) {
555 list( $message, $name, $field ) = $item;
556 $line = Xml
::tags( 'div', null, Xml
::checkLabel( wfMsg($message), $name, $name,
557 $bitfields & $field ) );
558 if( $field == Revision
::DELETED_RESTRICTED
) $line = "<b>$line</b>";
565 * @param Revision $rev
568 private function historyLine( $rev ) {
569 global $wgLang, $wgUser;
571 $date = $wgLang->timeanddate( $rev->getTimestamp() );
572 $difflink = $del = '';
574 if( $this->deleteKey
=='oldid' ) {
575 $tokenParams = '&unhide=1&token='.urlencode( $wgUser->editToken( $rev->getId() ) );
576 $revlink = $this->skin
->makeLinkObj( $this->page
, $date, 'oldid='.$rev->getId() . $tokenParams );
577 $difflink = '(' . $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml('diff'),
578 'diff=' . $rev->getId() . '&oldid=prev' . $tokenParams ) . ')';
579 // Archived revisions
581 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
582 $target = $this->page
->getPrefixedText();
583 $revlink = $this->skin
->makeLinkObj( $undelete, $date,
584 "target=$target×tamp=" . $rev->getTimestamp() );
585 $difflink = '(' . $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml('diff'),
586 "target=$target&diff=prev×tamp=" . $rev->getTimestamp() ) . ')';
588 // Check permissions; items may be "suppressed"
589 if( $rev->isDeleted(Revision
::DELETED_TEXT
) ) {
590 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
591 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
592 if( !$rev->userCan(Revision
::DELETED_TEXT
) ) {
593 $revlink = '<span class="history-deleted">'.$date.'</span>';
594 $difflink = '(' . wfMsgHtml('diff') . ')';
597 $userlink = $this->skin
->revUserLink( $rev );
598 $comment = $this->skin
->revComment( $rev );
600 return "<li>$difflink $revlink $userlink $comment{$del}</li>";
607 private function fileLine( $file ) {
608 global $wgLang, $wgTitle;
610 $target = $this->page
->getPrefixedText();
611 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
615 if( $file->isDeleted(File
::DELETED_FILE
) ) {
616 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
617 if( !$file->userCan(File
::DELETED_FILE
) ) {
620 $pageLink = $this->skin
->makeKnownLinkObj( $wgTitle, $date,
621 "target=$target&file=$file->sha1.".$file->getExtension() );
623 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
626 $url = $file->getUrlRel();
627 $pageLink = "<a href=\"{$url}\">{$date}</a>";
630 $data = wfMsg( 'widthheight',
631 $wgLang->formatNum( $file->getWidth() ),
632 $wgLang->formatNum( $file->getHeight() ) ) .
633 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
634 $data = htmlspecialchars( $data );
636 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
640 * @param ArchivedFile $file
643 private function archivedfileLine( $file ) {
646 $target = $this->page
->getPrefixedText();
647 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
649 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
650 $pageLink = $this->skin
->makeKnownLinkObj( $undelete, $date, "target=$target&file={$file->getKey()}" );
653 if( $file->isDeleted(File
::DELETED_FILE
) ) {
654 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
657 $data = wfMsg( 'widthheight',
658 $wgLang->formatNum( $file->getWidth() ),
659 $wgLang->formatNum( $file->getHeight() ) ) .
660 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
661 $data = htmlspecialchars( $data );
663 return "<li> $pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
667 * @param Array $row row
670 private function logLine( $row ) {
673 $date = $wgLang->timeanddate( $row->log_timestamp
);
674 $paramArray = LogPage
::extractParams( $row->log_params
);
675 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
677 $logtitle = SpecialPage
::getTitleFor( 'Log' );
678 $loglink = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
679 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
681 if( !LogEventsList
::userCan($row,LogPage
::DELETED_ACTION
) ) {
682 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
684 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
685 $this->skin
, $paramArray, true, true );
686 if( $row->log_deleted
& LogPage
::DELETED_ACTION
)
687 $action = '<span class="history-deleted">' . $action . '</span>';
690 $userLink = $this->skin
->userLink( $row->log_user
, User
::WhoIs($row->log_user
) );
691 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_USER
) ) {
692 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
695 $comment = $wgLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
696 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
697 $comment = '<span class="history-deleted">' . $comment . '</span>';
699 return "<li>($loglink) $date $userLink $action $comment</li>";
703 * Generate a user tool link cluster if the current user is allowed to view it
704 * @param ArchivedFile $file
705 * @return string HTML
707 private function fileUserTools( $file ) {
708 if( $file->userCan( Revision
::DELETED_USER
) ) {
709 $link = $this->skin
->userLink( $file->user
, $file->user_text
) .
710 $this->skin
->userToolLinks( $file->user
, $file->user_text
);
712 $link = wfMsgHtml( 'rev-deleted-user' );
714 if( $file->isDeleted( Revision
::DELETED_USER
) ) {
715 return '<span class="history-deleted">' . $link . '</span>';
721 * Wrap and format the given file's comment block, if the current
722 * user is allowed to view it.
724 * @param ArchivedFile $file
725 * @return string HTML
727 private function fileComment( $file ) {
728 if( $file->userCan( File
::DELETED_COMMENT
) ) {
729 $block = $this->skin
->commentBlock( $file->description
);
731 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
733 if( $file->isDeleted( File
::DELETED_COMMENT
) ) {
734 return "<span class=\"history-deleted\">$block</span>";
740 * @param WebRequest $request
742 private function submit( $request ) {
743 global $wgUser, $wgOut;
745 $bitfield = $this->extractBitfield( $request );
746 $comment = $request->getText( 'wpReason' );
747 # Can the user set this field?
748 if( $bitfield & Revision
::DELETED_RESTRICTED
&& !$wgUser->isAllowed('suppressrevision') ) {
749 $wgOut->permissionRequired( 'suppressrevision' );
752 # If the save went through, go to success message. Otherwise
753 # bounce back to form...
754 if( $this->save( $bitfield, $comment, $this->page
) ) {
756 } else if( $request->getCheck( 'oldid' ) ||
$request->getCheck( 'artimestamp' ) ) {
757 return $this->showRevs();
758 } else if( $request->getCheck( 'logid' ) ) {
759 return $this->showLogs();
760 } else if( $request->getCheck( 'oldimage' ) ||
$request->getCheck( 'fileid' ) ) {
761 return $this->showImages();
765 private function success() {
768 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
770 $wrap = '<span class="success">$1</span>';
772 if( $this->deleteKey
=='logid' ) {
773 $wgOut->wrapWikiMsg( $wrap, 'logdelete-success' );
774 $this->showLogItems();
775 } else if( $this->deleteKey
=='oldid' ||
$this->deleteKey
=='artimestamp' ) {
776 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
778 } else if( $this->deleteKey
=='fileid' ) {
779 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
781 } else if( $this->deleteKey
=='oldimage' ) {
782 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
788 * Put together a rev_deleted bitfield from the submitted checkboxes
789 * @param WebRequest $request
792 private function extractBitfield( $request ) {
794 foreach( $this->checks
as $item ) {
795 list( /* message */ , $name, $field ) = $item;
796 if( $request->getCheck( $name ) ) {
803 private function save( $bitfield, $reason, $title ) {
804 $dbw = wfGetDB( DB_MASTER
);
805 // Don't allow simply locking the interface for no reason
806 if( $bitfield == Revision
::DELETED_RESTRICTED
) {
809 $deleter = new RevisionDeleter( $dbw );
810 // By this point, only one of the below should be set
811 if( isset($this->revisions
) ) {
812 return $deleter->setRevVisibility( $title, $this->revisions
, $bitfield, $reason );
813 } else if( isset($this->archrevs
) ) {
814 return $deleter->setArchiveVisibility( $title, $this->archrevs
, $bitfield, $reason );
815 } else if( isset($this->ofiles
) ) {
816 return $deleter->setOldImgVisibility( $title, $this->ofiles
, $bitfield, $reason );
817 } else if( isset($this->afiles
) ) {
818 return $deleter->setArchFileVisibility( $title, $this->afiles
, $bitfield, $reason );
819 } else if( isset($this->events
) ) {
820 return $deleter->setEventVisibility( $title, $this->events
, $bitfield, $reason );
826 * Implements the actions for Revision Deletion.
827 * @ingroup SpecialPage
829 class RevisionDeleter
{
830 function __construct( $db ) {
835 * @param $title, the page these events apply to
836 * @param array $items list of revision ID numbers
837 * @param int $bitfield new rev_deleted value
838 * @param string $comment Comment for log records
840 function setRevVisibility( $title, $items, $bitfield, $comment ) {
843 $userAllowedAll = $success = true;
846 // Run through and pull all our data in one query
847 foreach( $items as $revid ) {
848 $where[] = intval($revid);
850 $result = $this->dbw
->select( 'revision', '*',
852 'rev_page' => $title->getArticleID(),
853 'rev_id' => $where ),
855 while( $row = $this->dbw
->fetchObject( $result ) ) {
856 $revObjs[$row->rev_id
] = new Revision( $row );
859 foreach( $items as $revid ) {
860 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
862 continue; // Must exist
863 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
864 $userAllowedAll=false;
867 // For logging, maintain a count of revisions
868 if( $revObjs[$revid]->mDeleted
!= $bitfield ) {
872 $this->updateRevision( $revObjs[$revid], $bitfield );
873 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
877 // Don't log or touch if nothing changed
878 if( $revCount > 0 ) {
879 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted
,
880 $comment, $title, 'oldid', $revIDs );
881 $this->updatePage( $title );
883 // Where all revs allowed to be set?
884 if( !$userAllowedAll ) {
885 //FIXME: still might be confusing???
886 $wgOut->permissionRequired( 'suppressrevision' );
894 * @param $title, the page these events apply to
895 * @param array $items list of revision ID numbers
896 * @param int $bitfield new rev_deleted value
897 * @param string $comment Comment for log records
899 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
902 $userAllowedAll = $success = true;
905 // Run through and pull all our data in one query
906 foreach( $items as $timestamp ) {
907 $where[] = $this->dbw
->timestamp( $timestamp );
909 $result = $this->dbw
->select( 'archive', '*',
911 'ar_namespace' => $title->getNamespace(),
912 'ar_title' => $title->getDBKey(),
913 'ar_timestamp' => $where ),
915 while( $row = $this->dbw
->fetchObject( $result ) ) {
916 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
917 $revObjs[$timestamp] = new Revision( array(
918 'page' => $title->getArticleId(),
919 'id' => $row->ar_rev_id
,
920 'text' => $row->ar_text_id
,
921 'comment' => $row->ar_comment
,
922 'user' => $row->ar_user
,
923 'user_text' => $row->ar_user_text
,
924 'timestamp' => $timestamp,
925 'minor_edit' => $row->ar_minor_edit
,
926 'text_id' => $row->ar_text_id
,
927 'deleted' => $row->ar_deleted
,
928 'len' => $row->ar_len
) );
931 foreach( $items as $timestamp ) {
932 // This will only select the first revision with this timestamp.
933 // Since they are all selected/deleted at once, we can just check the
934 // permissions of one. UPDATE is done via timestamp, so all revs are set.
935 if( !is_object($revObjs[$timestamp]) ) {
937 continue; // Must exist
938 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
939 $userAllowedAll=false;
942 // Which revisions did we change anything about?
943 if( $revObjs[$timestamp]->mDeleted
!= $bitfield ) {
944 $Id_set[]=$timestamp;
947 $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
950 // For logging, maintain a count of revisions
952 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted
,
953 $comment, $title, 'artimestamp', $Id_set );
955 // Where all revs allowed to be set?
956 if( !$userAllowedAll ) {
957 $wgOut->permissionRequired( 'suppressrevision' );
965 * @param $title, the page these events apply to
966 * @param array $items list of revision ID numbers
967 * @param int $bitfield new rev_deleted value
968 * @param string $comment Comment for log records
970 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
973 $userAllowedAll = $success = true;
976 // Run through and pull all our data in one query
977 foreach( $items as $timestamp ) {
978 $where[] = $timestamp.'!'.$title->getDBKey();
980 $result = $this->dbw
->select( 'oldimage', '*',
982 'oi_name' => $title->getDBKey(),
983 'oi_archive_name' => $where ),
985 while( $row = $this->dbw
->fetchObject( $result ) ) {
986 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
987 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
988 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
991 foreach( $items as $timestamp ) {
992 $archivename = $timestamp.'!'.$title->getDBKey();
993 if( !isset($filesObjs[$archivename]) ) {
995 continue; // Must exist
996 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
997 $userAllowedAll=false;
1001 $transaction = true;
1002 // Which revisions did we change anything about?
1003 if( $filesObjs[$archivename]->deleted
!= $bitfield ) {
1006 $this->dbw
->begin();
1007 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
1008 // If this image is currently hidden...
1009 if( $filesObjs[$archivename]->deleted
& File
::DELETED_FILE
) {
1010 if( $bitfield & File
::DELETED_FILE
) {
1011 # Leave it alone if we are not changing this...
1012 $set[]=$archivename;
1013 $transaction = true;
1015 # We are moving this out
1016 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
1017 $set[]=$transaction;
1019 // Is it just now becoming hidden?
1020 } else if( $bitfield & File
::DELETED_FILE
) {
1021 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
1022 $set[]=$transaction;
1026 // If our file operations fail, then revert back the db
1027 if( $transaction==false ) {
1028 $this->dbw
->rollback();
1031 $this->dbw
->commit();
1035 // Log if something was changed
1037 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted
,
1038 $comment, $title, 'oldimage', $set );
1039 # Purge page/history
1040 $file = wfLocalFile( $title );
1041 $file->purgeCache();
1042 $file->purgeHistory();
1043 # Invalidate cache for all pages using this file
1044 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
1045 $update->doUpdate();
1047 // Where all revs allowed to be set?
1048 if( !$userAllowedAll ) {
1049 $wgOut->permissionRequired( 'suppressrevision' );
1057 * @param $title, the page these events apply to
1058 * @param array $items list of revision ID numbers
1059 * @param int $bitfield new rev_deleted value
1060 * @param string $comment Comment for log records
1062 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
1065 $userAllowedAll = $success = true;
1069 // Run through and pull all our data in one query
1070 foreach( $items as $id ) {
1071 $where[] = intval($id);
1073 $result = $this->dbw
->select( 'filearchive', '*',
1074 array( 'fa_name' => $title->getDBKey(),
1075 'fa_id' => $where ),
1077 while( $row = $this->dbw
->fetchObject( $result ) ) {
1078 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
1081 foreach( $items as $fileid ) {
1082 if( !isset($filesObjs[$fileid]) ) {
1084 continue; // Must exist
1085 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
1086 $userAllowedAll=false;
1089 // Which revisions did we change anything about?
1090 if( $filesObjs[$fileid]->deleted
!= $bitfield ) {
1094 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1097 // Log if something was changed
1099 $this->updateLog( $title, $count, $bitfield, $comment,
1100 $filesObjs[$fileid]->deleted
, $title, 'fileid', $Id_set );
1102 // Where all revs allowed to be set?
1103 if( !$userAllowedAll ) {
1104 $wgOut->permissionRequired( 'suppressrevision' );
1112 * @param $title, the log page these events apply to
1113 * @param array $items list of log ID numbers
1114 * @param int $bitfield new log_deleted value
1115 * @param string $comment Comment for log records
1117 function setEventVisibility( $title, $items, $bitfield, $comment ) {
1120 $userAllowedAll = $success = true;
1124 // Run through and pull all our data in one query
1125 foreach( $items as $logid ) {
1126 $where[] = intval($logid);
1128 list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
1129 $result = $this->dbw
->select( 'logging', '*',
1131 'log_type' => $logtype,
1132 'log_id' => $where ),
1134 while( $row = $this->dbw
->fetchObject( $result ) ) {
1135 $logRows[$row->log_id
] = $row;
1138 foreach( $items as $logid ) {
1139 if( !isset($logRows[$logid]) ) {
1141 continue; // Must exist
1142 } else if( !LogEventsList
::userCan($logRows[$logid], LogPage
::DELETED_RESTRICTED
)
1143 ||
$logRows[$logid]->log_type
== 'suppress' ) {
1144 // Don't hide from oversight log!!!
1145 $userAllowedAll=false;
1148 // Which logs did we change anything about?
1149 if( $logRows[$logid]->log_deleted
!= $bitfield ) {
1153 $this->updateLogs( $logRows[$logid], $bitfield );
1154 $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
1157 // Don't log or touch if nothing changed
1159 $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted
,
1160 $comment, $title, 'logid', $log_Ids );
1162 // Were all revs allowed to be set?
1163 if( !$userAllowedAll ) {
1164 $wgOut->permissionRequired( 'suppressrevision' );
1172 * Moves an image to a safe private location
1173 * Caller is responsible for clearing caches
1174 * @param File $oimage
1175 * @returns mixed, timestamp string on success, false on failure
1177 function makeOldImagePrivate( $oimage ) {
1178 $transaction = new FSTransaction();
1179 if( !FileStore
::lock() ) {
1180 wfDebug( __METHOD__
.": failed to acquire file store lock, aborting\n" );
1183 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1184 // Dupe the file into the file store
1185 if( file_exists( $oldpath ) ) {
1186 // Is our directory configured?
1187 if( $store = FileStore
::get( 'deleted' ) ) {
1188 if( !$oimage->sha1
) {
1189 $oimage->upgradeRow(); // sha1 may be missing
1191 $key = $oimage->sha1
. '.' . $oimage->getExtension();
1192 $transaction->add( $store->insert( $key, $oldpath, FileStore
::DELETE_ORIGINAL
) );
1196 $transaction = false; // Return an error and do nothing
1199 wfDebug( __METHOD__
." deleting already-missing '$oldpath'; moving on to database\n" );
1202 $transaction = new FSTransaction(); // empty
1205 if( $transaction === false ) {
1207 wfDebug( __METHOD__
.": import to file store failed, aborting\n" );
1208 throw new MWException( "Could not archive and delete file $oldpath" );
1212 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1213 $transaction->commit();
1214 FileStore
::unlock();
1216 $m = explode('!',$oimage->archive_name
,2);
1223 * Moves an image from a safe private location
1224 * Caller is responsible for clearing caches
1225 * @param File $oimage
1226 * @returns mixed, string timestamp on success, false on failure
1228 function makeOldImagePublic( $oimage ) {
1229 $transaction = new FSTransaction();
1230 if( !FileStore
::lock() ) {
1231 wfDebug( __METHOD__
." could not acquire filestore lock\n" );
1235 $store = FileStore
::get( 'deleted' );
1237 wfDebug( __METHOD__
.": skipping row with no file.\n" );
1241 $key = $oimage->sha1
.'.'.$oimage->getExtension();
1242 $destDir = $oimage->getArchivePath();
1243 if( !is_dir( $destDir ) ) {
1244 wfMkdirParents( $destDir );
1246 $destPath = $destDir . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1247 // Check if any other stored revisions use this file;
1248 // if so, we shouldn't remove the file from the hidden
1249 // archives so they will still work. Check hidden files first.
1250 $useCount = $this->dbw
->selectField( 'oldimage', '1',
1251 array( 'oi_sha1' => $oimage->sha1
,
1252 'oi_deleted & '.File
::DELETED_FILE
=> File
::DELETED_FILE
),
1253 __METHOD__
, array( 'FOR UPDATE' ) );
1254 // Check the rest of the deleted archives too.
1255 // (these are the ones that don't show in the image history)
1257 $useCount = $this->dbw
->selectField( 'filearchive', '1',
1258 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1259 __METHOD__
, array( 'FOR UPDATE' ) );
1262 if( $useCount == 0 ) {
1263 wfDebug( __METHOD__
.": nothing else using {$oimage->sha1}, will deleting after\n" );
1264 $flags = FileStore
::DELETE_ORIGINAL
;
1268 $transaction->add( $store->export( $key, $destPath, $flags ) );
1270 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1271 $transaction->commit();
1272 FileStore
::unlock();
1274 $m = explode('!',$oimage->archive_name
,2);
1281 * Update the revision's rev_deleted field
1282 * @param Revision $rev
1283 * @param int $bitfield new rev_deleted bitfield value
1285 function updateRevision( $rev, $bitfield ) {
1286 $this->dbw
->update( 'revision',
1287 array( 'rev_deleted' => $bitfield ),
1288 array( 'rev_id' => $rev->getId(),
1289 'rev_page' => $rev->getPage() ),
1294 * Update the revision's rev_deleted field
1295 * @param Revision $rev
1296 * @param Title $title
1297 * @param int $bitfield new rev_deleted bitfield value
1299 function updateArchive( $rev, $title, $bitfield ) {
1300 $this->dbw
->update( 'archive',
1301 array( 'ar_deleted' => $bitfield ),
1302 array( 'ar_namespace' => $title->getNamespace(),
1303 'ar_title' => $title->getDBKey(),
1304 'ar_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ),
1305 'ar_rev_id' => $rev->getId() ),
1310 * Update the images's oi_deleted field
1312 * @param int $bitfield new rev_deleted bitfield value
1314 function updateOldFiles( $file, $bitfield ) {
1315 $this->dbw
->update( 'oldimage',
1316 array( 'oi_deleted' => $bitfield ),
1317 array( 'oi_name' => $file->getName(),
1318 'oi_timestamp' => $this->dbw
->timestamp( $file->getTimestamp() ) ),
1323 * Update the images's fa_deleted field
1324 * @param ArchivedFile $file
1325 * @param int $bitfield new rev_deleted bitfield value
1327 function updateArchFiles( $file, $bitfield ) {
1328 $this->dbw
->update( 'filearchive',
1329 array( 'fa_deleted' => $bitfield ),
1330 array( 'fa_id' => $file->getId() ),
1335 * Update the logging log_deleted field
1337 * @param int $bitfield new rev_deleted bitfield value
1339 function updateLogs( $row, $bitfield ) {
1340 $this->dbw
->update( 'logging',
1341 array( 'log_deleted' => $bitfield ),
1342 array( 'log_id' => $row->log_id
),
1347 * Update the revision's recentchanges record if fields have been hidden
1348 * @param Revision $rev
1349 * @param int $bitfield new rev_deleted bitfield value
1351 function updateRecentChangesEdits( $rev, $bitfield ) {
1352 $this->dbw
->update( 'recentchanges',
1353 array( 'rc_deleted' => $bitfield,
1354 'rc_patrolled' => 1 ),
1355 array( 'rc_this_oldid' => $rev->getId(),
1356 'rc_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ) ),
1361 * Update the revision's recentchanges record if fields have been hidden
1363 * @param int $bitfield new rev_deleted bitfield value
1365 function updateRecentChangesLog( $row, $bitfield ) {
1366 $this->dbw
->update( 'recentchanges',
1367 array( 'rc_deleted' => $bitfield,
1368 'rc_patrolled' => 1 ),
1369 array( 'rc_logid' => $row->log_id
,
1370 'rc_timestamp' => $row->log_timestamp
),
1375 * Touch the page's cache invalidation timestamp; this forces cached
1376 * history views to refresh, so any newly hidden or shown fields will
1378 * @param Title $title
1380 function updatePage( $title ) {
1381 $title->invalidateCache();
1382 $title->purgeSquid();
1383 $title->touchLinks();
1384 // Extensions that require referencing previous revisions may need this
1385 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1389 * Checks for a change in the bitfield for a certain option and updates the
1390 * provided array accordingly.
1392 * @param String $desc Description to add to the array if the option was
1393 * enabled / disabled.
1394 * @param int $field The bitmask describing the single option.
1395 * @param int $diff The xor of the old and new bitfields.
1396 * @param array $arr The array to update.
1398 function checkItem ( $desc, $field, $diff, $new, &$arr ) {
1399 if ( $diff & $field ) {
1400 $arr [ ( $new & $field ) ?
0 : 1 ][] = $desc;
1405 * Gets an array describing the changes made to the visibilit of the revision.
1406 * If the resulting array is $arr, then $arr[0] will contain an array of strings
1407 * describing the items that were hidden, $arr[2] will contain an array of strings
1408 * describing the items that were unhidden, and $arr[3] will contain an array with
1409 * a single string, which can be one of "applied restrictions to sysops",
1410 * "removed restrictions from sysops", or null.
1412 * @param int $n The new bitfield.
1413 * @param int $o The old bitfield.
1414 * @return An array as described above.
1416 function getChanges ( $n, $o ) {
1418 $ret = array ( 0 => array(), 1 => array(), 2 => array() );
1420 $this->checkItem ( wfMsgForContent ( 'revdelete-content' ),
1421 Revision
::DELETED_TEXT
, $diff, $n, $ret );
1422 $this->checkItem ( wfMsgForContent ( 'revdelete-summary' ),
1423 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
1424 $this->checkItem ( wfMsgForContent ( 'revdelete-uname' ),
1425 Revision
::DELETED_USER
, $diff, $n, $ret );
1427 // Restriction application to sysops
1428 if ( $diff & Revision
::DELETED_RESTRICTED
) {
1429 if ( $n & Revision
::DELETED_RESTRICTED
)
1430 $ret[2][] = wfMsgForContent ( 'revdelete-restricted' );
1432 $ret[2][] = wfMsgForContent ( 'revdelete-unrestricted' );
1439 * Gets a log message to describe the given revision visibility change. This
1440 * message will be of the form "[hid {content, edit summary, username}];
1441 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
1443 * @param int $count The number of effected revisions.
1444 * @param int $nbitfield The new bitfield for the revision.
1445 * @param int $obitfield The old bitfield for the revision.
1446 * @param string $comment The comment associated with the change.
1447 * @param bool $isForLog
1449 function getLogMessage ( $count, $nbitfield, $obitfield, $comment, $isForLog = false ) {
1453 $changes = $this->getChanges( $nbitfield, $obitfield );
1455 if ( count ( $changes[0] ) ) {
1456 $s .= wfMsgForContent ( 'revdelete-hid', implode ( ', ', $changes[0] ) );
1459 if ( count ( $changes[1] ) ) {
1462 $s .= wfMsgForContent ( 'revdelete-unhid', implode ( ', ', $changes[1] ) );
1465 if ( count ( $changes[2] )) {
1467 $s .= ' (' . $changes[2][0] . ')';
1469 $s = $changes[2][0];
1472 $msg = $isForLog ?
'logdelete-log-message' : 'revdelete-log-message';
1473 $ret = wfMsgExt ( $msg, array( 'parsemag', 'content' ),
1474 $s, $wgContLang->formatNum( $count ) );
1477 $ret .= ": $comment";
1484 * Record a log entry on the action
1485 * @param Title $title, page where item was removed from
1486 * @param int $count the number of revisions altered for this page
1487 * @param int $nbitfield the new _deleted value
1488 * @param int $obitfield the old _deleted value
1489 * @param string $comment
1490 * @param Title $target, the relevant page
1491 * @param string $param, URL param
1492 * @param Array $items
1494 function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target, $param, $items = array() ) {
1495 // Put things hidden from sysops in the oversight log
1496 $logtype = ( ($nbitfield |
$obitfield) & Revision
::DELETED_RESTRICTED
) ?
'suppress' : 'delete';
1497 $log = new LogPage( $logtype );
1499 $reason = $this->getLogMessage ( $count, $nbitfield, $obitfield, $comment, $param == 'logid' );
1501 if( $param == 'logid' ) {
1502 $params = array( implode( ',', $items) );
1503 $log->addEntry( 'event', $title, $reason, $params );
1505 // Add params for effected page and ids
1506 $params = array( $param, implode( ',', $items) );
1507 $log->addEntry( 'revision', $title, $reason, $params );