* Add a nice fieldset around the input form
[mediawiki.git] / includes / SpecialRevisiondelete.php
blob4c337893eb4fc02b4a396ae4e588db6dbb5ba05d
1 <?php
3 /**
4 * Special page allowing users with the appropriate permissions to view
5 * and hide revisions. Log items can also be hidden.
7 * @addtogroup SpecialPage
8 */
10 function wfSpecialRevisiondelete( $par = null ) {
11 global $wgOut, $wgRequest, $wgUser;
12 # Handle our many different possible input types
13 $target = $wgRequest->getText( 'target' );
14 $oldid = $wgRequest->getArray( 'oldid' );
15 $artimestamp = $wgRequest->getArray( 'artimestamp' );
16 $logid = $wgRequest->getArray( 'logid' );
17 $img = $wgRequest->getArray( 'oldimage' );
18 $fileid = $wgRequest->getArray( 'fileid' );
19 # For reviewing deleted files...
20 $file = $wgRequest->getVal( 'file' );
21 # If this is a revision, then we need a target page
22 $page = Title::newFromUrl( $target );
23 if( is_null($page) ) {
24 $wgOut->addWikiText( wfMsgHtml( 'undelete-header' ) );
25 return;
27 # Only one target set at a time please!
28 $i = (bool)$file + (bool)$oldid + (bool)$logid + (bool)$artimestamp + (bool)$fileid + (bool)$img;
29 if( $i !== 1 ) {
30 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
31 return;
33 # Logs must have a type given
34 if( $logid && !strpos($page->getDBKey(),'/') ) {
35 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
36 return;
38 # Either submit or create our form
39 $form = new RevisionDeleteForm( $page, $oldid, $logid, $artimestamp, $fileid, $img, $file );
40 if( $wgRequest->wasPosted() ) {
41 $form->submit( $wgRequest );
42 } else if( $oldid || $artimestamp ) {
43 $form->showRevs( $wgRequest );
44 } else if( $fileid || $img ) {
45 $form->showImages( $wgRequest );
46 } else if( $logid ) {
47 $form->showLogItems( $wgRequest );
49 # Show relevant lines from the deletion log. This will show even if said ID
50 # does not exist...might be helpful
51 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
52 LogEventsList::showLogExtract( $wgOut, 'delete', $page->getPrefixedText() );
53 if( $wgUser->isAllowed( 'suppress' ) ){
54 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'suppress' ) ) . "</h2>\n" );
55 LogEventsList::showLogExtract( $wgOut, 'suppress', $page->getPrefixedText() );
59 /**
60 * Implements the GUI for Revision Deletion.
61 * @addtogroup SpecialPage
63 class RevisionDeleteForm {
64 /**
65 * @param Title $page
66 * @param array $oldids
67 * @param array $logids
68 * @param array $artimestamps
69 * @param array $fileids
70 * @param array $img
71 * @param string $file
73 function __construct( $page, $oldids, $logids, $artimestamps, $fileids, $img, $file ) {
74 global $wgUser, $wgOut;
76 $this->page = $page;
77 # For reviewing deleted files...
78 if( $file ) {
79 $oimage = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $page, $file );
80 $oimage->load();
81 // Check if user is allowed to see this file
82 if( !$oimage->userCan(File::DELETED_FILE) ) {
83 $wgOut->permissionRequired( 'hiderevision' );
84 } else {
85 $this->showFile( $file );
87 return;
89 $this->skin = $wgUser->getSkin();
90 # Give a link to the log for this page
91 if( !is_null($this->page) && $this->page->getNamespace() > -1 ) {
92 $links = array();
94 $logtitle = SpecialPage::getTitleFor( 'Log' );
95 $links[] = $this->skin->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
96 wfArrayToCGI( array( 'page' => $this->page->getPrefixedUrl() ) ) );
97 # Give a link to the page history
98 $links[] = $this->skin->makeKnownLinkObj( $this->page, wfMsgHtml( 'pagehist' ),
99 wfArrayToCGI( array( 'action' => 'history' ) ) );
100 # Link to deleted edits
101 if( $wgUser->isAllowed('undelete') ) {
102 $undelete = SpecialPage::getTitleFor( 'Undelete' );
103 $links[] = $this->skin->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
104 wfArrayToCGI( array( 'target' => $this->page->getPrefixedUrl() ) ) );
106 # Logs themselves don't have histories or archived revisions
107 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
109 // At this point, we should only have one of these
110 if( $oldids ) {
111 $this->revisions = $oldids;
112 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision::DELETED_TEXT );
113 $this->deleteKey='oldid';
114 } else if( $artimestamps ) {
115 $this->archrevs = $artimestamps;
116 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision::DELETED_TEXT );
117 $this->deleteKey='artimestamp';
118 } else if( $img ) {
119 $this->ofiles = $img;
120 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File::DELETED_FILE );
121 $this->deleteKey='oldimage';
122 } else if( $fileids ) {
123 $this->afiles = $fileids;
124 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File::DELETED_FILE );
125 $this->deleteKey='fileid';
126 } else if( $logids ) {
127 $this->events = $logids;
128 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage::DELETED_ACTION );
129 $this->deleteKey='logid';
131 // Our checkbox messages depends one what we are doing,
132 // e.g. we don't hide "text" for logs or images
133 $this->checks = array(
134 $hide_content_name,
135 array( 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ),
136 array( 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER ),
137 array( 'revdelete-hide-restricted', 'wpHideRestricted', Revision::DELETED_RESTRICTED ) );
141 * Show a deleted file version requested by the visitor.
143 private function showFile( $key ) {
144 global $wgOut, $wgRequest;
145 $wgOut->disable();
147 # We mustn't allow the output to be Squid cached, otherwise
148 # if an admin previews a deleted image, and it's cached, then
149 # a user without appropriate permissions can toddle off and
150 # nab the image, and Squid will serve it
151 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
152 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
153 $wgRequest->response()->header( 'Pragma: no-cache' );
155 $store = FileStore::get( 'deleted' );
156 $store->stream( $key );
160 * This lets a user set restrictions for live and archived revisions
161 * @param WebRequest $request
163 function showRevs( $request ) {
164 global $wgOut, $wgUser, $action;
166 $UserAllowed = true;
168 $count = ($this->deleteKey=='oldid') ?
169 count($this->revisions) : count($this->archrevs);
170 $wgOut->addWikiMsg( 'revdelete-selected', $this->page->getPrefixedText(), $count );
172 $bitfields = 0;
173 $wgOut->addHtml( "<ul>" );
175 $where = $revObjs = array();
176 $dbr = wfGetDB( DB_SLAVE );
178 $revisions = 0;
179 // Live revisions...
180 if( $this->deleteKey=='oldid' ) {
181 // Run through and pull all our data in one query
182 foreach( $this->revisions as $revid ) {
183 $where[] = intval($revid);
185 $whereClause = 'rev_id IN(' . implode(',',$where) . ')';
186 $result = $dbr->select( array('revision','page'), '*',
187 array( 'rev_page' => $this->page->getArticleID(),
188 $whereClause, 'rev_page = page_id' ),
189 __METHOD__ );
190 while( $row = $dbr->fetchObject( $result ) ) {
191 $revObjs[$row->rev_id] = new Revision( $row );
193 foreach( $this->revisions as $revid ) {
194 // Hiding top revisison is bad
195 if( !isset($revObjs[$revid]) || $revObjs[$revid]->isCurrent() ) {
196 continue;
197 } else if( !$revObjs[$revid]->userCan(Revision::DELETED_RESTRICTED) ) {
198 // If a rev is hidden from sysops
199 if( $action != 'submit') {
200 $wgOut->permissionRequired( 'hiderevision' );
201 return;
203 $UserAllowed = false;
205 $revisions++;
206 $wgOut->addHtml( $this->historyLine( $revObjs[$revid] ) );
207 $bitfields |= $revObjs[$revid]->mDeleted;
209 // The archives...
210 } else {
211 // Run through and pull all our data in one query
212 foreach( $this->archrevs as $timestamp ) {
213 $where[] = $dbr->addQuotes( $timestamp );
215 $whereClause = 'ar_timestamp IN(' . implode(',',$where) . ')';
216 $result = $dbr->select( 'archive', '*',
217 array( 'ar_namespace' => $this->page->getNamespace(),
218 'ar_title' => $this->page->getDBKey(),
219 $whereClause ),
220 __METHOD__ );
221 while( $row = $dbr->fetchObject( $result ) ) {
222 $revObjs[$row->ar_timestamp] = new Revision( array(
223 'page' => $this->page->getArticleId(),
224 'id' => $row->ar_rev_id,
225 'text' => $row->ar_text_id,
226 'comment' => $row->ar_comment,
227 'user' => $row->ar_user,
228 'user_text' => $row->ar_user_text,
229 'timestamp' => $row->ar_timestamp,
230 'minor_edit' => $row->ar_minor_edit,
231 'text_id' => $row->ar_text_id,
232 'deleted' => $row->ar_deleted,
233 'len' => $row->ar_len) );
235 foreach( $this->archrevs as $timestamp ) {
236 if( !isset($revObjs[$timestamp]) ) {
237 continue;
238 } else if( !$revObjs[$timestamp]->userCan(Revision::DELETED_RESTRICTED) ) {
239 // If a rev is hidden from sysops
240 if( $action != 'submit') {
241 $wgOut->permissionRequired( 'hiderevision' );
242 return;
244 $UserAllowed = false;
246 $revisions++;
247 $wgOut->addHtml( $this->historyLine( $revObjs[$timestamp] ) );
248 $bitfields |= $revObjs[$timestamp]->mDeleted;
251 if( !$revisions ) {
252 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
253 return;
256 $wgOut->addHtml( "</ul>" );
258 $wgOut->addWikiText( wfMsgHtml( 'revdelete-text' ) );
260 // Normal sysops can always see what they did, but can't always change it
261 if( !$UserAllowed ) return;
263 $items = array(
264 Xml::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
265 Xml::submitButton( wfMsg( 'revdelete-submit' ) )
267 $hidden = array(
268 Xml::hidden( 'wpEditToken', $wgUser->editToken() ),
269 Xml::hidden( 'target', $this->page->getPrefixedText() ),
270 Xml::hidden( 'type', $this->deleteKey )
272 if( $this->deleteKey=='oldid' ) {
273 foreach( $revObjs as $rev )
274 $hidden[] = wfHidden( 'oldid[]', $rev->getID() );
275 } else {
276 foreach( $revObjs as $rev )
277 $hidden[] = wfHidden( 'artimestamp[]', $rev->getTimestamp() );
279 $special = SpecialPage::getTitleFor( 'Revisiondelete' );
280 $wgOut->addHtml(
281 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
282 'id' => 'mw-revdel-form-revisions' ) ) .
283 Xml::openElement( 'fieldset' ) .
284 xml::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
286 // FIXME: all items checked for just one rev are checked, even if not set for the others
287 foreach( $this->checks as $item ) {
288 list( $message, $name, $field ) = $item;
289 $wgOut->addHtml( Xml::tags( 'div', null, Xml::checkLabel( wfMsg( $message ), $name, $name, $bitfields & $field ) ) );
291 foreach( $items as $item ) {
292 $wgOut->addHtml( Xml::tags( 'p', null, $item ) );
294 foreach( $hidden as $item ) {
295 $wgOut->addHtml( $item );
297 $wgOut->addHtml(
298 Xml::closeElement( 'fieldset' ) .
299 Xml::closeElement( 'form' ) . "\n"
305 * This lets a user set restrictions for archived images
306 * @param WebRequest $request
308 function showImages( $request ) {
309 global $wgOut, $wgUser, $action;
311 $UserAllowed = true;
313 $count = ($this->deleteKey=='oldimage') ? count($this->ofiles) : count($this->afiles);
314 $wgOut->addWikiText( wfMsgExt( 'revdelete-selected', array('parsemag'),
315 $this->page->getPrefixedText(), $count ) );
317 $bitfields = 0;
318 $wgOut->addHtml( "<ul>" );
320 $where = $filesObjs = array();
321 $dbr = wfGetDB( DB_SLAVE );
322 // Live old revisions...
323 $revisions = 0;
324 if( $this->deleteKey=='oldimage' ) {
325 // Run through and pull all our data in one query
326 foreach( $this->ofiles as $timestamp ) {
327 $where[] = $dbr->addQuotes( $timestamp.'!'.$this->page->getDbKey() );
329 $whereClause = 'oi_archive_name IN(' . implode(',',$where) . ')';
330 $result = $dbr->select( 'oldimage', '*',
331 array( 'oi_name' => $this->page->getDbKey(),
332 $whereClause ),
333 __METHOD__ );
334 while( $row = $dbr->fetchObject( $result ) ) {
335 $filesObjs[$row->oi_archive_name] = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
336 $filesObjs[$row->oi_archive_name]->user = $row->oi_user;
337 $filesObjs[$row->oi_archive_name]->user_text = $row->oi_user_text;
339 // Check through our images
340 foreach( $this->ofiles as $timestamp ) {
341 $archivename = $timestamp.'!'.$this->page->getDbKey();
342 if( !isset($filesObjs[$archivename]) ) {
343 continue;
344 } else if( !$filesObjs[$archivename]->userCan(File::DELETED_RESTRICTED) ) {
345 // If a rev is hidden from sysops
346 if( $action != 'submit' ) {
347 $wgOut->permissionRequired( 'hiderevision' );
348 return;
350 $UserAllowed = false;
352 $revisions++;
353 // Inject history info
354 $wgOut->addHtml( $this->fileLine( $filesObjs[$archivename] ) );
355 $bitfields |= $filesObjs[$archivename]->deleted;
357 // Archived files...
358 } else {
359 // Run through and pull all our data in one query
360 foreach( $this->afiles as $id ) {
361 $where[] = intval($id);
363 $whereClause = 'fa_id IN(' . implode(',',$where) . ')';
364 $result = $dbr->select( 'filearchive', '*',
365 array( 'fa_name' => $this->page->getDbKey(),
366 $whereClause ),
367 __METHOD__ );
368 while( $row = $dbr->fetchObject( $result ) ) {
369 $filesObjs[$row->fa_id] = ArchivedFile::newFromRow( $row );
372 foreach( $this->afiles as $fileid ) {
373 if( !isset($filesObjs[$fileid]) ) {
374 continue;
375 } else if( !$filesObjs[$fileid]->userCan(File::DELETED_RESTRICTED) ) {
376 // If a rev is hidden from sysops
377 if( $action != 'submit' ) {
378 $wgOut->permissionRequired( 'hiderevision' );
379 return;
381 $UserAllowed = false;
383 $revisions++;
384 // Inject history info
385 $wgOut->addHtml( $this->archivedfileLine( $filesObjs[$fileid] ) );
386 $bitfields |= $filesObjs[$fileid]->deleted;
389 if( !$revisions ) {
390 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
391 return;
394 $wgOut->addHtml( "</ul>" );
396 $wgOut->addWikiText( wfMsgHtml( 'revdelete-text' ) );
397 //Normal sysops can always see what they did, but can't always change it
398 if( !$UserAllowed ) return;
400 $items = array(
401 Xml::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
402 Xml::submitButton( wfMsg( 'revdelete-submit' ) )
404 $hidden = array(
405 Xml::hidden( 'wpEditToken', $wgUser->editToken() ),
406 Xml::hidden( 'target', $this->page->getPrefixedText() ),
407 Xml::hidden( 'type', $this->deleteKey )
409 if( $this->deleteKey=='oldimage' ) {
410 foreach( $this->ofiles as $filename )
411 $hidden[] = wfHidden( 'oldimage[]', $filename );
412 } else {
413 foreach( $this->afiles as $fileid )
414 $hidden[] = wfHidden( 'fileid[]', $fileid );
416 $special = SpecialPage::getTitleFor( 'Revisiondelete' );
417 $wgOut->addHtml(
418 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
419 'id' => 'mw-revdel-form-filerevisions' ) ) .
420 Xml::openElement( 'fieldset' ) .
421 xml::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
423 // FIXME: all items checked for just one file are checked, even if not set for the others
424 foreach( $this->checks as $item ) {
425 list( $message, $name, $field ) = $item;
426 $wgOut->addHtml( Xml::tags( 'div', null, Xml::checkLabel( wfMsg( $message ), $name, $name, $bitfields & $field ) ) );
428 foreach( $items as $item ) {
429 $wgOut->addHtml( Xml::tags( 'p', null, $item ) );
431 foreach( $hidden as $item ) {
432 $wgOut->addHtml( $item );
435 $wgOut->addHtml(
436 Xml::closeElement( 'fieldset' ) .
437 Xml::closeElement( 'form' ) . "\n"
442 * This lets a user set restrictions for log items
443 * @param WebRequest $request
445 function showLogItems( $request ) {
446 global $wgOut, $wgUser, $action, $wgMessageCache;
448 $UserAllowed = true;
449 $wgOut->addWikiText( wfMsgExt( 'logdelete-selected', array('parsemag'), count($this->events) ) );
451 $bitfields = 0;
452 $wgOut->addHtml( "<ul>" );
454 $where = $logRows = array();
455 $dbr = wfGetDB( DB_SLAVE );
456 // Run through and pull all our data in one query
457 $logItems = 0;
458 foreach( $this->events as $logid ) {
459 $where[] = intval($logid);
461 list($log,$logtype) = explode( '/',$this->page->getDBKey(), 2 );
462 $whereClause = "log_type = '$logtype' AND log_id IN(" . implode(',',$where) . ")";
463 $result = $dbr->select( 'logging', '*',
464 array( $whereClause ),
465 __METHOD__ );
466 while( $row = $dbr->fetchObject( $result ) ) {
467 $logRows[$row->log_id] = $row;
469 $wgMessageCache->loadAllMessages();
470 foreach( $this->events as $logid ) {
471 // Don't hide from oversight log!!!
472 if( !isset( $logRows[$logid] ) || $logRows[$logid]->log_type=='suppress' ) {
473 continue;
474 } else if( !LogEventsList::userCan( $logRows[$logid],Revision::DELETED_RESTRICTED) ) {
475 // If an event is hidden from sysops
476 if( $action != 'submit') {
477 $wgOut->permissionRequired( 'hiderevision' );
478 return;
480 $UserAllowed = false;
482 $logItems++;
483 $wgOut->addHtml( $this->logLine( $logRows[$logid] ) );
484 $bitfields |= $logRows[$logid]->log_deleted;
486 if( !$logItems ) {
487 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
488 return;
491 $wgOut->addHtml( "</ul>" );
493 $wgOut->addWikiMsg( 'revdelete-text' );
494 // Normal sysops can always see what they did, but can't always change it
495 if( !$UserAllowed ) return;
497 $items = array(
498 Xml::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
499 Xml::submitButton( wfMsg( 'revdelete-submit' ) ) );
500 $hidden = array(
501 Xml::hidden( 'wpEditToken', $wgUser->editToken() ),
502 Xml::hidden( 'target', $this->page->getPrefixedText() ),
503 Xml::hidden( 'type', $this->deleteKey ) );
504 foreach( $this->events as $logid ) {
505 $hidden[] = Xml::hidden( 'logid[]', $logid );
508 $special = SpecialPage::getTitleFor( 'Revisiondelete' );
509 $wgOut->addHtml(
510 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
511 'id' => 'mw-revdel-form-logs' ) ) .
512 Xml::openElement( 'fieldset' ) .
513 xml::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
515 // FIXME: all items checked for just on event are checked, even if not set for the others
516 foreach( $this->checks as $item ) {
517 list( $message, $name, $field ) = $item;
518 $wgOut->addHtml( Xml::tags( 'div', null, Xml::checkLabel( wfMsg( $message ), $name, $name, $bitfields & $field ) ) );
520 foreach( $items as $item ) {
521 $wgOut->addHtml( Xml::tags( 'p', null, $item ) );
523 foreach( $hidden as $item ) {
524 $wgOut->addHtml( $item );
527 $wgOut->addHtml(
528 Xml::closeElement( 'fieldset' ) .
529 Xml::closeElement( 'form' ) . "\n"
534 * @param Revision $rev
535 * @returns string
537 private function historyLine( $rev ) {
538 global $wgContLang;
540 $date = $wgContLang->timeanddate( $rev->getTimestamp() );
541 $difflink = $del = '';
542 // Live revisions
543 if( $this->deleteKey=='oldid' ) {
544 $revlink = $this->skin->makeLinkObj( $this->page, $date, 'oldid=' . $rev->getId() );
545 $difflink = '(' . $this->skin->makeKnownLinkObj( $this->page, wfMsgHtml('diff'),
546 'diff=' . $rev->getId() . '&oldid=prev' ) . ')';
547 // Archived revisions
548 } else {
549 $undelete = SpecialPage::getTitleFor( 'Undelete' );
550 $target = $this->page->getPrefixedText();
551 $revlink = $this->skin->makeLinkObj( $undelete, $date,
552 "target=$target&timestamp=" . $rev->getTimestamp() );
553 $difflink = '(' . $this->skin->makeKnownLinkObj( $undelete, wfMsgHtml('diff'),
554 "target=$target&diff=prev&timestamp=" . $rev->getTimestamp() ) . ')';
557 if( $rev->isDeleted(Revision::DELETED_TEXT) ) {
558 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
559 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
560 if( !$rev->userCan(Revision::DELETED_TEXT) ) {
561 $revlink = '<span class="history-deleted">'.$date.'</span>';
562 $difflink = '(' . wfMsgHtml('diff') . ')';
566 return "<li> $difflink $revlink ".$this->skin->revUserLink( $rev )." ".$this->skin->revComment( $rev )."$del</li>";
570 * @param File $file
571 * @returns string
573 private function fileLine( $file ) {
574 global $wgContLang, $wgTitle;
576 $target = $this->page->getPrefixedText();
577 $date = $wgContLang->timeanddate( $file->getTimestamp(), true );
579 $del = '';
580 # Hidden files...
581 if( $file->isDeleted(File::DELETED_FILE) ) {
582 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
583 if( !$file->userCan(File::DELETED_FILE) ) {
584 $pageLink = $date;
585 } else {
586 $pageLink = $this->skin->makeKnownLinkObj( $wgTitle, $date,
587 "target=$target&file=$file->sha1.".$file->getExtension() );
589 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
590 # Regular files...
591 } else {
592 $url = $file->getUrlRel();
593 $pageLink = "<a href=\"{$url}\">{$date}</a>";
596 $data = wfMsgHtml( 'widthheight',
597 $wgContLang->formatNum( $file->getWidth() ),
598 $wgContLang->formatNum( $file->getHeight() ) ) .
599 ' (' . wfMsgHtml( 'nbytes', $wgContLang->formatNum( $file->getSize() ) ) . ')';
601 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
605 * @param ArchivedFile $file
606 * @returns string
608 private function archivedfileLine( $file ) {
609 global $wgContLang, $wgTitle;
611 $target = $this->page->getPrefixedText();
612 $date = $wgContLang->timeanddate( $file->getTimestamp(), true );
614 $undelete = SpecialPage::getTitleFor( 'Undelete' );
615 $pageLink = $this->skin->makeKnownLinkObj( $undelete, $date, "target=$target&file={$file->getKey()}" );
617 $del = '';
618 if( $file->isDeleted(File::DELETED_FILE) ) {
619 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
622 $data = wfMsgHtml( 'widthheight',
623 $wgContLang->formatNum( $file->getWidth() ),
624 $wgContLang->formatNum( $file->getHeight() ) ) .
625 ' (' . wfMsgHtml( 'nbytes', $wgContLang->formatNum( $file->getSize() ) ) . ')';
627 return "<li> $pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
631 * @param Array $row row
632 * @returns string
634 private function logLine( $row ) {
635 global $wgContLang;
637 $date = $wgContLang->timeanddate( $row->log_timestamp );
638 $paramArray = LogPage::extractParams( $row->log_params );
639 $title = Title::makeTitle( $row->log_namespace, $row->log_title );
641 $logtitle = SpecialPage::getTitleFor( 'Log' );
642 $loglink = $this->skin->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
643 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
644 // Action text
645 if( !LogEventsList::userCan($row,LogPage::DELETED_ACTION) ) {
646 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
647 } else {
648 $action = LogPage::actionText( $row->log_type, $row->log_action, $title,
649 $this->skin, $paramArray, true, true );
650 if( $row->log_deleted & LogPage::DELETED_ACTION )
651 $action = '<span class="history-deleted">' . $action . '</span>';
653 // User links
654 $userLink = $this->skin->userLink( $row->log_user, User::WhoIs($row->log_user) );
655 if( LogEventsList::isDeleted($row,LogPage::DELETED_USER) ) {
656 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
658 // Comment
659 $comment = $wgContLang->getDirMark() . $this->skin->commentBlock( $row->log_comment );
660 if( LogEventsList::isDeleted($row,LogPage::DELETED_COMMENT) ) {
661 $comment = '<span class="history-deleted">' . $comment . '</span>';
663 return "<li>($loglink) $date $userLink $action $comment</li>";
667 * Generate a user tool link cluster if the current user is allowed to view it
668 * @param ArchivedFile $file
669 * @return string HTML
671 private function fileUserTools( $file ) {
672 if( $file->userCan( Revision::DELETED_USER ) ) {
673 $link = $this->skin->userLink( $file->user, $file->user_text ) .
674 $this->skin->userToolLinks( $file->user, $file->user_text );
675 } else {
676 $link = wfMsgHtml( 'rev-deleted-user' );
678 if( $file->isDeleted( Revision::DELETED_USER ) ) {
679 return '<span class="history-deleted">' . $link . '</span>';
681 return $link;
685 * Wrap and format the given file's comment block, if the current
686 * user is allowed to view it.
688 * @param ArchivedFile $file
689 * @return string HTML
691 private function fileComment( $file ) {
692 if( $file->userCan( File::DELETED_COMMENT ) ) {
693 $block = $this->skin->commentBlock( $file->description );
694 } else {
695 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
697 if( $file->isDeleted( File::DELETED_COMMENT ) ) {
698 return "<span class=\"history-deleted\">$block</span>";
700 return $block;
704 * @param WebRequest $request
706 function submit( $request ) {
707 $bitfield = $this->extractBitfield( $request );
708 $comment = $request->getText( 'wpReason' );
710 $this->target = $request->getText( 'target' );
711 $this->title = Title::newFromURL( $this->target );
713 if( $this->save( $bitfield, $comment, $this->title ) ) {
714 $this->success( $request );
715 } else if( $request->getCheck( 'oldid' ) || $request->getCheck( 'artimestamp' ) ) {
716 return $this->showRevs( $request );
717 } else if( $request->getCheck( 'logid' ) ) {
718 return $this->showLogs( $request );
719 } else if( $request->getCheck( 'oldimage' ) || $request->getCheck( 'fileid' ) ) {
720 return $this->showImages( $request );
724 private function success( $request ) {
725 global $wgOut;
727 $wgOut->setPagetitle( wfMsgHtml( 'actioncomplete' ) );
729 if( $this->deleteKey=='logid' ) {
730 $wgOut->addWikiText( Xml::element( 'span', array( 'class' => 'success' ), wfMsg( 'logdelete-success' ) ), false );
731 $this->showLogItems( $request );
732 } else if( $this->deleteKey=='oldid' || $this->deleteKey=='artimestamp' ) {
733 $wgOut->addWikiText( Xml::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
734 $this->showRevs( $request );
735 } else if( $this->deleteKey=='fileid' ) {
736 $wgOut->addWikiText( Xml::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
737 $this->showImages( $request );
738 } else if( $this->deleteKey=='oldimage' ) {
739 $wgOut->addWikiText( Xml::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
740 $this->showImages( $request );
745 * Put together a rev_deleted bitfield from the submitted checkboxes
746 * @param WebRequest $request
747 * @return int
749 private function extractBitfield( $request ) {
750 $bitfield = 0;
751 foreach( $this->checks as $item ) {
752 list( /* message */ , $name, $field ) = $item;
753 if( $request->getCheck( $name ) ) {
754 $bitfield |= $field;
757 return $bitfield;
760 private function save( $bitfield, $reason, $title ) {
761 $dbw = wfGetDB( DB_MASTER );
762 // Don't allow simply locking the interface for no reason
763 if( $bitfield == Revision::DELETED_RESTRICTED ) {
764 $bitfield = 0;
766 $deleter = new RevisionDeleter( $dbw );
767 // By this point, only one of the below should be set
768 if( isset($this->revisions) ) {
769 return $deleter->setRevVisibility( $title, $this->revisions, $bitfield, $reason );
770 } else if( isset($this->archrevs) ) {
771 return $deleter->setArchiveVisibility( $title, $this->archrevs, $bitfield, $reason );
772 } else if( isset($this->ofiles) ) {
773 return $deleter->setOldImgVisibility( $title, $this->ofiles, $bitfield, $reason );
774 } else if( isset($this->afiles) ) {
775 return $deleter->setArchFileVisibility( $title, $this->afiles, $bitfield, $reason );
776 } else if( isset($this->events) ) {
777 return $deleter->setEventVisibility( $title, $this->events, $bitfield, $reason );
783 * Implements the actions for Revision Deletion.
784 * @addtogroup SpecialPage
786 class RevisionDeleter {
787 function __construct( $db ) {
788 $this->dbw = $db;
792 * @param $title, the page these events apply to
793 * @param array $items list of revision ID numbers
794 * @param int $bitfield new rev_deleted value
795 * @param string $comment Comment for log records
797 function setRevVisibility( $title, $items, $bitfield, $comment ) {
798 global $wgOut;
800 $userAllowedAll = $success = true;
801 $revIDs = array();
802 $revCount = 0;
803 // Run through and pull all our data in one query
804 foreach( $items as $revid ) {
805 $where[] = intval($revid);
807 $whereClause = 'rev_id IN(' . implode(',',$where) . ')';
808 $result = $this->dbw->select( 'revision', '*',
809 array( 'rev_page' => $title->getArticleID(),
810 $whereClause ),
811 __METHOD__ );
812 while( $row = $this->dbw->fetchObject( $result ) ) {
813 $revObjs[$row->rev_id] = new Revision( $row );
815 // To work!
816 foreach( $items as $revid ) {
817 if( !isset($revObjs[$revid]) || $revObjs[$revid]->isCurrent() ) {
818 $success = false;
819 continue; // Must exist
820 } else if( !$revObjs[$revid]->userCan(Revision::DELETED_RESTRICTED) ) {
821 $userAllowedAll=false;
822 continue;
824 // For logging, maintain a count of revisions
825 if( $revObjs[$revid]->mDeleted != $bitfield ) {
826 $revCount++;
827 $revIDs[]=$revid;
829 $this->updateRevision( $revObjs[$revid], $bitfield );
830 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
833 // Clear caches...
834 // Don't log or touch if nothing changed
835 if( $revCount > 0 ) {
836 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted,
837 $comment, $title, 'oldid', $revIDs );
838 $this->updatePage( $title );
840 // Where all revs allowed to be set?
841 if( !$userAllowedAll ) {
842 //FIXME: still might be confusing???
843 $wgOut->permissionRequired( 'hiderevision' );
844 return false;
847 return $success;
851 * @param $title, the page these events apply to
852 * @param array $items list of revision ID numbers
853 * @param int $bitfield new rev_deleted value
854 * @param string $comment Comment for log records
856 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
857 global $wgOut;
859 $userAllowedAll = $success = true;
860 $count = 0;
861 $Id_set = array();
862 // Run through and pull all our data in one query
863 foreach( $items as $timestamp ) {
864 $where[] = $this->dbw->addQuotes( $timestamp );
866 $whereClause = 'ar_timestamp IN(' . implode(',',$where) . ')';
867 $result = $this->dbw->select( 'archive', '*',
868 array( 'ar_namespace' => $title->getNamespace(),
869 'ar_title' => $title->getDBKey(),
870 $whereClause ),
871 __METHOD__ );
872 while( $row = $this->dbw->fetchObject( $result ) ) {
873 $revObjs[$row->ar_timestamp] = new Revision( array(
874 'page' => $title->getArticleId(),
875 'id' => $row->ar_rev_id,
876 'text' => $row->ar_text_id,
877 'comment' => $row->ar_comment,
878 'user' => $row->ar_user,
879 'user_text' => $row->ar_user_text,
880 'timestamp' => $row->ar_timestamp,
881 'minor_edit' => $row->ar_minor_edit,
882 'text_id' => $row->ar_text_id,
883 'deleted' => $row->ar_deleted,
884 'len' => $row->ar_len) );
886 // To work!
887 foreach( $items as $timestamp ) {
888 // This will only select the first revision with this timestamp.
889 // Since they are all selected/deleted at once, we can just check the
890 // permissions of one. UPDATE is done via timestamp, so all revs are set.
891 if( !is_object($revObjs[$timestamp]) ) {
892 $success = false;
893 continue; // Must exist
894 } else if( !$revObjs[$timestamp]->userCan(Revision::DELETED_RESTRICTED) ) {
895 $userAllowedAll=false;
896 continue;
898 // Which revisions did we change anything about?
899 if( $revObjs[$timestamp]->mDeleted != $bitfield ) {
900 $Id_set[]=$timestamp;
901 $count++;
903 $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
906 // For logging, maintain a count of revisions
907 if( $count > 0 ) {
908 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted,
909 $comment, $title, 'artimestamp', $Id_set );
911 // Where all revs allowed to be set?
912 if( !$userAllowedAll ) {
913 $wgOut->permissionRequired( 'hiderevision' );
914 return false;
917 return $success;
921 * @param $title, the page these events apply to
922 * @param array $items list of revision ID numbers
923 * @param int $bitfield new rev_deleted value
924 * @param string $comment Comment for log records
926 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
927 global $wgOut;
929 $userAllowedAll = $success = true;
930 $count = 0;
931 $set = array();
932 // Run through and pull all our data in one query
933 foreach( $items as $timestamp ) {
934 $where[] = $this->dbw->addQuotes( $timestamp.'!'.$title->getDbKey() );
936 $whereClause = 'oi_archive_name IN(' . implode(',',$where) . ')';
937 $result = $this->dbw->select( 'oldimage', '*',
938 array( 'oi_name' => $title->getDbKey(),
939 $whereClause ),
940 __METHOD__ );
941 while( $row = $this->dbw->fetchObject( $result ) ) {
942 $filesObjs[$row->oi_archive_name] = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
943 $filesObjs[$row->oi_archive_name]->user = $row->oi_user;
944 $filesObjs[$row->oi_archive_name]->user_text = $row->oi_user_text;
946 // To work!
947 foreach( $items as $timestamp ) {
948 $archivename = $timestamp.'!'.$title->getDbKey();
949 if( !isset($filesObjs[$archivename]) ) {
950 $success = false;
951 continue; // Must exist
952 } else if( !$filesObjs[$archivename]->userCan(File::DELETED_RESTRICTED) ) {
953 $userAllowedAll=false;
954 continue;
957 $transaction = true;
958 // Which revisions did we change anything about?
959 if( $filesObjs[$archivename]->deleted != $bitfield ) {
960 $count++;
962 $this->dbw->begin();
963 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
964 // If this image is currently hidden...
965 if( $filesObjs[$archivename]->deleted & File::DELETED_FILE ) {
966 if( $bitfield & File::DELETED_FILE ) {
967 # Leave it alone if we are not changing this...
968 $set[]=$archivename;
969 $transaction = true;
970 } else {
971 # We are moving this out
972 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
973 $set[]=$transaction;
975 // Is it just now becoming hidden?
976 } else if( $bitfield & File::DELETED_FILE ) {
977 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
978 $set[]=$transaction;
979 } else {
980 $set[]=$timestamp;
982 // If our file operations fail, then revert back the db
983 if( $transaction==false ) {
984 $this->dbw->rollback();
985 return false;
987 $this->dbw->commit();
991 // Log if something was changed
992 if( $count > 0 ) {
993 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted,
994 $comment, $title, 'oldimage', $set );
995 # Purge page/history
996 $file = wfLocalFile( $title );
997 $file->purgeCache();
998 $file->purgeHistory();
999 # Invalidate cache for all pages using this file
1000 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
1001 $update->doUpdate();
1003 // Where all revs allowed to be set?
1004 if( !$userAllowedAll ) {
1005 $wgOut->permissionRequired( 'hiderevision' );
1006 return false;
1009 return $success;
1013 * @param $title, the page these events apply to
1014 * @param array $items list of revision ID numbers
1015 * @param int $bitfield new rev_deleted value
1016 * @param string $comment Comment for log records
1018 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
1019 global $wgOut;
1021 $userAllowedAll = $success = true;
1022 $count = 0;
1023 $Id_set = array();
1025 // Run through and pull all our data in one query
1026 foreach( $items as $id ) {
1027 $where[] = intval($id);
1029 $whereClause = 'fa_id IN(' . implode(',',$where) . ')';
1030 $result = $this->dbw->select( 'filearchive', '*',
1031 array( 'fa_name' => $title->getDbKey(),
1032 $whereClause ),
1033 __METHOD__ );
1034 while( $row = $this->dbw->fetchObject( $result ) ) {
1035 $filesObjs[$row->fa_id] = ArchivedFile::newFromRow( $row );
1037 // To work!
1038 foreach( $items as $fileid ) {
1039 if( !isset($filesObjs[$fileid]) ) {
1040 $success = false;
1041 continue; // Must exist
1042 } else if( !$filesObjs[$fileid]->userCan(File::DELETED_RESTRICTED) ) {
1043 $userAllowedAll=false;
1044 continue;
1046 // Which revisions did we change anything about?
1047 if( $filesObjs[$fileid]->deleted != $bitfield ) {
1048 $Id_set[]=$fileid;
1049 $count++;
1051 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1054 // Log if something was changed
1055 if( $count > 0 ) {
1056 $this->updateLog( $title, $count, $bitfield, $comment,
1057 $filesObjs[$fileid]->deleted, $title, 'fileid', $Id_set );
1059 // Where all revs allowed to be set?
1060 if( !$userAllowedAll ) {
1061 $wgOut->permissionRequired( 'hiderevision' );
1062 return false;
1065 return $success;
1069 * @param $title, the log page these events apply to
1070 * @param array $items list of log ID numbers
1071 * @param int $bitfield new log_deleted value
1072 * @param string $comment Comment for log records
1074 function setEventVisibility( $title, $items, $bitfield, $comment ) {
1075 global $wgOut;
1077 $userAllowedAll = $success = true;
1078 $count = 0;
1079 $log_Ids = array();
1081 // Run through and pull all our data in one query
1082 foreach( $items as $logid ) {
1083 $where[] = intval($logid);
1085 list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
1086 $whereClause = "log_type ='$logtype' AND log_id IN(" . implode(',',$where) . ")";
1087 $result = $this->dbw->select( 'logging', '*',
1088 array( $whereClause ),
1089 __METHOD__ );
1090 while( $row = $this->dbw->fetchObject( $result ) ) {
1091 $logRows[$row->log_id] = $row;
1093 // To work!
1094 foreach( $items as $logid ) {
1095 if( !isset($logRows[$logid]) ) {
1096 $success = false;
1097 continue; // Must exist
1098 } else if( !LogEventsList::userCan($logRows[$logid], LogPage::DELETED_RESTRICTED)
1099 || $logRows[$logid]->log_type == 'suppress' ) {
1100 // Don't hide from oversight log!!!
1101 $userAllowedAll=false;
1102 continue;
1104 // Which logs did we change anything about?
1105 if( $logRows[$logid]->log_deleted != $bitfield ) {
1106 $log_Ids[]=$logid;
1107 $count++;
1109 $this->updateLogs( $logRows[$logid], $bitfield );
1110 $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
1113 // Don't log or touch if nothing changed
1114 if( $count > 0 ) {
1115 $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted,
1116 $comment, $title, 'logid', $log_Ids );
1118 // Where all revs allowed to be set?
1119 if( !$userAllowedAll ) {
1120 $wgOut->permissionRequired( 'hiderevision' );
1121 return false;
1124 return $success;
1128 * Moves an image to a safe private location
1129 * Caller is responsible for clearing caches
1130 * @param File $oimage
1131 * @returns mixed, timestamp string on success, false on failure
1133 function makeOldImagePrivate( $oimage ) {
1134 global $wgFileStore, $wgUseSquid;
1136 $transaction = new FSTransaction();
1137 if( !FileStore::lock() ) {
1138 wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" );
1139 return false;
1141 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR . $oimage->archive_name;
1142 // Dupe the file into the file store
1143 if( file_exists( $oldpath ) ) {
1144 // Is our directory configured?
1145 if( $store = FileStore::get( 'deleted' ) ) {
1146 if( !$oimage->sha1 ) {
1147 $oimage->upgradeRow(); // sha1 may be missing
1149 $key = $oimage->sha1 . '.' . $oimage->getExtension();
1150 $transaction->add( $store->insert( $key, $oldpath, FileStore::DELETE_ORIGINAL ) );
1151 } else {
1152 $group = null;
1153 $key = null;
1154 $transaction = false; // Return an error and do nothing
1156 } else {
1157 wfDebug( __METHOD__." deleting already-missing '$oldpath'; moving on to database\n" );
1158 $group = null;
1159 $key = '';
1160 $transaction = new FSTransaction(); // empty
1163 if( $transaction === false ) {
1164 // Fail to restore?
1165 wfDebug( __METHOD__.": import to file store failed, aborting\n" );
1166 throw new MWException( "Could not archive and delete file $oldpath" );
1167 return false;
1170 wfDebug( __METHOD__.": set db items, applying file transactions\n" );
1171 $transaction->commit();
1172 FileStore::unlock();
1174 $m = explode('!',$oimage->archive_name,2);
1175 $timestamp = $m[0];
1177 return $timestamp;
1181 * Moves an image from a safe private location
1182 * Caller is responsible for clearing caches
1183 * @param File $oimage
1184 * @returns mixed, string timestamp on success, false on failure
1186 function makeOldImagePublic( $oimage ) {
1187 global $wgFileStore;
1189 $transaction = new FSTransaction();
1190 if( !FileStore::lock() ) {
1191 wfDebug( __METHOD__." could not acquire filestore lock\n" );
1192 return false;
1195 $store = FileStore::get( 'deleted' );
1196 if( !$store ) {
1197 wfDebug( __METHOD__.": skipping row with no file.\n" );
1198 return false;
1201 $key = $oimage->sha1.'.'.$oimage->getExtension();
1202 $destDir = $oimage->getArchivePath();
1203 if( !is_dir( $destDir ) ) {
1204 wfMkdirParents( $destDir );
1206 $destPath = $destDir . DIRECTORY_SEPARATOR . $oimage->archive_name;
1207 // Check if any other stored revisions use this file;
1208 // if so, we shouldn't remove the file from the hidden
1209 // archives so they will still work. Check hidden files first.
1210 $useCount = $this->dbw->selectField( 'oldimage', '1',
1211 array( 'oi_sha1' => $oimage->sha1,
1212 'oi_deleted & '.File::DELETED_FILE => File::DELETED_FILE ),
1213 __METHOD__, array( 'FOR UPDATE' ) );
1214 // Check the rest of the deleted archives too.
1215 // (these are the ones that don't show in the image history)
1216 if( !$useCount ) {
1217 $useCount = $this->dbw->selectField( 'filearchive', '1',
1218 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1219 __METHOD__, array( 'FOR UPDATE' ) );
1222 if( $useCount == 0 ) {
1223 wfDebug( __METHOD__.": nothing else using {$oimage->sha1}, will deleting after\n" );
1224 $flags = FileStore::DELETE_ORIGINAL;
1225 } else {
1226 $flags = 0;
1228 $transaction->add( $store->export( $key, $destPath, $flags ) );
1230 wfDebug( __METHOD__.": set db items, applying file transactions\n" );
1231 $transaction->commit();
1232 FileStore::unlock();
1234 $m = explode('!',$oimage->archive_name,2);
1235 $timestamp = $m[0];
1237 return $timestamp;
1241 * Update the revision's rev_deleted field
1242 * @param Revision $rev
1243 * @param int $bitfield new rev_deleted bitfield value
1245 function updateRevision( $rev, $bitfield ) {
1246 $this->dbw->update( 'revision',
1247 array( 'rev_deleted' => $bitfield ),
1248 array( 'rev_id' => $rev->getId(),
1249 'rev_page' => $rev->getPage() ),
1250 __METHOD__ );
1254 * Update the revision's rev_deleted field
1255 * @param Revision $rev
1256 * @param Title $title
1257 * @param int $bitfield new rev_deleted bitfield value
1259 function updateArchive( $rev, $title, $bitfield ) {
1260 $this->dbw->update( 'archive',
1261 array( 'ar_deleted' => $bitfield ),
1262 array( 'ar_namespace' => $title->getNamespace(),
1263 'ar_title' => $title->getDBKey(),
1264 'ar_timestamp' => $this->dbw->timestamp( $rev->getTimestamp() ),
1265 'ar_rev_id' => $rev->getId() ),
1266 __METHOD__ );
1270 * Update the images's oi_deleted field
1271 * @param File $file
1272 * @param int $bitfield new rev_deleted bitfield value
1274 function updateOldFiles( $file, $bitfield ) {
1275 $this->dbw->update( 'oldimage',
1276 array( 'oi_deleted' => $bitfield ),
1277 array( 'oi_name' => $file->getName(),
1278 'oi_timestamp' => $this->dbw->timestamp( $file->getTimestamp() ) ),
1279 __METHOD__ );
1283 * Update the images's fa_deleted field
1284 * @param ArchivedFile $file
1285 * @param int $bitfield new rev_deleted bitfield value
1287 function updateArchFiles( $file, $bitfield ) {
1288 $this->dbw->update( 'filearchive',
1289 array( 'fa_deleted' => $bitfield ),
1290 array( 'fa_id' => $file->getID() ),
1291 __METHOD__ );
1295 * Update the logging log_deleted field
1296 * @param Row $row
1297 * @param int $bitfield new rev_deleted bitfield value
1299 function updateLogs( $row, $bitfield ) {
1300 $this->dbw->update( 'logging',
1301 array( 'log_deleted' => $bitfield ),
1302 array( 'log_id' => $row->log_id ),
1303 __METHOD__ );
1307 * Update the revision's recentchanges record if fields have been hidden
1308 * @param Revision $rev
1309 * @param int $bitfield new rev_deleted bitfield value
1311 function updateRecentChangesEdits( $rev, $bitfield ) {
1312 $this->dbw->update( 'recentchanges',
1313 array( 'rc_deleted' => $bitfield,
1314 'rc_patrolled' => 1 ),
1315 array( 'rc_this_oldid' => $rev->getId(),
1316 'rc_timestamp' => $this->dbw->timestamp( $rev->getTimestamp() ) ),
1317 __METHOD__ );
1321 * Update the revision's recentchanges record if fields have been hidden
1322 * @param Row $row
1323 * @param int $bitfield new rev_deleted bitfield value
1325 function updateRecentChangesLog( $row, $bitfield ) {
1326 $this->dbw->update( 'recentchanges',
1327 array( 'rc_deleted' => $bitfield,
1328 'rc_patrolled' => 1 ),
1329 array( 'rc_logid' => $row->log_id,
1330 'rc_timestamp' => $row->log_timestamp ),
1331 __METHOD__ );
1335 * Touch the page's cache invalidation timestamp; this forces cached
1336 * history views to refresh, so any newly hidden or shown fields will
1337 * update properly.
1338 * @param Title $title
1340 function updatePage( $title ) {
1341 $title->invalidateCache();
1342 $title->purgeSquid();
1344 // Extensions that require referencing previous revisions may need this
1345 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1349 * Checks for a change in the bitfield for a certain option and updates the
1350 * provided array accordingly.
1352 * @param String $desc Description to add to the array if the option was
1353 * enabled / disabled.
1354 * @param int $field The bitmask describing the single option.
1355 * @param int $diff The xor of the old and new bitfields.
1356 * @param array $arr The array to update.
1358 function checkItem ( $desc, $field, $diff, $new, &$arr ) {
1359 if ( $diff & $field ) {
1360 $arr [ ( $new & $field ) ? 0 : 1 ][] = $desc;
1365 * Gets an array describing the changes made to the visibilit of the revision.
1366 * If the resulting array is $arr, then $arr[0] will contain an array of strings
1367 * describing the items that were hidden, $arr[2] will contain an array of strings
1368 * describing the items that were unhidden, and $arr[3] will contain an array with
1369 * a single string, which can be one of "applied restrictions to sysops",
1370 * "removed restrictions from sysops", or null.
1372 * @param int $n The new bitfield.
1373 * @param int $o The old bitfield.
1374 * @return An array as described above.
1376 function getChanges ( $n, $o ) {
1377 $diff = $n ^ $o;
1378 $ret = array ( 0 => array(), 1 => array(), 2 => array() );
1380 $this->checkItem ( wfMsgForContent ( 'revdelete-content' ),
1381 Revision::DELETED_TEXT, $diff, $n, $ret );
1382 $this->checkItem ( wfMsgForContent ( 'revdelete-summary' ),
1383 Revision::DELETED_COMMENT, $diff, $n, $ret );
1384 $this->checkItem ( wfMsgForContent ( 'revdelete-uname' ),
1385 Revision::DELETED_USER, $diff, $n, $ret );
1387 // Restriction application to sysops
1388 if ( $diff & Revision::DELETED_RESTRICTED ) {
1389 if ( $n & Revision::DELETED_RESTRICTED )
1390 $ret[2][] = wfMsgForContent ( 'revdelete-restricted' );
1391 else
1392 $ret[2][] = wfMsgForContent ( 'revdelete-unrestricted' );
1395 return $ret;
1399 * Gets a log message to describe the given revision visibility change. This
1400 * message will be of the form "[hid {content, edit summary, username}];
1401 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
1403 * @param int $count The number of effected revisions.
1404 * @param int $nbitfield The new bitfield for the revision.
1405 * @param int $obitfield The old bitfield for the revision.
1406 * @param string $comment The comment associated with the change.
1407 * @param bool $isForLog
1409 function getLogMessage ( $count, $nbitfield, $obitfield, $comment, $isForLog = false ) {
1410 global $wgContLang;
1412 $s = '';
1413 $changes = $this->getChanges( $nbitfield, $obitfield );
1415 if ( count ( $changes[0] ) ) {
1416 $s .= wfMsgForContent ( 'revdelete-hid', implode ( ', ', $changes[0] ) );
1419 if ( count ( $changes[1] ) ) {
1420 if ($s) $s .= '; ';
1422 $s .= wfMsgForContent ( 'revdelete-unhid', implode ( ', ', $changes[1] ) );
1425 if ( count ( $changes[2] )) {
1426 if ($s)
1427 $s .= ' (' . $changes[2][0] . ')';
1428 else
1429 $s = $changes[2][0];
1432 $msg = $isForLog ? 'logdelete-log-message' : 'revdelete-log-message';
1433 $ret = wfMsgExt ( $msg, array( 'parsemag', 'content' ),
1434 $s, $wgContLang->formatNum( $count ) );
1436 if ( $comment )
1437 $ret .= ": $comment";
1439 return $ret;
1444 * Record a log entry on the action
1445 * @param Title $title, page where item was removed from
1446 * @param int $count the number of revisions altered for this page
1447 * @param int $nbitfield the new _deleted value
1448 * @param int $obitfield the old _deleted value
1449 * @param string $comment
1450 * @param Title $target, the relevant page
1451 * @param string $param, URL param
1452 * @param Array $items
1454 function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target, $param, $items = array() ) {
1455 // Put things hidden from sysops in the oversight log
1456 $logtype = ( ($nbitfield | $obitfield) & Revision::DELETED_RESTRICTED ) ? 'suppress' : 'delete';
1457 $log = new LogPage( $logtype );
1459 $reason = $this->getLogMessage ( $count, $nbitfield, $obitfield, $comment, $param == 'logid' );
1461 if( $param == 'logid' ) {
1462 $params = array( implode( ',', $items) );
1463 $log->addEntry( 'event', $title, $reason, $params );
1464 } else {
1465 // Add params for effected page and ids
1466 $params = array( $param, implode( ',', $items) );
1467 $log->addEntry( 'revision', $title, $reason, $params );