5857bb8e10f638e5eda924ac7b7361775a385471
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();
88 return; // no logs for now
90 list($qc,$lim) = $this->getLogQueryCond();
91 # Show relevant lines from the deletion log
92 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'delete' ) ) . "</h2>\n" );
93 LogEventsList
::showLogExtract( $wgOut, 'delete', $this->page
->getPrefixedText(), '', $lim, $qc );
94 # Show relevant lines from the suppression log
95 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
96 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'suppress' ) ) . "</h2>\n" );
97 LogEventsList
::showLogExtract( $wgOut, 'suppress', $this->page
->getPrefixedText(), '', $lim, $qc );
101 private function showConvenienceLinks() {
102 global $wgOut, $wgUser;
103 # Give a link to the logs/hist for this page
104 if( !is_null($this->page
) && $this->page
->getNamespace() > -1 ) {
106 $logtitle = SpecialPage
::getTitleFor( 'Log' );
107 $links[] = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
108 wfArrayToCGI( array( 'page' => $this->page
->getPrefixedUrl() ) ) );
109 # Give a link to the page history
110 $links[] = $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml( 'pagehist' ),
111 wfArrayToCGI( array( 'action' => 'history' ) ) );
112 # Link to deleted edits
113 if( $wgUser->isAllowed('undelete') ) {
114 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
115 $links[] = $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
116 wfArrayToCGI( array( 'target' => $this->page
->getPrefixedDBkey() ) ) );
118 # Logs themselves don't have histories or archived revisions
119 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
123 private function getLogQueryCond() {
124 $ids = $safeIds = array();
125 $limit = 25; // default
126 $conds = array( 'log_action' => 'revision' ); // revision delete logs
127 switch( $this->deleteKey
) {
129 $ids = $this->oldids
;
132 $ids = $this->artimestamps
;
135 $ids = $this->oldimgs
;
138 $ids = $this->fileids
;
140 default: // bad type?
141 return array($conds,$limit);
143 // Just get the whole log if there are a lot if items
144 if( count($ids) > $limit )
145 return array($conds,$limit);
147 foreach( $ids as $id ) {
148 if( preg_match( '/^\d+$/', $id, $m ) ) {
152 // Format is <id1,id2,i3...>
153 if( count($safeIds) ) {
154 $conds[] = "log_params RLIKE '^{$this->deleteKey}.*(^|\n|,)(".implode('|',$safeIds).")(,|\n|$)'";
156 $conds = array('1=0');
158 return array($conds,$limit);
161 private function secureOperation() {
163 $this->deleteKey
= '';
164 // At this point, we should only have one of these
165 if( $this->oldids
) {
166 $this->revisions
= $this->oldids
;
167 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
168 $this->deleteKey
= 'oldid';
169 } else if( $this->artimestamps
) {
170 $this->archrevs
= $this->artimestamps
;
171 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
172 $this->deleteKey
= 'artimestamp';
173 } else if( $this->oldimgs
) {
174 $this->ofiles
= $this->oldimgs
;
175 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
176 $this->deleteKey
= 'oldimage';
177 } else if( $this->fileids
) {
178 $this->afiles
= $this->fileids
;
179 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
180 $this->deleteKey
= 'fileid';
181 } else if( $this->logids
) {
182 $this->events
= $this->logids
;
183 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage
::DELETED_ACTION
);
184 $this->deleteKey
= 'logid';
186 // Our checkbox messages depends one what we are doing,
187 // e.g. we don't hide "text" for logs or images
188 $this->checks
= array(
190 array( 'revdelete-hide-comment', 'wpHideComment', Revision
::DELETED_COMMENT
),
191 array( 'revdelete-hide-user', 'wpHideUser', Revision
::DELETED_USER
)
193 if( $wgUser->isAllowed('suppressrevision') ) {
194 $this->checks
[] = array( 'revdelete-hide-restricted',
195 'wpHideRestricted', Revision
::DELETED_RESTRICTED
);
200 * Show a deleted file version requested by the visitor.
202 private function tryShowFile( $key ) {
203 global $wgOut, $wgRequest;
204 $oimage = RepoGroup
::singleton()->getLocalRepo()->newFromArchiveName( $this->page
, $key );
206 // Check if user is allowed to see this file
207 if( !$oimage->userCan(File
::DELETED_FILE
) ) {
208 $wgOut->permissionRequired( 'suppressrevision' );
211 # We mustn't allow the output to be Squid cached, otherwise
212 # if an admin previews a deleted image, and it's cached, then
213 # a user without appropriate permissions can toddle off and
214 # nab the image, and Squid will serve it
215 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
216 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
217 $wgRequest->response()->header( 'Pragma: no-cache' );
218 # Stream the file to the client
219 $store = FileStore
::get( 'deleted' );
220 $store->stream( $key );
225 * This lets a user set restrictions for live and archived revisions
227 private function showRevs() {
228 global $wgOut, $wgUser;
231 $count = ($this->deleteKey
== 'oldid') ?
232 count($this->revisions
) : count($this->archrevs
);
233 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(), $count );
236 $wgOut->addHTML( "<ul>" );
238 $where = $revObjs = array();
239 $dbr = wfGetDB( DB_MASTER
);
243 if( $this->deleteKey
== 'oldid' ) {
244 // Run through and pull all our data in one query
245 foreach( $this->revisions
as $revid ) {
246 $where[] = intval($revid);
248 $result = $dbr->select( array('revision','page'), '*',
250 'rev_page' => $this->page
->getArticleID(),
256 while( $row = $dbr->fetchObject( $result ) ) {
257 $revObjs[$row->rev_id
] = new Revision( $row );
259 foreach( $this->revisions
as $revid ) {
260 if( !isset($revObjs[$revid]) ) continue; // Must exist
261 // Check if the revision was Oversighted
262 if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
263 if( !$this->wasPosted
) {
264 return $wgOut->permissionRequired( 'suppressrevision' );
266 $UserAllowed = false;
269 $wgOut->addHTML( $this->historyLine( $revObjs[$revid] ) );
270 $bitfields |
= $revObjs[$revid]->mDeleted
;
274 // Run through and pull all our data in one query
275 foreach( $this->archrevs
as $timestamp ) {
276 $where[] = $dbr->timestamp( $timestamp );
278 $result = $dbr->select( 'archive', '*',
280 'ar_namespace' => $this->page
->getNamespace(),
281 'ar_title' => $this->page
->getDBKey(),
282 'ar_timestamp' => $where
286 while( $row = $dbr->fetchObject( $result ) ) {
287 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
288 $revObjs[$timestamp] = new Revision( array(
289 'page' => $this->page
->getArticleId(),
290 'id' => $row->ar_rev_id
,
291 'text' => $row->ar_text_id
,
292 'comment' => $row->ar_comment
,
293 'user' => $row->ar_user
,
294 'user_text' => $row->ar_user_text
,
295 'timestamp' => $timestamp,
296 'minor_edit' => $row->ar_minor_edit
,
297 'text_id' => $row->ar_text_id
,
298 'deleted' => $row->ar_deleted
,
299 'len' => $row->ar_len
) );
301 foreach( $this->archrevs
as $timestamp ) {
302 if( !isset($revObjs[$timestamp]) ) {
304 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
305 // If a rev is hidden from sysops
306 if( !$this->wasPosted
) {
307 return $wgOut->permissionRequired( 'suppressrevision' );
309 $UserAllowed = false;
312 $wgOut->addHTML( $this->historyLine( $revObjs[$timestamp] ) );
313 $bitfields |
= $revObjs[$timestamp]->mDeleted
;
317 return $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
320 $wgOut->addHTML( "</ul>" );
322 $this->addUsageText();
324 // Normal sysops can always see what they did, but can't always change it
325 if( !$UserAllowed ) return;
328 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
329 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
332 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
333 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
334 Xml
::hidden( 'type', $this->deleteKey
)
336 if( $this->deleteKey
== 'oldid' ) {
337 $hidden[] = Xml
::hidden( 'oldid', implode(',',$this->oldids
) );
339 $hidden[] = Xml
::hidden( 'artimestamp', implode(',',$this->artimestamps
) );
342 Xml
::openElement( 'form', array( 'method' => 'post',
343 'action' => $this->getTitle()->getLocalUrl( 'action=submit' ),
344 'id' => 'mw-revdel-form-revisions' ) ) .
345 Xml
::openElement( 'fieldset' ) .
346 xml
::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
349 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
350 foreach( $items as $item ) {
351 $wgOut->addHTML( Xml
::tags( 'p', null, $item ) );
353 foreach( $hidden as $item ) {
354 $wgOut->addHTML( $item );
357 Xml
::closeElement( 'fieldset' ) .
358 Xml
::closeElement( 'form' ) . "\n"
363 * This lets a user set restrictions for archived images
365 private function showImages() {
366 global $wgOut, $wgUser, $wgLang;
369 $count = ($this->deleteKey
== 'oldimage') ?
count($this->ofiles
) : count($this->afiles
);
370 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(),
371 $wgLang->formatNum($count) );
374 $wgOut->addHTML( "<ul>" );
376 $where = $filesObjs = array();
377 $dbr = wfGetDB( DB_MASTER
);
378 // Live old revisions...
380 if( $this->deleteKey
== 'oldimage' ) {
381 // Run through and pull all our data in one query
382 foreach( $this->ofiles
as $timestamp ) {
383 $where[] = $timestamp.'!'.$this->page
->getDBKey();
385 $result = $dbr->select( 'oldimage', '*',
387 'oi_name' => $this->page
->getDBKey(),
388 'oi_archive_name' => $where
392 while( $row = $dbr->fetchObject( $result ) ) {
393 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
394 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
395 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
397 // Check through our images
398 foreach( $this->ofiles
as $timestamp ) {
399 $archivename = $timestamp.'!'.$this->page
->getDBKey();
400 if( !isset($filesObjs[$archivename]) ) {
402 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
403 // If a rev is hidden from sysops
404 if( !$this->wasPosted
) {
405 return $wgOut->permissionRequired( 'suppressrevision' );
407 $UserAllowed = false;
410 // Inject history info
411 $wgOut->addHTML( $this->fileLine( $filesObjs[$archivename] ) );
412 $bitfields |
= $filesObjs[$archivename]->deleted
;
416 // Run through and pull all our data in one query
417 foreach( $this->afiles
as $id ) {
418 $where[] = intval($id);
420 $result = $dbr->select( 'filearchive', '*',
422 'fa_name' => $this->page
->getDBKey(),
427 while( $row = $dbr->fetchObject( $result ) ) {
428 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
431 foreach( $this->afiles
as $fileid ) {
432 if( !isset($filesObjs[$fileid]) ) {
434 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
435 // If a rev is hidden from sysops
436 if( !$this->wasPosted
) {
437 return $wgOut->permissionRequired( 'suppressrevision' );
439 $UserAllowed = false;
442 // Inject history info
443 $wgOut->addHTML( $this->archivedfileLine( $filesObjs[$fileid] ) );
444 $bitfields |
= $filesObjs[$fileid]->deleted
;
448 return $wgOut->showErrorPage( 'revdelete-nooldid-title','revdelete-nooldid-text' );
451 $wgOut->addHTML( "</ul>" );
453 $this->addUsageText();
454 // Normal sysops can always see what they did, but can't always change it
455 if( !$UserAllowed ) return;
458 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
459 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
462 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
463 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
464 Xml
::hidden( 'type', $this->deleteKey
)
466 if( $this->deleteKey
== 'oldimage' ) {
467 $hidden[] = Xml
::hidden( 'oldimage', implode(',',$this->oldimgs
) );
469 $hidden[] = Xml
::hidden( 'fileid', implode(',',$this->fileids
) );
472 Xml
::openElement( 'form', array( 'method' => 'post',
473 'action' => $this->getTitle()->getLocalUrl( 'action=submit' ),
474 'id' => 'mw-revdel-form-filerevisions' )
476 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
479 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
480 foreach( $items as $item ) {
481 $wgOut->addHTML( "<p>$item</p>" );
483 foreach( $hidden as $item ) {
484 $wgOut->addHTML( $item );
488 Xml
::closeElement( 'fieldset' ) .
489 Xml
::closeElement( 'form' ) . "\n"
494 * This lets a user set restrictions for log items
496 private function showLogItems() {
497 global $wgOut, $wgUser, $wgMessageCache, $wgLang;
500 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->events
) ) );
503 $wgOut->addHTML( "<ul>" );
505 $where = $logRows = array();
506 $dbr = wfGetDB( DB_MASTER
);
507 // Run through and pull all our data in one query
509 foreach( $this->events
as $logid ) {
510 $where[] = intval($logid);
512 list($log,$logtype) = explode( '/',$this->page
->getDBKey(), 2 );
513 $result = $dbr->select( 'logging', '*',
514 array( 'log_type' => $logtype, 'log_id' => $where ),
517 while( $row = $dbr->fetchObject( $result ) ) {
518 $logRows[$row->log_id
] = $row;
520 $wgMessageCache->loadAllMessages();
521 foreach( $this->events
as $logid ) {
522 // Don't hide from oversight log!!!
523 if( !isset( $logRows[$logid] ) ||
$logRows[$logid]->log_type
=='suppress' ) {
525 } else if( !LogEventsList
::userCan( $logRows[$logid],Revision
::DELETED_RESTRICTED
) ) {
526 // If an event is hidden from sysops
527 if( !$this->wasPosted
) {
528 return $wgOut->permissionRequired( 'suppressrevision' );
530 $UserAllowed = false;
533 $wgOut->addHTML( $this->logLine( $logRows[$logid] ) );
534 $bitfields |
= $logRows[$logid]->log_deleted
;
537 return $wgOut->showErrorPage( 'revdelete-nologid-title', 'revdelete-nologid-text' );
540 $wgOut->addHTML( "</ul>" );
542 $this->addUsageText();
543 // Normal sysops can always see what they did, but can't always change it
544 if( !$UserAllowed ) return;
547 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
548 Xml
::submitButton( wfMsg( 'revdelete-submit' ) ) );
550 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
551 Xml
::hidden( 'target', $this->page
->getPrefixedDBKey() ),
552 Xml
::hidden( 'page', $this->contextPage ?
$this->contextPage
->getPrefixedDBKey() : '' ),
553 Xml
::hidden( 'type', $this->deleteKey
),
554 Xml
::hidden( 'logid', implode(',',$this->logids
) )
558 Xml
::openElement( 'form', array( 'method' => 'post',
559 'action' => $this->getTitle()->getLocalUrl( 'action=submit' ), 'id' => 'mw-revdel-form-logs' ) ) .
560 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
563 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
564 foreach( $items as $item ) {
565 $wgOut->addHTML( "<p>$item</p>" );
567 foreach( $hidden as $item ) {
568 $wgOut->addHTML( $item );
572 Xml
::closeElement( 'fieldset' ) .
573 Xml
::closeElement( 'form' ) . "\n"
577 private function addUsageText() {
578 global $wgOut, $wgUser;
579 $wgOut->addWikiMsg( 'revdelete-text' );
580 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
581 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
586 * @param int $bitfields, aggregate bitfield of all the bitfields
587 * @returns string HTML
589 private function buildCheckBoxes( $bitfields ) {
591 // FIXME: all items checked for just one rev are checked, even if not set for the others
592 foreach( $this->checks
as $item ) {
593 list( $message, $name, $field ) = $item;
594 $line = Xml
::tags( 'div', null, Xml
::checkLabel( wfMsg($message), $name, $name,
595 $bitfields & $field ) );
596 if( $field == Revision
::DELETED_RESTRICTED
) $line = "<b>$line</b>";
603 * @param Revision $rev
606 private function historyLine( $rev ) {
607 global $wgLang, $wgUser;
609 $date = $wgLang->timeanddate( $rev->getTimestamp() );
610 $difflink = $del = '';
612 if( $this->deleteKey
== 'oldid' ) {
613 $tokenParams = '&unhide=1&token='.urlencode( $wgUser->editToken( $rev->getId() ) );
614 $revlink = $this->skin
->makeLinkObj( $this->page
, $date, 'oldid='.$rev->getId() . $tokenParams );
615 $difflink = '(' . $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml('diff'),
616 'diff=' . $rev->getId() . '&oldid=prev' . $tokenParams ) . ')';
617 // Archived revisions
619 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
620 $target = $this->page
->getPrefixedText();
621 $revlink = $this->skin
->makeLinkObj( $undelete, $date,
622 "target=$target×tamp=" . $rev->getTimestamp() );
623 $difflink = '(' . $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml('diff'),
624 "target=$target&diff=prev×tamp=" . $rev->getTimestamp() ) . ')';
626 // Check permissions; items may be "suppressed"
627 if( $rev->isDeleted(Revision
::DELETED_TEXT
) ) {
628 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
629 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
630 if( !$rev->userCan(Revision
::DELETED_TEXT
) ) {
631 $revlink = '<span class="history-deleted">'.$date.'</span>';
632 $difflink = '(' . wfMsgHtml('diff') . ')';
635 $userlink = $this->skin
->revUserLink( $rev );
636 $comment = $this->skin
->revComment( $rev );
638 return "<li>$difflink $revlink $userlink $comment{$del}</li>";
645 private function fileLine( $file ) {
648 $target = $this->page
->getPrefixedText();
649 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
653 if( $file->isDeleted(File
::DELETED_FILE
) ) {
654 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
655 if( !$file->userCan(File
::DELETED_FILE
) ) {
658 $pageLink = $this->skin
->makeKnownLinkObj( $this->getTitle(), $date,
659 "target=$target&file=$file->sha1.".$file->getExtension() );
661 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
664 $url = $file->getUrlRel();
665 $pageLink = "<a href=\"{$url}\">{$date}</a>";
668 $data = wfMsg( 'widthheight', $wgLang->formatNum( $file->getWidth() ),
669 $wgLang->formatNum( $file->getHeight() ) ) .
670 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
671 $data = htmlspecialchars( $data );
673 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".
674 $this->fileComment( $file )."$del</li>";
678 * @param ArchivedFile $file
681 private function archivedfileLine( $file ) {
684 $target = $this->page
->getPrefixedText();
685 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
687 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
688 $pageLink = $this->skin
->makeKnownLinkObj( $undelete, $date,
689 "target=$target&file={$file->getKey()}" );
692 if( $file->isDeleted(File
::DELETED_FILE
) ) {
693 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
696 $data = wfMsg( 'widthheight', $wgLang->formatNum( $file->getWidth() ),
697 $wgLang->formatNum( $file->getHeight() ) ) .
698 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
699 $data = htmlspecialchars( $data );
701 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".
702 $this->fileComment( $file )."$del</li>";
706 * @param Array $row row
709 private function logLine( $row ) {
712 $date = $wgLang->timeanddate( $row->log_timestamp
);
713 $paramArray = LogPage
::extractParams( $row->log_params
);
714 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
716 $logtitle = SpecialPage
::getTitleFor( 'Log' );
717 $loglink = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
718 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
720 if( !LogEventsList
::userCan($row,LogPage
::DELETED_ACTION
) ) {
721 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
723 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
724 $this->skin
, $paramArray, true, true );
725 if( $row->log_deleted
& LogPage
::DELETED_ACTION
)
726 $action = '<span class="history-deleted">' . $action . '</span>';
729 $userLink = $this->skin
->userLink( $row->log_user
, User
::WhoIs($row->log_user
) );
730 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_USER
) ) {
731 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
734 $comment = $wgLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
735 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
736 $comment = '<span class="history-deleted">' . $comment . '</span>';
738 return "<li>($loglink) $date $userLink $action $comment</li>";
742 * Generate a user tool link cluster if the current user is allowed to view it
743 * @param ArchivedFile $file
744 * @return string HTML
746 private function fileUserTools( $file ) {
747 if( $file->userCan( Revision
::DELETED_USER
) ) {
748 $link = $this->skin
->userLink( $file->user
, $file->user_text
) .
749 $this->skin
->userToolLinks( $file->user
, $file->user_text
);
751 $link = wfMsgHtml( 'rev-deleted-user' );
753 if( $file->isDeleted( Revision
::DELETED_USER
) ) {
754 return '<span class="history-deleted">' . $link . '</span>';
760 * Wrap and format the given file's comment block, if the current
761 * user is allowed to view it.
763 * @param ArchivedFile $file
764 * @return string HTML
766 private function fileComment( $file ) {
767 if( $file->userCan( File
::DELETED_COMMENT
) ) {
768 $block = $this->skin
->commentBlock( $file->description
);
770 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
772 if( $file->isDeleted( File
::DELETED_COMMENT
) ) {
773 return "<span class=\"history-deleted\">$block</span>";
779 * @param WebRequest $request
781 private function submit( $request ) {
782 global $wgUser, $wgOut;
783 # Check edit token on submission
784 if( $this->wasPosted
&& !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
785 $wgOut->addWikiMsg( 'sessionfailure' );
788 $bitfield = $this->extractBitfield( $request );
789 $comment = $request->getText( 'wpReason' );
790 # Can the user set this field?
791 if( $bitfield & Revision
::DELETED_RESTRICTED
&& !$wgUser->isAllowed('suppressrevision') ) {
792 $wgOut->permissionRequired( 'suppressrevision' );
795 # If the save went through, go to success message...
796 if( $this->save( $bitfield, $comment, $this->page
) ) {
799 # ...otherwise, bounce back to form...
806 private function success() {
808 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
809 $wrap = '<span class="success">$1</span>';
810 if( $this->deleteKey
== 'logid' ) {
811 $wgOut->wrapWikiMsg( $wrap, 'logdelete-success' );
812 $this->showLogItems();
813 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
814 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
816 } else if( $this->deleteKey
== 'fileid' ) {
817 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
819 } else if( $this->deleteKey
== 'oldimage' ) {
820 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
825 private function failure() {
827 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
828 $wrap = '<span class="error">$1</span>';
829 if( $this->deleteKey
== 'logid' ) {
830 $this->showLogItems();
831 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
832 $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
834 } else if( $this->deleteKey
== 'fileid' ) {
835 $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
837 } else if( $this->deleteKey
== 'oldimage' ) {
838 $wgOut->wrapWikiMsg( $wrap, 'revdelete-failure' );
844 * Put together a rev_deleted bitfield from the submitted checkboxes
845 * @param WebRequest $request
848 private function extractBitfield( $request ) {
850 foreach( $this->checks
as $item ) {
851 list( /* message */ , $name, $field ) = $item;
852 if( $request->getCheck( $name ) ) {
859 private function save( $bitfield, $reason, $title ) {
860 $dbw = wfGetDB( DB_MASTER
);
861 // Don't allow simply locking the interface for no reason
862 if( $bitfield == Revision
::DELETED_RESTRICTED
) {
865 $deleter = new RevisionDeleter( $dbw );
866 // By this point, only one of the below should be set
867 if( isset($this->revisions
) ) {
868 return $deleter->setRevVisibility( $title, $this->revisions
, $bitfield, $reason );
869 } else if( isset($this->archrevs
) ) {
870 return $deleter->setArchiveVisibility( $title, $this->archrevs
, $bitfield, $reason );
871 } else if( isset($this->ofiles
) ) {
872 return $deleter->setOldImgVisibility( $title, $this->ofiles
, $bitfield, $reason );
873 } else if( isset($this->afiles
) ) {
874 return $deleter->setArchFileVisibility( $title, $this->afiles
, $bitfield, $reason );
875 } else if( isset($this->events
) ) {
876 return $deleter->setEventVisibility( $title, $this->events
, $bitfield, $reason );
883 * Implements the actions for Revision Deletion.
884 * @ingroup SpecialPage
886 class RevisionDeleter
{
887 function __construct( $db ) {
892 * @param $title, the page these events apply to
893 * @param array $items list of revision ID numbers
894 * @param int $bitfield new rev_deleted value
895 * @param string $comment Comment for log records
897 function setRevVisibility( $title, $items, $bitfield, $comment ) {
900 $userAllowedAll = $success = true;
903 // Run through and pull all our data in one query
904 foreach( $items as $revid ) {
905 $where[] = intval($revid);
907 $result = $this->dbw
->select( array('revision','page'), '*',
908 array( 'rev_page' => $title->getArticleID(),
909 'rev_id' => $where, 'rev_page = page_id' ),
912 while( $row = $this->dbw
->fetchObject( $result ) ) {
913 $revObjs[$row->rev_id
] = new Revision( $row );
916 foreach( $items as $revid ) {
917 if( !isset($revObjs[$revid]) ) {
919 continue; // Must exist
920 } else if( $revObjs[$revid]->isCurrent() && ($bitfield & Revision
::DELETED_TEXT
) ) {
922 continue; // Cannot hide current version text
923 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
924 $userAllowedAll = false;
927 // For logging, maintain a count of revisions
928 if( $revObjs[$revid]->mDeleted
!= $bitfield ) {
930 $this->updateRevision( $revObjs[$revid], $bitfield );
931 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
936 // Don't log or touch if nothing changed
937 if( $revCount > 0 ) {
938 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted
,
939 $comment, $title, 'oldid', $revIDs );
940 $this->updatePage( $title );
942 // Where all revs allowed to be set?
943 if( !$userAllowedAll ) {
944 //FIXME: still might be confusing???
945 $wgOut->permissionRequired( 'suppressrevision' );
953 * @param $title, the page these events apply to
954 * @param array $items list of revision ID numbers
955 * @param int $bitfield new rev_deleted value
956 * @param string $comment Comment for log records
958 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
961 $userAllowedAll = $success = true;
964 // Run through and pull all our data in one query
965 foreach( $items as $timestamp ) {
966 $where[] = $this->dbw
->timestamp( $timestamp );
968 $result = $this->dbw
->select( 'archive', '*',
970 'ar_namespace' => $title->getNamespace(),
971 'ar_title' => $title->getDBKey(),
972 'ar_timestamp' => $where
975 while( $row = $this->dbw
->fetchObject( $result ) ) {
976 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
977 $revObjs[$timestamp] = new Revision( array(
978 'page' => $title->getArticleId(),
979 'id' => $row->ar_rev_id
,
980 'text' => $row->ar_text_id
,
981 'comment' => $row->ar_comment
,
982 'user' => $row->ar_user
,
983 'user_text' => $row->ar_user_text
,
984 'timestamp' => $timestamp,
985 'minor_edit' => $row->ar_minor_edit
,
986 'text_id' => $row->ar_text_id
,
987 'deleted' => $row->ar_deleted
,
988 'len' => $row->ar_len
) );
991 foreach( $items as $timestamp ) {
992 // This will only select the first revision with this timestamp.
993 // Since they are all selected/deleted at once, we can just check the
994 // permissions of one. UPDATE is done via timestamp, so all revs are set.
995 if( !is_object($revObjs[$timestamp]) ) {
997 continue; // Must exist
998 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
999 $userAllowedAll=false;
1002 // Which revisions did we change anything about?
1003 if( $revObjs[$timestamp]->mDeleted
!= $bitfield ) {
1004 $Id_set[] = $timestamp;
1005 $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
1009 // For logging, maintain a count of revisions
1011 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted
,
1012 $comment, $title, 'artimestamp', $Id_set );
1014 // Where all revs allowed to be set?
1015 if( !$userAllowedAll ) {
1016 $wgOut->permissionRequired( 'suppressrevision' );
1024 * @param $title, the page these events apply to
1025 * @param array $items list of revision ID numbers
1026 * @param int $bitfield new rev_deleted value
1027 * @param string $comment Comment for log records
1029 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
1032 $userAllowedAll = $success = true;
1035 // Run through and pull all our data in one query
1036 foreach( $items as $timestamp ) {
1037 $where[] = $timestamp.'!'.$title->getDBKey();
1039 $result = $this->dbw
->select( 'oldimage', '*',
1040 array( 'oi_name' => $title->getDBKey(), 'oi_archive_name' => $where ),
1043 while( $row = $this->dbw
->fetchObject( $result ) ) {
1044 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
1045 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
1046 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
1049 foreach( $items as $timestamp ) {
1050 $archivename = $timestamp.'!'.$title->getDBKey();
1051 if( !isset($filesObjs[$archivename]) ) {
1053 continue; // Must exist
1054 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
1055 $userAllowedAll=false;
1059 $transaction = true;
1060 // Which revisions did we change anything about?
1061 if( $filesObjs[$archivename]->deleted
!= $bitfield ) {
1064 $this->dbw
->begin();
1065 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
1066 // If this image is currently hidden...
1067 if( $filesObjs[$archivename]->deleted
& File
::DELETED_FILE
) {
1068 if( $bitfield & File
::DELETED_FILE
) {
1069 # Leave it alone if we are not changing this...
1071 $transaction = true;
1073 # We are moving this out
1074 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
1075 $set[]=$transaction;
1077 // Is it just now becoming hidden?
1078 } else if( $bitfield & File
::DELETED_FILE
) {
1079 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
1080 $set[]=$transaction;
1084 // If our file operations fail, then revert back the db
1085 if( $transaction==false ) {
1086 $this->dbw
->rollback();
1089 $this->dbw
->commit();
1093 // Log if something was changed
1095 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted
,
1096 $comment, $title, 'oldimage', $set );
1097 # Purge page/history
1098 $file = wfLocalFile( $title );
1099 $file->purgeCache();
1100 $file->purgeHistory();
1101 # Invalidate cache for all pages using this file
1102 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
1103 $update->doUpdate();
1105 // Where all revs allowed to be set?
1106 if( !$userAllowedAll ) {
1107 $wgOut->permissionRequired( 'suppressrevision' );
1115 * @param $title, the page these events apply to
1116 * @param array $items list of revision ID numbers
1117 * @param int $bitfield new rev_deleted value
1118 * @param string $comment Comment for log records
1120 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
1123 $userAllowedAll = $success = true;
1127 // Run through and pull all our data in one query
1128 foreach( $items as $id ) {
1129 $where[] = intval($id);
1131 $result = $this->dbw
->select( 'filearchive', '*',
1132 array( 'fa_name' => $title->getDBKey(),
1133 'fa_id' => $where ),
1135 while( $row = $this->dbw
->fetchObject( $result ) ) {
1136 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
1139 foreach( $items as $fileid ) {
1140 if( !isset($filesObjs[$fileid]) ) {
1142 continue; // Must exist
1143 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
1144 $userAllowedAll=false;
1147 // Which revisions did we change anything about?
1148 if( $filesObjs[$fileid]->deleted
!= $bitfield ) {
1152 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1155 // Log if something was changed
1157 $this->updateLog( $title, $count, $bitfield, $comment,
1158 $filesObjs[$fileid]->deleted
, $title, 'fileid', $Id_set );
1160 // Where all revs allowed to be set?
1161 if( !$userAllowedAll ) {
1162 $wgOut->permissionRequired( 'suppressrevision' );
1170 * @param $title, the log page these events apply to
1171 * @param array $items list of log ID numbers
1172 * @param int $bitfield new log_deleted value
1173 * @param string $comment Comment for log records
1175 function setEventVisibility( $title, $items, $bitfield, $comment ) {
1178 $userAllowedAll = $success = true;
1182 // Run through and pull all our data in one query
1183 foreach( $items as $logid ) {
1184 $where[] = intval($logid);
1186 list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
1187 $result = $this->dbw
->select( 'logging', '*',
1188 array( 'log_type' => $logtype, 'log_id' => $where ),
1191 while( $row = $this->dbw
->fetchObject( $result ) ) {
1192 $logRows[$row->log_id
] = $row;
1195 foreach( $items as $logid ) {
1196 if( !isset($logRows[$logid]) ) {
1198 continue; // Must exist
1199 } else if( !LogEventsList
::userCan($logRows[$logid], LogPage
::DELETED_RESTRICTED
)
1200 ||
$logRows[$logid]->log_type
== 'suppress' )
1202 $userAllowedAll=false; // Don't hide from oversight log!!!
1205 // Which logs did we change anything about?
1206 if( $logRows[$logid]->log_deleted
!= $bitfield ) {
1207 $log_Ids[] = $logid;
1208 $this->updateLogs( $logRows[$logid], $bitfield );
1209 $this->updateRecentChangesLog( $logRows[$logid], $bitfield );
1213 // Don't log or touch if nothing changed
1215 $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted
,
1216 $comment, $title, 'logid', $log_Ids );
1218 // Were all revs allowed to be set?
1219 if( !$userAllowedAll ) {
1220 $wgOut->permissionRequired( 'suppressrevision' );
1228 * Moves an image to a safe private location
1229 * Caller is responsible for clearing caches
1230 * @param File $oimage
1231 * @returns mixed, timestamp string on success, false on failure
1233 function makeOldImagePrivate( $oimage ) {
1234 $transaction = new FSTransaction();
1235 if( !FileStore
::lock() ) {
1236 wfDebug( __METHOD__
.": failed to acquire file store lock, aborting\n" );
1239 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1240 // Dupe the file into the file store
1241 if( file_exists( $oldpath ) ) {
1242 // Is our directory configured?
1243 if( $store = FileStore
::get( 'deleted' ) ) {
1244 if( !$oimage->sha1
) {
1245 $oimage->upgradeRow(); // sha1 may be missing
1247 $key = $oimage->sha1
. '.' . $oimage->getExtension();
1248 $transaction->add( $store->insert( $key, $oldpath, FileStore
::DELETE_ORIGINAL
) );
1252 $transaction = false; // Return an error and do nothing
1255 wfDebug( __METHOD__
." deleting already-missing '$oldpath'; moving on to database\n" );
1258 $transaction = new FSTransaction(); // empty
1261 if( $transaction === false ) {
1263 wfDebug( __METHOD__
.": import to file store failed, aborting\n" );
1264 throw new MWException( "Could not archive and delete file $oldpath" );
1268 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1269 $transaction->commit();
1270 FileStore
::unlock();
1272 $m = explode('!',$oimage->archive_name
,2);
1279 * Moves an image from a safe private location
1280 * Caller is responsible for clearing caches
1281 * @param File $oimage
1282 * @returns mixed, string timestamp on success, false on failure
1284 function makeOldImagePublic( $oimage ) {
1285 $transaction = new FSTransaction();
1286 if( !FileStore
::lock() ) {
1287 wfDebug( __METHOD__
." could not acquire filestore lock\n" );
1291 $store = FileStore
::get( 'deleted' );
1293 wfDebug( __METHOD__
.": skipping row with no file.\n" );
1297 $key = $oimage->sha1
.'.'.$oimage->getExtension();
1298 $destDir = $oimage->getArchivePath();
1299 if( !is_dir( $destDir ) ) {
1300 wfMkdirParents( $destDir );
1302 $destPath = $destDir . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1303 // Check if any other stored revisions use this file;
1304 // if so, we shouldn't remove the file from the hidden
1305 // archives so they will still work. Check hidden files first.
1306 $useCount = $this->dbw
->selectField( 'oldimage', '1',
1307 array( 'oi_sha1' => $oimage->sha1
,
1308 'oi_deleted & '.File
::DELETED_FILE
=> File
::DELETED_FILE
),
1309 __METHOD__
, array( 'FOR UPDATE' ) );
1310 // Check the rest of the deleted archives too.
1311 // (these are the ones that don't show in the image history)
1313 $useCount = $this->dbw
->selectField( 'filearchive', '1',
1314 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1315 __METHOD__
, array( 'FOR UPDATE' ) );
1318 if( $useCount == 0 ) {
1319 wfDebug( __METHOD__
.": nothing else using {$oimage->sha1}, will deleting after\n" );
1320 $flags = FileStore
::DELETE_ORIGINAL
;
1324 $transaction->add( $store->export( $key, $destPath, $flags ) );
1326 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1327 $transaction->commit();
1328 FileStore
::unlock();
1330 $m = explode('!',$oimage->archive_name
,2);
1337 * Update the revision's rev_deleted field
1338 * @param Revision $rev
1339 * @param int $bitfield new rev_deleted bitfield value
1341 function updateRevision( $rev, $bitfield ) {
1342 $this->dbw
->update( 'revision',
1343 array( 'rev_deleted' => $bitfield ),
1344 array( 'rev_id' => $rev->getId(), 'rev_page' => $rev->getPage() ),
1350 * Update the revision's rev_deleted field
1351 * @param Revision $rev
1352 * @param Title $title
1353 * @param int $bitfield new rev_deleted bitfield value
1355 function updateArchive( $rev, $title, $bitfield ) {
1356 $this->dbw
->update( 'archive',
1357 array( 'ar_deleted' => $bitfield ),
1358 array( 'ar_namespace' => $title->getNamespace(),
1359 'ar_title' => $title->getDBKey(),
1360 // use timestamp for index
1361 'ar_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ),
1362 'ar_rev_id' => $rev->getId()
1368 * Update the images's oi_deleted field
1370 * @param int $bitfield new rev_deleted bitfield value
1372 function updateOldFiles( $file, $bitfield ) {
1373 $this->dbw
->update( 'oldimage',
1374 array( 'oi_deleted' => $bitfield ),
1375 array( 'oi_name' => $file->getName(),
1376 'oi_timestamp' => $this->dbw
->timestamp( $file->getTimestamp() ) ),
1382 * Update the images's fa_deleted field
1383 * @param ArchivedFile $file
1384 * @param int $bitfield new rev_deleted bitfield value
1386 function updateArchFiles( $file, $bitfield ) {
1387 $this->dbw
->update( 'filearchive',
1388 array( 'fa_deleted' => $bitfield ),
1389 array( 'fa_id' => $file->getId() ),
1395 * Update the logging log_deleted field
1397 * @param int $bitfield new rev_deleted bitfield value
1399 function updateLogs( $row, $bitfield ) {
1400 $this->dbw
->update( 'logging',
1401 array( 'log_deleted' => $bitfield ),
1402 array( 'log_id' => $row->log_id
),
1408 * Update the revision's recentchanges record if fields have been hidden
1409 * @param Revision $rev
1410 * @param int $bitfield new rev_deleted bitfield value
1412 function updateRecentChangesEdits( $rev, $bitfield ) {
1413 $this->dbw
->update( 'recentchanges',
1414 array( 'rc_deleted' => $bitfield,
1415 'rc_patrolled' => 1 ),
1416 array( 'rc_this_oldid' => $rev->getId(),
1417 'rc_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ) ),
1423 * Update the revision's recentchanges record if fields have been hidden
1425 * @param int $bitfield new rev_deleted bitfield value
1427 function updateRecentChangesLog( $row, $bitfield ) {
1428 $this->dbw
->update( 'recentchanges',
1429 array( 'rc_deleted' => $bitfield,
1430 'rc_patrolled' => 1 ),
1431 array( 'rc_logid' => $row->log_id
,
1432 'rc_timestamp' => $row->log_timestamp
),
1438 * Touch the page's cache invalidation timestamp; this forces cached
1439 * history views to refresh, so any newly hidden or shown fields will
1441 * @param Title $title
1443 function updatePage( $title ) {
1444 $title->invalidateCache();
1445 $this->dbw
->commit(); // Commit the transaction before the purge is sent
1446 $title->purgeSquid();
1447 $title->touchLinks();
1448 // Extensions that require referencing previous revisions may need this
1449 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1453 * Checks for a change in the bitfield for a certain option and updates the
1454 * provided array accordingly.
1456 * @param String $desc Description to add to the array if the option was
1457 * enabled / disabled.
1458 * @param int $field The bitmask describing the single option.
1459 * @param int $diff The xor of the old and new bitfields.
1460 * @param array $arr The array to update.
1462 protected static function checkItem( $desc, $field, $diff, $new, &$arr ) {
1463 if( $diff & $field ) {
1464 $arr[ ( $new & $field ) ?
0 : 1 ][] = $desc;
1469 * Gets an array describing the changes made to the visibilit of the revision.
1470 * If the resulting array is $arr, then $arr[0] will contain an array of strings
1471 * describing the items that were hidden, $arr[2] will contain an array of strings
1472 * describing the items that were unhidden, and $arr[3] will contain an array with
1473 * a single string, which can be one of "applied restrictions to sysops",
1474 * "removed restrictions from sysops", or null.
1476 * @param int $n The new bitfield.
1477 * @param int $o The old bitfield.
1478 * @return An array as described above.
1480 protected static function getChanges( $n, $o ) {
1482 $ret = array( 0 => array(), 1 => array(), 2 => array() );
1483 // Build bitfield changes in language
1484 self
::checkItem( wfMsgForContent( 'revdelete-content' ),
1485 Revision
::DELETED_TEXT
, $diff, $n, $ret );
1486 self
::checkItem( wfMsgForContent( 'revdelete-summary' ),
1487 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
1488 self
::checkItem( wfMsgForContent( 'revdelete-uname' ),
1489 Revision
::DELETED_USER
, $diff, $n, $ret );
1490 // Restriction application to sysops
1491 if( $diff & Revision
::DELETED_RESTRICTED
) {
1492 if( $n & Revision
::DELETED_RESTRICTED
)
1493 $ret[2][] = wfMsgForContent( 'revdelete-restricted' );
1495 $ret[2][] = wfMsgForContent( 'revdelete-unrestricted' );
1501 * Gets a log message to describe the given revision visibility change. This
1502 * message will be of the form "[hid {content, edit summary, username}];
1503 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
1505 * @param int $count The number of effected revisions.
1506 * @param int $nbitfield The new bitfield for the revision.
1507 * @param int $obitfield The old bitfield for the revision.
1508 * @param bool $isForLog
1510 public static function getLogMessage( $count, $nbitfield, $obitfield, $isForLog = false ) {
1513 $changes = self
::getChanges( $nbitfield, $obitfield );
1514 if( count( $changes[0] ) ) {
1515 $s .= wfMsgForContent( 'revdelete-hid', implode( ', ', $changes[0] ) );
1517 if( count( $changes[1] ) ) {
1519 $s .= wfMsgForContent( 'revdelete-unhid', implode( ', ', $changes[1] ) );
1521 if( count( $changes[2] ) ) {
1522 $s .= $s ?
' (' . $changes[2][0] . ')' : $changes[2][0];
1524 $msg = $isForLog ?
'logdelete-log-message' : 'revdelete-log-message';
1525 return wfMsgExt( $msg, array( 'parsemag', 'content' ), $s, $wgLang->formatNum($count) );
1530 * Record a log entry on the action
1531 * @param Title $title, page where item was removed from
1532 * @param int $count the number of revisions altered for this page
1533 * @param int $nbitfield the new _deleted value
1534 * @param int $obitfield the old _deleted value
1535 * @param string $comment
1536 * @param Title $target, the relevant page
1537 * @param string $param, URL param
1538 * @param Array $items
1540 function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target,
1541 $param, $items = array() )
1543 // Put things hidden from sysops in the oversight log
1544 $logtype = ( ($nbitfield |
$obitfield) & Revision
::DELETED_RESTRICTED
) ?
1545 'suppress' : 'delete';
1546 $log = new LogPage( $logtype );
1547 $itemCSV = implode(',',$items);
1549 if( $param == 'logid' ) {
1550 $params = array( $itemCSV, "ofield={$obitfield}", "nfield={$nbitfield}" );
1551 $log->addEntry( 'event', $title, $comment, $params );
1553 // Add params for effected page and ids
1554 $params = array( $param, $itemCSV, "ofield={$obitfield}", "nfield={$nbitfield}" );
1555 $log->addEntry( 'revision', $title, $comment, $params );