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() );
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 if( !$rev->userCan(Revision
::DELETED_TEXT
) ) {
622 $revlink = '<span class="history-deleted">'.$date.'</span>';
623 $difflink = '(' . wfMsgHtml('diff') . ')';
626 $userlink = $this->skin
->revUserLink( $rev );
627 $comment = $this->skin
->revComment( $rev );
629 return "<li>$difflink $revlink $userlink $comment</li>";
636 private function fileLine( $file ) {
639 $target = $this->page
->getPrefixedText();
640 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
643 if( $file->isDeleted(File
::DELETED_FILE
) ) {
644 if( !$file->userCan(File
::DELETED_FILE
) ) {
647 $pageLink = $this->skin
->makeKnownLinkObj( $this->getTitle(), $date,
648 "target=$target&file=$file->sha1.".$file->getExtension() );
650 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
653 $url = $file->getUrlRel();
654 $pageLink = "<a href=\"{$url}\">{$date}</a>";
657 $data = wfMsg( 'widthheight', $wgLang->formatNum( $file->getWidth() ),
658 $wgLang->formatNum( $file->getHeight() ) ) .
659 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
660 $data = htmlspecialchars( $data );
662 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".
663 $this->fileComment( $file )."</li>";
667 * @param ArchivedFile $file
670 private function archivedfileLine( $file ) {
673 $target = $this->page
->getPrefixedText();
674 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
676 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
677 $pageLink = $this->skin
->makeKnownLinkObj( $undelete, $date,
678 "target=$target&file={$file->getKey()}" );
680 $data = wfMsg( 'widthheight', $wgLang->formatNum( $file->getWidth() ),
681 $wgLang->formatNum( $file->getHeight() ) ) .
682 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
683 $data = htmlspecialchars( $data );
685 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".
686 $this->fileComment( $file )."</li>";
690 * @param Array $row row
693 private function logLine( $row ) {
696 $date = htmlspecialchars( $wgLang->timeanddate( $row->log_timestamp
) );
697 $paramArray = LogPage
::extractParams( $row->log_params
);
698 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
700 $logtitle = SpecialPage
::getTitleFor( 'Log' );
701 $loglink = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
702 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
704 if( !LogEventsList
::userCan($row,LogPage
::DELETED_ACTION
) ) {
705 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
707 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
708 $this->skin
, $paramArray, true, true );
709 if( $row->log_deleted
& LogPage
::DELETED_ACTION
)
710 $action = '<span class="history-deleted">' . $action . '</span>';
713 $userLink = $this->skin
->userLink( $row->log_user
, User
::WhoIs($row->log_user
) );
714 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_USER
) ) {
715 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
718 $comment = $wgLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
719 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
720 $comment = '<span class="history-deleted">' . $comment . '</span>';
722 return "<li>($loglink) $date $userLink $action $comment</li>";
726 * Generate a user tool link cluster if the current user is allowed to view it
727 * @param ArchivedFile $file
728 * @return string HTML
730 private function fileUserTools( $file ) {
731 if( $file->userCan( Revision
::DELETED_USER
) ) {
732 $link = $this->skin
->userLink( $file->user
, $file->user_text
) .
733 $this->skin
->userToolLinks( $file->user
, $file->user_text
);
735 $link = wfMsgHtml( 'rev-deleted-user' );
737 if( $file->isDeleted( Revision
::DELETED_USER
) ) {
738 return '<span class="history-deleted">' . $link . '</span>';
744 * Wrap and format the given file's comment block, if the current
745 * user is allowed to view it.
747 * @param ArchivedFile $file
748 * @return string HTML
750 private function fileComment( $file ) {
751 if( $file->userCan( File
::DELETED_COMMENT
) ) {
752 $block = $this->skin
->commentBlock( $file->description
);
754 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
756 if( $file->isDeleted( File
::DELETED_COMMENT
) ) {
757 return "<span class=\"history-deleted\">$block</span>";
763 * @param WebRequest $request
765 private function submit( $request ) {
766 global $wgUser, $wgOut;
767 # Check edit token on submission
768 if( $this->wasPosted
&& !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
769 $wgOut->addWikiMsg( 'sessionfailure' );
772 $bitfield = $this->extractBitfield( $request );
773 $comment = $request->getText( 'wpReason' );
774 # Can the user set this field?
775 if( $bitfield & Revision
::DELETED_RESTRICTED
&& !$wgUser->isAllowed('suppressrevision') ) {
776 $wgOut->permissionRequired( 'suppressrevision' );
779 # If the save went through, go to success message...
780 if( $this->save( $bitfield, $comment, $this->page
) ) {
783 # ...otherwise, bounce back to form...
790 private function success() {
792 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
793 $wrap = '<span class="success">$1</span>';
794 if( $this->deleteKey
== 'logid' ) {
795 $wgOut->wrapWikiMsg( $wrap, 'logdelete-success' );
796 $this->showLogItems();
797 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
798 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
800 } else if( $this->deleteKey
== 'fileid' ) {
801 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
803 } else if( $this->deleteKey
== 'oldimage' ) {
804 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
809 private function failure() {
811 $wgOut->setPagetitle( wfMsg( 'actionfailed' ) );
812 $wrap = '<span class="error">$1</span>';
813 if( $this->deleteKey
== 'logid' ) {
814 $this->showLogItems();
815 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
816 $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
818 } else if( $this->deleteKey
== 'fileid' ) {
819 $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
821 } else if( $this->deleteKey
== 'oldimage' ) {
822 $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
828 * Put together a rev_deleted bitfield from the submitted checkboxes
829 * @param WebRequest $request
832 private function extractBitfield( $request ) {
834 foreach( $this->checks
as $item ) {
835 list( /* message */ , $name, $field ) = $item;
836 if( $request->getCheck( $name ) ) {
843 private function save( $bitfield, $reason, $title ) {
844 $dbw = wfGetDB( DB_MASTER
);
845 // Don't allow simply locking the interface for no reason
846 if( $bitfield == Revision
::DELETED_RESTRICTED
) {
849 $deleter = new RevisionDeleter( $dbw );
850 // By this point, only one of the below should be set
851 if( isset($this->revisions
) ) {
852 return $deleter->setRevVisibility( $title, $this->revisions
, $bitfield, $reason );
853 } else if( isset($this->archrevs
) ) {
854 return $deleter->setArchiveVisibility( $title, $this->archrevs
, $bitfield, $reason );
855 } else if( isset($this->ofiles
) ) {
856 return $deleter->setOldImgVisibility( $title, $this->ofiles
, $bitfield, $reason );
857 } else if( isset($this->afiles
) ) {
858 return $deleter->setArchFileVisibility( $title, $this->afiles
, $bitfield, $reason );
859 } else if( isset($this->events
) ) {
860 return $deleter->setEventVisibility( $title, $this->events
, $bitfield, $reason );
867 * Implements the actions for Revision Deletion.
868 * @ingroup SpecialPage
870 class RevisionDeleter
{
871 function __construct( $db ) {
876 * @param $title, the page these events apply to
877 * @param array $items list of revision ID numbers
878 * @param int $bitfield new rev_deleted value
879 * @param string $comment Comment for log records
881 function setRevVisibility( $title, $items, $bitfield, $comment ) {
884 $userAllowedAll = $success = true;
887 // Run through and pull all our data in one query
888 foreach( $items as $revid ) {
889 $where[] = intval($revid);
891 $result = $this->dbw
->select( array('revision','page'), '*',
892 array( 'rev_page' => $title->getArticleID(),
893 'rev_id' => $where, 'rev_page = page_id' ),
896 while( $row = $this->dbw
->fetchObject( $result ) ) {
897 $revObjs[$row->rev_id
] = new Revision( $row );
900 foreach( $items as $revid ) {
901 if( !isset($revObjs[$revid]) ) {
903 continue; // Must exist
904 } else if( $revObjs[$revid]->isCurrent() && ($bitfield & Revision
::DELETED_TEXT
) ) {
906 continue; // Cannot hide current version text
907 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
908 $userAllowedAll = false;
911 // For logging, maintain a count of revisions
912 if( $revObjs[$revid]->mDeleted
!= $bitfield ) {
914 $this->updateRevision( $revObjs[$revid], $bitfield );
915 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
920 // Don't log or touch if nothing changed
921 if( $revCount > 0 ) {
922 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted
,
923 $comment, $title, 'oldid', $revIDs );
924 $this->updatePage( $title );
926 // Where all revs allowed to be set?
927 if( !$userAllowedAll ) {
928 //FIXME: still might be confusing???
929 $wgOut->permissionRequired( 'suppressrevision' );
937 * @param $title, the page these events apply to
938 * @param array $items list of revision ID numbers
939 * @param int $bitfield new rev_deleted value
940 * @param string $comment Comment for log records
942 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
945 $userAllowedAll = $success = true;
948 // Run through and pull all our data in one query
949 foreach( $items as $timestamp ) {
950 $where[] = $this->dbw
->timestamp( $timestamp );
952 $result = $this->dbw
->select( 'archive', '*',
954 'ar_namespace' => $title->getNamespace(),
955 'ar_title' => $title->getDBkey(),
956 'ar_timestamp' => $where
959 while( $row = $this->dbw
->fetchObject( $result ) ) {
960 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
961 $revObjs[$timestamp] = new Revision( array(
962 'page' => $title->getArticleId(),
963 'id' => $row->ar_rev_id
,
964 'text' => $row->ar_text_id
,
965 'comment' => $row->ar_comment
,
966 'user' => $row->ar_user
,
967 'user_text' => $row->ar_user_text
,
968 'timestamp' => $timestamp,
969 'minor_edit' => $row->ar_minor_edit
,
970 'text_id' => $row->ar_text_id
,
971 'deleted' => $row->ar_deleted
,
972 'len' => $row->ar_len
) );
975 foreach( $items as $timestamp ) {
976 // This will only select the first revision with this timestamp.
977 // Since they are all selected/deleted at once, we can just check the
978 // permissions of one. UPDATE is done via timestamp, so all revs are set.
979 if( !is_object($revObjs[$timestamp]) ) {
981 continue; // Must exist
982 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
983 $userAllowedAll=false;
986 // Which revisions did we change anything about?
987 if( $revObjs[$timestamp]->mDeleted
!= $bitfield ) {
988 $Id_set[] = $timestamp;
989 $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
993 // For logging, maintain a count of revisions
995 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted
,
996 $comment, $title, 'artimestamp', $Id_set );
998 // Where all revs allowed to be set?
999 if( !$userAllowedAll ) {
1000 $wgOut->permissionRequired( 'suppressrevision' );
1008 * @param $title, the page these events apply to
1009 * @param array $items list of revision ID numbers
1010 * @param int $bitfield new rev_deleted value
1011 * @param string $comment Comment for log records
1013 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
1016 $userAllowedAll = $success = true;
1019 // Run through and pull all our data in one query
1020 foreach( $items as $timestamp ) {
1021 $where[] = $timestamp.'!'.$title->getDBkey();
1023 $result = $this->dbw
->select( 'oldimage', '*',
1024 array( 'oi_name' => $title->getDBkey(), 'oi_archive_name' => $where ),
1027 while( $row = $this->dbw
->fetchObject( $result ) ) {
1028 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
1029 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
1030 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
1033 foreach( $items as $timestamp ) {
1034 $archivename = $timestamp.'!'.$title->getDBkey();
1035 if( !isset($filesObjs[$archivename]) ) {
1037 continue; // Must exist
1038 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
1039 $userAllowedAll=false;
1043 $transaction = true;
1044 // Which revisions did we change anything about?
1045 if( $filesObjs[$archivename]->deleted
!= $bitfield ) {
1048 $this->dbw
->begin();
1049 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
1050 // If this image is currently hidden...
1051 if( $filesObjs[$archivename]->deleted
& File
::DELETED_FILE
) {
1052 if( $bitfield & File
::DELETED_FILE
) {
1053 # Leave it alone if we are not changing this...
1055 $transaction = true;
1057 # We are moving this out
1058 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
1059 $set[]=$transaction;
1061 // Is it just now becoming hidden?
1062 } else if( $bitfield & File
::DELETED_FILE
) {
1063 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
1064 $set[]=$transaction;
1068 // If our file operations fail, then revert back the db
1069 if( $transaction==false ) {
1070 $this->dbw
->rollback();
1073 $this->dbw
->commit();
1077 // Log if something was changed
1079 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted
,
1080 $comment, $title, 'oldimage', $set );
1081 # Purge page/history
1082 $file = wfLocalFile( $title );
1083 $file->purgeCache();
1084 $file->purgeHistory();
1085 # Invalidate cache for all pages using this file
1086 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
1087 $update->doUpdate();
1089 // Where all revs allowed to be set?
1090 if( !$userAllowedAll ) {
1091 $wgOut->permissionRequired( 'suppressrevision' );
1099 * @param $title, the page these events apply to
1100 * @param array $items list of revision ID numbers
1101 * @param int $bitfield new rev_deleted value
1102 * @param string $comment Comment for log records
1104 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
1107 $userAllowedAll = $success = true;
1111 // Run through and pull all our data in one query
1112 foreach( $items as $id ) {
1113 $where[] = intval($id);
1115 $result = $this->dbw
->select( 'filearchive', '*',
1116 array( 'fa_name' => $title->getDBkey(),
1117 'fa_id' => $where ),
1119 while( $row = $this->dbw
->fetchObject( $result ) ) {
1120 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
1123 foreach( $items as $fileid ) {
1124 if( !isset($filesObjs[$fileid]) ) {
1126 continue; // Must exist
1127 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
1128 $userAllowedAll=false;
1131 // Which revisions did we change anything about?
1132 if( $filesObjs[$fileid]->deleted
!= $bitfield ) {
1136 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1139 // Log if something was changed
1141 $this->updateLog( $title, $count, $bitfield, $comment,
1142 $filesObjs[$fileid]->deleted
, $title, 'fileid', $Id_set );
1144 // Where all revs allowed to be set?
1145 if( !$userAllowedAll ) {
1146 $wgOut->permissionRequired( 'suppressrevision' );
1154 * @param $title, the log page these events apply to
1155 * @param array $items list of log ID numbers
1156 * @param int $bitfield new log_deleted value
1157 * @param string $comment Comment for log records
1159 function setEventVisibility( $title, $items, $bitfield, $comment ) {
1162 $userAllowedAll = $success = true;
1166 // Run through and pull all our data in one query
1167 foreach( $items as $logid ) {
1168 $where[] = intval($logid);
1170 list($log,$logtype) = explode( '/',$title->getDBkey(), 2 );
1171 $result = $this->dbw
->select( 'logging', '*',
1172 array( 'log_type' => $logtype, 'log_id' => $where ),
1175 while( $row = $this->dbw
->fetchObject( $result ) ) {
1176 $logRows[$row->log_id
] = $row;
1179 foreach( $items as $logid ) {
1180 if( !isset($logRows[$logid]) ) {
1182 continue; // Must exist
1183 } else if( !LogEventsList
::userCan($logRows[$logid], LogPage
::DELETED_RESTRICTED
)
1184 ||
$logRows[$logid]->log_type
== 'suppress' )
1186 $userAllowedAll=false; // Don't hide from oversight log!!!
1189 // Which logs did we change anything about?
1190 if( $logRows[$logid]->log_deleted
!= $bitfield ) {
1191 $log_Ids[] = $logid;
1192 $this->updateLogs( $logRows[$logid], $bitfield );
1193 $this->updateRecentChangesLog( $logRows[$logid], $bitfield );
1197 // Don't log or touch if nothing changed
1199 $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted
,
1200 $comment, $title, 'logid', $log_Ids );
1202 // Were all revs allowed to be set?
1203 if( !$userAllowedAll ) {
1204 $wgOut->permissionRequired( 'suppressrevision' );
1212 * Moves an image to a safe private location
1213 * Caller is responsible for clearing caches
1214 * @param File $oimage
1215 * @returns mixed, timestamp string on success, false on failure
1217 function makeOldImagePrivate( $oimage ) {
1218 $transaction = new FSTransaction();
1219 if( !FileStore
::lock() ) {
1220 wfDebug( __METHOD__
.": failed to acquire file store lock, aborting\n" );
1223 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1224 // Dupe the file into the file store
1225 if( file_exists( $oldpath ) ) {
1226 // Is our directory configured?
1227 if( $store = FileStore
::get( 'deleted' ) ) {
1228 if( !$oimage->sha1
) {
1229 $oimage->upgradeRow(); // sha1 may be missing
1231 $key = $oimage->sha1
. '.' . $oimage->getExtension();
1232 $transaction->add( $store->insert( $key, $oldpath, FileStore
::DELETE_ORIGINAL
) );
1236 $transaction = false; // Return an error and do nothing
1239 wfDebug( __METHOD__
." deleting already-missing '$oldpath'; moving on to database\n" );
1242 $transaction = new FSTransaction(); // empty
1245 if( $transaction === false ) {
1247 wfDebug( __METHOD__
.": import to file store failed, aborting\n" );
1248 throw new MWException( "Could not archive and delete file $oldpath" );
1252 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1253 $transaction->commit();
1254 FileStore
::unlock();
1256 $m = explode('!',$oimage->archive_name
,2);
1263 * Moves an image from a safe private location
1264 * Caller is responsible for clearing caches
1265 * @param File $oimage
1266 * @returns mixed, string timestamp on success, false on failure
1268 function makeOldImagePublic( $oimage ) {
1269 $transaction = new FSTransaction();
1270 if( !FileStore
::lock() ) {
1271 wfDebug( __METHOD__
." could not acquire filestore lock\n" );
1275 $store = FileStore
::get( 'deleted' );
1277 wfDebug( __METHOD__
.": skipping row with no file.\n" );
1281 $key = $oimage->sha1
.'.'.$oimage->getExtension();
1282 $destDir = $oimage->getArchivePath();
1283 if( !is_dir( $destDir ) ) {
1284 wfMkdirParents( $destDir );
1286 $destPath = $destDir . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1287 // Check if any other stored revisions use this file;
1288 // if so, we shouldn't remove the file from the hidden
1289 // archives so they will still work. Check hidden files first.
1290 $useCount = $this->dbw
->selectField( 'oldimage', '1',
1291 array( 'oi_sha1' => $oimage->sha1
,
1292 'oi_deleted & '.File
::DELETED_FILE
=> File
::DELETED_FILE
),
1293 __METHOD__
, array( 'FOR UPDATE' ) );
1294 // Check the rest of the deleted archives too.
1295 // (these are the ones that don't show in the image history)
1297 $useCount = $this->dbw
->selectField( 'filearchive', '1',
1298 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1299 __METHOD__
, array( 'FOR UPDATE' ) );
1302 if( $useCount == 0 ) {
1303 wfDebug( __METHOD__
.": nothing else using {$oimage->sha1}, will deleting after\n" );
1304 $flags = FileStore
::DELETE_ORIGINAL
;
1308 $transaction->add( $store->export( $key, $destPath, $flags ) );
1310 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1311 $transaction->commit();
1312 FileStore
::unlock();
1314 $m = explode('!',$oimage->archive_name
,2);
1321 * Update the revision's rev_deleted field
1322 * @param Revision $rev
1323 * @param int $bitfield new rev_deleted bitfield value
1325 function updateRevision( $rev, $bitfield ) {
1326 $this->dbw
->update( 'revision',
1327 array( 'rev_deleted' => $bitfield ),
1328 array( 'rev_id' => $rev->getId(), 'rev_page' => $rev->getPage() ),
1334 * Update the revision's rev_deleted field
1335 * @param Revision $rev
1336 * @param Title $title
1337 * @param int $bitfield new rev_deleted bitfield value
1339 function updateArchive( $rev, $title, $bitfield ) {
1340 $this->dbw
->update( 'archive',
1341 array( 'ar_deleted' => $bitfield ),
1342 array( 'ar_namespace' => $title->getNamespace(),
1343 'ar_title' => $title->getDBkey(),
1344 // use timestamp for index
1345 'ar_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ),
1346 'ar_rev_id' => $rev->getId()
1352 * Update the images's oi_deleted field
1354 * @param int $bitfield new rev_deleted bitfield value
1356 function updateOldFiles( $file, $bitfield ) {
1357 $this->dbw
->update( 'oldimage',
1358 array( 'oi_deleted' => $bitfield ),
1359 array( 'oi_name' => $file->getName(),
1360 'oi_timestamp' => $this->dbw
->timestamp( $file->getTimestamp() ) ),
1366 * Update the images's fa_deleted field
1367 * @param ArchivedFile $file
1368 * @param int $bitfield new rev_deleted bitfield value
1370 function updateArchFiles( $file, $bitfield ) {
1371 $this->dbw
->update( 'filearchive',
1372 array( 'fa_deleted' => $bitfield ),
1373 array( 'fa_id' => $file->getId() ),
1379 * Update the logging log_deleted field
1381 * @param int $bitfield new rev_deleted bitfield value
1383 function updateLogs( $row, $bitfield ) {
1384 $this->dbw
->update( 'logging',
1385 array( 'log_deleted' => $bitfield ),
1386 array( 'log_id' => $row->log_id
),
1392 * Update the revision's recentchanges record if fields have been hidden
1393 * @param Revision $rev
1394 * @param int $bitfield new rev_deleted bitfield value
1396 function updateRecentChangesEdits( $rev, $bitfield ) {
1397 $this->dbw
->update( 'recentchanges',
1398 array( 'rc_deleted' => $bitfield,
1399 'rc_patrolled' => 1 ),
1400 array( 'rc_this_oldid' => $rev->getId(),
1401 'rc_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ) ),
1407 * Update the revision's recentchanges record if fields have been hidden
1409 * @param int $bitfield new rev_deleted bitfield value
1411 function updateRecentChangesLog( $row, $bitfield ) {
1412 $this->dbw
->update( 'recentchanges',
1413 array( 'rc_deleted' => $bitfield,
1414 'rc_patrolled' => 1 ),
1415 array( 'rc_logid' => $row->log_id
,
1416 'rc_timestamp' => $row->log_timestamp
),
1422 * Touch the page's cache invalidation timestamp; this forces cached
1423 * history views to refresh, so any newly hidden or shown fields will
1425 * @param Title $title
1427 function updatePage( $title ) {
1428 $title->invalidateCache();
1429 $this->dbw
->commit(); // Commit the transaction before the purge is sent
1430 $title->purgeSquid();
1431 // Extensions that require referencing previous revisions may need this
1432 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1436 * Checks for a change in the bitfield for a certain option and updates the
1437 * provided array accordingly.
1439 * @param String $desc Description to add to the array if the option was
1440 * enabled / disabled.
1441 * @param int $field The bitmask describing the single option.
1442 * @param int $diff The xor of the old and new bitfields.
1443 * @param array $arr The array to update.
1445 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
1446 if( $diff & $field ) {
1447 $arr[ ( $new & $field ) ?
0 : 1 ][] = $desc;
1452 * Gets an array describing the changes made to the visibilit of the revision.
1453 * If the resulting array is $arr, then $arr[0] will contain an array of strings
1454 * describing the items that were hidden, $arr[2] will contain an array of strings
1455 * describing the items that were unhidden, and $arr[3] will contain an array with
1456 * a single string, which can be one of "applied restrictions to sysops",
1457 * "removed restrictions from sysops", or null.
1459 * @param int $n The new bitfield.
1460 * @param int $o The old bitfield.
1461 * @return An array as described above.
1463 protected static function getChanges( $n, $o ) {
1465 $ret = array( 0 => array(), 1 => array(), 2 => array() );
1466 // Build bitfield changes in language
1467 self
::checkItem( wfMsgForContent( 'revdelete-content' ),
1468 Revision
::DELETED_TEXT
, $diff, $n, $ret );
1469 self
::checkItem( wfMsgForContent( 'revdelete-summary' ),
1470 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
1471 self
::checkItem( wfMsgForContent( 'revdelete-uname' ),
1472 Revision
::DELETED_USER
, $diff, $n, $ret );
1473 // Restriction application to sysops
1474 if( $diff & Revision
::DELETED_RESTRICTED
) {
1475 if( $n & Revision
::DELETED_RESTRICTED
)
1476 $ret[2][] = wfMsgForContent( 'revdelete-restricted' );
1478 $ret[2][] = wfMsgForContent( 'revdelete-unrestricted' );
1484 * Gets a log message to describe the given revision visibility change. This
1485 * message will be of the form "[hid {content, edit summary, username}];
1486 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
1488 * @param int $count The number of effected revisions.
1489 * @param int $nbitfield The new bitfield for the revision.
1490 * @param int $obitfield The old bitfield for the revision.
1491 * @param bool $isForLog
1493 public static function getLogMessage( $count, $nbitfield, $obitfield, $isForLog = false ) {
1496 $changes = self
::getChanges( $nbitfield, $obitfield );
1497 if( count( $changes[0] ) ) {
1498 $s .= wfMsgForContent( 'revdelete-hid', implode( ', ', $changes[0] ) );
1500 if( count( $changes[1] ) ) {
1502 $s .= wfMsgForContent( 'revdelete-unhid', implode( ', ', $changes[1] ) );
1504 if( count( $changes[2] ) ) {
1505 $s .= $s ?
' (' . $changes[2][0] . ')' : $changes[2][0];
1507 $msg = $isForLog ?
'logdelete-log-message' : 'revdelete-log-message';
1508 return wfMsgExt( $msg, array( 'parsemag', 'content' ), $s, $wgLang->formatNum($count) );
1513 * Record a log entry on the action
1514 * @param Title $title, page where item was removed from
1515 * @param int $count the number of revisions altered for this page
1516 * @param int $nbitfield the new _deleted value
1517 * @param int $obitfield the old _deleted value
1518 * @param string $comment
1519 * @param Title $target, the relevant page
1520 * @param string $param, URL param
1521 * @param Array $items
1523 protected function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target,
1524 $param, $items = array() )
1526 // Get the URL param's corresponding DB field
1527 if( !($field = self
::getRelationType($param)) )
1528 throw new MWException( "Bad log URL param type!" );
1529 // Put things hidden from sysops in the oversight log
1530 $logType = ( ($nbitfield |
$obitfield) & Revision
::DELETED_RESTRICTED
) ?
1531 'suppress' : 'delete';
1532 // Log deletions show with a difference action message
1533 $logAction = ( $param == 'logid' ) ?
'event' : 'revision';
1534 // Track what items changed here
1535 $itemCSV = implode(',',$items);
1536 // Add params for effected page and ids
1537 if( $param == 'logid' ) {
1538 $params = array( $itemCSV, "ofield={$obitfield}", "nfield={$nbitfield}" );
1540 $params = array( $param, $itemCSV, "ofield={$obitfield}", "nfield={$nbitfield}" );
1542 // Actually add the deletion log entry
1543 $log = new LogPage( $logType );
1544 $logid = $log->addEntry( $logAction, $title, $comment, $params );
1545 // Allow for easy searching of deletion log items for revision/log items
1546 $log->addRelations( $field, $items, $logid );
1549 // Get DB field name for URL param...
1550 // Future code for other things may also track
1551 // other types of revision-specific changes.
1552 public static function getRelationType( $param ) {
1557 return 'rev_timestamp';
1559 return 'oi_timestamp';
1565 return null; // bad URL type