(bug 12698) Create PAGESIZE parser function, to return the size of a page. Quite...
[mediawiki.git] / includes / SpecialRevisiondelete.php
blob49538080e44567e87d95cddde7634e30ef8ab142
1 <?php
3 /**
4 * Special page allowing users with the appropriate permissions to view
5 * and hide revisions. Log items can also be hidden.
7 * @addtogroup SpecialPage
8 */
10 function wfSpecialRevisiondelete( $par = null ) {
11 global $wgOut, $wgRequest, $wgUser;
12 # Handle our many different possible input types
13 $target = $wgRequest->getText( 'target' );
14 $oldid = $wgRequest->getArray( 'oldid' );
15 $artimestamp = $wgRequest->getArray( 'artimestamp' );
16 $logid = $wgRequest->getArray( 'logid' );
17 $img = $wgRequest->getArray( 'oldimage' );
18 $fileid = $wgRequest->getArray( 'fileid' );
19 # For reviewing deleted files...
20 $file = $wgRequest->getVal( 'file' );
21 # If this is a revision, then we need a target page
22 $page = Title::newFromUrl( $target );
23 if( is_null($page) ) {
24 $wgOut->addWikiText( wfMsgHtml( 'undelete-header' ) );
25 return;
27 # Only one target set at a time please!
28 $i = (bool)$file + (bool)$oldid + (bool)$logid + (bool)$artimestamp + (bool)$fileid + (bool)$img;
29 if( $i !== 1 ) {
30 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
31 return;
33 # Logs must have a type given
34 if( $logid && !strpos($page->getDBKey(),'/') ) {
35 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
36 return;
38 # Either submit or create our form
39 $form = new RevisionDeleteForm( $page, $oldid, $logid, $artimestamp, $fileid, $img, $file );
40 if( $wgRequest->wasPosted() ) {
41 $form->submit( $wgRequest );
42 } else if( $oldid || $artimestamp ) {
43 $form->showRevs( $wgRequest );
44 } else if( $fileid || $img ) {
45 $form->showImages( $wgRequest );
46 } else if( $logid ) {
47 $form->showLogItems( $wgRequest );
49 # Show relevant lines from the deletion log. This will show even if said ID
50 # does not exist...might be helpful
51 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
52 LogEventsList::showLogExtract( $wgOut, 'delete', $page->getPrefixedText() );
53 if( $wgUser->isAllowed( 'suppress' ) ){
54 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'suppress' ) ) . "</h2>\n" );
55 LogEventsList::showLogExtract( $wgOut, 'suppress', $page->getPrefixedText() );
59 /**
60 * Implements the GUI for Revision Deletion.
61 * @addtogroup SpecialPage
63 class RevisionDeleteForm {
64 /**
65 * @param Title $page
66 * @param array $oldids
67 * @param array $logids
68 * @param array $artimestamps
69 * @param array $fileids
70 * @param array $img
71 * @param string $file
73 function __construct( $page, $oldids, $logids, $artimestamps, $fileids, $img, $file ) {
74 global $wgUser, $wgOut;
76 $this->page = $page;
77 # For reviewing deleted files...
78 if( $file ) {
79 $oimage = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $page, $file );
80 $oimage->load();
81 // Check if user is allowed to see this file
82 if( !$oimage->userCan(File::DELETED_FILE) ) {
83 $wgOut->permissionRequired( 'hiderevision' );
84 } else {
85 $this->showFile( $file );
87 return;
89 $this->skin = $wgUser->getSkin();
90 # Give a link to the log for this page
91 if( !is_null($this->page) && $this->page->getNamespace() > -1 ) {
92 $links = array();
94 $logtitle = SpecialPage::getTitleFor( 'Log' );
95 $links[] = $this->skin->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
96 wfArrayToCGI( array( 'page' => $this->page->getPrefixedUrl() ) ) );
97 # Give a link to the page history
98 $links[] = $this->skin->makeKnownLinkObj( $this->page, wfMsgHtml( 'pagehist' ),
99 wfArrayToCGI( array( 'action' => 'history' ) ) );
100 # Link to deleted edits
101 if( $wgUser->isAllowed('undelete') ) {
102 $undelete = SpecialPage::getTitleFor( 'Undelete' );
103 $links[] = $this->skin->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
104 wfArrayToCGI( array( 'target' => $this->page->getPrefixedUrl() ) ) );
106 # Logs themselves don't have histories or archived revisions
107 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
109 // At this point, we should only have one of these
110 if( $oldids ) {
111 $this->revisions = $oldids;
112 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision::DELETED_TEXT );
113 $this->deleteKey='oldid';
114 } else if( $artimestamps ) {
115 $this->archrevs = $artimestamps;
116 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision::DELETED_TEXT );
117 $this->deleteKey='artimestamp';
118 } else if( $img ) {
119 $this->ofiles = $img;
120 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File::DELETED_FILE );
121 $this->deleteKey='oldimage';
122 } else if( $fileids ) {
123 $this->afiles = $fileids;
124 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File::DELETED_FILE );
125 $this->deleteKey='fileid';
126 } else if( $logids ) {
127 $this->events = $logids;
128 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage::DELETED_ACTION );
129 $this->deleteKey='logid';
131 // Our checkbox messages depends one what we are doing,
132 // e.g. we don't hide "text" for logs or images
133 $this->checks = array(
134 $hide_content_name,
135 array( 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ),
136 array( 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER ),
137 array( 'revdelete-hide-restricted', 'wpHideRestricted', Revision::DELETED_RESTRICTED ) );
141 * Show a deleted file version requested by the visitor.
143 private function showFile( $key ) {
144 global $wgOut, $wgRequest;
145 $wgOut->disable();
147 # We mustn't allow the output to be Squid cached, otherwise
148 # if an admin previews a deleted image, and it's cached, then
149 # a user without appropriate permissions can toddle off and
150 # nab the image, and Squid will serve it
151 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
152 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
153 $wgRequest->response()->header( 'Pragma: no-cache' );
155 $store = FileStore::get( 'deleted' );
156 $store->stream( $key );
160 * This lets a user set restrictions for live and archived revisions
161 * @param WebRequest $request
163 function showRevs( $request ) {
164 global $wgOut, $wgUser, $action;
166 $UserAllowed = true;
168 $count = ($this->deleteKey=='oldid') ?
169 count($this->revisions) : count($this->archrevs);
170 $wgOut->addWikiMsg( 'revdelete-selected', $this->page->getPrefixedText(), $count );
172 $bitfields = 0;
173 $wgOut->addHtml( "<ul>" );
175 $where = $revObjs = array();
176 $dbr = wfGetDB( DB_SLAVE );
177 // Live revisions...
178 if( $this->deleteKey=='oldid' ) {
179 // Run through and pull all our data in one query
180 foreach( $this->revisions as $revid ) {
181 $where[] = intval($revid);
183 $whereClause = 'rev_id IN(' . implode(',',$where) . ')';
184 $result = $dbr->select( array('revision','page'), '*',
185 array( 'rev_page' => $this->page->getArticleID(),
186 $whereClause, 'rev_page = page_id' ),
187 __METHOD__ );
188 while( $row = $dbr->fetchObject( $result ) ) {
189 $revObjs[$row->rev_id] = new Revision( $row );
191 foreach( $this->revisions as $revid ) {
192 // Hiding top revisison is bad
193 if( !is_object($revObjs[$revid]) || $revObjs[$revid]->isCurrent() ) {
194 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
195 return;
196 } else if( !$revObjs[$revid]->userCan(Revision::DELETED_RESTRICTED) ) {
197 // If a rev is hidden from sysops
198 if( $action != 'submit') {
199 $wgOut->permissionRequired( 'hiderevision' );
200 return;
202 $UserAllowed = false;
204 $wgOut->addHtml( $this->historyLine( $revObjs[$revid] ) );
205 $bitfields |= $revObjs[$revid]->mDeleted;
207 // The archives...
208 } else {
209 // Run through and pull all our data in one query
210 foreach( $this->archrevs as $timestamp ) {
211 $where[] = $dbr->addQuotes( $timestamp );
213 $whereClause = 'ar_timestamp IN(' . implode(',',$where) . ')';
214 $result = $dbr->select( 'archive', '*',
215 array( 'ar_namespace' => $this->page->getNamespace(),
216 'ar_title' => $this->page->getDBKey(),
217 $whereClause ),
218 __METHOD__ );
219 while( $row = $dbr->fetchObject( $result ) ) {
220 $revObjs[$row->ar_timestamp] = new Revision( array(
221 'page' => $this->page->getArticleId(),
222 'id' => $row->ar_rev_id,
223 'text' => $row->ar_text_id,
224 'comment' => $row->ar_comment,
225 'user' => $row->ar_user,
226 'user_text' => $row->ar_user_text,
227 'timestamp' => $row->ar_timestamp,
228 'minor_edit' => $row->ar_minor_edit,
229 'text_id' => $row->ar_text_id,
230 'deleted' => $row->ar_deleted,
231 'len' => $row->ar_len) );
233 foreach( $this->archrevs as $timestamp ) {
234 if( !is_object($revObjs[$timestamp]) ) {
235 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
236 return;
239 foreach( $revObjs as $rev ) {
240 if( !$rev->userCan(Revision::DELETED_RESTRICTED) ) {
241 // If a rev is hidden from sysops
242 if( $action != 'submit') {
243 $wgOut->permissionRequired( 'hiderevision' );
244 return;
246 $UserAllowed = false;
248 $wgOut->addHtml( $this->historyLine( $rev ) );
249 $bitfields |= $rev->mDeleted;
252 $wgOut->addHtml( "</ul>" );
254 $wgOut->addWikiText( wfMsgHtml( 'revdelete-text' ) );
256 // Normal sysops can always see what they did, but can't always change it
257 if( !$UserAllowed ) return;
259 $items = array(
260 Xml::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
261 Xml::submitButton( wfMsg( 'revdelete-submit' ) )
263 $hidden = array(
264 Xml::hidden( 'wpEditToken', $wgUser->editToken() ),
265 Xml::hidden( 'target', $this->page->getPrefixedText() ),
266 Xml::hidden( 'type', $this->deleteKey )
268 if( $this->deleteKey=='oldid' ) {
269 foreach( $revObjs as $rev )
270 $hidden[] = wfHidden( 'oldid[]', $rev->getID() );
271 } else {
272 foreach( $revObjs as $rev )
273 $hidden[] = wfHidden( 'artimestamp[]', $rev->getTimestamp() );
275 $special = SpecialPage::getTitleFor( 'Revisiondelete' );
276 $wgOut->addHtml(
277 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
278 'id' => 'mw-revdel-form-revisions' ) ) .
279 Xml::openElement( 'fieldset' ) .
280 xml::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
282 // FIXME: all items checked for just one rev are checked, even if not set for the others
283 foreach( $this->checks as $item ) {
284 list( $message, $name, $field ) = $item;
285 $wgOut->addHtml( Xml::tags( 'div', null, Xml::checkLabel( wfMsg( $message ), $name, $name, $bitfields & $field ) ) );
287 foreach( $items as $item ) {
288 $wgOut->addHtml( Xml::tags( 'p', null, $item ) );
290 foreach( $hidden as $item ) {
291 $wgOut->addHtml( $item );
293 $wgOut->addHtml(
294 Xml::closeElement( 'fieldset' ) .
295 Xml::closeElement( 'form' ) . "\n"
301 * This lets a user set restrictions for archived images
302 * @param WebRequest $request
304 function showImages( $request ) {
305 global $wgOut, $wgUser, $action;
307 $UserAllowed = true;
309 $count = ($this->deleteKey=='oldimage') ? count($this->ofiles) : count($this->afiles);
310 $wgOut->addWikiText( wfMsgExt( 'revdelete-selected', array('parsemag'),
311 $this->page->getPrefixedText(), $count ) );
313 $bitfields = 0;
314 $wgOut->addHtml( "<ul>" );
316 $where = $filesObjs = array();
317 $dbr = wfGetDB( DB_SLAVE );
318 // Live old revisions...
319 if( $this->deleteKey=='oldimage' ) {
320 // Run through and pull all our data in one query
321 foreach( $this->ofiles as $timestamp ) {
322 $where[] = $dbr->addQuotes( $timestamp.'!'.$this->page->getDbKey() );
324 $whereClause = 'oi_archive_name IN(' . implode(',',$where) . ')';
325 $result = $dbr->select( 'oldimage', '*',
326 array( 'oi_name' => $this->page->getDbKey(),
327 $whereClause ),
328 __METHOD__ );
329 while( $row = $dbr->fetchObject( $result ) ) {
330 $filesObjs[$row->oi_archive_name] = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
331 $filesObjs[$row->oi_archive_name]->user = $row->oi_user;
332 $filesObjs[$row->oi_archive_name]->user_text = $row->oi_user_text;
334 // Check through our images
335 foreach( $this->ofiles as $timestamp ) {
336 $archivename = $timestamp.'!'.$this->page->getDbKey();
337 if( !isset($filesObjs[$archivename]) ) {
338 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
339 return;
342 foreach( $filesObjs as $file ) {
343 if( !isset($file) ) {
344 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
345 return;
346 } else if( !$file->userCan(File::DELETED_RESTRICTED) ) {
347 // If a rev is hidden from sysops
348 if( $action != 'submit' ) {
349 $wgOut->permissionRequired( 'hiderevision' );
350 return;
352 $UserAllowed = false;
354 // Inject history info
355 $wgOut->addHtml( $this->fileLine( $file ) );
356 $bitfields |= $file->deleted;
358 // Archived files...
359 } else {
360 // Run through and pull all our data in one query
361 foreach( $this->afiles as $id ) {
362 $where[] = intval($id);
364 $whereClause = 'fa_id IN(' . implode(',',$where) . ')';
365 $result = $dbr->select( 'filearchive', '*',
366 array( 'fa_name' => $this->page->getDbKey(),
367 $whereClause ),
368 __METHOD__ );
369 while( $row = $dbr->fetchObject( $result ) ) {
370 $filesObjs[$row->fa_id] = ArchivedFile::newFromRow( $row );
373 foreach( $this->afiles as $fileid ) {
374 if( !isset($filesObjs[$fileid]) ) {
375 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
376 return;
377 } else if( !$filesObjs[$fileid]->userCan(File::DELETED_RESTRICTED) ) {
378 // If a rev is hidden from sysops
379 if( $action != 'submit' ) {
380 $wgOut->permissionRequired( 'hiderevision' );
381 return;
383 $UserAllowed = false;
385 // Inject history info
386 $wgOut->addHtml( $this->archivedfileLine( $filesObjs[$fileid] ) );
387 $bitfields |= $filesObjs[$fileid]->deleted;
390 $wgOut->addHtml( "</ul>" );
392 $wgOut->addWikiText( wfMsgHtml( 'revdelete-text' ) );
393 //Normal sysops can always see what they did, but can't always change it
394 if( !$UserAllowed ) return;
396 $items = array(
397 Xml::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
398 Xml::submitButton( wfMsg( 'revdelete-submit' ) )
400 $hidden = array(
401 Xml::hidden( 'wpEditToken', $wgUser->editToken() ),
402 Xml::hidden( 'target', $this->page->getPrefixedText() ),
403 Xml::hidden( 'type', $this->deleteKey )
405 if( $this->deleteKey=='oldimage' ) {
406 foreach( $this->ofiles as $filename )
407 $hidden[] = wfHidden( 'oldimage[]', $filename );
408 } else {
409 foreach( $this->afiles as $fileid )
410 $hidden[] = wfHidden( 'fileid[]', $fileid );
412 $special = SpecialPage::getTitleFor( 'Revisiondelete' );
413 $wgOut->addHtml(
414 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
415 'id' => 'mw-revdel-form-filerevisions' ) ) .
416 Xml::openElement( 'fieldset' ) .
417 xml::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
419 // FIXME: all items checked for just one file are checked, even if not set for the others
420 foreach( $this->checks as $item ) {
421 list( $message, $name, $field ) = $item;
422 $wgOut->addHtml( Xml::tags( 'div', null, Xml::checkLabel( wfMsg( $message ), $name, $name, $bitfields & $field ) ) );
424 foreach( $items as $item ) {
425 $wgOut->addHtml( Xml::tags( 'p', null, $item ) );
427 foreach( $hidden as $item ) {
428 $wgOut->addHtml( $item );
431 $wgOut->addHtml(
432 Xml::closeElement( 'fieldset' ) .
433 Xml::closeElement( 'form' ) . "\n"
438 * This lets a user set restrictions for log items
439 * @param WebRequest $request
441 function showLogItems( $request ) {
442 global $wgOut, $wgUser, $action, $wgMessageCache;
444 $UserAllowed = true;
445 $wgOut->addWikiText( wfMsgExt( 'logdelete-selected', array('parsemag'), count($this->events) ) );
447 $bitfields = 0;
448 $wgOut->addHtml( "<ul>" );
450 $where = $logRows = array();
451 $dbr = wfGetDB( DB_SLAVE );
452 // Run through and pull all our data in one query
453 foreach( $this->events as $logid ) {
454 $where[] = intval($logid);
456 list($log,$logtype) = explode( '/',$this->page->getDBKey(), 2 );
457 $whereClause = "log_type = '$logtype' AND log_id IN(" . implode(',',$where) . ")";
458 $result = $dbr->select( 'logging', '*',
459 array( $whereClause ),
460 __METHOD__ );
461 while( $row = $dbr->fetchObject( $result ) ) {
462 $logRows[$row->log_id] = $row;
464 $wgMessageCache->loadAllMessages();
465 foreach( $this->events as $logid ) {
466 // Don't hide from oversight log!!!
467 if( !isset( $logRows[$logid] ) || $logRows[$logid]->log_type=='suppress' ) {
468 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
469 return;
470 } else if( !LogEventsList::userCan( $logRows[$logid],Revision::DELETED_RESTRICTED) ) {
471 // If an event is hidden from sysops
472 if( $action != 'submit') {
473 $wgOut->permissionRequired( 'hiderevision' );
474 return;
476 $UserAllowed = false;
478 $wgOut->addHtml( $this->logLine( $logRows[$logid] ) );
479 $bitfields |= $logRows[$logid]->log_deleted;
481 $wgOut->addHtml( "</ul>" );
483 $wgOut->addWikiMsg( 'revdelete-text' );
484 // Normal sysops can always see what they did, but can't always change it
485 if( !$UserAllowed ) return;
487 $items = array(
488 Xml::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
489 Xml::submitButton( wfMsg( 'revdelete-submit' ) ) );
490 $hidden = array(
491 Xml::hidden( 'wpEditToken', $wgUser->editToken() ),
492 Xml::hidden( 'target', $this->page->getPrefixedText() ),
493 Xml::hidden( 'type', $this->deleteKey ) );
494 foreach( $this->events as $logid ) {
495 $hidden[] = Xml::hidden( 'logid[]', $logid );
498 $special = SpecialPage::getTitleFor( 'Revisiondelete' );
499 $wgOut->addHtml(
500 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $special->getLocalUrl( 'action=submit' ),
501 'id' => 'mw-revdel-form-logs' ) ) .
502 Xml::openElement( 'fieldset' ) .
503 xml::element( 'legend', null, wfMsg( 'revdelete-legend' ) )
505 // FIXME: all items checked for just on event are checked, even if not set for the others
506 foreach( $this->checks as $item ) {
507 list( $message, $name, $field ) = $item;
508 $wgOut->addHtml( Xml::tags( 'div', null, Xml::checkLabel( wfMsg( $message ), $name, $name, $bitfields & $field ) ) );
510 foreach( $items as $item ) {
511 $wgOut->addHtml( Xml::tags( 'p', null, $item ) );
513 foreach( $hidden as $item ) {
514 $wgOut->addHtml( $item );
517 $wgOut->addHtml(
518 Xml::closeElement( 'fieldset' ) .
519 Xml::closeElement( 'form' ) . "\n"
524 * @param Revision $rev
525 * @returns string
527 private function historyLine( $rev ) {
528 global $wgContLang;
530 $date = $wgContLang->timeanddate( $rev->getTimestamp() );
531 $difflink = $del = '';
532 // Live revisions
533 if( $this->deleteKey=='oldid' ) {
534 $revlink = $this->skin->makeLinkObj( $this->page, $date, 'oldid=' . $rev->getId() );
535 $difflink = '(' . $this->skin->makeKnownLinkObj( $this->page, wfMsgHtml('diff'),
536 'diff=' . $rev->getId() . '&oldid=prev' ) . ')';
537 // Archived revisions
538 } else {
539 $undelete = SpecialPage::getTitleFor( 'Undelete' );
540 $target = $this->page->getPrefixedText();
541 $revlink = $this->skin->makeLinkObj( $undelete, $date,
542 "target=$target&timestamp=" . $rev->getTimestamp() );
543 $difflink = '(' . $this->skin->makeKnownLinkObj( $undelete, wfMsgHtml('diff'),
544 "target=$target&diff=prev&timestamp=" . $rev->getTimestamp() ) . ')';
547 if( $rev->isDeleted(Revision::DELETED_TEXT) ) {
548 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
549 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
550 if( !$rev->userCan(Revision::DELETED_TEXT) ) {
551 $revlink = '<span class="history-deleted">'.$date.'</span>';
552 $difflink = '(' . wfMsgHtml('diff') . ')';
556 return "<li> $difflink $revlink ".$this->skin->revUserLink( $rev )." ".$this->skin->revComment( $rev )."$del</li>";
560 * @param File $file
561 * @returns string
563 private function fileLine( $file ) {
564 global $wgContLang, $wgTitle;
566 $target = $this->page->getPrefixedText();
567 $date = $wgContLang->timeanddate( $file->getTimestamp(), true );
569 $del = '';
570 # Hidden files...
571 if( $file->isDeleted(File::DELETED_FILE) ) {
572 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
573 if( !$file->userCan(File::DELETED_FILE) ) {
574 $pageLink = $date;
575 } else {
576 $pageLink = $this->skin->makeKnownLinkObj( $wgTitle, $date,
577 "target=$target&file=$file->sha1.".$file->getExtension() );
579 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
580 # Regular files...
581 } else {
582 $url = $file->getUrlRel();
583 $pageLink = "<a href=\"{$url}\">{$date}</a>";
586 $data = wfMsgHtml( 'widthheight',
587 $wgContLang->formatNum( $file->getWidth() ),
588 $wgContLang->formatNum( $file->getHeight() ) ) .
589 ' (' . wfMsgHtml( 'nbytes', $wgContLang->formatNum( $file->getSize() ) ) . ')';
591 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
595 * @param ArchivedFile $file
596 * @returns string
598 private function archivedfileLine( $file ) {
599 global $wgContLang, $wgTitle;
601 $target = $this->page->getPrefixedText();
602 $date = $wgContLang->timeanddate( $file->getTimestamp(), true );
604 $undelete = SpecialPage::getTitleFor( 'Undelete' );
605 $pageLink = $this->skin->makeKnownLinkObj( $undelete, $date, "target=$target&file={$file->getKey()}" );
607 $del = '';
608 if( $file->isDeleted(File::DELETED_FILE) ) {
609 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
612 $data = wfMsgHtml( 'widthheight',
613 $wgContLang->formatNum( $file->getWidth() ),
614 $wgContLang->formatNum( $file->getHeight() ) ) .
615 ' (' . wfMsgHtml( 'nbytes', $wgContLang->formatNum( $file->getSize() ) ) . ')';
617 return "<li> $pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
621 * @param Array $row row
622 * @returns string
624 private function logLine( $row ) {
625 global $wgContLang;
627 $date = $wgContLang->timeanddate( $row->log_timestamp );
628 $paramArray = LogPage::extractParams( $row->log_params );
629 $title = Title::makeTitle( $row->log_namespace, $row->log_title );
631 $logtitle = SpecialPage::getTitleFor( 'Log' );
632 $loglink = $this->skin->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
633 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
634 // Action text
635 if( !LogEventsList::userCan($row,LogPage::DELETED_ACTION) ) {
636 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
637 } else {
638 $action = LogPage::actionText( $row->log_type, $row->log_action, $title,
639 $this->skin, $paramArray, true, true );
640 if( $row->log_deleted & LogPage::DELETED_ACTION )
641 $action = '<span class="history-deleted">' . $action . '</span>';
643 // User links
644 $userLink = $this->skin->userLink( $row->log_user, User::WhoIs($row->log_user) );
645 if( LogEventsList::isDeleted($row,LogPage::DELETED_USER) ) {
646 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
648 // Comment
649 $comment = $wgContLang->getDirMark() . $this->skin->commentBlock( $row->log_comment );
650 if( LogEventsList::isDeleted($row,LogPage::DELETED_COMMENT) ) {
651 $comment = '<span class="history-deleted">' . $comment . '</span>';
653 return "<li>($loglink) $date $userLink $action $comment</li>";
657 * Generate a user tool link cluster if the current user is allowed to view it
658 * @param ArchivedFile $file
659 * @return string HTML
661 private function fileUserTools( $file ) {
662 if( $file->userCan( Revision::DELETED_USER ) ) {
663 $link = $this->skin->userLink( $file->user, $file->user_text ) .
664 $this->skin->userToolLinks( $file->user, $file->user_text );
665 } else {
666 $link = wfMsgHtml( 'rev-deleted-user' );
668 if( $file->isDeleted( Revision::DELETED_USER ) ) {
669 return '<span class="history-deleted">' . $link . '</span>';
671 return $link;
675 * Wrap and format the given file's comment block, if the current
676 * user is allowed to view it.
678 * @param ArchivedFile $file
679 * @return string HTML
681 private function fileComment( $file ) {
682 if( $file->userCan( File::DELETED_COMMENT ) ) {
683 $block = $this->skin->commentBlock( $file->description );
684 } else {
685 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
687 if( $file->isDeleted( File::DELETED_COMMENT ) ) {
688 return "<span class=\"history-deleted\">$block</span>";
690 return $block;
694 * @param WebRequest $request
696 function submit( $request ) {
697 $bitfield = $this->extractBitfield( $request );
698 $comment = $request->getText( 'wpReason' );
700 $this->target = $request->getText( 'target' );
701 $this->title = Title::newFromURL( $this->target );
703 if( $this->save( $bitfield, $comment, $this->title ) ) {
704 $this->success( $request );
705 } else if( $request->getCheck( 'oldid' ) || $request->getCheck( 'artimestamp' ) ) {
706 return $this->showRevs( $request );
707 } else if( $request->getCheck( 'logid' ) ) {
708 return $this->showLogs( $request );
709 } else if( $request->getCheck( 'oldimage' ) || $request->getCheck( 'fileid' ) ) {
710 return $this->showImages( $request );
714 private function success( $request ) {
715 global $wgOut;
717 $wgOut->setPagetitle( wfMsgHtml( 'actioncomplete' ) );
719 if( $this->deleteKey=='logid' ) {
720 $wgOut->addWikiText( Xml::element( 'span', array( 'class' => 'success' ), wfMsg( 'logdelete-success' ) ), false );
721 $this->showLogItems( $request );
722 } else if( $this->deleteKey=='oldid' || $this->deleteKey=='artimestamp' ) {
723 $wgOut->addWikiText( Xml::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
724 $this->showRevs( $request );
725 } else if( $this->deleteKey=='fileid' ) {
726 $wgOut->addWikiText( Xml::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
727 $this->showImages( $request );
728 } else if( $this->deleteKey=='oldimage' ) {
729 $wgOut->addWikiText( Xml::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
730 $this->showImages( $request );
735 * Put together a rev_deleted bitfield from the submitted checkboxes
736 * @param WebRequest $request
737 * @return int
739 private function extractBitfield( $request ) {
740 $bitfield = 0;
741 foreach( $this->checks as $item ) {
742 list( /* message */ , $name, $field ) = $item;
743 if( $request->getCheck( $name ) ) {
744 $bitfield |= $field;
747 return $bitfield;
750 private function save( $bitfield, $reason, $title ) {
751 $dbw = wfGetDB( DB_MASTER );
752 // Don't allow simply locking the interface for no reason
753 if( $bitfield == Revision::DELETED_RESTRICTED ) {
754 $bitfield = 0;
756 $deleter = new RevisionDeleter( $dbw );
757 // By this point, only one of the below should be set
758 if( isset($this->revisions) ) {
759 return $deleter->setRevVisibility( $title, $this->revisions, $bitfield, $reason );
760 } else if( isset($this->archrevs) ) {
761 return $deleter->setArchiveVisibility( $title, $this->archrevs, $bitfield, $reason );
762 } else if( isset($this->ofiles) ) {
763 return $deleter->setOldImgVisibility( $title, $this->ofiles, $bitfield, $reason );
764 } else if( isset($this->afiles) ) {
765 return $deleter->setArchFileVisibility( $title, $this->afiles, $bitfield, $reason );
766 } else if( isset($this->events) ) {
767 return $deleter->setEventVisibility( $title, $this->events, $bitfield, $reason );
773 * Implements the actions for Revision Deletion.
774 * @addtogroup SpecialPage
776 class RevisionDeleter {
777 function __construct( $db ) {
778 $this->dbw = $db;
782 * @param $title, the page these events apply to
783 * @param array $items list of revision ID numbers
784 * @param int $bitfield new rev_deleted value
785 * @param string $comment Comment for log records
787 function setRevVisibility( $title, $items, $bitfield, $comment ) {
788 global $wgOut;
790 $userAllowedAll = $success = true;
791 $revIDs = array();
792 $revCount = 0;
793 // Run through and pull all our data in one query
794 foreach( $items as $revid ) {
795 $where[] = intval($revid);
797 $whereClause = 'rev_id IN(' . implode(',',$where) . ')';
798 $result = $this->dbw->select( 'revision', '*',
799 array( 'rev_page' => $title->getArticleID(),
800 $whereClause ),
801 __METHOD__ );
802 while( $row = $this->dbw->fetchObject( $result ) ) {
803 $revObjs[$row->rev_id] = new Revision( $row );
805 // To work!
806 foreach( $items as $revid ) {
807 if( !isset($revObjs[$revid]) || $revObjs[$revid]->isCurrent() ) {
808 $success = false;
809 continue; // Must exist
810 } else if( !$revObjs[$revid]->userCan(Revision::DELETED_RESTRICTED) ) {
811 $userAllowedAll=false;
812 continue;
814 // For logging, maintain a count of revisions
815 if( $revObjs[$revid]->mDeleted != $bitfield ) {
816 $revCount++;
817 $revIDs[]=$revid;
819 $this->updateRevision( $revObjs[$revid], $bitfield );
820 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
823 // Clear caches...
824 // Don't log or touch if nothing changed
825 if( $revCount > 0 ) {
826 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted,
827 $comment, $title, 'oldid', $revIDs );
828 $this->updatePage( $title );
830 // Where all revs allowed to be set?
831 if( !$userAllowedAll ) {
832 //FIXME: still might be confusing???
833 $wgOut->permissionRequired( 'hiderevision' );
834 return false;
837 return $success;
841 * @param $title, the page these events apply to
842 * @param array $items list of revision ID numbers
843 * @param int $bitfield new rev_deleted value
844 * @param string $comment Comment for log records
846 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
847 global $wgOut;
849 $userAllowedAll = $success = true;
850 $count = 0;
851 $Id_set = array();
852 // Run through and pull all our data in one query
853 foreach( $items as $timestamp ) {
854 $where[] = $this->dbw->addQuotes( $timestamp );
856 $whereClause = 'ar_timestamp IN(' . implode(',',$where) . ')';
857 $result = $this->dbw->select( 'archive', '*',
858 array( 'ar_namespace' => $title->getNamespace(),
859 'ar_title' => $title->getDBKey(),
860 $whereClause ),
861 __METHOD__ );
862 while( $row = $this->dbw->fetchObject( $result ) ) {
863 $revObjs[$row->ar_timestamp] = new Revision( array(
864 'page' => $title->getArticleId(),
865 'id' => $row->ar_rev_id,
866 'text' => $row->ar_text_id,
867 'comment' => $row->ar_comment,
868 'user' => $row->ar_user,
869 'user_text' => $row->ar_user_text,
870 'timestamp' => $row->ar_timestamp,
871 'minor_edit' => $row->ar_minor_edit,
872 'text_id' => $row->ar_text_id,
873 'deleted' => $row->ar_deleted,
874 'len' => $row->ar_len) );
876 // To work!
877 foreach( $items as $timestamp ) {
878 // This will only select the first revision with this timestamp.
879 // Since they are all selected/deleted at once, we can just check the
880 // permissions of one. UPDATE is done via timestamp, so all revs are set.
881 if( !is_object($revObjs[$timestamp]) ) {
882 $success = false;
883 continue; // Must exist
884 } else if( !$revObjs[$timestamp]->userCan(Revision::DELETED_RESTRICTED) ) {
885 $userAllowedAll=false;
886 continue;
888 // Which revisions did we change anything about?
889 if( $revObjs[$timestamp]->mDeleted != $bitfield ) {
890 $Id_set[]=$timestamp;
891 $count++;
893 $this->updateArchive( $revObjs[$timestamp], $title, $bitfield );
896 // For logging, maintain a count of revisions
897 if( $count > 0 ) {
898 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted,
899 $comment, $title, 'artimestamp', $Id_set );
901 // Where all revs allowed to be set?
902 if( !$userAllowedAll ) {
903 $wgOut->permissionRequired( 'hiderevision' );
904 return false;
907 return $success;
911 * @param $title, the page these events apply to
912 * @param array $items list of revision ID numbers
913 * @param int $bitfield new rev_deleted value
914 * @param string $comment Comment for log records
916 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
917 global $wgOut;
919 $userAllowedAll = $success = true;
920 $count = 0;
921 $set = array();
922 // Run through and pull all our data in one query
923 foreach( $items as $timestamp ) {
924 $where[] = $this->dbw->addQuotes( $timestamp.'!'.$title->getDbKey() );
926 $whereClause = 'oi_archive_name IN(' . implode(',',$where) . ')';
927 $result = $this->dbw->select( 'oldimage', '*',
928 array( 'oi_name' => $title->getDbKey(),
929 $whereClause ),
930 __METHOD__ );
931 while( $row = $this->dbw->fetchObject( $result ) ) {
932 $filesObjs[$row->oi_archive_name] = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
933 $filesObjs[$row->oi_archive_name]->user = $row->oi_user;
934 $filesObjs[$row->oi_archive_name]->user_text = $row->oi_user_text;
936 // To work!
937 foreach( $items as $timestamp ) {
938 $archivename = $timestamp.'!'.$title->getDbKey();
939 if( !isset($filesObjs[$archivename]) ) {
940 $success = false;
941 continue; // Must exist
942 } else if( !$filesObjs[$archivename]->userCan(File::DELETED_RESTRICTED) ) {
943 $userAllowedAll=false;
944 continue;
947 $transaction = true;
948 // Which revisions did we change anything about?
949 if( $filesObjs[$archivename]->deleted != $bitfield ) {
950 $count++;
952 $this->dbw->begin();
953 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
954 // If this image is currently hidden...
955 if( $filesObjs[$archivename]->deleted & File::DELETED_FILE ) {
956 if( $bitfield & File::DELETED_FILE ) {
957 # Leave it alone if we are not changing this...
958 $set[]=$archivename;
959 $transaction = true;
960 } else {
961 # We are moving this out
962 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
963 $set[]=$transaction;
965 // Is it just now becoming hidden?
966 } else if( $bitfield & File::DELETED_FILE ) {
967 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
968 $set[]=$transaction;
969 } else {
970 $set[]=$timestamp;
972 // If our file operations fail, then revert back the db
973 if( $transaction==false ) {
974 $this->dbw->rollback();
975 return false;
977 $this->dbw->commit();
981 // Log if something was changed
982 if( $count > 0 ) {
983 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted,
984 $comment, $title, 'oldimage', $set );
985 # Purge page/history
986 $file = wfLocalFile( $title );
987 $file->purgeCache();
988 $file->purgeHistory();
989 # Invalidate cache for all pages using this file
990 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
991 $update->doUpdate();
993 // Where all revs allowed to be set?
994 if( !$userAllowedAll ) {
995 $wgOut->permissionRequired( 'hiderevision' );
996 return false;
999 return $success;
1003 * @param $title, the page these events apply to
1004 * @param array $items list of revision ID numbers
1005 * @param int $bitfield new rev_deleted value
1006 * @param string $comment Comment for log records
1008 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
1009 global $wgOut;
1011 $userAllowedAll = $success = true;
1012 $count = 0;
1013 $Id_set = array();
1015 // Run through and pull all our data in one query
1016 foreach( $items as $id ) {
1017 $where[] = intval($id);
1019 $whereClause = 'fa_id IN(' . implode(',',$where) . ')';
1020 $result = $this->dbw->select( 'filearchive', '*',
1021 array( 'fa_name' => $title->getDbKey(),
1022 $whereClause ),
1023 __METHOD__ );
1024 while( $row = $this->dbw->fetchObject( $result ) ) {
1025 $filesObjs[$row->fa_id] = ArchivedFile::newFromRow( $row );
1027 // To work!
1028 foreach( $items as $fileid ) {
1029 if( !isset($filesObjs[$fileid]) ) {
1030 $success = false;
1031 continue; // Must exist
1032 } else if( !$filesObjs[$fileid]->userCan(File::DELETED_RESTRICTED) ) {
1033 $userAllowedAll=false;
1034 continue;
1036 // Which revisions did we change anything about?
1037 if( $filesObjs[$fileid]->deleted != $bitfield ) {
1038 $Id_set[]=$fileid;
1039 $count++;
1041 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1044 // Log if something was changed
1045 if( $count > 0 ) {
1046 $this->updateLog( $title, $count, $bitfield, $comment,
1047 $filesObjs[$fileid]->deleted, $title, 'fileid', $Id_set );
1049 // Where all revs allowed to be set?
1050 if( !$userAllowedAll ) {
1051 $wgOut->permissionRequired( 'hiderevision' );
1052 return false;
1055 return $success;
1059 * @param $title, the log page these events apply to
1060 * @param array $items list of log ID numbers
1061 * @param int $bitfield new log_deleted value
1062 * @param string $comment Comment for log records
1064 function setEventVisibility( $title, $items, $bitfield, $comment ) {
1065 global $wgOut;
1067 $userAllowedAll = $success = true;
1068 $count = 0;
1069 $log_Ids = array();
1071 // Run through and pull all our data in one query
1072 foreach( $items as $logid ) {
1073 $where[] = intval($logid);
1075 list($log,$logtype) = explode( '/',$title->getDBKey(), 2 );
1076 $whereClause = "log_type ='$logtype' AND log_id IN(" . implode(',',$where) . ")";
1077 $result = $this->dbw->select( 'logging', '*',
1078 array( $whereClause ),
1079 __METHOD__ );
1080 while( $row = $this->dbw->fetchObject( $result ) ) {
1081 $logRows[$row->log_id] = $row;
1083 // To work!
1084 foreach( $items as $logid ) {
1085 if( !isset($logRows[$logid]) ) {
1086 $success = false;
1087 continue; // Must exist
1088 } else if( !LogEventsList::userCan($logRows[$logid], LogPage::DELETED_RESTRICTED)
1089 || $logRows[$logid]->log_type == 'suppress' ) {
1090 // Don't hide from oversight log!!!
1091 $userAllowedAll=false;
1092 continue;
1094 // Which logs did we change anything about?
1095 if( $logRows[$logid]->log_deleted != $bitfield ) {
1096 $log_Ids[]=$logid;
1097 $count++;
1099 $this->updateLogs( $logRows[$logid], $bitfield );
1100 $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
1103 // Don't log or touch if nothing changed
1104 if( $count > 0 ) {
1105 $this->updateLog( $title, $count, $bitfield, $logRows[$logid]->log_deleted,
1106 $comment, $title, 'logid', $log_Ids );
1108 // Where all revs allowed to be set?
1109 if( !$userAllowedAll ) {
1110 $wgOut->permissionRequired( 'hiderevision' );
1111 return false;
1114 return $success;
1118 * Moves an image to a safe private location
1119 * Caller is responsible for clearing caches
1120 * @param File $oimage
1121 * @returns mixed, timestamp string on success, false on failure
1123 function makeOldImagePrivate( $oimage ) {
1124 global $wgFileStore, $wgUseSquid;
1126 $transaction = new FSTransaction();
1127 if( !FileStore::lock() ) {
1128 wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" );
1129 return false;
1131 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR . $oimage->archive_name;
1132 // Dupe the file into the file store
1133 if( file_exists( $oldpath ) ) {
1134 // Is our directory configured?
1135 if( $store = FileStore::get( 'deleted' ) ) {
1136 if( !$oimage->sha1 ) {
1137 $oimage->upgradeRow(); // sha1 may be missing
1139 $key = $oimage->sha1 . '.' . $oimage->getExtension();
1140 $transaction->add( $store->insert( $key, $oldpath, FileStore::DELETE_ORIGINAL ) );
1141 } else {
1142 $group = null;
1143 $key = null;
1144 $transaction = false; // Return an error and do nothing
1146 } else {
1147 wfDebug( __METHOD__." deleting already-missing '$oldpath'; moving on to database\n" );
1148 $group = null;
1149 $key = '';
1150 $transaction = new FSTransaction(); // empty
1153 if( $transaction === false ) {
1154 // Fail to restore?
1155 wfDebug( __METHOD__.": import to file store failed, aborting\n" );
1156 throw new MWException( "Could not archive and delete file $oldpath" );
1157 return false;
1160 wfDebug( __METHOD__.": set db items, applying file transactions\n" );
1161 $transaction->commit();
1162 FileStore::unlock();
1164 $m = explode('!',$oimage->archive_name,2);
1165 $timestamp = $m[0];
1167 return $timestamp;
1171 * Moves an image from a safe private location
1172 * Caller is responsible for clearing caches
1173 * @param File $oimage
1174 * @returns mixed, string timestamp on success, false on failure
1176 function makeOldImagePublic( $oimage ) {
1177 global $wgFileStore;
1179 $transaction = new FSTransaction();
1180 if( !FileStore::lock() ) {
1181 wfDebug( __METHOD__." could not acquire filestore lock\n" );
1182 return false;
1185 $store = FileStore::get( 'deleted' );
1186 if( !$store ) {
1187 wfDebug( __METHOD__.": skipping row with no file.\n" );
1188 return false;
1191 $key = $oimage->sha1.'.'.$oimage->getExtension();
1192 $destDir = $oimage->getArchivePath();
1193 if( !is_dir( $destDir ) ) {
1194 wfMkdirParents( $destDir );
1196 $destPath = $destDir . DIRECTORY_SEPARATOR . $oimage->archive_name;
1197 // Check if any other stored revisions use this file;
1198 // if so, we shouldn't remove the file from the hidden
1199 // archives so they will still work. Check hidden files first.
1200 $useCount = $this->dbw->selectField( 'oldimage', '1',
1201 array( 'oi_sha1' => $oimage->sha1,
1202 'oi_deleted & '.File::DELETED_FILE => File::DELETED_FILE ),
1203 __METHOD__, array( 'FOR UPDATE' ) );
1204 // Check the rest of the deleted archives too.
1205 // (these are the ones that don't show in the image history)
1206 if( !$useCount ) {
1207 $useCount = $this->dbw->selectField( 'filearchive', '1',
1208 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1209 __METHOD__, array( 'FOR UPDATE' ) );
1212 if( $useCount == 0 ) {
1213 wfDebug( __METHOD__.": nothing else using {$oimage->sha1}, will deleting after\n" );
1214 $flags = FileStore::DELETE_ORIGINAL;
1215 } else {
1216 $flags = 0;
1218 $transaction->add( $store->export( $key, $destPath, $flags ) );
1220 wfDebug( __METHOD__.": set db items, applying file transactions\n" );
1221 $transaction->commit();
1222 FileStore::unlock();
1224 $m = explode('!',$oimage->archive_name,2);
1225 $timestamp = $m[0];
1227 return $timestamp;
1231 * Update the revision's rev_deleted field
1232 * @param Revision $rev
1233 * @param int $bitfield new rev_deleted bitfield value
1235 function updateRevision( $rev, $bitfield ) {
1236 $this->dbw->update( 'revision',
1237 array( 'rev_deleted' => $bitfield ),
1238 array( 'rev_id' => $rev->getId(),
1239 'rev_page' => $rev->getPage() ),
1240 __METHOD__ );
1244 * Update the revision's rev_deleted field
1245 * @param Revision $rev
1246 * @param Title $title
1247 * @param int $bitfield new rev_deleted bitfield value
1249 function updateArchive( $rev, $title, $bitfield ) {
1250 $this->dbw->update( 'archive',
1251 array( 'ar_deleted' => $bitfield ),
1252 array( 'ar_namespace' => $title->getNamespace(),
1253 'ar_title' => $title->getDBKey(),
1254 'ar_timestamp' => $this->dbw->timestamp( $rev->getTimestamp() ),
1255 'ar_rev_id' => $rev->getId() ),
1256 __METHOD__ );
1260 * Update the images's oi_deleted field
1261 * @param File $file
1262 * @param int $bitfield new rev_deleted bitfield value
1264 function updateOldFiles( $file, $bitfield ) {
1265 $this->dbw->update( 'oldimage',
1266 array( 'oi_deleted' => $bitfield ),
1267 array( 'oi_name' => $file->getName(),
1268 'oi_timestamp' => $this->dbw->timestamp( $file->getTimestamp() ) ),
1269 __METHOD__ );
1273 * Update the images's fa_deleted field
1274 * @param ArchivedFile $file
1275 * @param int $bitfield new rev_deleted bitfield value
1277 function updateArchFiles( $file, $bitfield ) {
1278 $this->dbw->update( 'filearchive',
1279 array( 'fa_deleted' => $bitfield ),
1280 array( 'fa_id' => $file->getID() ),
1281 __METHOD__ );
1285 * Update the logging log_deleted field
1286 * @param Row $row
1287 * @param int $bitfield new rev_deleted bitfield value
1289 function updateLogs( $row, $bitfield ) {
1290 $this->dbw->update( 'logging',
1291 array( 'log_deleted' => $bitfield ),
1292 array( 'log_id' => $row->log_id ),
1293 __METHOD__ );
1297 * Update the revision's recentchanges record if fields have been hidden
1298 * @param Revision $rev
1299 * @param int $bitfield new rev_deleted bitfield value
1301 function updateRecentChangesEdits( $rev, $bitfield ) {
1302 $this->dbw->update( 'recentchanges',
1303 array( 'rc_deleted' => $bitfield,
1304 'rc_patrolled' => 1 ),
1305 array( 'rc_this_oldid' => $rev->getId(),
1306 'rc_timestamp' => $this->dbw->timestamp( $rev->getTimestamp() ) ),
1307 __METHOD__ );
1311 * Update the revision's recentchanges record if fields have been hidden
1312 * @param Row $row
1313 * @param int $bitfield new rev_deleted bitfield value
1315 function updateRecentChangesLog( $row, $bitfield ) {
1316 $this->dbw->update( 'recentchanges',
1317 array( 'rc_deleted' => $bitfield,
1318 'rc_patrolled' => 1 ),
1319 array( 'rc_logid' => $row->log_id,
1320 'rc_timestamp' => $row->log_timestamp ),
1321 __METHOD__ );
1325 * Touch the page's cache invalidation timestamp; this forces cached
1326 * history views to refresh, so any newly hidden or shown fields will
1327 * update properly.
1328 * @param Title $title
1330 function updatePage( $title ) {
1331 $title->invalidateCache();
1332 $title->purgeSquid();
1334 // Extensions that require referencing previous revisions may need this
1335 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1339 * Checks for a change in the bitfield for a certain option and updates the
1340 * provided array accordingly.
1342 * @param String $desc Description to add to the array if the option was
1343 * enabled / disabled.
1344 * @param int $field The bitmask describing the single option.
1345 * @param int $diff The xor of the old and new bitfields.
1346 * @param array $arr The array to update.
1348 function checkItem ( $desc, $field, $diff, $new, &$arr ) {
1349 if ( $diff & $field ) {
1350 $arr [ ( $new & $field ) ? 0 : 1 ][] = $desc;
1355 * Gets an array describing the changes made to the visibilit of the revision.
1356 * If the resulting array is $arr, then $arr[0] will contain an array of strings
1357 * describing the items that were hidden, $arr[2] will contain an array of strings
1358 * describing the items that were unhidden, and $arr[3] will contain an array with
1359 * a single string, which can be one of "applied restrictions to sysops",
1360 * "removed restrictions from sysops", or null.
1362 * @param int $n The new bitfield.
1363 * @param int $o The old bitfield.
1364 * @return An array as described above.
1366 function getChanges ( $n, $o ) {
1367 $diff = $n ^ $o;
1368 $ret = array ( 0 => array(), 1 => array(), 2 => array() );
1370 $this->checkItem ( wfMsgForContent ( 'revdelete-content' ),
1371 Revision::DELETED_TEXT, $diff, $n, $ret );
1372 $this->checkItem ( wfMsgForContent ( 'revdelete-summary' ),
1373 Revision::DELETED_COMMENT, $diff, $n, $ret );
1374 $this->checkItem ( wfMsgForContent ( 'revdelete-uname' ),
1375 Revision::DELETED_USER, $diff, $n, $ret );
1377 // Restriction application to sysops
1378 if ( $diff & Revision::DELETED_RESTRICTED ) {
1379 if ( $n & Revision::DELETED_RESTRICTED )
1380 $ret[2][] = wfMsgForContent ( 'revdelete-restricted' );
1381 else
1382 $ret[2][] = wfMsgForContent ( 'revdelete-unrestricted' );
1385 return $ret;
1389 * Gets a log message to describe the given revision visibility change. This
1390 * message will be of the form "[hid {content, edit summary, username}];
1391 * [unhid {...}][applied restrictions to sysops] for $count revisions: $comment".
1393 * @param int $count The number of effected revisions.
1394 * @param int $nbitfield The new bitfield for the revision.
1395 * @param int $obitfield The old bitfield for the revision.
1396 * @param string $comment The comment associated with the change.
1397 * @param bool $isForLog
1399 function getLogMessage ( $count, $nbitfield, $obitfield, $comment, $isForLog = false ) {
1400 global $wgContLang;
1402 $s = '';
1403 $changes = $this->getChanges( $nbitfield, $obitfield );
1405 if ( count ( $changes[0] ) ) {
1406 $s .= wfMsgForContent ( 'revdelete-hid', implode ( ', ', $changes[0] ) );
1409 if ( count ( $changes[1] ) ) {
1410 if ($s) $s .= '; ';
1412 $s .= wfMsgForContent ( 'revdelete-unhid', implode ( ', ', $changes[1] ) );
1415 if ( count ( $changes[2] )) {
1416 if ($s)
1417 $s .= ' (' . $changes[2][0] . ')';
1418 else
1419 $s = $changes[2][0];
1422 $msg = $isForLog ? 'logdelete-log-message' : 'revdelete-log-message';
1423 $ret = wfMsgExt ( $msg, array( 'parsemag', 'content' ),
1424 $s, $wgContLang->formatNum( $count ) );
1426 if ( $comment )
1427 $ret .= ": $comment";
1429 return $ret;
1434 * Record a log entry on the action
1435 * @param Title $title, page where item was removed from
1436 * @param int $count the number of revisions altered for this page
1437 * @param int $nbitfield the new _deleted value
1438 * @param int $obitfield the old _deleted value
1439 * @param string $comment
1440 * @param Title $target, the relevant page
1441 * @param string $param, URL param
1442 * @param Array $items
1444 function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target, $param, $items = array() ) {
1445 // Put things hidden from sysops in the oversight log
1446 $logtype = ( ($nbitfield | $obitfield) & Revision::DELETED_RESTRICTED ) ? 'suppress' : 'delete';
1447 $log = new LogPage( $logtype );
1449 $reason = $this->getLogMessage ( $count, $nbitfield, $obitfield, $comment, $param == 'logid' );
1451 if( $param == 'logid' ) {
1452 $params = array( implode( ',', $items) );
1453 $log->addEntry( 'event', $title, $reason, $params );
1454 } else {
1455 // Add params for effected page and ids
1456 $params = array( $param, implode( ',', $items) );
1457 $log->addEntry( 'revision', $title, $reason, $params );