Fix bug: max-slave-length => max-slave-lag
[lhc/web/wiklou.git] / includes / SpecialRevisiondelete.php
1 <?php
2
3 /**
4 * Special page allowing users with the appropriate permissions to view
5 * and hide revisions. Log items can also be hidden.
6 *
7 * @addtogroup SpecialPage
8 */
9
10 function wfSpecialRevisiondelete( $par = null ) {
11 global $wgOut, $wgRequest, $wgUser, $wgAllowLogDeletion;
12 # Handle our many different possible input types
13 $target = $wgRequest->getText( 'target' );
14 $oldid = $wgRequest->getArray( 'oldid' );
15 $artimestamp = $wgRequest->getArray( 'artimestamp' );
16 $logid = $wgAllowLogDeletion ? $wgRequest->getArray( 'logid' ) : '';
17 $img = $wgRequest->getArray( 'oldimage' );
18 $fileid = $wgRequest->getArray( 'fileid' );
19 # For reviewing deleted files...
20 $file = $wgRequest->getVal( 'file' );
21 # If this is a revision, then we need a target page
22 $page = Title::newFromUrl( $target );
23 if( is_null($page) && is_null($logid) ) {
24 $wgOut->addWikiText( wfMsgHtml( 'undelete-header' ) );
25 return;
26 }
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;
32 }
33 # Either submit or create our form
34 $form = new RevisionDeleteForm( $page, $oldid, $logid, $artimestamp, $fileid, $img, $file );
35 if( $wgRequest->wasPosted() ) {
36 $form->submit( $wgRequest );
37 } else if( $oldid || $artimestamp ) {
38 $form->showRevs( $wgRequest );
39 } else if( $fileid || $img ) {
40 $form->showImages( $wgRequest );
41 } else if( $logid ) {
42 $form->showLogItems( $wgRequest );
43 }
44 # Show relevant lines from the deletion log. This will show even if said ID
45 # does not exist...might be helpful
46 if( !is_null($page) ) {
47 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
48 $logViewer = new LogViewer(
49 new LogReader(
50 new FauxRequest(
51 array( 'page' => $page->getPrefixedText(), 'type' => 'delete' ) ) ) );
52 $logViewer->showList( $wgOut );
53 }
54 }
55
56 /**
57 * Implements the GUI for Revision Deletion.
58 * @addtogroup SpecialPage
59 */
60 class RevisionDeleteForm {
61 /**
62 * @param Title $page
63 * @param array $oldids
64 * @param array $logids
65 * @param array $artimestamps
66 * @param array $fileids
67 * @param array $img
68 * @param string $file
69 */
70 function __construct( $page, $oldids, $logids, $artimestamps, $fileids, $img, $file ) {
71 global $wgUser, $wgOut;
72
73 $this->page = $page;
74 # For reviewing deleted files...
75 if( $file ) {
76 $oimage = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $page, $file );
77 $oimage->load();
78 // Check if user is allowed to see this file
79 if( !$oimage->userCan(File::DELETED_FILE) ) {
80 $wgOut->permissionRequired( 'hiderevision' );
81 } else {
82 $this->showFile( $file );
83 }
84 return;
85 }
86 $this->skin = $wgUser->getSkin();
87 # Give a link to the log for this page
88 if( !is_null($this->page) && $this->page->getNamespace() > -1 ) {
89 $links = array();
90
91 $logtitle = SpecialPage::getTitleFor( 'Log' );
92 $links[] = $this->skin->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ),
93 wfArrayToCGI( array( 'page' => $this->page->getPrefixedUrl() ) ) );
94 # Give a link to the page history
95 $links[] = $this->skin->makeKnownLinkObj( $this->page, wfMsgHtml( 'pagehist' ),
96 wfArrayToCGI( array( 'action' => 'history' ) ) );
97 # Link to deleted edits
98 if( $wgUser->isAllowed('undelete') ) {
99 $undelete = SpecialPage::getTitleFor( 'Undelete' );
100 $links[] = $this->skin->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ),
101 wfArrayToCGI( array( 'target' => $this->page->getPrefixedUrl() ) ) );
102 }
103 # Logs themselves don't have histories or archived revisions
104 $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' );
105 }
106 // At this point, we should only have one of these
107 if( $oldids ) {
108 $this->revisions = $oldids;
109 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision::DELETED_TEXT );
110 $this->deleteKey='oldid';
111 } else if( $artimestamps ) {
112 $this->archrevs = $artimestamps;
113 $hide_content_name = array( 'revdelete-hide-text', 'wpHideText', Revision::DELETED_TEXT );
114 $this->deleteKey='artimestamp';
115 } else if( $img ) {
116 $this->ofiles = $img;
117 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File::DELETED_FILE );
118 $this->deleteKey='oldimage';
119 } else if( $fileids ) {
120 $this->afiles = $fileids;
121 $hide_content_name = array( 'revdelete-hide-image', 'wpHideImage', File::DELETED_FILE );
122 $this->deleteKey='fileid';
123 } else if( $logids ) {
124 $this->events = $logids;
125 $hide_content_name = array( 'revdelete-hide-name', 'wpHideName', LogPage::DELETED_ACTION );
126 $this->deleteKey='logid';
127 }
128 // Our checkbox messages depends one what we are doing,
129 // e.g. we don't hide "text" for logs or images
130 $this->checks = array(
131 $hide_content_name,
132 array( 'revdelete-hide-comment', 'wpHideComment', Revision::DELETED_COMMENT ),
133 array( 'revdelete-hide-user', 'wpHideUser', Revision::DELETED_USER ),
134 array( 'revdelete-hide-restricted', 'wpHideRestricted', Revision::DELETED_RESTRICTED ) );
135 }
136
137 /**
138 * Show a deleted file version requested by the visitor.
139 */
140 private function showFile( $key ) {
141 global $wgOut, $wgRequest;
142 $wgOut->disable();
143
144 # We mustn't allow the output to be Squid cached, otherwise
145 # if an admin previews a deleted image, and it's cached, then
146 # a user without appropriate permissions can toddle off and
147 # nab the image, and Squid will serve it
148 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
149 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
150 $wgRequest->response()->header( 'Pragma: no-cache' );
151
152 $store = FileStore::get( 'deleted' );
153 $store->stream( $key );
154 }
155
156 /**
157 * This lets a user set restrictions for live and archived revisions
158 * @param WebRequest $request
159 */
160 function showRevs( $request ) {
161 global $wgOut, $wgUser, $action;
162
163 $UserAllowed = true;
164
165 $count = ($this->deleteKey=='oldid') ?
166 count($this->revisions) : count($this->archrevs);
167 $wgOut->addWikiMsg( 'revdelete-selected', $this->page->getPrefixedText(), $count );
168
169 $bitfields = 0;
170 $wgOut->addHtml( "<ul>" );
171
172 $where = $revObjs = array();
173 $dbr = wfGetDB( DB_SLAVE );
174 // Live revisions...
175 if( $this->deleteKey=='oldid' ) {
176 // Run through and pull all our data in one query
177 foreach( $this->revisions as $revid ) {
178 $where[] = intval($revid);
179 }
180 $whereClause = 'rev_id IN(' . implode(',',$where) . ')';
181 $result = $dbr->select( array('revision','page'), '*',
182 array( 'rev_page' => $this->page->getArticleID(),
183 $whereClause, 'rev_page = page_id' ),
184 __METHOD__ );
185 while( $row = $dbr->fetchObject( $result ) ) {
186 $revObjs[$row->rev_id] = new Revision( $row );
187 }
188 foreach( $this->revisions as $revid ) {
189 // Hiding top revisison is bad
190 if( !is_object($revObjs[$revid]) || $revObjs[$revid]->isCurrent() ) {
191 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
192 return;
193 } else if( !$revObjs[$revid]->userCan(Revision::DELETED_RESTRICTED) ) {
194 // If a rev is hidden from sysops
195 if( $action != 'submit') {
196 $wgOut->permissionRequired( 'hiderevision' );
197 return;
198 }
199 $UserAllowed = false;
200 }
201 $wgOut->addHtml( $this->historyLine( $revObjs[$revid] ) );
202 $bitfields |= $revObjs[$revid]->mDeleted;
203 }
204 // The archives...
205 } else {
206 // Run through and pull all our data in one query
207 foreach( $this->archrevs as $timestamp ) {
208 $where[] = $dbr->addQuotes( $timestamp );
209 }
210 $whereClause = 'ar_timestamp IN(' . implode(',',$where) . ')';
211 $result = $dbr->select( 'archive', '*',
212 array( 'ar_namespace' => $this->page->getNamespace(),
213 'ar_title' => $this->page->getDBKey(),
214 $whereClause ),
215 __METHOD__ );
216 while( $row = $dbr->fetchObject( $result ) ) {
217 $revObjs[$row->ar_timestamp] = new Revision( array(
218 'page' => $this->page->getArticleId(),
219 'id' => $row->ar_rev_id,
220 'text' => $row->ar_text_id,
221 'comment' => $row->ar_comment,
222 'user' => $row->ar_user,
223 'user_text' => $row->ar_user_text,
224 'timestamp' => $row->ar_timestamp,
225 'minor_edit' => $row->ar_minor_edit,
226 'text_id' => $row->ar_text_id,
227 'deleted' => $row->ar_deleted,
228 'len' => $row->ar_len) );
229 }
230 foreach( $this->archrevs as $timestamp ) {
231 if( !is_object($revObjs[$timestamp]) ) {
232 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
233 return;
234 }
235 }
236 foreach( $revObjs as $rev ) {
237 if( !$rev->userCan(Revision::DELETED_RESTRICTED) ) {
238 // If a rev is hidden from sysops
239 if( $action != 'submit') {
240 $wgOut->permissionRequired( 'hiderevision' );
241 return;
242 }
243 $UserAllowed = false;
244 }
245 $wgOut->addHtml( $this->historyLine( $rev ) );
246 $bitfields |= $rev->mDeleted;
247 }
248 }
249 $wgOut->addHtml( "</ul>" );
250
251 $wgOut->addWikiText( wfMsgHtml( 'revdelete-text' ) );
252
253 // Normal sysops can always see what they did, but can't always change it
254 if( !$UserAllowed ) return;
255
256 $items = array(
257 wfInputLabel( wfMsgHtml( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
258 wfSubmitButton( wfMsgHtml( 'revdelete-submit' ) ) );
259 $hidden = array(
260 wfHidden( 'wpEditToken', $wgUser->editToken() ),
261 wfHidden( 'target', $this->page->getPrefixedText() ),
262 wfHidden( 'type', $this->deleteKey ) );
263 if( $this->deleteKey=='oldid' ) {
264 foreach( $revObjs as $rev )
265 $hidden[] = wfHidden( 'oldid[]', $rev->getID() );
266 } else {
267 foreach( $revObjs as $rev )
268 $hidden[] = wfHidden( 'artimestamp[]', $rev->getTimestamp() );
269 }
270 $special = SpecialPage::getTitleFor( 'Revisiondelete' );
271 $wgOut->addHtml( wfElement( 'form', array(
272 'method' => 'post',
273 'action' => $special->getLocalUrl( 'action=submit' ) ),
274 null ) );
275
276 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'revdelete-legend' ) . '</legend>' );
277 // FIXME: all items checked for just one rev are checked, even if not set for the others
278 foreach( $this->checks as $item ) {
279 list( $message, $name, $field ) = $item;
280 $wgOut->addHtml( "<div>" .
281 wfCheckLabel( wfMsgHtml( $message), $name, $name, $bitfields & $field ) .
282 "</div>\n" );
283 }
284 $wgOut->addHtml( '</fieldset>' );
285 foreach( $items as $item ) {
286 $wgOut->addHtml( '<p>' . $item . '</p>' );
287 }
288 foreach( $hidden as $item ) {
289 $wgOut->addHtml( $item );
290 }
291
292 $wgOut->addHtml( '</form>' );
293 }
294
295 /**
296 * This lets a user set restrictions for archived images
297 * @param WebRequest $request
298 */
299 function showImages( $request ) {
300 global $wgOut, $wgUser, $action;
301
302 $UserAllowed = true;
303
304 $count = ($this->deleteKey=='oldimage') ? count($this->ofiles) : count($this->afiles);
305 $wgOut->addWikiText( wfMsgExt( 'revdelete-selected', array('parsemag'),
306 $this->page->getPrefixedText(), $count ) );
307
308 $bitfields = 0;
309 $wgOut->addHtml( "<ul>" );
310
311 $where = $filesObjs = array();
312 $dbr = wfGetDB( DB_SLAVE );
313 // Live old revisions...
314 if( $this->deleteKey=='oldimage' ) {
315 // Run through and pull all our data in one query
316 foreach( $this->ofiles as $timestamp ) {
317 $where[] = $dbr->addQuotes( $timestamp.'!'.$this->page->getDbKey() );
318 }
319 $whereClause = 'oi_archive_name IN(' . implode(',',$where) . ')';
320 $result = $dbr->select( 'oldimage', '*',
321 array( 'oi_name' => $this->page->getDbKey(),
322 $whereClause ),
323 __METHOD__ );
324 while( $row = $dbr->fetchObject( $result ) ) {
325 $filesObjs[$row->oi_archive_name] = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
326 $filesObjs[$row->oi_archive_name]->user = $row->oi_user;
327 $filesObjs[$row->oi_archive_name]->user_text = $row->oi_user_text;
328 }
329 // Check through our images
330 foreach( $this->ofiles as $timestamp ) {
331 $archivename = $timestamp.'!'.$this->page->getDbKey();
332 if( !isset($filesObjs[$archivename]) ) {
333 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
334 return;
335 }
336 }
337 foreach( $filesObjs as $file ) {
338 if( !isset($file) ) {
339 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
340 return;
341 } else if( !$file->userCan(File::DELETED_RESTRICTED) ) {
342 // If a rev is hidden from sysops
343 if( $action != 'submit' ) {
344 $wgOut->permissionRequired( 'hiderevision' );
345 return;
346 }
347 $UserAllowed = false;
348 }
349 // Inject history info
350 $wgOut->addHtml( $this->fileLine( $file ) );
351 $bitfields |= $file->deleted;
352 }
353 // Archived files...
354 } else {
355 // Run through and pull all our data in one query
356 foreach( $this->afiles as $id ) {
357 $where[] = intval($id);
358 }
359 $whereClause = 'fa_id IN(' . implode(',',$where) . ')';
360 $result = $dbr->select( 'filearchive', '*',
361 array( 'fa_name' => $this->page->getDbKey(),
362 $whereClause ),
363 __METHOD__ );
364 while( $row = $dbr->fetchObject( $result ) ) {
365 $filesObjs[$row->fa_id] = ArchivedFile::newFromRow( $row );
366 }
367
368 foreach( $this->afiles as $fileid ) {
369 if( !isset($filesObjs[$fileid]) ) {
370 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
371 return;
372 } else if( !$filesObjs[$fileid]->userCan(File::DELETED_RESTRICTED) ) {
373 // If a rev is hidden from sysops
374 if( $action != 'submit' ) {
375 $wgOut->permissionRequired( 'hiderevision' );
376 return;
377 }
378 $UserAllowed = false;
379 }
380 // Inject history info
381 $wgOut->addHtml( $this->archivedfileLine( $filesObjs[$fileid] ) );
382 $bitfields |= $filesObjs[$fileid]->deleted;
383 }
384 }
385 $wgOut->addHtml( "</ul>" );
386
387 $wgOut->addWikiText( wfMsgHtml( 'revdelete-text' ) );
388 //Normal sysops can always see what they did, but can't always change it
389 if( !$UserAllowed ) return;
390
391 $items = array(
392 wfInputLabel( wfMsgHtml( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
393 wfSubmitButton( wfMsgHtml( 'revdelete-submit' ) ) );
394 $hidden = array(
395 wfHidden( 'wpEditToken', $wgUser->editToken() ),
396 wfHidden( 'target', $this->page->getPrefixedText() ),
397 wfHidden( 'type', $this->deleteKey ) );
398 if( $this->deleteKey=='oldimage' ) {
399 foreach( $this->ofiles as $filename )
400 $hidden[] = wfHidden( 'oldimage[]', $filename );
401 } else {
402 foreach( $this->afiles as $fileid )
403 $hidden[] = wfHidden( 'fileid[]', $fileid );
404 }
405 $special = SpecialPage::getTitleFor( 'Revisiondelete' );
406 $wgOut->addHtml( wfElement( 'form', array(
407 'method' => 'post',
408 'action' => $special->getLocalUrl( 'action=submit' ) ),
409 null ) );
410
411 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'revdelete-legend' ) . '</legend>' );
412 // FIXME: all items checked for just one file are checked, even if not set for the others
413 foreach( $this->checks as $item ) {
414 list( $message, $name, $field ) = $item;
415 $wgOut->addHtml( '<div>' .
416 wfCheckLabel( wfMsgHtml( $message), $name, $name, $bitfields & $field ) .
417 '</div>' );
418 }
419 $wgOut->addHtml( '</fieldset>' );
420 foreach( $items as $item ) {
421 $wgOut->addHtml( '<p>' . $item . '</p>' );
422 }
423 foreach( $hidden as $item ) {
424 $wgOut->addHtml( $item );
425 }
426
427 $wgOut->addHtml( '</form>' );
428 }
429
430 /**
431 * This lets a user set restrictions for log items
432 * @param WebRequest $request
433 */
434 function showLogItems( $request ) {
435 global $wgOut, $wgUser, $action;
436
437 $UserAllowed = true;
438 $wgOut->addWikiText( wfMsgExt( 'logdelete-selected', array('parsemag'), count($this->events) ) );
439
440 $bitfields = 0;
441 $wgOut->addHtml( "<ul>" );
442
443 $where = $logRows = array();
444 $dbr = wfGetDB( DB_SLAVE );
445 // Run through and pull all our data in one query
446 foreach( $this->events as $logid ) {
447 $where[] = intval($logid);
448 }
449 $whereClause = 'log_id IN(' . implode(',',$where) . ')';
450 $result = $dbr->select( 'logging', '*',
451 array( $whereClause ),
452 __METHOD__ );
453 while( $row = $dbr->fetchObject( $result ) ) {
454 $logRows[$row->log_id] = $row;
455 }
456 foreach( $this->events as $logid ) {
457 // Don't hide from oversight log!!!
458 if( !isset( $logRows[$logid] ) || $logRows[$logid]->log_type=='oversight' ) {
459 $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' );
460 return;
461 } else if( !LogPage::userCan( $logRows[$logid],Revision::DELETED_RESTRICTED) ) {
462 // If an event is hidden from sysops
463 if( $action != 'submit') {
464 $wgOut->permissionRequired( 'hiderevision' );
465 return;
466 }
467 $UserAllowed = false;
468 }
469 $wgOut->addHtml( $this->logLine( $logRows[$logid] ) );
470 $bitfields |= $logRows[$logid]->log_deleted;
471 }
472 $wgOut->addHtml( "</ul>" );
473
474 $wgOut->addWikiMsg( 'revdelete-text' );
475 // Normal sysops can always see what they did, but can't always change it
476 if( !$UserAllowed ) return;
477
478 $items = array(
479 Xml::inputLabel( wfMsg( 'revdelete-log' ), 'wpReason', 'wpReason', 60 ),
480 Xml::submitButton( wfMsg( 'revdelete-submit' ) ) );
481 $hidden = array(
482 Xml::hidden( 'wpEditToken', $wgUser->editToken() ),
483 Xml::hidden( 'type', $this->deleteKey ) );
484 foreach( $this->events as $logid ) {
485 $hidden[] = Xml::hidden( 'logid[]', $logid );
486 }
487
488 $special = SpecialPage::getTitleFor( 'Revisiondelete' );
489 $wgOut->addHtml( Xml::element( 'form', array(
490 'method' => 'post',
491 'action' => $special->getLocalUrl( 'action=submit' ) ),
492 null ) );
493
494 $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'revdelete-legend' ) . '</legend>' );
495 // FIXME: all items checked for just on event are checked, even if not set for the others
496 foreach( $this->checks as $item ) {
497 list( $message, $name, $field ) = $item;
498 $wgOut->addHtml( '<div>' .
499 Xml::checkLabel( wfMsg( $message), $name, $name, $bitfields & $field ) .
500 '</div>' );
501 }
502 $wgOut->addHtml( '</fieldset>' );
503 foreach( $items as $item ) {
504 $wgOut->addHtml( '<p>' . $item . '</p>' );
505 }
506 foreach( $hidden as $item ) {
507 $wgOut->addHtml( $item );
508 }
509
510 $wgOut->addHtml( '</form>' );
511 }
512
513 /**
514 * @param Revision $rev
515 * @returns string
516 */
517 private function historyLine( $rev ) {
518 global $wgContLang;
519 $date = $wgContLang->timeanddate( $rev->getTimestamp() );
520
521 $difflink=''; $del = '';
522 // Live revisions
523 if( $this->deleteKey=='oldid' ) {
524 $difflink = '(' . $this->skin->makeKnownLinkObj( $this->page, wfMsgHtml('diff'),
525 'diff=' . $rev->getId() . '&oldid=prev' ) . ')';
526 $revlink = $this->skin->makeLinkObj( $this->page, $date, 'oldid=' . $rev->getId() );
527 } else {
528 // Archived revisions
529 $undelete = SpecialPage::getTitleFor( 'Undelete' );
530 $target = $this->page->getPrefixedText();
531 $revlink = $this->skin->makeLinkObj( $undelete, $date,
532 "target=$target&timestamp=" . $rev->getTimestamp() );
533 }
534
535 if( $rev->isDeleted(Revision::DELETED_TEXT) ) {
536 $revlink = '<span class="history-deleted">'.$revlink.'</span>';
537 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
538 if( !$rev->userCan(Revision::DELETED_TEXT) ) {
539 $revlink = '<span class="history-deleted">'.$date.'</span>';
540 }
541 }
542
543 return "<li> $difflink $revlink ".$this->skin->revUserLink( $rev )." ".$this->skin->revComment( $rev )."$del</li>";
544 }
545
546 /**
547 * @param File $file
548 * @returns string
549 */
550 private function fileLine( $file ) {
551 global $wgContLang, $wgTitle;
552
553 $target = $this->page->getPrefixedText();
554 $date = $wgContLang->timeanddate( $file->getTimestamp(), true );
555
556 $del = '';
557 # Hidden files...
558 if( $file->isDeleted(File::DELETED_FILE) ) {
559 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
560 if( !$file->userCan(File::DELETED_FILE) ) {
561 $pageLink = $date;
562 } else {
563 $pageLink = $this->skin->makeKnownLinkObj( $wgTitle, $date,
564 "target=$target&file=$file->sha1.".$file->getExtension() );
565 }
566 $pageLink = '<span class="history-deleted">' . $pageLink . '</span>';
567 # Regular files...
568 } else {
569 $url = $file->getUrlRel();
570 $pageLink = "<a href=\"{$url}\">{$date}</a>";
571 }
572
573 $data = wfMsgHtml( 'widthheight',
574 $wgContLang->formatNum( $file->getWidth() ),
575 $wgContLang->formatNum( $file->getHeight() ) ) .
576 ' (' . wfMsgHtml( 'nbytes', $wgContLang->formatNum( $file->getSize() ) ) . ')';
577
578 return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
579 }
580
581 /**
582 * @param ArchivedFile $file
583 * @returns string
584 */
585 private function archivedfileLine( $file ) {
586 global $wgContLang, $wgTitle;
587
588 $target = $this->page->getPrefixedText();
589 $date = $wgContLang->timeanddate( $file->getTimestamp(), true );
590
591 $undelete = SpecialPage::getTitleFor( 'Undelete' );
592 $pageLink = $this->skin->makeKnownLinkObj( $undelete, $date, "target=$target&file={$file->getKey()}" );
593
594 $del = '';
595 if( $file->isDeleted(File::DELETED_FILE) ) {
596 $del = ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
597 }
598
599 $data = wfMsgHtml( 'widthheight',
600 $wgContLang->formatNum( $file->getWidth() ),
601 $wgContLang->formatNum( $file->getHeight() ) ) .
602 ' (' . wfMsgHtml( 'nbytes', $wgContLang->formatNum( $file->getSize() ) ) . ')';
603
604 return "<li> $pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>";
605 }
606
607 /**
608 * @param Array $row row
609 * @returns string
610 */
611 private function logLine( $row ) {
612 global $wgContLang;
613
614 $date = $wgContLang->timeanddate( $row->log_timestamp );
615 $paramArray = LogPage::extractParams( $row->log_params );
616 $title = Title::makeTitle( $row->log_namespace, $row->log_title );
617
618 $logtitle = SpecialPage::getTitleFor( 'Log' );
619 $loglink = $this->skin->makeKnownLinkObj( $logtitle, wfMsgHtml( 'log' ),
620 wfArrayToCGI( array( 'page' => $title->getPrefixedUrl() ) ) );
621 // Action text
622 if( !LogPage::userCan($row,LogPage::DELETED_ACTION) ) {
623 $action = '<span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
624 } else {
625 $action = LogPage::actionText( $row->log_type, $row->log_action, $title,
626 $this->skin, $paramArray, true, true );
627 if( $row->log_deleted & LogPage::DELETED_ACTION )
628 $action = '<span class="history-deleted">' . $action . '</span>';
629 }
630 // User links
631 $userLink = $this->skin->userLink( $row->log_user, User::WhoIs($row->log_user) );
632 if( LogPage::isDeleted($row,LogPage::DELETED_USER) ) {
633 $userLink = '<span class="history-deleted">' . $userLink . '</span>';
634 }
635 // Comment
636 $comment = $wgContLang->getDirMark() . $this->skin->commentBlock( $row->log_comment );
637 if( LogPage::isDeleted($row,LogPage::DELETED_COMMENT) ) {
638 $comment = '<span class="history-deleted">' . $comment . '</span>';
639 }
640 return "<li>($loglink) $date $userLink $action $comment</li>";
641 }
642
643 /**
644 * Generate a user tool link cluster if the current user is allowed to view it
645 * @param ArchivedFile $file
646 * @return string HTML
647 */
648 private function fileUserTools( $file ) {
649 if( $file->userCan( Revision::DELETED_USER ) ) {
650 $link = $this->skin->userLink( $file->user, $file->user_text ) .
651 $this->skin->userToolLinks( $file->user, $file->user_text );
652 } else {
653 $link = wfMsgHtml( 'rev-deleted-user' );
654 }
655 if( $file->isDeleted( Revision::DELETED_USER ) ) {
656 return '<span class="history-deleted">' . $link . '</span>';
657 }
658 return $link;
659 }
660
661 /**
662 * Wrap and format the given file's comment block, if the current
663 * user is allowed to view it.
664 *
665 * @param ArchivedFile $file
666 * @return string HTML
667 */
668 private function fileComment( $file ) {
669 if( $file->userCan( File::DELETED_COMMENT ) ) {
670 $block = $this->skin->commentBlock( $file->description );
671 } else {
672 $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
673 }
674 if( $file->isDeleted( File::DELETED_COMMENT ) ) {
675 return "<span class=\"history-deleted\">$block</span>";
676 }
677 return $block;
678 }
679
680 /**
681 * @param WebRequest $request
682 */
683 function submit( $request ) {
684 $bitfield = $this->extractBitfield( $request );
685 $comment = $request->getText( 'wpReason' );
686
687 $this->target = $request->getText( 'target' );
688 $this->title = Title::newFromURL( $this->target );
689
690 if( $this->save( $bitfield, $comment, $this->title ) ) {
691 $this->success( $request );
692 } else if( $request->getCheck( 'oldid' ) || $request->getCheck( 'artimestamp' ) ) {
693 return $this->showRevs( $request );
694 } else if( $request->getCheck( 'logid' ) ) {
695 return $this->showLogs( $request );
696 } else if( $request->getCheck( 'oldimage' ) || $request->getCheck( 'fileid' ) ) {
697 return $this->showImages( $request );
698 }
699 }
700
701 private function success( $request ) {
702 global $wgOut;
703
704 $wgOut->setPagetitle( wfMsgHtml( 'actioncomplete' ) );
705
706 if( $this->deleteKey=='logid' ) {
707 $wgOut->addWikiText( Xml::element( 'span', array( 'class' => 'success' ), wfMsg( 'logdelete-success' ) ), false );
708 $this->showLogItems( $request );
709 } else if( $this->deleteKey=='oldid' || $this->deleteKey=='artimestamp' ) {
710 $wgOut->addWikiText( Xml::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
711 $this->showRevs( $request );
712 } else if( $this->deleteKey=='fileid' ) {
713 $wgOut->addWikiText( Xml::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
714 $this->showImages( $request );
715 } else if( $this->deleteKey=='oldimage' ) {
716 $this->showImages( $request );
717 }
718 }
719
720 /**
721 * Put together a rev_deleted bitfield from the submitted checkboxes
722 * @param WebRequest $request
723 * @return int
724 */
725 private function extractBitfield( $request ) {
726 $bitfield = 0;
727 foreach( $this->checks as $item ) {
728 list( /* message */ , $name, $field ) = $item;
729 if( $request->getCheck( $name ) ) {
730 $bitfield |= $field;
731 }
732 }
733 return $bitfield;
734 }
735
736 private function save( $bitfield, $reason, $title ) {
737 $dbw = wfGetDB( DB_MASTER );
738 // Don't allow simply locking the interface for no reason
739 if( $bitfield == Revision::DELETED_RESTRICTED ) {
740 $bitfield = 0;
741 }
742 $deleter = new RevisionDeleter( $dbw );
743 // By this point, only one of the below should be set
744 if( isset($this->revisions) ) {
745 return $deleter->setRevVisibility( $title, $this->revisions, $bitfield, $reason );
746 } else if( isset($this->archrevs) ) {
747 return $deleter->setArchiveVisibility( $title, $this->archrevs, $bitfield, $reason );
748 } else if( isset($this->ofiles) ) {
749 return $deleter->setOldImgVisibility( $title, $this->ofiles, $bitfield, $reason );
750 } else if( isset($this->afiles) ) {
751 return $deleter->setArchFileVisibility( $title, $this->afiles, $bitfield, $reason );
752 } else if( isset($this->events) ) {
753 return $deleter->setEventVisibility( $this->events, $bitfield, $reason );
754 }
755 }
756 }
757
758 /**
759 * Implements the actions for Revision Deletion.
760 * @addtogroup SpecialPage
761 */
762 class RevisionDeleter {
763 function __construct( $db ) {
764 $this->dbw = $db;
765 }
766
767 /**
768 * @param $title, the page these events apply to
769 * @param array $items list of revision ID numbers
770 * @param int $bitfield new rev_deleted value
771 * @param string $comment Comment for log records
772 */
773 function setRevVisibility( $title, $items, $bitfield, $comment ) {
774 global $wgOut;
775
776 $userAllowedAll = $success = true;
777 $revIDs = array();
778 $revCount = 0;
779 // Run through and pull all our data in one query
780 foreach( $items as $revid ) {
781 $where[] = intval($revid);
782 }
783 $whereClause = 'rev_id IN(' . implode(',',$where) . ')';
784 $result = $this->dbw->select( 'revision', '*',
785 array( 'rev_page' => $title->getArticleID(),
786 $whereClause ),
787 __METHOD__ );
788 while( $row = $this->dbw->fetchObject( $result ) ) {
789 $revObjs[$row->rev_id] = new Revision( $row );
790 }
791 // To work!
792 foreach( $items as $revid ) {
793 if( !isset($revObjs[$revid]) || $revObjs[$revid]->isCurrent() ) {
794 $success = false;
795 continue; // Must exist
796 } else if( !$revObjs[$revid]->userCan(Revision::DELETED_RESTRICTED) ) {
797 $userAllowedAll=false;
798 continue;
799 }
800 // For logging, maintain a count of revisions
801 if( $revObjs[$revid]->mDeleted != $bitfield ) {
802 $revCount++;
803 $revIDs[]=$revid;
804
805 $this->updateRevision( $revObjs[$revid], $bitfield );
806 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
807 }
808 }
809 // Clear caches...
810 // Don't log or touch if nothing changed
811 if( $revCount > 0 ) {
812 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted,
813 $comment, $title, 'oldid', $revIDs );
814 $this->updatePage( $title );
815 }
816 // Where all revs allowed to be set?
817 if( !$userAllowedAll ) {
818 //FIXME: still might be confusing???
819 $wgOut->permissionRequired( 'hiderevision' );
820 return false;
821 }
822
823 return $success;
824 }
825
826 /**
827 * @param $title, the page these events apply to
828 * @param array $items list of revision ID numbers
829 * @param int $bitfield new rev_deleted value
830 * @param string $comment Comment for log records
831 */
832 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
833 global $wgOut;
834
835 $userAllowedAll = $success = true;
836 $count = 0;
837 $Id_set = array();
838 // Run through and pull all our data in one query
839 foreach( $items as $timestamp ) {
840 $where[] = $this->dbw->addQuotes( $timestamp );
841 }
842 $whereClause = 'ar_timestamp IN(' . implode(',',$where) . ')';
843 $result = $this->dbw->select( 'archive', '*',
844 array( 'ar_namespace' => $title->getNamespace(),
845 'ar_title' => $title->getDBKey(),
846 $whereClause ),
847 __METHOD__ );
848 while( $row = $this->dbw->fetchObject( $result ) ) {
849 $revObjs[$row->ar_timestamp] = new Revision( array(
850 'page' => $title->getArticleId(),
851 'id' => $row->ar_rev_id,
852 'text' => $row->ar_text_id,
853 'comment' => $row->ar_comment,
854 'user' => $row->ar_user,
855 'user_text' => $row->ar_user_text,
856 'timestamp' => $row->ar_timestamp,
857 'minor_edit' => $row->ar_minor_edit,
858 'text_id' => $row->ar_text_id,
859 'deleted' => $row->ar_deleted,
860 'len' => $row->ar_len) );
861 }
862 // To work!
863 foreach( $items as $timestamp ) {
864 // This will only select the first revision with this timestamp.
865 // Since they are all selected/deleted at once, we can just check the
866 // permissions of one. UPDATE is done via timestamp, so all revs are set.
867 if( !is_object($revObjs[$timestamp]) ) {
868 $success = false;
869 continue; // Must exist
870 } else if( !$revObjs[$timestamp]->userCan(Revision::DELETED_RESTRICTED) ) {
871 $userAllowedAll=false;
872 continue;
873 }
874 // Which revisions did we change anything about?
875 if( $revObjs[$timestamp]->mDeleted != $bitfield ) {
876 $Id_set[]=$timestamp;
877 $count++;
878
879 $this->updateArchive( $revObjs[$timestamp], $bitfield );
880 }
881 }
882 // For logging, maintain a count of revisions
883 if( $count > 0 ) {
884 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted,
885 $comment, $title, 'artimestamp', $Id_set );
886 }
887 // Where all revs allowed to be set?
888 if( !$userAllowedAll ) {
889 $wgOut->permissionRequired( 'hiderevision' );
890 return false;
891 }
892
893 return $success;
894 }
895
896 /**
897 * @param $title, the page these events apply to
898 * @param array $items list of revision ID numbers
899 * @param int $bitfield new rev_deleted value
900 * @param string $comment Comment for log records
901 */
902 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
903 global $wgOut;
904
905 $userAllowedAll = $success = true;
906 $count = 0;
907 $set = array();
908 // Run through and pull all our data in one query
909 foreach( $items as $timestamp ) {
910 $where[] = $this->dbw->addQuotes( $timestamp.'!'.$title->getDbKey() );
911 }
912 $whereClause = 'oi_archive_name IN(' . implode(',',$where) . ')';
913 $result = $this->dbw->select( 'oldimage', '*',
914 array( 'oi_name' => $title->getDbKey(),
915 $whereClause ),
916 __METHOD__ );
917 while( $row = $this->dbw->fetchObject( $result ) ) {
918 $filesObjs[$row->oi_archive_name] = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
919 $filesObjs[$row->oi_archive_name]->user = $row->oi_user;
920 $filesObjs[$row->oi_archive_name]->user_text = $row->oi_user_text;
921 }
922 // To work!
923 foreach( $items as $timestamp ) {
924 $archivename = $timestamp.'!'.$title->getDbKey();
925 if( !isset($filesObjs[$archivename]) ) {
926 $success = false;
927 continue; // Must exist
928 } else if( !$filesObjs[$archivename]->userCan(File::DELETED_RESTRICTED) ) {
929 $userAllowedAll=false;
930 continue;
931 }
932
933 $transaction = true;
934 // Which revisions did we change anything about?
935 if( $filesObjs[$archivename]->deleted != $bitfield ) {
936 $count++;
937
938 $this->dbw->begin();
939 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
940 // If this image is currently hidden...
941 if( $filesObjs[$archivename]->deleted & File::DELETED_FILE ) {
942 if( $bitfield & File::DELETED_FILE ) {
943 # Leave it alone if we are not changing this...
944 $set[]=$archivename;
945 $transaction = true;
946 } else {
947 # We are moving this out
948 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
949 $set[]=$transaction;
950 }
951 // Is it just now becoming hidden?
952 } else if( $bitfield & File::DELETED_FILE ) {
953 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
954 $set[]=$transaction;
955 } else {
956 $set[]=$timestamp;
957 }
958 // If our file operations fail, then revert back the db
959 if( $transaction==false ) {
960 $this->dbw->rollback();
961 return false;
962 }
963 $this->dbw->commit();
964 }
965 }
966
967 // Log if something was changed
968 if( $count > 0 ) {
969 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted,
970 $comment, $title, 'oldimage', $set );
971 # Purge page/history
972 $file = wfLocalFile( $title );
973 $file->purgeCache();
974 $file->purgeHistory();
975 # Invalidate cache for all pages using this file
976 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
977 $update->doUpdate();
978 }
979 // Where all revs allowed to be set?
980 if( !$userAllowedAll ) {
981 $wgOut->permissionRequired( 'hiderevision' );
982 return false;
983 }
984
985 return $success;
986 }
987
988 /**
989 * @param $title, the page these events apply to
990 * @param array $items list of revision ID numbers
991 * @param int $bitfield new rev_deleted value
992 * @param string $comment Comment for log records
993 */
994 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
995 global $wgOut;
996
997 $userAllowedAll = $success = true;
998 $count = 0;
999 $Id_set = array();
1000
1001 // Run through and pull all our data in one query
1002 foreach( $items as $id ) {
1003 $where[] = intval($id);
1004 }
1005 $whereClause = 'fa_id IN(' . implode(',',$where) . ')';
1006 $result = $this->dbw->select( 'filearchive', '*',
1007 array( 'fa_name' => $title->getDbKey(),
1008 $whereClause ),
1009 __METHOD__ );
1010 while( $row = $this->dbw->fetchObject( $result ) ) {
1011 $filesObjs[$row->fa_id] = ArchivedFile::newFromRow( $row );
1012 }
1013 // To work!
1014 foreach( $items as $fileid ) {
1015 if( !isset($filesObjs[$fileid]) ) {
1016 $success = false;
1017 continue; // Must exist
1018 } else if( !$filesObjs[$fileid]->userCan(File::DELETED_RESTRICTED) ) {
1019 $userAllowedAll=false;
1020 continue;
1021 }
1022 // Which revisions did we change anything about?
1023 if( $filesObjs[$fileid]->deleted != $bitfield ) {
1024 $Id_set[]=$fileid;
1025 $count++;
1026
1027 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1028 }
1029 }
1030 // Log if something was changed
1031 if( $count > 0 ) {
1032 $this->updateLog( $title, $count, $bitfield, $comment,
1033 $filesObjs[$fileid]->deleted, $title, 'fileid', $Id_set );
1034 }
1035 // Where all revs allowed to be set?
1036 if( !$userAllowedAll ) {
1037 $wgOut->permissionRequired( 'hiderevision' );
1038 return false;
1039 }
1040
1041 return $success;
1042 }
1043
1044 /**
1045 * @param array $items list of log ID numbers
1046 * @param int $bitfield new log_deleted value
1047 * @param string $comment Comment for log records
1048 */
1049 function setEventVisibility( $items, $bitfield, $comment ) {
1050 global $wgOut;
1051
1052 $userAllowedAll = $success = true;
1053 $logs_count = array();
1054 $logs_Ids = array();
1055
1056 // Run through and pull all our data in one query
1057 foreach( $items as $logid ) {
1058 $where[] = intval($logid);
1059 }
1060 $whereClause = 'log_id IN(' . implode(',',$where) . ')';
1061 $result = $this->dbw->select( 'logging', '*',
1062 array( $whereClause ),
1063 __METHOD__ );
1064 while( $row = $this->dbw->fetchObject( $result ) ) {
1065 $logRows[$row->log_id] = $row;
1066 }
1067 // To work!
1068 foreach( $items as $logid ) {
1069 if( !isset($logRows[$logid]) ) {
1070 $success = false;
1071 continue; // Must exist
1072 } else if( !LogPage::userCan($logRows[$logid], Revision::DELETED_RESTRICTED)
1073 || $logRows[$logid]->log_type=='oversight' ) {
1074 // Don't hide from oversight log!!!
1075 $userAllowedAll=false;
1076 continue;
1077 }
1078 $logtype = $logRows[$logid]->log_type;
1079 // For logging, maintain a count of events per log type
1080 if( !isset( $logs_count[$logtype] ) ) {
1081 $logs_count[$logtype]=0;
1082 $logs_Ids[$logtype]=array();
1083 }
1084 // Which logs did we change anything about?
1085 if( $logRows[$logid]->log_deleted != $bitfield ) {
1086 $logs_Ids[$logtype][]=$logid;
1087 $logs_count[$logtype]++;
1088
1089 $this->updateLogs( $logRows[$logid], $bitfield );
1090 $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
1091 }
1092 }
1093 foreach( $logs_count as $logtype => $count ) {
1094 // Don't log or touch if nothing changed
1095 if( $count > 0 ) {
1096 $target = SpecialPage::getTitleFor( 'Log', $logtype );
1097 $this->updateLog( $target, $count, $bitfield, $logRows[$logid]->log_deleted,
1098 $comment, $target, 'logid', $logs_Ids[$logtype] );
1099 }
1100 }
1101 // Where all revs allowed to be set?
1102 if( !$userAllowedAll ) {
1103 $wgOut->permissionRequired( 'hiderevision' );
1104 return false;
1105 }
1106
1107 return $success;
1108 }
1109
1110 /**
1111 * Moves an image to a safe private location
1112 * Caller is responsible for clearing caches
1113 * @param File $oimage
1114 * @returns mixed, timestamp string on success, false on failure
1115 */
1116 function makeOldImagePrivate( $oimage ) {
1117 global $wgFileStore, $wgUseSquid;
1118
1119 $transaction = new FSTransaction();
1120 if( !FileStore::lock() ) {
1121 wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" );
1122 return false;
1123 }
1124 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR . $oimage->archive_name;
1125 // Dupe the file into the file store
1126 if( file_exists( $oldpath ) ) {
1127 // Is our directory configured?
1128 if( $store = FileStore::get( 'deleted' ) ) {
1129 if( !$oimage->sha1 ) {
1130 $oimage->upgradeRow(); // sha1 may be missing
1131 }
1132 $key = $oimage->sha1 . '.' . $oimage->getExtension();
1133 $transaction->add( $store->insert( $key, $oldpath, FileStore::DELETE_ORIGINAL ) );
1134 } else {
1135 $group = null;
1136 $key = null;
1137 $transaction = false; // Return an error and do nothing
1138 }
1139 } else {
1140 wfDebug( __METHOD__." deleting already-missing '$oldpath'; moving on to database\n" );
1141 $group = null;
1142 $key = '';
1143 $transaction = new FSTransaction(); // empty
1144 }
1145
1146 if( $transaction === false ) {
1147 // Fail to restore?
1148 wfDebug( __METHOD__.": import to file store failed, aborting\n" );
1149 throw new MWException( "Could not archive and delete file $oldpath" );
1150 return false;
1151 }
1152
1153 wfDebug( __METHOD__.": set db items, applying file transactions\n" );
1154 $transaction->commit();
1155 FileStore::unlock();
1156
1157 $m = explode('!',$oimage->archive_name,2);
1158 $timestamp = $m[0];
1159
1160 return $timestamp;
1161 }
1162
1163 /**
1164 * Moves an image from a safe private location
1165 * Caller is responsible for clearing caches
1166 * @param File $oimage
1167 * @returns mixed, string timestamp on success, false on failure
1168 */
1169 function makeOldImagePublic( $oimage ) {
1170 global $wgFileStore;
1171
1172 $transaction = new FSTransaction();
1173 if( !FileStore::lock() ) {
1174 wfDebug( __METHOD__." could not acquire filestore lock\n" );
1175 return false;
1176 }
1177
1178 $store = FileStore::get( 'deleted' );
1179 if( !$store ) {
1180 wfDebug( __METHOD__.": skipping row with no file.\n" );
1181 return false;
1182 }
1183
1184 $key = $oimage->sha1.'.'.$oimage->getExtension();
1185 $destDir = $oimage->getArchivePath();
1186 if( !is_dir( $destDir ) ) {
1187 wfMkdirParents( $destDir );
1188 }
1189 $destPath = $destDir . DIRECTORY_SEPARATOR . $oimage->archive_name;
1190 // Check if any other stored revisions use this file;
1191 // if so, we shouldn't remove the file from the hidden
1192 // archives so they will still work. Check hidden files first.
1193 $useCount = $this->dbw->selectField( 'oldimage', '1',
1194 array( 'oi_sha1' => $oimage->sha1,
1195 'oi_deleted & '.File::DELETED_FILE => File::DELETED_FILE ),
1196 __METHOD__, array( 'FOR UPDATE' ) );
1197 // Check the rest of the deleted archives too.
1198 // (these are the ones that don't show in the image history)
1199 if( !$useCount ) {
1200 $useCount = $this->dbw->selectField( 'filearchive', '1',
1201 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1202 __METHOD__, array( 'FOR UPDATE' ) );
1203 }
1204
1205 if( $useCount == 0 ) {
1206 wfDebug( __METHOD__.": nothing else using {$oimage->sha1}, will deleting after\n" );
1207 $flags = FileStore::DELETE_ORIGINAL;
1208 } else {
1209 $flags = 0;
1210 }
1211 $transaction->add( $store->export( $key, $destPath, $flags ) );
1212
1213 wfDebug( __METHOD__.": set db items, applying file transactions\n" );
1214 $transaction->commit();
1215 FileStore::unlock();
1216
1217 $m = explode('!',$oimage->archive_name,2);
1218 $timestamp = $m[0];
1219
1220 return $timestamp;
1221 }
1222
1223 /**
1224 * Update the revision's rev_deleted field
1225 * @param Revision $rev
1226 * @param int $bitfield new rev_deleted bitfield value
1227 */
1228 function updateRevision( $rev, $bitfield ) {
1229 $this->dbw->update( 'revision',
1230 array( 'rev_deleted' => $bitfield ),
1231 array( 'rev_id' => $rev->getId() ),
1232 __METHOD__ );
1233 }
1234
1235 /**
1236 * Update the revision's rev_deleted field
1237 * @param Revision $rev
1238 * @param int $bitfield new rev_deleted bitfield value
1239 */
1240 function updateArchive( $rev, $bitfield ) {
1241 $this->dbw->update( 'archive',
1242 array( 'ar_deleted' => $bitfield ),
1243 array( 'ar_rev_id' => $rev->getId() ),
1244 __METHOD__ );
1245 }
1246
1247 /**
1248 * Update the images's oi_deleted field
1249 * @param File $oimage
1250 * @param int $bitfield new rev_deleted bitfield value
1251 */
1252 function updateOldFiles( $oimage, $bitfield ) {
1253 $this->dbw->update( 'oldimage',
1254 array( 'oi_deleted' => $bitfield ),
1255 array( 'oi_archive_name' => $oimage->archive_name ),
1256 __METHOD__ );
1257 }
1258
1259 /**
1260 * Update the images's fa_deleted field
1261 * @param ArchivedFile $file
1262 * @param int $bitfield new rev_deleted bitfield value
1263 */
1264 function updateArchFiles( $file, $bitfield ) {
1265 $this->dbw->update( 'filearchive',
1266 array( 'fa_deleted' => $bitfield ),
1267 array( 'fa_id' => $file->getID() ),
1268 __METHOD__ );
1269 }
1270
1271 /**
1272 * Update the logging log_deleted field
1273 * @param Row $row
1274 * @param int $bitfield new rev_deleted bitfield value
1275 */
1276 function updateLogs( $row, $bitfield ) {
1277 $this->dbw->update( 'logging',
1278 array( 'log_deleted' => $bitfield ),
1279 array( 'log_id' => $row->log_id ),
1280 __METHOD__ );
1281 }
1282
1283 /**
1284 * Update the revision's recentchanges record if fields have been hidden
1285 * @param Revision $rev
1286 * @param int $bitfield new rev_deleted bitfield value
1287 */
1288 function updateRecentChangesEdits( $rev, $bitfield ) {
1289 $this->dbw->update( 'recentchanges',
1290 array( 'rc_deleted' => $bitfield,
1291 'rc_patrolled' => 1 ),
1292 array( 'rc_this_oldid' => $rev->getId() ),
1293 __METHOD__ );
1294 }
1295
1296 /**
1297 * Update the revision's recentchanges record if fields have been hidden
1298 * @param Row $row
1299 * @param int $bitfield new rev_deleted bitfield value
1300 */
1301 function updateRecentChangesLog( $row, $bitfield ) {
1302 $this->dbw->update( 'recentchanges',
1303 array( 'rc_deleted' => $bitfield,
1304 'rc_patrolled' => 1 ),
1305 array( 'rc_logid' => $row->log_id ),
1306 __METHOD__ );
1307 }
1308
1309 /**
1310 * Touch the page's cache invalidation timestamp; this forces cached
1311 * history views to refresh, so any newly hidden or shown fields will
1312 * update properly.
1313 * @param Title $title
1314 */
1315 function updatePage( $title ) {
1316 $title->invalidateCache();
1317 $title->purgeSquid();
1318
1319 // Extensions that require referencing previous revisions may need this
1320 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1321 }
1322
1323 /**
1324 * Record a log entry on the action
1325 * @param Title $title, page where item was removed from
1326 * @param int $count the number of revisions altered for this page
1327 * @param int $nbitfield the new _deleted value
1328 * @param int $obitfield the old _deleted value
1329 * @param string $comment
1330 * @param Title $target, the relevant page
1331 * @param string $param, URL param
1332 * @param Array $items
1333 */
1334 function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target, $param, $items = array() ) {
1335 // Put things hidden from sysops in the oversight log
1336 $logtype = ( ($nbitfield | $obitfield) & Revision::DELETED_RESTRICTED ) ? 'oversight' : 'delete';
1337 $log = new LogPage( $logtype );
1338 // FIXME: do this better
1339 if( $param=='logid' ) {
1340 $params = array( implode( ',', $items) );
1341 $reason = wfMsgExt('logdelete-logaction', array('parsemag'), $count, $nbitfield );
1342 if($comment) $reason .= ": $comment";
1343 $log->addEntry( 'event', $title, $reason, $params );
1344 } else {
1345 // Add params for effected page and ids
1346 $params = array( $target->getPrefixedText(), $param, implode( ',', $items) );
1347 $reason = wfMsgExt('revdelete-logaction', array('parsemag'), $count, $nbitfield );
1348 if($comment) $reason .= ": $comment";
1349 $log->addEntry( 'revision', $title, $reason, $params );
1350 }
1351 }
1352 }