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 ); // paranoia
17 public function execute( $par ) {
18 global $wgOut, $wgUser, $wgRequest;
19 if( !$wgUser->isAllowed( 'deleterevision' ) ) {
20 return $wgOut->permissionRequired( 'deleterevision' );
21 } else if( wfReadOnly() ) {
22 return $wgOut->readOnlyPage();
24 $this->skin
=& $wgUser->getSkin();
26 $this->outputHeader();
27 $this->wasPosted
= $wgRequest->wasPosted();
29 $this->target
= $wgRequest->getText( 'target' );
30 # Handle our many different possible input types.
31 # Use CVS, since the cgi handling will break on arrays.
32 $this->oldids
= explode( ',', $wgRequest->getVal('oldid') );
33 $this->oldids
= array_unique( array_filter($this->oldids
) );
34 $this->artimestamps
= explode( ',', $wgRequest->getVal('artimestamp') );
35 $this->artimestamps
= array_unique( array_filter($this->artimestamps
) );
36 $this->logids
= explode( ',', $wgRequest->getVal('logid') );
37 $this->logids
= array_unique( array_filter($this->logids
) );
38 $this->oldimgs
= explode( ',', $wgRequest->getVal('oldimage') );
39 $this->oldimgs
= array_unique( array_filter($this->oldimgs
) );
40 $this->fileids
= explode( ',', $wgRequest->getVal('fileid') );
41 $this->fileids
= array_unique( array_filter($this->fileids
) );
42 # For reviewing deleted files...
43 $this->file
= $wgRequest->getVal( 'file' );
44 # Only one target set at a time please!
45 $types = (bool)$this->file +
(bool)$this->oldids +
(bool)$this->logids
46 +
(bool)$this->artimestamps +
(bool)$this->fileids +
(bool)$this->oldimgs
;
49 return $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
51 } else if( $types > 1 ) {
52 return $wgOut->showErrorPage( 'revdelete-toomanytargets-title', 'revdelete-toomanytargets-text' );
54 $this->page
= Title
::newFromUrl( $this->target
);
55 $this->contextPage
= Title
::newFromUrl( $wgRequest->getText( 'page' ) );
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 return $wgOut->addWikiMsg( 'undelete-header' );
67 # For reviewing deleted files...show it now if allowed
69 return $this->tryShowFile( $this->file
);
71 # Logs must have a type given
72 if( $this->logids
&& !strpos($this->page
->getDBKey(),'/') ) {
73 return $wgOut->showErrorPage( 'revdelete-nologtype-title', 'revdelete-nologtype-text' );
75 # Give a link to the logs/hist for this page
76 $this->showConvenienceLinks();
77 # Lock the operation and the form context
78 $this->secureOperation();
79 # Either submit or create our form
80 if( $this->wasPosted
) {
81 $this->submit( $wgRequest );
82 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
84 } else if( $this->deleteKey
== 'fileid' ||
$this->deleteKey
== 'oldimage' ) {
86 } else if( $this->deleteKey
== 'logid' ) {
87 $this->showLogItems();
89 list($qc,$lim) = $this->getLogQueryCond();
90 # Show relevant lines from the deletion log
91 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'delete' ) ) . "</h2>\n" );
92 LogEventsList
::showLogExtract( $wgOut, 'delete', $this->page
->getPrefixedText(), '', $lim, $qc );
93 # Show relevant lines from the suppression log
94 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
95 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'suppress' ) ) . "</h2>\n" );
96 LogEventsList
::showLogExtract( $wgOut, 'suppress', $this->page
->getPrefixedText(), '', $lim, $qc );
100 private function showConvenienceLinks() {
101 global $wgOut, $wgUser;
102 # Give a link to the logs/hist for this page
103 if( !is_null($this->page
) && $this->page
->getNamespace() > -1 ) {
105 $logtitle = SpecialPage
::getTitleFor( 'Log' );
106 $links[] = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
107 wfArrayToCGI( array( 'page' => $this->page
->getPrefixedUrl() ) ) );
108 # Give a link to the page history
109 $links[] = $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml( 'pagehist' ),
110 wfArrayToCGI( array( 'action' => 'history' ) ) );
111 # Link to deleted edits
112 if( $wgUser->isAllowed('undelete') ) {
113 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
114 $links[] = $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
115 wfArrayToCGI( array( 'target' => $this->page
->getPrefixedDBkey() ) ) );
117 # Logs themselves don't have histories or archived revisions
118 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
122 private function getLogQueryCond() {
123 $ids = $safeIds = array();
124 $action = 'revision';
125 $limit = 25; // default
126 switch( $this->deleteKey
) {
128 $ids = $this->oldids
;
131 $ids = $this->artimestamps
;
134 $ids = $this->oldimgs
;
137 $ids = $this->fileids
;
140 $ids = $this->logids
;
144 // Revision delete logs
145 $conds = array( 'log_action' => $action );
146 // Just get the whole log if there are a lot if items
147 if( count($ids) > $limit )
148 return array($conds,$limit);
150 foreach( $ids as $id ) {
151 if( preg_match( '/^\d+$/', $id, $m ) ) {
155 // Optimization for logs
156 if( $action == 'event' ) {
157 $dbr = wfGetDB( DB_SLAVE
);
158 # Get the timestamp of the first item
159 $first = $dbr->selectField( 'logging', 'log_timestamp',
160 array('log_id' => $safeIds), __METHOD__
, array('ORDER BY' => 'log_id') );
161 # If there are no items, then stop here
162 if( $first == false ) {
163 $conds = array('1=0');
164 return array($conds,$limit);
166 # The event was be hidden after it was made
167 $conds[] = 'log_timestamp > '.$dbr->addQuotes($first); // type,time index
169 // Format is <id1,id2,i3...>
170 if( count($safeIds) ) {
171 $conds[] = "log_params RLIKE '(^|\n|,)(".implode('|',$safeIds).")(,|\n|$)'";
173 $conds = array('1=0');
175 return array($conds,$limit);
178 private function secureOperation() {
180 $this->deleteKey
= '';
181 // At this point, we should only have one of these
182 if( $this->oldids
) {
183 $this->revisions
= $this->oldids
;
184 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
185 $this->deleteKey
= 'oldid';
186 } else if( $this->artimestamps
) {
187 $this->archrevs
= $this->artimestamps
;
188 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
189 $this->deleteKey
= 'artimestamp';
190 } else if( $this->oldimgs
) {
191 $this->ofiles
= $this->oldimgs
;
192 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
193 $this->deleteKey
= 'oldimage';
194 } else if( $this->fileids
) {
195 $this->afiles
= $this->fileids
;
196 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
197 $this->deleteKey
= 'fileid';
198 } else if( $this->logids
) {
199 $this->events
= $this->logids
;
200 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage
::DELETED_ACTION
);
201 $this->deleteKey
= 'logid';
203 // Our checkbox messages depends one what we are doing,
204 // e.g. we don't hide "text" for logs or images
205 $this->checks
= array(
207 array( 'revdelete-hide-comment', 'wpHideComment', Revision
::DELETED_COMMENT
),
208 array( 'revdelete-hide-user', 'wpHideUser', Revision
::DELETED_USER
)
210 if( $wgUser->isAllowed('suppressrevision') ) {
211 $this->checks
[] = array( 'revdelete-hide-restricted',
212 'wpHideRestricted', Revision
::DELETED_RESTRICTED
);
217 * Show a deleted file version requested by the visitor.
219 private function tryShowFile( $key ) {
220 global $wgOut, $wgRequest;
221 $oimage = RepoGroup
::singleton()->getLocalRepo()->newFromArchiveName( $this->page
, $key );
223 // Check if user is allowed to see this file
224 if( !$oimage->userCan(File
::DELETED_FILE
) ) {
225 $wgOut->permissionRequired( 'suppressrevision' );
228 # We mustn't allow the output to be Squid cached, otherwise
229 # if an admin previews a deleted image, and it's cached, then
230 # a user without appropriate permissions can toddle off and
231 # nab the image, and Squid will serve it
232 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
233 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
234 $wgRequest->response()->header( 'Pragma: no-cache' );
235 # Stream the file to the client
236 $store = FileStore
::get( 'deleted' );
237 $store->stream( $key );
242 * This lets a user set restrictions for live and archived revisions
244 private function showRevs() {
245 global $wgOut, $wgUser;
248 $count = ($this->deleteKey
== 'oldid') ?
249 count($this->revisions
) : count($this->archrevs
);
250 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(), $count );
253 $wgOut->addHTML( "<ul>" );
255 $where = $revObjs = array();
256 $dbr = wfGetDB( DB_MASTER
);
260 if( $this->deleteKey
== 'oldid' ) {
261 // Run through and pull all our data in one query
262 foreach( $this->revisions
as $revid ) {
263 $where[] = intval($revid);
265 $result = $dbr->select( array('revision','page'), '*',
267 'rev_page' => $this->page
->getArticleID(),
273 while( $row = $dbr->fetchObject( $result ) ) {
274 $revObjs[$row->rev_id
] = new Revision( $row );
276 foreach( $this->revisions
as $revid ) {
277 if( !isset($revObjs[$revid]) ) continue; // Must exist
278 // Check if the revision was Oversighted
279 if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
280 if( !$this->wasPosted
) {
281 return $wgOut->permissionRequired( 'suppressrevision' );
283 $UserAllowed = false;
286 $wgOut->addHTML( $this->historyLine( $revObjs[$revid] ) );
287 $bitfields |
= $revObjs[$revid]->mDeleted
;
291 // Run through and pull all our data in one query
292 foreach( $this->archrevs
as $timestamp ) {
293 $where[] = $dbr->timestamp( $timestamp );
295 $result = $dbr->select( 'archive', '*',
297 'ar_namespace' => $this->page
->getNamespace(),
298 'ar_title' => $this->page
->getDBKey(),
299 'ar_timestamp' => $where
303 while( $row = $dbr->fetchObject( $result ) ) {
304 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
305 $revObjs[$timestamp] = new Revision( array(
306 'page' => $this->page
->getArticleId(),
307 'id' => $row->ar_rev_id
,
308 'text' => $row->ar_text_id
,
309 'comment' => $row->ar_comment
,
310 'user' => $row->ar_user
,
311 'user_text' => $row->ar_user_text
,
312 'timestamp' => $timestamp,
313 'minor_edit' => $row->ar_minor_edit
,
314 'text_id' => $row->ar_text_id
,
315 'deleted' => $row->ar_deleted
,
316 'len' => $row->ar_len
) );
318 foreach( $this->archrevs
as $timestamp ) {
319 if( !isset($revObjs[$timestamp]) ) {
321 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
322 // If a rev is hidden from sysops
323 if( !$this->wasPosted
) {
324 return $wgOut->permissionRequired( 'suppressrevision' );
326 $UserAllowed = false;
329 $wgOut->addHTML( $this->historyLine( $revObjs[$timestamp] ) );
330 $bitfields |
= $revObjs[$timestamp]->mDeleted
;
334 return $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
337 $wgOut->addHTML( "</ul>" );
339 $this->addUsageText();
341 // Normal sysops can always see what they did, but can't always change it
342 if( !$UserAllowed ) return;
345 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
346 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
349 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
350 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
351 Xml
::hidden( 'type', $this->deleteKey
)
353 if( $this->deleteKey
== 'oldid' ) {
354 $hidden[] = Xml
::hidden( 'oldid', implode(',',$this->oldids
) );
356 $hidden[] = Xml
::hidden( 'artimestamp', implode(',',$this->artimestamps
) );
359 Xml
::openElement( 'form', array( 'method' => 'post',
360 'action' => $this->getTitle()->getLocalUrl( 'action=submit' ),
361 'id' => 'mw-revdel-form-revisions' ) ) .
362 Xml
::openElement( 'fieldset' ) .
363 xml
::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
366 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
367 foreach( $items as $item ) {
368 $wgOut->addHTML( Xml
::tags( 'p', null, $item ) );
370 foreach( $hidden as $item ) {
371 $wgOut->addHTML( $item );
374 Xml
::closeElement( 'fieldset' ) .
375 Xml
::closeElement( 'form' ) . "\n"
380 * This lets a user set restrictions for archived images
382 private function showImages() {
383 global $wgOut, $wgUser, $wgLang;
386 $count = ($this->deleteKey
== 'oldimage') ?
count($this->ofiles
) : count($this->afiles
);
387 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(),
388 $wgLang->formatNum($count) );
391 $wgOut->addHTML( "<ul>" );
393 $where = $filesObjs = array();
394 $dbr = wfGetDB( DB_MASTER
);
395 // Live old revisions...
397 if( $this->deleteKey
== 'oldimage' ) {
398 // Run through and pull all our data in one query
399 foreach( $this->ofiles
as $timestamp ) {
400 $where[] = $timestamp.'!'.$this->page
->getDBKey();
402 $result = $dbr->select( 'oldimage', '*',
404 'oi_name' => $this->page
->getDBKey(),
405 'oi_archive_name' => $where
409 while( $row = $dbr->fetchObject( $result ) ) {
410 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
411 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
412 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
414 // Check through our images
415 foreach( $this->ofiles
as $timestamp ) {
416 $archivename = $timestamp.'!'.$this->page
->getDBKey();
417 if( !isset($filesObjs[$archivename]) ) {
419 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
420 // If a rev is hidden from sysops
421 if( !$this->wasPosted
) {
422 return $wgOut->permissionRequired( 'suppressrevision' );
424 $UserAllowed = false;
427 // Inject history info
428 $wgOut->addHTML( $this->fileLine( $filesObjs[$archivename] ) );
429 $bitfields |
= $filesObjs[$archivename]->deleted
;
433 // Run through and pull all our data in one query
434 foreach( $this->afiles
as $id ) {
435 $where[] = intval($id);
437 $result = $dbr->select( 'filearchive', '*',
439 'fa_name' => $this->page
->getDBKey(),
444 while( $row = $dbr->fetchObject( $result ) ) {
445 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
448 foreach( $this->afiles
as $fileid ) {
449 if( !isset($filesObjs[$fileid]) ) {
451 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
452 // If a rev is hidden from sysops
453 if( !$this->wasPosted
) {
454 return $wgOut->permissionRequired( 'suppressrevision' );
456 $UserAllowed = false;
459 // Inject history info
460 $wgOut->addHTML( $this->archivedfileLine( $filesObjs[$fileid] ) );
461 $bitfields |
= $filesObjs[$fileid]->deleted
;
465 return $wgOut->showErrorPage( 'revdelete-nooldid-title','revdelete-nooldid-text' );
468 $wgOut->addHTML( "</ul>" );
470 $this->addUsageText();
471 // Normal sysops can always see what they did, but can't always change it
472 if( !$UserAllowed ) return;
475 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
476 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
479 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
480 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
481 Xml
::hidden( 'type', $this->deleteKey
)
483 if( $this->deleteKey
== 'oldimage' ) {
484 $hidden[] = Xml
::hidden( 'oldimage', implode(',',$this->oldimgs
) );
486 $hidden[] = Xml
::hidden( 'fileid', implode(',',$this->fileids
) );
489 Xml
::openElement( 'form', array( 'method' => 'post',
490 'action' => $this->getTitle()->getLocalUrl( 'action=submit' ),
491 'id' => 'mw-revdel-form-filerevisions' )
493 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
496 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
497 foreach( $items as $item ) {
498 $wgOut->addHTML( "<p>$item</p>" );
500 foreach( $hidden as $item ) {
501 $wgOut->addHTML( $item );
505 Xml
::closeElement( 'fieldset' ) .
506 Xml
::closeElement( 'form' ) . "\n"
511 * This lets a user set restrictions for log items
513 private function showLogItems() {
514 global $wgOut, $wgUser, $wgMessageCache, $wgLang;
517 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->events
) ) );
520 $wgOut->addHTML( "<ul>" );
522 $where = $logRows = array();
523 $dbr = wfGetDB( DB_MASTER
);
524 // Run through and pull all our data in one query
526 foreach( $this->events
as $logid ) {
527 $where[] = intval($logid);
529 list($log,$logtype) = explode( '/',$this->page
->getDBKey(), 2 );
530 $result = $dbr->select( 'logging', '*',
531 array( 'log_type' => $logtype, 'log_id' => $where ),
534 while( $row = $dbr->fetchObject( $result ) ) {
535 $logRows[$row->log_id
] = $row;
537 $wgMessageCache->loadAllMessages();
538 foreach( $this->events
as $logid ) {
539 // Don't hide from oversight log!!!
540 if( !isset( $logRows[$logid] ) ||
$logRows[$logid]->log_type
=='suppress' ) {
542 } else if( !LogEventsList
::userCan( $logRows[$logid],Revision
::DELETED_RESTRICTED
) ) {
543 // If an event is hidden from sysops
544 if( !$this->wasPosted
) {
545 return $wgOut->permissionRequired( 'suppressrevision' );
547 $UserAllowed = false;
550 $wgOut->addHTML( $this->logLine( $logRows[$logid] ) );
551 $bitfields |
= $logRows[$logid]->log_deleted
;
554 return $wgOut->showErrorPage( 'revdelete-nologid-title', 'revdelete-nologid-text' );
557 $wgOut->addHTML( "</ul>" );
559 $this->addUsageText();
560 // Normal sysops can always see what they did, but can't always change it
561 if( !$UserAllowed ) return;
564 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
565 Xml
::submitButton( wfMsg( 'revdelete-submit' ) ) );
567 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
568 Xml
::hidden( 'target', $this->page
->getPrefixedDBKey() ),
569 Xml
::hidden( 'page', $this->contextPage ?
$this->contextPage
->getPrefixedDBKey() : '' ),
570 Xml
::hidden( 'type', $this->deleteKey
),
571 Xml
::hidden( 'logid', implode(',',$this->logids
) )
575 Xml
::openElement( 'form', array( 'method' => 'post',
576 'action' => $this->getTitle()->getLocalUrl( 'action=submit' ), 'id' => 'mw-revdel-form-logs' ) ) .
577 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
580 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
581 foreach( $items as $item ) {
582 $wgOut->addHTML( "<p>$item</p>" );
584 foreach( $hidden as $item ) {
585 $wgOut->addHTML( $item );
589 Xml
::closeElement( 'fieldset' ) .
590 Xml
::closeElement( 'form' ) . "\n"
594 private function addUsageText() {
595 global $wgOut, $wgUser;
596 $wgOut->addWikiMsg( 'revdelete-text' );
597 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
598 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
603 * @param int $bitfields, aggregate bitfield of all the bitfields
604 * @returns string HTML
606 private function buildCheckBoxes( $bitfields ) {
608 // FIXME: all items checked for just one rev are checked, even if not set for the others
609 foreach( $this->checks
as $item ) {
610 list( $message, $name, $field ) = $item;
611 $line = Xml
::tags( 'div', null, Xml
::checkLabel( wfMsg($message), $name, $name,
612 $bitfields & $field ) );
613 if( $field == Revision
::DELETED_RESTRICTED
) $line = "<b>$line</b>";
620 * @param Revision $rev
623 private function historyLine( $rev ) {
624 global $wgLang, $wgUser;
626 $date = $wgLang->timeanddate( $rev->getTimestamp() );
627 $difflink = $del = '';
629 if( $this->deleteKey
== 'oldid' ) {
630 $tokenParams = '&unhide=1&token='.urlencode( $wgUser->editToken( $rev->getId() ) );
631 $revlink = $this->skin
->makeLinkObj( $this->page
, $date, 'oldid='.$rev->getId() . $tokenParams );
632 $difflink = '(' . $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml('diff'),
633 'diff=' . $rev->getId() . '&oldid=prev' . $tokenParams ) . ')';
634 // Archived revisions
636 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
637 $target = $this->page
->getPrefixedText();
638 $revlink = $this->skin
->makeLinkObj( $undelete, $date,
639 "target=$target×tamp=" . $rev->getTimestamp() );
640 $difflink = '(' . $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml('diff'),
641 "target=$target&diff=prev×tamp=" . $rev->getTimestamp() ) . ')';
643 // Check permissions; items may be "suppressed"
644 if( $rev->isDeleted(Revision
::DELETED_TEXT
) ) {
645 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
646 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
647 if( !$rev->userCan(Revision
::DELETED_TEXT
) ) {
648 $revlink = '<span class="history-deleted">'.$date.'</span>';
649 $difflink = '(' . wfMsgHtml('diff') . ')';
652 $userlink = $this->skin
->revUserLink( $rev );
653 $comment = $this->skin
->revComment( $rev );
655 return "<li>$difflink $revlink $userlink $comment{$del}</li>";
662 private function fileLine( $file ) {
665 $target = $this->page
->getPrefixedText();
666 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
670 if( $file->isDeleted(File
::DELETED_FILE
) ) {
671 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
672 if( !$file->userCan(File
::DELETED_FILE
) ) {
675 $pageLink = $this->skin
->makeKnownLinkObj( $this->getTitle(), $date,
676 "target=$target&file=$file->sha1.".$file->getExtension() );
678 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
681 $url = $file->getUrlRel();
682 $pageLink = "<a href=\"{$url}\">{$date}</a>";
685 $data = wfMsg( 'widthheight', $wgLang->formatNum( $file->getWidth() ),
686 $wgLang->formatNum( $file->getHeight() ) ) .
687 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
688 $data = htmlspecialchars( $data );
690 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".
691 $this->fileComment( $file )."$del</li>";
695 * @param ArchivedFile $file
698 private function archivedfileLine( $file ) {
701 $target = $this->page
->getPrefixedText();
702 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
704 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
705 $pageLink = $this->skin
->makeKnownLinkObj( $undelete, $date,
706 "target=$target&file={$file->getKey()}" );
709 if( $file->isDeleted(File
::DELETED_FILE
) ) {
710 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
713 $data = wfMsg( 'widthheight', $wgLang->formatNum( $file->getWidth() ),
714 $wgLang->formatNum( $file->getHeight() ) ) .
715 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
716 $data = htmlspecialchars( $data );
718 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".
719 $this->fileComment( $file )."$del</li>";
723 * @param Array $row row
726 private function logLine( $row ) {
729 $date = $wgLang->timeanddate( $row->log_timestamp
);
730 $paramArray = LogPage
::extractParams( $row->log_params
);
731 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
733 $logtitle = SpecialPage
::getTitleFor( 'Log' );
734 $loglink = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
735 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
737 if( !LogEventsList
::userCan($row,LogPage
::DELETED_ACTION
) ) {
738 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
740 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
741 $this->skin
, $paramArray, true, true );
742 if( $row->log_deleted
& LogPage
::DELETED_ACTION
)
743 $action = '<span class="history-deleted">' . $action . '</span>';
746 $userLink = $this->skin
->userLink( $row->log_user
, User
::WhoIs($row->log_user
) );
747 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_USER
) ) {
748 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
751 $comment = $wgLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
752 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
753 $comment = '<span class="history-deleted">' . $comment . '</span>';
755 return "<li>($loglink) $date $userLink $action $comment</li>";
759 * Generate a user tool link cluster if the current user is allowed to view it
760 * @param ArchivedFile $file
761 * @return string HTML
763 private function fileUserTools( $file ) {
764 if( $file->userCan( Revision
::DELETED_USER
) ) {
765 $link = $this->skin
->userLink( $file->user
, $file->user_text
) .
766 $this->skin
->userToolLinks( $file->user
, $file->user_text
);
768 $link = wfMsgHtml( 'rev-deleted-user' );
770 if( $file->isDeleted( Revision
::DELETED_USER
) ) {
771 return '<span class="history-deleted">' . $link . '</span>';
777 * Wrap and format the given file's comment block, if the current
778 * user is allowed to view it.
780 * @param ArchivedFile $file
781 * @return string HTML
783 private function fileComment( $file ) {
784 if( $file->userCan( File
::DELETED_COMMENT
) ) {
785 $block = $this->skin
->commentBlock( $file->description
);
787 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
789 if( $file->isDeleted( File
::DELETED_COMMENT
) ) {
790 return "<span class=\"history-deleted\">$block</span>";
796 * @param WebRequest $request
798 private function submit( $request ) {
799 global $wgUser, $wgOut;
800 # Check edit token on submission
801 if( $this->wasPosted
&& !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
802 $wgOut->addWikiMsg( 'sessionfailure' );
805 $bitfield = $this->extractBitfield( $request );
806 $comment = $request->getText( 'wpReason' );
807 # Can the user set this field?
808 if( $bitfield & Revision
::DELETED_RESTRICTED
&& !$wgUser->isAllowed('suppressrevision') ) {
809 $wgOut->permissionRequired( 'suppressrevision' );
812 # If the save went through, go to success message...
813 if( $this->save( $bitfield, $comment, $this->page
) ) {
816 # ...otherwise, bounce back to form...
823 private function success() {
825 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
826 $wrap = '<span class="success">$1</span>';
827 if( $this->deleteKey
== 'logid' ) {
828 $wgOut->wrapWikiMsg( $wrap, 'logdelete-success' );
829 $this->showLogItems();
830 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
831 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
833 } else if( $this->deleteKey
== 'fileid' ) {
834 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
836 } else if( $this->deleteKey
== 'oldimage' ) {
837 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
842 private function failure() {
844 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
845 $wrap = '<span class="error">$1</span>';
846 if( $this->deleteKey
== 'logid' ) {
847 $this->showLogItems();
848 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
849 $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
851 } else if( $this->deleteKey
== 'fileid' ) {
852 $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
854 } else if( $this->deleteKey
== 'oldimage' ) {
855 $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
861 * Put together a rev_deleted bitfield from the submitted checkboxes
862 * @param WebRequest $request
865 private function extractBitfield( $request ) {
867 foreach( $this->checks
as $item ) {
868 list( /* message */ , $name, $field ) = $item;
869 if( $request->getCheck( $name ) ) {
876 private function save( $bitfield, $reason, $title ) {
877 $dbw = wfGetDB( DB_MASTER
);
878 // Don't allow simply locking the interface for no reason
879 if( $bitfield == Revision
::DELETED_RESTRICTED
) {
882 $deleter = new RevisionDeleter( $dbw );
883 // By this point, only one of the below should be set
884 if( isset($this->revisions
) ) {
885 return $deleter->setRevVisibility( $title, $this->revisions
, $bitfield, $reason );
886 } else if( isset($this->archrevs
) ) {
887 return $deleter->setArchiveVisibility( $title, $this->archrevs
, $bitfield, $reason );
888 } else if( isset($this->ofiles
) ) {
889 return $deleter->setOldImgVisibility( $title, $this->ofiles
, $bitfield, $reason );
890 } else if( isset($this->afiles
) ) {
891 return $deleter->setArchFileVisibility( $title, $this->afiles
, $bitfield, $reason );
892 } else if( isset($this->events
) ) {
893 return $deleter->setEventVisibility( $title, $this->events
, $bitfield, $reason );
900 * Implements the actions for Revision Deletion.
901 * @ingroup SpecialPage
903 class RevisionDeleter
{
904 function __construct( $db ) {
909 * @param $title, the page these events apply to
910 * @param array $items list of revision ID numbers
911 * @param int $bitfield new rev_deleted value
912 * @param string $comment Comment for log records
914 function setRevVisibility( $title, $items, $bitfield, $comment ) {
917 $userAllowedAll = $success = true;
920 // Run through and pull all our data in one query
921 foreach( $items as $revid ) {
922 $where[] = intval($revid);
924 $result = $this->dbw
->select( array('revision','page'), '*',
925 array( 'rev_page' => $title->getArticleID(),
926 'rev_id' => $where, 'rev_page = page_id' ),
929 while( $row = $this->dbw
->fetchObject( $result ) ) {
930 $revObjs[$row->rev_id
] = new Revision( $row );
933 foreach( $items as $revid ) {
934 if( !isset($revObjs[$revid]) ) {
936 continue; // Must exist
937 } else if( $revObjs[$revid]->isCurrent() && ($bitfield & Revision
::DELETED_TEXT
) ) {
939 continue; // Cannot hide current version text
940 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
941 $userAllowedAll = false;
944 // For logging, maintain a count of revisions
945 if( $revObjs[$revid]->mDeleted
!= $bitfield ) {
947 $this->updateRevision( $revObjs[$revid], $bitfield );
948 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
953 // Don't log or touch if nothing changed
954 if( $revCount > 0 ) {
955 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted
,
956 $comment, $title, 'oldid', $revIDs );
957 $this->updatePage( $title );
959 // Where all revs allowed to be set?
960 if( !$userAllowedAll ) {
961 //FIXME: still might be confusing???
962 $wgOut->permissionRequired( 'suppressrevision' );
970 * @param $title, the page these events apply to
971 * @param array $items list of revision ID numbers
972 * @param int $bitfield new rev_deleted value
973 * @param string $comment Comment for log records
975 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
978 $userAllowedAll = $success = true;
981 // Run through and pull all our data in one query
982 foreach( $items as $timestamp ) {
983 $where[] = $this->dbw
->timestamp( $timestamp );
985 $result = $this->dbw
->select( 'archive', '*',
987 'ar_namespace' => $title->getNamespace(),
988 'ar_title' => $title->getDBKey(),
989 'ar_timestamp' => $where
992 while( $row = $this->dbw
->fetchObject( $result ) ) {
993 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
994 $revObjs[$timestamp] = new Revision( array(
995 'page' => $title->getArticleId(),
996 'id' => $row->ar_rev_id
,
997 'text' => $row->ar_text_id
,
998 'comment' => $row->ar_comment
,
999 'user' => $row->ar_user
,
1000 'user_text' => $row->ar_user_text
,
1001 'timestamp' => $timestamp,
1002 'minor_edit' => $row->ar_minor_edit
,
1003 'text_id' => $row->ar_text_id
,
1004 'deleted' => $row->ar_deleted
,
1005 'len' => $row->ar_len
) );
1008 foreach( $items as $timestamp ) {
1009 // This will only select the first revision with this timestamp.
1010 // Since they are all selected/deleted at once, we can just check the
1011 // permissions of one. UPDATE is done via timestamp, so all revs are set.
1012 if( !is_object($revObjs[$timestamp]) ) {
1014 continue; // Must exist
1015 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
1016 $userAllowedAll=false;
1019 // Which revisions did we change anything about?
1020 if( $revObjs[$timestamp]->mDeleted
!= $bitfield ) {
1021 $Id_set[] = $timestamp;
1022 $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
1026 // For logging, maintain a count of revisions
1028 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted
,
1029 $comment, $title, 'artimestamp', $Id_set );
1031 // Where all revs allowed to be set?
1032 if( !$userAllowedAll ) {
1033 $wgOut->permissionRequired( 'suppressrevision' );
1041 * @param $title, the page these events apply to
1042 * @param array $items list of revision ID numbers
1043 * @param int $bitfield new rev_deleted value
1044 * @param string $comment Comment for log records
1046 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
1049 $userAllowedAll = $success = true;
1052 // Run through and pull all our data in one query
1053 foreach( $items as $timestamp ) {
1054 $where[] = $timestamp.'!'.$title->getDBKey();
1056 $result = $this->dbw
->select( 'oldimage', '*',
1057 array( 'oi_name' => $title->getDBKey(), 'oi_archive_name' => $where ),
1060 while( $row = $this->dbw
->fetchObject( $result ) ) {
1061 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
1062 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
1063 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
1066 foreach( $items as $timestamp ) {
1067 $archivename = $timestamp.'!'.$title->getDBKey();
1068 if( !isset($filesObjs[$archivename]) ) {
1070 continue; // Must exist
1071 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
1072 $userAllowedAll=false;
1076 $transaction = true;
1077 // Which revisions did we change anything about?
1078 if( $filesObjs[$archivename]->deleted
!= $bitfield ) {
1081 $this->dbw
->begin();
1082 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
1083 // If this image is currently hidden...
1084 if( $filesObjs[$archivename]->deleted
& File
::DELETED_FILE
) {
1085 if( $bitfield & File
::DELETED_FILE
) {
1086 # Leave it alone if we are not changing this...
1088 $transaction = true;
1090 # We are moving this out
1091 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
1092 $set[]=$transaction;
1094 // Is it just now becoming hidden?
1095 } else if( $bitfield & File
::DELETED_FILE
) {
1096 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
1097 $set[]=$transaction;
1101 // If our file operations fail, then revert back the db
1102 if( $transaction==false ) {
1103 $this->dbw
->rollback();
1106 $this->dbw
->commit();
1110 // Log if something was changed
1112 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted
,
1113 $comment, $title, 'oldimage', $set );
1114 # Purge page/history
1115 $file = wfLocalFile( $title );
1116 $file->purgeCache();
1117 $file->purgeHistory();
1118 # Invalidate cache for all pages using this file
1119 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
1120 $update->doUpdate();
1122 // Where all revs allowed to be set?
1123 if( !$userAllowedAll ) {
1124 $wgOut->permissionRequired( 'suppressrevision' );
1132 * @param $title, the page these events apply to
1133 * @param array $items list of revision ID numbers
1134 * @param int $bitfield new rev_deleted value
1135 * @param string $comment Comment for log records
1137 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
1140 $userAllowedAll = $success = true;
1144 // Run through and pull all our data in one query
1145 foreach( $items as $id ) {
1146 $where[] = intval($id);
1148 $result = $this->dbw
->select( 'filearchive', '*',
1149 array( 'fa_name' => $title->getDBKey(),
1150 'fa_id' => $where ),
1152 while( $row = $this->dbw
->fetchObject( $result ) ) {
1153 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
1156 foreach( $items as $fileid ) {
1157 if( !isset($filesObjs[$fileid]) ) {
1159 continue; // Must exist
1160 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
1161 $userAllowedAll=false;
1164 // Which revisions did we change anything about?
1165 if( $filesObjs[$fileid]->deleted
!= $bitfield ) {
1169 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1172 // Log if something was changed
1174 $this->updateLog( $title, $count, $bitfield, $comment,
1175 $filesObjs[$fileid]->deleted
, $title, 'fileid', $Id_set );
1177 // Where all revs allowed to be set?
1178 if( !$userAllowedAll ) {
1179 $wgOut->permissionRequired( 'suppressrevision' );
1187 * @param $title, the log page these events apply to
1188 * @param array $items list of log ID numbers
1189 * @param int $bitfield new log_deleted value
1190 * @param string $comment Comment for log records
1192 function setEventVisibility( $title, $items, $bitfield, $comment ) {
1195 $userAllowedAll = $success = true;
1199 // Run through and pull all our data in one query
1200 foreach( $items as $logid ) {
1201 $where[] = intval($logid);
1203 list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
1204 $result = $this->dbw
->select( 'logging', '*',
1205 array( 'log_type' => $logtype, 'log_id' => $where ),
1208 while( $row = $this->dbw
->fetchObject( $result ) ) {
1209 $logRows[$row->log_id
] = $row;
1212 foreach( $items as $logid ) {
1213 if( !isset($logRows[$logid]) ) {
1215 continue; // Must exist
1216 } else if( !LogEventsList
::userCan($logRows[$logid], LogPage
::DELETED_RESTRICTED
)
1217 ||
$logRows[$logid]->log_type
== 'suppress' )
1219 $userAllowedAll=false; // Don't hide from oversight log!!!
1222 // Which logs did we change anything about?
1223 if( $logRows[$logid]->log_deleted
!= $bitfield ) {
1224 $log_Ids[] = $logid;
1225 $this->updateLogs( $logRows[$logid], $bitfield );
1226 $this->updateRecentChangesLog( $logRows[$logid], $bitfield );
1230 // Don't log or touch if nothing changed
1232 $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted
,
1233 $comment, $title, 'logid', $log_Ids );
1235 // Were all revs allowed to be set?
1236 if( !$userAllowedAll ) {
1237 $wgOut->permissionRequired( 'suppressrevision' );
1245 * Moves an image to a safe private location
1246 * Caller is responsible for clearing caches
1247 * @param File $oimage
1248 * @returns mixed, timestamp string on success, false on failure
1250 function makeOldImagePrivate( $oimage ) {
1251 $transaction = new FSTransaction();
1252 if( !FileStore
::lock() ) {
1253 wfDebug( __METHOD__
.": failed to acquire file store lock, aborting\n" );
1256 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1257 // Dupe the file into the file store
1258 if( file_exists( $oldpath ) ) {
1259 // Is our directory configured?
1260 if( $store = FileStore
::get( 'deleted' ) ) {
1261 if( !$oimage->sha1
) {
1262 $oimage->upgradeRow(); // sha1 may be missing
1264 $key = $oimage->sha1
. '.' . $oimage->getExtension();
1265 $transaction->add( $store->insert( $key, $oldpath, FileStore
::DELETE_ORIGINAL
) );
1269 $transaction = false; // Return an error and do nothing
1272 wfDebug( __METHOD__
." deleting already-missing '$oldpath'; moving on to database\n" );
1275 $transaction = new FSTransaction(); // empty
1278 if( $transaction === false ) {
1280 wfDebug( __METHOD__
.": import to file store failed, aborting\n" );
1281 throw new MWException( "Could not archive and delete file $oldpath" );
1285 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1286 $transaction->commit();
1287 FileStore
::unlock();
1289 $m = explode('!',$oimage->archive_name
,2);
1296 * Moves an image from a safe private location
1297 * Caller is responsible for clearing caches
1298 * @param File $oimage
1299 * @returns mixed, string timestamp on success, false on failure
1301 function makeOldImagePublic( $oimage ) {
1302 $transaction = new FSTransaction();
1303 if( !FileStore
::lock() ) {
1304 wfDebug( __METHOD__
." could not acquire filestore lock\n" );
1308 $store = FileStore
::get( 'deleted' );
1310 wfDebug( __METHOD__
.": skipping row with no file.\n" );
1314 $key = $oimage->sha1
.'.'.$oimage->getExtension();
1315 $destDir = $oimage->getArchivePath();
1316 if( !is_dir( $destDir ) ) {
1317 wfMkdirParents( $destDir );
1319 $destPath = $destDir . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1320 // Check if any other stored revisions use this file;
1321 // if so, we shouldn't remove the file from the hidden
1322 // archives so they will still work. Check hidden files first.
1323 $useCount = $this->dbw
->selectField( 'oldimage', '1',
1324 array( 'oi_sha1' => $oimage->sha1
,
1325 'oi_deleted & '.File
::DELETED_FILE
=> File
::DELETED_FILE
),
1326 __METHOD__
, array( 'FOR UPDATE' ) );
1327 // Check the rest of the deleted archives too.
1328 // (these are the ones that don't show in the image history)
1330 $useCount = $this->dbw
->selectField( 'filearchive', '1',
1331 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1332 __METHOD__
, array( 'FOR UPDATE' ) );
1335 if( $useCount == 0 ) {
1336 wfDebug( __METHOD__
.": nothing else using {$oimage->sha1}, will deleting after\n" );
1337 $flags = FileStore
::DELETE_ORIGINAL
;
1341 $transaction->add( $store->export( $key, $destPath, $flags ) );
1343 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1344 $transaction->commit();
1345 FileStore
::unlock();
1347 $m = explode('!',$oimage->archive_name
,2);
1354 * Update the revision's rev_deleted field
1355 * @param Revision $rev
1356 * @param int $bitfield new rev_deleted bitfield value
1358 function updateRevision( $rev, $bitfield ) {
1359 $this->dbw
->update( 'revision',
1360 array( 'rev_deleted' => $bitfield ),
1361 array( 'rev_id' => $rev->getId(), 'rev_page' => $rev->getPage() ),
1367 * Update the revision's rev_deleted field
1368 * @param Revision $rev
1369 * @param Title $title
1370 * @param int $bitfield new rev_deleted bitfield value
1372 function updateArchive( $rev, $title, $bitfield ) {
1373 $this->dbw
->update( 'archive',
1374 array( 'ar_deleted' => $bitfield ),
1375 array( 'ar_namespace' => $title->getNamespace(),
1376 'ar_title' => $title->getDBKey(),
1377 // use timestamp for index
1378 'ar_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ),
1379 'ar_rev_id' => $rev->getId()
1385 * Update the images's oi_deleted field
1387 * @param int $bitfield new rev_deleted bitfield value
1389 function updateOldFiles( $file, $bitfield ) {
1390 $this->dbw
->update( 'oldimage',
1391 array( 'oi_deleted' => $bitfield ),
1392 array( 'oi_name' => $file->getName(),
1393 'oi_timestamp' => $this->dbw
->timestamp( $file->getTimestamp() ) ),
1399 * Update the images's fa_deleted field
1400 * @param ArchivedFile $file
1401 * @param int $bitfield new rev_deleted bitfield value
1403 function updateArchFiles( $file, $bitfield ) {
1404 $this->dbw
->update( 'filearchive',
1405 array( 'fa_deleted' => $bitfield ),
1406 array( 'fa_id' => $file->getId() ),
1412 * Update the logging log_deleted field
1414 * @param int $bitfield new rev_deleted bitfield value
1416 function updateLogs( $row, $bitfield ) {
1417 $this->dbw
->update( 'logging',
1418 array( 'log_deleted' => $bitfield ),
1419 array( 'log_id' => $row->log_id
),
1425 * Update the revision's recentchanges record if fields have been hidden
1426 * @param Revision $rev
1427 * @param int $bitfield new rev_deleted bitfield value
1429 function updateRecentChangesEdits( $rev, $bitfield ) {
1430 $this->dbw
->update( 'recentchanges',
1431 array( 'rc_deleted' => $bitfield,
1432 'rc_patrolled' => 1 ),
1433 array( 'rc_this_oldid' => $rev->getId(),
1434 'rc_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ) ),
1440 * Update the revision's recentchanges record if fields have been hidden
1442 * @param int $bitfield new rev_deleted bitfield value
1444 function updateRecentChangesLog( $row, $bitfield ) {
1445 $this->dbw
->update( 'recentchanges',
1446 array( 'rc_deleted' => $bitfield,
1447 'rc_patrolled' => 1 ),
1448 array( 'rc_logid' => $row->log_id
,
1449 'rc_timestamp' => $row->log_timestamp
),
1455 * Touch the page's cache invalidation timestamp; this forces cached
1456 * history views to refresh, so any newly hidden or shown fields will
1458 * @param Title $title
1460 function updatePage( $title ) {
1461 $title->invalidateCache();
1462 $title->purgeSquid();
1463 $title->touchLinks();
1464 // Extensions that require referencing previous revisions may need this
1465 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1469 * Checks for a change in the bitfield for a certain option and updates the
1470 * provided array accordingly.
1472 * @param String $desc Description to add to the array if the option was
1473 * enabled / disabled.
1474 * @param int $field The bitmask describing the single option.
1475 * @param int $diff The xor of the old and new bitfields.
1476 * @param array $arr The array to update.
1478 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
1479 if( $diff & $field ) {
1480 $arr[ ( $new & $field ) ?
0 : 1 ][] = $desc;
1485 * Gets an array describing the changes made to the visibilit of the revision.
1486 * If the resulting array is $arr, then $arr[0] will contain an array of strings
1487 * describing the items that were hidden, $arr[2] will contain an array of strings
1488 * describing the items that were unhidden, and $arr[3] will contain an array with
1489 * a single string, which can be one of "applied restrictions to sysops",
1490 * "removed restrictions from sysops", or null.
1492 * @param int $n The new bitfield.
1493 * @param int $o The old bitfield.
1494 * @return An array as described above.
1496 protected static function getChanges( $n, $o ) {
1498 $ret = array( 0 => array(), 1 => array(), 2 => array() );
1499 // Build bitfield changes in language
1500 self
::checkItem( wfMsgForContent( 'revdelete-content' ),
1501 Revision
::DELETED_TEXT
, $diff, $n, $ret );
1502 self
::checkItem( wfMsgForContent( 'revdelete-summary' ),
1503 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
1504 self
::checkItem( wfMsgForContent( 'revdelete-uname' ),
1505 Revision
::DELETED_USER
, $diff, $n, $ret );
1506 // Restriction application to sysops
1507 if( $diff & Revision
::DELETED_RESTRICTED
) {
1508 if( $n & Revision
::DELETED_RESTRICTED
)
1509 $ret[2][] = wfMsgForContent( 'revdelete-restricted' );
1511 $ret[2][] = wfMsgForContent( 'revdelete-unrestricted' );
1517 * Gets a log message to describe the given revision visibility change. This
1518 * message will be of the form "[hid {content, edit summary, username}];
1519 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
1521 * @param int $count The number of effected revisions.
1522 * @param int $nbitfield The new bitfield for the revision.
1523 * @param int $obitfield The old bitfield for the revision.
1524 * @param bool $isForLog
1526 public static function getLogMessage( $count, $nbitfield, $obitfield, $isForLog = false ) {
1529 $changes = self
::getChanges( $nbitfield, $obitfield );
1530 if( count( $changes[0] ) ) {
1531 $s .= wfMsgForContent ( 'revdelete-hid', implode ( ', ', $changes[0] ) );
1533 if( count( $changes[1] ) ) {
1535 $s .= wfMsgForContent ( 'revdelete-unhid', implode ( ', ', $changes[1] ) );
1537 if( count( $changes[2] ) ) {
1538 $s .= $s ?
' (' . $changes[2][0] . ')' : $changes[2][0];
1540 $msg = $isForLog ?
'logdelete-log-message' : 'revdelete-log-message';
1541 return wfMsgExt( $msg, array( 'parsemag', 'content' ), $s, $wgLang->formatNum($count) );
1546 * Record a log entry on the action
1547 * @param Title $title, page where item was removed from
1548 * @param int $count the number of revisions altered for this page
1549 * @param int $nbitfield the new _deleted value
1550 * @param int $obitfield the old _deleted value
1551 * @param string $comment
1552 * @param Title $target, the relevant page
1553 * @param string $param, URL param
1554 * @param Array $items
1556 function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target,
1557 $param, $items = array() )
1559 // Put things hidden from sysops in the oversight log
1560 $logtype = ( ($nbitfield |
$obitfield) & Revision
::DELETED_RESTRICTED
) ?
1561 'suppress' : 'delete';
1562 $log = new LogPage( $logtype );
1563 $itemCSV = implode(',',$items);
1565 if( $param == 'logid' ) {
1566 $params = array( $itemCSV, "ofield={$obitfield}", "nfield={$nbitfield}" );
1567 $log->addEntry( 'event', $title, $comment, $params );
1569 // Add params for effected page and ids
1570 $params = array( $param, $itemCSV, "ofield={$obitfield}", "nfield={$nbitfield}" );
1571 $log->addEntry( 'revision', $title, $comment, $params );