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 ) {
71 global $wgUser, $wgOut;
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 # Give a link to the log for this page
88 if( !is_null($this->page
) && $this->page
->getNamespace() > -1 ) {
91 $logtitle = SpecialPage
::getTitleFor( 'Log' );
92 $links[] = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
93 wfArrayToCGI( array( 'page' => $this->page
->getPrefixedUrl() ) ) );
94 # Give a link to the page history
95 $links[] = $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml( 'pagehist' ),
96 wfArrayToCGI( array( 'action' => 'history' ) ) );
97 # Link to deleted edits
98 if( $wgUser->isAllowed('undelete') ) {
99 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
100 $links[] = $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
101 wfArrayToCGI( array( 'target' => $this->page
->getPrefixedUrl() ) ) );
103 # Logs themselves don't have histories or archived revisions
104 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
106 // At this point, we should only have one of these
108 $this->revisions
= $oldids;
109 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
110 $this->deleteKey
='oldid';
111 } else if( $artimestamps ) {
112 $this->archrevs
= $artimestamps;
113 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
114 $this->deleteKey
='artimestamp';
116 $this->ofiles
= $img;
117 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
118 $this->deleteKey
='oldimage';
119 } else if( $fileids ) {
120 $this->afiles
= $fileids;
121 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
122 $this->deleteKey
='fileid';
123 } else if( $logids ) {
124 $this->events
= $logids;
125 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage
::DELETED_ACTION
);
126 $this->deleteKey
='logid';
128 // Our checkbox messages depends one what we are doing,
129 // e.g. we don't hide "text" for logs or images
130 $this->checks
= array(
132 array( 'revdelete-hide-comment', 'wpHideComment', Revision
::DELETED_COMMENT
),
133 array( 'revdelete-hide-user', 'wpHideUser', Revision
::DELETED_USER
),
134 array( 'revdelete-hide-restricted', 'wpHideRestricted', Revision
::DELETED_RESTRICTED
) );
138 * Show a deleted file version requested by the visitor.
140 private function showFile( $key ) {
141 global $wgOut, $wgRequest;
144 # We mustn't allow the output to be Squid cached, otherwise
145 # if an admin previews a deleted image, and it's cached, then
146 # a user without appropriate permissions can toddle off and
147 # nab the image, and Squid will serve it
148 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
149 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
150 $wgRequest->response()->header( 'Pragma: no-cache' );
152 $store = FileStore
::get( 'deleted' );
153 $store->stream( $key );
157 * This lets a user set restrictions for live and archived revisions
158 * @param WebRequest $request
160 function showRevs( $request ) {
161 global $wgOut, $wgUser, $action;
165 $count = ($this->deleteKey
=='oldid') ?
166 count($this->revisions
) : count($this->archrevs
);
167 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(), $count );
170 $wgOut->addHtml( "<ul>" );
172 $where = $revObjs = array();
173 $dbr = wfGetDB( DB_SLAVE
);
175 if( $this->deleteKey
=='oldid' ) {
176 // Run through and pull all our data in one query
177 foreach( $this->revisions
as $revid ) {
178 $where[] = intval($revid);
180 $whereClause = 'rev_id IN(' . implode(',',$where) . ')';
181 $result = $dbr->select( array('revision','page'), '*',
182 array( 'rev_page' => $this->page
->getArticleID(),
183 $whereClause, 'rev_page = page_id' ),
185 while( $row = $dbr->fetchObject( $result ) ) {
186 $revObjs[$row->rev_id
] = new Revision( $row );
188 foreach( $this->revisions
as $revid ) {
189 // Hiding top revisison is bad
190 if( !is_object($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
191 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
193 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
194 // If a rev is hidden from sysops
195 if( $action != 'submit') {
196 $wgOut->permissionRequired( 'hiderevision' );
199 $UserAllowed = false;
201 $wgOut->addHtml( $this->historyLine( $revObjs[$revid] ) );
202 $bitfields |
= $revObjs[$revid]->mDeleted
;
206 // Run through and pull all our data in one query
207 foreach( $this->archrevs
as $timestamp ) {
208 $where[] = $dbr->addQuotes( $timestamp );
210 $whereClause = 'ar_timestamp IN(' . implode(',',$where) . ')';
211 $result = $dbr->select( 'archive', '*',
212 array( 'ar_namespace' => $this->page
->getNamespace(),
213 'ar_title' => $this->page
->getDBKey(),
216 while( $row = $dbr->fetchObject( $result ) ) {
217 $revObjs[$row->ar_timestamp
] = new Revision( array(
218 'page' => $this->page
->getArticleId(),
219 'id' => $row->ar_rev_id
,
220 'text' => $row->ar_text_id
,
221 'comment' => $row->ar_comment
,
222 'user' => $row->ar_user
,
223 'user_text' => $row->ar_user_text
,
224 'timestamp' => $row->ar_timestamp
,
225 'minor_edit' => $row->ar_minor_edit
,
226 'text_id' => $row->ar_text_id
,
227 'deleted' => $row->ar_deleted
,
228 'len' => $row->ar_len
) );
230 foreach( $this->archrevs
as $timestamp ) {
231 if( !is_object($revObjs[$timestamp]) ) {
232 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
236 foreach( $revObjs as $rev ) {
237 if( !$rev->userCan(Revision
::DELETED_RESTRICTED
) ) {
238 // If a rev is hidden from sysops
239 if( $action != 'submit') {
240 $wgOut->permissionRequired( 'hiderevision' );
243 $UserAllowed = false;
245 $wgOut->addHtml( $this->historyLine( $rev ) );
246 $bitfields |
= $rev->mDeleted
;
249 $wgOut->addHtml( "</ul>" );
251 $wgOut->addWikiText( wfMsgHtml( 'revdelete-text' ) );
253 // Normal sysops can always see what they did, but can't always change it
254 if( !$UserAllowed ) return;
257 wfInputLabel( wfMsgHtml( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
258 wfSubmitButton( wfMsgHtml( 'revdelete-submit' ) ) );
260 wfHidden( 'wpEditToken', $wgUser->editToken() ),
261 wfHidden( 'target', $this->page
->getPrefixedText() ),
262 wfHidden( 'type', $this->deleteKey
) );
263 if( $this->deleteKey
=='oldid' ) {
264 foreach( $revObjs as $rev )
265 $hidden[] = wfHidden( 'oldid[]', $rev->getID() );
267 foreach( $revObjs as $rev )
268 $hidden[] = wfHidden( 'artimestamp[]', $rev->getTimestamp() );
270 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
271 $wgOut->addHtml( wfElement( 'form', array(
273 'action' => $special->getLocalUrl( 'action=submit' ) ),
276 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'revdelete-legend' ) . '</legend>' );
277 // FIXME: all items checked for just one rev are checked, even if not set for the others
278 foreach( $this->checks
as $item ) {
279 list( $message, $name, $field ) = $item;
280 $wgOut->addHtml( "<div>" .
281 wfCheckLabel( wfMsgHtml( $message), $name, $name, $bitfields & $field ) .
284 $wgOut->addHtml( '</fieldset>' );
285 foreach( $items as $item ) {
286 $wgOut->addHtml( '<p>' . $item . '</p>' );
288 foreach( $hidden as $item ) {
289 $wgOut->addHtml( $item );
292 $wgOut->addHtml( '</form>' );
296 * This lets a user set restrictions for archived images
297 * @param WebRequest $request
299 function showImages( $request ) {
300 global $wgOut, $wgUser, $action;
304 $count = ($this->deleteKey
=='oldimage') ?
count($this->ofiles
) : count($this->afiles
);
305 $wgOut->addWikiText( wfMsgExt( 'revdelete-selected', array('parsemag'),
306 $this->page
->getPrefixedText(), $count ) );
309 $wgOut->addHtml( "<ul>" );
311 $where = $filesObjs = array();
312 $dbr = wfGetDB( DB_SLAVE
);
313 // Live old revisions...
314 if( $this->deleteKey
=='oldimage' ) {
315 // Run through and pull all our data in one query
316 foreach( $this->ofiles
as $timestamp ) {
317 $where[] = $dbr->addQuotes( $timestamp.'!'.$this->page
->getDbKey() );
319 $whereClause = 'oi_archive_name IN(' . implode(',',$where) . ')';
320 $result = $dbr->select( 'oldimage', '*',
321 array( 'oi_name' => $this->page
->getDbKey(),
324 while( $row = $dbr->fetchObject( $result ) ) {
325 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
326 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
327 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
329 // Check through our images
330 foreach( $this->ofiles
as $timestamp ) {
331 $archivename = $timestamp.'!'.$this->page
->getDbKey();
332 if( !isset($filesObjs[$archivename]) ) {
333 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
337 foreach( $filesObjs as $file ) {
338 if( !isset($file) ) {
339 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
341 } else if( !$file->userCan(File
::DELETED_RESTRICTED
) ) {
342 // If a rev is hidden from sysops
343 if( $action != 'submit' ) {
344 $wgOut->permissionRequired( 'hiderevision' );
347 $UserAllowed = false;
349 // Inject history info
350 $wgOut->addHtml( $this->fileLine( $file ) );
351 $bitfields |
= $file->deleted
;
355 // Run through and pull all our data in one query
356 foreach( $this->afiles
as $id ) {
357 $where[] = intval($id);
359 $whereClause = 'fa_id IN(' . implode(',',$where) . ')';
360 $result = $dbr->select( 'filearchive', '*',
361 array( 'fa_name' => $this->page
->getDbKey(),
364 while( $row = $dbr->fetchObject( $result ) ) {
365 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
368 foreach( $this->afiles
as $fileid ) {
369 if( !isset($filesObjs[$fileid]) ) {
370 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
372 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
373 // If a rev is hidden from sysops
374 if( $action != 'submit' ) {
375 $wgOut->permissionRequired( 'hiderevision' );
378 $UserAllowed = false;
380 // Inject history info
381 $wgOut->addHtml( $this->archivedfileLine( $filesObjs[$fileid] ) );
382 $bitfields |
= $filesObjs[$fileid]->deleted
;
385 $wgOut->addHtml( "</ul>" );
387 $wgOut->addWikiText( wfMsgHtml( 'revdelete-text' ) );
388 //Normal sysops can always see what they did, but can't always change it
389 if( !$UserAllowed ) return;
392 wfInputLabel( wfMsgHtml( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
393 wfSubmitButton( wfMsgHtml( 'revdelete-submit' ) ) );
395 wfHidden( 'wpEditToken', $wgUser->editToken() ),
396 wfHidden( 'target', $this->page
->getPrefixedText() ),
397 wfHidden( 'type', $this->deleteKey
) );
398 if( $this->deleteKey
=='oldimage' ) {
399 foreach( $this->ofiles
as $filename )
400 $hidden[] = wfHidden( 'oldimage[]', $filename );
402 foreach( $this->afiles
as $fileid )
403 $hidden[] = wfHidden( 'fileid[]', $fileid );
405 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
406 $wgOut->addHtml( wfElement( 'form', array(
408 'action' => $special->getLocalUrl( 'action=submit' ) ),
411 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'revdelete-legend' ) . '</legend>' );
412 // FIXME: all items checked for just one file are checked, even if not set for the others
413 foreach( $this->checks
as $item ) {
414 list( $message, $name, $field ) = $item;
415 $wgOut->addHtml( '<div>' .
416 wfCheckLabel( wfMsgHtml( $message), $name, $name, $bitfields & $field ) .
419 $wgOut->addHtml( '</fieldset>' );
420 foreach( $items as $item ) {
421 $wgOut->addHtml( '<p>' . $item . '</p>' );
423 foreach( $hidden as $item ) {
424 $wgOut->addHtml( $item );
427 $wgOut->addHtml( '</form>' );
431 * This lets a user set restrictions for log items
432 * @param WebRequest $request
434 function showLogItems( $request ) {
435 global $wgOut, $wgUser, $action;
438 $wgOut->addWikiText( wfMsgExt( 'logdelete-selected', array('parsemag'), count($this->events
) ) );
441 $wgOut->addHtml( "<ul>" );
443 $where = $logRows = array();
444 $dbr = wfGetDB( DB_SLAVE
);
445 // Run through and pull all our data in one query
446 foreach( $this->events
as $logid ) {
447 $where[] = intval($logid);
449 $whereClause = 'log_id IN(' . implode(',',$where) . ')';
450 $result = $dbr->select( 'logging', '*',
451 array( $whereClause ),
453 while( $row = $dbr->fetchObject( $result ) ) {
454 $logRows[$row->log_id
] = $row;
456 foreach( $this->events
as $logid ) {
457 // Don't hide from oversight log!!!
458 if( !isset( $logRows[$logid] ) ||
$logRows[$logid]->log_type
=='oversight' ) {
459 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
461 } else if( !LogPage
::userCan( $logRows[$logid],Revision
::DELETED_RESTRICTED
) ) {
462 // If an event is hidden from sysops
463 if( $action != 'submit') {
464 $wgOut->permissionRequired( 'hiderevision' );
467 $UserAllowed = false;
469 $wgOut->addHtml( $this->logLine( $logRows[$logid] ) );
470 $bitfields |
= $logRows[$logid]->log_deleted
;
472 $wgOut->addHtml( "</ul>" );
474 $wgOut->addWikiMsg( 'revdelete-text' );
475 // Normal sysops can always see what they did, but can't always change it
476 if( !$UserAllowed ) return;
479 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
480 Xml
::submitButton( wfMsg( 'revdelete-submit' ) ) );
482 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
483 Xml
::hidden( 'type', $this->deleteKey
) );
484 foreach( $this->events
as $logid ) {
485 $hidden[] = Xml
::hidden( 'logid[]', $logid );
488 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
489 $wgOut->addHtml( Xml
::element( 'form', array(
491 'action' => $special->getLocalUrl( 'action=submit' ) ),
494 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'revdelete-legend' ) . '</legend>' );
495 // FIXME: all items checked for just on event are checked, even if not set for the others
496 foreach( $this->checks
as $item ) {
497 list( $message, $name, $field ) = $item;
498 $wgOut->addHtml( '<div>' .
499 Xml
::checkLabel( wfMsg( $message), $name, $name, $bitfields & $field ) .
502 $wgOut->addHtml( '</fieldset>' );
503 foreach( $items as $item ) {
504 $wgOut->addHtml( '<p>' . $item . '</p>' );
506 foreach( $hidden as $item ) {
507 $wgOut->addHtml( $item );
510 $wgOut->addHtml( '</form>' );
514 * @param Revision $rev
517 private function historyLine( $rev ) {
519 $date = $wgContLang->timeanddate( $rev->getTimestamp() );
521 $difflink=''; $del = '';
523 if( $this->deleteKey
=='oldid' ) {
524 $difflink = '(' . $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml('diff'),
525 'diff=' . $rev->getId() . '&oldid=prev' ) . ')';
526 $revlink = $this->skin
->makeLinkObj( $this->page
, $date, 'oldid=' . $rev->getId() );
528 // Archived revisions
529 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
530 $target = $this->page
->getPrefixedText();
531 $revlink = $this->skin
->makeLinkObj( $undelete, $date,
532 "target=$target×tamp=" . $rev->getTimestamp() );
535 if( $rev->isDeleted(Revision
::DELETED_TEXT
) ) {
536 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
537 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
538 if( !$rev->userCan(Revision
::DELETED_TEXT
) ) {
539 $revlink = '<span class="history-deleted">'.$date.'</span>';
543 return "<li> $difflink $revlink ".$this->skin
->revUserLink( $rev )." ".$this->skin
->revComment( $rev )."$del</li>";
550 private function fileLine( $file ) {
551 global $wgContLang, $wgTitle;
553 $target = $this->page
->getPrefixedText();
554 $date = $wgContLang->timeanddate( $file->getTimestamp(), true );
558 if( $file->isDeleted(File
::DELETED_FILE
) ) {
559 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
560 if( !$file->userCan(File
::DELETED_FILE
) ) {
563 $pageLink = $this->skin
->makeKnownLinkObj( $wgTitle, $date,
564 "target=$target&file=$file->sha1.".$file->getExtension() );
566 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
569 $url = $file->getUrlRel();
570 $pageLink = "<a href=\"{$url}\">{$date}</a>";
573 $data = wfMsgHtml( 'widthheight',
574 $wgContLang->formatNum( $file->getWidth() ),
575 $wgContLang->formatNum( $file->getHeight() ) ) .
576 ' (' . wfMsgHtml( 'nbytes', $wgContLang->formatNum( $file->getSize() ) ) . ')';
578 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
582 * @param ArchivedFile $file
585 private function archivedfileLine( $file ) {
586 global $wgContLang, $wgTitle;
588 $target = $this->page
->getPrefixedText();
589 $date = $wgContLang->timeanddate( $file->getTimestamp(), true );
591 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
592 $pageLink = $this->skin
->makeKnownLinkObj( $undelete, $date, "target=$target&file={$file->getKey()}" );
595 if( $file->isDeleted(File
::DELETED_FILE
) ) {
596 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
599 $data = wfMsgHtml( 'widthheight',
600 $wgContLang->formatNum( $file->getWidth() ),
601 $wgContLang->formatNum( $file->getHeight() ) ) .
602 ' (' . wfMsgHtml( 'nbytes', $wgContLang->formatNum( $file->getSize() ) ) . ')';
604 return "<li> $pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
608 * @param Array $row row
611 private function logLine( $row ) {
614 $date = $wgContLang->timeanddate( $row->log_timestamp
);
615 $paramArray = LogPage
::extractParams( $row->log_params
);
616 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
618 $logtitle = SpecialPage
::getTitleFor( 'Log' );
619 $loglink = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
620 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
622 if( !LogPage
::userCan($row,LogPage
::DELETED_ACTION
) ) {
623 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
625 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
626 $this->skin
, $paramArray, true, true );
627 if( $row->log_deleted
& LogPage
::DELETED_ACTION
)
628 $action = '<span class="history-deleted">' . $action . '</span>';
631 $userLink = $this->skin
->userLink( $row->log_user
, User
::WhoIs($row->log_user
) );
632 if( LogPage
::isDeleted($row,LogPage
::DELETED_USER
) ) {
633 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
636 $comment = $wgContLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
637 if( LogPage
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
638 $comment = '<span class="history-deleted">' . $comment . '</span>';
640 return "<li>($loglink) $date $userLink $action $comment</li>";
644 * Generate a user tool link cluster if the current user is allowed to view it
645 * @param ArchivedFile $file
646 * @return string HTML
648 private function fileUserTools( $file ) {
649 if( $file->userCan( Revision
::DELETED_USER
) ) {
650 $link = $this->skin
->userLink( $file->user
, $file->user_text
) .
651 $this->skin
->userToolLinks( $file->user
, $file->user_text
);
653 $link = wfMsgHtml( 'rev-deleted-user' );
655 if( $file->isDeleted( Revision
::DELETED_USER
) ) {
656 return '<span class="history-deleted">' . $link . '</span>';
662 * Wrap and format the given file's comment block, if the current
663 * user is allowed to view it.
665 * @param ArchivedFile $file
666 * @return string HTML
668 private function fileComment( $file ) {
669 if( $file->userCan( File
::DELETED_COMMENT
) ) {
670 $block = $this->skin
->commentBlock( $file->description
);
672 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
674 if( $file->isDeleted( File
::DELETED_COMMENT
) ) {
675 return "<span class=\"history-deleted\">$block</span>";
681 * @param WebRequest $request
683 function submit( $request ) {
684 $bitfield = $this->extractBitfield( $request );
685 $comment = $request->getText( 'wpReason' );
687 $this->target
= $request->getText( 'target' );
688 $this->title
= Title
::newFromURL( $this->target
);
690 if( $this->save( $bitfield, $comment, $this->title
) ) {
691 $this->success( $request );
692 } else if( $request->getCheck( 'oldid' ) ||
$request->getCheck( 'artimestamp' ) ) {
693 return $this->showRevs( $request );
694 } else if( $request->getCheck( 'logid' ) ) {
695 return $this->showLogs( $request );
696 } else if( $request->getCheck( 'oldimage' ) ||
$request->getCheck( 'fileid' ) ) {
697 return $this->showImages( $request );
701 private function success( $request ) {
704 $wgOut->setPagetitle( wfMsgHtml( 'actioncomplete' ) );
706 if( $this->deleteKey
=='logid' ) {
707 $wgOut->addWikiText( Xml
::element( 'span', array( 'class' => 'success' ), wfMsg( 'logdelete-success' ) ), false );
708 $this->showLogItems( $request );
709 } else if( $this->deleteKey
=='oldid' ||
$this->deleteKey
=='artimestamp' ) {
710 $wgOut->addWikiText( Xml
::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
711 $this->showRevs( $request );
712 } else if( $this->deleteKey
=='fileid' ) {
713 $wgOut->addWikiText( Xml
::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
714 $this->showImages( $request );
715 } else if( $this->deleteKey
=='oldimage' ) {
716 $this->showImages( $request );
721 * Put together a rev_deleted bitfield from the submitted checkboxes
722 * @param WebRequest $request
725 private function extractBitfield( $request ) {
727 foreach( $this->checks
as $item ) {
728 list( /* message */ , $name, $field ) = $item;
729 if( $request->getCheck( $name ) ) {
736 private function save( $bitfield, $reason, $title ) {
737 $dbw = wfGetDB( DB_MASTER
);
738 // Don't allow simply locking the interface for no reason
739 if( $bitfield == Revision
::DELETED_RESTRICTED
) {
742 $deleter = new RevisionDeleter( $dbw );
743 // By this point, only one of the below should be set
744 if( isset($this->revisions
) ) {
745 return $deleter->setRevVisibility( $title, $this->revisions
, $bitfield, $reason );
746 } else if( isset($this->archrevs
) ) {
747 return $deleter->setArchiveVisibility( $title, $this->archrevs
, $bitfield, $reason );
748 } else if( isset($this->ofiles
) ) {
749 return $deleter->setOldImgVisibility( $title, $this->ofiles
, $bitfield, $reason );
750 } else if( isset($this->afiles
) ) {
751 return $deleter->setArchFileVisibility( $title, $this->afiles
, $bitfield, $reason );
752 } else if( isset($this->events
) ) {
753 return $deleter->setEventVisibility( $this->events
, $bitfield, $reason );
759 * Implements the actions for Revision Deletion.
760 * @addtogroup SpecialPage
762 class RevisionDeleter
{
763 function __construct( $db ) {
768 * @param $title, the page these events apply to
769 * @param array $items list of revision ID numbers
770 * @param int $bitfield new rev_deleted value
771 * @param string $comment Comment for log records
773 function setRevVisibility( $title, $items, $bitfield, $comment ) {
776 $userAllowedAll = $success = true;
779 // Run through and pull all our data in one query
780 foreach( $items as $revid ) {
781 $where[] = intval($revid);
783 $whereClause = 'rev_id IN(' . implode(',',$where) . ')';
784 $result = $this->dbw
->select( 'revision', '*',
785 array( 'rev_page' => $title->getArticleID(),
788 while( $row = $this->dbw
->fetchObject( $result ) ) {
789 $revObjs[$row->rev_id
] = new Revision( $row );
792 foreach( $items as $revid ) {
793 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
795 continue; // Must exist
796 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
797 $userAllowedAll=false;
800 // For logging, maintain a count of revisions
801 if( $revObjs[$revid]->mDeleted
!= $bitfield ) {
805 $this->updateRevision( $revObjs[$revid], $bitfield );
806 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
810 // Don't log or touch if nothing changed
811 if( $revCount > 0 ) {
812 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted
,
813 $comment, $title, 'oldid', $revIDs );
814 $this->updatePage( $title );
816 // Where all revs allowed to be set?
817 if( !$userAllowedAll ) {
818 //FIXME: still might be confusing???
819 $wgOut->permissionRequired( 'hiderevision' );
827 * @param $title, the page these events apply to
828 * @param array $items list of revision ID numbers
829 * @param int $bitfield new rev_deleted value
830 * @param string $comment Comment for log records
832 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
835 $userAllowedAll = $success = true;
838 // Run through and pull all our data in one query
839 foreach( $items as $timestamp ) {
840 $where[] = $this->dbw
->addQuotes( $timestamp );
842 $whereClause = 'ar_timestamp IN(' . implode(',',$where) . ')';
843 $result = $this->dbw
->select( 'archive', '*',
844 array( 'ar_namespace' => $title->getNamespace(),
845 'ar_title' => $title->getDBKey(),
848 while( $row = $this->dbw
->fetchObject( $result ) ) {
849 $revObjs[$row->ar_timestamp
] = new Revision( array(
850 'page' => $title->getArticleId(),
851 'id' => $row->ar_rev_id
,
852 'text' => $row->ar_text_id
,
853 'comment' => $row->ar_comment
,
854 'user' => $row->ar_user
,
855 'user_text' => $row->ar_user_text
,
856 'timestamp' => $row->ar_timestamp
,
857 'minor_edit' => $row->ar_minor_edit
,
858 'text_id' => $row->ar_text_id
,
859 'deleted' => $row->ar_deleted
,
860 'len' => $row->ar_len
) );
863 foreach( $items as $timestamp ) {
864 // This will only select the first revision with this timestamp.
865 // Since they are all selected/deleted at once, we can just check the
866 // permissions of one. UPDATE is done via timestamp, so all revs are set.
867 if( !is_object($revObjs[$timestamp]) ) {
869 continue; // Must exist
870 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
871 $userAllowedAll=false;
874 // Which revisions did we change anything about?
875 if( $revObjs[$timestamp]->mDeleted
!= $bitfield ) {
876 $Id_set[]=$timestamp;
879 $this->updateArchive( $revObjs[$timestamp], $bitfield );
882 // For logging, maintain a count of revisions
884 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted
,
885 $comment, $title, 'artimestamp', $Id_set );
887 // Where all revs allowed to be set?
888 if( !$userAllowedAll ) {
889 $wgOut->permissionRequired( 'hiderevision' );
897 * @param $title, the page these events apply to
898 * @param array $items list of revision ID numbers
899 * @param int $bitfield new rev_deleted value
900 * @param string $comment Comment for log records
902 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
905 $userAllowedAll = $success = true;
908 // Run through and pull all our data in one query
909 foreach( $items as $timestamp ) {
910 $where[] = $this->dbw
->addQuotes( $timestamp.'!'.$title->getDbKey() );
912 $whereClause = 'oi_archive_name IN(' . implode(',',$where) . ')';
913 $result = $this->dbw
->select( 'oldimage', '*',
914 array( 'oi_name' => $title->getDbKey(),
917 while( $row = $this->dbw
->fetchObject( $result ) ) {
918 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
919 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
920 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
923 foreach( $items as $timestamp ) {
924 $archivename = $timestamp.'!'.$title->getDbKey();
925 if( !isset($filesObjs[$archivename]) ) {
927 continue; // Must exist
928 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
929 $userAllowedAll=false;
934 // Which revisions did we change anything about?
935 if( $filesObjs[$archivename]->deleted
!= $bitfield ) {
939 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
940 // If this image is currently hidden...
941 if( $filesObjs[$archivename]->deleted
& File
::DELETED_FILE
) {
942 if( $bitfield & File
::DELETED_FILE
) {
943 # Leave it alone if we are not changing this...
947 # We are moving this out
948 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
951 // Is it just now becoming hidden?
952 } else if( $bitfield & File
::DELETED_FILE
) {
953 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
958 // If our file operations fail, then revert back the db
959 if( $transaction==false ) {
960 $this->dbw
->rollback();
963 $this->dbw
->commit();
967 // Log if something was changed
969 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted
,
970 $comment, $title, 'oldimage', $set );
972 $file = wfLocalFile( $title );
974 $file->purgeHistory();
975 # Invalidate cache for all pages using this file
976 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
979 // Where all revs allowed to be set?
980 if( !$userAllowedAll ) {
981 $wgOut->permissionRequired( 'hiderevision' );
989 * @param $title, the page these events apply to
990 * @param array $items list of revision ID numbers
991 * @param int $bitfield new rev_deleted value
992 * @param string $comment Comment for log records
994 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
997 $userAllowedAll = $success = true;
1001 // Run through and pull all our data in one query
1002 foreach( $items as $id ) {
1003 $where[] = intval($id);
1005 $whereClause = 'fa_id IN(' . implode(',',$where) . ')';
1006 $result = $this->dbw
->select( 'filearchive', '*',
1007 array( 'fa_name' => $title->getDbKey(),
1010 while( $row = $this->dbw
->fetchObject( $result ) ) {
1011 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
1014 foreach( $items as $fileid ) {
1015 if( !isset($filesObjs[$fileid]) ) {
1017 continue; // Must exist
1018 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
1019 $userAllowedAll=false;
1022 // Which revisions did we change anything about?
1023 if( $filesObjs[$fileid]->deleted
!= $bitfield ) {
1027 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1030 // Log if something was changed
1032 $this->updateLog( $title, $count, $bitfield, $comment,
1033 $filesObjs[$fileid]->deleted
, $title, 'fileid', $Id_set );
1035 // Where all revs allowed to be set?
1036 if( !$userAllowedAll ) {
1037 $wgOut->permissionRequired( 'hiderevision' );
1045 * @param array $items list of log ID numbers
1046 * @param int $bitfield new log_deleted value
1047 * @param string $comment Comment for log records
1049 function setEventVisibility( $items, $bitfield, $comment ) {
1052 $userAllowedAll = $success = true;
1053 $logs_count = array();
1054 $logs_Ids = array();
1056 // Run through and pull all our data in one query
1057 foreach( $items as $logid ) {
1058 $where[] = intval($logid);
1060 $whereClause = 'log_id IN(' . implode(',',$where) . ')';
1061 $result = $this->dbw
->select( 'logging', '*',
1062 array( $whereClause ),
1064 while( $row = $this->dbw
->fetchObject( $result ) ) {
1065 $logRows[$row->log_id
] = $row;
1068 foreach( $items as $logid ) {
1069 if( !isset($logRows[$logid]) ) {
1071 continue; // Must exist
1072 } else if( !LogPage
::userCan($logRows[$logid], Revision
::DELETED_RESTRICTED
)
1073 ||
$logRows[$logid]->log_type
=='oversight' ) {
1074 // Don't hide from oversight log!!!
1075 $userAllowedAll=false;
1078 $logtype = $logRows[$logid]->log_type
;
1079 // For logging, maintain a count of events per log type
1080 if( !isset( $logs_count[$logtype] ) ) {
1081 $logs_count[$logtype]=0;
1082 $logs_Ids[$logtype]=array();
1084 // Which logs did we change anything about?
1085 if( $logRows[$logid]->log_deleted
!= $bitfield ) {
1086 $logs_Ids[$logtype][]=$logid;
1087 $logs_count[$logtype]++
;
1089 $this->updateLogs( $logRows[$logid], $bitfield );
1090 $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
1093 foreach( $logs_count as $logtype => $count ) {
1094 // Don't log or touch if nothing changed
1096 $target = SpecialPage
::getTitleFor( 'Log', $logtype );
1097 $this->updateLog( $target, $count, $bitfield, $logRows[$logid]->log_deleted
,
1098 $comment, $target, 'logid', $logs_Ids[$logtype] );
1101 // Where all revs allowed to be set?
1102 if( !$userAllowedAll ) {
1103 $wgOut->permissionRequired( 'hiderevision' );
1111 * Moves an image to a safe private location
1112 * Caller is responsible for clearing caches
1113 * @param File $oimage
1114 * @returns mixed, timestamp string on success, false on failure
1116 function makeOldImagePrivate( $oimage ) {
1117 global $wgFileStore, $wgUseSquid;
1119 $transaction = new FSTransaction();
1120 if( !FileStore
::lock() ) {
1121 wfDebug( __METHOD__
.": failed to acquire file store lock, aborting\n" );
1124 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1125 // Dupe the file into the file store
1126 if( file_exists( $oldpath ) ) {
1127 // Is our directory configured?
1128 if( $store = FileStore
::get( 'deleted' ) ) {
1129 if( !$oimage->sha1
) {
1130 $oimage->upgradeRow(); // sha1 may be missing
1132 $key = $oimage->sha1
. '.' . $oimage->getExtension();
1133 $transaction->add( $store->insert( $key, $oldpath, FileStore
::DELETE_ORIGINAL
) );
1137 $transaction = false; // Return an error and do nothing
1140 wfDebug( __METHOD__
." deleting already-missing '$oldpath'; moving on to database\n" );
1143 $transaction = new FSTransaction(); // empty
1146 if( $transaction === false ) {
1148 wfDebug( __METHOD__
.": import to file store failed, aborting\n" );
1149 throw new MWException( "Could not archive and delete file $oldpath" );
1153 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1154 $transaction->commit();
1155 FileStore
::unlock();
1157 $m = explode('!',$oimage->archive_name
,2);
1164 * Moves an image from a safe private location
1165 * Caller is responsible for clearing caches
1166 * @param File $oimage
1167 * @returns mixed, string timestamp on success, false on failure
1169 function makeOldImagePublic( $oimage ) {
1170 global $wgFileStore;
1172 $transaction = new FSTransaction();
1173 if( !FileStore
::lock() ) {
1174 wfDebug( __METHOD__
." could not acquire filestore lock\n" );
1178 $store = FileStore
::get( 'deleted' );
1180 wfDebug( __METHOD__
.": skipping row with no file.\n" );
1184 $key = $oimage->sha1
.'.'.$oimage->getExtension();
1185 $destDir = $oimage->getArchivePath();
1186 if( !is_dir( $destDir ) ) {
1187 wfMkdirParents( $destDir );
1189 $destPath = $destDir . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1190 // Check if any other stored revisions use this file;
1191 // if so, we shouldn't remove the file from the hidden
1192 // archives so they will still work. Check hidden files first.
1193 $useCount = $this->dbw
->selectField( 'oldimage', '1',
1194 array( 'oi_sha1' => $oimage->sha1
,
1195 'oi_deleted & '.File
::DELETED_FILE
=> File
::DELETED_FILE
),
1196 __METHOD__
, array( 'FOR UPDATE' ) );
1197 // Check the rest of the deleted archives too.
1198 // (these are the ones that don't show in the image history)
1200 $useCount = $this->dbw
->selectField( 'filearchive', '1',
1201 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1202 __METHOD__
, array( 'FOR UPDATE' ) );
1205 if( $useCount == 0 ) {
1206 wfDebug( __METHOD__
.": nothing else using {$oimage->sha1}, will deleting after\n" );
1207 $flags = FileStore
::DELETE_ORIGINAL
;
1211 $transaction->add( $store->export( $key, $destPath, $flags ) );
1213 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1214 $transaction->commit();
1215 FileStore
::unlock();
1217 $m = explode('!',$oimage->archive_name
,2);
1224 * Update the revision's rev_deleted field
1225 * @param Revision $rev
1226 * @param int $bitfield new rev_deleted bitfield value
1228 function updateRevision( $rev, $bitfield ) {
1229 $this->dbw
->update( 'revision',
1230 array( 'rev_deleted' => $bitfield ),
1231 array( 'rev_id' => $rev->getId() ),
1236 * Update the revision's rev_deleted field
1237 * @param Revision $rev
1238 * @param int $bitfield new rev_deleted bitfield value
1240 function updateArchive( $rev, $bitfield ) {
1241 $this->dbw
->update( 'archive',
1242 array( 'ar_deleted' => $bitfield ),
1243 array( 'ar_rev_id' => $rev->getId() ),
1248 * Update the images's oi_deleted field
1249 * @param File $oimage
1250 * @param int $bitfield new rev_deleted bitfield value
1252 function updateOldFiles( $oimage, $bitfield ) {
1253 $this->dbw
->update( 'oldimage',
1254 array( 'oi_deleted' => $bitfield ),
1255 array( 'oi_archive_name' => $oimage->archive_name
),
1260 * Update the images's fa_deleted field
1261 * @param ArchivedFile $file
1262 * @param int $bitfield new rev_deleted bitfield value
1264 function updateArchFiles( $file, $bitfield ) {
1265 $this->dbw
->update( 'filearchive',
1266 array( 'fa_deleted' => $bitfield ),
1267 array( 'fa_id' => $file->getID() ),
1272 * Update the logging log_deleted field
1274 * @param int $bitfield new rev_deleted bitfield value
1276 function updateLogs( $row, $bitfield ) {
1277 $this->dbw
->update( 'logging',
1278 array( 'log_deleted' => $bitfield ),
1279 array( 'log_id' => $row->log_id
),
1284 * Update the revision's recentchanges record if fields have been hidden
1285 * @param Revision $rev
1286 * @param int $bitfield new rev_deleted bitfield value
1288 function updateRecentChangesEdits( $rev, $bitfield ) {
1289 $this->dbw
->update( 'recentchanges',
1290 array( 'rc_deleted' => $bitfield,
1291 'rc_patrolled' => 1 ),
1292 array( 'rc_this_oldid' => $rev->getId() ),
1297 * Update the revision's recentchanges record if fields have been hidden
1299 * @param int $bitfield new rev_deleted bitfield value
1301 function updateRecentChangesLog( $row, $bitfield ) {
1302 $this->dbw
->update( 'recentchanges',
1303 array( 'rc_deleted' => $bitfield,
1304 'rc_patrolled' => 1 ),
1305 array( 'rc_logid' => $row->log_id
),
1310 * Touch the page's cache invalidation timestamp; this forces cached
1311 * history views to refresh, so any newly hidden or shown fields will
1313 * @param Title $title
1315 function updatePage( $title ) {
1316 $title->invalidateCache();
1317 $title->purgeSquid();
1319 // Extensions that require referencing previous revisions may need this
1320 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1324 * Record a log entry on the action
1325 * @param Title $title, page where item was removed from
1326 * @param int $count the number of revisions altered for this page
1327 * @param int $nbitfield the new _deleted value
1328 * @param int $obitfield the old _deleted value
1329 * @param string $comment
1330 * @param Title $target, the relevant page
1331 * @param string $param, URL param
1332 * @param Array $items
1334 function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target, $param, $items = array() ) {
1335 // Put things hidden from sysops in the oversight log
1336 $logtype = ( ($nbitfield |
$obitfield) & Revision
::DELETED_RESTRICTED
) ?
'oversight' : 'delete';
1337 $log = new LogPage( $logtype );
1338 // FIXME: do this better
1339 if( $param=='logid' ) {
1340 $params = array( implode( ',', $items) );
1341 $reason = wfMsgExt('logdelete-logaction', array('parsemag'), $count, $nbitfield );
1342 if($comment) $reason .= ": $comment";
1343 $log->addEntry( 'event', $title, $reason, $params );
1345 // Add params for effected page and ids
1346 $params = array( $target->getPrefixedText(), $param, implode( ',', $items) );
1347 $reason = wfMsgExt('revdelete-logaction', array('parsemag'), $count, $nbitfield );
1348 if($comment) $reason .= ": $comment";
1349 $log->addEntry( 'revision', $title, $reason, $params );