* Trackback display formatting fixed
[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 if( $this->deleteKey=='logid' ) {
697 $wgOut->addWikiText( Xml::element( 'span', array( 'class' => 'success' ), wfMsg( 'logdelete-success' ) ), false );
698 $this->showLogItems( $request );
699 } else if( $this->deleteKey=='oldid' || $this->deleteKey=='artimestamp' ) {
700 $wgOut->addWikiText( Xml::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
701 $this->showRevs( $request );
702 } else if( $this->deleteKey=='fileid' ) {
703 $wgOut->addWikiText( Xml::element( 'span', array( 'class' => 'success' ), wfMsg( 'revdelete-success' ) ), false );
704 $this->showImages( $request );
705 } else if( $this->deleteKey=='oldimage' ) {
706 $this->showImages( $request );
707 }
708 }
709
710 /**
711 * Put together a rev_deleted bitfield from the submitted checkboxes
712 * @param WebRequest $request
713 * @return int
714 */
715 private function extractBitfield( $request ) {
716 $bitfield = 0;
717 foreach( $this->checks as $item ) {
718 list( /* message */ , $name, $field ) = $item;
719 if( $request->getCheck( $name ) ) {
720 $bitfield |= $field;
721 }
722 }
723 return $bitfield;
724 }
725
726 private function save( $bitfield, $reason, $title ) {
727 $dbw = wfGetDB( DB_MASTER );
728 // Don't allow simply locking the interface for no reason
729 if( $bitfield == Revision::DELETED_RESTRICTED ) {
730 $bitfield = 0;
731 }
732 $deleter = new RevisionDeleter( $dbw );
733 // By this point, only one of the below should be set
734 if( isset($this->revisions) ) {
735 return $deleter->setRevVisibility( $title, $this->revisions, $bitfield, $reason );
736 } else if( isset($this->archrevs) ) {
737 return $deleter->setArchiveVisibility( $title, $this->archrevs, $bitfield, $reason );
738 } else if( isset($this->ofiles) ) {
739 return $deleter->setOldImgVisibility( $title, $this->ofiles, $bitfield, $reason );
740 } else if( isset($this->afiles) ) {
741 return $deleter->setArchFileVisibility( $title, $this->afiles, $bitfield, $reason );
742 } else if( isset($this->events) ) {
743 return $deleter->setEventVisibility( $this->events, $bitfield, $reason );
744 }
745 }
746 }
747
748 /**
749 * Implements the actions for Revision Deletion.
750 * @addtogroup SpecialPage
751 */
752 class RevisionDeleter {
753 function __construct( $db ) {
754 $this->dbw = $db;
755 }
756
757 /**
758 * @param $title, the page these events apply to
759 * @param array $items list of revision ID numbers
760 * @param int $bitfield new rev_deleted value
761 * @param string $comment Comment for log records
762 */
763 function setRevVisibility( $title, $items, $bitfield, $comment ) {
764 global $wgOut;
765
766 $userAllowedAll = $success = true;
767 $revIDs = array();
768 $revCount = 0;
769 // Run through and pull all our data in one query
770 foreach( $items as $revid ) {
771 $where[] = intval($revid);
772 }
773 $whereClause = 'rev_id IN(' . implode(',',$where) . ')';
774 $result = $this->dbw->select( 'revision', '*',
775 array( 'rev_page' => $title->getArticleID(),
776 $whereClause ),
777 __METHOD__ );
778 while( $row = $this->dbw->fetchObject( $result ) ) {
779 $revObjs[$row->rev_id] = new Revision( $row );
780 }
781 // To work!
782 foreach( $items as $revid ) {
783 if( !isset($revObjs[$revid]) || $revObjs[$revid]->isCurrent() ) {
784 $success = false;
785 continue; // Must exist
786 } else if( !$revObjs[$revid]->userCan(Revision::DELETED_RESTRICTED) ) {
787 $userAllowedAll=false;
788 continue;
789 }
790 // For logging, maintain a count of revisions
791 if( $revObjs[$revid]->mDeleted != $bitfield ) {
792 $revCount++;
793 $revIDs[]=$revid;
794
795 $this->updateRevision( $revObjs[$revid], $bitfield );
796 $this->updateRecentChangesEdits( $revObjs[$revid], $bitfield, false );
797 }
798 }
799 // Clear caches...
800 // Don't log or touch if nothing changed
801 if( $revCount > 0 ) {
802 $this->updateLog( $title, $revCount, $bitfield, $revObjs[$revid]->mDeleted,
803 $comment, $title, 'oldid', $revIDs );
804 $this->updatePage( $title );
805 }
806 // Where all revs allowed to be set?
807 if( !$userAllowedAll ) {
808 //FIXME: still might be confusing???
809 $wgOut->permissionRequired( 'hiderevision' );
810 return false;
811 }
812
813 return $success;
814 }
815
816 /**
817 * @param $title, the page these events apply to
818 * @param array $items list of revision ID numbers
819 * @param int $bitfield new rev_deleted value
820 * @param string $comment Comment for log records
821 */
822 function setArchiveVisibility( $title, $items, $bitfield, $comment ) {
823 global $wgOut;
824
825 $userAllowedAll = $success = true;
826 $count = 0;
827 $Id_set = array();
828 // Run through and pull all our data in one query
829 foreach( $items as $timestamp ) {
830 $where[] = $this->dbw->addQuotes( $timestamp );
831 }
832 $whereClause = 'ar_timestamp IN(' . implode(',',$where) . ')';
833 $result = $this->dbw->select( 'archive', '*',
834 array( 'ar_namespace' => $title->getNamespace(),
835 'ar_title' => $title->getDBKey(),
836 $whereClause ),
837 __METHOD__ );
838 while( $row = $this->dbw->fetchObject( $result ) ) {
839 $revObjs[$row->ar_timestamp] = new Revision( array(
840 'page' => $title->getArticleId(),
841 'id' => $row->ar_rev_id,
842 'text' => $row->ar_text_id,
843 'comment' => $row->ar_comment,
844 'user' => $row->ar_user,
845 'user_text' => $row->ar_user_text,
846 'timestamp' => $row->ar_timestamp,
847 'minor_edit' => $row->ar_minor_edit,
848 'text_id' => $row->ar_text_id,
849 'deleted' => $row->ar_deleted,
850 'len' => $row->ar_len) );
851 }
852 // To work!
853 foreach( $items as $timestamp ) {
854 // This will only select the first revision with this timestamp.
855 // Since they are all selected/deleted at once, we can just check the
856 // permissions of one. UPDATE is done via timestamp, so all revs are set.
857 if( !is_object($revObjs[$timestamp]) ) {
858 $success = false;
859 continue; // Must exist
860 } else if( !$revObjs[$timestamp]->userCan(Revision::DELETED_RESTRICTED) ) {
861 $userAllowedAll=false;
862 continue;
863 }
864 // Which revisions did we change anything about?
865 if( $revObjs[$timestamp]->mDeleted != $bitfield ) {
866 $Id_set[]=$timestamp;
867 $count++;
868
869 $this->updateArchive( $revObjs[$timestamp], $bitfield );
870 }
871 }
872 // For logging, maintain a count of revisions
873 if( $count > 0 ) {
874 $this->updateLog( $title, $count, $bitfield, $revObjs[$timestamp]->mDeleted,
875 $comment, $title, 'artimestamp', $Id_set );
876 }
877 // Where all revs allowed to be set?
878 if( !$userAllowedAll ) {
879 $wgOut->permissionRequired( 'hiderevision' );
880 return false;
881 }
882
883 return $success;
884 }
885
886 /**
887 * @param $title, the page these events apply to
888 * @param array $items list of revision ID numbers
889 * @param int $bitfield new rev_deleted value
890 * @param string $comment Comment for log records
891 */
892 function setOldImgVisibility( $title, $items, $bitfield, $comment ) {
893 global $wgOut;
894
895 $userAllowedAll = $success = true;
896 $count = 0;
897 $set = array();
898 // Run through and pull all our data in one query
899 foreach( $items as $timestamp ) {
900 $where[] = $this->dbw->addQuotes( $timestamp.'!'.$title->getDbKey() );
901 }
902 $whereClause = 'oi_archive_name IN(' . implode(',',$where) . ')';
903 $result = $this->dbw->select( 'oldimage', '*',
904 array( 'oi_name' => $title->getDbKey(),
905 $whereClause ),
906 __METHOD__ );
907 while( $row = $this->dbw->fetchObject( $result ) ) {
908 $filesObjs[$row->oi_archive_name] = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
909 $filesObjs[$row->oi_archive_name]->user = $row->oi_user;
910 $filesObjs[$row->oi_archive_name]->user_text = $row->oi_user_text;
911 }
912 // To work!
913 foreach( $items as $timestamp ) {
914 $archivename = $timestamp.'!'.$title->getDbKey();
915 if( !isset($filesObjs[$archivename]) ) {
916 $success = false;
917 continue; // Must exist
918 } else if( !$filesObjs[$archivename]->userCan(File::DELETED_RESTRICTED) ) {
919 $userAllowedAll=false;
920 continue;
921 }
922
923 $transaction = true;
924 // Which revisions did we change anything about?
925 if( $filesObjs[$archivename]->deleted != $bitfield ) {
926 $count++;
927
928 $this->dbw->begin();
929 $this->updateOldFiles( $filesObjs[$archivename], $bitfield );
930 // If this image is currently hidden...
931 if( $filesObjs[$archivename]->deleted & File::DELETED_FILE ) {
932 if( $bitfield & File::DELETED_FILE ) {
933 # Leave it alone if we are not changing this...
934 $set[]=$archivename;
935 $transaction = true;
936 } else {
937 # We are moving this out
938 $transaction = $this->makeOldImagePublic( $filesObjs[$archivename] );
939 $set[]=$transaction;
940 }
941 // Is it just now becoming hidden?
942 } else if( $bitfield & File::DELETED_FILE ) {
943 $transaction = $this->makeOldImagePrivate( $filesObjs[$archivename] );
944 $set[]=$transaction;
945 } else {
946 $set[]=$timestamp;
947 }
948 // If our file operations fail, then revert back the db
949 if( $transaction==false ) {
950 $this->dbw->rollback();
951 return false;
952 }
953 $this->dbw->commit();
954 }
955 }
956
957 // Log if something was changed
958 if( $count > 0 ) {
959 $this->updateLog( $title, $count, $bitfield, $filesObjs[$archivename]->deleted,
960 $comment, $title, 'oldimage', $set );
961 # Purge page/history
962 $file = wfLocalFile( $title );
963 $file->purgeCache();
964 $file->purgeHistory();
965 # Invalidate cache for all pages using this file
966 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
967 $update->doUpdate();
968 }
969 // Where all revs allowed to be set?
970 if( !$userAllowedAll ) {
971 $wgOut->permissionRequired( 'hiderevision' );
972 return false;
973 }
974
975 return $success;
976 }
977
978 /**
979 * @param $title, the page these events apply to
980 * @param array $items list of revision ID numbers
981 * @param int $bitfield new rev_deleted value
982 * @param string $comment Comment for log records
983 */
984 function setArchFileVisibility( $title, $items, $bitfield, $comment ) {
985 global $wgOut;
986
987 $userAllowedAll = $success = true;
988 $count = 0;
989 $Id_set = array();
990
991 // Run through and pull all our data in one query
992 foreach( $items as $id ) {
993 $where[] = intval($id);
994 }
995 $whereClause = 'fa_id IN(' . implode(',',$where) . ')';
996 $result = $this->dbw->select( 'filearchive', '*',
997 array( 'fa_name' => $title->getDbKey(),
998 $whereClause ),
999 __METHOD__ );
1000 while( $row = $this->dbw->fetchObject( $result ) ) {
1001 $filesObjs[$row->fa_id] = ArchivedFile::newFromRow( $row );
1002 }
1003 // To work!
1004 foreach( $items as $fileid ) {
1005 if( !isset($filesObjs[$fileid]) ) {
1006 $success = false;
1007 continue; // Must exist
1008 } else if( !$filesObjs[$fileid]->userCan(File::DELETED_RESTRICTED) ) {
1009 $userAllowedAll=false;
1010 continue;
1011 }
1012 // Which revisions did we change anything about?
1013 if( $filesObjs[$fileid]->deleted != $bitfield ) {
1014 $Id_set[]=$fileid;
1015 $count++;
1016
1017 $this->updateArchFiles( $filesObjs[$fileid], $bitfield );
1018 }
1019 }
1020 // Log if something was changed
1021 if( $count > 0 ) {
1022 $this->updateLog( $title, $count, $bitfield, $comment,
1023 $filesObjs[$fileid]->deleted, $title, 'fileid', $Id_set );
1024 }
1025 // Where all revs allowed to be set?
1026 if( !$userAllowedAll ) {
1027 $wgOut->permissionRequired( 'hiderevision' );
1028 return false;
1029 }
1030
1031 return $success;
1032 }
1033
1034 /**
1035 * @param array $items list of log ID numbers
1036 * @param int $bitfield new log_deleted value
1037 * @param string $comment Comment for log records
1038 */
1039 function setEventVisibility( $items, $bitfield, $comment ) {
1040 global $wgOut;
1041
1042 $userAllowedAll = $success = true;
1043 $logs_count = array();
1044 $logs_Ids = array();
1045
1046 // Run through and pull all our data in one query
1047 foreach( $items as $logid ) {
1048 $where[] = intval($logid);
1049 }
1050 $whereClause = 'log_id IN(' . implode(',',$where) . ')';
1051 $result = $this->dbw->select( 'logging', '*',
1052 array( $whereClause ),
1053 __METHOD__ );
1054 while( $row = $this->dbw->fetchObject( $result ) ) {
1055 $logRows[$row->log_id] = $row;
1056 }
1057 // To work!
1058 foreach( $items as $logid ) {
1059 if( !isset($logRows[$logid]) ) {
1060 $success = false;
1061 continue; // Must exist
1062 } else if( !LogPage::userCan($logRows[$logid], Revision::DELETED_RESTRICTED)
1063 || $logRows[$logid]->log_type=='oversight' ) {
1064 // Don't hide from oversight log!!!
1065 $userAllowedAll=false;
1066 continue;
1067 }
1068 $logtype = $logRows[$logid]->log_type;
1069 // For logging, maintain a count of events per log type
1070 if( !isset( $logs_count[$logtype] ) ) {
1071 $logs_count[$logtype]=0;
1072 $logs_Ids[$logtype]=array();
1073 }
1074 // Which logs did we change anything about?
1075 if( $logRows[$logid]->log_deleted != $bitfield ) {
1076 $logs_Ids[$logtype][]=$logid;
1077 $logs_count[$logtype]++;
1078
1079 $this->updateLogs( $logRows[$logid], $bitfield );
1080 $this->updateRecentChangesLog( $logRows[$logid], $bitfield, true );
1081 }
1082 }
1083 foreach( $logs_count as $logtype => $count ) {
1084 // Don't log or touch if nothing changed
1085 if( $count > 0 ) {
1086 $target = SpecialPage::getTitleFor( 'Log', $logtype );
1087 $this->updateLog( $target, $count, $bitfield, $logRows[$logid]->log_deleted,
1088 $comment, $target, 'logid', $logs_Ids[$logtype] );
1089 }
1090 }
1091 // Where all revs allowed to be set?
1092 if( !$userAllowedAll ) {
1093 $wgOut->permissionRequired( 'hiderevision' );
1094 return false;
1095 }
1096
1097 return $success;
1098 }
1099
1100 /**
1101 * Moves an image to a safe private location
1102 * Caller is responsible for clearing caches
1103 * @param File $oimage
1104 * @returns mixed, timestamp string on success, false on failure
1105 */
1106 function makeOldImagePrivate( $oimage ) {
1107 global $wgFileStore, $wgUseSquid;
1108
1109 $transaction = new FSTransaction();
1110 if( !FileStore::lock() ) {
1111 wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" );
1112 return false;
1113 }
1114 $oldpath = $oimage->getArchivePath() . DIRECTORY_SEPARATOR . $oimage->archive_name;
1115 // Dupe the file into the file store
1116 if( file_exists( $oldpath ) ) {
1117 // Is our directory configured?
1118 if( $store = FileStore::get( 'deleted' ) ) {
1119 if( !$oimage->sha1 ) {
1120 $oimage->upgradeRow(); // sha1 may be missing
1121 }
1122 $key = $oimage->sha1 . '.' . $oimage->getExtension();
1123 $transaction->add( $store->insert( $key, $oldpath, FileStore::DELETE_ORIGINAL ) );
1124 } else {
1125 $group = null;
1126 $key = null;
1127 $transaction = false; // Return an error and do nothing
1128 }
1129 } else {
1130 wfDebug( __METHOD__." deleting already-missing '$oldpath'; moving on to database\n" );
1131 $group = null;
1132 $key = '';
1133 $transaction = new FSTransaction(); // empty
1134 }
1135
1136 if( $transaction === false ) {
1137 // Fail to restore?
1138 wfDebug( __METHOD__.": import to file store failed, aborting\n" );
1139 throw new MWException( "Could not archive and delete file $oldpath" );
1140 return false;
1141 }
1142
1143 wfDebug( __METHOD__.": set db items, applying file transactions\n" );
1144 $transaction->commit();
1145 FileStore::unlock();
1146
1147 $m = explode('!',$oimage->archive_name,2);
1148 $timestamp = $m[0];
1149
1150 return $timestamp;
1151 }
1152
1153 /**
1154 * Moves an image from a safe private location
1155 * Caller is responsible for clearing caches
1156 * @param File $oimage
1157 * @returns mixed, string timestamp on success, false on failure
1158 */
1159 function makeOldImagePublic( $oimage ) {
1160 global $wgFileStore;
1161
1162 $transaction = new FSTransaction();
1163 if( !FileStore::lock() ) {
1164 wfDebug( __METHOD__." could not acquire filestore lock\n" );
1165 return false;
1166 }
1167
1168 $store = FileStore::get( 'deleted' );
1169 if( !$store ) {
1170 wfDebug( __METHOD__.": skipping row with no file.\n" );
1171 return false;
1172 }
1173
1174 $key = $oimage->sha1.'.'.$oimage->getExtension();
1175 $destDir = $oimage->getArchivePath();
1176 if( !is_dir( $destDir ) ) {
1177 wfMkdirParents( $destDir );
1178 }
1179 $destPath = $destDir . DIRECTORY_SEPARATOR . $oimage->archive_name;
1180 // Check if any other stored revisions use this file;
1181 // if so, we shouldn't remove the file from the hidden
1182 // archives so they will still work. Check hidden files first.
1183 $useCount = $this->dbw->selectField( 'oldimage', '1',
1184 array( 'oi_sha1' => $oimage->sha1,
1185 'oi_deleted & '.File::DELETED_FILE => File::DELETED_FILE ),
1186 __METHOD__, array( 'FOR UPDATE' ) );
1187 // Check the rest of the deleted archives too.
1188 // (these are the ones that don't show in the image history)
1189 if( !$useCount ) {
1190 $useCount = $this->dbw->selectField( 'filearchive', '1',
1191 array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ),
1192 __METHOD__, array( 'FOR UPDATE' ) );
1193 }
1194
1195 if( $useCount == 0 ) {
1196 wfDebug( __METHOD__.": nothing else using {$oimage->sha1}, will deleting after\n" );
1197 $flags = FileStore::DELETE_ORIGINAL;
1198 } else {
1199 $flags = 0;
1200 }
1201 $transaction->add( $store->export( $key, $destPath, $flags ) );
1202
1203 wfDebug( __METHOD__.": set db items, applying file transactions\n" );
1204 $transaction->commit();
1205 FileStore::unlock();
1206
1207 $m = explode('!',$oimage->archive_name,2);
1208 $timestamp = $m[0];
1209
1210 return $timestamp;
1211 }
1212
1213 /**
1214 * Update the revision's rev_deleted field
1215 * @param Revision $rev
1216 * @param int $bitfield new rev_deleted bitfield value
1217 */
1218 function updateRevision( $rev, $bitfield ) {
1219 $this->dbw->update( 'revision',
1220 array( 'rev_deleted' => $bitfield ),
1221 array( 'rev_id' => $rev->getId() ),
1222 __METHOD__ );
1223 }
1224
1225 /**
1226 * Update the revision's rev_deleted field
1227 * @param Revision $rev
1228 * @param int $bitfield new rev_deleted bitfield value
1229 */
1230 function updateArchive( $rev, $bitfield ) {
1231 $this->dbw->update( 'archive',
1232 array( 'ar_deleted' => $bitfield ),
1233 array( 'ar_rev_id' => $rev->getId() ),
1234 __METHOD__ );
1235 }
1236
1237 /**
1238 * Update the images's oi_deleted field
1239 * @param File $oimage
1240 * @param int $bitfield new rev_deleted bitfield value
1241 */
1242 function updateOldFiles( $oimage, $bitfield ) {
1243 $this->dbw->update( 'oldimage',
1244 array( 'oi_deleted' => $bitfield ),
1245 array( 'oi_archive_name' => $oimage->archive_name ),
1246 __METHOD__ );
1247 }
1248
1249 /**
1250 * Update the images's fa_deleted field
1251 * @param ArchivedFile $file
1252 * @param int $bitfield new rev_deleted bitfield value
1253 */
1254 function updateArchFiles( $file, $bitfield ) {
1255 $this->dbw->update( 'filearchive',
1256 array( 'fa_deleted' => $bitfield ),
1257 array( 'fa_id' => $file->getID() ),
1258 __METHOD__ );
1259 }
1260
1261 /**
1262 * Update the logging log_deleted field
1263 * @param Row $row
1264 * @param int $bitfield new rev_deleted bitfield value
1265 */
1266 function updateLogs( $row, $bitfield ) {
1267 $this->dbw->update( 'logging',
1268 array( 'log_deleted' => $bitfield ),
1269 array( 'log_id' => $row->log_id ),
1270 __METHOD__ );
1271 }
1272
1273 /**
1274 * Update the revision's recentchanges record if fields have been hidden
1275 * @param Revision $rev
1276 * @param int $bitfield new rev_deleted bitfield value
1277 */
1278 function updateRecentChangesEdits( $rev, $bitfield ) {
1279 $this->dbw->update( 'recentchanges',
1280 array( 'rc_deleted' => $bitfield,
1281 'rc_patrolled' => 1 ),
1282 array( 'rc_this_oldid' => $rev->getId() ),
1283 __METHOD__ );
1284 }
1285
1286 /**
1287 * Update the revision's recentchanges record if fields have been hidden
1288 * @param Row $row
1289 * @param int $bitfield new rev_deleted bitfield value
1290 */
1291 function updateRecentChangesLog( $row, $bitfield ) {
1292 $this->dbw->update( 'recentchanges',
1293 array( 'rc_deleted' => $bitfield,
1294 'rc_patrolled' => 1 ),
1295 array( 'rc_logid' => $row->log_id ),
1296 __METHOD__ );
1297 }
1298
1299 /**
1300 * Touch the page's cache invalidation timestamp; this forces cached
1301 * history views to refresh, so any newly hidden or shown fields will
1302 * update properly.
1303 * @param Title $title
1304 */
1305 function updatePage( $title ) {
1306 $title->invalidateCache();
1307 $title->purgeSquid();
1308
1309 // Extensions that require referencing previous revisions may need this
1310 wfRunHooks( 'ArticleRevisionVisiblitySet', array( &$title ) );
1311 }
1312
1313 /**
1314 * Record a log entry on the action
1315 * @param Title $title, page where item was removed from
1316 * @param int $count the number of revisions altered for this page
1317 * @param int $nbitfield the new _deleted value
1318 * @param int $obitfield the old _deleted value
1319 * @param string $comment
1320 * @param Title $target, the relevant page
1321 * @param string $param, URL param
1322 * @param Array $items
1323 */
1324 function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target, $param, $items = array() ) {
1325 // Put things hidden from sysops in the oversight log
1326 $logtype = ( ($nbitfield | $obitfield) & Revision::DELETED_RESTRICTED ) ? 'oversight' : 'delete';
1327 $log = new LogPage( $logtype );
1328 // FIXME: do this better
1329 if( $param=='logid' ) {
1330 $params = array( implode( ',', $items) );
1331 $reason = wfMsgExt('logdelete-logaction', array('parsemag'), $count, $nbitfield );
1332 if($comment) $reason .= ": $comment";
1333 $log->addEntry( 'event', $title, $reason, $params );
1334 } else {
1335 // Add params for effected page and ids
1336 $params = array( $target->getPrefixedText(), $param, implode( ',', $items) );
1337 $reason = wfMsgExt('revdelete-logaction', array('parsemag'), $count, $nbitfield );
1338 if($comment) $reason .= ": $comment";
1339 $log->addEntry( 'revision', $title, $reason, $params );
1340 }
1341 }
1342 }