4 * Special page allowing users with the appropriate permissions to view
5 * and hide revisions. Log items can also be hidden.
7 * @addtogroup SpecialPage
10 function wfSpecialRevisiondelete( $par = null ) {
11 global $wgOut, $wgRequest, $wgUser, $wgAllowLogDeletion;
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 = $wgAllowLogDeletion ?
$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) && is_null($logid) ) {
24 $wgOut->addWikiText( wfMsgHtml( 'undelete-header' ) );
27 # Only one target set at a time please!
28 $i = (bool)$file +
(bool)$oldid +
(bool)$logid +
(bool)$artimestamp +
(bool)$fileid +
(bool)$img;
30 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
33 # Either submit or create our form
34 $form = new RevisionDeleteForm( $page, $oldid, $logid, $artimestamp, $fileid, $img, $file );
35 if( $wgRequest->wasPosted() ) {
36 $form->submit( $wgRequest );
37 } else if( $oldid ||
$artimestamp ) {
38 $form->showRevs( $wgRequest );
39 } else if( $fileid ||
$img ) {
40 $form->showImages( $wgRequest );
42 $form->showLogItems( $wgRequest );
44 # Show relevant lines from the deletion log. This will show even if said ID
45 # does not exist...might be helpful
46 if( !is_null($page) ) {
47 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'delete' ) ) . "</h2>\n" );
48 $logViewer = new LogViewer(
51 array( 'page' => $page->getPrefixedText(), 'type' => 'delete' ) ) ) );
52 $logViewer->showList( $wgOut );
57 * Implements the GUI for Revision Deletion.
58 * @addtogroup SpecialPage
60 class RevisionDeleteForm
{
63 * @param array $oldids
64 * @param array $logids
65 * @param array $artimestamps
66 * @param array $fileids
70 function __construct( $page, $oldids, $logids, $artimestamps, $fileids, $img, $file ) {
74 # For reviewing deleted files...
76 $oimage = RepoGroup
::singleton()->getLocalRepo()->newFromArchiveName( $page, $file );
78 // Check if user is allowed to see this file
79 if( !$oimage->userCan(File
::DELETED_FILE
) ) {
80 $wgOut->permissionRequired( 'hiderevision' );
82 $this->showFile( $file );
86 $this->skin
= $wgUser->getSkin();
87 // At this point, we should only have one of these
89 $this->revisions
= $oldids;
90 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
91 $this->deleteKey
='oldid';
92 } else if( $artimestamps ) {
93 $this->archrevs
= $artimestamps;
94 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
95 $this->deleteKey
='artimestamp';
98 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
99 $this->deleteKey
='oldimage';
100 } else if( $fileids ) {
101 $this->afiles
= $fileids;
102 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
103 $this->deleteKey
='fileid';
104 } else if( $logids ) {
105 $this->events
= $logids;
106 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage
::DELETED_ACTION
);
107 $this->deleteKey
='logid';
109 // Our checkbox messages depends one what we are doing,
110 // e.g. we don't hide "text" for logs or images
111 $this->checks
= array(
113 array( 'revdelete-hide-comment', 'wpHideComment', Revision
::DELETED_COMMENT
),
114 array( 'revdelete-hide-user', 'wpHideUser', Revision
::DELETED_USER
),
115 array( 'revdelete-hide-restricted', 'wpHideRestricted', Revision
::DELETED_RESTRICTED
) );
119 * Show a deleted file version requested by the visitor.
121 private function showFile( $key ) {
122 global $wgOut, $wgRequest;
125 # We mustn't allow the output to be Squid cached, otherwise
126 # if an admin previews a deleted image, and it's cached, then
127 # a user without appropriate permissions can toddle off and
128 # nab the image, and Squid will serve it
129 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
130 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
131 $wgRequest->response()->header( 'Pragma: no-cache' );
133 $store = FileStore
::get( 'deleted' );
134 $store->stream( $key );
138 * This lets a user set restrictions for live and archived revisions
139 * @param WebRequest $request
141 function showRevs( $request ) {
142 global $wgOut, $wgUser, $action;
146 $count = ($this->deleteKey
=='oldid') ?
147 count($this->revisions
) : count($this->archrevs
);
148 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(), $count );
151 $wgOut->addHtml( "<ul>" );
153 $where = $revObjs = array();
154 $dbr = wfGetDB( DB_SLAVE
);
156 if( $this->deleteKey
=='oldid' ) {
157 // Run through and pull all our data in one query
158 foreach( $this->revisions
as $revid ) {
159 $where[] = intval($revid);
161 $whereClause = 'rev_id IN(' . implode(',',$where) . ')';
162 $result = $dbr->select( array('revision','page'), '*',
163 array( 'rev_page' => $this->page
->getArticleID(),
164 $whereClause, 'rev_page = page_id' ),
166 while( $row = $dbr->fetchObject( $result ) ) {
167 $revObjs[$row->rev_id
] = new Revision( $row );
169 foreach( $this->revisions
as $revid ) {
170 // Hiding top revisison is bad
171 if( !is_object($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
172 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
174 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
175 // If a rev is hidden from sysops
176 if( $action != 'submit') {
177 $wgOut->permissionRequired( 'hiderevision' );
180 $UserAllowed = false;
182 $wgOut->addHtml( $this->historyLine( $revObjs[$revid] ) );
183 $bitfields |
= $revObjs[$revid]->mDeleted
;
187 // Run through and pull all our data in one query
188 foreach( $this->archrevs
as $timestamp ) {
189 $where[] = $dbr->addQuotes( $timestamp );
191 $whereClause = 'ar_timestamp IN(' . implode(',',$where) . ')';
192 $result = $dbr->select( 'archive', '*',
193 array( 'ar_namespace' => $this->page
->getNamespace(),
194 'ar_title' => $this->page
->getDBKey(),
197 while( $row = $dbr->fetchObject( $result ) ) {
198 $revObjs[$row->ar_timestamp
] = new Revision( array(
199 'page' => $this->page
->getArticleId(),
200 'id' => $row->ar_rev_id
,
201 'text' => $row->ar_text_id
,
202 'comment' => $row->ar_comment
,
203 'user' => $row->ar_user
,
204 'user_text' => $row->ar_user_text
,
205 'timestamp' => $row->ar_timestamp
,
206 'minor_edit' => $row->ar_minor_edit
,
207 'text_id' => $row->ar_text_id
,
208 'deleted' => $row->ar_deleted
,
209 'len' => $row->ar_len
) );
211 foreach( $this->archrevs
as $timestamp ) {
212 if( !is_object($revObjs[$timestamp]) ) {
213 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
217 foreach( $revObjs as $rev ) {
218 if( !$rev->userCan(Revision
::DELETED_RESTRICTED
) ) {
219 // If a rev is hidden from sysops
220 if( $action != 'submit') {
221 $wgOut->permissionRequired( 'hiderevision' );
224 $UserAllowed = false;
226 $wgOut->addHtml( $this->historyLine( $rev ) );
227 $bitfields |
= $rev->mDeleted
;
230 $wgOut->addHtml( "</ul>" );
232 $wgOut->addWikiText( wfMsgHtml( 'revdelete-text' ) );
234 // Normal sysops can always see what they did, but can't always change it
235 if( !$UserAllowed ) return;
238 wfInputLabel( wfMsgHtml( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
239 wfSubmitButton( wfMsgHtml( 'revdelete-submit' ) ) );
241 wfHidden( 'wpEditToken', $wgUser->editToken() ),
242 wfHidden( 'target', $this->page
->getPrefixedText() ),
243 wfHidden( 'type', $this->deleteKey
) );
244 if( $this->deleteKey
=='oldid' ) {
245 foreach( $revObjs as $rev )
246 $hidden[] = wfHidden( 'oldid[]', $rev->getID() );
248 foreach( $revObjs as $rev )
249 $hidden[] = wfHidden( 'artimestamp[]', $rev->getTimestamp() );
251 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
252 $wgOut->addHtml( wfElement( 'form', array(
254 'action' => $special->getLocalUrl( 'action=submit' ) ),
257 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'revdelete-legend' ) . '</legend>' );
258 // FIXME: all items checked for just one rev are checked, even if not set for the others
259 foreach( $this->checks
as $item ) {
260 list( $message, $name, $field ) = $item;
261 $wgOut->addHtml( "<div>" .
262 wfCheckLabel( wfMsgHtml( $message), $name, $name, $bitfields & $field ) .
265 $wgOut->addHtml( '</fieldset>' );
266 foreach( $items as $item ) {
267 $wgOut->addHtml( '<p>' . $item . '</p>' );
269 foreach( $hidden as $item ) {
270 $wgOut->addHtml( $item );
273 $wgOut->addHtml( '</form>' );
277 * This lets a user set restrictions for archived images
278 * @param WebRequest $request
280 function showImages( $request ) {
281 global $wgOut, $wgUser, $action;
285 $count = ($this->deleteKey
=='oldimage') ?
count($this->ofiles
) : count($this->afiles
);
286 $wgOut->addWikiText( wfMsgExt( 'revdelete-selected', array('parsemag'),
287 $this->page
->getPrefixedText(), $count ) );
290 $wgOut->addHtml( "<ul>" );
292 $where = $filesObjs = array();
293 $dbr = wfGetDB( DB_SLAVE
);
294 // Live old revisions...
295 if( $this->deleteKey
=='oldimage' ) {
296 // Run through and pull all our data in one query
297 foreach( $this->ofiles
as $timestamp ) {
298 $where[] = $dbr->addQuotes( $timestamp.'!'.$this->page
->getDbKey() );
300 $whereClause = 'oi_archive_name IN(' . implode(',',$where) . ')';
301 $result = $dbr->select( 'oldimage', '*',
302 array( 'oi_name' => $this->page
->getDbKey(),
305 while( $row = $dbr->fetchObject( $result ) ) {
306 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
307 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
308 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
310 // Check through our images
311 foreach( $this->ofiles
as $timestamp ) {
312 $archivename = $timestamp.'!'.$this->page
->getDbKey();
313 if( !isset($filesObjs[$archivename]) ) {
314 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
318 foreach( $filesObjs as $file ) {
319 if( !isset($file) ) {
320 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
322 } else if( !$file->userCan(File
::DELETED_RESTRICTED
) ) {
323 // If a rev is hidden from sysops
324 if( $action != 'submit' ) {
325 $wgOut->permissionRequired( 'hiderevision' );
328 $UserAllowed = false;
330 // Inject history info
331 $wgOut->addHtml( $this->fileLine( $file ) );
332 $bitfields |
= $file->deleted
;
336 // Run through and pull all our data in one query
337 foreach( $this->afiles
as $id ) {
338 $where[] = intval($id);
340 $whereClause = 'fa_id IN(' . implode(',',$where) . ')';
341 $result = $dbr->select( 'filearchive', '*',
342 array( 'fa_name' => $this->page
->getDbKey(),
345 while( $row = $dbr->fetchObject( $result ) ) {
346 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
349 foreach( $this->afiles
as $fileid ) {
350 if( !isset($filesObjs[$fileid]) ) {
351 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
353 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
354 // If a rev is hidden from sysops
355 if( $action != 'submit' ) {
356 $wgOut->permissionRequired( 'hiderevision' );
359 $UserAllowed = false;
361 // Inject history info
362 $wgOut->addHtml( $this->archivedfileLine( $filesObjs[$fileid] ) );
363 $bitfields |
= $filesObjs[$fileid]->deleted
;
366 $wgOut->addHtml( "</ul>" );
368 $wgOut->addWikiText( wfMsgHtml( 'revdelete-text' ) );
369 //Normal sysops can always see what they did, but can't always change it
370 if( !$UserAllowed ) return;
373 wfInputLabel( wfMsgHtml( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
374 wfSubmitButton( wfMsgHtml( 'revdelete-submit' ) ) );
376 wfHidden( 'wpEditToken', $wgUser->editToken() ),
377 wfHidden( 'target', $this->page
->getPrefixedText() ),
378 wfHidden( 'type', $this->deleteKey
) );
379 if( $this->deleteKey
=='oldimage' ) {
380 foreach( $this->ofiles
as $filename )
381 $hidden[] = wfHidden( 'oldimage[]', $filename );
383 foreach( $this->afiles
as $fileid )
384 $hidden[] = wfHidden( 'fileid[]', $fileid );
386 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
387 $wgOut->addHtml( wfElement( 'form', array(
389 'action' => $special->getLocalUrl( 'action=submit' ) ),
392 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'revdelete-legend' ) . '</legend>' );
393 // FIXME: all items checked for just one file are checked, even if not set for the others
394 foreach( $this->checks
as $item ) {
395 list( $message, $name, $field ) = $item;
396 $wgOut->addHtml( '<div>' .
397 wfCheckLabel( wfMsgHtml( $message), $name, $name, $bitfields & $field ) .
400 $wgOut->addHtml( '</fieldset>' );
401 foreach( $items as $item ) {
402 $wgOut->addHtml( '<p>' . $item . '</p>' );
404 foreach( $hidden as $item ) {
405 $wgOut->addHtml( $item );
408 $wgOut->addHtml( '</form>' );
412 * This lets a user set restrictions for log items
413 * @param WebRequest $request
415 function showLogItems( $request ) {
416 global $wgOut, $wgUser, $action;
419 $wgOut->addWikiText( wfMsgExt( 'logdelete-selected', array('parsemag'), count($this->events
) ) );
422 $wgOut->addHtml( "<ul>" );
424 $where = $logRows = array();
425 $dbr = wfGetDB( DB_SLAVE
);
426 // Run through and pull all our data in one query
427 foreach( $this->events
as $logid ) {
428 $where[] = intval($logid);
430 $whereClause = 'log_id IN(' . implode(',',$where) . ')';
431 $result = $dbr->select( 'logging', '*',
432 array( $whereClause ),
434 while( $row = $dbr->fetchObject( $result ) ) {
435 $logRows[$row->log_id
] = $row;
437 foreach( $this->events
as $logid ) {
438 // Don't hide from oversight log!!!
439 if( !isset( $logRows[$logid] ) ||
$logRows[$logid]->log_type
=='oversight' ) {
440 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
442 } else if( !LogPage
::userCan( $logRows[$logid],Revision
::DELETED_RESTRICTED
) ) {
443 // If an event is hidden from sysops
444 if( $action != 'submit') {
445 $wgOut->permissionRequired( 'hiderevision' );
448 $UserAllowed = false;
450 $wgOut->addHtml( $this->logLine( $logRows[$logid] ) );
451 $bitfields |
= $logRows[$logid]->log_deleted
;
453 $wgOut->addHtml( "</ul>" );
455 $wgOut->addWikiMsg( 'revdelete-text' );
456 // Normal sysops can always see what they did, but can't always change it
457 if( !$UserAllowed ) return;
460 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
461 Xml
::submitButton( wfMsg( 'revdelete-submit' ) ) );
463 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
464 Xml
::hidden( 'type', $this->deleteKey
) );
465 foreach( $this->events
as $logid ) {
466 $hidden[] = Xml
::hidden( 'logid[]', $logid );
469 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
470 $wgOut->addHtml( Xml
::element( 'form', array(
472 'action' => $special->getLocalUrl( 'action=submit' ) ),
475 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'revdelete-legend' ) . '</legend>' );
476 // FIXME: all items checked for just on event are checked, even if not set for the others
477 foreach( $this->checks
as $item ) {
478 list( $message, $name, $field ) = $item;
479 $wgOut->addHtml( '<div>' .
480 Xml
::checkLabel( wfMsg( $message), $name, $name, $bitfields & $field ) .
483 $wgOut->addHtml( '</fieldset>' );
484 foreach( $items as $item ) {
485 $wgOut->addHtml( '<p>' . $item . '</p>' );
487 foreach( $hidden as $item ) {
488 $wgOut->addHtml( $item );
491 $wgOut->addHtml( '</form>' );
495 * @param Revision $rev
498 private function historyLine( $rev ) {
500 $date = $wgContLang->timeanddate( $rev->getTimestamp() );
502 $difflink=''; $del = '';
504 if( $this->deleteKey
=='oldid' ) {
505 $difflink = '(' . $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml('diff'),
506 'diff=' . $rev->getId() . '&oldid=prev' ) . ')';
507 $revlink = $this->skin
->makeLinkObj( $this->page
, $date, 'oldid=' . $rev->getId() );
509 // Archived revisions
510 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
511 $target = $this->page
->getPrefixedText();
512 $revlink = $this->skin
->makeLinkObj( $undelete, $date,
513 "target=$target×tamp=" . $rev->getTimestamp() );
516 if( $rev->isDeleted(Revision
::DELETED_TEXT
) ) {
517 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
518 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
519 if( !$rev->userCan(Revision
::DELETED_TEXT
) ) {
520 $revlink = '<span class="history-deleted">'.$date.'</span>';
524 return "<li> $difflink $revlink ".$this->skin
->revUserLink( $rev )." ".$this->skin
->revComment( $rev )."$del</li>";
531 private function fileLine( $file ) {
532 global $wgContLang, $wgTitle;
534 $target = $this->page
->getPrefixedText();
535 $date = $wgContLang->timeanddate( $file->getTimestamp(), true );
539 if( $file->isDeleted(File
::DELETED_FILE
) ) {
540 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
541 if( !$file->userCan(File
::DELETED_FILE
) ) {
544 $pageLink = $this->skin
->makeKnownLinkObj( $wgTitle, $date,
545 "target=$target&file=$file->sha1.".$file->getExtension() );
547 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
550 $url = $file->getUrlRel();
551 $pageLink = "<a href=\"{$url}\">{$date}</a>";
554 $data = wfMsgHtml( 'widthheight',
555 $wgContLang->formatNum( $file->getWidth() ),
556 $wgContLang->formatNum( $file->getHeight() ) ) .
557 ' (' . wfMsgHtml( 'nbytes', $wgContLang->formatNum( $file->getSize() ) ) . ')';
559 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
563 * @param ArchivedFile $file
566 private function archivedfileLine( $file ) {
567 global $wgContLang, $wgTitle;
569 $target = $this->page
->getPrefixedText();
570 $date = $wgContLang->timeanddate( $file->getTimestamp(), true );
572 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
573 $pageLink = $this->skin
->makeKnownLinkObj( $undelete, $date, "target=$target&file={$file->getKey()}" );
576 if( $file->isDeleted(File
::DELETED_FILE
) ) {
577 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
580 $data = wfMsgHtml( 'widthheight',
581 $wgContLang->formatNum( $file->getWidth() ),
582 $wgContLang->formatNum( $file->getHeight() ) ) .
583 ' (' . wfMsgHtml( 'nbytes', $wgContLang->formatNum( $file->getSize() ) ) . ')';
585 return "<li> $pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
589 * @param Array $row row
592 private function logLine( $row ) {
595 $date = $wgContLang->timeanddate( $row->log_timestamp
);
596 $paramArray = LogPage
::extractParams( $row->log_params
);
598 if( !LogPage
::userCan($row,LogPage
::DELETED_ACTION
) ) {
599 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
601 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
602 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
603 $this->skin
, $paramArray, true, true );
604 if( $row->log_deleted
& LogPage
::DELETED_ACTION
)
605 $action = '<span class="history-deleted">' . $action . '</span>';
608 $userLink = $this->skin
->userLink( $row->log_user
, User
::WhoIs($row->log_user
) );
609 if( LogPage
::isDeleted($row,LogPage
::DELETED_USER
) ) {
610 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
613 $comment = $wgContLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
614 if( LogPage
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
615 $comment = '<span class="history-deleted">' . $comment . '</span>';
617 return "<li>$date $userLink $action $comment</li>";
621 * Generate a user tool link cluster if the current user is allowed to view it
622 * @param ArchivedFile $file
623 * @return string HTML
625 private function fileUserTools( $file ) {
626 if( $file->userCan( Revision
::DELETED_USER
) ) {
627 $link = $this->skin
->userLink( $file->user
, $file->user_text
) .
628 $this->skin
->userToolLinks( $file->user
, $file->user_text
);
630 $link = wfMsgHtml( 'rev-deleted-user' );
632 if( $file->isDeleted( Revision
::DELETED_USER
) ) {
633 return '<span class="history-deleted">' . $link . '</span>';
639 * Wrap and format the given file's comment block, if the current
640 * user is allowed to view it.
642 * @param ArchivedFile $file
643 * @return string HTML
645 private function fileComment( $file ) {
646 if( $file->userCan( File
::DELETED_COMMENT
) ) {
647 $block = $this->skin
->commentBlock( $file->description
);
649 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
651 if( $file->isDeleted( File
::DELETED_COMMENT
) ) {
652 return "<span class=\"history-deleted\">$block</span>";
658 * @param WebRequest $request
660 function submit( $request ) {
661 $bitfield = $this->extractBitfield( $request );
662 $comment = $request->getText( 'wpReason' );
664 $this->target
= $request->getText( 'target' );
665 $this->title
= Title
::newFromURL( $this->target
);
667 if( $this->save( $bitfield, $comment, $this->title
) ) {
668 $this->success( $request );
669 } else if( $request->getCheck( 'oldid' ) ||
$request->getCheck( 'artimestamp' ) ) {
670 return $this->showRevs( $request );
671 } else if( $request->getCheck( 'logid' ) ) {
672 return $this->showLogs( $request );
673 } else if( $request->getCheck( 'oldimage' ) ||
$request->getCheck( 'fileid' ) ) {
674 return $this->showImages( $request );
678 private function success( $request ) {
681 $wgOut->setPagetitle( wfMsgHtml( 'actioncomplete' ) );
682 # Give a link to the log for this page
683 $logtitle = SpecialPage
::getTitleFor( 'Log' );
684 $loglink = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
685 wfArrayToCGI( array('page' => $this->target
) ) );
686 # Give a link to the page history
687 $histlink = $this->skin
->makeKnownLinkObj( $this->title
, wfMsgHtml( 'pagehist' ),
688 wfArrayToCGI( array('action' => 'history' ) ) );
689 # Link to deleted edits
690 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
691 $dellink = $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
692 wfArrayToCGI( array('target' => $this->target
) ) );
693 # Logs themselves don't have histories or archived revisions
694 if( !is_null($this->title
) && $this->title
->getNamespace() > -1)
695 $wgOut->setSubtitle( '<p>'.$histlink.' / '.$loglink.' / '.$dellink.'</p>' );
697 if( $this->deleteKey
=='logid' ) {
698 $wgOut->addWikiText( wfMsgHtml('logdelete-success'), false );
699 $this->showLogItems( $request );
700 } else if( $this->deleteKey
=='oldid' ||
$this->deleteKey
=='artimestamp' ) {
701 $wgOut->addWikiText( wfMsgHtml('revdelete-success'), false );
702 $this->showRevs( $request );
703 } else if( $this->deleteKey
=='fileid' ) {
704 $wgOut->addWikiText( wfMsgHtml('revdelete-success'), false );
705 $this->showImages( $request );
706 } else if( $this->deleteKey
=='oldimage' ) {
707 $this->showImages( $request );
712 * Put together a rev_deleted bitfield from the submitted checkboxes
713 * @param WebRequest $request
716 private function extractBitfield( $request ) {
718 foreach( $this->checks
as $item ) {
719 list( /* message */ , $name, $field ) = $item;
720 if( $request->getCheck( $name ) ) {
727 private function save( $bitfield, $reason, $title ) {
728 $dbw = wfGetDB( DB_MASTER
);
729 // Don't allow simply locking the interface for no reason
730 if( $bitfield == Revision
::DELETED_RESTRICTED
) {
733 $deleter = new RevisionDeleter( $dbw );
734 // By this point, only one of the below should be set
735 if( isset($this->revisions
) ) {
736 return $deleter->setRevVisibility( $title, $this->revisions
, $bitfield, $reason );
737 } else if( isset($this->archrevs
) ) {
738 return $deleter->setArchiveVisibility( $title, $this->archrevs
, $bitfield, $reason );
739 } else if( isset($this->ofiles
) ) {
740 return $deleter->setOldImgVisibility( $title, $this->ofiles
, $bitfield, $reason );
741 } else if( isset($this->afiles
) ) {
742 return $deleter->setArchFileVisibility( $title, $this->afiles
, $bitfield, $reason );
743 } else if( isset($this->events
) ) {
744 return $deleter->setEventVisibility( $this->events
, $bitfield, $reason );
750 * Implements the actions for Revision Deletion.
751 * @addtogroup SpecialPage
753 class RevisionDeleter
{
754 function __construct( $db ) {
759 * @param $title, the page these events apply to
760 * @param array $items list of revision ID numbers
761 * @param int $bitfield new rev_deleted value
762 * @param string $comment Comment for log records
764 function setRevVisibility( $title, $items, $bitfield, $comment ) {
767 $userAllowedAll = $success = true;
770 // Run through and pull all our data in one query
771 foreach( $items as $revid ) {
772 $where[] = intval($revid);
774 $whereClause = 'rev_id IN(' . implode(',',$where) . ')';
775 $result = $this->dbw
->select( 'revision', '*',
776 array( 'rev_page' => $title->getArticleID(),
779 while( $row = $this->dbw
->fetchObject( $result ) ) {
780 $revObjs[$row->rev_id
] = new Revision( $row );
783 foreach( $items as $revid ) {
784 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
786 continue; // Must exist
787 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
788 $userAllowedAll=false;
791 // For logging, maintain a count of revisions
792 if( $revObjs[$revid]->mDeleted
!= $bitfield ) {
796 $this->updateRevision( $revObjs[$revid], $bitfield );
797 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
801 // Don't log or touch if nothing changed
802 if( $revCount > 0 ) {
803 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted
,
804 $comment, $title, 'oldid', $revIDs );
805 $this->updatePage( $title );
807 // Where all revs allowed to be set?
808 if( !$userAllowedAll ) {
809 //FIXME: still might be confusing???
810 $wgOut->permissionRequired( 'hiderevision' );
818 * @param $title, the page these events apply to
819 * @param array $items list of revision ID numbers
820 * @param int $bitfield new rev_deleted value
821 * @param string $comment Comment for log records
823 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
826 $userAllowedAll = $success = true;
829 // Run through and pull all our data in one query
830 foreach( $items as $timestamp ) {
831 $where[] = $this->dbw
->addQuotes( $timestamp );
833 $whereClause = 'ar_timestamp IN(' . implode(',',$where) . ')';
834 $result = $this->dbw
->select( 'archive', '*',
835 array( 'ar_namespace' => $title->getNamespace(),
836 'ar_title' => $title->getDBKey(),
839 while( $row = $this->dbw
->fetchObject( $result ) ) {
840 $revObjs[$row->ar_timestamp
] = new Revision( array(
841 'page' => $title->getArticleId(),
842 'id' => $row->ar_rev_id
,
843 'text' => $row->ar_text_id
,
844 'comment' => $row->ar_comment
,
845 'user' => $row->ar_user
,
846 'user_text' => $row->ar_user_text
,
847 'timestamp' => $row->ar_timestamp
,
848 'minor_edit' => $row->ar_minor_edit
,
849 'text_id' => $row->ar_text_id
,
850 'deleted' => $row->ar_deleted
,
851 'len' => $row->ar_len
) );
854 foreach( $items as $timestamp ) {
855 // This will only select the first revision with this timestamp.
856 // Since they are all selected/deleted at once, we can just check the
857 // permissions of one. UPDATE is done via timestamp, so all revs are set.
858 if( !is_object($revObjs[$timestamp]) ) {
860 continue; // Must exist
861 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
862 $userAllowedAll=false;
865 // Which revisions did we change anything about?
866 if( $revObjs[$timestamp]->mDeleted
!= $bitfield ) {
867 $Id_set[]=$timestamp;
870 $this->updateArchive( $revObjs[$timestamp], $bitfield );
873 // For logging, maintain a count of revisions
875 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted
,
876 $comment, $title, 'artimestamp', $Id_set );
878 // Where all revs allowed to be set?
879 if( !$userAllowedAll ) {
880 $wgOut->permissionRequired( 'hiderevision' );
888 * @param $title, the page these events apply to
889 * @param array $items list of revision ID numbers
890 * @param int $bitfield new rev_deleted value
891 * @param string $comment Comment for log records
893 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
896 $userAllowedAll = $success = true;
899 // Run through and pull all our data in one query
900 foreach( $items as $timestamp ) {
901 $where[] = $this->dbw
->addQuotes( $timestamp.'!'.$title->getDbKey() );
903 $whereClause = 'oi_archive_name IN(' . implode(',',$where) . ')';
904 $result = $this->dbw
->select( 'oldimage', '*',
905 array( 'oi_name' => $title->getDbKey(),
908 while( $row = $this->dbw
->fetchObject( $result ) ) {
909 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
910 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
911 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
914 foreach( $items as $timestamp ) {
915 $archivename = $timestamp.'!'.$title->getDbKey();
916 if( !isset($filesObjs[$archivename]) ) {
918 continue; // Must exist
919 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
920 $userAllowedAll=false;
925 // Which revisions did we change anything about?
926 if( $filesObjs[$archivename]->deleted
!= $bitfield ) {
930 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
931 // If this image is currently hidden...
932 if( $filesObjs[$archivename]->deleted
& File
::DELETED_FILE
) {
933 if( $bitfield & File
::DELETED_FILE
) {
934 # Leave it alone if we are not changing this...
938 # We are moving this out
939 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
942 // Is it just now becoming hidden?
943 } else if( $bitfield & File
::DELETED_FILE
) {
944 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
949 // If our file operations fail, then revert back the db
950 if( $transaction==false ) {
951 $this->dbw
->rollback();
954 $this->dbw
->commit();
958 // Log if something was changed
960 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted
,
961 $comment, $title, 'oldimage', $set );
963 $file = wfLocalFile( $title );
965 $file->purgeHistory();
966 # Invalidate cache for all pages using this file
967 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
970 // Where all revs allowed to be set?
971 if( !$userAllowedAll ) {
972 $wgOut->permissionRequired( 'hiderevision' );
980 * @param $title, the page these events apply to
981 * @param array $items list of revision ID numbers
982 * @param int $bitfield new rev_deleted value
983 * @param string $comment Comment for log records
985 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
988 $userAllowedAll = $success = true;
992 // Run through and pull all our data in one query
993 foreach( $items as $id ) {
994 $where[] = intval($id);
996 $whereClause = 'fa_id IN(' . implode(',',$where) . ')';
997 $result = $this->dbw
->select( 'filearchive', '*',
998 array( 'fa_name' => $title->getDbKey(),
1001 while( $row = $this->dbw
->fetchObject( $result ) ) {
1002 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
1005 foreach( $items as $fileid ) {
1006 if( !isset($filesObjs[$fileid]) ) {
1008 continue; // Must exist
1009 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
1010 $userAllowedAll=false;
1013 // Which revisions did we change anything about?
1014 if( $filesObjs[$fileid]->deleted
!= $bitfield ) {
1018 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1021 // Log if something was changed
1023 $this->updateLog( $title, $count, $bitfield, $comment,
1024 $filesObjs[$fileid]->deleted
, $title, 'fileid', $Id_set );
1026 // Where all revs allowed to be set?
1027 if( !$userAllowedAll ) {
1028 $wgOut->permissionRequired( 'hiderevision' );
1036 * @param array $items list of log ID numbers
1037 * @param int $bitfield new log_deleted value
1038 * @param string $comment Comment for log records
1040 function setEventVisibility( $items, $bitfield, $comment ) {
1043 $userAllowedAll = $success = true;
1044 $logs_count = array();
1045 $logs_Ids = array();
1047 // Run through and pull all our data in one query
1048 foreach( $items as $logid ) {
1049 $where[] = intval($logid);
1051 $whereClause = 'log_id IN(' . implode(',',$where) . ')';
1052 $result = $this->dbw
->select( 'logging', '*',
1053 array( $whereClause ),
1055 while( $row = $this->dbw
->fetchObject( $result ) ) {
1056 $logRows[$row->log_id
] = $row;
1059 foreach( $items as $logid ) {
1060 if( !isset($logRows[$logid]) ) {
1062 continue; // Must exist
1063 } else if( !LogPage
::userCan($logRows[$logid], Revision
::DELETED_RESTRICTED
)
1064 ||
$logRows[$logid]->log_type
=='oversight' ) {
1065 // Don't hide from oversight log!!!
1066 $userAllowedAll=false;
1069 $logtype = $logRows[$logid]->log_type
;
1070 // For logging, maintain a count of events per log type
1071 if( !isset( $logs_count[$logtype] ) ) {
1072 $logs_count[$logtype]=0;
1073 $logs_Ids[$logtype]=array();
1075 // Which logs did we change anything about?
1076 if( $logRows[$logid]->log_deleted
!= $bitfield ) {
1077 $logs_Ids[$logtype][]=$logid;
1078 $logs_count[$logtype]++
;
1080 $this->updateLogs( $logRows[$logid], $bitfield );
1081 $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
1084 foreach( $logs_count as $logtype => $count ) {
1085 // Don't log or touch if nothing changed
1087 $target = SpecialPage
::getTitleFor( 'Log', $logtype );
1088 $this->updateLog( $target, $count, $bitfield, $logRows[$logid]->log_deleted
,
1089 $comment, $target, 'logid', $logs_Ids[$logtype] );
1092 // Where all revs allowed to be set?
1093 if( !$userAllowedAll ) {
1094 $wgOut->permissionRequired( 'hiderevision' );
1102 * Moves an image to a safe private location
1103 * Caller is responsible for clearing caches
1104 * @param File $oimage
1105 * @returns mixed, timestamp string on success, false on failure
1107 function makeOldImagePrivate( $oimage ) {
1108 global $wgFileStore, $wgUseSquid;
1110 $transaction = new FSTransaction();
1111 if( !FileStore
::lock() ) {
1112 wfDebug( __METHOD__
.": failed to acquire file store lock, aborting\n" );
1115 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1116 // Dupe the file into the file store
1117 if( file_exists( $oldpath ) ) {
1118 // Is our directory configured?
1119 if( $store = FileStore
::get( 'deleted' ) ) {
1120 if( !$oimage->sha1
) {
1121 $oimage->upgradeRow(); // sha1 may be missing
1123 $key = $oimage->sha1
. '.' . $oimage->getExtension();
1124 $transaction->add( $store->insert( $key, $oldpath, FileStore
::DELETE_ORIGINAL
) );
1128 $transaction = false; // Return an error and do nothing
1131 wfDebug( __METHOD__
." deleting already-missing '$oldpath'; moving on to database\n" );
1134 $transaction = new FSTransaction(); // empty
1137 if( $transaction === false ) {
1139 wfDebug( __METHOD__
.": import to file store failed, aborting\n" );
1140 throw new MWException( "Could not archive and delete file $oldpath" );
1144 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1145 $transaction->commit();
1146 FileStore
::unlock();
1148 $m = explode('!',$oimage->archive_name
,2);
1155 * Moves an image from a safe private location
1156 * Caller is responsible for clearing caches
1157 * @param File $oimage
1158 * @returns mixed, string timestamp on success, false on failure
1160 function makeOldImagePublic( $oimage ) {
1161 global $wgFileStore;
1163 $transaction = new FSTransaction();
1164 if( !FileStore
::lock() ) {
1165 wfDebug( __METHOD__
." could not acquire filestore lock\n" );
1169 $store = FileStore
::get( 'deleted' );
1171 wfDebug( __METHOD__
.": skipping row with no file.\n" );
1175 $key = $oimage->sha1
.'.'.$oimage->getExtension();
1176 $destDir = $oimage->getArchivePath();
1177 if( !is_dir( $destDir ) ) {
1178 wfMkdirParents( $destDir );
1180 $destPath = $destDir . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1181 // Check if any other stored revisions use this file;
1182 // if so, we shouldn't remove the file from the hidden
1183 // archives so they will still work. Check hidden files first.
1184 $useCount = $this->dbw
->selectField( 'oldimage', '1',
1185 array( 'oi_sha1' => $oimage->sha1
,
1186 'oi_deleted & '.File
::DELETED_FILE
=> File
::DELETED_FILE
),
1187 __METHOD__
, array( 'FOR UPDATE' ) );
1188 // Check the rest of the deleted archives too.
1189 // (these are the ones that don't show in the image history)
1191 $useCount = $this->dbw
->selectField( 'filearchive', '1',
1192 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1193 __METHOD__
, array( 'FOR UPDATE' ) );
1196 if( $useCount == 0 ) {
1197 wfDebug( __METHOD__
.": nothing else using {$oimage->sha1}, will deleting after\n" );
1198 $flags = FileStore
::DELETE_ORIGINAL
;
1202 $transaction->add( $store->export( $key, $destPath, $flags ) );
1204 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1205 $transaction->commit();
1206 FileStore
::unlock();
1208 $m = explode('!',$oimage->archive_name
,2);
1215 * Update the revision's rev_deleted field
1216 * @param Revision $rev
1217 * @param int $bitfield new rev_deleted bitfield value
1219 function updateRevision( $rev, $bitfield ) {
1220 $this->dbw
->update( 'revision',
1221 array( 'rev_deleted' => $bitfield ),
1222 array( 'rev_id' => $rev->getId() ),
1227 * Update the revision's rev_deleted field
1228 * @param Revision $rev
1229 * @param int $bitfield new rev_deleted bitfield value
1231 function updateArchive( $rev, $bitfield ) {
1232 $this->dbw
->update( 'archive',
1233 array( 'ar_deleted' => $bitfield ),
1234 array( 'ar_rev_id' => $rev->getId() ),
1239 * Update the images's oi_deleted field
1240 * @param File $oimage
1241 * @param int $bitfield new rev_deleted bitfield value
1243 function updateOldFiles( $oimage, $bitfield ) {
1244 $this->dbw
->update( 'oldimage',
1245 array( 'oi_deleted' => $bitfield ),
1246 array( 'oi_archive_name' => $oimage->archive_name
),
1251 * Update the images's fa_deleted field
1252 * @param ArchivedFile $file
1253 * @param int $bitfield new rev_deleted bitfield value
1255 function updateArchFiles( $file, $bitfield ) {
1256 $this->dbw
->update( 'filearchive',
1257 array( 'fa_deleted' => $bitfield ),
1258 array( 'fa_id' => $file->getID() ),
1263 * Update the logging log_deleted field
1265 * @param int $bitfield new rev_deleted bitfield value
1267 function updateLogs( $row, $bitfield ) {
1268 $this->dbw
->update( 'logging',
1269 array( 'log_deleted' => $bitfield ),
1270 array( 'log_id' => $row->log_id
),
1275 * Update the revision's recentchanges record if fields have been hidden
1276 * @param Revision $rev
1277 * @param int $bitfield new rev_deleted bitfield value
1279 function updateRecentChangesEdits( $rev, $bitfield ) {
1280 $this->dbw
->update( 'recentchanges',
1281 array( 'rc_deleted' => $bitfield,
1282 'rc_patrolled' => 1 ),
1283 array( 'rc_this_oldid' => $rev->getId() ),
1288 * Update the revision's recentchanges record if fields have been hidden
1290 * @param int $bitfield new rev_deleted bitfield value
1292 function updateRecentChangesLog( $row, $bitfield ) {
1293 $this->dbw
->update( 'recentchanges',
1294 array( 'rc_deleted' => $bitfield,
1295 'rc_patrolled' => 1 ),
1296 array( 'rc_logid' => $row->log_id
),
1301 * Touch the page's cache invalidation timestamp; this forces cached
1302 * history views to refresh, so any newly hidden or shown fields will
1304 * @param Title $title
1306 function updatePage( $title ) {
1307 $title->invalidateCache();
1308 $title->purgeSquid();
1310 // Extensions that require referencing previous revisions may need this
1311 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1315 * Record a log entry on the action
1316 * @param Title $title, page where item was removed from
1317 * @param int $count the number of revisions altered for this page
1318 * @param int $nbitfield the new _deleted value
1319 * @param int $obitfield the old _deleted value
1320 * @param string $comment
1321 * @param Title $target, the relevant page
1322 * @param string $param, URL param
1323 * @param Array $items
1325 function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target, $param, $items = array() ) {
1326 // Put things hidden from sysops in the oversight log
1327 $logtype = ( ($nbitfield |
$obitfield) & Revision
::DELETED_RESTRICTED
) ?
'oversight' : 'delete';
1328 $log = new LogPage( $logtype );
1329 // FIXME: do this better
1330 if( $param=='logid' ) {
1331 $params = array( implode( ',', $items) );
1332 $reason = wfMsgExt('logdelete-logaction', array('parsemag'), $count, $nbitfield );
1333 if($comment) $reason .= ": $comment";
1334 $log->addEntry( 'event', $title, $reason, $params );
1336 // Add params for effected page and ids
1337 $params = array( $target->getPrefixedText(), $param, implode( ',', $items) );
1338 $reason = wfMsgExt('revdelete-logaction', array('parsemag'), $count, $nbitfield );
1339 if($comment) $reason .= ": $comment";
1340 $log->addEntry( 'revision', $title, $reason, $params );