3 * Special page allowing users with the appropriate permissions to view
4 * and hide revisions. Log items can also be hidden.
10 class SpecialRevisionDelete
extends UnlistedSpecialPage
{
12 public function __construct() {
13 parent
::__construct( 'Revisiondelete', 'deleterevision' );
14 $this->includable( false );
17 public function execute( $par ) {
18 global $wgOut, $wgUser, $wgRequest;
20 $wgOut->readOnlyPage();
23 if( !$wgUser->isAllowed( 'deleterevision' ) ) {
24 $wgOut->permissionRequired( 'deleterevision' );
27 $this->skin
=& $wgUser->getSkin();
29 $this->outputHeader();
30 $this->wasPosted
= $wgRequest->wasPosted();
32 $this->target
= $wgRequest->getText( 'target' );
33 # Handle our many different possible input types.
34 # Use CVS, since the cgi handling will break on arrays.
35 $this->oldids
= array_filter( explode( ',', $wgRequest->getVal('oldid') ) );
36 $this->artimestamps
= array_filter( explode( ',', $wgRequest->getVal('artimestamp') ) );
37 $this->logids
= array_filter( explode( ',', $wgRequest->getVal('logid') ) );
38 $this->oldimgs
= array_filter( explode( ',', $wgRequest->getVal('oldimage') ) );
39 $this->fileids
= array_filter( explode( ',', $wgRequest->getVal('fileid') ) );
40 # For reviewing deleted files...
41 $this->file
= $wgRequest->getVal( 'file' );
42 # Only one target set at a time please!
43 $i = (bool)$this->file +
(bool)$this->oldids +
(bool)$this->logids
44 +
(bool)$this->artimestamps +
(bool)$this->fileids +
(bool)$this->oldimgs
;
47 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
52 $wgOut->showErrorPage( 'revdelete-toomanytargets-title', 'revdelete-toomanytargets-text' );
55 $this->page
= Title
::newFromUrl( $this->target
);
56 # If we have revisions, get the title from the first one
57 # since they should all be from the same page. This allows
58 # for more flexibility with page moves...
59 if( count($this->oldids
) > 0 ) {
60 $rev = Revision
::newFromId( $this->oldids
[0] );
61 $this->page
= $rev ?
$rev->getTitle() : $this->page
;
63 # We need a target page!
64 if( is_null($this->page
) ) {
65 $wgOut->addWikiMsg( 'undelete-header' );
68 # Logs must have a type given
69 if( $this->logids
&& !strpos($this->page
->getDBKey(),'/') ) {
70 $wgOut->showErrorPage( 'revdelete-nologtype-title', 'revdelete-nologtype-text' );
73 # For reviewing deleted files...show it now if allowed
75 $oimage = RepoGroup
::singleton()->getLocalRepo()->newFromArchiveName( $this->page
, $this->file
);
77 // Check if user is allowed to see this file
78 if( !$oimage->userCan(File
::DELETED_FILE
) ) {
79 $wgOut->permissionRequired( 'suppressrevision' );
81 $this->showFile( $this->file
);
85 # Give a link to the logs/hist for this page
86 if( !is_null($this->page
) && $this->page
->getNamespace() > -1 ) {
89 $logtitle = SpecialPage
::getTitleFor( 'Log' );
90 $links[] = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
91 wfArrayToCGI( array( 'page' => $this->page
->getPrefixedUrl() ) ) );
92 # Give a link to the page history
93 $links[] = $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml( 'pagehist' ),
94 wfArrayToCGI( array( 'action' => 'history' ) ) );
95 # Link to deleted edits
96 if( $wgUser->isAllowed('undelete') ) {
97 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
98 $links[] = $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
99 wfArrayToCGI( array( 'target' => $this->page
->getPrefixedDBkey() ) ) );
101 # Logs themselves don't have histories or archived revisions
102 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
104 # Lock the operation and the form context
105 $this->secureOperation();
106 # Either submit or create our form
107 if( $this->wasPosted
) {
108 $this->submit( $wgRequest );
109 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
111 } else if( $this->deleteKey
== 'fileid' ||
$this->deleteKey
== 'oldimage' ) {
113 } else if( $this->deleteKey
== 'logid' ) {
114 $this->showLogItems();
116 # Show relevant lines from the deletion log
117 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'delete' ) ) . "</h2>\n" );
118 LogEventsList
::showLogExtract( $wgOut, 'delete', $this->page
->getPrefixedText() );
119 # Show relevant lines from the suppression log
120 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
121 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'suppress' ) ) . "</h2>\n" );
122 LogEventsList
::showLogExtract( $wgOut, 'suppress', $this->page
->getPrefixedText() );
126 private function secureOperation() {
128 $this->deleteKey
= '';
129 // At this point, we should only have one of these
130 if( $this->oldids
) {
131 $this->revisions
= $this->oldids
;
132 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
133 $this->deleteKey
= 'oldid';
134 } else if( $this->artimestamps
) {
135 $this->archrevs
= $this->artimestamps
;
136 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
137 $this->deleteKey
= 'artimestamp';
138 } else if( $this->oldimgs
) {
139 $this->ofiles
= $this->oldimgs
;
140 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
141 $this->deleteKey
= 'oldimage';
142 } else if( $this->fileids
) {
143 $this->afiles
= $this->fileids
;
144 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
145 $this->deleteKey
= 'fileid';
146 } else if( $this->logids
) {
147 $this->events
= $this->logids
;
148 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage
::DELETED_ACTION
);
149 $this->deleteKey
= 'logid';
151 // Our checkbox messages depends one what we are doing,
152 // e.g. we don't hide "text" for logs or images
153 $this->checks
= array(
155 array( 'revdelete-hide-comment', 'wpHideComment', Revision
::DELETED_COMMENT
),
156 array( 'revdelete-hide-user', 'wpHideUser', Revision
::DELETED_USER
)
158 if( $wgUser->isAllowed('suppressrevision') ) {
159 $this->checks
[] = array( 'revdelete-hide-restricted',
160 'wpHideRestricted', Revision
::DELETED_RESTRICTED
);
165 * Show a deleted file version requested by the visitor.
167 private function showFile( $key ) {
168 global $wgOut, $wgRequest;
171 # We mustn't allow the output to be Squid cached, otherwise
172 # if an admin previews a deleted image, and it's cached, then
173 # a user without appropriate permissions can toddle off and
174 # nab the image, and Squid will serve it
175 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
176 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
177 $wgRequest->response()->header( 'Pragma: no-cache' );
179 $store = FileStore
::get( 'deleted' );
180 $store->stream( $key );
184 * This lets a user set restrictions for live and archived revisions
186 private function showRevs() {
187 global $wgOut, $wgUser;
190 $count = ($this->deleteKey
=='oldid') ?
191 count($this->revisions
) : count($this->archrevs
);
192 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(), $count );
195 $wgOut->addHTML( "<ul>" );
197 $where = $revObjs = array();
198 $dbr = wfGetDB( DB_MASTER
);
202 if( $this->deleteKey
=='oldid' ) {
203 // Run through and pull all our data in one query
204 foreach( $this->revisions
as $revid ) {
205 $where[] = intval($revid);
207 $result = $dbr->select( array('revision','page'), '*',
209 'rev_page' => $this->page
->getArticleID(),
211 'rev_page = page_id' ),
213 while( $row = $dbr->fetchObject( $result ) ) {
214 $revObjs[$row->rev_id
] = new Revision( $row );
216 foreach( $this->revisions
as $revid ) {
217 // Hiding top revisison is bad
218 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
220 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
221 // If a rev is hidden from sysops
222 if( !$this->wasPosted
) {
223 $wgOut->permissionRequired( 'suppressrevision' );
226 $UserAllowed = false;
229 $wgOut->addHTML( $this->historyLine( $revObjs[$revid] ) );
230 $bitfields |
= $revObjs[$revid]->mDeleted
;
234 // Run through and pull all our data in one query
235 foreach( $this->archrevs
as $timestamp ) {
236 $where[] = $dbr->timestamp( $timestamp );
238 $result = $dbr->select( 'archive', '*',
240 'ar_namespace' => $this->page
->getNamespace(),
241 'ar_title' => $this->page
->getDBKey(),
242 'ar_timestamp' => $where ),
244 while( $row = $dbr->fetchObject( $result ) ) {
245 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
246 $revObjs[$timestamp] = new Revision( array(
247 'page' => $this->page
->getArticleId(),
248 'id' => $row->ar_rev_id
,
249 'text' => $row->ar_text_id
,
250 'comment' => $row->ar_comment
,
251 'user' => $row->ar_user
,
252 'user_text' => $row->ar_user_text
,
253 'timestamp' => $timestamp,
254 'minor_edit' => $row->ar_minor_edit
,
255 'text_id' => $row->ar_text_id
,
256 'deleted' => $row->ar_deleted
,
257 'len' => $row->ar_len
) );
259 foreach( $this->archrevs
as $timestamp ) {
260 if( !isset($revObjs[$timestamp]) ) {
262 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
263 // If a rev is hidden from sysops
264 if( !$this->wasPosted
) {
265 $wgOut->permissionRequired( 'suppressrevision' );
268 $UserAllowed = false;
271 $wgOut->addHTML( $this->historyLine( $revObjs[$timestamp] ) );
272 $bitfields |
= $revObjs[$timestamp]->mDeleted
;
276 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
280 $wgOut->addHTML( "</ul>" );
282 $this->addUsageText();
284 // Normal sysops can always see what they did, but can't always change it
285 if( !$UserAllowed ) return;
288 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
289 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
292 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
293 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
294 Xml
::hidden( 'type', $this->deleteKey
)
296 if( $this->deleteKey
=='oldid' ) {
297 $hidden[] = Xml
::hidden( 'oldid', implode(',',$this->oldids
) );
299 $hidden[] = Xml
::hidden( 'artimestamp', implode(',',$this->artimestamps
) );
301 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
303 Xml
::openElement( 'form', array( 'method' => 'post',
304 'action' => $special->getLocalUrl( 'action=submit' ),
305 'id' => 'mw-revdel-form-revisions' ) ) .
306 Xml
::openElement( 'fieldset' ) .
307 xml
::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
310 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
311 foreach( $items as $item ) {
312 $wgOut->addHTML( Xml
::tags( 'p', null, $item ) );
314 foreach( $hidden as $item ) {
315 $wgOut->addHTML( $item );
318 Xml
::closeElement( 'fieldset' ) .
319 Xml
::closeElement( 'form' ) . "\n"
324 * This lets a user set restrictions for archived images
326 private function showImages() {
327 global $wgOut, $wgUser, $wgLang;
330 $count = ($this->deleteKey
=='oldimage') ?
count($this->ofiles
) : count($this->afiles
);
331 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(),
332 $wgLang->formatNum($count) );
335 $wgOut->addHTML( "<ul>" );
337 $where = $filesObjs = array();
338 $dbr = wfGetDB( DB_MASTER
);
339 // Live old revisions...
341 if( $this->deleteKey
=='oldimage' ) {
342 // Run through and pull all our data in one query
343 foreach( $this->ofiles
as $timestamp ) {
344 $where[] = $timestamp.'!'.$this->page
->getDBKey();
346 $result = $dbr->select( 'oldimage', '*',
348 'oi_name' => $this->page
->getDBKey(),
349 'oi_archive_name' => $where ),
351 while( $row = $dbr->fetchObject( $result ) ) {
352 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
353 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
354 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
356 // Check through our images
357 foreach( $this->ofiles
as $timestamp ) {
358 $archivename = $timestamp.'!'.$this->page
->getDBKey();
359 if( !isset($filesObjs[$archivename]) ) {
361 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
362 // If a rev is hidden from sysops
363 if( !$this->wasPosted
) {
364 $wgOut->permissionRequired( 'suppressrevision' );
367 $UserAllowed = false;
370 // Inject history info
371 $wgOut->addHTML( $this->fileLine( $filesObjs[$archivename] ) );
372 $bitfields |
= $filesObjs[$archivename]->deleted
;
376 // Run through and pull all our data in one query
377 foreach( $this->afiles
as $id ) {
378 $where[] = intval($id);
380 $result = $dbr->select( 'filearchive', '*',
382 'fa_name' => $this->page
->getDBKey(),
385 while( $row = $dbr->fetchObject( $result ) ) {
386 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
389 foreach( $this->afiles
as $fileid ) {
390 if( !isset($filesObjs[$fileid]) ) {
392 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
393 // If a rev is hidden from sysops
394 if( !$this->wasPosted
) {
395 $wgOut->permissionRequired( 'suppressrevision' );
398 $UserAllowed = false;
401 // Inject history info
402 $wgOut->addHTML( $this->archivedfileLine( $filesObjs[$fileid] ) );
403 $bitfields |
= $filesObjs[$fileid]->deleted
;
407 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
411 $wgOut->addHTML( "</ul>" );
413 $this->addUsageText();
414 // Normal sysops can always see what they did, but can't always change it
415 if( !$UserAllowed ) return;
418 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
419 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
422 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
423 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
424 Xml
::hidden( 'type', $this->deleteKey
)
426 if( $this->deleteKey
=='oldimage' ) {
427 $hidden[] = Xml
::hidden( 'oldimage', implode(',',$this->oldimgs
) );
429 $hidden[] = Xml
::hidden( 'fileid', implode(',',$this->fileids
) );
431 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
433 Xml
::openElement( 'form', array( 'method' => 'post',
434 'action' => $special->getLocalUrl( 'action=submit' ),
435 'id' => 'mw-revdel-form-filerevisions' )
437 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
440 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
441 foreach( $items as $item ) {
442 $wgOut->addHTML( "<p>$item</p>" );
444 foreach( $hidden as $item ) {
445 $wgOut->addHTML( $item );
449 Xml
::closeElement( 'fieldset' ) .
450 Xml
::closeElement( 'form' ) . "\n"
455 * This lets a user set restrictions for log items
457 private function showLogItems() {
458 global $wgOut, $wgUser, $wgMessageCache, $wgLang;
461 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->events
) ) );
464 $wgOut->addHTML( "<ul>" );
466 $where = $logRows = array();
467 $dbr = wfGetDB( DB_MASTER
);
468 // Run through and pull all our data in one query
470 foreach( $this->events
as $logid ) {
471 $where[] = intval($logid);
473 list($log,$logtype) = explode( '/',$this->page
->getDBKey(), 2 );
474 $result = $dbr->select( 'logging', '*',
476 'log_type' => $logtype,
477 'log_id' => $where ),
479 while( $row = $dbr->fetchObject( $result ) ) {
480 $logRows[$row->log_id
] = $row;
482 $wgMessageCache->loadAllMessages();
483 foreach( $this->events
as $logid ) {
484 // Don't hide from oversight log!!!
485 if( !isset( $logRows[$logid] ) ||
$logRows[$logid]->log_type
=='suppress' ) {
487 } else if( !LogEventsList
::userCan( $logRows[$logid],Revision
::DELETED_RESTRICTED
) ) {
488 // If an event is hidden from sysops
489 if( !$this->wasPosted
) {
490 $wgOut->permissionRequired( 'suppressrevision' );
493 $UserAllowed = false;
496 $wgOut->addHTML( $this->logLine( $logRows[$logid] ) );
497 $bitfields |
= $logRows[$logid]->log_deleted
;
500 $wgOut->showErrorPage( 'revdelete-nologid-title', 'revdelete-nologid-text' );
504 $wgOut->addHTML( "</ul>" );
506 $this->addUsageText();
507 // Normal sysops can always see what they did, but can't always change it
508 if( !$UserAllowed ) return;
511 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
512 Xml
::submitButton( wfMsg( 'revdelete-submit' ) ) );
514 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
515 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
516 Xml
::hidden( 'type', $this->deleteKey
),
517 Xml
::hidden( 'logid', implode(',',$this->logids
) )
520 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
522 Xml
::openElement( 'form', array( 'method' => 'post',
523 'action' => $special->getLocalUrl( 'action=submit' ), 'id' => 'mw-revdel-form-logs' ) ) .
524 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
527 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
528 foreach( $items as $item ) {
529 $wgOut->addHTML( "<p>$item</p>" );
531 foreach( $hidden as $item ) {
532 $wgOut->addHTML( $item );
536 Xml
::closeElement( 'fieldset' ) .
537 Xml
::closeElement( 'form' ) . "\n"
541 private function addUsageText() {
542 global $wgOut, $wgUser;
543 $wgOut->addWikiMsg( 'revdelete-text' );
544 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
545 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
550 * @param int $bitfields, aggregate bitfield of all the bitfields
551 * @returns string HTML
553 private function buildCheckBoxes( $bitfields ) {
555 // FIXME: all items checked for just one rev are checked, even if not set for the others
556 foreach( $this->checks
as $item ) {
557 list( $message, $name, $field ) = $item;
558 $line = Xml
::tags( 'div', null, Xml
::checkLabel( wfMsg($message), $name, $name,
559 $bitfields & $field ) );
560 if( $field == Revision
::DELETED_RESTRICTED
) $line = "<b>$line</b>";
567 * @param Revision $rev
570 private function historyLine( $rev ) {
571 global $wgLang, $wgUser;
573 $date = $wgLang->timeanddate( $rev->getTimestamp() );
574 $difflink = $del = '';
576 if( $this->deleteKey
=='oldid' ) {
577 $tokenParams = '&unhide=1&token='.urlencode( $wgUser->editToken( $rev->getId() ) );
578 $revlink = $this->skin
->makeLinkObj( $this->page
, $date, 'oldid='.$rev->getId() . $tokenParams );
579 $difflink = '(' . $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml('diff'),
580 'diff=' . $rev->getId() . '&oldid=prev' . $tokenParams ) . ')';
581 // Archived revisions
583 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
584 $target = $this->page
->getPrefixedText();
585 $revlink = $this->skin
->makeLinkObj( $undelete, $date,
586 "target=$target×tamp=" . $rev->getTimestamp() );
587 $difflink = '(' . $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml('diff'),
588 "target=$target&diff=prev×tamp=" . $rev->getTimestamp() ) . ')';
590 // Check permissions; items may be "suppressed"
591 if( $rev->isDeleted(Revision
::DELETED_TEXT
) ) {
592 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
593 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
594 if( !$rev->userCan(Revision
::DELETED_TEXT
) ) {
595 $revlink = '<span class="history-deleted">'.$date.'</span>';
596 $difflink = '(' . wfMsgHtml('diff') . ')';
599 $userlink = $this->skin
->revUserLink( $rev );
600 $comment = $this->skin
->revComment( $rev );
602 return "<li>$difflink $revlink $userlink $comment{$del}</li>";
609 private function fileLine( $file ) {
610 global $wgLang, $wgTitle;
612 $target = $this->page
->getPrefixedText();
613 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
617 if( $file->isDeleted(File
::DELETED_FILE
) ) {
618 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
619 if( !$file->userCan(File
::DELETED_FILE
) ) {
622 $pageLink = $this->skin
->makeKnownLinkObj( $wgTitle, $date,
623 "target=$target&file=$file->sha1.".$file->getExtension() );
625 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
628 $url = $file->getUrlRel();
629 $pageLink = "<a href=\"{$url}\">{$date}</a>";
632 $data = wfMsg( 'widthheight',
633 $wgLang->formatNum( $file->getWidth() ),
634 $wgLang->formatNum( $file->getHeight() ) ) .
635 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
636 $data = htmlspecialchars( $data );
638 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
642 * @param ArchivedFile $file
645 private function archivedfileLine( $file ) {
648 $target = $this->page
->getPrefixedText();
649 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
651 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
652 $pageLink = $this->skin
->makeKnownLinkObj( $undelete, $date, "target=$target&file={$file->getKey()}" );
655 if( $file->isDeleted(File
::DELETED_FILE
) ) {
656 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
659 $data = wfMsg( 'widthheight',
660 $wgLang->formatNum( $file->getWidth() ),
661 $wgLang->formatNum( $file->getHeight() ) ) .
662 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
663 $data = htmlspecialchars( $data );
665 return "<li> $pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
669 * @param Array $row row
672 private function logLine( $row ) {
675 $date = $wgLang->timeanddate( $row->log_timestamp
);
676 $paramArray = LogPage
::extractParams( $row->log_params
);
677 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
679 $logtitle = SpecialPage
::getTitleFor( 'Log' );
680 $loglink = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
681 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
683 if( !LogEventsList
::userCan($row,LogPage
::DELETED_ACTION
) ) {
684 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
686 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
687 $this->skin
, $paramArray, true, true );
688 if( $row->log_deleted
& LogPage
::DELETED_ACTION
)
689 $action = '<span class="history-deleted">' . $action . '</span>';
692 $userLink = $this->skin
->userLink( $row->log_user
, User
::WhoIs($row->log_user
) );
693 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_USER
) ) {
694 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
697 $comment = $wgLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
698 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
699 $comment = '<span class="history-deleted">' . $comment . '</span>';
701 return "<li>($loglink) $date $userLink $action $comment</li>";
705 * Generate a user tool link cluster if the current user is allowed to view it
706 * @param ArchivedFile $file
707 * @return string HTML
709 private function fileUserTools( $file ) {
710 if( $file->userCan( Revision
::DELETED_USER
) ) {
711 $link = $this->skin
->userLink( $file->user
, $file->user_text
) .
712 $this->skin
->userToolLinks( $file->user
, $file->user_text
);
714 $link = wfMsgHtml( 'rev-deleted-user' );
716 if( $file->isDeleted( Revision
::DELETED_USER
) ) {
717 return '<span class="history-deleted">' . $link . '</span>';
723 * Wrap and format the given file's comment block, if the current
724 * user is allowed to view it.
726 * @param ArchivedFile $file
727 * @return string HTML
729 private function fileComment( $file ) {
730 if( $file->userCan( File
::DELETED_COMMENT
) ) {
731 $block = $this->skin
->commentBlock( $file->description
);
733 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
735 if( $file->isDeleted( File
::DELETED_COMMENT
) ) {
736 return "<span class=\"history-deleted\">$block</span>";
742 * @param WebRequest $request
744 private function submit( $request ) {
745 global $wgUser, $wgOut;
746 # Check edit token on submission
747 if( $this->wasPosted
&& !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
748 $wgOut->addWikiMsg( 'sessionfailure' );
751 $bitfield = $this->extractBitfield( $request );
752 $comment = $request->getText( 'wpReason' );
753 # Can the user set this field?
754 if( $bitfield & Revision
::DELETED_RESTRICTED
&& !$wgUser->isAllowed('suppressrevision') ) {
755 $wgOut->permissionRequired( 'suppressrevision' );
758 # If the save went through, go to success message. Otherwise
759 # bounce back to form...
760 if( $this->save( $bitfield, $comment, $this->page
) ) {
762 } else if( $request->getCheck( 'oldid' ) ||
$request->getCheck( 'artimestamp' ) ) {
763 return $this->showRevs();
764 } else if( $request->getCheck( 'logid' ) ) {
765 return $this->showLogs();
766 } else if( $request->getCheck( 'oldimage' ) ||
$request->getCheck( 'fileid' ) ) {
767 return $this->showImages();
771 private function success() {
774 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
776 $wrap = '<span class="success">$1</span>';
778 if( $this->deleteKey
=='logid' ) {
779 $wgOut->wrapWikiMsg( $wrap, 'logdelete-success' );
780 $this->showLogItems();
781 } else if( $this->deleteKey
=='oldid' ||
$this->deleteKey
=='artimestamp' ) {
782 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
784 } else if( $this->deleteKey
=='fileid' ) {
785 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
787 } else if( $this->deleteKey
=='oldimage' ) {
788 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
794 * Put together a rev_deleted bitfield from the submitted checkboxes
795 * @param WebRequest $request
798 private function extractBitfield( $request ) {
800 foreach( $this->checks
as $item ) {
801 list( /* message */ , $name, $field ) = $item;
802 if( $request->getCheck( $name ) ) {
809 private function save( $bitfield, $reason, $title ) {
810 $dbw = wfGetDB( DB_MASTER
);
811 // Don't allow simply locking the interface for no reason
812 if( $bitfield == Revision
::DELETED_RESTRICTED
) {
815 $deleter = new RevisionDeleter( $dbw );
816 // By this point, only one of the below should be set
817 if( isset($this->revisions
) ) {
818 return $deleter->setRevVisibility( $title, $this->revisions
, $bitfield, $reason );
819 } else if( isset($this->archrevs
) ) {
820 return $deleter->setArchiveVisibility( $title, $this->archrevs
, $bitfield, $reason );
821 } else if( isset($this->ofiles
) ) {
822 return $deleter->setOldImgVisibility( $title, $this->ofiles
, $bitfield, $reason );
823 } else if( isset($this->afiles
) ) {
824 return $deleter->setArchFileVisibility( $title, $this->afiles
, $bitfield, $reason );
825 } else if( isset($this->events
) ) {
826 return $deleter->setEventVisibility( $title, $this->events
, $bitfield, $reason );
832 * Implements the actions for Revision Deletion.
833 * @ingroup SpecialPage
835 class RevisionDeleter
{
836 function __construct( $db ) {
841 * @param $title, the page these events apply to
842 * @param array $items list of revision ID numbers
843 * @param int $bitfield new rev_deleted value
844 * @param string $comment Comment for log records
846 function setRevVisibility( $title, $items, $bitfield, $comment ) {
849 $userAllowedAll = $success = true;
852 // Run through and pull all our data in one query
853 foreach( $items as $revid ) {
854 $where[] = intval($revid);
856 $result = $this->dbw
->select( 'revision', '*',
858 'rev_page' => $title->getArticleID(),
859 'rev_id' => $where ),
861 while( $row = $this->dbw
->fetchObject( $result ) ) {
862 $revObjs[$row->rev_id
] = new Revision( $row );
865 foreach( $items as $revid ) {
866 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
868 continue; // Must exist
869 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
870 $userAllowedAll=false;
873 // For logging, maintain a count of revisions
874 if( $revObjs[$revid]->mDeleted
!= $bitfield ) {
878 $this->updateRevision( $revObjs[$revid], $bitfield );
879 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
883 // Don't log or touch if nothing changed
884 if( $revCount > 0 ) {
885 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted
,
886 $comment, $title, 'oldid', $revIDs );
887 $this->updatePage( $title );
889 // Where all revs allowed to be set?
890 if( !$userAllowedAll ) {
891 //FIXME: still might be confusing???
892 $wgOut->permissionRequired( 'suppressrevision' );
900 * @param $title, the page these events apply to
901 * @param array $items list of revision ID numbers
902 * @param int $bitfield new rev_deleted value
903 * @param string $comment Comment for log records
905 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
908 $userAllowedAll = $success = true;
911 // Run through and pull all our data in one query
912 foreach( $items as $timestamp ) {
913 $where[] = $this->dbw
->timestamp( $timestamp );
915 $result = $this->dbw
->select( 'archive', '*',
917 'ar_namespace' => $title->getNamespace(),
918 'ar_title' => $title->getDBKey(),
919 'ar_timestamp' => $where ),
921 while( $row = $this->dbw
->fetchObject( $result ) ) {
922 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
923 $revObjs[$timestamp] = new Revision( array(
924 'page' => $title->getArticleId(),
925 'id' => $row->ar_rev_id
,
926 'text' => $row->ar_text_id
,
927 'comment' => $row->ar_comment
,
928 'user' => $row->ar_user
,
929 'user_text' => $row->ar_user_text
,
930 'timestamp' => $timestamp,
931 'minor_edit' => $row->ar_minor_edit
,
932 'text_id' => $row->ar_text_id
,
933 'deleted' => $row->ar_deleted
,
934 'len' => $row->ar_len
) );
937 foreach( $items as $timestamp ) {
938 // This will only select the first revision with this timestamp.
939 // Since they are all selected/deleted at once, we can just check the
940 // permissions of one. UPDATE is done via timestamp, so all revs are set.
941 if( !is_object($revObjs[$timestamp]) ) {
943 continue; // Must exist
944 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
945 $userAllowedAll=false;
948 // Which revisions did we change anything about?
949 if( $revObjs[$timestamp]->mDeleted
!= $bitfield ) {
950 $Id_set[]=$timestamp;
953 $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
956 // For logging, maintain a count of revisions
958 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted
,
959 $comment, $title, 'artimestamp', $Id_set );
961 // Where all revs allowed to be set?
962 if( !$userAllowedAll ) {
963 $wgOut->permissionRequired( 'suppressrevision' );
971 * @param $title, the page these events apply to
972 * @param array $items list of revision ID numbers
973 * @param int $bitfield new rev_deleted value
974 * @param string $comment Comment for log records
976 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
979 $userAllowedAll = $success = true;
982 // Run through and pull all our data in one query
983 foreach( $items as $timestamp ) {
984 $where[] = $timestamp.'!'.$title->getDBKey();
986 $result = $this->dbw
->select( 'oldimage', '*',
988 'oi_name' => $title->getDBKey(),
989 'oi_archive_name' => $where ),
991 while( $row = $this->dbw
->fetchObject( $result ) ) {
992 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
993 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
994 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
997 foreach( $items as $timestamp ) {
998 $archivename = $timestamp.'!'.$title->getDBKey();
999 if( !isset($filesObjs[$archivename]) ) {
1001 continue; // Must exist
1002 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
1003 $userAllowedAll=false;
1007 $transaction = true;
1008 // Which revisions did we change anything about?
1009 if( $filesObjs[$archivename]->deleted
!= $bitfield ) {
1012 $this->dbw
->begin();
1013 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
1014 // If this image is currently hidden...
1015 if( $filesObjs[$archivename]->deleted
& File
::DELETED_FILE
) {
1016 if( $bitfield & File
::DELETED_FILE
) {
1017 # Leave it alone if we are not changing this...
1019 $transaction = true;
1021 # We are moving this out
1022 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
1023 $set[]=$transaction;
1025 // Is it just now becoming hidden?
1026 } else if( $bitfield & File
::DELETED_FILE
) {
1027 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
1028 $set[]=$transaction;
1032 // If our file operations fail, then revert back the db
1033 if( $transaction==false ) {
1034 $this->dbw
->rollback();
1037 $this->dbw
->commit();
1041 // Log if something was changed
1043 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted
,
1044 $comment, $title, 'oldimage', $set );
1045 # Purge page/history
1046 $file = wfLocalFile( $title );
1047 $file->purgeCache();
1048 $file->purgeHistory();
1049 # Invalidate cache for all pages using this file
1050 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
1051 $update->doUpdate();
1053 // Where all revs allowed to be set?
1054 if( !$userAllowedAll ) {
1055 $wgOut->permissionRequired( 'suppressrevision' );
1063 * @param $title, the page these events apply to
1064 * @param array $items list of revision ID numbers
1065 * @param int $bitfield new rev_deleted value
1066 * @param string $comment Comment for log records
1068 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
1071 $userAllowedAll = $success = true;
1075 // Run through and pull all our data in one query
1076 foreach( $items as $id ) {
1077 $where[] = intval($id);
1079 $result = $this->dbw
->select( 'filearchive', '*',
1080 array( 'fa_name' => $title->getDBKey(),
1081 'fa_id' => $where ),
1083 while( $row = $this->dbw
->fetchObject( $result ) ) {
1084 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
1087 foreach( $items as $fileid ) {
1088 if( !isset($filesObjs[$fileid]) ) {
1090 continue; // Must exist
1091 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
1092 $userAllowedAll=false;
1095 // Which revisions did we change anything about?
1096 if( $filesObjs[$fileid]->deleted
!= $bitfield ) {
1100 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1103 // Log if something was changed
1105 $this->updateLog( $title, $count, $bitfield, $comment,
1106 $filesObjs[$fileid]->deleted
, $title, 'fileid', $Id_set );
1108 // Where all revs allowed to be set?
1109 if( !$userAllowedAll ) {
1110 $wgOut->permissionRequired( 'suppressrevision' );
1118 * @param $title, the log page these events apply to
1119 * @param array $items list of log ID numbers
1120 * @param int $bitfield new log_deleted value
1121 * @param string $comment Comment for log records
1123 function setEventVisibility( $title, $items, $bitfield, $comment ) {
1126 $userAllowedAll = $success = true;
1130 // Run through and pull all our data in one query
1131 foreach( $items as $logid ) {
1132 $where[] = intval($logid);
1134 list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
1135 $result = $this->dbw
->select( 'logging', '*',
1137 'log_type' => $logtype,
1138 'log_id' => $where ),
1140 while( $row = $this->dbw
->fetchObject( $result ) ) {
1141 $logRows[$row->log_id
] = $row;
1144 foreach( $items as $logid ) {
1145 if( !isset($logRows[$logid]) ) {
1147 continue; // Must exist
1148 } else if( !LogEventsList
::userCan($logRows[$logid], LogPage
::DELETED_RESTRICTED
)
1149 ||
$logRows[$logid]->log_type
== 'suppress' ) {
1150 // Don't hide from oversight log!!!
1151 $userAllowedAll=false;
1154 // Which logs did we change anything about?
1155 if( $logRows[$logid]->log_deleted
!= $bitfield ) {
1159 $this->updateLogs( $logRows[$logid], $bitfield );
1160 $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
1163 // Don't log or touch if nothing changed
1165 $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted
,
1166 $comment, $title, 'logid', $log_Ids );
1168 // Were all revs allowed to be set?
1169 if( !$userAllowedAll ) {
1170 $wgOut->permissionRequired( 'suppressrevision' );
1178 * Moves an image to a safe private location
1179 * Caller is responsible for clearing caches
1180 * @param File $oimage
1181 * @returns mixed, timestamp string on success, false on failure
1183 function makeOldImagePrivate( $oimage ) {
1184 $transaction = new FSTransaction();
1185 if( !FileStore
::lock() ) {
1186 wfDebug( __METHOD__
.": failed to acquire file store lock, aborting\n" );
1189 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1190 // Dupe the file into the file store
1191 if( file_exists( $oldpath ) ) {
1192 // Is our directory configured?
1193 if( $store = FileStore
::get( 'deleted' ) ) {
1194 if( !$oimage->sha1
) {
1195 $oimage->upgradeRow(); // sha1 may be missing
1197 $key = $oimage->sha1
. '.' . $oimage->getExtension();
1198 $transaction->add( $store->insert( $key, $oldpath, FileStore
::DELETE_ORIGINAL
) );
1202 $transaction = false; // Return an error and do nothing
1205 wfDebug( __METHOD__
." deleting already-missing '$oldpath'; moving on to database\n" );
1208 $transaction = new FSTransaction(); // empty
1211 if( $transaction === false ) {
1213 wfDebug( __METHOD__
.": import to file store failed, aborting\n" );
1214 throw new MWException( "Could not archive and delete file $oldpath" );
1218 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1219 $transaction->commit();
1220 FileStore
::unlock();
1222 $m = explode('!',$oimage->archive_name
,2);
1229 * Moves an image from a safe private location
1230 * Caller is responsible for clearing caches
1231 * @param File $oimage
1232 * @returns mixed, string timestamp on success, false on failure
1234 function makeOldImagePublic( $oimage ) {
1235 $transaction = new FSTransaction();
1236 if( !FileStore
::lock() ) {
1237 wfDebug( __METHOD__
." could not acquire filestore lock\n" );
1241 $store = FileStore
::get( 'deleted' );
1243 wfDebug( __METHOD__
.": skipping row with no file.\n" );
1247 $key = $oimage->sha1
.'.'.$oimage->getExtension();
1248 $destDir = $oimage->getArchivePath();
1249 if( !is_dir( $destDir ) ) {
1250 wfMkdirParents( $destDir );
1252 $destPath = $destDir . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1253 // Check if any other stored revisions use this file;
1254 // if so, we shouldn't remove the file from the hidden
1255 // archives so they will still work. Check hidden files first.
1256 $useCount = $this->dbw
->selectField( 'oldimage', '1',
1257 array( 'oi_sha1' => $oimage->sha1
,
1258 'oi_deleted & '.File
::DELETED_FILE
=> File
::DELETED_FILE
),
1259 __METHOD__
, array( 'FOR UPDATE' ) );
1260 // Check the rest of the deleted archives too.
1261 // (these are the ones that don't show in the image history)
1263 $useCount = $this->dbw
->selectField( 'filearchive', '1',
1264 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1265 __METHOD__
, array( 'FOR UPDATE' ) );
1268 if( $useCount == 0 ) {
1269 wfDebug( __METHOD__
.": nothing else using {$oimage->sha1}, will deleting after\n" );
1270 $flags = FileStore
::DELETE_ORIGINAL
;
1274 $transaction->add( $store->export( $key, $destPath, $flags ) );
1276 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1277 $transaction->commit();
1278 FileStore
::unlock();
1280 $m = explode('!',$oimage->archive_name
,2);
1287 * Update the revision's rev_deleted field
1288 * @param Revision $rev
1289 * @param int $bitfield new rev_deleted bitfield value
1291 function updateRevision( $rev, $bitfield ) {
1292 $this->dbw
->update( 'revision',
1293 array( 'rev_deleted' => $bitfield ),
1294 array( 'rev_id' => $rev->getId(),
1295 'rev_page' => $rev->getPage() ),
1300 * Update the revision's rev_deleted field
1301 * @param Revision $rev
1302 * @param Title $title
1303 * @param int $bitfield new rev_deleted bitfield value
1305 function updateArchive( $rev, $title, $bitfield ) {
1306 $this->dbw
->update( 'archive',
1307 array( 'ar_deleted' => $bitfield ),
1308 array( 'ar_namespace' => $title->getNamespace(),
1309 'ar_title' => $title->getDBKey(),
1310 'ar_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ),
1311 'ar_rev_id' => $rev->getId() ),
1316 * Update the images's oi_deleted field
1318 * @param int $bitfield new rev_deleted bitfield value
1320 function updateOldFiles( $file, $bitfield ) {
1321 $this->dbw
->update( 'oldimage',
1322 array( 'oi_deleted' => $bitfield ),
1323 array( 'oi_name' => $file->getName(),
1324 'oi_timestamp' => $this->dbw
->timestamp( $file->getTimestamp() ) ),
1329 * Update the images's fa_deleted field
1330 * @param ArchivedFile $file
1331 * @param int $bitfield new rev_deleted bitfield value
1333 function updateArchFiles( $file, $bitfield ) {
1334 $this->dbw
->update( 'filearchive',
1335 array( 'fa_deleted' => $bitfield ),
1336 array( 'fa_id' => $file->getId() ),
1341 * Update the logging log_deleted field
1343 * @param int $bitfield new rev_deleted bitfield value
1345 function updateLogs( $row, $bitfield ) {
1346 $this->dbw
->update( 'logging',
1347 array( 'log_deleted' => $bitfield ),
1348 array( 'log_id' => $row->log_id
),
1353 * Update the revision's recentchanges record if fields have been hidden
1354 * @param Revision $rev
1355 * @param int $bitfield new rev_deleted bitfield value
1357 function updateRecentChangesEdits( $rev, $bitfield ) {
1358 $this->dbw
->update( 'recentchanges',
1359 array( 'rc_deleted' => $bitfield,
1360 'rc_patrolled' => 1 ),
1361 array( 'rc_this_oldid' => $rev->getId(),
1362 'rc_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ) ),
1367 * Update the revision's recentchanges record if fields have been hidden
1369 * @param int $bitfield new rev_deleted bitfield value
1371 function updateRecentChangesLog( $row, $bitfield ) {
1372 $this->dbw
->update( 'recentchanges',
1373 array( 'rc_deleted' => $bitfield,
1374 'rc_patrolled' => 1 ),
1375 array( 'rc_logid' => $row->log_id
,
1376 'rc_timestamp' => $row->log_timestamp
),
1381 * Touch the page's cache invalidation timestamp; this forces cached
1382 * history views to refresh, so any newly hidden or shown fields will
1384 * @param Title $title
1386 function updatePage( $title ) {
1387 $title->invalidateCache();
1388 $title->purgeSquid();
1389 $title->touchLinks();
1390 // Extensions that require referencing previous revisions may need this
1391 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1395 * Checks for a change in the bitfield for a certain option and updates the
1396 * provided array accordingly.
1398 * @param String $desc Description to add to the array if the option was
1399 * enabled / disabled.
1400 * @param int $field The bitmask describing the single option.
1401 * @param int $diff The xor of the old and new bitfields.
1402 * @param array $arr The array to update.
1404 function checkItem ( $desc, $field, $diff, $new, &$arr ) {
1405 if ( $diff & $field ) {
1406 $arr [ ( $new & $field ) ?
0 : 1 ][] = $desc;
1411 * Gets an array describing the changes made to the visibilit of the revision.
1412 * If the resulting array is $arr, then $arr[0] will contain an array of strings
1413 * describing the items that were hidden, $arr[2] will contain an array of strings
1414 * describing the items that were unhidden, and $arr[3] will contain an array with
1415 * a single string, which can be one of "applied restrictions to sysops",
1416 * "removed restrictions from sysops", or null.
1418 * @param int $n The new bitfield.
1419 * @param int $o The old bitfield.
1420 * @return An array as described above.
1422 function getChanges ( $n, $o ) {
1424 $ret = array ( 0 => array(), 1 => array(), 2 => array() );
1426 $this->checkItem ( wfMsgForContent ( 'revdelete-content' ),
1427 Revision
::DELETED_TEXT
, $diff, $n, $ret );
1428 $this->checkItem ( wfMsgForContent ( 'revdelete-summary' ),
1429 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
1430 $this->checkItem ( wfMsgForContent ( 'revdelete-uname' ),
1431 Revision
::DELETED_USER
, $diff, $n, $ret );
1433 // Restriction application to sysops
1434 if ( $diff & Revision
::DELETED_RESTRICTED
) {
1435 if ( $n & Revision
::DELETED_RESTRICTED
)
1436 $ret[2][] = wfMsgForContent ( 'revdelete-restricted' );
1438 $ret[2][] = wfMsgForContent ( 'revdelete-unrestricted' );
1445 * Gets a log message to describe the given revision visibility change. This
1446 * message will be of the form "[hid {content, edit summary, username}];
1447 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
1449 * @param int $count The number of effected revisions.
1450 * @param int $nbitfield The new bitfield for the revision.
1451 * @param int $obitfield The old bitfield for the revision.
1452 * @param string $comment The comment associated with the change.
1453 * @param bool $isForLog
1455 function getLogMessage ( $count, $nbitfield, $obitfield, $comment, $isForLog = false ) {
1459 $changes = $this->getChanges( $nbitfield, $obitfield );
1461 if ( count ( $changes[0] ) ) {
1462 $s .= wfMsgForContent ( 'revdelete-hid', implode ( ', ', $changes[0] ) );
1465 if ( count ( $changes[1] ) ) {
1468 $s .= wfMsgForContent ( 'revdelete-unhid', implode ( ', ', $changes[1] ) );
1471 if ( count ( $changes[2] )) {
1473 $s .= ' (' . $changes[2][0] . ')';
1475 $s = $changes[2][0];
1478 $msg = $isForLog ?
'logdelete-log-message' : 'revdelete-log-message';
1479 $ret = wfMsgExt ( $msg, array( 'parsemag', 'content' ),
1480 $s, $wgContLang->formatNum( $count ) );
1483 $ret .= ": $comment";
1490 * Record a log entry on the action
1491 * @param Title $title, page where item was removed from
1492 * @param int $count the number of revisions altered for this page
1493 * @param int $nbitfield the new _deleted value
1494 * @param int $obitfield the old _deleted value
1495 * @param string $comment
1496 * @param Title $target, the relevant page
1497 * @param string $param, URL param
1498 * @param Array $items
1500 function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target, $param, $items = array() ) {
1501 // Put things hidden from sysops in the oversight log
1502 $logtype = ( ($nbitfield |
$obitfield) & Revision
::DELETED_RESTRICTED
) ?
'suppress' : 'delete';
1503 $log = new LogPage( $logtype );
1505 $reason = $this->getLogMessage ( $count, $nbitfield, $obitfield, $comment, $param == 'logid' );
1507 if( $param == 'logid' ) {
1508 $params = array( implode( ',', $items) );
1509 $log->addEntry( 'event', $title, $reason, $params );
1511 // Add params for effected page and ids
1512 $params = array( $param, implode( ',', $items) );
1513 $log->addEntry( 'revision', $title, $reason, $params );