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