3 * Special page allowing users with the appropriate permissions to view
4 * and hide revisions. Log items can also be hidden.
10 class SpecialRevisionDelete
extends UnlistedSpecialPage
{
12 public function __construct() {
13 parent
::__construct( 'Revisiondelete', 'deleterevision' );
14 $this->includable( false );
17 public function execute( $par ) {
18 global $wgOut, $wgUser, $wgRequest;
20 $wgOut->readOnlyPage();
23 if( !$wgUser->isAllowed( 'deleterevision' ) ) {
24 $wgOut->permissionRequired( 'deleterevision' );
27 $this->skin
=& $wgUser->getSkin();
29 $this->outputHeader();
30 $this->wasPosted
= $wgRequest->wasPosted();
32 $this->target
= $wgRequest->getText( 'target' );
33 # Handle our many different possible input types.
34 # Use CVS, since the cgi handling will break on arrays.
35 $this->oldids
= array_filter( explode( ',', $wgRequest->getVal('oldid') ) );
36 $this->artimestamps
= array_filter( explode( ',', $wgRequest->getVal('artimestamp') ) );
37 $this->logids
= array_filter( explode( ',', $wgRequest->getVal('logid') ) );
38 $this->oldimgs
= array_filter( explode( ',', $wgRequest->getVal('oldimage') ) );
39 $this->fileids
= array_filter( explode( ',', $wgRequest->getVal('fileid') ) );
40 # For reviewing deleted files...
41 $this->file
= $wgRequest->getVal( 'file' );
42 # Only one target set at a time please!
43 $i = (bool)$this->file +
(bool)$this->oldids +
(bool)$this->logids
44 +
(bool)$this->artimestamps +
(bool)$this->fileids +
(bool)$this->oldimgs
;
47 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
52 $wgOut->showErrorPage( 'revdelete-toomanytargets-title', 'revdelete-toomanytargets-text' );
55 $this->page
= Title
::newFromUrl( $this->target
);
56 # If we have revisions, get the title from the first one
57 # since they should all be from the same page. This allows
58 # for more flexibility with page moves...
59 if( count($this->oldids
) > 0 ) {
60 $rev = Revision
::newFromId( $this->oldids
[0] );
61 $this->page
= $rev ?
$rev->getTitle() : $this->page
;
63 # We need a target page!
64 if( is_null($this->page
) ) {
65 $wgOut->addWikiMsg( 'undelete-header' );
68 # Logs must have a type given
69 if( $this->logids
&& !strpos($this->page
->getDBKey(),'/') ) {
70 $wgOut->showErrorPage( 'revdelete-nologtype-title', 'revdelete-nologtype-text' );
73 # For reviewing deleted files...show it now if allowed
75 $oimage = RepoGroup
::singleton()->getLocalRepo()->newFromArchiveName( $this->page
, $this->file
);
77 // Check if user is allowed to see this file
78 if( !$oimage->userCan(File
::DELETED_FILE
) ) {
79 $wgOut->permissionRequired( 'suppressrevision' );
81 $this->showFile( $this->file
);
85 # Give a link to the logs/hist for this page
86 if( !is_null($this->page
) && $this->page
->getNamespace() > -1 ) {
89 $logtitle = SpecialPage
::getTitleFor( 'Log' );
90 $links[] = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
91 wfArrayToCGI( array( 'page' => $this->page
->getPrefixedUrl() ) ) );
92 # Give a link to the page history
93 $links[] = $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml( 'pagehist' ),
94 wfArrayToCGI( array( 'action' => 'history' ) ) );
95 # Link to deleted edits
96 if( $wgUser->isAllowed('undelete') ) {
97 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
98 $links[] = $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
99 wfArrayToCGI( array( 'target' => $this->page
->getPrefixedDBkey() ) ) );
101 # Logs themselves don't have histories or archived revisions
102 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
104 # Lock the operation and the form context
105 $this->secureOperation();
106 # Either submit or create our form
107 if( $this->wasPosted
) {
108 $this->submit( $wgRequest );
109 } else if( $this->deleteKey
== 'oldid' ||
$this->deleteKey
== 'artimestamp' ) {
111 } else if( $this->deleteKey
== 'fileid' ||
$this->deleteKey
== 'oldimage' ) {
113 } else if( $this->deleteKey
== 'logid' ) {
114 $this->showLogItems();
116 $qc = $this->getLogQueryCond();
117 # Show relevant lines from the deletion log
118 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'delete' ) ) . "</h2>\n" );
119 LogEventsList
::showLogExtract( $wgOut, 'delete', $this->page
->getPrefixedText(), '', 25, $qc );
120 # Show relevant lines from the suppression log
121 if( $wgUser->isAllowed( 'suppressionlog' ) ) {
122 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'suppress' ) ) . "</h2>\n" );
123 LogEventsList
::showLogExtract( $wgOut, 'suppress', $this->page
->getPrefixedText(), '', 25, $qc );
127 private function getLogQueryCond() {
128 $ids = $safeIds = array();
129 switch( $this->deleteKey
) {
131 $ids = $this->oldids
;
134 $ids = $this->artimestamps
;
137 $ids = $this->oldimgs
;
140 $ids = $this->fileids
;
143 $ids = $this->logids
;
147 foreach( $ids as $id ) {
148 if( preg_match( '/^\d+$/', $id, $m ) ) {
152 if( count($safeIds) ) {
153 return array("log_params RLIKE '".implode('|',$safeIds)."'");
158 private function secureOperation() {
160 $this->deleteKey
= '';
161 // At this point, we should only have one of these
162 if( $this->oldids
) {
163 $this->revisions
= $this->oldids
;
164 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
165 $this->deleteKey
= 'oldid';
166 } else if( $this->artimestamps
) {
167 $this->archrevs
= $this->artimestamps
;
168 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
169 $this->deleteKey
= 'artimestamp';
170 } else if( $this->oldimgs
) {
171 $this->ofiles
= $this->oldimgs
;
172 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
173 $this->deleteKey
= 'oldimage';
174 } else if( $this->fileids
) {
175 $this->afiles
= $this->fileids
;
176 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
177 $this->deleteKey
= 'fileid';
178 } else if( $this->logids
) {
179 $this->events
= $this->logids
;
180 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage
::DELETED_ACTION
);
181 $this->deleteKey
= 'logid';
183 // Our checkbox messages depends one what we are doing,
184 // e.g. we don't hide "text" for logs or images
185 $this->checks
= array(
187 array( 'revdelete-hide-comment', 'wpHideComment', Revision
::DELETED_COMMENT
),
188 array( 'revdelete-hide-user', 'wpHideUser', Revision
::DELETED_USER
)
190 if( $wgUser->isAllowed('suppressrevision') ) {
191 $this->checks
[] = array( 'revdelete-hide-restricted',
192 'wpHideRestricted', Revision
::DELETED_RESTRICTED
);
197 * Show a deleted file version requested by the visitor.
199 private function showFile( $key ) {
200 global $wgOut, $wgRequest;
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' );
211 $store = FileStore
::get( 'deleted' );
212 $store->stream( $key );
216 * This lets a user set restrictions for live and archived revisions
218 private function showRevs() {
219 global $wgOut, $wgUser;
222 $count = ($this->deleteKey
=='oldid') ?
223 count($this->revisions
) : count($this->archrevs
);
224 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(), $count );
227 $wgOut->addHTML( "<ul>" );
229 $where = $revObjs = array();
230 $dbr = wfGetDB( DB_MASTER
);
234 if( $this->deleteKey
=='oldid' ) {
235 // Run through and pull all our data in one query
236 foreach( $this->revisions
as $revid ) {
237 $where[] = intval($revid);
239 $result = $dbr->select( array('revision','page'), '*',
241 'rev_page' => $this->page
->getArticleID(),
243 'rev_page = page_id' ),
245 while( $row = $dbr->fetchObject( $result ) ) {
246 $revObjs[$row->rev_id
] = new Revision( $row );
248 foreach( $this->revisions
as $revid ) {
249 // Hiding top revisison is bad
250 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
252 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
253 // If a rev is hidden from sysops
254 if( !$this->wasPosted
) {
255 $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 ),
276 while( $row = $dbr->fetchObject( $result ) ) {
277 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
278 $revObjs[$timestamp] = new Revision( array(
279 'page' => $this->page
->getArticleId(),
280 'id' => $row->ar_rev_id
,
281 'text' => $row->ar_text_id
,
282 'comment' => $row->ar_comment
,
283 'user' => $row->ar_user
,
284 'user_text' => $row->ar_user_text
,
285 'timestamp' => $timestamp,
286 'minor_edit' => $row->ar_minor_edit
,
287 'text_id' => $row->ar_text_id
,
288 'deleted' => $row->ar_deleted
,
289 'len' => $row->ar_len
) );
291 foreach( $this->archrevs
as $timestamp ) {
292 if( !isset($revObjs[$timestamp]) ) {
294 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
295 // If a rev is hidden from sysops
296 if( !$this->wasPosted
) {
297 $wgOut->permissionRequired( 'suppressrevision' );
300 $UserAllowed = false;
303 $wgOut->addHTML( $this->historyLine( $revObjs[$timestamp] ) );
304 $bitfields |
= $revObjs[$timestamp]->mDeleted
;
308 $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
) );
333 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
335 Xml
::openElement( 'form', array( 'method' => 'post',
336 'action' => $special->getLocalUrl( 'action=submit' ),
337 'id' => 'mw-revdel-form-revisions' ) ) .
338 Xml
::openElement( 'fieldset' ) .
339 xml
::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
342 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
343 foreach( $items as $item ) {
344 $wgOut->addHTML( Xml
::tags( 'p', null, $item ) );
346 foreach( $hidden as $item ) {
347 $wgOut->addHTML( $item );
350 Xml
::closeElement( 'fieldset' ) .
351 Xml
::closeElement( 'form' ) . "\n"
356 * This lets a user set restrictions for archived images
358 private function showImages() {
359 global $wgOut, $wgUser, $wgLang;
362 $count = ($this->deleteKey
=='oldimage') ?
count($this->ofiles
) : count($this->afiles
);
363 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(),
364 $wgLang->formatNum($count) );
367 $wgOut->addHTML( "<ul>" );
369 $where = $filesObjs = array();
370 $dbr = wfGetDB( DB_MASTER
);
371 // Live old revisions...
373 if( $this->deleteKey
=='oldimage' ) {
374 // Run through and pull all our data in one query
375 foreach( $this->ofiles
as $timestamp ) {
376 $where[] = $timestamp.'!'.$this->page
->getDBKey();
378 $result = $dbr->select( 'oldimage', '*',
380 'oi_name' => $this->page
->getDBKey(),
381 'oi_archive_name' => $where ),
383 while( $row = $dbr->fetchObject( $result ) ) {
384 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
385 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
386 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
388 // Check through our images
389 foreach( $this->ofiles
as $timestamp ) {
390 $archivename = $timestamp.'!'.$this->page
->getDBKey();
391 if( !isset($filesObjs[$archivename]) ) {
393 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
394 // If a rev is hidden from sysops
395 if( !$this->wasPosted
) {
396 $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(),
417 while( $row = $dbr->fetchObject( $result ) ) {
418 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
421 foreach( $this->afiles
as $fileid ) {
422 if( !isset($filesObjs[$fileid]) ) {
424 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
425 // If a rev is hidden from sysops
426 if( !$this->wasPosted
) {
427 $wgOut->permissionRequired( 'suppressrevision' );
430 $UserAllowed = false;
433 // Inject history info
434 $wgOut->addHTML( $this->archivedfileLine( $filesObjs[$fileid] ) );
435 $bitfields |
= $filesObjs[$fileid]->deleted
;
439 $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
) );
463 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
465 Xml
::openElement( 'form', array( 'method' => 'post',
466 'action' => $special->getLocalUrl( 'action=submit' ),
467 'id' => 'mw-revdel-form-filerevisions' )
469 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
472 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
473 foreach( $items as $item ) {
474 $wgOut->addHTML( "<p>$item</p>" );
476 foreach( $hidden as $item ) {
477 $wgOut->addHTML( $item );
481 Xml
::closeElement( 'fieldset' ) .
482 Xml
::closeElement( 'form' ) . "\n"
487 * This lets a user set restrictions for log items
489 private function showLogItems() {
490 global $wgOut, $wgUser, $wgMessageCache, $wgLang;
493 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->events
) ) );
496 $wgOut->addHTML( "<ul>" );
498 $where = $logRows = array();
499 $dbr = wfGetDB( DB_MASTER
);
500 // Run through and pull all our data in one query
502 foreach( $this->events
as $logid ) {
503 $where[] = intval($logid);
505 list($log,$logtype) = explode( '/',$this->page
->getDBKey(), 2 );
506 $result = $dbr->select( 'logging', '*',
508 'log_type' => $logtype,
509 'log_id' => $where ),
511 while( $row = $dbr->fetchObject( $result ) ) {
512 $logRows[$row->log_id
] = $row;
514 $wgMessageCache->loadAllMessages();
515 foreach( $this->events
as $logid ) {
516 // Don't hide from oversight log!!!
517 if( !isset( $logRows[$logid] ) ||
$logRows[$logid]->log_type
=='suppress' ) {
519 } else if( !LogEventsList
::userCan( $logRows[$logid],Revision
::DELETED_RESTRICTED
) ) {
520 // If an event is hidden from sysops
521 if( !$this->wasPosted
) {
522 $wgOut->permissionRequired( 'suppressrevision' );
525 $UserAllowed = false;
528 $wgOut->addHTML( $this->logLine( $logRows[$logid] ) );
529 $bitfields |
= $logRows[$logid]->log_deleted
;
532 $wgOut->showErrorPage( 'revdelete-nologid-title', 'revdelete-nologid-text' );
536 $wgOut->addHTML( "</ul>" );
538 $this->addUsageText();
539 // Normal sysops can always see what they did, but can't always change it
540 if( !$UserAllowed ) return;
543 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
544 Xml
::submitButton( wfMsg( 'revdelete-submit' ) ) );
546 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
547 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
548 Xml
::hidden( 'type', $this->deleteKey
),
549 Xml
::hidden( 'logid', implode(',',$this->logids
) )
552 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
554 Xml
::openElement( 'form', array( 'method' => 'post',
555 'action' => $special->getLocalUrl( 'action=submit' ), 'id' => 'mw-revdel-form-logs' ) ) .
556 Xml
::fieldset( wfMsg( 'revdelete-legend' ) )
559 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
560 foreach( $items as $item ) {
561 $wgOut->addHTML( "<p>$item</p>" );
563 foreach( $hidden as $item ) {
564 $wgOut->addHTML( $item );
568 Xml
::closeElement( 'fieldset' ) .
569 Xml
::closeElement( 'form' ) . "\n"
573 private function addUsageText() {
574 global $wgOut, $wgUser;
575 $wgOut->addWikiMsg( 'revdelete-text' );
576 if( $wgUser->isAllowed( 'suppressrevision' ) ) {
577 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
582 * @param int $bitfields, aggregate bitfield of all the bitfields
583 * @returns string HTML
585 private function buildCheckBoxes( $bitfields ) {
587 // FIXME: all items checked for just one rev are checked, even if not set for the others
588 foreach( $this->checks
as $item ) {
589 list( $message, $name, $field ) = $item;
590 $line = Xml
::tags( 'div', null, Xml
::checkLabel( wfMsg($message), $name, $name,
591 $bitfields & $field ) );
592 if( $field == Revision
::DELETED_RESTRICTED
) $line = "<b>$line</b>";
599 * @param Revision $rev
602 private function historyLine( $rev ) {
603 global $wgLang, $wgUser;
605 $date = $wgLang->timeanddate( $rev->getTimestamp() );
606 $difflink = $del = '';
608 if( $this->deleteKey
=='oldid' ) {
609 $tokenParams = '&unhide=1&token='.urlencode( $wgUser->editToken( $rev->getId() ) );
610 $revlink = $this->skin
->makeLinkObj( $this->page
, $date, 'oldid='.$rev->getId() . $tokenParams );
611 $difflink = '(' . $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml('diff'),
612 'diff=' . $rev->getId() . '&oldid=prev' . $tokenParams ) . ')';
613 // Archived revisions
615 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
616 $target = $this->page
->getPrefixedText();
617 $revlink = $this->skin
->makeLinkObj( $undelete, $date,
618 "target=$target×tamp=" . $rev->getTimestamp() );
619 $difflink = '(' . $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml('diff'),
620 "target=$target&diff=prev×tamp=" . $rev->getTimestamp() ) . ')';
622 // Check permissions; items may be "suppressed"
623 if( $rev->isDeleted(Revision
::DELETED_TEXT
) ) {
624 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
625 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
626 if( !$rev->userCan(Revision
::DELETED_TEXT
) ) {
627 $revlink = '<span class="history-deleted">'.$date.'</span>';
628 $difflink = '(' . wfMsgHtml('diff') . ')';
631 $userlink = $this->skin
->revUserLink( $rev );
632 $comment = $this->skin
->revComment( $rev );
634 return "<li>$difflink $revlink $userlink $comment{$del}</li>";
641 private function fileLine( $file ) {
642 global $wgLang, $wgTitle;
644 $target = $this->page
->getPrefixedText();
645 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
649 if( $file->isDeleted(File
::DELETED_FILE
) ) {
650 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
651 if( !$file->userCan(File
::DELETED_FILE
) ) {
654 $pageLink = $this->skin
->makeKnownLinkObj( $wgTitle, $date,
655 "target=$target&file=$file->sha1.".$file->getExtension() );
657 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
660 $url = $file->getUrlRel();
661 $pageLink = "<a href=\"{$url}\">{$date}</a>";
664 $data = wfMsg( 'widthheight',
665 $wgLang->formatNum( $file->getWidth() ),
666 $wgLang->formatNum( $file->getHeight() ) ) .
667 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
668 $data = htmlspecialchars( $data );
670 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
674 * @param ArchivedFile $file
677 private function archivedfileLine( $file ) {
680 $target = $this->page
->getPrefixedText();
681 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
683 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
684 $pageLink = $this->skin
->makeKnownLinkObj( $undelete, $date, "target=$target&file={$file->getKey()}" );
687 if( $file->isDeleted(File
::DELETED_FILE
) ) {
688 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
691 $data = wfMsg( 'widthheight',
692 $wgLang->formatNum( $file->getWidth() ),
693 $wgLang->formatNum( $file->getHeight() ) ) .
694 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
695 $data = htmlspecialchars( $data );
697 return "<li> $pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
701 * @param Array $row row
704 private function logLine( $row ) {
707 $date = $wgLang->timeanddate( $row->log_timestamp
);
708 $paramArray = LogPage
::extractParams( $row->log_params
);
709 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
711 $logtitle = SpecialPage
::getTitleFor( 'Log' );
712 $loglink = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
713 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
715 if( !LogEventsList
::userCan($row,LogPage
::DELETED_ACTION
) ) {
716 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
718 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
719 $this->skin
, $paramArray, true, true );
720 if( $row->log_deleted
& LogPage
::DELETED_ACTION
)
721 $action = '<span class="history-deleted">' . $action . '</span>';
724 $userLink = $this->skin
->userLink( $row->log_user
, User
::WhoIs($row->log_user
) );
725 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_USER
) ) {
726 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
729 $comment = $wgLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
730 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
731 $comment = '<span class="history-deleted">' . $comment . '</span>';
733 return "<li>($loglink) $date $userLink $action $comment</li>";
737 * Generate a user tool link cluster if the current user is allowed to view it
738 * @param ArchivedFile $file
739 * @return string HTML
741 private function fileUserTools( $file ) {
742 if( $file->userCan( Revision
::DELETED_USER
) ) {
743 $link = $this->skin
->userLink( $file->user
, $file->user_text
) .
744 $this->skin
->userToolLinks( $file->user
, $file->user_text
);
746 $link = wfMsgHtml( 'rev-deleted-user' );
748 if( $file->isDeleted( Revision
::DELETED_USER
) ) {
749 return '<span class="history-deleted">' . $link . '</span>';
755 * Wrap and format the given file's comment block, if the current
756 * user is allowed to view it.
758 * @param ArchivedFile $file
759 * @return string HTML
761 private function fileComment( $file ) {
762 if( $file->userCan( File
::DELETED_COMMENT
) ) {
763 $block = $this->skin
->commentBlock( $file->description
);
765 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
767 if( $file->isDeleted( File
::DELETED_COMMENT
) ) {
768 return "<span class=\"history-deleted\">$block</span>";
774 * @param WebRequest $request
776 private function submit( $request ) {
777 global $wgUser, $wgOut;
778 # Check edit token on submission
779 if( $this->wasPosted
&& !$wgUser->matchEditToken( $request->getVal('wpEditToken') ) ) {
780 $wgOut->addWikiMsg( 'sessionfailure' );
783 $bitfield = $this->extractBitfield( $request );
784 $comment = $request->getText( 'wpReason' );
785 # Can the user set this field?
786 if( $bitfield & Revision
::DELETED_RESTRICTED
&& !$wgUser->isAllowed('suppressrevision') ) {
787 $wgOut->permissionRequired( 'suppressrevision' );
790 # If the save went through, go to success message. Otherwise
791 # bounce back to form...
792 if( $this->save( $bitfield, $comment, $this->page
) ) {
794 } else if( $request->getCheck( 'oldid' ) ||
$request->getCheck( 'artimestamp' ) ) {
795 return $this->showRevs();
796 } else if( $request->getCheck( 'logid' ) ) {
797 return $this->showLogs();
798 } else if( $request->getCheck( 'oldimage' ) ||
$request->getCheck( 'fileid' ) ) {
799 return $this->showImages();
803 private function success() {
806 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
808 $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' );
826 * Put together a rev_deleted bitfield from the submitted checkboxes
827 * @param WebRequest $request
830 private function extractBitfield( $request ) {
832 foreach( $this->checks
as $item ) {
833 list( /* message */ , $name, $field ) = $item;
834 if( $request->getCheck( $name ) ) {
841 private function save( $bitfield, $reason, $title ) {
842 $dbw = wfGetDB( DB_MASTER
);
843 // Don't allow simply locking the interface for no reason
844 if( $bitfield == Revision
::DELETED_RESTRICTED
) {
847 $deleter = new RevisionDeleter( $dbw );
848 // By this point, only one of the below should be set
849 if( isset($this->revisions
) ) {
850 return $deleter->setRevVisibility( $title, $this->revisions
, $bitfield, $reason );
851 } else if( isset($this->archrevs
) ) {
852 return $deleter->setArchiveVisibility( $title, $this->archrevs
, $bitfield, $reason );
853 } else if( isset($this->ofiles
) ) {
854 return $deleter->setOldImgVisibility( $title, $this->ofiles
, $bitfield, $reason );
855 } else if( isset($this->afiles
) ) {
856 return $deleter->setArchFileVisibility( $title, $this->afiles
, $bitfield, $reason );
857 } else if( isset($this->events
) ) {
858 return $deleter->setEventVisibility( $title, $this->events
, $bitfield, $reason );
864 * Implements the actions for Revision Deletion.
865 * @ingroup SpecialPage
867 class RevisionDeleter
{
868 function __construct( $db ) {
873 * @param $title, the page these events apply to
874 * @param array $items list of revision ID numbers
875 * @param int $bitfield new rev_deleted value
876 * @param string $comment Comment for log records
878 function setRevVisibility( $title, $items, $bitfield, $comment ) {
881 $userAllowedAll = $success = true;
884 // Run through and pull all our data in one query
885 foreach( $items as $revid ) {
886 $where[] = intval($revid);
888 $result = $this->dbw
->select( 'revision', '*',
890 'rev_page' => $title->getArticleID(),
891 'rev_id' => $where ),
893 while( $row = $this->dbw
->fetchObject( $result ) ) {
894 $revObjs[$row->rev_id
] = new Revision( $row );
897 foreach( $items as $revid ) {
898 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
900 continue; // Must exist
901 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
902 $userAllowedAll=false;
905 // For logging, maintain a count of revisions
906 if( $revObjs[$revid]->mDeleted
!= $bitfield ) {
910 $this->updateRevision( $revObjs[$revid], $bitfield );
911 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
915 // Don't log or touch if nothing changed
916 if( $revCount > 0 ) {
917 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted
,
918 $comment, $title, 'oldid', $revIDs );
919 $this->updatePage( $title );
921 // Where all revs allowed to be set?
922 if( !$userAllowedAll ) {
923 //FIXME: still might be confusing???
924 $wgOut->permissionRequired( 'suppressrevision' );
932 * @param $title, the page these events apply to
933 * @param array $items list of revision ID numbers
934 * @param int $bitfield new rev_deleted value
935 * @param string $comment Comment for log records
937 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
940 $userAllowedAll = $success = true;
943 // Run through and pull all our data in one query
944 foreach( $items as $timestamp ) {
945 $where[] = $this->dbw
->timestamp( $timestamp );
947 $result = $this->dbw
->select( 'archive', '*',
949 'ar_namespace' => $title->getNamespace(),
950 'ar_title' => $title->getDBKey(),
951 'ar_timestamp' => $where ),
953 while( $row = $this->dbw
->fetchObject( $result ) ) {
954 $timestamp = wfTimestamp( TS_MW
, $row->ar_timestamp
);
955 $revObjs[$timestamp] = new Revision( array(
956 'page' => $title->getArticleId(),
957 'id' => $row->ar_rev_id
,
958 'text' => $row->ar_text_id
,
959 'comment' => $row->ar_comment
,
960 'user' => $row->ar_user
,
961 'user_text' => $row->ar_user_text
,
962 'timestamp' => $timestamp,
963 'minor_edit' => $row->ar_minor_edit
,
964 'text_id' => $row->ar_text_id
,
965 'deleted' => $row->ar_deleted
,
966 'len' => $row->ar_len
) );
969 foreach( $items as $timestamp ) {
970 // This will only select the first revision with this timestamp.
971 // Since they are all selected/deleted at once, we can just check the
972 // permissions of one. UPDATE is done via timestamp, so all revs are set.
973 if( !is_object($revObjs[$timestamp]) ) {
975 continue; // Must exist
976 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
977 $userAllowedAll=false;
980 // Which revisions did we change anything about?
981 if( $revObjs[$timestamp]->mDeleted
!= $bitfield ) {
982 $Id_set[]=$timestamp;
985 $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
988 // For logging, maintain a count of revisions
990 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted
,
991 $comment, $title, 'artimestamp', $Id_set );
993 // Where all revs allowed to be set?
994 if( !$userAllowedAll ) {
995 $wgOut->permissionRequired( 'suppressrevision' );
1003 * @param $title, the page these events apply to
1004 * @param array $items list of revision ID numbers
1005 * @param int $bitfield new rev_deleted value
1006 * @param string $comment Comment for log records
1008 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
1011 $userAllowedAll = $success = true;
1014 // Run through and pull all our data in one query
1015 foreach( $items as $timestamp ) {
1016 $where[] = $timestamp.'!'.$title->getDBKey();
1018 $result = $this->dbw
->select( 'oldimage', '*',
1020 'oi_name' => $title->getDBKey(),
1021 'oi_archive_name' => $where ),
1023 while( $row = $this->dbw
->fetchObject( $result ) ) {
1024 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
1025 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
1026 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
1029 foreach( $items as $timestamp ) {
1030 $archivename = $timestamp.'!'.$title->getDBKey();
1031 if( !isset($filesObjs[$archivename]) ) {
1033 continue; // Must exist
1034 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
1035 $userAllowedAll=false;
1039 $transaction = true;
1040 // Which revisions did we change anything about?
1041 if( $filesObjs[$archivename]->deleted
!= $bitfield ) {
1044 $this->dbw
->begin();
1045 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
1046 // If this image is currently hidden...
1047 if( $filesObjs[$archivename]->deleted
& File
::DELETED_FILE
) {
1048 if( $bitfield & File
::DELETED_FILE
) {
1049 # Leave it alone if we are not changing this...
1051 $transaction = true;
1053 # We are moving this out
1054 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
1055 $set[]=$transaction;
1057 // Is it just now becoming hidden?
1058 } else if( $bitfield & File
::DELETED_FILE
) {
1059 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
1060 $set[]=$transaction;
1064 // If our file operations fail, then revert back the db
1065 if( $transaction==false ) {
1066 $this->dbw
->rollback();
1069 $this->dbw
->commit();
1073 // Log if something was changed
1075 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted
,
1076 $comment, $title, 'oldimage', $set );
1077 # Purge page/history
1078 $file = wfLocalFile( $title );
1079 $file->purgeCache();
1080 $file->purgeHistory();
1081 # Invalidate cache for all pages using this file
1082 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
1083 $update->doUpdate();
1085 // Where all revs allowed to be set?
1086 if( !$userAllowedAll ) {
1087 $wgOut->permissionRequired( 'suppressrevision' );
1095 * @param $title, the page these events apply to
1096 * @param array $items list of revision ID numbers
1097 * @param int $bitfield new rev_deleted value
1098 * @param string $comment Comment for log records
1100 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
1103 $userAllowedAll = $success = true;
1107 // Run through and pull all our data in one query
1108 foreach( $items as $id ) {
1109 $where[] = intval($id);
1111 $result = $this->dbw
->select( 'filearchive', '*',
1112 array( 'fa_name' => $title->getDBKey(),
1113 'fa_id' => $where ),
1115 while( $row = $this->dbw
->fetchObject( $result ) ) {
1116 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
1119 foreach( $items as $fileid ) {
1120 if( !isset($filesObjs[$fileid]) ) {
1122 continue; // Must exist
1123 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
1124 $userAllowedAll=false;
1127 // Which revisions did we change anything about?
1128 if( $filesObjs[$fileid]->deleted
!= $bitfield ) {
1132 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1135 // Log if something was changed
1137 $this->updateLog( $title, $count, $bitfield, $comment,
1138 $filesObjs[$fileid]->deleted
, $title, 'fileid', $Id_set );
1140 // Where all revs allowed to be set?
1141 if( !$userAllowedAll ) {
1142 $wgOut->permissionRequired( 'suppressrevision' );
1150 * @param $title, the log page these events apply to
1151 * @param array $items list of log ID numbers
1152 * @param int $bitfield new log_deleted value
1153 * @param string $comment Comment for log records
1155 function setEventVisibility( $title, $items, $bitfield, $comment ) {
1158 $userAllowedAll = $success = true;
1162 // Run through and pull all our data in one query
1163 foreach( $items as $logid ) {
1164 $where[] = intval($logid);
1166 list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
1167 $result = $this->dbw
->select( 'logging', '*',
1169 'log_type' => $logtype,
1170 'log_id' => $where ),
1172 while( $row = $this->dbw
->fetchObject( $result ) ) {
1173 $logRows[$row->log_id
] = $row;
1176 foreach( $items as $logid ) {
1177 if( !isset($logRows[$logid]) ) {
1179 continue; // Must exist
1180 } else if( !LogEventsList
::userCan($logRows[$logid], LogPage
::DELETED_RESTRICTED
)
1181 ||
$logRows[$logid]->log_type
== 'suppress' ) {
1182 // Don't hide from oversight log!!!
1183 $userAllowedAll=false;
1186 // Which logs did we change anything about?
1187 if( $logRows[$logid]->log_deleted
!= $bitfield ) {
1191 $this->updateLogs( $logRows[$logid], $bitfield );
1192 $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
1195 // Don't log or touch if nothing changed
1197 $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted
,
1198 $comment, $title, 'logid', $log_Ids );
1200 // Were all revs allowed to be set?
1201 if( !$userAllowedAll ) {
1202 $wgOut->permissionRequired( 'suppressrevision' );
1210 * Moves an image to a safe private location
1211 * Caller is responsible for clearing caches
1212 * @param File $oimage
1213 * @returns mixed, timestamp string on success, false on failure
1215 function makeOldImagePrivate( $oimage ) {
1216 $transaction = new FSTransaction();
1217 if( !FileStore
::lock() ) {
1218 wfDebug( __METHOD__
.": failed to acquire file store lock, aborting\n" );
1221 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1222 // Dupe the file into the file store
1223 if( file_exists( $oldpath ) ) {
1224 // Is our directory configured?
1225 if( $store = FileStore
::get( 'deleted' ) ) {
1226 if( !$oimage->sha1
) {
1227 $oimage->upgradeRow(); // sha1 may be missing
1229 $key = $oimage->sha1
. '.' . $oimage->getExtension();
1230 $transaction->add( $store->insert( $key, $oldpath, FileStore
::DELETE_ORIGINAL
) );
1234 $transaction = false; // Return an error and do nothing
1237 wfDebug( __METHOD__
." deleting already-missing '$oldpath'; moving on to database\n" );
1240 $transaction = new FSTransaction(); // empty
1243 if( $transaction === false ) {
1245 wfDebug( __METHOD__
.": import to file store failed, aborting\n" );
1246 throw new MWException( "Could not archive and delete file $oldpath" );
1250 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1251 $transaction->commit();
1252 FileStore
::unlock();
1254 $m = explode('!',$oimage->archive_name
,2);
1261 * Moves an image from a safe private location
1262 * Caller is responsible for clearing caches
1263 * @param File $oimage
1264 * @returns mixed, string timestamp on success, false on failure
1266 function makeOldImagePublic( $oimage ) {
1267 $transaction = new FSTransaction();
1268 if( !FileStore
::lock() ) {
1269 wfDebug( __METHOD__
." could not acquire filestore lock\n" );
1273 $store = FileStore
::get( 'deleted' );
1275 wfDebug( __METHOD__
.": skipping row with no file.\n" );
1279 $key = $oimage->sha1
.'.'.$oimage->getExtension();
1280 $destDir = $oimage->getArchivePath();
1281 if( !is_dir( $destDir ) ) {
1282 wfMkdirParents( $destDir );
1284 $destPath = $destDir . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1285 // Check if any other stored revisions use this file;
1286 // if so, we shouldn't remove the file from the hidden
1287 // archives so they will still work. Check hidden files first.
1288 $useCount = $this->dbw
->selectField( 'oldimage', '1',
1289 array( 'oi_sha1' => $oimage->sha1
,
1290 'oi_deleted & '.File
::DELETED_FILE
=> File
::DELETED_FILE
),
1291 __METHOD__
, array( 'FOR UPDATE' ) );
1292 // Check the rest of the deleted archives too.
1293 // (these are the ones that don't show in the image history)
1295 $useCount = $this->dbw
->selectField( 'filearchive', '1',
1296 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1297 __METHOD__
, array( 'FOR UPDATE' ) );
1300 if( $useCount == 0 ) {
1301 wfDebug( __METHOD__
.": nothing else using {$oimage->sha1}, will deleting after\n" );
1302 $flags = FileStore
::DELETE_ORIGINAL
;
1306 $transaction->add( $store->export( $key, $destPath, $flags ) );
1308 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1309 $transaction->commit();
1310 FileStore
::unlock();
1312 $m = explode('!',$oimage->archive_name
,2);
1319 * Update the revision's rev_deleted field
1320 * @param Revision $rev
1321 * @param int $bitfield new rev_deleted bitfield value
1323 function updateRevision( $rev, $bitfield ) {
1324 $this->dbw
->update( 'revision',
1325 array( 'rev_deleted' => $bitfield ),
1326 array( 'rev_id' => $rev->getId(),
1327 'rev_page' => $rev->getPage() ),
1332 * Update the revision's rev_deleted field
1333 * @param Revision $rev
1334 * @param Title $title
1335 * @param int $bitfield new rev_deleted bitfield value
1337 function updateArchive( $rev, $title, $bitfield ) {
1338 $this->dbw
->update( 'archive',
1339 array( 'ar_deleted' => $bitfield ),
1340 array( 'ar_namespace' => $title->getNamespace(),
1341 'ar_title' => $title->getDBKey(),
1342 'ar_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ),
1343 'ar_rev_id' => $rev->getId() ),
1348 * Update the images's oi_deleted field
1350 * @param int $bitfield new rev_deleted bitfield value
1352 function updateOldFiles( $file, $bitfield ) {
1353 $this->dbw
->update( 'oldimage',
1354 array( 'oi_deleted' => $bitfield ),
1355 array( 'oi_name' => $file->getName(),
1356 'oi_timestamp' => $this->dbw
->timestamp( $file->getTimestamp() ) ),
1361 * Update the images's fa_deleted field
1362 * @param ArchivedFile $file
1363 * @param int $bitfield new rev_deleted bitfield value
1365 function updateArchFiles( $file, $bitfield ) {
1366 $this->dbw
->update( 'filearchive',
1367 array( 'fa_deleted' => $bitfield ),
1368 array( 'fa_id' => $file->getId() ),
1373 * Update the logging log_deleted field
1375 * @param int $bitfield new rev_deleted bitfield value
1377 function updateLogs( $row, $bitfield ) {
1378 $this->dbw
->update( 'logging',
1379 array( 'log_deleted' => $bitfield ),
1380 array( 'log_id' => $row->log_id
),
1385 * Update the revision's recentchanges record if fields have been hidden
1386 * @param Revision $rev
1387 * @param int $bitfield new rev_deleted bitfield value
1389 function updateRecentChangesEdits( $rev, $bitfield ) {
1390 $this->dbw
->update( 'recentchanges',
1391 array( 'rc_deleted' => $bitfield,
1392 'rc_patrolled' => 1 ),
1393 array( 'rc_this_oldid' => $rev->getId(),
1394 'rc_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ) ),
1399 * Update the revision's recentchanges record if fields have been hidden
1401 * @param int $bitfield new rev_deleted bitfield value
1403 function updateRecentChangesLog( $row, $bitfield ) {
1404 $this->dbw
->update( 'recentchanges',
1405 array( 'rc_deleted' => $bitfield,
1406 'rc_patrolled' => 1 ),
1407 array( 'rc_logid' => $row->log_id
,
1408 'rc_timestamp' => $row->log_timestamp
),
1413 * Touch the page's cache invalidation timestamp; this forces cached
1414 * history views to refresh, so any newly hidden or shown fields will
1416 * @param Title $title
1418 function updatePage( $title ) {
1419 $title->invalidateCache();
1420 $title->purgeSquid();
1421 $title->touchLinks();
1422 // Extensions that require referencing previous revisions may need this
1423 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1427 * Checks for a change in the bitfield for a certain option and updates the
1428 * provided array accordingly.
1430 * @param String $desc Description to add to the array if the option was
1431 * enabled / disabled.
1432 * @param int $field The bitmask describing the single option.
1433 * @param int $diff The xor of the old and new bitfields.
1434 * @param array $arr The array to update.
1436 function checkItem ( $desc, $field, $diff, $new, &$arr ) {
1437 if ( $diff & $field ) {
1438 $arr [ ( $new & $field ) ?
0 : 1 ][] = $desc;
1443 * Gets an array describing the changes made to the visibilit of the revision.
1444 * If the resulting array is $arr, then $arr[0] will contain an array of strings
1445 * describing the items that were hidden, $arr[2] will contain an array of strings
1446 * describing the items that were unhidden, and $arr[3] will contain an array with
1447 * a single string, which can be one of "applied restrictions to sysops",
1448 * "removed restrictions from sysops", or null.
1450 * @param int $n The new bitfield.
1451 * @param int $o The old bitfield.
1452 * @return An array as described above.
1454 function getChanges ( $n, $o ) {
1456 $ret = array ( 0 => array(), 1 => array(), 2 => array() );
1458 $this->checkItem ( wfMsgForContent ( 'revdelete-content' ),
1459 Revision
::DELETED_TEXT
, $diff, $n, $ret );
1460 $this->checkItem ( wfMsgForContent ( 'revdelete-summary' ),
1461 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
1462 $this->checkItem ( wfMsgForContent ( 'revdelete-uname' ),
1463 Revision
::DELETED_USER
, $diff, $n, $ret );
1465 // Restriction application to sysops
1466 if ( $diff & Revision
::DELETED_RESTRICTED
) {
1467 if ( $n & Revision
::DELETED_RESTRICTED
)
1468 $ret[2][] = wfMsgForContent ( 'revdelete-restricted' );
1470 $ret[2][] = wfMsgForContent ( 'revdelete-unrestricted' );
1477 * Gets a log message to describe the given revision visibility change. This
1478 * message will be of the form "[hid {content, edit summary, username}];
1479 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
1481 * @param int $count The number of effected revisions.
1482 * @param int $nbitfield The new bitfield for the revision.
1483 * @param int $obitfield The old bitfield for the revision.
1484 * @param string $comment The comment associated with the change.
1485 * @param bool $isForLog
1487 function getLogMessage ( $count, $nbitfield, $obitfield, $comment, $isForLog = false ) {
1491 $changes = $this->getChanges( $nbitfield, $obitfield );
1493 if ( count ( $changes[0] ) ) {
1494 $s .= wfMsgForContent ( 'revdelete-hid', implode ( ', ', $changes[0] ) );
1497 if ( count ( $changes[1] ) ) {
1500 $s .= wfMsgForContent ( 'revdelete-unhid', implode ( ', ', $changes[1] ) );
1503 if ( count ( $changes[2] )) {
1505 $s .= ' (' . $changes[2][0] . ')';
1507 $s = $changes[2][0];
1510 $msg = $isForLog ?
'logdelete-log-message' : 'revdelete-log-message';
1511 $ret = wfMsgExt ( $msg, array( 'parsemag', 'content' ),
1512 $s, $wgContLang->formatNum( $count ) );
1515 $ret .= ": $comment";
1522 * Record a log entry on the action
1523 * @param Title $title, page where item was removed from
1524 * @param int $count the number of revisions altered for this page
1525 * @param int $nbitfield the new _deleted value
1526 * @param int $obitfield the old _deleted value
1527 * @param string $comment
1528 * @param Title $target, the relevant page
1529 * @param string $param, URL param
1530 * @param Array $items
1532 function updateLog( $title, $count, $nbitfield, $obitfield, $comment,
1533 $target, $param, $items = array() )
1535 // Put things hidden from sysops in the oversight log
1536 $logtype = ( ($nbitfield |
$obitfield) & Revision
::DELETED_RESTRICTED
) ?
'suppress' : 'delete';
1537 $log = new LogPage( $logtype );
1539 $reason = $this->getLogMessage( $count, $nbitfield, $obitfield, $comment, $param == 'logid' );
1541 if( $param == 'logid' ) {
1542 $params = array( implode( ',', $items) );
1543 $log->addEntry( 'event', $title, $reason, $params );
1545 // Add params for effected page and ids
1546 $params = array( $param, implode( ',', $items) );
1547 $log->addEntry( 'revision', $title, $reason, $params );