3 * Special page allowing users with the appropriate permissions to view
4 * and hide revisions. Log items can also be hidden.
10 function wfSpecialRevisiondelete( $par = null ) {
11 global $wgOut, $wgRequest, $wgUser;
12 # Handle our many different possible input types
13 $target = $wgRequest->getText( 'target' );
14 $oldid = $wgRequest->getArray( 'oldid' );
15 $artimestamp = $wgRequest->getArray( 'artimestamp' );
16 $logid = $wgRequest->getArray( 'logid' );
17 $img = $wgRequest->getArray( 'oldimage' );
18 $fileid = $wgRequest->getArray( 'fileid' );
19 # For reviewing deleted files...
20 $file = $wgRequest->getVal( 'file' );
21 # If this is a revision, then we need a target page
22 $page = Title
::newFromUrl( $target );
23 if( is_null($page) ) {
24 $wgOut->addWikiText( wfMsgHtml( 'undelete-header' ) );
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 # Logs must have a type given
34 if( $logid && !strpos($page->getDBKey(),'/') ) {
35 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
38 # Either submit or create our form
39 $form = new RevisionDeleteForm( $page, $oldid, $logid, $artimestamp, $fileid, $img, $file );
40 if( $wgRequest->wasPosted() ) {
41 $form->submit( $wgRequest );
42 } else if( $oldid ||
$artimestamp ) {
44 } else if( $fileid ||
$img ) {
47 $form->showLogItems();
49 # Show relevant lines from the deletion log. This will show even if said ID
50 # does not exist...might be helpful
51 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'delete' ) ) . "</h2>\n" );
52 LogEventsList
::showLogExtract( $wgOut, 'delete', $page->getPrefixedText() );
53 if( $wgUser->isAllowed( 'suppress' ) ){
54 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'suppress' ) ) . "</h2>\n" );
55 LogEventsList
::showLogExtract( $wgOut, 'suppress', $page->getPrefixedText() );
60 * Implements the GUI for Revision Deletion.
61 * @ingroup SpecialPage
63 class RevisionDeleteForm
{
66 * @param array $oldids
67 * @param array $logids
68 * @param array $artimestamps
69 * @param array $fileids
73 function __construct( $page, $oldids, $logids, $artimestamps, $fileids, $img, $file ) {
74 global $wgUser, $wgOut;
77 # For reviewing deleted files...
79 $oimage = RepoGroup
::singleton()->getLocalRepo()->newFromArchiveName( $page, $file );
81 // Check if user is allowed to see this file
82 if( !$oimage->userCan(File
::DELETED_FILE
) ) {
83 $wgOut->permissionRequired( 'hiderevision' );
85 $this->showFile( $file );
89 $this->skin
= $wgUser->getSkin();
90 # Give a link to the log for this page
91 if( !is_null($this->page
) && $this->page
->getNamespace() > -1 ) {
94 $logtitle = SpecialPage
::getTitleFor( 'Log' );
95 $links[] = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
96 wfArrayToCGI( array( 'page' => $this->page
->getPrefixedUrl() ) ) );
97 # Give a link to the page history
98 $links[] = $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml( 'pagehist' ),
99 wfArrayToCGI( array( 'action' => 'history' ) ) );
100 # Link to deleted edits
101 if( $wgUser->isAllowed('undelete') ) {
102 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
103 $links[] = $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
104 wfArrayToCGI( array( 'target' => $this->page
->getPrefixedUrl() ) ) );
106 # Logs themselves don't have histories or archived revisions
107 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
109 // At this point, we should only have one of these
111 $this->revisions
= $oldids;
112 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
113 $this->deleteKey
='oldid';
114 } else if( $artimestamps ) {
115 $this->archrevs
= $artimestamps;
116 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision
::DELETED_TEXT
);
117 $this->deleteKey
='artimestamp';
119 $this->ofiles
= $img;
120 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
121 $this->deleteKey
='oldimage';
122 } else if( $fileids ) {
123 $this->afiles
= $fileids;
124 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File
::DELETED_FILE
);
125 $this->deleteKey
='fileid';
126 } else if( $logids ) {
127 $this->events
= $logids;
128 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage
::DELETED_ACTION
);
129 $this->deleteKey
='logid';
131 // Our checkbox messages depends one what we are doing,
132 // e.g. we don't hide "text" for logs or images
133 $this->checks
= array(
135 array( 'revdelete-hide-comment', 'wpHideComment', Revision
::DELETED_COMMENT
),
136 array( 'revdelete-hide-user', 'wpHideUser', Revision
::DELETED_USER
) );
137 if( $wgUser->isAllowed('hiderevision') ) {
138 $this->checks
[] = array( 'revdelete-hide-restricted', 'wpHideRestricted', Revision
::DELETED_RESTRICTED
);
143 * Show a deleted file version requested by the visitor.
145 private function showFile( $key ) {
146 global $wgOut, $wgRequest;
149 # We mustn't allow the output to be Squid cached, otherwise
150 # if an admin previews a deleted image, and it's cached, then
151 # a user without appropriate permissions can toddle off and
152 # nab the image, and Squid will serve it
153 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
154 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
155 $wgRequest->response()->header( 'Pragma: no-cache' );
157 $store = FileStore
::get( 'deleted' );
158 $store->stream( $key );
162 * This lets a user set restrictions for live and archived revisions
164 function showRevs() {
165 global $wgOut, $wgUser, $action;
169 $count = ($this->deleteKey
=='oldid') ?
170 count($this->revisions
) : count($this->archrevs
);
171 $wgOut->addWikiMsg( 'revdelete-selected', $this->page
->getPrefixedText(), $count );
174 $wgOut->addHtml( "<ul>" );
176 $where = $revObjs = array();
177 $dbr = wfGetDB( DB_SLAVE
);
181 if( $this->deleteKey
=='oldid' ) {
182 // Run through and pull all our data in one query
183 foreach( $this->revisions
as $revid ) {
184 $where[] = intval($revid);
186 $whereClause = 'rev_id IN(' . implode(',',$where) . ')';
187 $result = $dbr->select( array('revision','page'), '*',
188 array( 'rev_page' => $this->page
->getArticleID(),
189 $whereClause, 'rev_page = page_id' ),
191 while( $row = $dbr->fetchObject( $result ) ) {
192 $revObjs[$row->rev_id
] = new Revision( $row );
194 foreach( $this->revisions
as $revid ) {
195 // Hiding top revisison is bad
196 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
198 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
199 // If a rev is hidden from sysops
200 if( $action != 'submit') {
201 $wgOut->permissionRequired( 'hiderevision' );
204 $UserAllowed = false;
207 $wgOut->addHtml( $this->historyLine( $revObjs[$revid] ) );
208 $bitfields |
= $revObjs[$revid]->mDeleted
;
212 // Run through and pull all our data in one query
213 foreach( $this->archrevs
as $timestamp ) {
214 $where[] = $dbr->addQuotes( $timestamp );
216 $whereClause = 'ar_timestamp IN(' . implode(',',$where) . ')';
217 $result = $dbr->select( 'archive', '*',
218 array( 'ar_namespace' => $this->page
->getNamespace(),
219 'ar_title' => $this->page
->getDBKey(),
222 while( $row = $dbr->fetchObject( $result ) ) {
223 $revObjs[$row->ar_timestamp
] = new Revision( array(
224 'page' => $this->page
->getArticleId(),
225 'id' => $row->ar_rev_id
,
226 'text' => $row->ar_text_id
,
227 'comment' => $row->ar_comment
,
228 'user' => $row->ar_user
,
229 'user_text' => $row->ar_user_text
,
230 'timestamp' => $row->ar_timestamp
,
231 'minor_edit' => $row->ar_minor_edit
,
232 'text_id' => $row->ar_text_id
,
233 'deleted' => $row->ar_deleted
,
234 'len' => $row->ar_len
) );
236 foreach( $this->archrevs
as $timestamp ) {
237 if( !isset($revObjs[$timestamp]) ) {
239 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
240 // If a rev is hidden from sysops
241 if( $action != 'submit') {
242 $wgOut->permissionRequired( 'hiderevision' );
245 $UserAllowed = false;
248 $wgOut->addHtml( $this->historyLine( $revObjs[$timestamp] ) );
249 $bitfields |
= $revObjs[$timestamp]->mDeleted
;
253 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
257 $wgOut->addHtml( "</ul>" );
259 $wgOut->addWikiText( wfMsgHtml( 'revdelete-text' ) );
261 // Normal sysops can always see what they did, but can't always change it
262 if( !$UserAllowed ) return;
265 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
266 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
269 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
270 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
271 Xml
::hidden( 'type', $this->deleteKey
)
273 if( $this->deleteKey
=='oldid' ) {
274 foreach( $revObjs as $rev )
275 $hidden[] = wfHidden( 'oldid[]', $rev->getId() );
277 foreach( $revObjs as $rev )
278 $hidden[] = wfHidden( 'artimestamp[]', $rev->getTimestamp() );
280 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
282 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
283 'id' => 'mw-revdel-form-revisions' ) ) .
284 Xml
::openElement( 'fieldset' ) .
285 xml
::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
287 // FIXME: all items checked for just one rev are checked, even if not set for the others
288 foreach( $this->checks
as $item ) {
289 list( $message, $name, $field ) = $item;
290 $wgOut->addHtml( Xml
::tags( 'div', null, Xml
::checkLabel( wfMsg( $message ), $name, $name, $bitfields & $field ) ) );
292 foreach( $items as $item ) {
293 $wgOut->addHtml( Xml
::tags( 'p', null, $item ) );
295 foreach( $hidden as $item ) {
296 $wgOut->addHtml( $item );
299 Xml
::closeElement( 'fieldset' ) .
300 Xml
::closeElement( 'form' ) . "\n"
306 * This lets a user set restrictions for archived images
308 function showImages() {
309 global $wgOut, $wgUser, $action;
313 $count = ($this->deleteKey
=='oldimage') ?
count($this->ofiles
) : count($this->afiles
);
314 $wgOut->addWikiText( wfMsgExt( 'revdelete-selected', array('parsemag'),
315 $this->page
->getPrefixedText(), $count ) );
318 $wgOut->addHtml( "<ul>" );
320 $where = $filesObjs = array();
321 $dbr = wfGetDB( DB_SLAVE
);
322 // Live old revisions...
324 if( $this->deleteKey
=='oldimage' ) {
325 // Run through and pull all our data in one query
326 foreach( $this->ofiles
as $timestamp ) {
327 $where[] = $dbr->addQuotes( $timestamp.'!'.$this->page
->getDbKey() );
329 $whereClause = 'oi_archive_name IN(' . implode(',',$where) . ')';
330 $result = $dbr->select( 'oldimage', '*',
331 array( 'oi_name' => $this->page
->getDbKey(),
334 while( $row = $dbr->fetchObject( $result ) ) {
335 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
336 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
337 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
339 // Check through our images
340 foreach( $this->ofiles
as $timestamp ) {
341 $archivename = $timestamp.'!'.$this->page
->getDbKey();
342 if( !isset($filesObjs[$archivename]) ) {
344 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
345 // If a rev is hidden from sysops
346 if( $action != 'submit' ) {
347 $wgOut->permissionRequired( 'hiderevision' );
350 $UserAllowed = false;
353 // Inject history info
354 $wgOut->addHtml( $this->fileLine( $filesObjs[$archivename] ) );
355 $bitfields |
= $filesObjs[$archivename]->deleted
;
359 // Run through and pull all our data in one query
360 foreach( $this->afiles
as $id ) {
361 $where[] = intval($id);
363 $whereClause = 'fa_id IN(' . implode(',',$where) . ')';
364 $result = $dbr->select( 'filearchive', '*',
365 array( 'fa_name' => $this->page
->getDbKey(),
368 while( $row = $dbr->fetchObject( $result ) ) {
369 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
372 foreach( $this->afiles
as $fileid ) {
373 if( !isset($filesObjs[$fileid]) ) {
375 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
376 // If a rev is hidden from sysops
377 if( $action != 'submit' ) {
378 $wgOut->permissionRequired( 'hiderevision' );
381 $UserAllowed = false;
384 // Inject history info
385 $wgOut->addHtml( $this->archivedfileLine( $filesObjs[$fileid] ) );
386 $bitfields |
= $filesObjs[$fileid]->deleted
;
390 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
394 $wgOut->addHtml( "</ul>" );
396 $wgOut->addWikiText( wfMsgHtml( 'revdelete-text' ) );
397 //Normal sysops can always see what they did, but can't always change it
398 if( !$UserAllowed ) return;
401 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
402 Xml
::submitButton( wfMsg( 'revdelete-submit' ) )
405 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
406 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
407 Xml
::hidden( 'type', $this->deleteKey
)
409 if( $this->deleteKey
=='oldimage' ) {
410 foreach( $this->ofiles
as $filename )
411 $hidden[] = wfHidden( 'oldimage[]', $filename );
413 foreach( $this->afiles
as $fileid )
414 $hidden[] = wfHidden( 'fileid[]', $fileid );
416 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
418 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
419 'id' => 'mw-revdel-form-filerevisions' ) ) .
420 Xml
::openElement( 'fieldset' ) .
421 xml
::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
423 // FIXME: all items checked for just one file are checked, even if not set for the others
424 foreach( $this->checks
as $item ) {
425 list( $message, $name, $field ) = $item;
426 $wgOut->addHtml( Xml
::tags( 'div', null, Xml
::checkLabel( wfMsg( $message ), $name, $name, $bitfields & $field ) ) );
428 foreach( $items as $item ) {
429 $wgOut->addHtml( Xml
::tags( 'p', null, $item ) );
431 foreach( $hidden as $item ) {
432 $wgOut->addHtml( $item );
436 Xml
::closeElement( 'fieldset' ) .
437 Xml
::closeElement( 'form' ) . "\n"
442 * This lets a user set restrictions for log items
444 function showLogItems() {
445 global $wgOut, $wgUser, $action, $wgMessageCache;
448 $wgOut->addWikiText( wfMsgExt( 'logdelete-selected', array('parsemag'), count($this->events
) ) );
451 $wgOut->addHtml( "<ul>" );
453 $where = $logRows = array();
454 $dbr = wfGetDB( DB_SLAVE
);
455 // Run through and pull all our data in one query
457 foreach( $this->events
as $logid ) {
458 $where[] = intval($logid);
460 list($log,$logtype) = explode( '/',$this->page
->getDBKey(), 2 );
461 $whereClause = "log_type = '$logtype' AND log_id IN(" . implode(',',$where) . ")";
462 $result = $dbr->select( 'logging', '*',
463 array( $whereClause ),
465 while( $row = $dbr->fetchObject( $result ) ) {
466 $logRows[$row->log_id
] = $row;
468 $wgMessageCache->loadAllMessages();
469 foreach( $this->events
as $logid ) {
470 // Don't hide from oversight log!!!
471 if( !isset( $logRows[$logid] ) ||
$logRows[$logid]->log_type
=='suppress' ) {
473 } else if( !LogEventsList
::userCan( $logRows[$logid],Revision
::DELETED_RESTRICTED
) ) {
474 // If an event is hidden from sysops
475 if( $action != 'submit') {
476 $wgOut->permissionRequired( 'hiderevision' );
479 $UserAllowed = false;
482 $wgOut->addHtml( $this->logLine( $logRows[$logid] ) );
483 $bitfields |
= $logRows[$logid]->log_deleted
;
486 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
490 $wgOut->addHtml( "</ul>" );
492 $wgOut->addWikiMsg( 'revdelete-text' );
493 // Normal sysops can always see what they did, but can't always change it
494 if( !$UserAllowed ) return;
497 Xml
::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
498 Xml
::submitButton( wfMsg( 'revdelete-submit' ) ) );
500 Xml
::hidden( 'wpEditToken', $wgUser->editToken() ),
501 Xml
::hidden( 'target', $this->page
->getPrefixedText() ),
502 Xml
::hidden( 'type', $this->deleteKey
) );
503 foreach( $this->events
as $logid ) {
504 $hidden[] = Xml
::hidden( 'logid[]', $logid );
507 $special = SpecialPage
::getTitleFor( 'Revisiondelete' );
509 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
510 'id' => 'mw-revdel-form-logs' ) ) .
511 Xml
::openElement( 'fieldset' ) .
512 xml
::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
514 // FIXME: all items checked for just on event are checked, even if not set for the others
515 foreach( $this->checks
as $item ) {
516 list( $message, $name, $field ) = $item;
517 $wgOut->addHtml( Xml
::tags( 'div', null, Xml
::checkLabel( wfMsg( $message ), $name, $name, $bitfields & $field ) ) );
519 foreach( $items as $item ) {
520 $wgOut->addHtml( Xml
::tags( 'p', null, $item ) );
522 foreach( $hidden as $item ) {
523 $wgOut->addHtml( $item );
527 Xml
::closeElement( 'fieldset' ) .
528 Xml
::closeElement( 'form' ) . "\n"
533 * @param Revision $rev
536 private function historyLine( $rev ) {
539 $date = $wgContLang->timeanddate( $rev->getTimestamp() );
540 $difflink = $del = '';
542 if( $this->deleteKey
=='oldid' ) {
543 $revlink = $this->skin
->makeLinkObj( $this->page
, $date, 'oldid=' . $rev->getId() );
544 $difflink = '(' . $this->skin
->makeKnownLinkObj( $this->page
, wfMsgHtml('diff'),
545 'diff=' . $rev->getId() . '&oldid=prev' ) . ')';
546 // Archived revisions
548 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
549 $target = $this->page
->getPrefixedText();
550 $revlink = $this->skin
->makeLinkObj( $undelete, $date,
551 "target=$target×tamp=" . $rev->getTimestamp() );
552 $difflink = '(' . $this->skin
->makeKnownLinkObj( $undelete, wfMsgHtml('diff'),
553 "target=$target&diff=prev×tamp=" . $rev->getTimestamp() ) . ')';
556 if( $rev->isDeleted(Revision
::DELETED_TEXT
) ) {
557 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
558 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
559 if( !$rev->userCan(Revision
::DELETED_TEXT
) ) {
560 $revlink = '<span class="history-deleted">'.$date.'</span>';
561 $difflink = '(' . wfMsgHtml('diff') . ')';
565 return "<li> $difflink $revlink ".$this->skin
->revUserLink( $rev )." ".$this->skin
->revComment( $rev )."$del</li>";
572 private function fileLine( $file ) {
573 global $wgContLang, $wgTitle;
575 $target = $this->page
->getPrefixedText();
576 $date = $wgContLang->timeanddate( $file->getTimestamp(), true );
580 if( $file->isDeleted(File
::DELETED_FILE
) ) {
581 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
582 if( !$file->userCan(File
::DELETED_FILE
) ) {
585 $pageLink = $this->skin
->makeKnownLinkObj( $wgTitle, $date,
586 "target=$target&file=$file->sha1.".$file->getExtension() );
588 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
591 $url = $file->getUrlRel();
592 $pageLink = "<a href=\"{$url}\">{$date}</a>";
595 $data = wfMsgHtml( 'widthheight',
596 $wgContLang->formatNum( $file->getWidth() ),
597 $wgContLang->formatNum( $file->getHeight() ) ) .
598 ' (' . wfMsgHtml( 'nbytes', $wgContLang->formatNum( $file->getSize() ) ) . ')';
600 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
604 * @param ArchivedFile $file
607 private function archivedfileLine( $file ) {
608 global $wgContLang, $wgTitle;
610 $target = $this->page
->getPrefixedText();
611 $date = $wgContLang->timeanddate( $file->getTimestamp(), true );
613 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
614 $pageLink = $this->skin
->makeKnownLinkObj( $undelete, $date, "target=$target&file={$file->getKey()}" );
617 if( $file->isDeleted(File
::DELETED_FILE
) ) {
618 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
621 $data = wfMsgHtml( 'widthheight',
622 $wgContLang->formatNum( $file->getWidth() ),
623 $wgContLang->formatNum( $file->getHeight() ) ) .
624 ' (' . wfMsgHtml( 'nbytes', $wgContLang->formatNum( $file->getSize() ) ) . ')';
626 return "<li> $pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
630 * @param Array $row row
633 private function logLine( $row ) {
636 $date = $wgContLang->timeanddate( $row->log_timestamp
);
637 $paramArray = LogPage
::extractParams( $row->log_params
);
638 $title = Title
::makeTitle( $row->log_namespace
, $row->log_title
);
640 $logtitle = SpecialPage
::getTitleFor( 'Log' );
641 $loglink = $this->skin
->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
642 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
644 if( !LogEventsList
::userCan($row,LogPage
::DELETED_ACTION
) ) {
645 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
647 $action = LogPage
::actionText( $row->log_type
, $row->log_action
, $title,
648 $this->skin
, $paramArray, true, true );
649 if( $row->log_deleted
& LogPage
::DELETED_ACTION
)
650 $action = '<span class="history-deleted">' . $action . '</span>';
653 $userLink = $this->skin
->userLink( $row->log_user
, User
::WhoIs($row->log_user
) );
654 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_USER
) ) {
655 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
658 $comment = $wgContLang->getDirMark() . $this->skin
->commentBlock( $row->log_comment
);
659 if( LogEventsList
::isDeleted($row,LogPage
::DELETED_COMMENT
) ) {
660 $comment = '<span class="history-deleted">' . $comment . '</span>';
662 return "<li>($loglink) $date $userLink $action $comment</li>";
666 * Generate a user tool link cluster if the current user is allowed to view it
667 * @param ArchivedFile $file
668 * @return string HTML
670 private function fileUserTools( $file ) {
671 if( $file->userCan( Revision
::DELETED_USER
) ) {
672 $link = $this->skin
->userLink( $file->user
, $file->user_text
) .
673 $this->skin
->userToolLinks( $file->user
, $file->user_text
);
675 $link = wfMsgHtml( 'rev-deleted-user' );
677 if( $file->isDeleted( Revision
::DELETED_USER
) ) {
678 return '<span class="history-deleted">' . $link . '</span>';
684 * Wrap and format the given file's comment block, if the current
685 * user is allowed to view it.
687 * @param ArchivedFile $file
688 * @return string HTML
690 private function fileComment( $file ) {
691 if( $file->userCan( File
::DELETED_COMMENT
) ) {
692 $block = $this->skin
->commentBlock( $file->description
);
694 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
696 if( $file->isDeleted( File
::DELETED_COMMENT
) ) {
697 return "<span class=\"history-deleted\">$block</span>";
703 * @param WebRequest $request
705 function submit( $request ) {
706 global $wgUser, $wgOut;
708 $bitfield = $this->extractBitfield( $request );
709 $comment = $request->getText( 'wpReason' );
710 # Can the user set this field?
711 if( $bitfield & Revision
::DELETED_RESTRICTED
&& !$wgUser->isAllowed('hiderevision') ) {
712 $wgOut->permissionRequired( 'hiderevision' );
715 # If the save went through, go to success message. Otherwise
716 # bounce back to form...
717 if( $this->save( $bitfield, $comment, $this->page
) ) {
719 } else if( $request->getCheck( 'oldid' ) ||
$request->getCheck( 'artimestamp' ) ) {
720 return $this->showRevs();
721 } else if( $request->getCheck( 'logid' ) ) {
722 return $this->showLogs();
723 } else if( $request->getCheck( 'oldimage' ) ||
$request->getCheck( 'fileid' ) ) {
724 return $this->showImages();
728 private function success() {
731 $wgOut->setPagetitle( wfMsgHtml( 'actioncomplete' ) );
733 if( $this->deleteKey
=='logid' ) {
734 $wgOut->addWikiText( Xml
::element( 'span', array( 'class' => 'success' ), wfMsg( 'logdelete-success' ) ), false );
735 $this->showLogItems();
736 } else if( $this->deleteKey
=='oldid' ||
$this->deleteKey
=='artimestamp' ) {
737 $wgOut->addWikiText( Xml
::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
739 } else if( $this->deleteKey
=='fileid' ) {
740 $wgOut->addWikiText( Xml
::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
742 } else if( $this->deleteKey
=='oldimage' ) {
743 $wgOut->addWikiText( Xml
::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
749 * Put together a rev_deleted bitfield from the submitted checkboxes
750 * @param WebRequest $request
753 private function extractBitfield( $request ) {
755 foreach( $this->checks
as $item ) {
756 list( /* message */ , $name, $field ) = $item;
757 if( $request->getCheck( $name ) ) {
764 private function save( $bitfield, $reason, $title ) {
765 $dbw = wfGetDB( DB_MASTER
);
766 // Don't allow simply locking the interface for no reason
767 if( $bitfield == Revision
::DELETED_RESTRICTED
) {
770 $deleter = new RevisionDeleter( $dbw );
771 // By this point, only one of the below should be set
772 if( isset($this->revisions
) ) {
773 return $deleter->setRevVisibility( $title, $this->revisions
, $bitfield, $reason );
774 } else if( isset($this->archrevs
) ) {
775 return $deleter->setArchiveVisibility( $title, $this->archrevs
, $bitfield, $reason );
776 } else if( isset($this->ofiles
) ) {
777 return $deleter->setOldImgVisibility( $title, $this->ofiles
, $bitfield, $reason );
778 } else if( isset($this->afiles
) ) {
779 return $deleter->setArchFileVisibility( $title, $this->afiles
, $bitfield, $reason );
780 } else if( isset($this->events
) ) {
781 return $deleter->setEventVisibility( $title, $this->events
, $bitfield, $reason );
787 * Implements the actions for Revision Deletion.
788 * @ingroup SpecialPage
790 class RevisionDeleter
{
791 function __construct( $db ) {
796 * @param $title, the page these events apply to
797 * @param array $items list of revision ID numbers
798 * @param int $bitfield new rev_deleted value
799 * @param string $comment Comment for log records
801 function setRevVisibility( $title, $items, $bitfield, $comment ) {
804 $userAllowedAll = $success = true;
807 // Run through and pull all our data in one query
808 foreach( $items as $revid ) {
809 $where[] = intval($revid);
811 $whereClause = 'rev_id IN(' . implode(',',$where) . ')';
812 $result = $this->dbw
->select( 'revision', '*',
813 array( 'rev_page' => $title->getArticleID(),
816 while( $row = $this->dbw
->fetchObject( $result ) ) {
817 $revObjs[$row->rev_id
] = new Revision( $row );
820 foreach( $items as $revid ) {
821 if( !isset($revObjs[$revid]) ||
$revObjs[$revid]->isCurrent() ) {
823 continue; // Must exist
824 } else if( !$revObjs[$revid]->userCan(Revision
::DELETED_RESTRICTED
) ) {
825 $userAllowedAll=false;
828 // For logging, maintain a count of revisions
829 if( $revObjs[$revid]->mDeleted
!= $bitfield ) {
833 $this->updateRevision( $revObjs[$revid], $bitfield );
834 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
838 // Don't log or touch if nothing changed
839 if( $revCount > 0 ) {
840 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted
,
841 $comment, $title, 'oldid', $revIDs );
842 $this->updatePage( $title );
844 // Where all revs allowed to be set?
845 if( !$userAllowedAll ) {
846 //FIXME: still might be confusing???
847 $wgOut->permissionRequired( 'hiderevision' );
855 * @param $title, the page these events apply to
856 * @param array $items list of revision ID numbers
857 * @param int $bitfield new rev_deleted value
858 * @param string $comment Comment for log records
860 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
863 $userAllowedAll = $success = true;
866 // Run through and pull all our data in one query
867 foreach( $items as $timestamp ) {
868 $where[] = $this->dbw
->addQuotes( $timestamp );
870 $whereClause = 'ar_timestamp IN(' . implode(',',$where) . ')';
871 $result = $this->dbw
->select( 'archive', '*',
872 array( 'ar_namespace' => $title->getNamespace(),
873 'ar_title' => $title->getDBKey(),
876 while( $row = $this->dbw
->fetchObject( $result ) ) {
877 $revObjs[$row->ar_timestamp
] = new Revision( array(
878 'page' => $title->getArticleId(),
879 'id' => $row->ar_rev_id
,
880 'text' => $row->ar_text_id
,
881 'comment' => $row->ar_comment
,
882 'user' => $row->ar_user
,
883 'user_text' => $row->ar_user_text
,
884 'timestamp' => $row->ar_timestamp
,
885 'minor_edit' => $row->ar_minor_edit
,
886 'text_id' => $row->ar_text_id
,
887 'deleted' => $row->ar_deleted
,
888 'len' => $row->ar_len
) );
891 foreach( $items as $timestamp ) {
892 // This will only select the first revision with this timestamp.
893 // Since they are all selected/deleted at once, we can just check the
894 // permissions of one. UPDATE is done via timestamp, so all revs are set.
895 if( !is_object($revObjs[$timestamp]) ) {
897 continue; // Must exist
898 } else if( !$revObjs[$timestamp]->userCan(Revision
::DELETED_RESTRICTED
) ) {
899 $userAllowedAll=false;
902 // Which revisions did we change anything about?
903 if( $revObjs[$timestamp]->mDeleted
!= $bitfield ) {
904 $Id_set[]=$timestamp;
907 $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
910 // For logging, maintain a count of revisions
912 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted
,
913 $comment, $title, 'artimestamp', $Id_set );
915 // Where all revs allowed to be set?
916 if( !$userAllowedAll ) {
917 $wgOut->permissionRequired( 'hiderevision' );
925 * @param $title, the page these events apply to
926 * @param array $items list of revision ID numbers
927 * @param int $bitfield new rev_deleted value
928 * @param string $comment Comment for log records
930 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
933 $userAllowedAll = $success = true;
936 // Run through and pull all our data in one query
937 foreach( $items as $timestamp ) {
938 $where[] = $this->dbw
->addQuotes( $timestamp.'!'.$title->getDbKey() );
940 $whereClause = 'oi_archive_name IN(' . implode(',',$where) . ')';
941 $result = $this->dbw
->select( 'oldimage', '*',
942 array( 'oi_name' => $title->getDbKey(),
945 while( $row = $this->dbw
->fetchObject( $result ) ) {
946 $filesObjs[$row->oi_archive_name
] = RepoGroup
::singleton()->getLocalRepo()->newFileFromRow( $row );
947 $filesObjs[$row->oi_archive_name
]->user
= $row->oi_user
;
948 $filesObjs[$row->oi_archive_name
]->user_text
= $row->oi_user_text
;
951 foreach( $items as $timestamp ) {
952 $archivename = $timestamp.'!'.$title->getDbKey();
953 if( !isset($filesObjs[$archivename]) ) {
955 continue; // Must exist
956 } else if( !$filesObjs[$archivename]->userCan(File
::DELETED_RESTRICTED
) ) {
957 $userAllowedAll=false;
962 // Which revisions did we change anything about?
963 if( $filesObjs[$archivename]->deleted
!= $bitfield ) {
967 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
968 // If this image is currently hidden...
969 if( $filesObjs[$archivename]->deleted
& File
::DELETED_FILE
) {
970 if( $bitfield & File
::DELETED_FILE
) {
971 # Leave it alone if we are not changing this...
975 # We are moving this out
976 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
979 // Is it just now becoming hidden?
980 } else if( $bitfield & File
::DELETED_FILE
) {
981 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
986 // If our file operations fail, then revert back the db
987 if( $transaction==false ) {
988 $this->dbw
->rollback();
991 $this->dbw
->commit();
995 // Log if something was changed
997 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted
,
998 $comment, $title, 'oldimage', $set );
1000 $file = wfLocalFile( $title );
1001 $file->purgeCache();
1002 $file->purgeHistory();
1003 # Invalidate cache for all pages using this file
1004 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
1005 $update->doUpdate();
1007 // Where all revs allowed to be set?
1008 if( !$userAllowedAll ) {
1009 $wgOut->permissionRequired( 'hiderevision' );
1017 * @param $title, the page these events apply to
1018 * @param array $items list of revision ID numbers
1019 * @param int $bitfield new rev_deleted value
1020 * @param string $comment Comment for log records
1022 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
1025 $userAllowedAll = $success = true;
1029 // Run through and pull all our data in one query
1030 foreach( $items as $id ) {
1031 $where[] = intval($id);
1033 $whereClause = 'fa_id IN(' . implode(',',$where) . ')';
1034 $result = $this->dbw
->select( 'filearchive', '*',
1035 array( 'fa_name' => $title->getDbKey(),
1038 while( $row = $this->dbw
->fetchObject( $result ) ) {
1039 $filesObjs[$row->fa_id
] = ArchivedFile
::newFromRow( $row );
1042 foreach( $items as $fileid ) {
1043 if( !isset($filesObjs[$fileid]) ) {
1045 continue; // Must exist
1046 } else if( !$filesObjs[$fileid]->userCan(File
::DELETED_RESTRICTED
) ) {
1047 $userAllowedAll=false;
1050 // Which revisions did we change anything about?
1051 if( $filesObjs[$fileid]->deleted
!= $bitfield ) {
1055 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1058 // Log if something was changed
1060 $this->updateLog( $title, $count, $bitfield, $comment,
1061 $filesObjs[$fileid]->deleted
, $title, 'fileid', $Id_set );
1063 // Where all revs allowed to be set?
1064 if( !$userAllowedAll ) {
1065 $wgOut->permissionRequired( 'hiderevision' );
1073 * @param $title, the log page these events apply to
1074 * @param array $items list of log ID numbers
1075 * @param int $bitfield new log_deleted value
1076 * @param string $comment Comment for log records
1078 function setEventVisibility( $title, $items, $bitfield, $comment ) {
1081 $userAllowedAll = $success = true;
1085 // Run through and pull all our data in one query
1086 foreach( $items as $logid ) {
1087 $where[] = intval($logid);
1089 list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
1090 $whereClause = "log_type ='$logtype' AND log_id IN(" . implode(',',$where) . ")";
1091 $result = $this->dbw
->select( 'logging', '*',
1092 array( $whereClause ),
1094 while( $row = $this->dbw
->fetchObject( $result ) ) {
1095 $logRows[$row->log_id
] = $row;
1098 foreach( $items as $logid ) {
1099 if( !isset($logRows[$logid]) ) {
1101 continue; // Must exist
1102 } else if( !LogEventsList
::userCan($logRows[$logid], LogPage
::DELETED_RESTRICTED
)
1103 ||
$logRows[$logid]->log_type
== 'suppress' ) {
1104 // Don't hide from oversight log!!!
1105 $userAllowedAll=false;
1108 // Which logs did we change anything about?
1109 if( $logRows[$logid]->log_deleted
!= $bitfield ) {
1113 $this->updateLogs( $logRows[$logid], $bitfield );
1114 $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
1117 // Don't log or touch if nothing changed
1119 $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted
,
1120 $comment, $title, 'logid', $log_Ids );
1122 // Were all revs allowed to be set?
1123 if( !$userAllowedAll ) {
1124 $wgOut->permissionRequired( 'hiderevision' );
1132 * Moves an image to a safe private location
1133 * Caller is responsible for clearing caches
1134 * @param File $oimage
1135 * @returns mixed, timestamp string on success, false on failure
1137 function makeOldImagePrivate( $oimage ) {
1138 $transaction = new FSTransaction();
1139 if( !FileStore
::lock() ) {
1140 wfDebug( __METHOD__
.": failed to acquire file store lock, aborting\n" );
1143 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1144 // Dupe the file into the file store
1145 if( file_exists( $oldpath ) ) {
1146 // Is our directory configured?
1147 if( $store = FileStore
::get( 'deleted' ) ) {
1148 if( !$oimage->sha1
) {
1149 $oimage->upgradeRow(); // sha1 may be missing
1151 $key = $oimage->sha1
. '.' . $oimage->getExtension();
1152 $transaction->add( $store->insert( $key, $oldpath, FileStore
::DELETE_ORIGINAL
) );
1156 $transaction = false; // Return an error and do nothing
1159 wfDebug( __METHOD__
." deleting already-missing '$oldpath'; moving on to database\n" );
1162 $transaction = new FSTransaction(); // empty
1165 if( $transaction === false ) {
1167 wfDebug( __METHOD__
.": import to file store failed, aborting\n" );
1168 throw new MWException( "Could not archive and delete file $oldpath" );
1172 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1173 $transaction->commit();
1174 FileStore
::unlock();
1176 $m = explode('!',$oimage->archive_name
,2);
1183 * Moves an image from a safe private location
1184 * Caller is responsible for clearing caches
1185 * @param File $oimage
1186 * @returns mixed, string timestamp on success, false on failure
1188 function makeOldImagePublic( $oimage ) {
1189 $transaction = new FSTransaction();
1190 if( !FileStore
::lock() ) {
1191 wfDebug( __METHOD__
." could not acquire filestore lock\n" );
1195 $store = FileStore
::get( 'deleted' );
1197 wfDebug( __METHOD__
.": skipping row with no file.\n" );
1201 $key = $oimage->sha1
.'.'.$oimage->getExtension();
1202 $destDir = $oimage->getArchivePath();
1203 if( !is_dir( $destDir ) ) {
1204 wfMkdirParents( $destDir );
1206 $destPath = $destDir . DIRECTORY_SEPARATOR
. $oimage->archive_name
;
1207 // Check if any other stored revisions use this file;
1208 // if so, we shouldn't remove the file from the hidden
1209 // archives so they will still work. Check hidden files first.
1210 $useCount = $this->dbw
->selectField( 'oldimage', '1',
1211 array( 'oi_sha1' => $oimage->sha1
,
1212 'oi_deleted & '.File
::DELETED_FILE
=> File
::DELETED_FILE
),
1213 __METHOD__
, array( 'FOR UPDATE' ) );
1214 // Check the rest of the deleted archives too.
1215 // (these are the ones that don't show in the image history)
1217 $useCount = $this->dbw
->selectField( 'filearchive', '1',
1218 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1219 __METHOD__
, array( 'FOR UPDATE' ) );
1222 if( $useCount == 0 ) {
1223 wfDebug( __METHOD__
.": nothing else using {$oimage->sha1}, will deleting after\n" );
1224 $flags = FileStore
::DELETE_ORIGINAL
;
1228 $transaction->add( $store->export( $key, $destPath, $flags ) );
1230 wfDebug( __METHOD__
.": set db items, applying file transactions\n" );
1231 $transaction->commit();
1232 FileStore
::unlock();
1234 $m = explode('!',$oimage->archive_name
,2);
1241 * Update the revision's rev_deleted field
1242 * @param Revision $rev
1243 * @param int $bitfield new rev_deleted bitfield value
1245 function updateRevision( $rev, $bitfield ) {
1246 $this->dbw
->update( 'revision',
1247 array( 'rev_deleted' => $bitfield ),
1248 array( 'rev_id' => $rev->getId(),
1249 'rev_page' => $rev->getPage() ),
1254 * Update the revision's rev_deleted field
1255 * @param Revision $rev
1256 * @param Title $title
1257 * @param int $bitfield new rev_deleted bitfield value
1259 function updateArchive( $rev, $title, $bitfield ) {
1260 $this->dbw
->update( 'archive',
1261 array( 'ar_deleted' => $bitfield ),
1262 array( 'ar_namespace' => $title->getNamespace(),
1263 'ar_title' => $title->getDBKey(),
1264 'ar_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ),
1265 'ar_rev_id' => $rev->getId() ),
1270 * Update the images's oi_deleted field
1272 * @param int $bitfield new rev_deleted bitfield value
1274 function updateOldFiles( $file, $bitfield ) {
1275 $this->dbw
->update( 'oldimage',
1276 array( 'oi_deleted' => $bitfield ),
1277 array( 'oi_name' => $file->getName(),
1278 'oi_timestamp' => $this->dbw
->timestamp( $file->getTimestamp() ) ),
1283 * Update the images's fa_deleted field
1284 * @param ArchivedFile $file
1285 * @param int $bitfield new rev_deleted bitfield value
1287 function updateArchFiles( $file, $bitfield ) {
1288 $this->dbw
->update( 'filearchive',
1289 array( 'fa_deleted' => $bitfield ),
1290 array( 'fa_id' => $file->getId() ),
1295 * Update the logging log_deleted field
1297 * @param int $bitfield new rev_deleted bitfield value
1299 function updateLogs( $row, $bitfield ) {
1300 $this->dbw
->update( 'logging',
1301 array( 'log_deleted' => $bitfield ),
1302 array( 'log_id' => $row->log_id
),
1307 * Update the revision's recentchanges record if fields have been hidden
1308 * @param Revision $rev
1309 * @param int $bitfield new rev_deleted bitfield value
1311 function updateRecentChangesEdits( $rev, $bitfield ) {
1312 $this->dbw
->update( 'recentchanges',
1313 array( 'rc_deleted' => $bitfield,
1314 'rc_patrolled' => 1 ),
1315 array( 'rc_this_oldid' => $rev->getId(),
1316 'rc_timestamp' => $this->dbw
->timestamp( $rev->getTimestamp() ) ),
1321 * Update the revision's recentchanges record if fields have been hidden
1323 * @param int $bitfield new rev_deleted bitfield value
1325 function updateRecentChangesLog( $row, $bitfield ) {
1326 $this->dbw
->update( 'recentchanges',
1327 array( 'rc_deleted' => $bitfield,
1328 'rc_patrolled' => 1 ),
1329 array( 'rc_logid' => $row->log_id
,
1330 'rc_timestamp' => $row->log_timestamp
),
1335 * Touch the page's cache invalidation timestamp; this forces cached
1336 * history views to refresh, so any newly hidden or shown fields will
1338 * @param Title $title
1340 function updatePage( $title ) {
1341 $title->invalidateCache();
1342 $title->purgeSquid();
1344 // Extensions that require referencing previous revisions may need this
1345 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1349 * Checks for a change in the bitfield for a certain option and updates the
1350 * provided array accordingly.
1352 * @param String $desc Description to add to the array if the option was
1353 * enabled / disabled.
1354 * @param int $field The bitmask describing the single option.
1355 * @param int $diff The xor of the old and new bitfields.
1356 * @param array $arr The array to update.
1358 function checkItem ( $desc, $field, $diff, $new, &$arr ) {
1359 if ( $diff & $field ) {
1360 $arr [ ( $new & $field ) ?
0 : 1 ][] = $desc;
1365 * Gets an array describing the changes made to the visibilit of the revision.
1366 * If the resulting array is $arr, then $arr[0] will contain an array of strings
1367 * describing the items that were hidden, $arr[2] will contain an array of strings
1368 * describing the items that were unhidden, and $arr[3] will contain an array with
1369 * a single string, which can be one of "applied restrictions to sysops",
1370 * "removed restrictions from sysops", or null.
1372 * @param int $n The new bitfield.
1373 * @param int $o The old bitfield.
1374 * @return An array as described above.
1376 function getChanges ( $n, $o ) {
1378 $ret = array ( 0 => array(), 1 => array(), 2 => array() );
1380 $this->checkItem ( wfMsgForContent ( 'revdelete-content' ),
1381 Revision
::DELETED_TEXT
, $diff, $n, $ret );
1382 $this->checkItem ( wfMsgForContent ( 'revdelete-summary' ),
1383 Revision
::DELETED_COMMENT
, $diff, $n, $ret );
1384 $this->checkItem ( wfMsgForContent ( 'revdelete-uname' ),
1385 Revision
::DELETED_USER
, $diff, $n, $ret );
1387 // Restriction application to sysops
1388 if ( $diff & Revision
::DELETED_RESTRICTED
) {
1389 if ( $n & Revision
::DELETED_RESTRICTED
)
1390 $ret[2][] = wfMsgForContent ( 'revdelete-restricted' );
1392 $ret[2][] = wfMsgForContent ( 'revdelete-unrestricted' );
1399 * Gets a log message to describe the given revision visibility change. This
1400 * message will be of the form "[hid {content, edit summary, username}];
1401 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
1403 * @param int $count The number of effected revisions.
1404 * @param int $nbitfield The new bitfield for the revision.
1405 * @param int $obitfield The old bitfield for the revision.
1406 * @param string $comment The comment associated with the change.
1407 * @param bool $isForLog
1409 function getLogMessage ( $count, $nbitfield, $obitfield, $comment, $isForLog = false ) {
1413 $changes = $this->getChanges( $nbitfield, $obitfield );
1415 if ( count ( $changes[0] ) ) {
1416 $s .= wfMsgForContent ( 'revdelete-hid', implode ( ', ', $changes[0] ) );
1419 if ( count ( $changes[1] ) ) {
1422 $s .= wfMsgForContent ( 'revdelete-unhid', implode ( ', ', $changes[1] ) );
1425 if ( count ( $changes[2] )) {
1427 $s .= ' (' . $changes[2][0] . ')';
1429 $s = $changes[2][0];
1432 $msg = $isForLog ?
'logdelete-log-message' : 'revdelete-log-message';
1433 $ret = wfMsgExt ( $msg, array( 'parsemag', 'content' ),
1434 $s, $wgContLang->formatNum( $count ) );
1437 $ret .= ": $comment";
1444 * Record a log entry on the action
1445 * @param Title $title, page where item was removed from
1446 * @param int $count the number of revisions altered for this page
1447 * @param int $nbitfield the new _deleted value
1448 * @param int $obitfield the old _deleted value
1449 * @param string $comment
1450 * @param Title $target, the relevant page
1451 * @param string $param, URL param
1452 * @param Array $items
1454 function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target, $param, $items = array() ) {
1455 // Put things hidden from sysops in the oversight log
1456 $logtype = ( ($nbitfield |
$obitfield) & Revision
::DELETED_RESTRICTED
) ?
'suppress' : 'delete';
1457 $log = new LogPage( $logtype );
1459 $reason = $this->getLogMessage ( $count, $nbitfield, $obitfield, $comment, $param == 'logid' );
1461 if( $param == 'logid' ) {
1462 $params = array( implode( ',', $items) );
1463 $log->addEntry( 'event', $title, $reason, $params );
1465 // Add params for effected page and ids
1466 $params = array( $param, implode( ',', $items) );
1467 $log->addEntry( 'revision', $title, $reason, $params );