3 * Special page allowing users with the appropriate permissions to view
4 * and hide revisions. Log items can also be hidden.
10 class SpecialRevisionDelete
extends UnlistedSpecialPage
{
12 public function __construct() {
13 parent
::__construct( 'Revisiondelete', 'deleterevision' );
14 $this->includable( false );
17 public function execute( $par ) {
18 global $wgOut, $wgUser, $wgRequest;
20 $wgOut->readOnlyPage();
23 if( !$wgUser->isAllowed( 'deleterevision' ) ) {
24 $wgOut->permissionRequired( 'deleterevision' );
27 $this->skin
=& $wgUser->getSkin();
29 $this->outputHeader();
30 $this->wasPosted
= $wgRequest->wasPosted();
32 $this->target
= $wgRequest->getText( 'target' );
33 # Handle our many different possible input types.
34 # Use CVS, since the cgi handling will break on arrays.
35 $this->oldids
= array_filter( explode( ',', $wgRequest->getVal('oldid') ) );
36 $this->artimestamps
= array_filter( explode( ',', $wgRequest->getVal('artimestamp') ) );
37 $this->logids
= array_filter( explode( ',', $wgRequest->getVal('logid') ) );
38 $this->oldimgs
= array_filter( explode( ',', $wgRequest->getVal('oldimage') ) );
39 $this->fileids
= array_filter( explode( ',', $wgRequest->getVal('fileid') ) );
40 # For reviewing deleted files...
41 $this->file
= $wgRequest->getVal( 'file' );
42 # Only one target set at a time please!
43 $i = (bool)$this->file +
(bool)$this->oldids +
(bool)$this->logids
44 +
(bool)$this->artimestamps +
(bool)$this->fileids +
(bool)$this->oldimgs
;
47 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
52 $wgOut->showErrorPage( 'revdelete-toomanytargets-title', 'revdelete-toomanytargets-text' );
55 $this->page
= Title
::newFromUrl( $this->target
);
56 # If we have revisions, get the title from the first one
57 # since they should all be from the same page. This allows
58 # for more flexibility with page moves...
59 if( count($this->oldids
) > 0 ) {
60 $rev = Revision
::newFromId( $this->oldids
[0] );
61 $this->page
= $rev ?
$rev->getTitle() : $this->page
;
63 # We need a target page!
64 if( is_null($this->page
) ) {
65 $wgOut->addWikiMsg( 'undelete-header' );
68 # Logs must have a type given
69 if( $this->logids
&& !strpos($this->page
->getDBKey(),'/') ) {
70 $wgOut->showErrorPage( 'revdelete-nologtype-title', 'revdelete-nologtype-text' );
73 # For reviewing deleted files...show it now if allowed
75 $oimage = RepoGroup
::singleton()->getLocalRepo()->newFromArchiveName( $this->page
, $this->file
);
77 // Check if user is allowed to see this file
78 if( !$oimage->userCan(File
::DELETED_FILE
) ) {
79 $wgOut->permissionRequired( 'suppressrevision' );
81 $this->showFile( $this->file
);
85 # Give a link to the logs/hist for this page
86 if( !is_null($this->page
) && $this->page
->getNamespace() > -1 ) {
89 $logtitle = SpecialPage
::getTitleFor( 'Log' );
90 $links[] = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
91 wfArrayToCGI( array( 'page' => $this->page
->getPrefixedUrl() ) ) );
92 # Give a link to the page history
93 $links[] = $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml( 'pagehist' ),
94 wfArrayToCGI( array( 'action' => 'history' ) ) );
95 # Link to deleted edits
96 if( $wgUser->isAllowed('undelete') ) {
97 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
98 $links[] = $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
99 wfArrayToCGI( array( 'target' => $this->page
->getPrefixedDBkey() ) ) );
101 # Logs themselves don't have histories or archived revisions
102 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
104 # Lock the operation and the form context
105 $this->secureOperation();
106 # Either submit or create our form
107 if( $this->wasPosted
) {
108 $this->submit( $wgRequest );
109 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
111 } else if( $this->deleteKey
== 'fileid' ||
$this->deleteKey
== 'oldimage' ) {
113 } else if( $this->deleteKey
== 'logid' ) {
114 $this->showLogItems();
116 $qc = $this->getLogQueryCond();
117 # Show relevant lines from the deletion log
118 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'delete' ) ) . "</h2>\n" );
119 LogEventsList
::showLogExtract( $wgOut, 'delete', $this->page
->getPrefixedText(), '', 25, $qc );
120 # Show relevant lines from the suppression log
121 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
122 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'suppress' ) ) . "</h2>\n" );
123 LogEventsList
::showLogExtract( $wgOut, 'suppress', $this->page
->getPrefixedText(), '', 25, $qc );
127 private function getLogQueryCond() {
128 $ids = $safeIds = array();
129 switch( $this->deleteKey
) {
131 $ids = $this->oldids
;
134 $ids = $this->artimestamps
;
137 $ids = $this->oldimgs
;
140 $ids = $this->fileids
;
143 $ids = $this->logids
;
146 // Revision delete logs
147 $conds = array( 'log_action' => 'revision' );
148 // Just get the whole log if there are a lot if items
149 if( count($ids) > 20 ) return $conds;
151 foreach( $ids as $id ) {
152 if( preg_match( '/^\d+$/', $id, $m ) ) {
156 // Format is <id1,id2,i3...>
157 if( count($safeIds) ) {
158 $conds[] = "log_params RLIKE '(^|\n|,)(".implode('|',$safeIds).")(,|$)'";
163 private function secureOperation() {
165 $this->deleteKey
= '';
166 // At this point, we should only have one of these
167 if( $this->oldids
) {
168 $this->revisions
= $this->oldids
;
169 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
170 $this->deleteKey
= 'oldid';
171 } else if( $this->artimestamps
) {
172 $this->archrevs
= $this->artimestamps
;
173 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
174 $this->deleteKey
= 'artimestamp';
175 } else if( $this->oldimgs
) {
176 $this->ofiles
= $this->oldimgs
;
177 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
178 $this->deleteKey
= 'oldimage';
179 } else if( $this->fileids
) {
180 $this->afiles
= $this->fileids
;
181 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
182 $this->deleteKey
= 'fileid';
183 } else if( $this->logids
) {
184 $this->events
= $this->logids
;
185 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage
::DELETED_ACTION
);
186 $this->deleteKey
= 'logid';
188 // Our checkbox messages depends one what we are doing,
189 // e.g. we don't hide "text" for logs or images
190 $this->checks
= array(
192 array( 'revdelete-hide-comment', 'wpHideComment', Revision
::DELETED_COMMENT
),
193 array( 'revdelete-hide-user', 'wpHideUser', Revision
::DELETED_USER
)
195 if( $wgUser->isAllowed('suppressrevision') ) {
196 $this->checks
[] = array( 'revdelete-hide-restricted',
197 'wpHideRestricted', Revision
::DELETED_RESTRICTED
);
202 * Show a deleted file version requested by the visitor.
204 private function showFile( $key ) {
205 global $wgOut, $wgRequest;
208 # We mustn't allow the output to be Squid cached, otherwise
209 # if an admin previews a deleted image, and it's cached, then
210 # a user without appropriate permissions can toddle off and
211 # nab the image, and Squid will serve it
212 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
213 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
214 $wgRequest->response()->header( 'Pragma: no-cache' );
216 $store = FileStore
::get( 'deleted' );
217 $store->stream( $key );
221 * This lets a user set restrictions for live and archived revisions
223 private function showRevs() {
224 global $wgOut, $wgUser;
227 $count = ($this->deleteKey
=='oldid') ?
228 count($this->revisions
) : count($this->archrevs
);
229 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(), $count );
232 $wgOut->addHTML( "<ul>" );
234 $where = $revObjs = array();
235 $dbr = wfGetDB( DB_MASTER
);
239 if( $this->deleteKey
=='oldid' ) {
240 // Run through and pull all our data in one query
241 foreach( $this->revisions
as $revid ) {
242 $where[] = intval($revid);
244 $result = $dbr->select( array('revision','page'), '*',
246 'rev_page' => $this->page
->getArticleID(),
248 'rev_page = page_id' ),
250 while( $row = $dbr->fetchObject( $result ) ) {
251 $revObjs[$row->rev_id
] = new Revision( $row );
253 foreach( $this->revisions
as $revid ) {
254 // Hiding top revisison is bad
255 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
257 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
258 // If a rev is hidden from sysops
259 if( !$this->wasPosted
) {
260 $wgOut->permissionRequired( 'suppressrevision' );
263 $UserAllowed = false;
266 $wgOut->addHTML( $this->historyLine( $revObjs[$revid] ) );
267 $bitfields |
= $revObjs[$revid]->mDeleted
;
271 // Run through and pull all our data in one query
272 foreach( $this->archrevs
as $timestamp ) {
273 $where[] = $dbr->timestamp( $timestamp );
275 $result = $dbr->select( 'archive', '*',
277 'ar_namespace' => $this->page
->getNamespace(),
278 'ar_title' => $this->page
->getDBKey(),
279 'ar_timestamp' => $where ),
281 while( $row = $dbr->fetchObject( $result ) ) {
282 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
283 $revObjs[$timestamp] = new Revision( array(
284 'page' => $this->page
->getArticleId(),
285 'id' => $row->ar_rev_id
,
286 'text' => $row->ar_text_id
,
287 'comment' => $row->ar_comment
,
288 'user' => $row->ar_user
,
289 'user_text' => $row->ar_user_text
,
290 'timestamp' => $timestamp,
291 'minor_edit' => $row->ar_minor_edit
,
292 'text_id' => $row->ar_text_id
,
293 'deleted' => $row->ar_deleted
,
294 'len' => $row->ar_len
) );
296 foreach( $this->archrevs
as $timestamp ) {
297 if( !isset($revObjs[$timestamp]) ) {
299 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
300 // If a rev is hidden from sysops
301 if( !$this->wasPosted
) {
302 $wgOut->permissionRequired( 'suppressrevision' );
305 $UserAllowed = false;
308 $wgOut->addHTML( $this->historyLine( $revObjs[$timestamp] ) );
309 $bitfields |
= $revObjs[$timestamp]->mDeleted
;
313 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
317 $wgOut->addHTML( "</ul>" );
319 $this->addUsageText();
321 // Normal sysops can always see what they did, but can't always change it
322 if( !$UserAllowed ) return;
325 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
326 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
329 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
330 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
331 Xml
::hidden( 'type', $this->deleteKey
)
333 if( $this->deleteKey
=='oldid' ) {
334 $hidden[] = Xml
::hidden( 'oldid', implode(',',$this->oldids
) );
336 $hidden[] = Xml
::hidden( 'artimestamp', implode(',',$this->artimestamps
) );
338 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
340 Xml
::openElement( 'form', array( 'method' => 'post',
341 'action' => $special->getLocalUrl( 'action=submit' ),
342 'id' => 'mw-revdel-form-revisions' ) ) .
343 Xml
::openElement( 'fieldset' ) .
344 xml
::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
347 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
348 foreach( $items as $item ) {
349 $wgOut->addHTML( Xml
::tags( 'p', null, $item ) );
351 foreach( $hidden as $item ) {
352 $wgOut->addHTML( $item );
355 Xml
::closeElement( 'fieldset' ) .
356 Xml
::closeElement( 'form' ) . "\n"
361 * This lets a user set restrictions for archived images
363 private function showImages() {
364 global $wgOut, $wgUser, $wgLang;
367 $count = ($this->deleteKey
=='oldimage') ?
count($this->ofiles
) : count($this->afiles
);
368 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(),
369 $wgLang->formatNum($count) );
372 $wgOut->addHTML( "<ul>" );
374 $where = $filesObjs = array();
375 $dbr = wfGetDB( DB_MASTER
);
376 // Live old revisions...
378 if( $this->deleteKey
=='oldimage' ) {
379 // Run through and pull all our data in one query
380 foreach( $this->ofiles
as $timestamp ) {
381 $where[] = $timestamp.'!'.$this->page
->getDBKey();
383 $result = $dbr->select( 'oldimage', '*',
385 'oi_name' => $this->page
->getDBKey(),
386 'oi_archive_name' => $where ),
388 while( $row = $dbr->fetchObject( $result ) ) {
389 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
390 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
391 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
393 // Check through our images
394 foreach( $this->ofiles
as $timestamp ) {
395 $archivename = $timestamp.'!'.$this->page
->getDBKey();
396 if( !isset($filesObjs[$archivename]) ) {
398 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
399 // If a rev is hidden from sysops
400 if( !$this->wasPosted
) {
401 $wgOut->permissionRequired( 'suppressrevision' );
404 $UserAllowed = false;
407 // Inject history info
408 $wgOut->addHTML( $this->fileLine( $filesObjs[$archivename] ) );
409 $bitfields |
= $filesObjs[$archivename]->deleted
;
413 // Run through and pull all our data in one query
414 foreach( $this->afiles
as $id ) {
415 $where[] = intval($id);
417 $result = $dbr->select( 'filearchive', '*',
419 'fa_name' => $this->page
->getDBKey(),
422 while( $row = $dbr->fetchObject( $result ) ) {
423 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
426 foreach( $this->afiles
as $fileid ) {
427 if( !isset($filesObjs[$fileid]) ) {
429 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
430 // If a rev is hidden from sysops
431 if( !$this->wasPosted
) {
432 $wgOut->permissionRequired( 'suppressrevision' );
435 $UserAllowed = false;
438 // Inject history info
439 $wgOut->addHTML( $this->archivedfileLine( $filesObjs[$fileid] ) );
440 $bitfields |
= $filesObjs[$fileid]->deleted
;
444 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
448 $wgOut->addHTML( "</ul>" );
450 $this->addUsageText();
451 // Normal sysops can always see what they did, but can't always change it
452 if( !$UserAllowed ) return;
455 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
456 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
459 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
460 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
461 Xml
::hidden( 'type', $this->deleteKey
)
463 if( $this->deleteKey
=='oldimage' ) {
464 $hidden[] = Xml
::hidden( 'oldimage', implode(',',$this->oldimgs
) );
466 $hidden[] = Xml
::hidden( 'fileid', implode(',',$this->fileids
) );
468 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
470 Xml
::openElement( 'form', array( 'method' => 'post',
471 'action' => $special->getLocalUrl( 'action=submit' ),
472 'id' => 'mw-revdel-form-filerevisions' )
474 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
477 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
478 foreach( $items as $item ) {
479 $wgOut->addHTML( "<p>$item</p>" );
481 foreach( $hidden as $item ) {
482 $wgOut->addHTML( $item );
486 Xml
::closeElement( 'fieldset' ) .
487 Xml
::closeElement( 'form' ) . "\n"
492 * This lets a user set restrictions for log items
494 private function showLogItems() {
495 global $wgOut, $wgUser, $wgMessageCache, $wgLang;
498 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->events
) ) );
501 $wgOut->addHTML( "<ul>" );
503 $where = $logRows = array();
504 $dbr = wfGetDB( DB_MASTER
);
505 // Run through and pull all our data in one query
507 foreach( $this->events
as $logid ) {
508 $where[] = intval($logid);
510 list($log,$logtype) = explode( '/',$this->page
->getDBKey(), 2 );
511 $result = $dbr->select( 'logging', '*',
513 'log_type' => $logtype,
514 'log_id' => $where ),
516 while( $row = $dbr->fetchObject( $result ) ) {
517 $logRows[$row->log_id
] = $row;
519 $wgMessageCache->loadAllMessages();
520 foreach( $this->events
as $logid ) {
521 // Don't hide from oversight log!!!
522 if( !isset( $logRows[$logid] ) ||
$logRows[$logid]->log_type
=='suppress' ) {
524 } else if( !LogEventsList
::userCan( $logRows[$logid],Revision
::DELETED_RESTRICTED
) ) {
525 // If an event is hidden from sysops
526 if( !$this->wasPosted
) {
527 $wgOut->permissionRequired( 'suppressrevision' );
530 $UserAllowed = false;
533 $wgOut->addHTML( $this->logLine( $logRows[$logid] ) );
534 $bitfields |
= $logRows[$logid]->log_deleted
;
537 $wgOut->showErrorPage( 'revdelete-nologid-title', 'revdelete-nologid-text' );
541 $wgOut->addHTML( "</ul>" );
543 $this->addUsageText();
544 // Normal sysops can always see what they did, but can't always change it
545 if( !$UserAllowed ) return;
548 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
549 Xml
::submitButton( wfMsg( 'revdelete-submit' ) ) );
551 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
552 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
553 Xml
::hidden( 'type', $this->deleteKey
),
554 Xml
::hidden( 'logid', implode(',',$this->logids
) )
557 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
559 Xml
::openElement( 'form', array( 'method' => 'post',
560 'action' => $special->getLocalUrl( 'action=submit' ), 'id' => 'mw-revdel-form-logs' ) ) .
561 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
564 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
565 foreach( $items as $item ) {
566 $wgOut->addHTML( "<p>$item</p>" );
568 foreach( $hidden as $item ) {
569 $wgOut->addHTML( $item );
573 Xml
::closeElement( 'fieldset' ) .
574 Xml
::closeElement( 'form' ) . "\n"
578 private function addUsageText() {
579 global $wgOut, $wgUser;
580 $wgOut->addWikiMsg( 'revdelete-text' );
581 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
582 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
587 * @param int $bitfields, aggregate bitfield of all the bitfields
588 * @returns string HTML
590 private function buildCheckBoxes( $bitfields ) {
592 // FIXME: all items checked for just one rev are checked, even if not set for the others
593 foreach( $this->checks
as $item ) {
594 list( $message, $name, $field ) = $item;
595 $line = Xml
::tags( 'div', null, Xml
::checkLabel( wfMsg($message), $name, $name,
596 $bitfields & $field ) );
597 if( $field == Revision
::DELETED_RESTRICTED
) $line = "<b>$line</b>";
604 * @param Revision $rev
607 private function historyLine( $rev ) {
608 global $wgLang, $wgUser;
610 $date = $wgLang->timeanddate( $rev->getTimestamp() );
611 $difflink = $del = '';
613 if( $this->deleteKey
=='oldid' ) {
614 $tokenParams = '&unhide=1&token='.urlencode( $wgUser->editToken( $rev->getId() ) );
615 $revlink = $this->skin
->makeLinkObj( $this->page
, $date, 'oldid='.$rev->getId() . $tokenParams );
616 $difflink = '(' . $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml('diff'),
617 'diff=' . $rev->getId() . '&oldid=prev' . $tokenParams ) . ')';
618 // Archived revisions
620 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
621 $target = $this->page
->getPrefixedText();
622 $revlink = $this->skin
->makeLinkObj( $undelete, $date,
623 "target=$target×tamp=" . $rev->getTimestamp() );
624 $difflink = '(' . $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml('diff'),
625 "target=$target&diff=prev×tamp=" . $rev->getTimestamp() ) . ')';
627 // Check permissions; items may be "suppressed"
628 if( $rev->isDeleted(Revision
::DELETED_TEXT
) ) {
629 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
630 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
631 if( !$rev->userCan(Revision
::DELETED_TEXT
) ) {
632 $revlink = '<span class="history-deleted">'.$date.'</span>';
633 $difflink = '(' . wfMsgHtml('diff') . ')';
636 $userlink = $this->skin
->revUserLink( $rev );
637 $comment = $this->skin
->revComment( $rev );
639 return "<li>$difflink $revlink $userlink $comment{$del}</li>";
646 private function fileLine( $file ) {
647 global $wgLang, $wgTitle;
649 $target = $this->page
->getPrefixedText();
650 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
654 if( $file->isDeleted(File
::DELETED_FILE
) ) {
655 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
656 if( !$file->userCan(File
::DELETED_FILE
) ) {
659 $pageLink = $this->skin
->makeKnownLinkObj( $wgTitle, $date,
660 "target=$target&file=$file->sha1.".$file->getExtension() );
662 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
665 $url = $file->getUrlRel();
666 $pageLink = "<a href=\"{$url}\">{$date}</a>";
669 $data = wfMsg( 'widthheight',
670 $wgLang->formatNum( $file->getWidth() ),
671 $wgLang->formatNum( $file->getHeight() ) ) .
672 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
673 $data = htmlspecialchars( $data );
675 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
679 * @param ArchivedFile $file
682 private function archivedfileLine( $file ) {
685 $target = $this->page
->getPrefixedText();
686 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
688 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
689 $pageLink = $this->skin
->makeKnownLinkObj( $undelete, $date, "target=$target&file={$file->getKey()}" );
692 if( $file->isDeleted(File
::DELETED_FILE
) ) {
693 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
696 $data = wfMsg( 'widthheight',
697 $wgLang->formatNum( $file->getWidth() ),
698 $wgLang->formatNum( $file->getHeight() ) ) .
699 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
700 $data = htmlspecialchars( $data );
702 return "<li> $pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
706 * @param Array $row row
709 private function logLine( $row ) {
712 $date = $wgLang->timeanddate( $row->log_timestamp
);
713 $paramArray = LogPage
::extractParams( $row->log_params
);
714 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
716 $logtitle = SpecialPage
::getTitleFor( 'Log' );
717 $loglink = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
718 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
720 if( !LogEventsList
::userCan($row,LogPage
::DELETED_ACTION
) ) {
721 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
723 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
724 $this->skin
, $paramArray, true, true );
725 if( $row->log_deleted
& LogPage
::DELETED_ACTION
)
726 $action = '<span class="history-deleted">' . $action . '</span>';
729 $userLink = $this->skin
->userLink( $row->log_user
, User
::WhoIs($row->log_user
) );
730 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_USER
) ) {
731 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
734 $comment = $wgLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
735 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
736 $comment = '<span class="history-deleted">' . $comment . '</span>';
738 return "<li>($loglink) $date $userLink $action $comment</li>";
742 * Generate a user tool link cluster if the current user is allowed to view it
743 * @param ArchivedFile $file
744 * @return string HTML
746 private function fileUserTools( $file ) {
747 if( $file->userCan( Revision
::DELETED_USER
) ) {
748 $link = $this->skin
->userLink( $file->user
, $file->user_text
) .
749 $this->skin
->userToolLinks( $file->user
, $file->user_text
);
751 $link = wfMsgHtml( 'rev-deleted-user' );
753 if( $file->isDeleted( Revision
::DELETED_USER
) ) {
754 return '<span class="history-deleted">' . $link . '</span>';
760 * Wrap and format the given file's comment block, if the current
761 * user is allowed to view it.
763 * @param ArchivedFile $file
764 * @return string HTML
766 private function fileComment( $file ) {
767 if( $file->userCan( File
::DELETED_COMMENT
) ) {
768 $block = $this->skin
->commentBlock( $file->description
);
770 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
772 if( $file->isDeleted( File
::DELETED_COMMENT
) ) {
773 return "<span class=\"history-deleted\">$block</span>";
779 * @param WebRequest $request
781 private function submit( $request ) {
782 global $wgUser, $wgOut;
783 # Check edit token on submission
784 if( $this->wasPosted
&& !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
785 $wgOut->addWikiMsg( 'sessionfailure' );
788 $bitfield = $this->extractBitfield( $request );
789 $comment = $request->getText( 'wpReason' );
790 # Can the user set this field?
791 if( $bitfield & Revision
::DELETED_RESTRICTED
&& !$wgUser->isAllowed('suppressrevision') ) {
792 $wgOut->permissionRequired( 'suppressrevision' );
795 # If the save went through, go to success message. Otherwise
796 # bounce back to form...
797 if( $this->save( $bitfield, $comment, $this->page
) ) {
799 } else if( $request->getCheck( 'oldid' ) ||
$request->getCheck( 'artimestamp' ) ) {
800 return $this->showRevs();
801 } else if( $request->getCheck( 'logid' ) ) {
802 return $this->showLogs();
803 } else if( $request->getCheck( 'oldimage' ) ||
$request->getCheck( 'fileid' ) ) {
804 return $this->showImages();
808 private function success() {
811 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
813 $wrap = '<span class="success">$1</span>';
815 if( $this->deleteKey
=='logid' ) {
816 $wgOut->wrapWikiMsg( $wrap, 'logdelete-success' );
817 $this->showLogItems();
818 } else if( $this->deleteKey
=='oldid' ||
$this->deleteKey
=='artimestamp' ) {
819 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
821 } else if( $this->deleteKey
=='fileid' ) {
822 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
824 } else if( $this->deleteKey
=='oldimage' ) {
825 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
831 * Put together a rev_deleted bitfield from the submitted checkboxes
832 * @param WebRequest $request
835 private function extractBitfield( $request ) {
837 foreach( $this->checks
as $item ) {
838 list( /* message */ , $name, $field ) = $item;
839 if( $request->getCheck( $name ) ) {
846 private function save( $bitfield, $reason, $title ) {
847 $dbw = wfGetDB( DB_MASTER
);
848 // Don't allow simply locking the interface for no reason
849 if( $bitfield == Revision
::DELETED_RESTRICTED
) {
852 $deleter = new RevisionDeleter( $dbw );
853 // By this point, only one of the below should be set
854 if( isset($this->revisions
) ) {
855 return $deleter->setRevVisibility( $title, $this->revisions
, $bitfield, $reason );
856 } else if( isset($this->archrevs
) ) {
857 return $deleter->setArchiveVisibility( $title, $this->archrevs
, $bitfield, $reason );
858 } else if( isset($this->ofiles
) ) {
859 return $deleter->setOldImgVisibility( $title, $this->ofiles
, $bitfield, $reason );
860 } else if( isset($this->afiles
) ) {
861 return $deleter->setArchFileVisibility( $title, $this->afiles
, $bitfield, $reason );
862 } else if( isset($this->events
) ) {
863 return $deleter->setEventVisibility( $title, $this->events
, $bitfield, $reason );
869 * Implements the actions for Revision Deletion.
870 * @ingroup SpecialPage
872 class RevisionDeleter
{
873 function __construct( $db ) {
878 * @param $title, the page these events apply to
879 * @param array $items list of revision ID numbers
880 * @param int $bitfield new rev_deleted value
881 * @param string $comment Comment for log records
883 function setRevVisibility( $title, $items, $bitfield, $comment ) {
886 $userAllowedAll = $success = true;
889 // Run through and pull all our data in one query
890 foreach( $items as $revid ) {
891 $where[] = intval($revid);
893 $result = $this->dbw
->select( 'revision', '*',
895 'rev_page' => $title->getArticleID(),
896 'rev_id' => $where ),
898 while( $row = $this->dbw
->fetchObject( $result ) ) {
899 $revObjs[$row->rev_id
] = new Revision( $row );
902 foreach( $items as $revid ) {
903 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
905 continue; // Must exist
906 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
907 $userAllowedAll=false;
910 // For logging, maintain a count of revisions
911 if( $revObjs[$revid]->mDeleted
!= $bitfield ) {
915 $this->updateRevision( $revObjs[$revid], $bitfield );
916 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
920 // Don't log or touch if nothing changed
921 if( $revCount > 0 ) {
922 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted
,
923 $comment, $title, 'oldid', $revIDs );
924 $this->updatePage( $title );
926 // Where all revs allowed to be set?
927 if( !$userAllowedAll ) {
928 //FIXME: still might be confusing???
929 $wgOut->permissionRequired( 'suppressrevision' );
937 * @param $title, the page these events apply to
938 * @param array $items list of revision ID numbers
939 * @param int $bitfield new rev_deleted value
940 * @param string $comment Comment for log records
942 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
945 $userAllowedAll = $success = true;
948 // Run through and pull all our data in one query
949 foreach( $items as $timestamp ) {
950 $where[] = $this->dbw
->timestamp( $timestamp );
952 $result = $this->dbw
->select( 'archive', '*',
954 'ar_namespace' => $title->getNamespace(),
955 'ar_title' => $title->getDBKey(),
956 'ar_timestamp' => $where ),
958 while( $row = $this->dbw
->fetchObject( $result ) ) {
959 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
960 $revObjs[$timestamp] = new Revision( array(
961 'page' => $title->getArticleId(),
962 'id' => $row->ar_rev_id
,
963 'text' => $row->ar_text_id
,
964 'comment' => $row->ar_comment
,
965 'user' => $row->ar_user
,
966 'user_text' => $row->ar_user_text
,
967 'timestamp' => $timestamp,
968 'minor_edit' => $row->ar_minor_edit
,
969 'text_id' => $row->ar_text_id
,
970 'deleted' => $row->ar_deleted
,
971 'len' => $row->ar_len
) );
974 foreach( $items as $timestamp ) {
975 // This will only select the first revision with this timestamp.
976 // Since they are all selected/deleted at once, we can just check the
977 // permissions of one. UPDATE is done via timestamp, so all revs are set.
978 if( !is_object($revObjs[$timestamp]) ) {
980 continue; // Must exist
981 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
982 $userAllowedAll=false;
985 // Which revisions did we change anything about?
986 if( $revObjs[$timestamp]->mDeleted
!= $bitfield ) {
987 $Id_set[]=$timestamp;
990 $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
993 // For logging, maintain a count of revisions
995 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted
,
996 $comment, $title, 'artimestamp', $Id_set );
998 // Where all revs allowed to be set?
999 if( !$userAllowedAll ) {
1000 $wgOut->permissionRequired( 'suppressrevision' );
1008 * @param $title, the page these events apply to
1009 * @param array $items list of revision ID numbers
1010 * @param int $bitfield new rev_deleted value
1011 * @param string $comment Comment for log records
1013 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
1016 $userAllowedAll = $success = true;
1019 // Run through and pull all our data in one query
1020 foreach( $items as $timestamp ) {
1021 $where[] = $timestamp.'!'.$title->getDBKey();
1023 $result = $this->dbw
->select( 'oldimage', '*',
1025 'oi_name' => $title->getDBKey(),
1026 'oi_archive_name' => $where ),
1028 while( $row = $this->dbw
->fetchObject( $result ) ) {
1029 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
1030 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
1031 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
1034 foreach( $items as $timestamp ) {
1035 $archivename = $timestamp.'!'.$title->getDBKey();
1036 if( !isset($filesObjs[$archivename]) ) {
1038 continue; // Must exist
1039 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
1040 $userAllowedAll=false;
1044 $transaction = true;
1045 // Which revisions did we change anything about?
1046 if( $filesObjs[$archivename]->deleted
!= $bitfield ) {
1049 $this->dbw
->begin();
1050 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
1051 // If this image is currently hidden...
1052 if( $filesObjs[$archivename]->deleted
& File
::DELETED_FILE
) {
1053 if( $bitfield & File
::DELETED_FILE
) {
1054 # Leave it alone if we are not changing this...
1056 $transaction = true;
1058 # We are moving this out
1059 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
1060 $set[]=$transaction;
1062 // Is it just now becoming hidden?
1063 } else if( $bitfield & File
::DELETED_FILE
) {
1064 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
1065 $set[]=$transaction;
1069 // If our file operations fail, then revert back the db
1070 if( $transaction==false ) {
1071 $this->dbw
->rollback();
1074 $this->dbw
->commit();
1078 // Log if something was changed
1080 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted
,
1081 $comment, $title, 'oldimage', $set );
1082 # Purge page/history
1083 $file = wfLocalFile( $title );
1084 $file->purgeCache();
1085 $file->purgeHistory();
1086 # Invalidate cache for all pages using this file
1087 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
1088 $update->doUpdate();
1090 // Where all revs allowed to be set?
1091 if( !$userAllowedAll ) {
1092 $wgOut->permissionRequired( 'suppressrevision' );
1100 * @param $title, the page these events apply to
1101 * @param array $items list of revision ID numbers
1102 * @param int $bitfield new rev_deleted value
1103 * @param string $comment Comment for log records
1105 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
1108 $userAllowedAll = $success = true;
1112 // Run through and pull all our data in one query
1113 foreach( $items as $id ) {
1114 $where[] = intval($id);
1116 $result = $this->dbw
->select( 'filearchive', '*',
1117 array( 'fa_name' => $title->getDBKey(),
1118 'fa_id' => $where ),
1120 while( $row = $this->dbw
->fetchObject( $result ) ) {
1121 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
1124 foreach( $items as $fileid ) {
1125 if( !isset($filesObjs[$fileid]) ) {
1127 continue; // Must exist
1128 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
1129 $userAllowedAll=false;
1132 // Which revisions did we change anything about?
1133 if( $filesObjs[$fileid]->deleted
!= $bitfield ) {
1137 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1140 // Log if something was changed
1142 $this->updateLog( $title, $count, $bitfield, $comment,
1143 $filesObjs[$fileid]->deleted
, $title, 'fileid', $Id_set );
1145 // Where all revs allowed to be set?
1146 if( !$userAllowedAll ) {
1147 $wgOut->permissionRequired( 'suppressrevision' );
1155 * @param $title, the log page these events apply to
1156 * @param array $items list of log ID numbers
1157 * @param int $bitfield new log_deleted value
1158 * @param string $comment Comment for log records
1160 function setEventVisibility( $title, $items, $bitfield, $comment ) {
1163 $userAllowedAll = $success = true;
1167 // Run through and pull all our data in one query
1168 foreach( $items as $logid ) {
1169 $where[] = intval($logid);
1171 list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
1172 $result = $this->dbw
->select( 'logging', '*',
1174 'log_type' => $logtype,
1175 'log_id' => $where ),
1177 while( $row = $this->dbw
->fetchObject( $result ) ) {
1178 $logRows[$row->log_id
] = $row;
1181 foreach( $items as $logid ) {
1182 if( !isset($logRows[$logid]) ) {
1184 continue; // Must exist
1185 } else if( !LogEventsList
::userCan($logRows[$logid], LogPage
::DELETED_RESTRICTED
)
1186 ||
$logRows[$logid]->log_type
== 'suppress' ) {
1187 // Don't hide from oversight log!!!
1188 $userAllowedAll=false;
1191 // Which logs did we change anything about?
1192 if( $logRows[$logid]->log_deleted
!= $bitfield ) {
1196 $this->updateLogs( $logRows[$logid], $bitfield );
1197 $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
1200 // Don't log or touch if nothing changed
1202 $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted
,
1203 $comment, $title, 'logid', $log_Ids );
1205 // Were all revs allowed to be set?
1206 if( !$userAllowedAll ) {
1207 $wgOut->permissionRequired( 'suppressrevision' );
1215 * Moves an image to a safe private location
1216 * Caller is responsible for clearing caches
1217 * @param File $oimage
1218 * @returns mixed, timestamp string on success, false on failure
1220 function makeOldImagePrivate( $oimage ) {
1221 $transaction = new FSTransaction();
1222 if( !FileStore
::lock() ) {
1223 wfDebug( __METHOD__
.": failed to acquire file store lock, aborting\n" );
1226 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1227 // Dupe the file into the file store
1228 if( file_exists( $oldpath ) ) {
1229 // Is our directory configured?
1230 if( $store = FileStore
::get( 'deleted' ) ) {
1231 if( !$oimage->sha1
) {
1232 $oimage->upgradeRow(); // sha1 may be missing
1234 $key = $oimage->sha1
. '.' . $oimage->getExtension();
1235 $transaction->add( $store->insert( $key, $oldpath, FileStore
::DELETE_ORIGINAL
) );
1239 $transaction = false; // Return an error and do nothing
1242 wfDebug( __METHOD__
." deleting already-missing '$oldpath'; moving on to database\n" );
1245 $transaction = new FSTransaction(); // empty
1248 if( $transaction === false ) {
1250 wfDebug( __METHOD__
.": import to file store failed, aborting\n" );
1251 throw new MWException( "Could not archive and delete file $oldpath" );
1255 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1256 $transaction->commit();
1257 FileStore
::unlock();
1259 $m = explode('!',$oimage->archive_name
,2);
1266 * Moves an image from a safe private location
1267 * Caller is responsible for clearing caches
1268 * @param File $oimage
1269 * @returns mixed, string timestamp on success, false on failure
1271 function makeOldImagePublic( $oimage ) {
1272 $transaction = new FSTransaction();
1273 if( !FileStore
::lock() ) {
1274 wfDebug( __METHOD__
." could not acquire filestore lock\n" );
1278 $store = FileStore
::get( 'deleted' );
1280 wfDebug( __METHOD__
.": skipping row with no file.\n" );
1284 $key = $oimage->sha1
.'.'.$oimage->getExtension();
1285 $destDir = $oimage->getArchivePath();
1286 if( !is_dir( $destDir ) ) {
1287 wfMkdirParents( $destDir );
1289 $destPath = $destDir . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1290 // Check if any other stored revisions use this file;
1291 // if so, we shouldn't remove the file from the hidden
1292 // archives so they will still work. Check hidden files first.
1293 $useCount = $this->dbw
->selectField( 'oldimage', '1',
1294 array( 'oi_sha1' => $oimage->sha1
,
1295 'oi_deleted & '.File
::DELETED_FILE
=> File
::DELETED_FILE
),
1296 __METHOD__
, array( 'FOR UPDATE' ) );
1297 // Check the rest of the deleted archives too.
1298 // (these are the ones that don't show in the image history)
1300 $useCount = $this->dbw
->selectField( 'filearchive', '1',
1301 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1302 __METHOD__
, array( 'FOR UPDATE' ) );
1305 if( $useCount == 0 ) {
1306 wfDebug( __METHOD__
.": nothing else using {$oimage->sha1}, will deleting after\n" );
1307 $flags = FileStore
::DELETE_ORIGINAL
;
1311 $transaction->add( $store->export( $key, $destPath, $flags ) );
1313 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1314 $transaction->commit();
1315 FileStore
::unlock();
1317 $m = explode('!',$oimage->archive_name
,2);
1324 * Update the revision's rev_deleted field
1325 * @param Revision $rev
1326 * @param int $bitfield new rev_deleted bitfield value
1328 function updateRevision( $rev, $bitfield ) {
1329 $this->dbw
->update( 'revision',
1330 array( 'rev_deleted' => $bitfield ),
1331 array( 'rev_id' => $rev->getId(),
1332 'rev_page' => $rev->getPage() ),
1337 * Update the revision's rev_deleted field
1338 * @param Revision $rev
1339 * @param Title $title
1340 * @param int $bitfield new rev_deleted bitfield value
1342 function updateArchive( $rev, $title, $bitfield ) {
1343 $this->dbw
->update( 'archive',
1344 array( 'ar_deleted' => $bitfield ),
1345 array( 'ar_namespace' => $title->getNamespace(),
1346 'ar_title' => $title->getDBKey(),
1347 'ar_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ),
1348 'ar_rev_id' => $rev->getId() ),
1353 * Update the images's oi_deleted field
1355 * @param int $bitfield new rev_deleted bitfield value
1357 function updateOldFiles( $file, $bitfield ) {
1358 $this->dbw
->update( 'oldimage',
1359 array( 'oi_deleted' => $bitfield ),
1360 array( 'oi_name' => $file->getName(),
1361 'oi_timestamp' => $this->dbw
->timestamp( $file->getTimestamp() ) ),
1366 * Update the images's fa_deleted field
1367 * @param ArchivedFile $file
1368 * @param int $bitfield new rev_deleted bitfield value
1370 function updateArchFiles( $file, $bitfield ) {
1371 $this->dbw
->update( 'filearchive',
1372 array( 'fa_deleted' => $bitfield ),
1373 array( 'fa_id' => $file->getId() ),
1378 * Update the logging log_deleted field
1380 * @param int $bitfield new rev_deleted bitfield value
1382 function updateLogs( $row, $bitfield ) {
1383 $this->dbw
->update( 'logging',
1384 array( 'log_deleted' => $bitfield ),
1385 array( 'log_id' => $row->log_id
),
1390 * Update the revision's recentchanges record if fields have been hidden
1391 * @param Revision $rev
1392 * @param int $bitfield new rev_deleted bitfield value
1394 function updateRecentChangesEdits( $rev, $bitfield ) {
1395 $this->dbw
->update( 'recentchanges',
1396 array( 'rc_deleted' => $bitfield,
1397 'rc_patrolled' => 1 ),
1398 array( 'rc_this_oldid' => $rev->getId(),
1399 'rc_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ) ),
1404 * Update the revision's recentchanges record if fields have been hidden
1406 * @param int $bitfield new rev_deleted bitfield value
1408 function updateRecentChangesLog( $row, $bitfield ) {
1409 $this->dbw
->update( 'recentchanges',
1410 array( 'rc_deleted' => $bitfield,
1411 'rc_patrolled' => 1 ),
1412 array( 'rc_logid' => $row->log_id
,
1413 'rc_timestamp' => $row->log_timestamp
),
1418 * Touch the page's cache invalidation timestamp; this forces cached
1419 * history views to refresh, so any newly hidden or shown fields will
1421 * @param Title $title
1423 function updatePage( $title ) {
1424 $title->invalidateCache();
1425 $title->purgeSquid();
1426 $title->touchLinks();
1427 // Extensions that require referencing previous revisions may need this
1428 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1432 * Checks for a change in the bitfield for a certain option and updates the
1433 * provided array accordingly.
1435 * @param String $desc Description to add to the array if the option was
1436 * enabled / disabled.
1437 * @param int $field The bitmask describing the single option.
1438 * @param int $diff The xor of the old and new bitfields.
1439 * @param array $arr The array to update.
1441 function checkItem ( $desc, $field, $diff, $new, &$arr ) {
1442 if ( $diff & $field ) {
1443 $arr [ ( $new & $field ) ?
0 : 1 ][] = $desc;
1448 * Gets an array describing the changes made to the visibilit of the revision.
1449 * If the resulting array is $arr, then $arr[0] will contain an array of strings
1450 * describing the items that were hidden, $arr[2] will contain an array of strings
1451 * describing the items that were unhidden, and $arr[3] will contain an array with
1452 * a single string, which can be one of "applied restrictions to sysops",
1453 * "removed restrictions from sysops", or null.
1455 * @param int $n The new bitfield.
1456 * @param int $o The old bitfield.
1457 * @return An array as described above.
1459 function getChanges ( $n, $o ) {
1461 $ret = array ( 0 => array(), 1 => array(), 2 => array() );
1463 $this->checkItem ( wfMsgForContent ( 'revdelete-content' ),
1464 Revision
::DELETED_TEXT
, $diff, $n, $ret );
1465 $this->checkItem ( wfMsgForContent ( 'revdelete-summary' ),
1466 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
1467 $this->checkItem ( wfMsgForContent ( 'revdelete-uname' ),
1468 Revision
::DELETED_USER
, $diff, $n, $ret );
1470 // Restriction application to sysops
1471 if ( $diff & Revision
::DELETED_RESTRICTED
) {
1472 if ( $n & Revision
::DELETED_RESTRICTED
)
1473 $ret[2][] = wfMsgForContent ( 'revdelete-restricted' );
1475 $ret[2][] = wfMsgForContent ( 'revdelete-unrestricted' );
1482 * Gets a log message to describe the given revision visibility change. This
1483 * message will be of the form "[hid {content, edit summary, username}];
1484 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
1486 * @param int $count The number of effected revisions.
1487 * @param int $nbitfield The new bitfield for the revision.
1488 * @param int $obitfield The old bitfield for the revision.
1489 * @param string $comment The comment associated with the change.
1490 * @param bool $isForLog
1492 function getLogMessage ( $count, $nbitfield, $obitfield, $comment, $isForLog = false ) {
1496 $changes = $this->getChanges( $nbitfield, $obitfield );
1498 if ( count ( $changes[0] ) ) {
1499 $s .= wfMsgForContent ( 'revdelete-hid', implode ( ', ', $changes[0] ) );
1502 if ( count ( $changes[1] ) ) {
1505 $s .= wfMsgForContent ( 'revdelete-unhid', implode ( ', ', $changes[1] ) );
1508 if ( count ( $changes[2] )) {
1510 $s .= ' (' . $changes[2][0] . ')';
1512 $s = $changes[2][0];
1515 $msg = $isForLog ?
'logdelete-log-message' : 'revdelete-log-message';
1516 $ret = wfMsgExt ( $msg, array( 'parsemag', 'content' ),
1517 $s, $wgContLang->formatNum( $count ) );
1520 $ret .= ": $comment";
1527 * Record a log entry on the action
1528 * @param Title $title, page where item was removed from
1529 * @param int $count the number of revisions altered for this page
1530 * @param int $nbitfield the new _deleted value
1531 * @param int $obitfield the old _deleted value
1532 * @param string $comment
1533 * @param Title $target, the relevant page
1534 * @param string $param, URL param
1535 * @param Array $items
1537 function updateLog( $title, $count, $nbitfield, $obitfield, $comment,
1538 $target, $param, $items = array() )
1540 // Put things hidden from sysops in the oversight log
1541 $logtype = ( ($nbitfield |
$obitfield) & Revision
::DELETED_RESTRICTED
) ?
'suppress' : 'delete';
1542 $log = new LogPage( $logtype );
1544 $reason = $this->getLogMessage( $count, $nbitfield, $obitfield, $comment, $param == 'logid' );
1546 if( $param == 'logid' ) {
1547 $params = array( implode( ',', $items) );
1548 $log->addEntry( 'event', $title, $reason, $params );
1550 // Add params for effected page and ids
1551 $params = array( $param, implode( ',', $items) );
1552 $log->addEntry( 'revision', $title, $reason, $params );