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>' );
696 if( $this->deleteKey
=='logid' ) {
697 $wgOut->addWikiText( Xml
::element( 'span', array( 'class' => 'success' ), wfMsg( 'logdelete-success' ) ), false );
698 $this->showLogItems( $request );
699 } else if( $this->deleteKey
=='oldid' ||
$this->deleteKey
=='artimestamp' ) {
700 $wgOut->addWikiText( Xml
::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
701 $this->showRevs( $request );
702 } else if( $this->deleteKey
=='fileid' ) {
703 $wgOut->addWikiText( Xml
::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
704 $this->showImages( $request );
705 } else if( $this->deleteKey
=='oldimage' ) {
706 $this->showImages( $request );
711 * Put together a rev_deleted bitfield from the submitted checkboxes
712 * @param WebRequest $request
715 private function extractBitfield( $request ) {
717 foreach( $this->checks
as $item ) {
718 list( /* message */ , $name, $field ) = $item;
719 if( $request->getCheck( $name ) ) {
726 private function save( $bitfield, $reason, $title ) {
727 $dbw = wfGetDB( DB_MASTER
);
728 // Don't allow simply locking the interface for no reason
729 if( $bitfield == Revision
::DELETED_RESTRICTED
) {
732 $deleter = new RevisionDeleter( $dbw );
733 // By this point, only one of the below should be set
734 if( isset($this->revisions
) ) {
735 return $deleter->setRevVisibility( $title, $this->revisions
, $bitfield, $reason );
736 } else if( isset($this->archrevs
) ) {
737 return $deleter->setArchiveVisibility( $title, $this->archrevs
, $bitfield, $reason );
738 } else if( isset($this->ofiles
) ) {
739 return $deleter->setOldImgVisibility( $title, $this->ofiles
, $bitfield, $reason );
740 } else if( isset($this->afiles
) ) {
741 return $deleter->setArchFileVisibility( $title, $this->afiles
, $bitfield, $reason );
742 } else if( isset($this->events
) ) {
743 return $deleter->setEventVisibility( $this->events
, $bitfield, $reason );
749 * Implements the actions for Revision Deletion.
750 * @addtogroup SpecialPage
752 class RevisionDeleter
{
753 function __construct( $db ) {
758 * @param $title, the page these events apply to
759 * @param array $items list of revision ID numbers
760 * @param int $bitfield new rev_deleted value
761 * @param string $comment Comment for log records
763 function setRevVisibility( $title, $items, $bitfield, $comment ) {
766 $userAllowedAll = $success = true;
769 // Run through and pull all our data in one query
770 foreach( $items as $revid ) {
771 $where[] = intval($revid);
773 $whereClause = 'rev_id IN(' . implode(',',$where) . ')';
774 $result = $this->dbw
->select( 'revision', '*',
775 array( 'rev_page' => $title->getArticleID(),
778 while( $row = $this->dbw
->fetchObject( $result ) ) {
779 $revObjs[$row->rev_id
] = new Revision( $row );
782 foreach( $items as $revid ) {
783 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
785 continue; // Must exist
786 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
787 $userAllowedAll=false;
790 // For logging, maintain a count of revisions
791 if( $revObjs[$revid]->mDeleted
!= $bitfield ) {
795 $this->updateRevision( $revObjs[$revid], $bitfield );
796 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
800 // Don't log or touch if nothing changed
801 if( $revCount > 0 ) {
802 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted
,
803 $comment, $title, 'oldid', $revIDs );
804 $this->updatePage( $title );
806 // Where all revs allowed to be set?
807 if( !$userAllowedAll ) {
808 //FIXME: still might be confusing???
809 $wgOut->permissionRequired( 'hiderevision' );
817 * @param $title, the page these events apply to
818 * @param array $items list of revision ID numbers
819 * @param int $bitfield new rev_deleted value
820 * @param string $comment Comment for log records
822 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
825 $userAllowedAll = $success = true;
828 // Run through and pull all our data in one query
829 foreach( $items as $timestamp ) {
830 $where[] = $this->dbw
->addQuotes( $timestamp );
832 $whereClause = 'ar_timestamp IN(' . implode(',',$where) . ')';
833 $result = $this->dbw
->select( 'archive', '*',
834 array( 'ar_namespace' => $title->getNamespace(),
835 'ar_title' => $title->getDBKey(),
838 while( $row = $this->dbw
->fetchObject( $result ) ) {
839 $revObjs[$row->ar_timestamp
] = new Revision( array(
840 'page' => $title->getArticleId(),
841 'id' => $row->ar_rev_id
,
842 'text' => $row->ar_text_id
,
843 'comment' => $row->ar_comment
,
844 'user' => $row->ar_user
,
845 'user_text' => $row->ar_user_text
,
846 'timestamp' => $row->ar_timestamp
,
847 'minor_edit' => $row->ar_minor_edit
,
848 'text_id' => $row->ar_text_id
,
849 'deleted' => $row->ar_deleted
,
850 'len' => $row->ar_len
) );
853 foreach( $items as $timestamp ) {
854 // This will only select the first revision with this timestamp.
855 // Since they are all selected/deleted at once, we can just check the
856 // permissions of one. UPDATE is done via timestamp, so all revs are set.
857 if( !is_object($revObjs[$timestamp]) ) {
859 continue; // Must exist
860 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
861 $userAllowedAll=false;
864 // Which revisions did we change anything about?
865 if( $revObjs[$timestamp]->mDeleted
!= $bitfield ) {
866 $Id_set[]=$timestamp;
869 $this->updateArchive( $revObjs[$timestamp], $bitfield );
872 // For logging, maintain a count of revisions
874 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted
,
875 $comment, $title, 'artimestamp', $Id_set );
877 // Where all revs allowed to be set?
878 if( !$userAllowedAll ) {
879 $wgOut->permissionRequired( 'hiderevision' );
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 setOldImgVisibility( $title, $items, $bitfield, $comment ) {
895 $userAllowedAll = $success = true;
898 // Run through and pull all our data in one query
899 foreach( $items as $timestamp ) {
900 $where[] = $this->dbw
->addQuotes( $timestamp.'!'.$title->getDbKey() );
902 $whereClause = 'oi_archive_name IN(' . implode(',',$where) . ')';
903 $result = $this->dbw
->select( 'oldimage', '*',
904 array( 'oi_name' => $title->getDbKey(),
907 while( $row = $this->dbw
->fetchObject( $result ) ) {
908 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
909 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
910 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
913 foreach( $items as $timestamp ) {
914 $archivename = $timestamp.'!'.$title->getDbKey();
915 if( !isset($filesObjs[$archivename]) ) {
917 continue; // Must exist
918 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
919 $userAllowedAll=false;
924 // Which revisions did we change anything about?
925 if( $filesObjs[$archivename]->deleted
!= $bitfield ) {
929 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
930 // If this image is currently hidden...
931 if( $filesObjs[$archivename]->deleted
& File
::DELETED_FILE
) {
932 if( $bitfield & File
::DELETED_FILE
) {
933 # Leave it alone if we are not changing this...
937 # We are moving this out
938 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
941 // Is it just now becoming hidden?
942 } else if( $bitfield & File
::DELETED_FILE
) {
943 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
948 // If our file operations fail, then revert back the db
949 if( $transaction==false ) {
950 $this->dbw
->rollback();
953 $this->dbw
->commit();
957 // Log if something was changed
959 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted
,
960 $comment, $title, 'oldimage', $set );
962 $file = wfLocalFile( $title );
964 $file->purgeHistory();
965 # Invalidate cache for all pages using this file
966 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
969 // Where all revs allowed to be set?
970 if( !$userAllowedAll ) {
971 $wgOut->permissionRequired( 'hiderevision' );
979 * @param $title, the page these events apply to
980 * @param array $items list of revision ID numbers
981 * @param int $bitfield new rev_deleted value
982 * @param string $comment Comment for log records
984 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
987 $userAllowedAll = $success = true;
991 // Run through and pull all our data in one query
992 foreach( $items as $id ) {
993 $where[] = intval($id);
995 $whereClause = 'fa_id IN(' . implode(',',$where) . ')';
996 $result = $this->dbw
->select( 'filearchive', '*',
997 array( 'fa_name' => $title->getDbKey(),
1000 while( $row = $this->dbw
->fetchObject( $result ) ) {
1001 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
1004 foreach( $items as $fileid ) {
1005 if( !isset($filesObjs[$fileid]) ) {
1007 continue; // Must exist
1008 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
1009 $userAllowedAll=false;
1012 // Which revisions did we change anything about?
1013 if( $filesObjs[$fileid]->deleted
!= $bitfield ) {
1017 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1020 // Log if something was changed
1022 $this->updateLog( $title, $count, $bitfield, $comment,
1023 $filesObjs[$fileid]->deleted
, $title, 'fileid', $Id_set );
1025 // Where all revs allowed to be set?
1026 if( !$userAllowedAll ) {
1027 $wgOut->permissionRequired( 'hiderevision' );
1035 * @param array $items list of log ID numbers
1036 * @param int $bitfield new log_deleted value
1037 * @param string $comment Comment for log records
1039 function setEventVisibility( $items, $bitfield, $comment ) {
1042 $userAllowedAll = $success = true;
1043 $logs_count = array();
1044 $logs_Ids = array();
1046 // Run through and pull all our data in one query
1047 foreach( $items as $logid ) {
1048 $where[] = intval($logid);
1050 $whereClause = 'log_id IN(' . implode(',',$where) . ')';
1051 $result = $this->dbw
->select( 'logging', '*',
1052 array( $whereClause ),
1054 while( $row = $this->dbw
->fetchObject( $result ) ) {
1055 $logRows[$row->log_id
] = $row;
1058 foreach( $items as $logid ) {
1059 if( !isset($logRows[$logid]) ) {
1061 continue; // Must exist
1062 } else if( !LogPage
::userCan($logRows[$logid], Revision
::DELETED_RESTRICTED
)
1063 ||
$logRows[$logid]->log_type
=='oversight' ) {
1064 // Don't hide from oversight log!!!
1065 $userAllowedAll=false;
1068 $logtype = $logRows[$logid]->log_type
;
1069 // For logging, maintain a count of events per log type
1070 if( !isset( $logs_count[$logtype] ) ) {
1071 $logs_count[$logtype]=0;
1072 $logs_Ids[$logtype]=array();
1074 // Which logs did we change anything about?
1075 if( $logRows[$logid]->log_deleted
!= $bitfield ) {
1076 $logs_Ids[$logtype][]=$logid;
1077 $logs_count[$logtype]++
;
1079 $this->updateLogs( $logRows[$logid], $bitfield );
1080 $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
1083 foreach( $logs_count as $logtype => $count ) {
1084 // Don't log or touch if nothing changed
1086 $target = SpecialPage
::getTitleFor( 'Log', $logtype );
1087 $this->updateLog( $target, $count, $bitfield, $logRows[$logid]->log_deleted
,
1088 $comment, $target, 'logid', $logs_Ids[$logtype] );
1091 // Where all revs allowed to be set?
1092 if( !$userAllowedAll ) {
1093 $wgOut->permissionRequired( 'hiderevision' );
1101 * Moves an image to a safe private location
1102 * Caller is responsible for clearing caches
1103 * @param File $oimage
1104 * @returns mixed, timestamp string on success, false on failure
1106 function makeOldImagePrivate( $oimage ) {
1107 global $wgFileStore, $wgUseSquid;
1109 $transaction = new FSTransaction();
1110 if( !FileStore
::lock() ) {
1111 wfDebug( __METHOD__
.": failed to acquire file store lock, aborting\n" );
1114 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1115 // Dupe the file into the file store
1116 if( file_exists( $oldpath ) ) {
1117 // Is our directory configured?
1118 if( $store = FileStore
::get( 'deleted' ) ) {
1119 if( !$oimage->sha1
) {
1120 $oimage->upgradeRow(); // sha1 may be missing
1122 $key = $oimage->sha1
. '.' . $oimage->getExtension();
1123 $transaction->add( $store->insert( $key, $oldpath, FileStore
::DELETE_ORIGINAL
) );
1127 $transaction = false; // Return an error and do nothing
1130 wfDebug( __METHOD__
." deleting already-missing '$oldpath'; moving on to database\n" );
1133 $transaction = new FSTransaction(); // empty
1136 if( $transaction === false ) {
1138 wfDebug( __METHOD__
.": import to file store failed, aborting\n" );
1139 throw new MWException( "Could not archive and delete file $oldpath" );
1143 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1144 $transaction->commit();
1145 FileStore
::unlock();
1147 $m = explode('!',$oimage->archive_name
,2);
1154 * Moves an image from a safe private location
1155 * Caller is responsible for clearing caches
1156 * @param File $oimage
1157 * @returns mixed, string timestamp on success, false on failure
1159 function makeOldImagePublic( $oimage ) {
1160 global $wgFileStore;
1162 $transaction = new FSTransaction();
1163 if( !FileStore
::lock() ) {
1164 wfDebug( __METHOD__
." could not acquire filestore lock\n" );
1168 $store = FileStore
::get( 'deleted' );
1170 wfDebug( __METHOD__
.": skipping row with no file.\n" );
1174 $key = $oimage->sha1
.'.'.$oimage->getExtension();
1175 $destDir = $oimage->getArchivePath();
1176 if( !is_dir( $destDir ) ) {
1177 wfMkdirParents( $destDir );
1179 $destPath = $destDir . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1180 // Check if any other stored revisions use this file;
1181 // if so, we shouldn't remove the file from the hidden
1182 // archives so they will still work. Check hidden files first.
1183 $useCount = $this->dbw
->selectField( 'oldimage', '1',
1184 array( 'oi_sha1' => $oimage->sha1
,
1185 'oi_deleted & '.File
::DELETED_FILE
=> File
::DELETED_FILE
),
1186 __METHOD__
, array( 'FOR UPDATE' ) );
1187 // Check the rest of the deleted archives too.
1188 // (these are the ones that don't show in the image history)
1190 $useCount = $this->dbw
->selectField( 'filearchive', '1',
1191 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1192 __METHOD__
, array( 'FOR UPDATE' ) );
1195 if( $useCount == 0 ) {
1196 wfDebug( __METHOD__
.": nothing else using {$oimage->sha1}, will deleting after\n" );
1197 $flags = FileStore
::DELETE_ORIGINAL
;
1201 $transaction->add( $store->export( $key, $destPath, $flags ) );
1203 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1204 $transaction->commit();
1205 FileStore
::unlock();
1207 $m = explode('!',$oimage->archive_name
,2);
1214 * Update the revision's rev_deleted field
1215 * @param Revision $rev
1216 * @param int $bitfield new rev_deleted bitfield value
1218 function updateRevision( $rev, $bitfield ) {
1219 $this->dbw
->update( 'revision',
1220 array( 'rev_deleted' => $bitfield ),
1221 array( 'rev_id' => $rev->getId() ),
1226 * Update the revision's rev_deleted field
1227 * @param Revision $rev
1228 * @param int $bitfield new rev_deleted bitfield value
1230 function updateArchive( $rev, $bitfield ) {
1231 $this->dbw
->update( 'archive',
1232 array( 'ar_deleted' => $bitfield ),
1233 array( 'ar_rev_id' => $rev->getId() ),
1238 * Update the images's oi_deleted field
1239 * @param File $oimage
1240 * @param int $bitfield new rev_deleted bitfield value
1242 function updateOldFiles( $oimage, $bitfield ) {
1243 $this->dbw
->update( 'oldimage',
1244 array( 'oi_deleted' => $bitfield ),
1245 array( 'oi_archive_name' => $oimage->archive_name
),
1250 * Update the images's fa_deleted field
1251 * @param ArchivedFile $file
1252 * @param int $bitfield new rev_deleted bitfield value
1254 function updateArchFiles( $file, $bitfield ) {
1255 $this->dbw
->update( 'filearchive',
1256 array( 'fa_deleted' => $bitfield ),
1257 array( 'fa_id' => $file->getID() ),
1262 * Update the logging log_deleted field
1264 * @param int $bitfield new rev_deleted bitfield value
1266 function updateLogs( $row, $bitfield ) {
1267 $this->dbw
->update( 'logging',
1268 array( 'log_deleted' => $bitfield ),
1269 array( 'log_id' => $row->log_id
),
1274 * Update the revision's recentchanges record if fields have been hidden
1275 * @param Revision $rev
1276 * @param int $bitfield new rev_deleted bitfield value
1278 function updateRecentChangesEdits( $rev, $bitfield ) {
1279 $this->dbw
->update( 'recentchanges',
1280 array( 'rc_deleted' => $bitfield,
1281 'rc_patrolled' => 1 ),
1282 array( 'rc_this_oldid' => $rev->getId() ),
1287 * Update the revision's recentchanges record if fields have been hidden
1289 * @param int $bitfield new rev_deleted bitfield value
1291 function updateRecentChangesLog( $row, $bitfield ) {
1292 $this->dbw
->update( 'recentchanges',
1293 array( 'rc_deleted' => $bitfield,
1294 'rc_patrolled' => 1 ),
1295 array( 'rc_logid' => $row->log_id
),
1300 * Touch the page's cache invalidation timestamp; this forces cached
1301 * history views to refresh, so any newly hidden or shown fields will
1303 * @param Title $title
1305 function updatePage( $title ) {
1306 $title->invalidateCache();
1307 $title->purgeSquid();
1309 // Extensions that require referencing previous revisions may need this
1310 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1314 * Record a log entry on the action
1315 * @param Title $title, page where item was removed from
1316 * @param int $count the number of revisions altered for this page
1317 * @param int $nbitfield the new _deleted value
1318 * @param int $obitfield the old _deleted value
1319 * @param string $comment
1320 * @param Title $target, the relevant page
1321 * @param string $param, URL param
1322 * @param Array $items
1324 function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target, $param, $items = array() ) {
1325 // Put things hidden from sysops in the oversight log
1326 $logtype = ( ($nbitfield |
$obitfield) & Revision
::DELETED_RESTRICTED
) ?
'oversight' : 'delete';
1327 $log = new LogPage( $logtype );
1328 // FIXME: do this better
1329 if( $param=='logid' ) {
1330 $params = array( implode( ',', $items) );
1331 $reason = wfMsgExt('logdelete-logaction', array('parsemag'), $count, $nbitfield );
1332 if($comment) $reason .= ": $comment";
1333 $log->addEntry( 'event', $title, $reason, $params );
1335 // Add params for effected page and ids
1336 $params = array( $target->getPrefixedText(), $param, implode( ',', $items) );
1337 $reason = wfMsgExt('revdelete-logaction', array('parsemag'), $count, $nbitfield );
1338 if($comment) $reason .= ": $comment";
1339 $log->addEntry( 'revision', $title, $reason, $params );