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
;
46 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
51 $wgOut->showErrorPage( 'revdelete-toomanytargets-title', 'revdelete-toomanytargets-text' );
54 $this->page
= Title
::newFromUrl( $this->target
);
55 # If this is just one revision, get the title from it.
56 # This allows for more flexibility with page moves...
57 if( count($this->oldids
) === 1 ) {
58 $rev = Revision
::newFromId( $this->oldids
[0] );
59 $this->page
= $rev ?
$rev->getTitle() : $this->page
;
61 # We need a target page!
62 if( is_null($this->page
) ) {
63 $wgOut->addWikiMsg( 'undelete-header' );
66 # Logs must have a type given
67 if( $this->logids
&& !strpos($this->page
->getDBKey(),'/') ) {
68 $wgOut->showErrorPage( 'revdelete-nologtype-title', 'revdelete-nologtype-text' );
71 # For reviewing deleted files...show it now if allowed
73 $oimage = RepoGroup
::singleton()->getLocalRepo()->newFromArchiveName( $this->page
, $this->file
);
75 // Check if user is allowed to see this file
76 if( !$oimage->userCan(File
::DELETED_FILE
) ) {
77 $wgOut->permissionRequired( 'suppressrevision' );
79 $this->showFile( $this->file
);
83 # Give a link to the logs/hist for this page
84 if( !is_null($this->page
) && $this->page
->getNamespace() > -1 ) {
87 $logtitle = SpecialPage
::getTitleFor( 'Log' );
88 $links[] = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
89 wfArrayToCGI( array( 'page' => $this->page
->getPrefixedUrl() ) ) );
90 # Give a link to the page history
91 $links[] = $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml( 'pagehist' ),
92 wfArrayToCGI( array( 'action' => 'history' ) ) );
93 # Link to deleted edits
94 if( $wgUser->isAllowed('undelete') ) {
95 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
96 $links[] = $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
97 wfArrayToCGI( array( 'target' => $this->page
->getPrefixedDBkey() ) ) );
99 # Logs themselves don't have histories or archived revisions
100 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
102 # Lock the operation and the form context
103 $this->secureOperation();
104 # Either submit or create our form
105 if( $this->wasPosted
) {
106 $this->submit( $wgRequest );
107 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
109 } else if( $this->deleteKey
== 'fileid' ||
$this->deleteKey
== 'oldimage' ) {
111 } else if( $this->deleteKey
== 'logid' ) {
112 $this->showLogItems();
114 # Show relevant lines from the deletion log. This will show even if said ID
115 # does not exist...might be helpful
116 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'delete' ) ) . "</h2>\n" );
117 LogEventsList
::showLogExtract( $wgOut, 'delete', $this->page
->getPrefixedText() );
118 if( $wgUser->isAllowed( 'suppressionlog' ) ){
119 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'suppress' ) ) . "</h2>\n" );
120 LogEventsList
::showLogExtract( $wgOut, 'suppress', $this->page
->getPrefixedText() );
124 private function secureOperation() {
126 $this->deleteKey
= '';
127 // At this point, we should only have one of these
128 if( $this->oldids
) {
129 $this->revisions
= $this->oldids
;
130 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
131 $this->deleteKey
= 'oldid';
132 } else if( $this->artimestamps
) {
133 $this->archrevs
= $this->artimestamps
;
134 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
135 $this->deleteKey
= 'artimestamp';
136 } else if( $this->oldimgs
) {
137 $this->ofiles
= $this->oldimgs
;
138 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
139 $this->deleteKey
= 'oldimage';
140 } else if( $this->fileids
) {
141 $this->afiles
= $this->fileids
;
142 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
143 $this->deleteKey
= 'fileid';
144 } else if( $this->logids
) {
145 $this->events
= $this->logids
;
146 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage
::DELETED_ACTION
);
147 $this->deleteKey
= 'logid';
149 // Our checkbox messages depends one what we are doing,
150 // e.g. we don't hide "text" for logs or images
151 $this->checks
= array(
153 array( 'revdelete-hide-comment', 'wpHideComment', Revision
::DELETED_COMMENT
),
154 array( 'revdelete-hide-user', 'wpHideUser', Revision
::DELETED_USER
)
156 if( $wgUser->isAllowed('suppressrevision') ) {
157 $this->checks
[] = array( 'revdelete-hide-restricted', 'wpHideRestricted', Revision
::DELETED_RESTRICTED
);
162 * Show a deleted file version requested by the visitor.
164 private function showFile( $key ) {
165 global $wgOut, $wgRequest;
168 # We mustn't allow the output to be Squid cached, otherwise
169 # if an admin previews a deleted image, and it's cached, then
170 # a user without appropriate permissions can toddle off and
171 # nab the image, and Squid will serve it
172 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
173 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
174 $wgRequest->response()->header( 'Pragma: no-cache' );
176 $store = FileStore
::get( 'deleted' );
177 $store->stream( $key );
181 * This lets a user set restrictions for live and archived revisions
183 private function showRevs() {
184 global $wgOut, $wgUser;
187 $count = ($this->deleteKey
=='oldid') ?
188 count($this->revisions
) : count($this->archrevs
);
189 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(), $count );
192 $wgOut->addHTML( "<ul>" );
194 $where = $revObjs = array();
195 $dbr = wfGetDB( DB_MASTER
);
199 if( $this->deleteKey
=='oldid' ) {
200 // Run through and pull all our data in one query
201 foreach( $this->revisions
as $revid ) {
202 $where[] = intval($revid);
204 $result = $dbr->select( array('revision','page'), '*',
206 'rev_page' => $this->page
->getArticleID(),
208 'rev_page = page_id' ),
210 while( $row = $dbr->fetchObject( $result ) ) {
211 $revObjs[$row->rev_id
] = new Revision( $row );
213 foreach( $this->revisions
as $revid ) {
214 // Hiding top revisison is bad
215 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
217 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
218 // If a rev is hidden from sysops
219 if( !$this->wasPosted
) {
220 $wgOut->permissionRequired( 'suppressrevision' );
223 $UserAllowed = false;
226 $wgOut->addHTML( $this->historyLine( $revObjs[$revid] ) );
227 $bitfields |
= $revObjs[$revid]->mDeleted
;
231 // Run through and pull all our data in one query
232 foreach( $this->archrevs
as $timestamp ) {
233 $where[] = $dbr->timestamp( $timestamp );
235 $result = $dbr->select( 'archive', '*',
237 'ar_namespace' => $this->page
->getNamespace(),
238 'ar_title' => $this->page
->getDBKey(),
239 'ar_timestamp' => $where ),
241 while( $row = $dbr->fetchObject( $result ) ) {
242 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
243 $revObjs[$timestamp] = new Revision( array(
244 'page' => $this->page
->getArticleId(),
245 'id' => $row->ar_rev_id
,
246 'text' => $row->ar_text_id
,
247 'comment' => $row->ar_comment
,
248 'user' => $row->ar_user
,
249 'user_text' => $row->ar_user_text
,
250 'timestamp' => $timestamp,
251 'minor_edit' => $row->ar_minor_edit
,
252 'text_id' => $row->ar_text_id
,
253 'deleted' => $row->ar_deleted
,
254 'len' => $row->ar_len
) );
256 foreach( $this->archrevs
as $timestamp ) {
257 if( !isset($revObjs[$timestamp]) ) {
259 } else if( !$revObjs[$timestamp]->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[$timestamp] ) );
269 $bitfields |
= $revObjs[$timestamp]->mDeleted
;
273 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
277 $wgOut->addHTML( "</ul>" );
279 $this->addUsageText();
281 // Normal sysops can always see what they did, but can't always change it
282 if( !$UserAllowed ) return;
285 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
286 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
289 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
290 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
291 Xml
::hidden( 'type', $this->deleteKey
)
293 if( $this->deleteKey
=='oldid' ) {
294 foreach( $revObjs as $rev )
295 $hidden[] = Xml
::hidden( 'oldid[]', $rev->getId() );
297 foreach( $revObjs as $rev )
298 $hidden[] = Xml
::hidden( 'artimestamp[]', $rev->getTimestamp() );
300 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
302 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
303 'id' => 'mw-revdel-form-revisions' ) ) .
304 Xml
::openElement( 'fieldset' ) .
305 xml
::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
308 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
309 foreach( $items as $item ) {
310 $wgOut->addHTML( Xml
::tags( 'p', null, $item ) );
312 foreach( $hidden as $item ) {
313 $wgOut->addHTML( $item );
316 Xml
::closeElement( 'fieldset' ) .
317 Xml
::closeElement( 'form' ) . "\n"
322 * This lets a user set restrictions for archived images
324 private function showImages() {
325 global $wgOut, $wgUser, $wgLang;
328 $count = ($this->deleteKey
=='oldimage') ?
count($this->ofiles
) : count($this->afiles
);
329 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(),
330 $wgLang->formatNum($count) );
333 $wgOut->addHTML( "<ul>" );
335 $where = $filesObjs = array();
336 $dbr = wfGetDB( DB_MASTER
);
337 // Live old revisions...
339 if( $this->deleteKey
=='oldimage' ) {
340 // Run through and pull all our data in one query
341 foreach( $this->ofiles
as $timestamp ) {
342 $where[] = $timestamp.'!'.$this->page
->getDBKey();
344 $result = $dbr->select( 'oldimage', '*',
346 'oi_name' => $this->page
->getDBKey(),
347 'oi_archive_name' => $where ),
349 while( $row = $dbr->fetchObject( $result ) ) {
350 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
351 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
352 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
354 // Check through our images
355 foreach( $this->ofiles
as $timestamp ) {
356 $archivename = $timestamp.'!'.$this->page
->getDBKey();
357 if( !isset($filesObjs[$archivename]) ) {
359 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
360 // If a rev is hidden from sysops
361 if( !$this->wasPosted
) {
362 $wgOut->permissionRequired( 'suppressrevision' );
365 $UserAllowed = false;
368 // Inject history info
369 $wgOut->addHTML( $this->fileLine( $filesObjs[$archivename] ) );
370 $bitfields |
= $filesObjs[$archivename]->deleted
;
374 // Run through and pull all our data in one query
375 foreach( $this->afiles
as $id ) {
376 $where[] = intval($id);
378 $result = $dbr->select( 'filearchive', '*',
380 'fa_name' => $this->page
->getDBKey(),
383 while( $row = $dbr->fetchObject( $result ) ) {
384 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
387 foreach( $this->afiles
as $fileid ) {
388 if( !isset($filesObjs[$fileid]) ) {
390 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
391 // If a rev is hidden from sysops
392 if( !$this->wasPosted
) {
393 $wgOut->permissionRequired( 'suppressrevision' );
396 $UserAllowed = false;
399 // Inject history info
400 $wgOut->addHTML( $this->archivedfileLine( $filesObjs[$fileid] ) );
401 $bitfields |
= $filesObjs[$fileid]->deleted
;
405 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
409 $wgOut->addHTML( "</ul>" );
411 $this->addUsageText();
412 // Normal sysops can always see what they did, but can't always change it
413 if( !$UserAllowed ) return;
416 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
417 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
420 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
421 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
422 Xml
::hidden( 'type', $this->deleteKey
)
424 if( $this->deleteKey
=='oldimage' ) {
425 foreach( $this->ofiles
as $filename )
426 $hidden[] = Xml
::hidden( 'oldimage[]', $filename );
428 foreach( $this->afiles
as $fileid )
429 $hidden[] = Xml
::hidden( 'fileid[]', $fileid );
431 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
433 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
434 'id' => 'mw-revdel-form-filerevisions' ) ) .
435 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
438 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
439 foreach( $items as $item ) {
440 $wgOut->addHTML( "<p>$item</p>" );
442 foreach( $hidden as $item ) {
443 $wgOut->addHTML( $item );
447 Xml
::closeElement( 'fieldset' ) .
448 Xml
::closeElement( 'form' ) . "\n"
453 * This lets a user set restrictions for log items
455 private function showLogItems() {
456 global $wgOut, $wgUser, $wgMessageCache, $wgLang;
459 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->events
) ) );
462 $wgOut->addHTML( "<ul>" );
464 $where = $logRows = array();
465 $dbr = wfGetDB( DB_MASTER
);
466 // Run through and pull all our data in one query
468 foreach( $this->events
as $logid ) {
469 $where[] = intval($logid);
471 list($log,$logtype) = explode( '/',$this->page
->getDBKey(), 2 );
472 $result = $dbr->select( 'logging', '*',
474 'log_type' => $logtype,
475 'log_id' => $where ),
477 while( $row = $dbr->fetchObject( $result ) ) {
478 $logRows[$row->log_id
] = $row;
480 $wgMessageCache->loadAllMessages();
481 foreach( $this->events
as $logid ) {
482 // Don't hide from oversight log!!!
483 if( !isset( $logRows[$logid] ) ||
$logRows[$logid]->log_type
=='suppress' ) {
485 } else if( !LogEventsList
::userCan( $logRows[$logid],Revision
::DELETED_RESTRICTED
) ) {
486 // If an event is hidden from sysops
487 if( !$this->wasPosted
) {
488 $wgOut->permissionRequired( 'suppressrevision' );
491 $UserAllowed = false;
494 $wgOut->addHTML( $this->logLine( $logRows[$logid] ) );
495 $bitfields |
= $logRows[$logid]->log_deleted
;
498 $wgOut->showErrorPage( 'revdelete-nologid-title', 'revdelete-nologid-text' );
502 $wgOut->addHTML( "</ul>" );
504 $this->addUsageText();
505 // Normal sysops can always see what they did, but can't always change it
506 if( !$UserAllowed ) return;
509 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
510 Xml
::submitButton( wfMsg( 'revdelete-submit' ) ) );
512 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
513 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
514 Xml
::hidden( 'type', $this->deleteKey
) );
515 foreach( $this->events
as $logid ) {
516 $hidden[] = Xml
::hidden( 'logid[]', $logid );
519 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
521 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
522 'id' => 'mw-revdel-form-logs' ) ) .
523 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
526 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
527 foreach( $items as $item ) {
528 $wgOut->addHTML( "<p>$item</p>" );
530 foreach( $hidden as $item ) {
531 $wgOut->addHTML( $item );
535 Xml
::closeElement( 'fieldset' ) .
536 Xml
::closeElement( 'form' ) . "\n"
540 private function addUsageText() {
541 global $wgOut, $wgUser;
542 $wgOut->addWikiMsg( 'revdelete-text' );
543 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
544 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
549 * @param int $bitfields, aggregate bitfield of all the bitfields
550 * @returns string HTML
552 private function buildCheckBoxes( $bitfields ) {
554 // FIXME: all items checked for just one rev are checked, even if not set for the others
555 foreach( $this->checks
as $item ) {
556 list( $message, $name, $field ) = $item;
557 $line = Xml
::tags( 'div', null, Xml
::checkLabel( wfMsg($message), $name, $name,
558 $bitfields & $field ) );
559 if( $field == Revision
::DELETED_RESTRICTED
) $line = "<b>$line</b>";
566 * @param Revision $rev
569 private function historyLine( $rev ) {
570 global $wgLang, $wgUser;
572 $date = $wgLang->timeanddate( $rev->getTimestamp() );
573 $difflink = $del = '';
575 if( $this->deleteKey
=='oldid' ) {
576 $tokenParams = '&unhide=1&token='.urlencode( $wgUser->editToken( $rev->getId() ) );
577 $revlink = $this->skin
->makeLinkObj( $this->page
, $date, 'oldid='.$rev->getId() . $tokenParams );
578 $difflink = '(' . $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml('diff'),
579 'diff=' . $rev->getId() . '&oldid=prev' . $tokenParams ) . ')';
580 // Archived revisions
582 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
583 $target = $this->page
->getPrefixedText();
584 $revlink = $this->skin
->makeLinkObj( $undelete, $date,
585 "target=$target×tamp=" . $rev->getTimestamp() );
586 $difflink = '(' . $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml('diff'),
587 "target=$target&diff=prev×tamp=" . $rev->getTimestamp() ) . ')';
589 // Check permissions; items may be "suppressed"
590 if( $rev->isDeleted(Revision
::DELETED_TEXT
) ) {
591 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
592 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
593 if( !$rev->userCan(Revision
::DELETED_TEXT
) ) {
594 $revlink = '<span class="history-deleted">'.$date.'</span>';
595 $difflink = '(' . wfMsgHtml('diff') . ')';
598 $userlink = $this->skin
->revUserLink( $rev );
599 $comment = $this->skin
->revComment( $rev );
601 return "<li>$difflink $revlink $userlink $comment{$del}</li>";
608 private function fileLine( $file ) {
609 global $wgLang, $wgTitle;
611 $target = $this->page
->getPrefixedText();
612 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
616 if( $file->isDeleted(File
::DELETED_FILE
) ) {
617 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
618 if( !$file->userCan(File
::DELETED_FILE
) ) {
621 $pageLink = $this->skin
->makeKnownLinkObj( $wgTitle, $date,
622 "target=$target&file=$file->sha1.".$file->getExtension() );
624 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
627 $url = $file->getUrlRel();
628 $pageLink = "<a href=\"{$url}\">{$date}</a>";
631 $data = wfMsg( 'widthheight',
632 $wgLang->formatNum( $file->getWidth() ),
633 $wgLang->formatNum( $file->getHeight() ) ) .
634 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
635 $data = htmlspecialchars( $data );
637 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
641 * @param ArchivedFile $file
644 private function archivedfileLine( $file ) {
647 $target = $this->page
->getPrefixedText();
648 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
650 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
651 $pageLink = $this->skin
->makeKnownLinkObj( $undelete, $date, "target=$target&file={$file->getKey()}" );
654 if( $file->isDeleted(File
::DELETED_FILE
) ) {
655 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
658 $data = wfMsg( 'widthheight',
659 $wgLang->formatNum( $file->getWidth() ),
660 $wgLang->formatNum( $file->getHeight() ) ) .
661 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
662 $data = htmlspecialchars( $data );
664 return "<li> $pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
668 * @param Array $row row
671 private function logLine( $row ) {
674 $date = $wgLang->timeanddate( $row->log_timestamp
);
675 $paramArray = LogPage
::extractParams( $row->log_params
);
676 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
678 $logtitle = SpecialPage
::getTitleFor( 'Log' );
679 $loglink = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
680 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
682 if( !LogEventsList
::userCan($row,LogPage
::DELETED_ACTION
) ) {
683 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
685 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
686 $this->skin
, $paramArray, true, true );
687 if( $row->log_deleted
& LogPage
::DELETED_ACTION
)
688 $action = '<span class="history-deleted">' . $action . '</span>';
691 $userLink = $this->skin
->userLink( $row->log_user
, User
::WhoIs($row->log_user
) );
692 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_USER
) ) {
693 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
696 $comment = $wgLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
697 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
698 $comment = '<span class="history-deleted">' . $comment . '</span>';
700 return "<li>($loglink) $date $userLink $action $comment</li>";
704 * Generate a user tool link cluster if the current user is allowed to view it
705 * @param ArchivedFile $file
706 * @return string HTML
708 private function fileUserTools( $file ) {
709 if( $file->userCan( Revision
::DELETED_USER
) ) {
710 $link = $this->skin
->userLink( $file->user
, $file->user_text
) .
711 $this->skin
->userToolLinks( $file->user
, $file->user_text
);
713 $link = wfMsgHtml( 'rev-deleted-user' );
715 if( $file->isDeleted( Revision
::DELETED_USER
) ) {
716 return '<span class="history-deleted">' . $link . '</span>';
722 * Wrap and format the given file's comment block, if the current
723 * user is allowed to view it.
725 * @param ArchivedFile $file
726 * @return string HTML
728 private function fileComment( $file ) {
729 if( $file->userCan( File
::DELETED_COMMENT
) ) {
730 $block = $this->skin
->commentBlock( $file->description
);
732 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
734 if( $file->isDeleted( File
::DELETED_COMMENT
) ) {
735 return "<span class=\"history-deleted\">$block</span>";
741 * @param WebRequest $request
743 private function submit( $request ) {
744 global $wgUser, $wgOut;
745 # Check edit token on submission
746 if( $this->wasPosted
&& !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
747 $wgOut->addWikiMsg( 'sessionfailure' );
750 $bitfield = $this->extractBitfield( $request );
751 $comment = $request->getText( 'wpReason' );
752 # Can the user set this field?
753 if( $bitfield & Revision
::DELETED_RESTRICTED
&& !$wgUser->isAllowed('suppressrevision') ) {
754 $wgOut->permissionRequired( 'suppressrevision' );
757 # If the save went through, go to success message. Otherwise
758 # bounce back to form...
759 if( $this->save( $bitfield, $comment, $this->page
) ) {
761 } else if( $request->getCheck( 'oldid' ) ||
$request->getCheck( 'artimestamp' ) ) {
762 return $this->showRevs();
763 } else if( $request->getCheck( 'logid' ) ) {
764 return $this->showLogs();
765 } else if( $request->getCheck( 'oldimage' ) ||
$request->getCheck( 'fileid' ) ) {
766 return $this->showImages();
770 private function success() {
773 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
775 $wrap = '<span class="success">$1</span>';
777 if( $this->deleteKey
=='logid' ) {
778 $wgOut->wrapWikiMsg( $wrap, 'logdelete-success' );
779 $this->showLogItems();
780 } else if( $this->deleteKey
=='oldid' ||
$this->deleteKey
=='artimestamp' ) {
781 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
783 } else if( $this->deleteKey
=='fileid' ) {
784 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
786 } else if( $this->deleteKey
=='oldimage' ) {
787 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
793 * Put together a rev_deleted bitfield from the submitted checkboxes
794 * @param WebRequest $request
797 private function extractBitfield( $request ) {
799 foreach( $this->checks
as $item ) {
800 list( /* message */ , $name, $field ) = $item;
801 if( $request->getCheck( $name ) ) {
808 private function save( $bitfield, $reason, $title ) {
809 $dbw = wfGetDB( DB_MASTER
);
810 // Don't allow simply locking the interface for no reason
811 if( $bitfield == Revision
::DELETED_RESTRICTED
) {
814 $deleter = new RevisionDeleter( $dbw );
815 // By this point, only one of the below should be set
816 if( isset($this->revisions
) ) {
817 return $deleter->setRevVisibility( $title, $this->revisions
, $bitfield, $reason );
818 } else if( isset($this->archrevs
) ) {
819 return $deleter->setArchiveVisibility( $title, $this->archrevs
, $bitfield, $reason );
820 } else if( isset($this->ofiles
) ) {
821 return $deleter->setOldImgVisibility( $title, $this->ofiles
, $bitfield, $reason );
822 } else if( isset($this->afiles
) ) {
823 return $deleter->setArchFileVisibility( $title, $this->afiles
, $bitfield, $reason );
824 } else if( isset($this->events
) ) {
825 return $deleter->setEventVisibility( $title, $this->events
, $bitfield, $reason );
831 * Implements the actions for Revision Deletion.
832 * @ingroup SpecialPage
834 class RevisionDeleter
{
835 function __construct( $db ) {
840 * @param $title, the page these events apply to
841 * @param array $items list of revision ID numbers
842 * @param int $bitfield new rev_deleted value
843 * @param string $comment Comment for log records
845 function setRevVisibility( $title, $items, $bitfield, $comment ) {
848 $userAllowedAll = $success = true;
851 // Run through and pull all our data in one query
852 foreach( $items as $revid ) {
853 $where[] = intval($revid);
855 $result = $this->dbw
->select( 'revision', '*',
857 'rev_page' => $title->getArticleID(),
858 'rev_id' => $where ),
860 while( $row = $this->dbw
->fetchObject( $result ) ) {
861 $revObjs[$row->rev_id
] = new Revision( $row );
864 foreach( $items as $revid ) {
865 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
867 continue; // Must exist
868 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
869 $userAllowedAll=false;
872 // For logging, maintain a count of revisions
873 if( $revObjs[$revid]->mDeleted
!= $bitfield ) {
877 $this->updateRevision( $revObjs[$revid], $bitfield );
878 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
882 // Don't log or touch if nothing changed
883 if( $revCount > 0 ) {
884 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted
,
885 $comment, $title, 'oldid', $revIDs );
886 $this->updatePage( $title );
888 // Where all revs allowed to be set?
889 if( !$userAllowedAll ) {
890 //FIXME: still might be confusing???
891 $wgOut->permissionRequired( 'suppressrevision' );
899 * @param $title, the page these events apply to
900 * @param array $items list of revision ID numbers
901 * @param int $bitfield new rev_deleted value
902 * @param string $comment Comment for log records
904 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
907 $userAllowedAll = $success = true;
910 // Run through and pull all our data in one query
911 foreach( $items as $timestamp ) {
912 $where[] = $this->dbw
->timestamp( $timestamp );
914 $result = $this->dbw
->select( 'archive', '*',
916 'ar_namespace' => $title->getNamespace(),
917 'ar_title' => $title->getDBKey(),
918 'ar_timestamp' => $where ),
920 while( $row = $this->dbw
->fetchObject( $result ) ) {
921 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
922 $revObjs[$timestamp] = new Revision( array(
923 'page' => $title->getArticleId(),
924 'id' => $row->ar_rev_id
,
925 'text' => $row->ar_text_id
,
926 'comment' => $row->ar_comment
,
927 'user' => $row->ar_user
,
928 'user_text' => $row->ar_user_text
,
929 'timestamp' => $timestamp,
930 'minor_edit' => $row->ar_minor_edit
,
931 'text_id' => $row->ar_text_id
,
932 'deleted' => $row->ar_deleted
,
933 'len' => $row->ar_len
) );
936 foreach( $items as $timestamp ) {
937 // This will only select the first revision with this timestamp.
938 // Since they are all selected/deleted at once, we can just check the
939 // permissions of one. UPDATE is done via timestamp, so all revs are set.
940 if( !is_object($revObjs[$timestamp]) ) {
942 continue; // Must exist
943 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
944 $userAllowedAll=false;
947 // Which revisions did we change anything about?
948 if( $revObjs[$timestamp]->mDeleted
!= $bitfield ) {
949 $Id_set[]=$timestamp;
952 $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
955 // For logging, maintain a count of revisions
957 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted
,
958 $comment, $title, 'artimestamp', $Id_set );
960 // Where all revs allowed to be set?
961 if( !$userAllowedAll ) {
962 $wgOut->permissionRequired( 'suppressrevision' );
970 * @param $title, the page these events apply to
971 * @param array $items list of revision ID numbers
972 * @param int $bitfield new rev_deleted value
973 * @param string $comment Comment for log records
975 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
978 $userAllowedAll = $success = true;
981 // Run through and pull all our data in one query
982 foreach( $items as $timestamp ) {
983 $where[] = $timestamp.'!'.$title->getDBKey();
985 $result = $this->dbw
->select( 'oldimage', '*',
987 'oi_name' => $title->getDBKey(),
988 'oi_archive_name' => $where ),
990 while( $row = $this->dbw
->fetchObject( $result ) ) {
991 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
992 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
993 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
996 foreach( $items as $timestamp ) {
997 $archivename = $timestamp.'!'.$title->getDBKey();
998 if( !isset($filesObjs[$archivename]) ) {
1000 continue; // Must exist
1001 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
1002 $userAllowedAll=false;
1006 $transaction = true;
1007 // Which revisions did we change anything about?
1008 if( $filesObjs[$archivename]->deleted
!= $bitfield ) {
1011 $this->dbw
->begin();
1012 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
1013 // If this image is currently hidden...
1014 if( $filesObjs[$archivename]->deleted
& File
::DELETED_FILE
) {
1015 if( $bitfield & File
::DELETED_FILE
) {
1016 # Leave it alone if we are not changing this...
1017 $set[]=$archivename;
1018 $transaction = true;
1020 # We are moving this out
1021 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
1022 $set[]=$transaction;
1024 // Is it just now becoming hidden?
1025 } else if( $bitfield & File
::DELETED_FILE
) {
1026 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
1027 $set[]=$transaction;
1031 // If our file operations fail, then revert back the db
1032 if( $transaction==false ) {
1033 $this->dbw
->rollback();
1036 $this->dbw
->commit();
1040 // Log if something was changed
1042 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted
,
1043 $comment, $title, 'oldimage', $set );
1044 # Purge page/history
1045 $file = wfLocalFile( $title );
1046 $file->purgeCache();
1047 $file->purgeHistory();
1048 # Invalidate cache for all pages using this file
1049 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
1050 $update->doUpdate();
1052 // Where all revs allowed to be set?
1053 if( !$userAllowedAll ) {
1054 $wgOut->permissionRequired( 'suppressrevision' );
1062 * @param $title, the page these events apply to
1063 * @param array $items list of revision ID numbers
1064 * @param int $bitfield new rev_deleted value
1065 * @param string $comment Comment for log records
1067 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
1070 $userAllowedAll = $success = true;
1074 // Run through and pull all our data in one query
1075 foreach( $items as $id ) {
1076 $where[] = intval($id);
1078 $result = $this->dbw
->select( 'filearchive', '*',
1079 array( 'fa_name' => $title->getDBKey(),
1080 'fa_id' => $where ),
1082 while( $row = $this->dbw
->fetchObject( $result ) ) {
1083 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
1086 foreach( $items as $fileid ) {
1087 if( !isset($filesObjs[$fileid]) ) {
1089 continue; // Must exist
1090 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
1091 $userAllowedAll=false;
1094 // Which revisions did we change anything about?
1095 if( $filesObjs[$fileid]->deleted
!= $bitfield ) {
1099 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1102 // Log if something was changed
1104 $this->updateLog( $title, $count, $bitfield, $comment,
1105 $filesObjs[$fileid]->deleted
, $title, 'fileid', $Id_set );
1107 // Where all revs allowed to be set?
1108 if( !$userAllowedAll ) {
1109 $wgOut->permissionRequired( 'suppressrevision' );
1117 * @param $title, the log page these events apply to
1118 * @param array $items list of log ID numbers
1119 * @param int $bitfield new log_deleted value
1120 * @param string $comment Comment for log records
1122 function setEventVisibility( $title, $items, $bitfield, $comment ) {
1125 $userAllowedAll = $success = true;
1129 // Run through and pull all our data in one query
1130 foreach( $items as $logid ) {
1131 $where[] = intval($logid);
1133 list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
1134 $result = $this->dbw
->select( 'logging', '*',
1136 'log_type' => $logtype,
1137 'log_id' => $where ),
1139 while( $row = $this->dbw
->fetchObject( $result ) ) {
1140 $logRows[$row->log_id
] = $row;
1143 foreach( $items as $logid ) {
1144 if( !isset($logRows[$logid]) ) {
1146 continue; // Must exist
1147 } else if( !LogEventsList
::userCan($logRows[$logid], LogPage
::DELETED_RESTRICTED
)
1148 ||
$logRows[$logid]->log_type
== 'suppress' ) {
1149 // Don't hide from oversight log!!!
1150 $userAllowedAll=false;
1153 // Which logs did we change anything about?
1154 if( $logRows[$logid]->log_deleted
!= $bitfield ) {
1158 $this->updateLogs( $logRows[$logid], $bitfield );
1159 $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
1162 // Don't log or touch if nothing changed
1164 $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted
,
1165 $comment, $title, 'logid', $log_Ids );
1167 // Were all revs allowed to be set?
1168 if( !$userAllowedAll ) {
1169 $wgOut->permissionRequired( 'suppressrevision' );
1177 * Moves an image to a safe private location
1178 * Caller is responsible for clearing caches
1179 * @param File $oimage
1180 * @returns mixed, timestamp string on success, false on failure
1182 function makeOldImagePrivate( $oimage ) {
1183 $transaction = new FSTransaction();
1184 if( !FileStore
::lock() ) {
1185 wfDebug( __METHOD__
.": failed to acquire file store lock, aborting\n" );
1188 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1189 // Dupe the file into the file store
1190 if( file_exists( $oldpath ) ) {
1191 // Is our directory configured?
1192 if( $store = FileStore
::get( 'deleted' ) ) {
1193 if( !$oimage->sha1
) {
1194 $oimage->upgradeRow(); // sha1 may be missing
1196 $key = $oimage->sha1
. '.' . $oimage->getExtension();
1197 $transaction->add( $store->insert( $key, $oldpath, FileStore
::DELETE_ORIGINAL
) );
1201 $transaction = false; // Return an error and do nothing
1204 wfDebug( __METHOD__
." deleting already-missing '$oldpath'; moving on to database\n" );
1207 $transaction = new FSTransaction(); // empty
1210 if( $transaction === false ) {
1212 wfDebug( __METHOD__
.": import to file store failed, aborting\n" );
1213 throw new MWException( "Could not archive and delete file $oldpath" );
1217 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1218 $transaction->commit();
1219 FileStore
::unlock();
1221 $m = explode('!',$oimage->archive_name
,2);
1228 * Moves an image from a safe private location
1229 * Caller is responsible for clearing caches
1230 * @param File $oimage
1231 * @returns mixed, string timestamp on success, false on failure
1233 function makeOldImagePublic( $oimage ) {
1234 $transaction = new FSTransaction();
1235 if( !FileStore
::lock() ) {
1236 wfDebug( __METHOD__
." could not acquire filestore lock\n" );
1240 $store = FileStore
::get( 'deleted' );
1242 wfDebug( __METHOD__
.": skipping row with no file.\n" );
1246 $key = $oimage->sha1
.'.'.$oimage->getExtension();
1247 $destDir = $oimage->getArchivePath();
1248 if( !is_dir( $destDir ) ) {
1249 wfMkdirParents( $destDir );
1251 $destPath = $destDir . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1252 // Check if any other stored revisions use this file;
1253 // if so, we shouldn't remove the file from the hidden
1254 // archives so they will still work. Check hidden files first.
1255 $useCount = $this->dbw
->selectField( 'oldimage', '1',
1256 array( 'oi_sha1' => $oimage->sha1
,
1257 'oi_deleted & '.File
::DELETED_FILE
=> File
::DELETED_FILE
),
1258 __METHOD__
, array( 'FOR UPDATE' ) );
1259 // Check the rest of the deleted archives too.
1260 // (these are the ones that don't show in the image history)
1262 $useCount = $this->dbw
->selectField( 'filearchive', '1',
1263 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1264 __METHOD__
, array( 'FOR UPDATE' ) );
1267 if( $useCount == 0 ) {
1268 wfDebug( __METHOD__
.": nothing else using {$oimage->sha1}, will deleting after\n" );
1269 $flags = FileStore
::DELETE_ORIGINAL
;
1273 $transaction->add( $store->export( $key, $destPath, $flags ) );
1275 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1276 $transaction->commit();
1277 FileStore
::unlock();
1279 $m = explode('!',$oimage->archive_name
,2);
1286 * Update the revision's rev_deleted field
1287 * @param Revision $rev
1288 * @param int $bitfield new rev_deleted bitfield value
1290 function updateRevision( $rev, $bitfield ) {
1291 $this->dbw
->update( 'revision',
1292 array( 'rev_deleted' => $bitfield ),
1293 array( 'rev_id' => $rev->getId(),
1294 'rev_page' => $rev->getPage() ),
1299 * Update the revision's rev_deleted field
1300 * @param Revision $rev
1301 * @param Title $title
1302 * @param int $bitfield new rev_deleted bitfield value
1304 function updateArchive( $rev, $title, $bitfield ) {
1305 $this->dbw
->update( 'archive',
1306 array( 'ar_deleted' => $bitfield ),
1307 array( 'ar_namespace' => $title->getNamespace(),
1308 'ar_title' => $title->getDBKey(),
1309 'ar_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ),
1310 'ar_rev_id' => $rev->getId() ),
1315 * Update the images's oi_deleted field
1317 * @param int $bitfield new rev_deleted bitfield value
1319 function updateOldFiles( $file, $bitfield ) {
1320 $this->dbw
->update( 'oldimage',
1321 array( 'oi_deleted' => $bitfield ),
1322 array( 'oi_name' => $file->getName(),
1323 'oi_timestamp' => $this->dbw
->timestamp( $file->getTimestamp() ) ),
1328 * Update the images's fa_deleted field
1329 * @param ArchivedFile $file
1330 * @param int $bitfield new rev_deleted bitfield value
1332 function updateArchFiles( $file, $bitfield ) {
1333 $this->dbw
->update( 'filearchive',
1334 array( 'fa_deleted' => $bitfield ),
1335 array( 'fa_id' => $file->getId() ),
1340 * Update the logging log_deleted field
1342 * @param int $bitfield new rev_deleted bitfield value
1344 function updateLogs( $row, $bitfield ) {
1345 $this->dbw
->update( 'logging',
1346 array( 'log_deleted' => $bitfield ),
1347 array( 'log_id' => $row->log_id
),
1352 * Update the revision's recentchanges record if fields have been hidden
1353 * @param Revision $rev
1354 * @param int $bitfield new rev_deleted bitfield value
1356 function updateRecentChangesEdits( $rev, $bitfield ) {
1357 $this->dbw
->update( 'recentchanges',
1358 array( 'rc_deleted' => $bitfield,
1359 'rc_patrolled' => 1 ),
1360 array( 'rc_this_oldid' => $rev->getId(),
1361 'rc_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ) ),
1366 * Update the revision's recentchanges record if fields have been hidden
1368 * @param int $bitfield new rev_deleted bitfield value
1370 function updateRecentChangesLog( $row, $bitfield ) {
1371 $this->dbw
->update( 'recentchanges',
1372 array( 'rc_deleted' => $bitfield,
1373 'rc_patrolled' => 1 ),
1374 array( 'rc_logid' => $row->log_id
,
1375 'rc_timestamp' => $row->log_timestamp
),
1380 * Touch the page's cache invalidation timestamp; this forces cached
1381 * history views to refresh, so any newly hidden or shown fields will
1383 * @param Title $title
1385 function updatePage( $title ) {
1386 $title->invalidateCache();
1387 $title->purgeSquid();
1388 $title->touchLinks();
1389 // Extensions that require referencing previous revisions may need this
1390 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1394 * Checks for a change in the bitfield for a certain option and updates the
1395 * provided array accordingly.
1397 * @param String $desc Description to add to the array if the option was
1398 * enabled / disabled.
1399 * @param int $field The bitmask describing the single option.
1400 * @param int $diff The xor of the old and new bitfields.
1401 * @param array $arr The array to update.
1403 function checkItem ( $desc, $field, $diff, $new, &$arr ) {
1404 if ( $diff & $field ) {
1405 $arr [ ( $new & $field ) ?
0 : 1 ][] = $desc;
1410 * Gets an array describing the changes made to the visibilit of the revision.
1411 * If the resulting array is $arr, then $arr[0] will contain an array of strings
1412 * describing the items that were hidden, $arr[2] will contain an array of strings
1413 * describing the items that were unhidden, and $arr[3] will contain an array with
1414 * a single string, which can be one of "applied restrictions to sysops",
1415 * "removed restrictions from sysops", or null.
1417 * @param int $n The new bitfield.
1418 * @param int $o The old bitfield.
1419 * @return An array as described above.
1421 function getChanges ( $n, $o ) {
1423 $ret = array ( 0 => array(), 1 => array(), 2 => array() );
1425 $this->checkItem ( wfMsgForContent ( 'revdelete-content' ),
1426 Revision
::DELETED_TEXT
, $diff, $n, $ret );
1427 $this->checkItem ( wfMsgForContent ( 'revdelete-summary' ),
1428 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
1429 $this->checkItem ( wfMsgForContent ( 'revdelete-uname' ),
1430 Revision
::DELETED_USER
, $diff, $n, $ret );
1432 // Restriction application to sysops
1433 if ( $diff & Revision
::DELETED_RESTRICTED
) {
1434 if ( $n & Revision
::DELETED_RESTRICTED
)
1435 $ret[2][] = wfMsgForContent ( 'revdelete-restricted' );
1437 $ret[2][] = wfMsgForContent ( 'revdelete-unrestricted' );
1444 * Gets a log message to describe the given revision visibility change. This
1445 * message will be of the form "[hid {content, edit summary, username}];
1446 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
1448 * @param int $count The number of effected revisions.
1449 * @param int $nbitfield The new bitfield for the revision.
1450 * @param int $obitfield The old bitfield for the revision.
1451 * @param string $comment The comment associated with the change.
1452 * @param bool $isForLog
1454 function getLogMessage ( $count, $nbitfield, $obitfield, $comment, $isForLog = false ) {
1458 $changes = $this->getChanges( $nbitfield, $obitfield );
1460 if ( count ( $changes[0] ) ) {
1461 $s .= wfMsgForContent ( 'revdelete-hid', implode ( ', ', $changes[0] ) );
1464 if ( count ( $changes[1] ) ) {
1467 $s .= wfMsgForContent ( 'revdelete-unhid', implode ( ', ', $changes[1] ) );
1470 if ( count ( $changes[2] )) {
1472 $s .= ' (' . $changes[2][0] . ')';
1474 $s = $changes[2][0];
1477 $msg = $isForLog ?
'logdelete-log-message' : 'revdelete-log-message';
1478 $ret = wfMsgExt ( $msg, array( 'parsemag', 'content' ),
1479 $s, $wgContLang->formatNum( $count ) );
1482 $ret .= ": $comment";
1489 * Record a log entry on the action
1490 * @param Title $title, page where item was removed from
1491 * @param int $count the number of revisions altered for this page
1492 * @param int $nbitfield the new _deleted value
1493 * @param int $obitfield the old _deleted value
1494 * @param string $comment
1495 * @param Title $target, the relevant page
1496 * @param string $param, URL param
1497 * @param Array $items
1499 function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target, $param, $items = array() ) {
1500 // Put things hidden from sysops in the oversight log
1501 $logtype = ( ($nbitfield |
$obitfield) & Revision
::DELETED_RESTRICTED
) ?
'suppress' : 'delete';
1502 $log = new LogPage( $logtype );
1504 $reason = $this->getLogMessage ( $count, $nbitfield, $obitfield, $comment, $param == 'logid' );
1506 if( $param == 'logid' ) {
1507 $params = array( implode( ',', $items) );
1508 $log->addEntry( 'event', $title, $reason, $params );
1510 // Add params for effected page and ids
1511 $params = array( $param, implode( ',', $items) );
1512 $log->addEntry( 'revision', $title, $reason, $params );