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 SpecialPage
{
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 # If this is a revision, then we need a target page
42 $this->page
= Title
::newFromUrl( $this->target
);
43 if( is_null($this->page
) ) {
44 $wgOut->addWikiMsg( 'undelete-header' );
47 # Only one target set at a time please!
48 $i = (bool)$this->file +
(bool)$this->oldids +
(bool)$this->logids
49 +
(bool)$this->artimestamps +
(bool)$this->fileids +
(bool)$this->oldimgs
;
51 $wgOut->showErrorPage( 'revdelete-toomanytargets-title', 'revdelete-toomanytargets-text' );
54 # Logs must have a type given
55 if( $this->logids
&& !strpos($this->page
->getDBKey(),'/') ) {
56 $wgOut->showErrorPage( 'revdelete-nologtype-title', 'revdelete-nologtype-text' );
59 # Check edit token on submission
60 if( $this->wasPosted
&& !$wgUser->matchEditToken( $wgRequest->getVal('wpEditToken') ) ) {
61 $wgOut->addWikiMsg( 'sessionfailure' );
64 # For reviewing deleted files...show it now if allowed
66 $oimage = RepoGroup
::singleton()->getLocalRepo()->newFromArchiveName( $this->page
, $this->file
);
68 // Check if user is allowed to see this file
69 if( !$oimage->userCan(File
::DELETED_FILE
) ) {
70 $wgOut->permissionRequired( 'suppressrevision' );
72 $this->showFile( $this->file
);
76 # Give a link to the logs/hist for this page
77 if( !is_null($this->page
) && $this->page
->getNamespace() > -1 ) {
80 $logtitle = SpecialPage
::getTitleFor( 'Log' );
81 $links[] = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
82 wfArrayToCGI( array( 'page' => $this->page
->getPrefixedUrl() ) ) );
83 # Give a link to the page history
84 $links[] = $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml( 'pagehist' ),
85 wfArrayToCGI( array( 'action' => 'history' ) ) );
86 # Link to deleted edits
87 if( $wgUser->isAllowed('undelete') ) {
88 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
89 $links[] = $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
90 wfArrayToCGI( array( 'target' => $this->page
->getPrefixedDBkey() ) ) );
92 # Logs themselves don't have histories or archived revisions
93 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
95 # Lock the operation and the form context
96 $this->secureOperation();
97 # Either submit or create our form
98 if( $this->wasPosted
) {
99 $this->submit( $wgRequest );
100 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
102 } else if( $this->deleteKey
== 'fileid' ||
$this->deleteKey
== 'oldimage' ) {
104 } else if( $this->deleteKey
== 'logid' ) {
105 $this->showLogItems();
107 # Show relevant lines from the deletion log. This will show even if said ID
108 # does not exist...might be helpful
109 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'delete' ) ) . "</h2>\n" );
110 LogEventsList
::showLogExtract( $wgOut, 'delete', $this->page
->getPrefixedText() );
111 if( $wgUser->isAllowed( 'suppressionlog' ) ){
112 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'suppress' ) ) . "</h2>\n" );
113 LogEventsList
::showLogExtract( $wgOut, 'suppress', $this->page
->getPrefixedText() );
117 private function secureOperation() {
119 $this->deleteKey
= '';
120 // At this point, we should only have one of these
121 if( $this->oldids
) {
122 $this->revisions
= $this->oldids
;
123 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
124 $this->deleteKey
= 'oldid';
125 } else if( $this->artimestamps
) {
126 $this->archrevs
= $this->artimestamps
;
127 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
128 $this->deleteKey
= 'artimestamp';
129 } else if( $this->oldimgs
) {
130 $this->ofiles
= $this->oldimgs
;
131 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
132 $this->deleteKey
= 'oldimage';
133 } else if( $this->fileids
) {
134 $this->afiles
= $this->fileids
;
135 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
136 $this->deleteKey
= 'fileid';
137 } else if( $this->logids
) {
138 $this->events
= $this->logids
;
139 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage
::DELETED_ACTION
);
140 $this->deleteKey
= 'logid';
142 // Our checkbox messages depends one what we are doing,
143 // e.g. we don't hide "text" for logs or images
144 $this->checks
= array(
146 array( 'revdelete-hide-comment', 'wpHideComment', Revision
::DELETED_COMMENT
),
147 array( 'revdelete-hide-user', 'wpHideUser', Revision
::DELETED_USER
)
149 if( $wgUser->isAllowed('suppressrevision') ) {
150 $this->checks
[] = array( 'revdelete-hide-restricted', 'wpHideRestricted', Revision
::DELETED_RESTRICTED
);
155 * Show a deleted file version requested by the visitor.
157 private function showFile( $key ) {
158 global $wgOut, $wgRequest;
161 # We mustn't allow the output to be Squid cached, otherwise
162 # if an admin previews a deleted image, and it's cached, then
163 # a user without appropriate permissions can toddle off and
164 # nab the image, and Squid will serve it
165 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
166 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
167 $wgRequest->response()->header( 'Pragma: no-cache' );
169 $store = FileStore
::get( 'deleted' );
170 $store->stream( $key );
174 * This lets a user set restrictions for live and archived revisions
176 private function showRevs() {
177 global $wgOut, $wgUser;
180 $count = ($this->deleteKey
=='oldid') ?
181 count($this->revisions
) : count($this->archrevs
);
182 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(), $count );
185 $wgOut->addHTML( "<ul>" );
187 $where = $revObjs = array();
188 $dbr = wfGetDB( DB_SLAVE
);
192 if( $this->deleteKey
=='oldid' ) {
193 // Run through and pull all our data in one query
194 foreach( $this->revisions
as $revid ) {
195 $where[] = intval($revid);
197 $result = $dbr->select( array('revision','page'), '*',
199 'rev_page' => $this->page
->getArticleID(),
201 'rev_page = page_id' ),
203 while( $row = $dbr->fetchObject( $result ) ) {
204 $revObjs[$row->rev_id
] = new Revision( $row );
206 foreach( $this->revisions
as $revid ) {
207 // Hiding top revisison is bad
208 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
210 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
211 // If a rev is hidden from sysops
212 if( !$this->wasPosted
) {
213 $wgOut->permissionRequired( 'suppressrevision' );
216 $UserAllowed = false;
219 $wgOut->addHTML( $this->historyLine( $revObjs[$revid] ) );
220 $bitfields |
= $revObjs[$revid]->mDeleted
;
224 // Run through and pull all our data in one query
225 foreach( $this->archrevs
as $timestamp ) {
226 $where[] = $dbr->timestamp( $timestamp );
228 $result = $dbr->select( 'archive', '*',
230 'ar_namespace' => $this->page
->getNamespace(),
231 'ar_title' => $this->page
->getDBKey(),
232 'ar_timestamp' => $where ),
234 while( $row = $dbr->fetchObject( $result ) ) {
235 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
236 $revObjs[$timestamp] = new Revision( array(
237 'page' => $this->page
->getArticleId(),
238 'id' => $row->ar_rev_id
,
239 'text' => $row->ar_text_id
,
240 'comment' => $row->ar_comment
,
241 'user' => $row->ar_user
,
242 'user_text' => $row->ar_user_text
,
243 'timestamp' => $timestamp,
244 'minor_edit' => $row->ar_minor_edit
,
245 'text_id' => $row->ar_text_id
,
246 'deleted' => $row->ar_deleted
,
247 'len' => $row->ar_len
) );
249 foreach( $this->archrevs
as $timestamp ) {
250 if( !isset($revObjs[$timestamp]) ) {
252 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
253 // If a rev is hidden from sysops
254 if( !$this->wasPosted
) {
255 $wgOut->permissionRequired( 'suppressrevision' );
258 $UserAllowed = false;
261 $wgOut->addHTML( $this->historyLine( $revObjs[$timestamp] ) );
262 $bitfields |
= $revObjs[$timestamp]->mDeleted
;
266 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
270 $wgOut->addHTML( "</ul>" );
272 $this->addUsageText();
274 // Normal sysops can always see what they did, but can't always change it
275 if( !$UserAllowed ) return;
278 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
279 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
282 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
283 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
284 Xml
::hidden( 'type', $this->deleteKey
)
286 if( $this->deleteKey
=='oldid' ) {
287 foreach( $revObjs as $rev )
288 $hidden[] = Xml
::hidden( 'oldid[]', $rev->getId() );
290 foreach( $revObjs as $rev )
291 $hidden[] = Xml
::hidden( 'artimestamp[]', $rev->getTimestamp() );
293 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
295 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
296 'id' => 'mw-revdel-form-revisions' ) ) .
297 Xml
::openElement( 'fieldset' ) .
298 xml
::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
301 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
302 foreach( $items as $item ) {
303 $wgOut->addHTML( Xml
::tags( 'p', null, $item ) );
305 foreach( $hidden as $item ) {
306 $wgOut->addHTML( $item );
309 Xml
::closeElement( 'fieldset' ) .
310 Xml
::closeElement( 'form' ) . "\n"
315 * This lets a user set restrictions for archived images
317 private function showImages() {
318 global $wgOut, $wgUser, $wgLang;
321 $count = ($this->deleteKey
=='oldimage') ?
count($this->ofiles
) : count($this->afiles
);
322 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(),
323 $wgLang->formatNum($count) );
326 $wgOut->addHTML( "<ul>" );
328 $where = $filesObjs = array();
329 $dbr = wfGetDB( DB_SLAVE
);
330 // Live old revisions...
332 if( $this->deleteKey
=='oldimage' ) {
333 // Run through and pull all our data in one query
334 foreach( $this->ofiles
as $timestamp ) {
335 $where[] = $timestamp.'!'.$this->page
->getDBKey();
337 $result = $dbr->select( 'oldimage', '*',
339 'oi_name' => $this->page
->getDBKey(),
340 'oi_archive_name' => $where ),
342 while( $row = $dbr->fetchObject( $result ) ) {
343 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
344 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
345 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
347 // Check through our images
348 foreach( $this->ofiles
as $timestamp ) {
349 $archivename = $timestamp.'!'.$this->page
->getDBKey();
350 if( !isset($filesObjs[$archivename]) ) {
352 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
353 // If a rev is hidden from sysops
354 if( !$this->wasPosted
) {
355 $wgOut->permissionRequired( 'suppressrevision' );
358 $UserAllowed = false;
361 // Inject history info
362 $wgOut->addHTML( $this->fileLine( $filesObjs[$archivename] ) );
363 $bitfields |
= $filesObjs[$archivename]->deleted
;
367 // Run through and pull all our data in one query
368 foreach( $this->afiles
as $id ) {
369 $where[] = intval($id);
371 $result = $dbr->select( 'filearchive', '*',
373 'fa_name' => $this->page
->getDBKey(),
376 while( $row = $dbr->fetchObject( $result ) ) {
377 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
380 foreach( $this->afiles
as $fileid ) {
381 if( !isset($filesObjs[$fileid]) ) {
383 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
384 // If a rev is hidden from sysops
385 if( !$this->wasPosted
) {
386 $wgOut->permissionRequired( 'suppressrevision' );
389 $UserAllowed = false;
392 // Inject history info
393 $wgOut->addHTML( $this->archivedfileLine( $filesObjs[$fileid] ) );
394 $bitfields |
= $filesObjs[$fileid]->deleted
;
398 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
402 $wgOut->addHTML( "</ul>" );
404 $this->addUsageText();
405 // Normal sysops can always see what they did, but can't always change it
406 if( !$UserAllowed ) return;
409 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
410 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
413 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
414 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
415 Xml
::hidden( 'type', $this->deleteKey
)
417 if( $this->deleteKey
=='oldimage' ) {
418 foreach( $this->ofiles
as $filename )
419 $hidden[] = Xml
::hidden( 'oldimage[]', $filename );
421 foreach( $this->afiles
as $fileid )
422 $hidden[] = Xml
::hidden( 'fileid[]', $fileid );
424 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
426 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
427 'id' => 'mw-revdel-form-filerevisions' ) ) .
428 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
431 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
432 foreach( $items as $item ) {
433 $wgOut->addHTML( "<p>$item</p>" );
435 foreach( $hidden as $item ) {
436 $wgOut->addHTML( $item );
440 Xml
::closeElement( 'fieldset' ) .
441 Xml
::closeElement( 'form' ) . "\n"
446 * This lets a user set restrictions for log items
448 private function showLogItems() {
449 global $wgOut, $wgUser, $wgMessageCache, $wgLang;
452 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->events
) ) );
455 $wgOut->addHTML( "<ul>" );
457 $where = $logRows = array();
458 $dbr = wfGetDB( DB_SLAVE
);
459 // Run through and pull all our data in one query
461 foreach( $this->events
as $logid ) {
462 $where[] = intval($logid);
464 list($log,$logtype) = explode( '/',$this->page
->getDBKey(), 2 );
465 $result = $dbr->select( 'logging', '*',
467 'log_type' => $logtype,
468 'log_id' => $where ),
470 while( $row = $dbr->fetchObject( $result ) ) {
471 $logRows[$row->log_id
] = $row;
473 $wgMessageCache->loadAllMessages();
474 foreach( $this->events
as $logid ) {
475 // Don't hide from oversight log!!!
476 if( !isset( $logRows[$logid] ) ||
$logRows[$logid]->log_type
=='suppress' ) {
478 } else if( !LogEventsList
::userCan( $logRows[$logid],Revision
::DELETED_RESTRICTED
) ) {
479 // If an event is hidden from sysops
480 if( !$this->wasPosted
) {
481 $wgOut->permissionRequired( 'suppressrevision' );
484 $UserAllowed = false;
487 $wgOut->addHTML( $this->logLine( $logRows[$logid] ) );
488 $bitfields |
= $logRows[$logid]->log_deleted
;
491 $wgOut->showErrorPage( 'revdelete-nologid-title', 'revdelete-nologid-text' );
495 $wgOut->addHTML( "</ul>" );
497 $this->addUsageText();
498 // Normal sysops can always see what they did, but can't always change it
499 if( !$UserAllowed ) return;
502 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
503 Xml
::submitButton( wfMsg( 'revdelete-submit' ) ) );
505 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
506 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
507 Xml
::hidden( 'type', $this->deleteKey
) );
508 foreach( $this->events
as $logid ) {
509 $hidden[] = Xml
::hidden( 'logid[]', $logid );
512 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
514 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
515 'id' => 'mw-revdel-form-logs' ) ) .
516 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
519 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
520 foreach( $items as $item ) {
521 $wgOut->addHTML( "<p>$item</p>" );
523 foreach( $hidden as $item ) {
524 $wgOut->addHTML( $item );
528 Xml
::closeElement( 'fieldset' ) .
529 Xml
::closeElement( 'form' ) . "\n"
533 private function addUsageText() {
534 global $wgOut, $wgUser;
535 $wgOut->addWikiMsg( 'revdelete-text' );
536 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
537 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
542 * @param int $bitfields, aggregate bitfield of all the bitfields
543 * @returns string HTML
545 private function buildCheckBoxes( $bitfields ) {
547 // FIXME: all items checked for just one rev are checked, even if not set for the others
548 foreach( $this->checks
as $item ) {
549 list( $message, $name, $field ) = $item;
550 $line = Xml
::tags( 'div', null, Xml
::checkLabel( wfMsg($message), $name, $name,
551 $bitfields & $field ) );
552 if( $field == Revision
::DELETED_RESTRICTED
) $line = "<b>$line</b>";
559 * @param Revision $rev
562 private function historyLine( $rev ) {
563 global $wgLang, $wgUser;
565 $date = $wgLang->timeanddate( $rev->getTimestamp() );
566 $difflink = $del = '';
568 if( $this->deleteKey
=='oldid' ) {
569 $tokenParams = '&unhide=1&token='.urlencode( $wgUser->editToken( $rev->getId() ) );
570 $revlink = $this->skin
->makeLinkObj( $this->page
, $date, 'oldid='.$rev->getId() . $tokenParams );
571 $difflink = '(' . $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml('diff'),
572 'diff=' . $rev->getId() . '&oldid=prev' . $tokenParams ) . ')';
573 // Archived revisions
575 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
576 $target = $this->page
->getPrefixedText();
577 $revlink = $this->skin
->makeLinkObj( $undelete, $date,
578 "target=$target×tamp=" . $rev->getTimestamp() );
579 $difflink = '(' . $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml('diff'),
580 "target=$target&diff=prev×tamp=" . $rev->getTimestamp() ) . ')';
582 // Check permissions; items may be "suppressed"
583 if( $rev->isDeleted(Revision
::DELETED_TEXT
) ) {
584 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
585 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
586 if( !$rev->userCan(Revision
::DELETED_TEXT
) ) {
587 $revlink = '<span class="history-deleted">'.$date.'</span>';
588 $difflink = '(' . wfMsgHtml('diff') . ')';
591 $userlink = $this->skin
->revUserLink( $rev );
592 $comment = $this->skin
->revComment( $rev );
594 return "<li>$difflink $revlink $userlink $comment{$del}</li>";
601 private function fileLine( $file ) {
602 global $wgLang, $wgTitle;
604 $target = $this->page
->getPrefixedText();
605 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
609 if( $file->isDeleted(File
::DELETED_FILE
) ) {
610 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
611 if( !$file->userCan(File
::DELETED_FILE
) ) {
614 $pageLink = $this->skin
->makeKnownLinkObj( $wgTitle, $date,
615 "target=$target&file=$file->sha1.".$file->getExtension() );
617 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
620 $url = $file->getUrlRel();
621 $pageLink = "<a href=\"{$url}\">{$date}</a>";
624 $data = wfMsg( 'widthheight',
625 $wgLang->formatNum( $file->getWidth() ),
626 $wgLang->formatNum( $file->getHeight() ) ) .
627 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
628 $data = htmlspecialchars( $data );
630 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
634 * @param ArchivedFile $file
637 private function archivedfileLine( $file ) {
640 $target = $this->page
->getPrefixedText();
641 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
643 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
644 $pageLink = $this->skin
->makeKnownLinkObj( $undelete, $date, "target=$target&file={$file->getKey()}" );
647 if( $file->isDeleted(File
::DELETED_FILE
) ) {
648 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
651 $data = wfMsg( 'widthheight',
652 $wgLang->formatNum( $file->getWidth() ),
653 $wgLang->formatNum( $file->getHeight() ) ) .
654 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
655 $data = htmlspecialchars( $data );
657 return "<li> $pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
661 * @param Array $row row
664 private function logLine( $row ) {
667 $date = $wgLang->timeanddate( $row->log_timestamp
);
668 $paramArray = LogPage
::extractParams( $row->log_params
);
669 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
671 $logtitle = SpecialPage
::getTitleFor( 'Log' );
672 $loglink = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
673 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
675 if( !LogEventsList
::userCan($row,LogPage
::DELETED_ACTION
) ) {
676 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
678 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
679 $this->skin
, $paramArray, true, true );
680 if( $row->log_deleted
& LogPage
::DELETED_ACTION
)
681 $action = '<span class="history-deleted">' . $action . '</span>';
684 $userLink = $this->skin
->userLink( $row->log_user
, User
::WhoIs($row->log_user
) );
685 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_USER
) ) {
686 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
689 $comment = $wgLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
690 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
691 $comment = '<span class="history-deleted">' . $comment . '</span>';
693 return "<li>($loglink) $date $userLink $action $comment</li>";
697 * Generate a user tool link cluster if the current user is allowed to view it
698 * @param ArchivedFile $file
699 * @return string HTML
701 private function fileUserTools( $file ) {
702 if( $file->userCan( Revision
::DELETED_USER
) ) {
703 $link = $this->skin
->userLink( $file->user
, $file->user_text
) .
704 $this->skin
->userToolLinks( $file->user
, $file->user_text
);
706 $link = wfMsgHtml( 'rev-deleted-user' );
708 if( $file->isDeleted( Revision
::DELETED_USER
) ) {
709 return '<span class="history-deleted">' . $link . '</span>';
715 * Wrap and format the given file's comment block, if the current
716 * user is allowed to view it.
718 * @param ArchivedFile $file
719 * @return string HTML
721 private function fileComment( $file ) {
722 if( $file->userCan( File
::DELETED_COMMENT
) ) {
723 $block = $this->skin
->commentBlock( $file->description
);
725 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
727 if( $file->isDeleted( File
::DELETED_COMMENT
) ) {
728 return "<span class=\"history-deleted\">$block</span>";
734 * @param WebRequest $request
736 private function submit( $request ) {
737 global $wgUser, $wgOut;
739 $bitfield = $this->extractBitfield( $request );
740 $comment = $request->getText( 'wpReason' );
741 # Can the user set this field?
742 if( $bitfield & Revision
::DELETED_RESTRICTED
&& !$wgUser->isAllowed('suppressrevision') ) {
743 $wgOut->permissionRequired( 'suppressrevision' );
746 # If the save went through, go to success message. Otherwise
747 # bounce back to form...
748 if( $this->save( $bitfield, $comment, $this->page
) ) {
750 } else if( $request->getCheck( 'oldid' ) ||
$request->getCheck( 'artimestamp' ) ) {
751 return $this->showRevs();
752 } else if( $request->getCheck( 'logid' ) ) {
753 return $this->showLogs();
754 } else if( $request->getCheck( 'oldimage' ) ||
$request->getCheck( 'fileid' ) ) {
755 return $this->showImages();
759 private function success() {
762 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
764 $wrap = '<span class="success">$1</span>';
766 if( $this->deleteKey
=='logid' ) {
767 $wgOut->wrapWikiMsg( $wrap, 'logdelete-success' );
768 $this->showLogItems();
769 } else if( $this->deleteKey
=='oldid' ||
$this->deleteKey
=='artimestamp' ) {
770 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
772 } else if( $this->deleteKey
=='fileid' ) {
773 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
775 } else if( $this->deleteKey
=='oldimage' ) {
776 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
782 * Put together a rev_deleted bitfield from the submitted checkboxes
783 * @param WebRequest $request
786 private function extractBitfield( $request ) {
788 foreach( $this->checks
as $item ) {
789 list( /* message */ , $name, $field ) = $item;
790 if( $request->getCheck( $name ) ) {
797 private function save( $bitfield, $reason, $title ) {
798 $dbw = wfGetDB( DB_MASTER
);
799 // Don't allow simply locking the interface for no reason
800 if( $bitfield == Revision
::DELETED_RESTRICTED
) {
803 $deleter = new RevisionDeleter( $dbw );
804 // By this point, only one of the below should be set
805 if( isset($this->revisions
) ) {
806 return $deleter->setRevVisibility( $title, $this->revisions
, $bitfield, $reason );
807 } else if( isset($this->archrevs
) ) {
808 return $deleter->setArchiveVisibility( $title, $this->archrevs
, $bitfield, $reason );
809 } else if( isset($this->ofiles
) ) {
810 return $deleter->setOldImgVisibility( $title, $this->ofiles
, $bitfield, $reason );
811 } else if( isset($this->afiles
) ) {
812 return $deleter->setArchFileVisibility( $title, $this->afiles
, $bitfield, $reason );
813 } else if( isset($this->events
) ) {
814 return $deleter->setEventVisibility( $title, $this->events
, $bitfield, $reason );
820 * Implements the actions for Revision Deletion.
821 * @ingroup SpecialPage
823 class RevisionDeleter
{
824 function __construct( $db ) {
829 * @param $title, the page these events apply to
830 * @param array $items list of revision ID numbers
831 * @param int $bitfield new rev_deleted value
832 * @param string $comment Comment for log records
834 function setRevVisibility( $title, $items, $bitfield, $comment ) {
837 $userAllowedAll = $success = true;
840 // Run through and pull all our data in one query
841 foreach( $items as $revid ) {
842 $where[] = intval($revid);
844 $result = $this->dbw
->select( 'revision', '*',
846 'rev_page' => $title->getArticleID(),
847 'rev_id' => $where ),
849 while( $row = $this->dbw
->fetchObject( $result ) ) {
850 $revObjs[$row->rev_id
] = new Revision( $row );
853 foreach( $items as $revid ) {
854 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
856 continue; // Must exist
857 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
858 $userAllowedAll=false;
861 // For logging, maintain a count of revisions
862 if( $revObjs[$revid]->mDeleted
!= $bitfield ) {
866 $this->updateRevision( $revObjs[$revid], $bitfield );
867 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
871 // Don't log or touch if nothing changed
872 if( $revCount > 0 ) {
873 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted
,
874 $comment, $title, 'oldid', $revIDs );
875 $this->updatePage( $title );
877 // Where all revs allowed to be set?
878 if( !$userAllowedAll ) {
879 //FIXME: still might be confusing???
880 $wgOut->permissionRequired( 'suppressrevision' );
888 * @param $title, the page these events apply to
889 * @param array $items list of revision ID numbers
890 * @param int $bitfield new rev_deleted value
891 * @param string $comment Comment for log records
893 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
896 $userAllowedAll = $success = true;
899 // Run through and pull all our data in one query
900 foreach( $items as $timestamp ) {
901 $where[] = $this->dbw
->timestamp( $timestamp );
903 $result = $this->dbw
->select( 'archive', '*',
905 'ar_namespace' => $title->getNamespace(),
906 'ar_title' => $title->getDBKey(),
907 'ar_timestamp' => $where ),
909 while( $row = $this->dbw
->fetchObject( $result ) ) {
910 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
911 $revObjs[$timestamp] = new Revision( array(
912 'page' => $title->getArticleId(),
913 'id' => $row->ar_rev_id
,
914 'text' => $row->ar_text_id
,
915 'comment' => $row->ar_comment
,
916 'user' => $row->ar_user
,
917 'user_text' => $row->ar_user_text
,
918 'timestamp' => $timestamp,
919 'minor_edit' => $row->ar_minor_edit
,
920 'text_id' => $row->ar_text_id
,
921 'deleted' => $row->ar_deleted
,
922 'len' => $row->ar_len
) );
925 foreach( $items as $timestamp ) {
926 // This will only select the first revision with this timestamp.
927 // Since they are all selected/deleted at once, we can just check the
928 // permissions of one. UPDATE is done via timestamp, so all revs are set.
929 if( !is_object($revObjs[$timestamp]) ) {
931 continue; // Must exist
932 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
933 $userAllowedAll=false;
936 // Which revisions did we change anything about?
937 if( $revObjs[$timestamp]->mDeleted
!= $bitfield ) {
938 $Id_set[]=$timestamp;
941 $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
944 // For logging, maintain a count of revisions
946 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted
,
947 $comment, $title, 'artimestamp', $Id_set );
949 // Where all revs allowed to be set?
950 if( !$userAllowedAll ) {
951 $wgOut->permissionRequired( 'suppressrevision' );
959 * @param $title, the page these events apply to
960 * @param array $items list of revision ID numbers
961 * @param int $bitfield new rev_deleted value
962 * @param string $comment Comment for log records
964 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
967 $userAllowedAll = $success = true;
970 // Run through and pull all our data in one query
971 foreach( $items as $timestamp ) {
972 $where[] = $timestamp.'!'.$title->getDBKey();
974 $result = $this->dbw
->select( 'oldimage', '*',
976 'oi_name' => $title->getDBKey(),
977 'oi_archive_name' => $where ),
979 while( $row = $this->dbw
->fetchObject( $result ) ) {
980 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
981 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
982 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
985 foreach( $items as $timestamp ) {
986 $archivename = $timestamp.'!'.$title->getDBKey();
987 if( !isset($filesObjs[$archivename]) ) {
989 continue; // Must exist
990 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
991 $userAllowedAll=false;
996 // Which revisions did we change anything about?
997 if( $filesObjs[$archivename]->deleted
!= $bitfield ) {
1000 $this->dbw
->begin();
1001 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
1002 // If this image is currently hidden...
1003 if( $filesObjs[$archivename]->deleted
& File
::DELETED_FILE
) {
1004 if( $bitfield & File
::DELETED_FILE
) {
1005 # Leave it alone if we are not changing this...
1006 $set[]=$archivename;
1007 $transaction = true;
1009 # We are moving this out
1010 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
1011 $set[]=$transaction;
1013 // Is it just now becoming hidden?
1014 } else if( $bitfield & File
::DELETED_FILE
) {
1015 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
1016 $set[]=$transaction;
1020 // If our file operations fail, then revert back the db
1021 if( $transaction==false ) {
1022 $this->dbw
->rollback();
1025 $this->dbw
->commit();
1029 // Log if something was changed
1031 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted
,
1032 $comment, $title, 'oldimage', $set );
1033 # Purge page/history
1034 $file = wfLocalFile( $title );
1035 $file->purgeCache();
1036 $file->purgeHistory();
1037 # Invalidate cache for all pages using this file
1038 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
1039 $update->doUpdate();
1041 // Where all revs allowed to be set?
1042 if( !$userAllowedAll ) {
1043 $wgOut->permissionRequired( 'suppressrevision' );
1051 * @param $title, the page these events apply to
1052 * @param array $items list of revision ID numbers
1053 * @param int $bitfield new rev_deleted value
1054 * @param string $comment Comment for log records
1056 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
1059 $userAllowedAll = $success = true;
1063 // Run through and pull all our data in one query
1064 foreach( $items as $id ) {
1065 $where[] = intval($id);
1067 $result = $this->dbw
->select( 'filearchive', '*',
1068 array( 'fa_name' => $title->getDBKey(),
1069 'fa_id' => $where ),
1071 while( $row = $this->dbw
->fetchObject( $result ) ) {
1072 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
1075 foreach( $items as $fileid ) {
1076 if( !isset($filesObjs[$fileid]) ) {
1078 continue; // Must exist
1079 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
1080 $userAllowedAll=false;
1083 // Which revisions did we change anything about?
1084 if( $filesObjs[$fileid]->deleted
!= $bitfield ) {
1088 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1091 // Log if something was changed
1093 $this->updateLog( $title, $count, $bitfield, $comment,
1094 $filesObjs[$fileid]->deleted
, $title, 'fileid', $Id_set );
1096 // Where all revs allowed to be set?
1097 if( !$userAllowedAll ) {
1098 $wgOut->permissionRequired( 'suppressrevision' );
1106 * @param $title, the log page these events apply to
1107 * @param array $items list of log ID numbers
1108 * @param int $bitfield new log_deleted value
1109 * @param string $comment Comment for log records
1111 function setEventVisibility( $title, $items, $bitfield, $comment ) {
1114 $userAllowedAll = $success = true;
1118 // Run through and pull all our data in one query
1119 foreach( $items as $logid ) {
1120 $where[] = intval($logid);
1122 list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
1123 $result = $this->dbw
->select( 'logging', '*',
1125 'log_type' => $logtype,
1126 'log_id' => $where ),
1128 while( $row = $this->dbw
->fetchObject( $result ) ) {
1129 $logRows[$row->log_id
] = $row;
1132 foreach( $items as $logid ) {
1133 if( !isset($logRows[$logid]) ) {
1135 continue; // Must exist
1136 } else if( !LogEventsList
::userCan($logRows[$logid], LogPage
::DELETED_RESTRICTED
)
1137 ||
$logRows[$logid]->log_type
== 'suppress' ) {
1138 // Don't hide from oversight log!!!
1139 $userAllowedAll=false;
1142 // Which logs did we change anything about?
1143 if( $logRows[$logid]->log_deleted
!= $bitfield ) {
1147 $this->updateLogs( $logRows[$logid], $bitfield );
1148 $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
1151 // Don't log or touch if nothing changed
1153 $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted
,
1154 $comment, $title, 'logid', $log_Ids );
1156 // Were all revs allowed to be set?
1157 if( !$userAllowedAll ) {
1158 $wgOut->permissionRequired( 'suppressrevision' );
1166 * Moves an image to a safe private location
1167 * Caller is responsible for clearing caches
1168 * @param File $oimage
1169 * @returns mixed, timestamp string on success, false on failure
1171 function makeOldImagePrivate( $oimage ) {
1172 $transaction = new FSTransaction();
1173 if( !FileStore
::lock() ) {
1174 wfDebug( __METHOD__
.": failed to acquire file store lock, aborting\n" );
1177 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1178 // Dupe the file into the file store
1179 if( file_exists( $oldpath ) ) {
1180 // Is our directory configured?
1181 if( $store = FileStore
::get( 'deleted' ) ) {
1182 if( !$oimage->sha1
) {
1183 $oimage->upgradeRow(); // sha1 may be missing
1185 $key = $oimage->sha1
. '.' . $oimage->getExtension();
1186 $transaction->add( $store->insert( $key, $oldpath, FileStore
::DELETE_ORIGINAL
) );
1190 $transaction = false; // Return an error and do nothing
1193 wfDebug( __METHOD__
." deleting already-missing '$oldpath'; moving on to database\n" );
1196 $transaction = new FSTransaction(); // empty
1199 if( $transaction === false ) {
1201 wfDebug( __METHOD__
.": import to file store failed, aborting\n" );
1202 throw new MWException( "Could not archive and delete file $oldpath" );
1206 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1207 $transaction->commit();
1208 FileStore
::unlock();
1210 $m = explode('!',$oimage->archive_name
,2);
1217 * Moves an image from a safe private location
1218 * Caller is responsible for clearing caches
1219 * @param File $oimage
1220 * @returns mixed, string timestamp on success, false on failure
1222 function makeOldImagePublic( $oimage ) {
1223 $transaction = new FSTransaction();
1224 if( !FileStore
::lock() ) {
1225 wfDebug( __METHOD__
." could not acquire filestore lock\n" );
1229 $store = FileStore
::get( 'deleted' );
1231 wfDebug( __METHOD__
.": skipping row with no file.\n" );
1235 $key = $oimage->sha1
.'.'.$oimage->getExtension();
1236 $destDir = $oimage->getArchivePath();
1237 if( !is_dir( $destDir ) ) {
1238 wfMkdirParents( $destDir );
1240 $destPath = $destDir . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1241 // Check if any other stored revisions use this file;
1242 // if so, we shouldn't remove the file from the hidden
1243 // archives so they will still work. Check hidden files first.
1244 $useCount = $this->dbw
->selectField( 'oldimage', '1',
1245 array( 'oi_sha1' => $oimage->sha1
,
1246 'oi_deleted & '.File
::DELETED_FILE
=> File
::DELETED_FILE
),
1247 __METHOD__
, array( 'FOR UPDATE' ) );
1248 // Check the rest of the deleted archives too.
1249 // (these are the ones that don't show in the image history)
1251 $useCount = $this->dbw
->selectField( 'filearchive', '1',
1252 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1253 __METHOD__
, array( 'FOR UPDATE' ) );
1256 if( $useCount == 0 ) {
1257 wfDebug( __METHOD__
.": nothing else using {$oimage->sha1}, will deleting after\n" );
1258 $flags = FileStore
::DELETE_ORIGINAL
;
1262 $transaction->add( $store->export( $key, $destPath, $flags ) );
1264 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1265 $transaction->commit();
1266 FileStore
::unlock();
1268 $m = explode('!',$oimage->archive_name
,2);
1275 * Update the revision's rev_deleted field
1276 * @param Revision $rev
1277 * @param int $bitfield new rev_deleted bitfield value
1279 function updateRevision( $rev, $bitfield ) {
1280 $this->dbw
->update( 'revision',
1281 array( 'rev_deleted' => $bitfield ),
1282 array( 'rev_id' => $rev->getId(),
1283 'rev_page' => $rev->getPage() ),
1288 * Update the revision's rev_deleted field
1289 * @param Revision $rev
1290 * @param Title $title
1291 * @param int $bitfield new rev_deleted bitfield value
1293 function updateArchive( $rev, $title, $bitfield ) {
1294 $this->dbw
->update( 'archive',
1295 array( 'ar_deleted' => $bitfield ),
1296 array( 'ar_namespace' => $title->getNamespace(),
1297 'ar_title' => $title->getDBKey(),
1298 'ar_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ),
1299 'ar_rev_id' => $rev->getId() ),
1304 * Update the images's oi_deleted field
1306 * @param int $bitfield new rev_deleted bitfield value
1308 function updateOldFiles( $file, $bitfield ) {
1309 $this->dbw
->update( 'oldimage',
1310 array( 'oi_deleted' => $bitfield ),
1311 array( 'oi_name' => $file->getName(),
1312 'oi_timestamp' => $this->dbw
->timestamp( $file->getTimestamp() ) ),
1317 * Update the images's fa_deleted field
1318 * @param ArchivedFile $file
1319 * @param int $bitfield new rev_deleted bitfield value
1321 function updateArchFiles( $file, $bitfield ) {
1322 $this->dbw
->update( 'filearchive',
1323 array( 'fa_deleted' => $bitfield ),
1324 array( 'fa_id' => $file->getId() ),
1329 * Update the logging log_deleted field
1331 * @param int $bitfield new rev_deleted bitfield value
1333 function updateLogs( $row, $bitfield ) {
1334 $this->dbw
->update( 'logging',
1335 array( 'log_deleted' => $bitfield ),
1336 array( 'log_id' => $row->log_id
),
1341 * Update the revision's recentchanges record if fields have been hidden
1342 * @param Revision $rev
1343 * @param int $bitfield new rev_deleted bitfield value
1345 function updateRecentChangesEdits( $rev, $bitfield ) {
1346 $this->dbw
->update( 'recentchanges',
1347 array( 'rc_deleted' => $bitfield,
1348 'rc_patrolled' => 1 ),
1349 array( 'rc_this_oldid' => $rev->getId(),
1350 'rc_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ) ),
1355 * Update the revision's recentchanges record if fields have been hidden
1357 * @param int $bitfield new rev_deleted bitfield value
1359 function updateRecentChangesLog( $row, $bitfield ) {
1360 $this->dbw
->update( 'recentchanges',
1361 array( 'rc_deleted' => $bitfield,
1362 'rc_patrolled' => 1 ),
1363 array( 'rc_logid' => $row->log_id
,
1364 'rc_timestamp' => $row->log_timestamp
),
1369 * Touch the page's cache invalidation timestamp; this forces cached
1370 * history views to refresh, so any newly hidden or shown fields will
1372 * @param Title $title
1374 function updatePage( $title ) {
1375 $title->invalidateCache();
1376 $title->purgeSquid();
1377 $title->touchLinks();
1378 // Extensions that require referencing previous revisions may need this
1379 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1383 * Checks for a change in the bitfield for a certain option and updates the
1384 * provided array accordingly.
1386 * @param String $desc Description to add to the array if the option was
1387 * enabled / disabled.
1388 * @param int $field The bitmask describing the single option.
1389 * @param int $diff The xor of the old and new bitfields.
1390 * @param array $arr The array to update.
1392 function checkItem ( $desc, $field, $diff, $new, &$arr ) {
1393 if ( $diff & $field ) {
1394 $arr [ ( $new & $field ) ?
0 : 1 ][] = $desc;
1399 * Gets an array describing the changes made to the visibilit of the revision.
1400 * If the resulting array is $arr, then $arr[0] will contain an array of strings
1401 * describing the items that were hidden, $arr[2] will contain an array of strings
1402 * describing the items that were unhidden, and $arr[3] will contain an array with
1403 * a single string, which can be one of "applied restrictions to sysops",
1404 * "removed restrictions from sysops", or null.
1406 * @param int $n The new bitfield.
1407 * @param int $o The old bitfield.
1408 * @return An array as described above.
1410 function getChanges ( $n, $o ) {
1412 $ret = array ( 0 => array(), 1 => array(), 2 => array() );
1414 $this->checkItem ( wfMsgForContent ( 'revdelete-content' ),
1415 Revision
::DELETED_TEXT
, $diff, $n, $ret );
1416 $this->checkItem ( wfMsgForContent ( 'revdelete-summary' ),
1417 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
1418 $this->checkItem ( wfMsgForContent ( 'revdelete-uname' ),
1419 Revision
::DELETED_USER
, $diff, $n, $ret );
1421 // Restriction application to sysops
1422 if ( $diff & Revision
::DELETED_RESTRICTED
) {
1423 if ( $n & Revision
::DELETED_RESTRICTED
)
1424 $ret[2][] = wfMsgForContent ( 'revdelete-restricted' );
1426 $ret[2][] = wfMsgForContent ( 'revdelete-unrestricted' );
1433 * Gets a log message to describe the given revision visibility change. This
1434 * message will be of the form "[hid {content, edit summary, username}];
1435 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
1437 * @param int $count The number of effected revisions.
1438 * @param int $nbitfield The new bitfield for the revision.
1439 * @param int $obitfield The old bitfield for the revision.
1440 * @param string $comment The comment associated with the change.
1441 * @param bool $isForLog
1443 function getLogMessage ( $count, $nbitfield, $obitfield, $comment, $isForLog = false ) {
1447 $changes = $this->getChanges( $nbitfield, $obitfield );
1449 if ( count ( $changes[0] ) ) {
1450 $s .= wfMsgForContent ( 'revdelete-hid', implode ( ', ', $changes[0] ) );
1453 if ( count ( $changes[1] ) ) {
1456 $s .= wfMsgForContent ( 'revdelete-unhid', implode ( ', ', $changes[1] ) );
1459 if ( count ( $changes[2] )) {
1461 $s .= ' (' . $changes[2][0] . ')';
1463 $s = $changes[2][0];
1466 $msg = $isForLog ?
'logdelete-log-message' : 'revdelete-log-message';
1467 $ret = wfMsgExt ( $msg, array( 'parsemag', 'content' ),
1468 $s, $wgContLang->formatNum( $count ) );
1471 $ret .= ": $comment";
1478 * Record a log entry on the action
1479 * @param Title $title, page where item was removed from
1480 * @param int $count the number of revisions altered for this page
1481 * @param int $nbitfield the new _deleted value
1482 * @param int $obitfield the old _deleted value
1483 * @param string $comment
1484 * @param Title $target, the relevant page
1485 * @param string $param, URL param
1486 * @param Array $items
1488 function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target, $param, $items = array() ) {
1489 // Put things hidden from sysops in the oversight log
1490 $logtype = ( ($nbitfield |
$obitfield) & Revision
::DELETED_RESTRICTED
) ?
'suppress' : 'delete';
1491 $log = new LogPage( $logtype );
1493 $reason = $this->getLogMessage ( $count, $nbitfield, $obitfield, $comment, $param == 'logid' );
1495 if( $param == 'logid' ) {
1496 $params = array( implode( ',', $items) );
1497 $log->addEntry( 'event', $title, $reason, $params );
1499 // Add params for effected page and ids
1500 $params = array( $param, implode( ',', $items) );
1501 $log->addEntry( 'revision', $title, $reason, $params );