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 $qc = $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(), '', 25, $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(), '', 25, $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() {
124 $logAction = 'revision';
125 switch( $this->deleteKey
) {
127 $ids = $this->oldids
;
130 $ids = $this->artimestamps
;
133 $ids = $this->oldimgs
;
136 $ids = $this->fileids
;
139 $ids = $this->logids
;
140 $logAction = 'event';
142 default: // bad type?
145 // Revision delete logs for these item
146 $conds['log_type'] = array('delete','suppress');
147 $conds['log_action'] = $logAction;
148 $conds['ls_field'] = RevisionDeleter
::getRelationType( $this->deleteKey
);
149 $conds['ls_value'] = $ids;
153 private function secureOperation() {
155 $this->deleteKey
= '';
156 // At this point, we should only have one of these
157 if( $this->oldids
) {
158 $this->revisions
= $this->oldids
;
159 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
160 $this->deleteKey
= 'oldid';
161 } else if( $this->artimestamps
) {
162 $this->archrevs
= $this->artimestamps
;
163 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
164 $this->deleteKey
= 'artimestamp';
165 } else if( $this->oldimgs
) {
166 $this->ofiles
= $this->oldimgs
;
167 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
168 $this->deleteKey
= 'oldimage';
169 } else if( $this->fileids
) {
170 $this->afiles
= $this->fileids
;
171 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
172 $this->deleteKey
= 'fileid';
173 } else if( $this->logids
) {
174 $this->events
= $this->logids
;
175 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage
::DELETED_ACTION
);
176 $this->deleteKey
= 'logid';
178 // Our checkbox messages depends one what we are doing,
179 // e.g. we don't hide "text" for logs or images
180 $this->checks
= array(
182 array( 'revdelete-hide-comment', 'wpHideComment', Revision
::DELETED_COMMENT
),
183 array( 'revdelete-hide-user', 'wpHideUser', Revision
::DELETED_USER
)
185 if( $wgUser->isAllowed('suppressrevision') ) {
186 $this->checks
[] = array( 'revdelete-hide-restricted',
187 'wpHideRestricted', Revision
::DELETED_RESTRICTED
);
192 * Show a deleted file version requested by the visitor.
194 private function tryShowFile( $key ) {
195 global $wgOut, $wgRequest;
196 $oimage = RepoGroup
::singleton()->getLocalRepo()->newFromArchiveName( $this->page
, $key );
198 // Check if user is allowed to see this file
199 if( !$oimage->userCan(File
::DELETED_FILE
) ) {
200 $wgOut->permissionRequired( 'suppressrevision' );
203 # We mustn't allow the output to be Squid cached, otherwise
204 # if an admin previews a deleted image, and it's cached, then
205 # a user without appropriate permissions can toddle off and
206 # nab the image, and Squid will serve it
207 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
208 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
209 $wgRequest->response()->header( 'Pragma: no-cache' );
210 # Stream the file to the client
211 $store = FileStore
::get( 'deleted' );
212 $store->stream( $key );
217 * This lets a user set restrictions for live and archived revisions
219 private function showRevs() {
220 global $wgOut, $wgUser;
223 $count = ($this->deleteKey
== 'oldid') ?
224 count($this->revisions
) : count($this->archrevs
);
225 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(), $count );
228 $wgOut->addHTML( "<ul>" );
230 $where = $revObjs = array();
231 $dbr = wfGetDB( DB_MASTER
);
235 if( $this->deleteKey
== 'oldid' ) {
236 // Run through and pull all our data in one query
237 foreach( $this->revisions
as $revid ) {
238 $where[] = intval($revid);
240 $result = $dbr->select( array('revision','page'), '*',
242 'rev_page' => $this->page
->getArticleID(),
248 while( $row = $dbr->fetchObject( $result ) ) {
249 $revObjs[$row->rev_id
] = new Revision( $row );
251 foreach( $this->revisions
as $revid ) {
252 if( !isset($revObjs[$revid]) ) continue; // Must exist
253 // Check if the revision was Oversighted
254 if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
255 if( !$this->wasPosted
) {
256 return $wgOut->permissionRequired( 'suppressrevision' );
258 $UserAllowed = false;
261 $wgOut->addHTML( $this->historyLine( $revObjs[$revid] ) );
262 $bitfields |
= $revObjs[$revid]->mDeleted
;
266 // Run through and pull all our data in one query
267 foreach( $this->archrevs
as $timestamp ) {
268 $where[] = $dbr->timestamp( $timestamp );
270 $result = $dbr->select( 'archive', '*',
272 'ar_namespace' => $this->page
->getNamespace(),
273 'ar_title' => $this->page
->getDBKey(),
274 'ar_timestamp' => $where
278 while( $row = $dbr->fetchObject( $result ) ) {
279 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
280 $revObjs[$timestamp] = new Revision( array(
281 'page' => $this->page
->getArticleId(),
282 'id' => $row->ar_rev_id
,
283 'text' => $row->ar_text_id
,
284 'comment' => $row->ar_comment
,
285 'user' => $row->ar_user
,
286 'user_text' => $row->ar_user_text
,
287 'timestamp' => $timestamp,
288 'minor_edit' => $row->ar_minor_edit
,
289 'text_id' => $row->ar_text_id
,
290 'deleted' => $row->ar_deleted
,
291 'len' => $row->ar_len
) );
293 foreach( $this->archrevs
as $timestamp ) {
294 if( !isset($revObjs[$timestamp]) ) {
296 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
297 // If a rev is hidden from sysops
298 if( !$this->wasPosted
) {
299 return $wgOut->permissionRequired( 'suppressrevision' );
301 $UserAllowed = false;
304 $wgOut->addHTML( $this->historyLine( $revObjs[$timestamp] ) );
305 $bitfields |
= $revObjs[$timestamp]->mDeleted
;
309 return $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
312 $wgOut->addHTML( "</ul>" );
314 $this->addUsageText();
316 // Normal sysops can always see what they did, but can't always change it
317 if( !$UserAllowed ) return;
320 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
321 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
324 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
325 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
326 Xml
::hidden( 'type', $this->deleteKey
)
328 if( $this->deleteKey
== 'oldid' ) {
329 $hidden[] = Xml
::hidden( 'oldid', implode(',',$this->oldids
) );
331 $hidden[] = Xml
::hidden( 'artimestamp', implode(',',$this->artimestamps
) );
334 Xml
::openElement( 'form', array( 'method' => 'post',
335 'action' => $this->getTitle()->getLocalUrl( 'action=submit' ),
336 'id' => 'mw-revdel-form-revisions' ) ) .
337 Xml
::openElement( 'fieldset' ) .
338 xml
::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
341 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
342 foreach( $items as $item ) {
343 $wgOut->addHTML( Xml
::tags( 'p', null, $item ) );
345 foreach( $hidden as $item ) {
346 $wgOut->addHTML( $item );
349 Xml
::closeElement( 'fieldset' ) .
350 Xml
::closeElement( 'form' ) . "\n"
355 * This lets a user set restrictions for archived images
357 private function showImages() {
358 global $wgOut, $wgUser, $wgLang;
361 $count = ($this->deleteKey
== 'oldimage') ?
count($this->ofiles
) : count($this->afiles
);
362 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(),
363 $wgLang->formatNum($count) );
366 $wgOut->addHTML( "<ul>" );
368 $where = $filesObjs = array();
369 $dbr = wfGetDB( DB_MASTER
);
370 // Live old revisions...
372 if( $this->deleteKey
== 'oldimage' ) {
373 // Run through and pull all our data in one query
374 foreach( $this->ofiles
as $timestamp ) {
375 $where[] = $timestamp.'!'.$this->page
->getDBKey();
377 $result = $dbr->select( 'oldimage', '*',
379 'oi_name' => $this->page
->getDBKey(),
380 'oi_archive_name' => $where
384 while( $row = $dbr->fetchObject( $result ) ) {
385 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
386 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
387 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
389 // Check through our images
390 foreach( $this->ofiles
as $timestamp ) {
391 $archivename = $timestamp.'!'.$this->page
->getDBKey();
392 if( !isset($filesObjs[$archivename]) ) {
394 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
395 // If a rev is hidden from sysops
396 if( !$this->wasPosted
) {
397 return $wgOut->permissionRequired( 'suppressrevision' );
399 $UserAllowed = false;
402 // Inject history info
403 $wgOut->addHTML( $this->fileLine( $filesObjs[$archivename] ) );
404 $bitfields |
= $filesObjs[$archivename]->deleted
;
408 // Run through and pull all our data in one query
409 foreach( $this->afiles
as $id ) {
410 $where[] = intval($id);
412 $result = $dbr->select( 'filearchive', '*',
414 'fa_name' => $this->page
->getDBKey(),
419 while( $row = $dbr->fetchObject( $result ) ) {
420 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
423 foreach( $this->afiles
as $fileid ) {
424 if( !isset($filesObjs[$fileid]) ) {
426 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
427 // If a rev is hidden from sysops
428 if( !$this->wasPosted
) {
429 return $wgOut->permissionRequired( 'suppressrevision' );
431 $UserAllowed = false;
434 // Inject history info
435 $wgOut->addHTML( $this->archivedfileLine( $filesObjs[$fileid] ) );
436 $bitfields |
= $filesObjs[$fileid]->deleted
;
440 return $wgOut->showErrorPage( 'revdelete-nooldid-title','revdelete-nooldid-text' );
443 $wgOut->addHTML( "</ul>" );
445 $this->addUsageText();
446 // Normal sysops can always see what they did, but can't always change it
447 if( !$UserAllowed ) return;
450 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
451 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
454 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
455 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
456 Xml
::hidden( 'type', $this->deleteKey
)
458 if( $this->deleteKey
== 'oldimage' ) {
459 $hidden[] = Xml
::hidden( 'oldimage', implode(',',$this->oldimgs
) );
461 $hidden[] = Xml
::hidden( 'fileid', implode(',',$this->fileids
) );
464 Xml
::openElement( 'form', array( 'method' => 'post',
465 'action' => $this->getTitle()->getLocalUrl( 'action=submit' ),
466 'id' => 'mw-revdel-form-filerevisions' )
468 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
471 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
472 foreach( $items as $item ) {
473 $wgOut->addHTML( "<p>$item</p>" );
475 foreach( $hidden as $item ) {
476 $wgOut->addHTML( $item );
480 Xml
::closeElement( 'fieldset' ) .
481 Xml
::closeElement( 'form' ) . "\n"
486 * This lets a user set restrictions for log items
488 private function showLogItems() {
489 global $wgOut, $wgUser, $wgMessageCache, $wgLang;
492 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->events
) ) );
495 $wgOut->addHTML( "<ul>" );
497 $where = $logRows = array();
498 $dbr = wfGetDB( DB_MASTER
);
499 // Run through and pull all our data in one query
501 foreach( $this->events
as $logid ) {
502 $where[] = intval($logid);
504 list($log,$logtype) = explode( '/',$this->page
->getDBKey(), 2 );
505 $result = $dbr->select( 'logging', '*',
506 array( 'log_type' => $logtype, 'log_id' => $where ),
509 while( $row = $dbr->fetchObject( $result ) ) {
510 $logRows[$row->log_id
] = $row;
512 $wgMessageCache->loadAllMessages();
513 foreach( $this->events
as $logid ) {
514 // Don't hide from oversight log!!!
515 if( !isset( $logRows[$logid] ) ||
$logRows[$logid]->log_type
=='suppress' ) {
517 } else if( !LogEventsList
::userCan( $logRows[$logid],Revision
::DELETED_RESTRICTED
) ) {
518 // If an event is hidden from sysops
519 if( !$this->wasPosted
) {
520 return $wgOut->permissionRequired( 'suppressrevision' );
522 $UserAllowed = false;
525 $wgOut->addHTML( $this->logLine( $logRows[$logid] ) );
526 $bitfields |
= $logRows[$logid]->log_deleted
;
529 return $wgOut->showErrorPage( 'revdelete-nologid-title', 'revdelete-nologid-text' );
532 $wgOut->addHTML( "</ul>" );
534 $this->addUsageText();
535 // Normal sysops can always see what they did, but can't always change it
536 if( !$UserAllowed ) return;
539 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
540 Xml
::submitButton( wfMsg( 'revdelete-submit' ) ) );
542 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
543 Xml
::hidden( 'target', $this->page
->getPrefixedDBKey() ),
544 Xml
::hidden( 'page', $this->contextPage ?
$this->contextPage
->getPrefixedDBKey() : '' ),
545 Xml
::hidden( 'type', $this->deleteKey
),
546 Xml
::hidden( 'logid', implode(',',$this->logids
) )
550 Xml
::openElement( 'form', array( 'method' => 'post',
551 'action' => $this->getTitle()->getLocalUrl( 'action=submit' ), 'id' => 'mw-revdel-form-logs' ) ) .
552 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
555 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
556 foreach( $items as $item ) {
557 $wgOut->addHTML( "<p>$item</p>" );
559 foreach( $hidden as $item ) {
560 $wgOut->addHTML( $item );
564 Xml
::closeElement( 'fieldset' ) .
565 Xml
::closeElement( 'form' ) . "\n"
569 private function addUsageText() {
570 global $wgOut, $wgUser;
571 $wgOut->addWikiMsg( 'revdelete-text' );
572 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
573 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
578 * @param int $bitfields, aggregate bitfield of all the bitfields
579 * @returns string HTML
581 private function buildCheckBoxes( $bitfields ) {
583 // FIXME: all items checked for just one rev are checked, even if not set for the others
584 foreach( $this->checks
as $item ) {
585 list( $message, $name, $field ) = $item;
586 $line = Xml
::tags( 'div', null, Xml
::checkLabel( wfMsg($message), $name, $name,
587 $bitfields & $field ) );
588 if( $field == Revision
::DELETED_RESTRICTED
) $line = "<b>$line</b>";
595 * @param Revision $rev
598 private function historyLine( $rev ) {
599 global $wgLang, $wgUser;
601 $date = $wgLang->timeanddate( $rev->getTimestamp() );
602 $difflink = $del = '';
604 if( $this->deleteKey
== 'oldid' ) {
605 $tokenParams = '&unhide=1&token='.urlencode( $wgUser->editToken( $rev->getId() ) );
606 $revlink = $this->skin
->makeLinkObj( $this->page
, $date, 'oldid='.$rev->getId() . $tokenParams );
607 $difflink = '(' . $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml('diff'),
608 'diff=' . $rev->getId() . '&oldid=prev' . $tokenParams ) . ')';
609 // Archived revisions
611 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
612 $target = $this->page
->getPrefixedText();
613 $revlink = $this->skin
->makeLinkObj( $undelete, $date,
614 "target=$target×tamp=" . $rev->getTimestamp() );
615 $difflink = '(' . $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml('diff'),
616 "target=$target&diff=prev×tamp=" . $rev->getTimestamp() ) . ')';
618 // Check permissions; items may be "suppressed"
619 if( $rev->isDeleted(Revision
::DELETED_TEXT
) ) {
620 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
621 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
622 if( !$rev->userCan(Revision
::DELETED_TEXT
) ) {
623 $revlink = '<span class="history-deleted">'.$date.'</span>';
624 $difflink = '(' . wfMsgHtml('diff') . ')';
627 $userlink = $this->skin
->revUserLink( $rev );
628 $comment = $this->skin
->revComment( $rev );
630 return "<li>$difflink $revlink $userlink $comment{$del}</li>";
637 private function fileLine( $file ) {
640 $target = $this->page
->getPrefixedText();
641 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
645 if( $file->isDeleted(File
::DELETED_FILE
) ) {
646 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
647 if( !$file->userCan(File
::DELETED_FILE
) ) {
650 $pageLink = $this->skin
->makeKnownLinkObj( $this->getTitle(), $date,
651 "target=$target&file=$file->sha1.".$file->getExtension() );
653 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
656 $url = $file->getUrlRel();
657 $pageLink = "<a href=\"{$url}\">{$date}</a>";
660 $data = wfMsg( 'widthheight', $wgLang->formatNum( $file->getWidth() ),
661 $wgLang->formatNum( $file->getHeight() ) ) .
662 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
663 $data = htmlspecialchars( $data );
665 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".
666 $this->fileComment( $file )."$del</li>";
670 * @param ArchivedFile $file
673 private function archivedfileLine( $file ) {
676 $target = $this->page
->getPrefixedText();
677 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
679 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
680 $pageLink = $this->skin
->makeKnownLinkObj( $undelete, $date,
681 "target=$target&file={$file->getKey()}" );
684 if( $file->isDeleted(File
::DELETED_FILE
) ) {
685 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
688 $data = wfMsg( 'widthheight', $wgLang->formatNum( $file->getWidth() ),
689 $wgLang->formatNum( $file->getHeight() ) ) .
690 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
691 $data = htmlspecialchars( $data );
693 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".
694 $this->fileComment( $file )."$del</li>";
698 * @param Array $row row
701 private function logLine( $row ) {
704 $date = $wgLang->timeanddate( $row->log_timestamp
);
705 $paramArray = LogPage
::extractParams( $row->log_params
);
706 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
708 $logtitle = SpecialPage
::getTitleFor( 'Log' );
709 $loglink = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
710 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
712 if( !LogEventsList
::userCan($row,LogPage
::DELETED_ACTION
) ) {
713 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
715 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
716 $this->skin
, $paramArray, true, true );
717 if( $row->log_deleted
& LogPage
::DELETED_ACTION
)
718 $action = '<span class="history-deleted">' . $action . '</span>';
721 $userLink = $this->skin
->userLink( $row->log_user
, User
::WhoIs($row->log_user
) );
722 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_USER
) ) {
723 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
726 $comment = $wgLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
727 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
728 $comment = '<span class="history-deleted">' . $comment . '</span>';
730 return "<li>($loglink) $date $userLink $action $comment</li>";
734 * Generate a user tool link cluster if the current user is allowed to view it
735 * @param ArchivedFile $file
736 * @return string HTML
738 private function fileUserTools( $file ) {
739 if( $file->userCan( Revision
::DELETED_USER
) ) {
740 $link = $this->skin
->userLink( $file->user
, $file->user_text
) .
741 $this->skin
->userToolLinks( $file->user
, $file->user_text
);
743 $link = wfMsgHtml( 'rev-deleted-user' );
745 if( $file->isDeleted( Revision
::DELETED_USER
) ) {
746 return '<span class="history-deleted">' . $link . '</span>';
752 * Wrap and format the given file's comment block, if the current
753 * user is allowed to view it.
755 * @param ArchivedFile $file
756 * @return string HTML
758 private function fileComment( $file ) {
759 if( $file->userCan( File
::DELETED_COMMENT
) ) {
760 $block = $this->skin
->commentBlock( $file->description
);
762 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
764 if( $file->isDeleted( File
::DELETED_COMMENT
) ) {
765 return "<span class=\"history-deleted\">$block</span>";
771 * @param WebRequest $request
773 private function submit( $request ) {
774 global $wgUser, $wgOut;
775 # Check edit token on submission
776 if( $this->wasPosted
&& !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
777 $wgOut->addWikiMsg( 'sessionfailure' );
780 $bitfield = $this->extractBitfield( $request );
781 $comment = $request->getText( 'wpReason' );
782 # Can the user set this field?
783 if( $bitfield & Revision
::DELETED_RESTRICTED
&& !$wgUser->isAllowed('suppressrevision') ) {
784 $wgOut->permissionRequired( 'suppressrevision' );
787 # If the save went through, go to success message...
788 if( $this->save( $bitfield, $comment, $this->page
) ) {
791 # ...otherwise, bounce back to form...
798 private function success() {
800 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
801 $wrap = '<span class="success">$1</span>';
802 if( $this->deleteKey
== 'logid' ) {
803 $wgOut->wrapWikiMsg( $wrap, 'logdelete-success' );
804 $this->showLogItems();
805 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
806 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
808 } else if( $this->deleteKey
== 'fileid' ) {
809 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
811 } else if( $this->deleteKey
== 'oldimage' ) {
812 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
817 private function failure() {
819 $wgOut->setPagetitle( wfMsg( 'actionfailed' ) );
820 $wrap = '<span class="error">$1</span>';
821 if( $this->deleteKey
== 'logid' ) {
822 $this->showLogItems();
823 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
824 $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
826 } else if( $this->deleteKey
== 'fileid' ) {
827 $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
829 } else if( $this->deleteKey
== 'oldimage' ) {
830 $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
836 * Put together a rev_deleted bitfield from the submitted checkboxes
837 * @param WebRequest $request
840 private function extractBitfield( $request ) {
842 foreach( $this->checks
as $item ) {
843 list( /* message */ , $name, $field ) = $item;
844 if( $request->getCheck( $name ) ) {
851 private function save( $bitfield, $reason, $title ) {
852 $dbw = wfGetDB( DB_MASTER
);
853 // Don't allow simply locking the interface for no reason
854 if( $bitfield == Revision
::DELETED_RESTRICTED
) {
857 $deleter = new RevisionDeleter( $dbw );
858 // By this point, only one of the below should be set
859 if( isset($this->revisions
) ) {
860 return $deleter->setRevVisibility( $title, $this->revisions
, $bitfield, $reason );
861 } else if( isset($this->archrevs
) ) {
862 return $deleter->setArchiveVisibility( $title, $this->archrevs
, $bitfield, $reason );
863 } else if( isset($this->ofiles
) ) {
864 return $deleter->setOldImgVisibility( $title, $this->ofiles
, $bitfield, $reason );
865 } else if( isset($this->afiles
) ) {
866 return $deleter->setArchFileVisibility( $title, $this->afiles
, $bitfield, $reason );
867 } else if( isset($this->events
) ) {
868 return $deleter->setEventVisibility( $title, $this->events
, $bitfield, $reason );
875 * Implements the actions for Revision Deletion.
876 * @ingroup SpecialPage
878 class RevisionDeleter
{
879 function __construct( $db ) {
884 * @param $title, the page these events apply to
885 * @param array $items list of revision ID numbers
886 * @param int $bitfield new rev_deleted value
887 * @param string $comment Comment for log records
889 function setRevVisibility( $title, $items, $bitfield, $comment ) {
892 $userAllowedAll = $success = true;
895 // Run through and pull all our data in one query
896 foreach( $items as $revid ) {
897 $where[] = intval($revid);
899 $result = $this->dbw
->select( array('revision','page'), '*',
900 array( 'rev_page' => $title->getArticleID(),
901 'rev_id' => $where, 'rev_page = page_id' ),
904 while( $row = $this->dbw
->fetchObject( $result ) ) {
905 $revObjs[$row->rev_id
] = new Revision( $row );
908 foreach( $items as $revid ) {
909 if( !isset($revObjs[$revid]) ) {
911 continue; // Must exist
912 } else if( $revObjs[$revid]->isCurrent() && ($bitfield & Revision
::DELETED_TEXT
) ) {
914 continue; // Cannot hide current version text
915 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
916 $userAllowedAll = false;
919 // For logging, maintain a count of revisions
920 if( $revObjs[$revid]->mDeleted
!= $bitfield ) {
922 $this->updateRevision( $revObjs[$revid], $bitfield );
923 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
928 // Don't log or touch if nothing changed
929 if( $revCount > 0 ) {
930 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted
,
931 $comment, $title, 'oldid', $revIDs );
932 $this->updatePage( $title );
934 // Where all revs allowed to be set?
935 if( !$userAllowedAll ) {
936 //FIXME: still might be confusing???
937 $wgOut->permissionRequired( 'suppressrevision' );
945 * @param $title, the page these events apply to
946 * @param array $items list of revision ID numbers
947 * @param int $bitfield new rev_deleted value
948 * @param string $comment Comment for log records
950 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
953 $userAllowedAll = $success = true;
956 // Run through and pull all our data in one query
957 foreach( $items as $timestamp ) {
958 $where[] = $this->dbw
->timestamp( $timestamp );
960 $result = $this->dbw
->select( 'archive', '*',
962 'ar_namespace' => $title->getNamespace(),
963 'ar_title' => $title->getDBKey(),
964 'ar_timestamp' => $where
967 while( $row = $this->dbw
->fetchObject( $result ) ) {
968 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
969 $revObjs[$timestamp] = new Revision( array(
970 'page' => $title->getArticleId(),
971 'id' => $row->ar_rev_id
,
972 'text' => $row->ar_text_id
,
973 'comment' => $row->ar_comment
,
974 'user' => $row->ar_user
,
975 'user_text' => $row->ar_user_text
,
976 'timestamp' => $timestamp,
977 'minor_edit' => $row->ar_minor_edit
,
978 'text_id' => $row->ar_text_id
,
979 'deleted' => $row->ar_deleted
,
980 'len' => $row->ar_len
) );
983 foreach( $items as $timestamp ) {
984 // This will only select the first revision with this timestamp.
985 // Since they are all selected/deleted at once, we can just check the
986 // permissions of one. UPDATE is done via timestamp, so all revs are set.
987 if( !is_object($revObjs[$timestamp]) ) {
989 continue; // Must exist
990 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
991 $userAllowedAll=false;
994 // Which revisions did we change anything about?
995 if( $revObjs[$timestamp]->mDeleted
!= $bitfield ) {
996 $Id_set[] = $timestamp;
997 $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
1001 // For logging, maintain a count of revisions
1003 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted
,
1004 $comment, $title, 'artimestamp', $Id_set );
1006 // Where all revs allowed to be set?
1007 if( !$userAllowedAll ) {
1008 $wgOut->permissionRequired( 'suppressrevision' );
1016 * @param $title, the page these events apply to
1017 * @param array $items list of revision ID numbers
1018 * @param int $bitfield new rev_deleted value
1019 * @param string $comment Comment for log records
1021 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
1024 $userAllowedAll = $success = true;
1027 // Run through and pull all our data in one query
1028 foreach( $items as $timestamp ) {
1029 $where[] = $timestamp.'!'.$title->getDBKey();
1031 $result = $this->dbw
->select( 'oldimage', '*',
1032 array( 'oi_name' => $title->getDBKey(), 'oi_archive_name' => $where ),
1035 while( $row = $this->dbw
->fetchObject( $result ) ) {
1036 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
1037 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
1038 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
1041 foreach( $items as $timestamp ) {
1042 $archivename = $timestamp.'!'.$title->getDBKey();
1043 if( !isset($filesObjs[$archivename]) ) {
1045 continue; // Must exist
1046 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
1047 $userAllowedAll=false;
1051 $transaction = true;
1052 // Which revisions did we change anything about?
1053 if( $filesObjs[$archivename]->deleted
!= $bitfield ) {
1056 $this->dbw
->begin();
1057 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
1058 // If this image is currently hidden...
1059 if( $filesObjs[$archivename]->deleted
& File
::DELETED_FILE
) {
1060 if( $bitfield & File
::DELETED_FILE
) {
1061 # Leave it alone if we are not changing this...
1063 $transaction = true;
1065 # We are moving this out
1066 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
1067 $set[]=$transaction;
1069 // Is it just now becoming hidden?
1070 } else if( $bitfield & File
::DELETED_FILE
) {
1071 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
1072 $set[]=$transaction;
1076 // If our file operations fail, then revert back the db
1077 if( $transaction==false ) {
1078 $this->dbw
->rollback();
1081 $this->dbw
->commit();
1085 // Log if something was changed
1087 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted
,
1088 $comment, $title, 'oldimage', $set );
1089 # Purge page/history
1090 $file = wfLocalFile( $title );
1091 $file->purgeCache();
1092 $file->purgeHistory();
1093 # Invalidate cache for all pages using this file
1094 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
1095 $update->doUpdate();
1097 // Where all revs allowed to be set?
1098 if( !$userAllowedAll ) {
1099 $wgOut->permissionRequired( 'suppressrevision' );
1107 * @param $title, the page these events apply to
1108 * @param array $items list of revision ID numbers
1109 * @param int $bitfield new rev_deleted value
1110 * @param string $comment Comment for log records
1112 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
1115 $userAllowedAll = $success = true;
1119 // Run through and pull all our data in one query
1120 foreach( $items as $id ) {
1121 $where[] = intval($id);
1123 $result = $this->dbw
->select( 'filearchive', '*',
1124 array( 'fa_name' => $title->getDBKey(),
1125 'fa_id' => $where ),
1127 while( $row = $this->dbw
->fetchObject( $result ) ) {
1128 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
1131 foreach( $items as $fileid ) {
1132 if( !isset($filesObjs[$fileid]) ) {
1134 continue; // Must exist
1135 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
1136 $userAllowedAll=false;
1139 // Which revisions did we change anything about?
1140 if( $filesObjs[$fileid]->deleted
!= $bitfield ) {
1144 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1147 // Log if something was changed
1149 $this->updateLog( $title, $count, $bitfield, $comment,
1150 $filesObjs[$fileid]->deleted
, $title, 'fileid', $Id_set );
1152 // Where all revs allowed to be set?
1153 if( !$userAllowedAll ) {
1154 $wgOut->permissionRequired( 'suppressrevision' );
1162 * @param $title, the log page these events apply to
1163 * @param array $items list of log ID numbers
1164 * @param int $bitfield new log_deleted value
1165 * @param string $comment Comment for log records
1167 function setEventVisibility( $title, $items, $bitfield, $comment ) {
1170 $userAllowedAll = $success = true;
1174 // Run through and pull all our data in one query
1175 foreach( $items as $logid ) {
1176 $where[] = intval($logid);
1178 list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
1179 $result = $this->dbw
->select( 'logging', '*',
1180 array( 'log_type' => $logtype, 'log_id' => $where ),
1183 while( $row = $this->dbw
->fetchObject( $result ) ) {
1184 $logRows[$row->log_id
] = $row;
1187 foreach( $items as $logid ) {
1188 if( !isset($logRows[$logid]) ) {
1190 continue; // Must exist
1191 } else if( !LogEventsList
::userCan($logRows[$logid], LogPage
::DELETED_RESTRICTED
)
1192 ||
$logRows[$logid]->log_type
== 'suppress' )
1194 $userAllowedAll=false; // Don't hide from oversight log!!!
1197 // Which logs did we change anything about?
1198 if( $logRows[$logid]->log_deleted
!= $bitfield ) {
1199 $log_Ids[] = $logid;
1200 $this->updateLogs( $logRows[$logid], $bitfield );
1201 $this->updateRecentChangesLog( $logRows[$logid], $bitfield );
1205 // Don't log or touch if nothing changed
1207 $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted
,
1208 $comment, $title, 'logid', $log_Ids );
1210 // Were all revs allowed to be set?
1211 if( !$userAllowedAll ) {
1212 $wgOut->permissionRequired( 'suppressrevision' );
1220 * Moves an image to a safe private location
1221 * Caller is responsible for clearing caches
1222 * @param File $oimage
1223 * @returns mixed, timestamp string on success, false on failure
1225 function makeOldImagePrivate( $oimage ) {
1226 $transaction = new FSTransaction();
1227 if( !FileStore
::lock() ) {
1228 wfDebug( __METHOD__
.": failed to acquire file store lock, aborting\n" );
1231 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1232 // Dupe the file into the file store
1233 if( file_exists( $oldpath ) ) {
1234 // Is our directory configured?
1235 if( $store = FileStore
::get( 'deleted' ) ) {
1236 if( !$oimage->sha1
) {
1237 $oimage->upgradeRow(); // sha1 may be missing
1239 $key = $oimage->sha1
. '.' . $oimage->getExtension();
1240 $transaction->add( $store->insert( $key, $oldpath, FileStore
::DELETE_ORIGINAL
) );
1244 $transaction = false; // Return an error and do nothing
1247 wfDebug( __METHOD__
." deleting already-missing '$oldpath'; moving on to database\n" );
1250 $transaction = new FSTransaction(); // empty
1253 if( $transaction === false ) {
1255 wfDebug( __METHOD__
.": import to file store failed, aborting\n" );
1256 throw new MWException( "Could not archive and delete file $oldpath" );
1260 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1261 $transaction->commit();
1262 FileStore
::unlock();
1264 $m = explode('!',$oimage->archive_name
,2);
1271 * Moves an image from a safe private location
1272 * Caller is responsible for clearing caches
1273 * @param File $oimage
1274 * @returns mixed, string timestamp on success, false on failure
1276 function makeOldImagePublic( $oimage ) {
1277 $transaction = new FSTransaction();
1278 if( !FileStore
::lock() ) {
1279 wfDebug( __METHOD__
." could not acquire filestore lock\n" );
1283 $store = FileStore
::get( 'deleted' );
1285 wfDebug( __METHOD__
.": skipping row with no file.\n" );
1289 $key = $oimage->sha1
.'.'.$oimage->getExtension();
1290 $destDir = $oimage->getArchivePath();
1291 if( !is_dir( $destDir ) ) {
1292 wfMkdirParents( $destDir );
1294 $destPath = $destDir . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1295 // Check if any other stored revisions use this file;
1296 // if so, we shouldn't remove the file from the hidden
1297 // archives so they will still work. Check hidden files first.
1298 $useCount = $this->dbw
->selectField( 'oldimage', '1',
1299 array( 'oi_sha1' => $oimage->sha1
,
1300 'oi_deleted & '.File
::DELETED_FILE
=> File
::DELETED_FILE
),
1301 __METHOD__
, array( 'FOR UPDATE' ) );
1302 // Check the rest of the deleted archives too.
1303 // (these are the ones that don't show in the image history)
1305 $useCount = $this->dbw
->selectField( 'filearchive', '1',
1306 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1307 __METHOD__
, array( 'FOR UPDATE' ) );
1310 if( $useCount == 0 ) {
1311 wfDebug( __METHOD__
.": nothing else using {$oimage->sha1}, will deleting after\n" );
1312 $flags = FileStore
::DELETE_ORIGINAL
;
1316 $transaction->add( $store->export( $key, $destPath, $flags ) );
1318 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1319 $transaction->commit();
1320 FileStore
::unlock();
1322 $m = explode('!',$oimage->archive_name
,2);
1329 * Update the revision's rev_deleted field
1330 * @param Revision $rev
1331 * @param int $bitfield new rev_deleted bitfield value
1333 function updateRevision( $rev, $bitfield ) {
1334 $this->dbw
->update( 'revision',
1335 array( 'rev_deleted' => $bitfield ),
1336 array( 'rev_id' => $rev->getId(), 'rev_page' => $rev->getPage() ),
1342 * Update the revision's rev_deleted field
1343 * @param Revision $rev
1344 * @param Title $title
1345 * @param int $bitfield new rev_deleted bitfield value
1347 function updateArchive( $rev, $title, $bitfield ) {
1348 $this->dbw
->update( 'archive',
1349 array( 'ar_deleted' => $bitfield ),
1350 array( 'ar_namespace' => $title->getNamespace(),
1351 'ar_title' => $title->getDBKey(),
1352 // use timestamp for index
1353 'ar_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ),
1354 'ar_rev_id' => $rev->getId()
1360 * Update the images's oi_deleted field
1362 * @param int $bitfield new rev_deleted bitfield value
1364 function updateOldFiles( $file, $bitfield ) {
1365 $this->dbw
->update( 'oldimage',
1366 array( 'oi_deleted' => $bitfield ),
1367 array( 'oi_name' => $file->getName(),
1368 'oi_timestamp' => $this->dbw
->timestamp( $file->getTimestamp() ) ),
1374 * Update the images's fa_deleted field
1375 * @param ArchivedFile $file
1376 * @param int $bitfield new rev_deleted bitfield value
1378 function updateArchFiles( $file, $bitfield ) {
1379 $this->dbw
->update( 'filearchive',
1380 array( 'fa_deleted' => $bitfield ),
1381 array( 'fa_id' => $file->getId() ),
1387 * Update the logging log_deleted field
1389 * @param int $bitfield new rev_deleted bitfield value
1391 function updateLogs( $row, $bitfield ) {
1392 $this->dbw
->update( 'logging',
1393 array( 'log_deleted' => $bitfield ),
1394 array( 'log_id' => $row->log_id
),
1400 * Update the revision's recentchanges record if fields have been hidden
1401 * @param Revision $rev
1402 * @param int $bitfield new rev_deleted bitfield value
1404 function updateRecentChangesEdits( $rev, $bitfield ) {
1405 $this->dbw
->update( 'recentchanges',
1406 array( 'rc_deleted' => $bitfield,
1407 'rc_patrolled' => 1 ),
1408 array( 'rc_this_oldid' => $rev->getId(),
1409 'rc_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ) ),
1415 * Update the revision's recentchanges record if fields have been hidden
1417 * @param int $bitfield new rev_deleted bitfield value
1419 function updateRecentChangesLog( $row, $bitfield ) {
1420 $this->dbw
->update( 'recentchanges',
1421 array( 'rc_deleted' => $bitfield,
1422 'rc_patrolled' => 1 ),
1423 array( 'rc_logid' => $row->log_id
,
1424 'rc_timestamp' => $row->log_timestamp
),
1430 * Touch the page's cache invalidation timestamp; this forces cached
1431 * history views to refresh, so any newly hidden or shown fields will
1433 * @param Title $title
1435 function updatePage( $title ) {
1436 $title->invalidateCache();
1437 $this->dbw
->commit(); // Commit the transaction before the purge is sent
1438 $title->purgeSquid();
1439 // Extensions that require referencing previous revisions may need this
1440 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1444 * Checks for a change in the bitfield for a certain option and updates the
1445 * provided array accordingly.
1447 * @param String $desc Description to add to the array if the option was
1448 * enabled / disabled.
1449 * @param int $field The bitmask describing the single option.
1450 * @param int $diff The xor of the old and new bitfields.
1451 * @param array $arr The array to update.
1453 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
1454 if( $diff & $field ) {
1455 $arr[ ( $new & $field ) ?
0 : 1 ][] = $desc;
1460 * Gets an array describing the changes made to the visibilit of the revision.
1461 * If the resulting array is $arr, then $arr[0] will contain an array of strings
1462 * describing the items that were hidden, $arr[2] will contain an array of strings
1463 * describing the items that were unhidden, and $arr[3] will contain an array with
1464 * a single string, which can be one of "applied restrictions to sysops",
1465 * "removed restrictions from sysops", or null.
1467 * @param int $n The new bitfield.
1468 * @param int $o The old bitfield.
1469 * @return An array as described above.
1471 protected static function getChanges( $n, $o ) {
1473 $ret = array( 0 => array(), 1 => array(), 2 => array() );
1474 // Build bitfield changes in language
1475 self
::checkItem( wfMsgForContent( 'revdelete-content' ),
1476 Revision
::DELETED_TEXT
, $diff, $n, $ret );
1477 self
::checkItem( wfMsgForContent( 'revdelete-summary' ),
1478 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
1479 self
::checkItem( wfMsgForContent( 'revdelete-uname' ),
1480 Revision
::DELETED_USER
, $diff, $n, $ret );
1481 // Restriction application to sysops
1482 if( $diff & Revision
::DELETED_RESTRICTED
) {
1483 if( $n & Revision
::DELETED_RESTRICTED
)
1484 $ret[2][] = wfMsgForContent( 'revdelete-restricted' );
1486 $ret[2][] = wfMsgForContent( 'revdelete-unrestricted' );
1492 * Gets a log message to describe the given revision visibility change. This
1493 * message will be of the form "[hid {content, edit summary, username}];
1494 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
1496 * @param int $count The number of effected revisions.
1497 * @param int $nbitfield The new bitfield for the revision.
1498 * @param int $obitfield The old bitfield for the revision.
1499 * @param bool $isForLog
1501 public static function getLogMessage( $count, $nbitfield, $obitfield, $isForLog = false ) {
1504 $changes = self
::getChanges( $nbitfield, $obitfield );
1505 if( count( $changes[0] ) ) {
1506 $s .= wfMsgForContent( 'revdelete-hid', implode( ', ', $changes[0] ) );
1508 if( count( $changes[1] ) ) {
1510 $s .= wfMsgForContent( 'revdelete-unhid', implode( ', ', $changes[1] ) );
1512 if( count( $changes[2] ) ) {
1513 $s .= $s ?
' (' . $changes[2][0] . ')' : $changes[2][0];
1515 $msg = $isForLog ?
'logdelete-log-message' : 'revdelete-log-message';
1516 return wfMsgExt( $msg, array( 'parsemag', 'content' ), $s, $wgLang->formatNum($count) );
1521 * Record a log entry on the action
1522 * @param Title $title, page where item was removed from
1523 * @param int $count the number of revisions altered for this page
1524 * @param int $nbitfield the new _deleted value
1525 * @param int $obitfield the old _deleted value
1526 * @param string $comment
1527 * @param Title $target, the relevant page
1528 * @param string $param, URL param
1529 * @param Array $items
1531 protected function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target,
1532 $param, $items = array() )
1534 // Get the URL param's corresponding DB field
1535 if( !($field = self
::getRelationType($param)) )
1536 throw new MWException( "Bad log URL param type!" );
1537 // Put things hidden from sysops in the oversight log
1538 $logType = ( ($nbitfield |
$obitfield) & Revision
::DELETED_RESTRICTED
) ?
1539 'suppress' : 'delete';
1540 // Log deletions show with a difference action message
1541 $logAction = ( $param == 'logid' ) ?
'event' : 'revision';
1542 // Track what items changed here
1543 $itemCSV = implode(',',$items);
1544 // Add params for effected page and ids
1545 if( $param == 'logid' ) {
1546 $params = array( $itemCSV, "ofield={$obitfield}", "nfield={$nbitfield}" );
1548 $params = array( $param, $itemCSV, "ofield={$obitfield}", "nfield={$nbitfield}" );
1550 // Actually add the deletion log entry
1551 $log = new LogPage( $logType );
1552 $logid = $log->addEntry( $logAction, $title, $comment, $params );
1553 // Allow for easy searching of deletion log items for revision/log items
1554 $log->addRelations( $field, $items, $logid );
1557 // Get DB field name for URL param...
1558 // Future code for other things may also track
1559 // other types of revision-specific changes.
1560 public static function getRelationType( $param ) {
1565 return 'rev_timestamp';
1567 return 'oi_timestamp';
1573 return null; // bad URL type