* Added revdelete-suppress-text
[mediawiki.git] / includes / specials / SpecialRevisiondelete.php
blobaf193dcefd38fe8a1d809ee7f5c7973ab9490c0b
1 <?php
2 /**
3 * Special page allowing users with the appropriate permissions to view
4 * and hide revisions. Log items can also be hidden.
6 * @file
7 * @ingroup SpecialPage
8 */
10 function wfSpecialRevisiondelete( $par = null ) {
11 global $wgOut, $wgRequest, $wgUser;
13 if ( wfReadOnly() ) {
14 $wgOut->readOnlyPage();
15 return;
18 # Handle our many different possible input types
19 $target = $wgRequest->getText( 'target' );
20 $oldid = $wgRequest->getArray( 'oldid' );
21 $artimestamp = $wgRequest->getArray( 'artimestamp' );
22 $logid = $wgRequest->getArray( 'logid' );
23 $img = $wgRequest->getArray( 'oldimage' );
24 $fileid = $wgRequest->getArray( 'fileid' );
25 # For reviewing deleted files...
26 $file = $wgRequest->getVal( 'file' );
27 # If this is a revision, then we need a target page
28 $page = Title::newFromUrl( $target );
29 if( is_null($page) ) {
30 $wgOut->addWikiMsg( 'undelete-header' );
31 return;
33 # Only one target set at a time please!
34 $i = (bool)$file + (bool)$oldid + (bool)$logid + (bool)$artimestamp + (bool)$fileid + (bool)$img;
35 if( $i !== 1 ) {
36 $wgOut->showErrorPage( 'revdelete-toomanytargets-title', 'revdelete-toomanytargets-text' );
37 return;
39 # Logs must have a type given
40 if( $logid && !strpos($page->getDBKey(),'/') ) {
41 $wgOut->showErrorPage( 'revdelete-nologtype-title', 'revdelete-nologtype-text' );
42 return;
44 # Either submit or create our form
45 $form = new RevisionDeleteForm( $page, $oldid, $logid, $artimestamp, $fileid, $img, $file );
46 if( $wgRequest->wasPosted() ) {
47 $form->submit( $wgRequest );
48 } else if( $oldid || $artimestamp ) {
49 $form->showRevs();
50 } else if( $fileid || $img ) {
51 $form->showImages();
52 } else if( $logid ) {
53 $form->showLogItems();
55 # Show relevant lines from the deletion log. This will show even if said ID
56 # does not exist...might be helpful
57 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
58 LogEventsList::showLogExtract( $wgOut, 'delete', $page->getPrefixedText() );
59 if( $wgUser->isAllowed( 'suppressionlog' ) ){
60 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'suppress' ) ) . "</h2>\n" );
61 LogEventsList::showLogExtract( $wgOut, 'suppress', $page->getPrefixedText() );
65 /**
66 * Implements the GUI for Revision Deletion.
67 * @ingroup SpecialPage
69 class RevisionDeleteForm {
70 /**
71 * @param Title $page
72 * @param array $oldids
73 * @param array $logids
74 * @param array $artimestamps
75 * @param array $fileids
76 * @param array $img
77 * @param string $file
79 function __construct( $page, $oldids, $logids, $artimestamps, $fileids, $img, $file ) {
80 global $wgUser, $wgOut;
82 $this->page = $page;
83 # For reviewing deleted files...
84 if( $file ) {
85 $oimage = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $page, $file );
86 $oimage->load();
87 // Check if user is allowed to see this file
88 if( !$oimage->userCan(File::DELETED_FILE) ) {
89 $wgOut->permissionRequired( 'suppressrevision' );
90 } else {
91 $this->showFile( $file );
93 return;
95 $this->skin = $wgUser->getSkin();
96 # Give a link to the log for this page
97 if( !is_null($this->page) && $this->page->getNamespace() > -1 ) {
98 $links = array();
100 $logtitle = SpecialPage::getTitleFor( 'Log' );
101 $links[] = $this->skin->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
102 wfArrayToCGI( array( 'page' => $this->page->getPrefixedUrl() ) ) );
103 # Give a link to the page history
104 $links[] = $this->skin->makeKnownLinkObj( $this->page, wfMsgHtml( 'pagehist' ),
105 wfArrayToCGI( array( 'action' => 'history' ) ) );
106 # Link to deleted edits
107 if( $wgUser->isAllowed('undelete') ) {
108 $undelete = SpecialPage::getTitleFor( 'Undelete' );
109 $links[] = $this->skin->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
110 wfArrayToCGI( array( 'target' => $this->page->getPrefixedDBkey() ) ) );
112 # Logs themselves don't have histories or archived revisions
113 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
115 // At this point, we should only have one of these
116 if( $oldids ) {
117 $this->revisions = $oldids;
118 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision::DELETED_TEXT );
119 $this->deleteKey='oldid';
120 } else if( $artimestamps ) {
121 $this->archrevs = $artimestamps;
122 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision::DELETED_TEXT );
123 $this->deleteKey='artimestamp';
124 } else if( $img ) {
125 $this->ofiles = $img;
126 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File::DELETED_FILE );
127 $this->deleteKey='oldimage';
128 } else if( $fileids ) {
129 $this->afiles = $fileids;
130 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File::DELETED_FILE );
131 $this->deleteKey='fileid';
132 } else if( $logids ) {
133 $this->events = $logids;
134 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage::DELETED_ACTION );
135 $this->deleteKey='logid';
137 // Our checkbox messages depends one what we are doing,
138 // e.g. we don't hide "text" for logs or images
139 $this->checks = array(
140 $hide_content_name,
141 array( 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ),
142 array( 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER ) );
143 if( $wgUser->isAllowed('suppressrevision') ) {
144 $this->checks[] = array( 'revdelete-hide-restricted', 'wpHideRestricted', Revision::DELETED_RESTRICTED );
149 * Show a deleted file version requested by the visitor.
151 private function showFile( $key ) {
152 global $wgOut, $wgRequest;
153 $wgOut->disable();
155 # We mustn't allow the output to be Squid cached, otherwise
156 # if an admin previews a deleted image, and it's cached, then
157 # a user without appropriate permissions can toddle off and
158 # nab the image, and Squid will serve it
159 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
160 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
161 $wgRequest->response()->header( 'Pragma: no-cache' );
163 $store = FileStore::get( 'deleted' );
164 $store->stream( $key );
168 * This lets a user set restrictions for live and archived revisions
170 function showRevs() {
171 global $wgOut, $wgUser, $action;
173 $UserAllowed = true;
175 $count = ($this->deleteKey=='oldid') ?
176 count($this->revisions) : count($this->archrevs);
177 $wgOut->addWikiMsg( 'revdelete-selected', $this->page->getPrefixedText(), $count );
179 $bitfields = 0;
180 $wgOut->addHTML( "<ul>" );
182 $where = $revObjs = array();
183 $dbr = wfGetDB( DB_SLAVE );
185 $revisions = 0;
186 // Live revisions...
187 if( $this->deleteKey=='oldid' ) {
188 // Run through and pull all our data in one query
189 foreach( $this->revisions as $revid ) {
190 $where[] = intval($revid);
192 $result = $dbr->select( array('revision','page'), '*',
193 array(
194 'rev_page' => $this->page->getArticleID(),
195 'rev_id' => $where,
196 'rev_page = page_id' ),
197 __METHOD__ );
198 while( $row = $dbr->fetchObject( $result ) ) {
199 $revObjs[$row->rev_id] = new Revision( $row );
201 foreach( $this->revisions as $revid ) {
202 // Hiding top revisison is bad
203 if( !isset($revObjs[$revid]) || $revObjs[$revid]->isCurrent() ) {
204 continue;
205 } else if( !$revObjs[$revid]->userCan(Revision::DELETED_RESTRICTED) ) {
206 // If a rev is hidden from sysops
207 if( $action != 'submit') {
208 $wgOut->permissionRequired( 'suppressrevision' );
209 return;
211 $UserAllowed = false;
213 $revisions++;
214 $wgOut->addHTML( $this->historyLine( $revObjs[$revid] ) );
215 $bitfields |= $revObjs[$revid]->mDeleted;
217 // The archives...
218 } else {
219 // Run through and pull all our data in one query
220 foreach( $this->archrevs as $timestamp ) {
221 $where[] = $dbr->timestamp( $timestamp );
223 $result = $dbr->select( 'archive', '*',
224 array(
225 'ar_namespace' => $this->page->getNamespace(),
226 'ar_title' => $this->page->getDBKey(),
227 'ar_timestamp' => $where ),
228 __METHOD__ );
229 while( $row = $dbr->fetchObject( $result ) ) {
230 $timestamp = wfTimestamp( TS_MW, $row->ar_timestamp );
231 $revObjs[$timestamp] = new Revision( array(
232 'page' => $this->page->getArticleId(),
233 'id' => $row->ar_rev_id,
234 'text' => $row->ar_text_id,
235 'comment' => $row->ar_comment,
236 'user' => $row->ar_user,
237 'user_text' => $row->ar_user_text,
238 'timestamp' => $timestamp,
239 'minor_edit' => $row->ar_minor_edit,
240 'text_id' => $row->ar_text_id,
241 'deleted' => $row->ar_deleted,
242 'len' => $row->ar_len) );
244 foreach( $this->archrevs as $timestamp ) {
245 if( !isset($revObjs[$timestamp]) ) {
246 continue;
247 } else if( !$revObjs[$timestamp]->userCan(Revision::DELETED_RESTRICTED) ) {
248 // If a rev is hidden from sysops
249 if( $action != 'submit') {
250 $wgOut->permissionRequired( 'suppressrevision' );
251 return;
253 $UserAllowed = false;
255 $revisions++;
256 $wgOut->addHTML( $this->historyLine( $revObjs[$timestamp] ) );
257 $bitfields |= $revObjs[$timestamp]->mDeleted;
260 if( !$revisions ) {
261 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
262 return;
265 $wgOut->addHTML( "</ul>" );
266 // Explanation text
267 $wgOut->addWikiMsg( 'revdelete-text' );
268 if( $wgUser->isAllowed( 'hiderevision' ) ) {
269 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
272 // Normal sysops can always see what they did, but can't always change it
273 if( !$UserAllowed ) return;
275 $items = array(
276 Xml::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
277 Xml::submitButton( wfMsg( 'revdelete-submit' ) )
279 $hidden = array(
280 Xml::hidden( 'wpEditToken', $wgUser->editToken() ),
281 Xml::hidden( 'target', $this->page->getPrefixedText() ),
282 Xml::hidden( 'type', $this->deleteKey )
284 if( $this->deleteKey=='oldid' ) {
285 foreach( $revObjs as $rev )
286 $hidden[] = Xml::hidden( 'oldid[]', $rev->getId() );
287 } else {
288 foreach( $revObjs as $rev )
289 $hidden[] = Xml::hidden( 'artimestamp[]', $rev->getTimestamp() );
291 $special = SpecialPage::getTitleFor( 'Revisiondelete' );
292 $wgOut->addHTML(
293 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
294 'id' => 'mw-revdel-form-revisions' ) ) .
295 Xml::openElement( 'fieldset' ) .
296 xml::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
299 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
300 foreach( $items as $item ) {
301 $wgOut->addHTML( Xml::tags( 'p', null, $item ) );
303 foreach( $hidden as $item ) {
304 $wgOut->addHTML( $item );
306 $wgOut->addHTML(
307 Xml::closeElement( 'fieldset' ) .
308 Xml::closeElement( 'form' ) . "\n"
313 * @param int $bitfields, aggregate bitfield of all the bitfields
314 * @returns string HTML
316 private function buildCheckBoxes( $bitfields ) {
317 $html = '';
318 // FIXME: all items checked for just one rev are checked, even if not set for the others
319 foreach( $this->checks as $item ) {
320 list( $message, $name, $field ) = $item;
321 $line = Xml::tags( 'div', null, Xml::checkLabel( wfMsg($message), $name, $name,
322 $bitfields & $field ) );
323 if( $field == Revision::DELETED_RESTRICTED ) $line = "<b>$line</b>";
324 $html .= $line;
326 return $html;
330 * This lets a user set restrictions for archived images
332 function showImages() {
333 // What is $action doing here???
334 global $wgOut, $wgUser, $action, $wgLang;
336 $UserAllowed = true;
338 $count = ($this->deleteKey=='oldimage') ? count($this->ofiles) : count($this->afiles);
339 $wgOut->addWikiMsg( 'revdelete-selected',
340 $this->page->getPrefixedText(),
341 $wgLang->formatNum($count) );
343 $bitfields = 0;
344 $wgOut->addHTML( "<ul>" );
346 $where = $filesObjs = array();
347 $dbr = wfGetDB( DB_SLAVE );
348 // Live old revisions...
349 $revisions = 0;
350 if( $this->deleteKey=='oldimage' ) {
351 // Run through and pull all our data in one query
352 foreach( $this->ofiles as $timestamp ) {
353 $where[] = $timestamp.'!'.$this->page->getDBKey();
355 $result = $dbr->select( 'oldimage', '*',
356 array(
357 'oi_name' => $this->page->getDBKey(),
358 'oi_archive_name' => $where ),
359 __METHOD__ );
360 while( $row = $dbr->fetchObject( $result ) ) {
361 $filesObjs[$row->oi_archive_name] = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
362 $filesObjs[$row->oi_archive_name]->user = $row->oi_user;
363 $filesObjs[$row->oi_archive_name]->user_text = $row->oi_user_text;
365 // Check through our images
366 foreach( $this->ofiles as $timestamp ) {
367 $archivename = $timestamp.'!'.$this->page->getDBKey();
368 if( !isset($filesObjs[$archivename]) ) {
369 continue;
370 } else if( !$filesObjs[$archivename]->userCan(File::DELETED_RESTRICTED) ) {
371 // If a rev is hidden from sysops
372 if( $action != 'submit' ) {
373 $wgOut->permissionRequired( 'suppressrevision' );
374 return;
376 $UserAllowed = false;
378 $revisions++;
379 // Inject history info
380 $wgOut->addHTML( $this->fileLine( $filesObjs[$archivename] ) );
381 $bitfields |= $filesObjs[$archivename]->deleted;
383 // Archived files...
384 } else {
385 // Run through and pull all our data in one query
386 foreach( $this->afiles as $id ) {
387 $where[] = intval($id);
389 $result = $dbr->select( 'filearchive', '*',
390 array(
391 'fa_name' => $this->page->getDBKey(),
392 'fa_id' => $where ),
393 __METHOD__ );
394 while( $row = $dbr->fetchObject( $result ) ) {
395 $filesObjs[$row->fa_id] = ArchivedFile::newFromRow( $row );
398 foreach( $this->afiles as $fileid ) {
399 if( !isset($filesObjs[$fileid]) ) {
400 continue;
401 } else if( !$filesObjs[$fileid]->userCan(File::DELETED_RESTRICTED) ) {
402 // If a rev is hidden from sysops
403 if( $action != 'submit' ) {
404 $wgOut->permissionRequired( 'suppressrevision' );
405 return;
407 $UserAllowed = false;
409 $revisions++;
410 // Inject history info
411 $wgOut->addHTML( $this->archivedfileLine( $filesObjs[$fileid] ) );
412 $bitfields |= $filesObjs[$fileid]->deleted;
415 if( !$revisions ) {
416 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
417 return;
420 $wgOut->addHTML( "</ul>" );
421 // Explanation text
422 $wgOut->addWikiMsg('revdelete-text' );
423 if( $wgUser->isAllowed( 'hiderevision' ) ) {
424 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
426 // Normal sysops can always see what they did, but can't always change it
427 if( !$UserAllowed ) return;
429 $items = array(
430 Xml::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
431 Xml::submitButton( wfMsg( 'revdelete-submit' ) )
433 $hidden = array(
434 Xml::hidden( 'wpEditToken', $wgUser->editToken() ),
435 Xml::hidden( 'target', $this->page->getPrefixedText() ),
436 Xml::hidden( 'type', $this->deleteKey )
438 if( $this->deleteKey=='oldimage' ) {
439 foreach( $this->ofiles as $filename )
440 $hidden[] = Xml::hidden( 'oldimage[]', $filename );
441 } else {
442 foreach( $this->afiles as $fileid )
443 $hidden[] = Xml::hidden( 'fileid[]', $fileid );
445 $special = SpecialPage::getTitleFor( 'Revisiondelete' );
446 $wgOut->addHTML(
447 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
448 'id' => 'mw-revdel-form-filerevisions' ) ) .
449 Xml::fieldset( wfMsg( 'revdelete-legend' ) )
452 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
453 foreach( $items as $item ) {
454 $wgOut->addHTML( "<p>$item</p>" );
456 foreach( $hidden as $item ) {
457 $wgOut->addHTML( $item );
460 $wgOut->addHTML(
461 Xml::closeElement( 'fieldset' ) .
462 Xml::closeElement( 'form' ) . "\n"
467 * This lets a user set restrictions for log items
469 function showLogItems() {
470 global $wgOut, $wgUser, $action, $wgMessageCache, $wgLang;
472 $UserAllowed = true;
473 $wgOut->addWikiMsg( 'logdelete-selected', $wgLang->formatNum( count($this->events) ) );
475 $bitfields = 0;
476 $wgOut->addHTML( "<ul>" );
478 $where = $logRows = array();
479 $dbr = wfGetDB( DB_SLAVE );
480 // Run through and pull all our data in one query
481 $logItems = 0;
482 foreach( $this->events as $logid ) {
483 $where[] = intval($logid);
485 list($log,$logtype) = explode( '/',$this->page->getDBKey(), 2 );
486 $result = $dbr->select( 'logging', '*',
487 array(
488 'log_type' => $logtype,
489 'log_id' => $where ),
490 __METHOD__ );
491 while( $row = $dbr->fetchObject( $result ) ) {
492 $logRows[$row->log_id] = $row;
494 $wgMessageCache->loadAllMessages();
495 foreach( $this->events as $logid ) {
496 // Don't hide from oversight log!!!
497 if( !isset( $logRows[$logid] ) || $logRows[$logid]->log_type=='suppress' ) {
498 continue;
499 } else if( !LogEventsList::userCan( $logRows[$logid],Revision::DELETED_RESTRICTED) ) {
500 // If an event is hidden from sysops
501 if( $action != 'submit') {
502 $wgOut->permissionRequired( 'suppressrevision' );
503 return;
505 $UserAllowed = false;
507 $logItems++;
508 $wgOut->addHTML( $this->logLine( $logRows[$logid] ) );
509 $bitfields |= $logRows[$logid]->log_deleted;
511 if( !$logItems ) {
512 $wgOut->showErrorPage( 'revdelete-nologid-title', 'revdelete-nologid-text' );
513 return;
516 $wgOut->addHTML( "</ul>" );
517 // Explanation text
518 $wgOut->addWikiMsg( 'revdelete-text' );
519 if( $wgUser->isAllowed( 'hiderevision' ) ) {
520 $wgOut->addWikiMsg( 'revdelete-suppress-text' );
522 // Normal sysops can always see what they did, but can't always change it
523 if( !$UserAllowed ) return;
525 $items = array(
526 Xml::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
527 Xml::submitButton( wfMsg( 'revdelete-submit' ) ) );
528 $hidden = array(
529 Xml::hidden( 'wpEditToken', $wgUser->editToken() ),
530 Xml::hidden( 'target', $this->page->getPrefixedText() ),
531 Xml::hidden( 'type', $this->deleteKey ) );
532 foreach( $this->events as $logid ) {
533 $hidden[] = Xml::hidden( 'logid[]', $logid );
536 $special = SpecialPage::getTitleFor( 'Revisiondelete' );
537 $wgOut->addHTML(
538 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
539 'id' => 'mw-revdel-form-logs' ) ) .
540 Xml::fieldset( wfMsg( 'revdelete-legend' ) )
543 $wgOut->addHTML( $this->buildCheckBoxes( $bitfields ) );
544 foreach( $items as $item ) {
545 $wgOut->addHTML( "<p>$item</p>" );
547 foreach( $hidden as $item ) {
548 $wgOut->addHTML( $item );
551 $wgOut->addHTML(
552 Xml::closeElement( 'fieldset' ) .
553 Xml::closeElement( 'form' ) . "\n"
558 * @param Revision $rev
559 * @returns string
561 private function historyLine( $rev ) {
562 global $wgLang, $wgUser;
564 $date = $wgLang->timeanddate( $rev->getTimestamp() );
565 $difflink = $del = '';
566 // Live revisions
567 if( $this->deleteKey=='oldid' ) {
568 $tokenParams = '&unhide=1&token='.urlencode( $wgUser->editToken( $rev->getId() ) );
569 $revlink = $this->skin->makeLinkObj( $this->page, $date, 'oldid='.$rev->getId() . $tokenParams );
570 $difflink = '(' . $this->skin->makeKnownLinkObj( $this->page, wfMsgHtml('diff'),
571 'diff=' . $rev->getId() . '&oldid=prev' . $tokenParams ) . ')';
572 // Archived revisions
573 } else {
574 $undelete = SpecialPage::getTitleFor( 'Undelete' );
575 $target = $this->page->getPrefixedText();
576 $revlink = $this->skin->makeLinkObj( $undelete, $date,
577 "target=$target&timestamp=" . $rev->getTimestamp() );
578 $difflink = '(' . $this->skin->makeKnownLinkObj( $undelete, wfMsgHtml('diff'),
579 "target=$target&diff=prev&timestamp=" . $rev->getTimestamp() ) . ')';
581 // Check permissions; items may be "suppressed"
582 if( $rev->isDeleted(Revision::DELETED_TEXT) ) {
583 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
584 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
585 if( !$rev->userCan(Revision::DELETED_TEXT) ) {
586 $revlink = '<span class="history-deleted">'.$date.'</span>';
587 $difflink = '(' . wfMsgHtml('diff') . ')';
590 $userlink = $this->skin->revUserLink( $rev );
591 $comment = $this->skin->revComment( $rev );
593 return "<li> $difflink $revlink $userlink $comment{$del}</li>";
597 * @param File $file
598 * @returns string
600 private function fileLine( $file ) {
601 global $wgLang, $wgTitle;
603 $target = $this->page->getPrefixedText();
604 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
606 $del = '';
607 # Hidden files...
608 if( $file->isDeleted(File::DELETED_FILE) ) {
609 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
610 if( !$file->userCan(File::DELETED_FILE) ) {
611 $pageLink = $date;
612 } else {
613 $pageLink = $this->skin->makeKnownLinkObj( $wgTitle, $date,
614 "target=$target&file=$file->sha1.".$file->getExtension() );
616 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
617 # Regular files...
618 } else {
619 $url = $file->getUrlRel();
620 $pageLink = "<a href=\"{$url}\">{$date}</a>";
623 $data = wfMsg( 'widthheight',
624 $wgLang->formatNum( $file->getWidth() ),
625 $wgLang->formatNum( $file->getHeight() ) ) .
626 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
627 $data = htmlspecialchars( $data );
629 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
633 * @param ArchivedFile $file
634 * @returns string
636 private function archivedfileLine( $file ) {
637 global $wgLang;
639 $target = $this->page->getPrefixedText();
640 $date = $wgLang->timeanddate( $file->getTimestamp(), true );
642 $undelete = SpecialPage::getTitleFor( 'Undelete' );
643 $pageLink = $this->skin->makeKnownLinkObj( $undelete, $date, "target=$target&file={$file->getKey()}" );
645 $del = '';
646 if( $file->isDeleted(File::DELETED_FILE) ) {
647 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
650 $data = wfMsg( 'widthheight',
651 $wgLang->formatNum( $file->getWidth() ),
652 $wgLang->formatNum( $file->getHeight() ) ) .
653 ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')';
654 $data = htmlspecialchars( $data );
656 return "<li> $pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
660 * @param Array $row row
661 * @returns string
663 private function logLine( $row ) {
664 global $wgLang;
666 $date = $wgLang->timeanddate( $row->log_timestamp );
667 $paramArray = LogPage::extractParams( $row->log_params );
668 $title = Title::makeTitle( $row->log_namespace, $row->log_title );
670 $logtitle = SpecialPage::getTitleFor( 'Log' );
671 $loglink = $this->skin->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
672 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
673 // Action text
674 if( !LogEventsList::userCan($row,LogPage::DELETED_ACTION) ) {
675 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
676 } else {
677 $action = LogPage::actionText( $row->log_type, $row->log_action, $title,
678 $this->skin, $paramArray, true, true );
679 if( $row->log_deleted & LogPage::DELETED_ACTION )
680 $action = '<span class="history-deleted">' . $action . '</span>';
682 // User links
683 $userLink = $this->skin->userLink( $row->log_user, User::WhoIs($row->log_user) );
684 if( LogEventsList::isDeleted($row,LogPage::DELETED_USER) ) {
685 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
687 // Comment
688 $comment = $wgLang->getDirMark() . $this->skin->commentBlock( $row->log_comment );
689 if( LogEventsList::isDeleted($row,LogPage::DELETED_COMMENT) ) {
690 $comment = '<span class="history-deleted">' . $comment . '</span>';
692 return "<li>($loglink) $date $userLink $action $comment</li>";
696 * Generate a user tool link cluster if the current user is allowed to view it
697 * @param ArchivedFile $file
698 * @return string HTML
700 private function fileUserTools( $file ) {
701 if( $file->userCan( Revision::DELETED_USER ) ) {
702 $link = $this->skin->userLink( $file->user, $file->user_text ) .
703 $this->skin->userToolLinks( $file->user, $file->user_text );
704 } else {
705 $link = wfMsgHtml( 'rev-deleted-user' );
707 if( $file->isDeleted( Revision::DELETED_USER ) ) {
708 return '<span class="history-deleted">' . $link . '</span>';
710 return $link;
714 * Wrap and format the given file's comment block, if the current
715 * user is allowed to view it.
717 * @param ArchivedFile $file
718 * @return string HTML
720 private function fileComment( $file ) {
721 if( $file->userCan( File::DELETED_COMMENT ) ) {
722 $block = $this->skin->commentBlock( $file->description );
723 } else {
724 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
726 if( $file->isDeleted( File::DELETED_COMMENT ) ) {
727 return "<span class=\"history-deleted\">$block</span>";
729 return $block;
733 * @param WebRequest $request
735 function submit( $request ) {
736 global $wgUser, $wgOut;
738 $bitfield = $this->extractBitfield( $request );
739 $comment = $request->getText( 'wpReason' );
740 # Can the user set this field?
741 if( $bitfield & Revision::DELETED_RESTRICTED && !$wgUser->isAllowed('suppressrevision') ) {
742 $wgOut->permissionRequired( 'suppressrevision' );
743 return false;
745 # If the save went through, go to success message. Otherwise
746 # bounce back to form...
747 if( $this->save( $bitfield, $comment, $this->page ) ) {
748 $this->success();
749 } else if( $request->getCheck( 'oldid' ) || $request->getCheck( 'artimestamp' ) ) {
750 return $this->showRevs();
751 } else if( $request->getCheck( 'logid' ) ) {
752 return $this->showLogs();
753 } else if( $request->getCheck( 'oldimage' ) || $request->getCheck( 'fileid' ) ) {
754 return $this->showImages();
758 private function success() {
759 global $wgOut;
761 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
763 $wrap = '<span class="success">$1</span>';
765 if( $this->deleteKey=='logid' ) {
766 $wgOut->wrapWikiMsg( $wrap, 'logdelete-success' );
767 $this->showLogItems();
768 } else if( $this->deleteKey=='oldid' || $this->deleteKey=='artimestamp' ) {
769 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
770 $this->showRevs();
771 } else if( $this->deleteKey=='fileid' ) {
772 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
773 $this->showImages();
774 } else if( $this->deleteKey=='oldimage' ) {
775 $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' );
776 $this->showImages();
781 * Put together a rev_deleted bitfield from the submitted checkboxes
782 * @param WebRequest $request
783 * @return int
785 private function extractBitfield( $request ) {
786 $bitfield = 0;
787 foreach( $this->checks as $item ) {
788 list( /* message */ , $name, $field ) = $item;
789 if( $request->getCheck( $name ) ) {
790 $bitfield |= $field;
793 return $bitfield;
796 private function save( $bitfield, $reason, $title ) {
797 $dbw = wfGetDB( DB_MASTER );
798 // Don't allow simply locking the interface for no reason
799 if( $bitfield == Revision::DELETED_RESTRICTED ) {
800 $bitfield = 0;
802 $deleter = new RevisionDeleter( $dbw );
803 // By this point, only one of the below should be set
804 if( isset($this->revisions) ) {
805 return $deleter->setRevVisibility( $title, $this->revisions, $bitfield, $reason );
806 } else if( isset($this->archrevs) ) {
807 return $deleter->setArchiveVisibility( $title, $this->archrevs, $bitfield, $reason );
808 } else if( isset($this->ofiles) ) {
809 return $deleter->setOldImgVisibility( $title, $this->ofiles, $bitfield, $reason );
810 } else if( isset($this->afiles) ) {
811 return $deleter->setArchFileVisibility( $title, $this->afiles, $bitfield, $reason );
812 } else if( isset($this->events) ) {
813 return $deleter->setEventVisibility( $title, $this->events, $bitfield, $reason );
819 * Implements the actions for Revision Deletion.
820 * @ingroup SpecialPage
822 class RevisionDeleter {
823 function __construct( $db ) {
824 $this->dbw = $db;
828 * @param $title, the page these events apply to
829 * @param array $items list of revision ID numbers
830 * @param int $bitfield new rev_deleted value
831 * @param string $comment Comment for log records
833 function setRevVisibility( $title, $items, $bitfield, $comment ) {
834 global $wgOut;
836 $userAllowedAll = $success = true;
837 $revIDs = array();
838 $revCount = 0;
839 // Run through and pull all our data in one query
840 foreach( $items as $revid ) {
841 $where[] = intval($revid);
843 $result = $this->dbw->select( 'revision', '*',
844 array(
845 'rev_page' => $title->getArticleID(),
846 'rev_id' => $where ),
847 __METHOD__ );
848 while( $row = $this->dbw->fetchObject( $result ) ) {
849 $revObjs[$row->rev_id] = new Revision( $row );
851 // To work!
852 foreach( $items as $revid ) {
853 if( !isset($revObjs[$revid]) || $revObjs[$revid]->isCurrent() ) {
854 $success = false;
855 continue; // Must exist
856 } else if( !$revObjs[$revid]->userCan(Revision::DELETED_RESTRICTED) ) {
857 $userAllowedAll=false;
858 continue;
860 // For logging, maintain a count of revisions
861 if( $revObjs[$revid]->mDeleted != $bitfield ) {
862 $revCount++;
863 $revIDs[]=$revid;
865 $this->updateRevision( $revObjs[$revid], $bitfield );
866 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
869 // Clear caches...
870 // Don't log or touch if nothing changed
871 if( $revCount > 0 ) {
872 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted,
873 $comment, $title, 'oldid', $revIDs );
874 $this->updatePage( $title );
876 // Where all revs allowed to be set?
877 if( !$userAllowedAll ) {
878 //FIXME: still might be confusing???
879 $wgOut->permissionRequired( 'suppressrevision' );
880 return false;
883 return $success;
887 * @param $title, the page these events apply to
888 * @param array $items list of revision ID numbers
889 * @param int $bitfield new rev_deleted value
890 * @param string $comment Comment for log records
892 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
893 global $wgOut;
895 $userAllowedAll = $success = true;
896 $count = 0;
897 $Id_set = array();
898 // Run through and pull all our data in one query
899 foreach( $items as $timestamp ) {
900 $where[] = $this->dbw->timestamp( $timestamp );
902 $result = $this->dbw->select( 'archive', '*',
903 array(
904 'ar_namespace' => $title->getNamespace(),
905 'ar_title' => $title->getDBKey(),
906 'ar_timestamp' => $where ),
907 __METHOD__ );
908 while( $row = $this->dbw->fetchObject( $result ) ) {
909 $timestamp = wfTimestamp( TS_MW, $row->ar_timestamp );
910 $revObjs[$timestamp] = new Revision( array(
911 'page' => $title->getArticleId(),
912 'id' => $row->ar_rev_id,
913 'text' => $row->ar_text_id,
914 'comment' => $row->ar_comment,
915 'user' => $row->ar_user,
916 'user_text' => $row->ar_user_text,
917 'timestamp' => $timestamp,
918 'minor_edit' => $row->ar_minor_edit,
919 'text_id' => $row->ar_text_id,
920 'deleted' => $row->ar_deleted,
921 'len' => $row->ar_len) );
923 // To work!
924 foreach( $items as $timestamp ) {
925 // This will only select the first revision with this timestamp.
926 // Since they are all selected/deleted at once, we can just check the
927 // permissions of one. UPDATE is done via timestamp, so all revs are set.
928 if( !is_object($revObjs[$timestamp]) ) {
929 $success = false;
930 continue; // Must exist
931 } else if( !$revObjs[$timestamp]->userCan(Revision::DELETED_RESTRICTED) ) {
932 $userAllowedAll=false;
933 continue;
935 // Which revisions did we change anything about?
936 if( $revObjs[$timestamp]->mDeleted != $bitfield ) {
937 $Id_set[]=$timestamp;
938 $count++;
940 $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
943 // For logging, maintain a count of revisions
944 if( $count > 0 ) {
945 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted,
946 $comment, $title, 'artimestamp', $Id_set );
948 // Where all revs allowed to be set?
949 if( !$userAllowedAll ) {
950 $wgOut->permissionRequired( 'suppressrevision' );
951 return false;
954 return $success;
958 * @param $title, the page these events apply to
959 * @param array $items list of revision ID numbers
960 * @param int $bitfield new rev_deleted value
961 * @param string $comment Comment for log records
963 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
964 global $wgOut;
966 $userAllowedAll = $success = true;
967 $count = 0;
968 $set = array();
969 // Run through and pull all our data in one query
970 foreach( $items as $timestamp ) {
971 $where[] = $timestamp.'!'.$title->getDBKey();
973 $result = $this->dbw->select( 'oldimage', '*',
974 array(
975 'oi_name' => $title->getDBKey(),
976 'oi_archive_name' => $where ),
977 __METHOD__ );
978 while( $row = $this->dbw->fetchObject( $result ) ) {
979 $filesObjs[$row->oi_archive_name] = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
980 $filesObjs[$row->oi_archive_name]->user = $row->oi_user;
981 $filesObjs[$row->oi_archive_name]->user_text = $row->oi_user_text;
983 // To work!
984 foreach( $items as $timestamp ) {
985 $archivename = $timestamp.'!'.$title->getDBKey();
986 if( !isset($filesObjs[$archivename]) ) {
987 $success = false;
988 continue; // Must exist
989 } else if( !$filesObjs[$archivename]->userCan(File::DELETED_RESTRICTED) ) {
990 $userAllowedAll=false;
991 continue;
994 $transaction = true;
995 // Which revisions did we change anything about?
996 if( $filesObjs[$archivename]->deleted != $bitfield ) {
997 $count++;
999 $this->dbw->begin();
1000 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
1001 // If this image is currently hidden...
1002 if( $filesObjs[$archivename]->deleted & File::DELETED_FILE ) {
1003 if( $bitfield & File::DELETED_FILE ) {
1004 # Leave it alone if we are not changing this...
1005 $set[]=$archivename;
1006 $transaction = true;
1007 } else {
1008 # We are moving this out
1009 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
1010 $set[]=$transaction;
1012 // Is it just now becoming hidden?
1013 } else if( $bitfield & File::DELETED_FILE ) {
1014 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
1015 $set[]=$transaction;
1016 } else {
1017 $set[]=$timestamp;
1019 // If our file operations fail, then revert back the db
1020 if( $transaction==false ) {
1021 $this->dbw->rollback();
1022 return false;
1024 $this->dbw->commit();
1028 // Log if something was changed
1029 if( $count > 0 ) {
1030 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted,
1031 $comment, $title, 'oldimage', $set );
1032 # Purge page/history
1033 $file = wfLocalFile( $title );
1034 $file->purgeCache();
1035 $file->purgeHistory();
1036 # Invalidate cache for all pages using this file
1037 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
1038 $update->doUpdate();
1040 // Where all revs allowed to be set?
1041 if( !$userAllowedAll ) {
1042 $wgOut->permissionRequired( 'suppressrevision' );
1043 return false;
1046 return $success;
1050 * @param $title, the page these events apply to
1051 * @param array $items list of revision ID numbers
1052 * @param int $bitfield new rev_deleted value
1053 * @param string $comment Comment for log records
1055 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
1056 global $wgOut;
1058 $userAllowedAll = $success = true;
1059 $count = 0;
1060 $Id_set = array();
1062 // Run through and pull all our data in one query
1063 foreach( $items as $id ) {
1064 $where[] = intval($id);
1066 $result = $this->dbw->select( 'filearchive', '*',
1067 array( 'fa_name' => $title->getDBKey(),
1068 'fa_id' => $where ),
1069 __METHOD__ );
1070 while( $row = $this->dbw->fetchObject( $result ) ) {
1071 $filesObjs[$row->fa_id] = ArchivedFile::newFromRow( $row );
1073 // To work!
1074 foreach( $items as $fileid ) {
1075 if( !isset($filesObjs[$fileid]) ) {
1076 $success = false;
1077 continue; // Must exist
1078 } else if( !$filesObjs[$fileid]->userCan(File::DELETED_RESTRICTED) ) {
1079 $userAllowedAll=false;
1080 continue;
1082 // Which revisions did we change anything about?
1083 if( $filesObjs[$fileid]->deleted != $bitfield ) {
1084 $Id_set[]=$fileid;
1085 $count++;
1087 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1090 // Log if something was changed
1091 if( $count > 0 ) {
1092 $this->updateLog( $title, $count, $bitfield, $comment,
1093 $filesObjs[$fileid]->deleted, $title, 'fileid', $Id_set );
1095 // Where all revs allowed to be set?
1096 if( !$userAllowedAll ) {
1097 $wgOut->permissionRequired( 'suppressrevision' );
1098 return false;
1101 return $success;
1105 * @param $title, the log page these events apply to
1106 * @param array $items list of log ID numbers
1107 * @param int $bitfield new log_deleted value
1108 * @param string $comment Comment for log records
1110 function setEventVisibility( $title, $items, $bitfield, $comment ) {
1111 global $wgOut;
1113 $userAllowedAll = $success = true;
1114 $count = 0;
1115 $log_Ids = array();
1117 // Run through and pull all our data in one query
1118 foreach( $items as $logid ) {
1119 $where[] = intval($logid);
1121 list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
1122 $result = $this->dbw->select( 'logging', '*',
1123 array(
1124 'log_type' => $logtype,
1125 'log_id' => $where ),
1126 __METHOD__ );
1127 while( $row = $this->dbw->fetchObject( $result ) ) {
1128 $logRows[$row->log_id] = $row;
1130 // To work!
1131 foreach( $items as $logid ) {
1132 if( !isset($logRows[$logid]) ) {
1133 $success = false;
1134 continue; // Must exist
1135 } else if( !LogEventsList::userCan($logRows[$logid], LogPage::DELETED_RESTRICTED)
1136 || $logRows[$logid]->log_type == 'suppress' ) {
1137 // Don't hide from oversight log!!!
1138 $userAllowedAll=false;
1139 continue;
1141 // Which logs did we change anything about?
1142 if( $logRows[$logid]->log_deleted != $bitfield ) {
1143 $log_Ids[]=$logid;
1144 $count++;
1146 $this->updateLogs( $logRows[$logid], $bitfield );
1147 $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
1150 // Don't log or touch if nothing changed
1151 if( $count > 0 ) {
1152 $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted,
1153 $comment, $title, 'logid', $log_Ids );
1155 // Were all revs allowed to be set?
1156 if( !$userAllowedAll ) {
1157 $wgOut->permissionRequired( 'suppressrevision' );
1158 return false;
1161 return $success;
1165 * Moves an image to a safe private location
1166 * Caller is responsible for clearing caches
1167 * @param File $oimage
1168 * @returns mixed, timestamp string on success, false on failure
1170 function makeOldImagePrivate( $oimage ) {
1171 $transaction = new FSTransaction();
1172 if( !FileStore::lock() ) {
1173 wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" );
1174 return false;
1176 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR . $oimage->archive_name;
1177 // Dupe the file into the file store
1178 if( file_exists( $oldpath ) ) {
1179 // Is our directory configured?
1180 if( $store = FileStore::get( 'deleted' ) ) {
1181 if( !$oimage->sha1 ) {
1182 $oimage->upgradeRow(); // sha1 may be missing
1184 $key = $oimage->sha1 . '.' . $oimage->getExtension();
1185 $transaction->add( $store->insert( $key, $oldpath, FileStore::DELETE_ORIGINAL ) );
1186 } else {
1187 $group = null;
1188 $key = null;
1189 $transaction = false; // Return an error and do nothing
1191 } else {
1192 wfDebug( __METHOD__." deleting already-missing '$oldpath'; moving on to database\n" );
1193 $group = null;
1194 $key = '';
1195 $transaction = new FSTransaction(); // empty
1198 if( $transaction === false ) {
1199 // Fail to restore?
1200 wfDebug( __METHOD__.": import to file store failed, aborting\n" );
1201 throw new MWException( "Could not archive and delete file $oldpath" );
1202 return false;
1205 wfDebug( __METHOD__.": set db items, applying file transactions\n" );
1206 $transaction->commit();
1207 FileStore::unlock();
1209 $m = explode('!',$oimage->archive_name,2);
1210 $timestamp = $m[0];
1212 return $timestamp;
1216 * Moves an image from a safe private location
1217 * Caller is responsible for clearing caches
1218 * @param File $oimage
1219 * @returns mixed, string timestamp on success, false on failure
1221 function makeOldImagePublic( $oimage ) {
1222 $transaction = new FSTransaction();
1223 if( !FileStore::lock() ) {
1224 wfDebug( __METHOD__." could not acquire filestore lock\n" );
1225 return false;
1228 $store = FileStore::get( 'deleted' );
1229 if( !$store ) {
1230 wfDebug( __METHOD__.": skipping row with no file.\n" );
1231 return false;
1234 $key = $oimage->sha1.'.'.$oimage->getExtension();
1235 $destDir = $oimage->getArchivePath();
1236 if( !is_dir( $destDir ) ) {
1237 wfMkdirParents( $destDir );
1239 $destPath = $destDir . DIRECTORY_SEPARATOR . $oimage->archive_name;
1240 // Check if any other stored revisions use this file;
1241 // if so, we shouldn't remove the file from the hidden
1242 // archives so they will still work. Check hidden files first.
1243 $useCount = $this->dbw->selectField( 'oldimage', '1',
1244 array( 'oi_sha1' => $oimage->sha1,
1245 'oi_deleted & '.File::DELETED_FILE => File::DELETED_FILE ),
1246 __METHOD__, array( 'FOR UPDATE' ) );
1247 // Check the rest of the deleted archives too.
1248 // (these are the ones that don't show in the image history)
1249 if( !$useCount ) {
1250 $useCount = $this->dbw->selectField( 'filearchive', '1',
1251 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1252 __METHOD__, array( 'FOR UPDATE' ) );
1255 if( $useCount == 0 ) {
1256 wfDebug( __METHOD__.": nothing else using {$oimage->sha1}, will deleting after\n" );
1257 $flags = FileStore::DELETE_ORIGINAL;
1258 } else {
1259 $flags = 0;
1261 $transaction->add( $store->export( $key, $destPath, $flags ) );
1263 wfDebug( __METHOD__.": set db items, applying file transactions\n" );
1264 $transaction->commit();
1265 FileStore::unlock();
1267 $m = explode('!',$oimage->archive_name,2);
1268 $timestamp = $m[0];
1270 return $timestamp;
1274 * Update the revision's rev_deleted field
1275 * @param Revision $rev
1276 * @param int $bitfield new rev_deleted bitfield value
1278 function updateRevision( $rev, $bitfield ) {
1279 $this->dbw->update( 'revision',
1280 array( 'rev_deleted' => $bitfield ),
1281 array( 'rev_id' => $rev->getId(),
1282 'rev_page' => $rev->getPage() ),
1283 __METHOD__ );
1287 * Update the revision's rev_deleted field
1288 * @param Revision $rev
1289 * @param Title $title
1290 * @param int $bitfield new rev_deleted bitfield value
1292 function updateArchive( $rev, $title, $bitfield ) {
1293 $this->dbw->update( 'archive',
1294 array( 'ar_deleted' => $bitfield ),
1295 array( 'ar_namespace' => $title->getNamespace(),
1296 'ar_title' => $title->getDBKey(),
1297 'ar_timestamp' => $this->dbw->timestamp( $rev->getTimestamp() ),
1298 'ar_rev_id' => $rev->getId() ),
1299 __METHOD__ );
1303 * Update the images's oi_deleted field
1304 * @param File $file
1305 * @param int $bitfield new rev_deleted bitfield value
1307 function updateOldFiles( $file, $bitfield ) {
1308 $this->dbw->update( 'oldimage',
1309 array( 'oi_deleted' => $bitfield ),
1310 array( 'oi_name' => $file->getName(),
1311 'oi_timestamp' => $this->dbw->timestamp( $file->getTimestamp() ) ),
1312 __METHOD__ );
1316 * Update the images's fa_deleted field
1317 * @param ArchivedFile $file
1318 * @param int $bitfield new rev_deleted bitfield value
1320 function updateArchFiles( $file, $bitfield ) {
1321 $this->dbw->update( 'filearchive',
1322 array( 'fa_deleted' => $bitfield ),
1323 array( 'fa_id' => $file->getId() ),
1324 __METHOD__ );
1328 * Update the logging log_deleted field
1329 * @param Row $row
1330 * @param int $bitfield new rev_deleted bitfield value
1332 function updateLogs( $row, $bitfield ) {
1333 $this->dbw->update( 'logging',
1334 array( 'log_deleted' => $bitfield ),
1335 array( 'log_id' => $row->log_id ),
1336 __METHOD__ );
1340 * Update the revision's recentchanges record if fields have been hidden
1341 * @param Revision $rev
1342 * @param int $bitfield new rev_deleted bitfield value
1344 function updateRecentChangesEdits( $rev, $bitfield ) {
1345 $this->dbw->update( 'recentchanges',
1346 array( 'rc_deleted' => $bitfield,
1347 'rc_patrolled' => 1 ),
1348 array( 'rc_this_oldid' => $rev->getId(),
1349 'rc_timestamp' => $this->dbw->timestamp( $rev->getTimestamp() ) ),
1350 __METHOD__ );
1354 * Update the revision's recentchanges record if fields have been hidden
1355 * @param Row $row
1356 * @param int $bitfield new rev_deleted bitfield value
1358 function updateRecentChangesLog( $row, $bitfield ) {
1359 $this->dbw->update( 'recentchanges',
1360 array( 'rc_deleted' => $bitfield,
1361 'rc_patrolled' => 1 ),
1362 array( 'rc_logid' => $row->log_id,
1363 'rc_timestamp' => $row->log_timestamp ),
1364 __METHOD__ );
1368 * Touch the page's cache invalidation timestamp; this forces cached
1369 * history views to refresh, so any newly hidden or shown fields will
1370 * update properly.
1371 * @param Title $title
1373 function updatePage( $title ) {
1374 $title->invalidateCache();
1375 $title->purgeSquid();
1376 $title->touchLinks();
1377 // Extensions that require referencing previous revisions may need this
1378 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1382 * Checks for a change in the bitfield for a certain option and updates the
1383 * provided array accordingly.
1385 * @param String $desc Description to add to the array if the option was
1386 * enabled / disabled.
1387 * @param int $field The bitmask describing the single option.
1388 * @param int $diff The xor of the old and new bitfields.
1389 * @param array $arr The array to update.
1391 function checkItem ( $desc, $field, $diff, $new, &$arr ) {
1392 if ( $diff & $field ) {
1393 $arr [ ( $new & $field ) ? 0 : 1 ][] = $desc;
1398 * Gets an array describing the changes made to the visibilit of the revision.
1399 * If the resulting array is $arr, then $arr[0] will contain an array of strings
1400 * describing the items that were hidden, $arr[2] will contain an array of strings
1401 * describing the items that were unhidden, and $arr[3] will contain an array with
1402 * a single string, which can be one of "applied restrictions to sysops",
1403 * "removed restrictions from sysops", or null.
1405 * @param int $n The new bitfield.
1406 * @param int $o The old bitfield.
1407 * @return An array as described above.
1409 function getChanges ( $n, $o ) {
1410 $diff = $n ^ $o;
1411 $ret = array ( 0 => array(), 1 => array(), 2 => array() );
1413 $this->checkItem ( wfMsgForContent ( 'revdelete-content' ),
1414 Revision::DELETED_TEXT, $diff, $n, $ret );
1415 $this->checkItem ( wfMsgForContent ( 'revdelete-summary' ),
1416 Revision::DELETED_COMMENT, $diff, $n, $ret );
1417 $this->checkItem ( wfMsgForContent ( 'revdelete-uname' ),
1418 Revision::DELETED_USER, $diff, $n, $ret );
1420 // Restriction application to sysops
1421 if ( $diff & Revision::DELETED_RESTRICTED ) {
1422 if ( $n & Revision::DELETED_RESTRICTED )
1423 $ret[2][] = wfMsgForContent ( 'revdelete-restricted' );
1424 else
1425 $ret[2][] = wfMsgForContent ( 'revdelete-unrestricted' );
1428 return $ret;
1432 * Gets a log message to describe the given revision visibility change. This
1433 * message will be of the form "[hid {content, edit summary, username}];
1434 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
1436 * @param int $count The number of effected revisions.
1437 * @param int $nbitfield The new bitfield for the revision.
1438 * @param int $obitfield The old bitfield for the revision.
1439 * @param string $comment The comment associated with the change.
1440 * @param bool $isForLog
1442 function getLogMessage ( $count, $nbitfield, $obitfield, $comment, $isForLog = false ) {
1443 global $wgContLang;
1445 $s = '';
1446 $changes = $this->getChanges( $nbitfield, $obitfield );
1448 if ( count ( $changes[0] ) ) {
1449 $s .= wfMsgForContent ( 'revdelete-hid', implode ( ', ', $changes[0] ) );
1452 if ( count ( $changes[1] ) ) {
1453 if ($s) $s .= '; ';
1455 $s .= wfMsgForContent ( 'revdelete-unhid', implode ( ', ', $changes[1] ) );
1458 if ( count ( $changes[2] )) {
1459 if ($s)
1460 $s .= ' (' . $changes[2][0] . ')';
1461 else
1462 $s = $changes[2][0];
1465 $msg = $isForLog ? 'logdelete-log-message' : 'revdelete-log-message';
1466 $ret = wfMsgExt ( $msg, array( 'parsemag', 'content' ),
1467 $s, $wgContLang->formatNum( $count ) );
1469 if ( $comment )
1470 $ret .= ": $comment";
1472 return $ret;
1477 * Record a log entry on the action
1478 * @param Title $title, page where item was removed from
1479 * @param int $count the number of revisions altered for this page
1480 * @param int $nbitfield the new _deleted value
1481 * @param int $obitfield the old _deleted value
1482 * @param string $comment
1483 * @param Title $target, the relevant page
1484 * @param string $param, URL param
1485 * @param Array $items
1487 function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target, $param, $items = array() ) {
1488 // Put things hidden from sysops in the oversight log
1489 $logtype = ( ($nbitfield | $obitfield) & Revision::DELETED_RESTRICTED ) ? 'suppress' : 'delete';
1490 $log = new LogPage( $logtype );
1492 $reason = $this->getLogMessage ( $count, $nbitfield, $obitfield, $comment, $param == 'logid' );
1494 if( $param == 'logid' ) {
1495 $params = array( implode( ',', $items) );
1496 $log->addEntry( 'event', $title, $reason, $params );
1497 } else {
1498 // Add params for effected page and ids
1499 $params = array( $param, implode( ',', $items) );
1500 $log->addEntry( 'revision', $title, $reason, $params );