482aac19384d796ef784e1e0cc865a35fe9fac11
4 * Special page allowing users with the appropriate permissions to view
5 * and restore deleted content
7 * @addtogroup SpecialPage
13 function wfSpecialUndelete( $par ) {
16 $form = new UndeleteForm( $wgRequest, $par );
21 * Used to show archived pages and eventually restore them.
22 * @addtogroup SpecialPage
28 function __construct( $title ) {
29 if( is_null( $title ) ) {
30 throw new MWException( 'Archiver() given a null title.');
32 $this->title
= $title;
36 * List all deleted pages recorded in the archive table. Returns result
37 * wrapper with (ar_namespace, ar_title, count) fields, ordered by page
40 * @return ResultWrapper
42 public static function listAllPages() {
43 $dbr = wfGetDB( DB_SLAVE
);
44 return self
::listPages( $dbr, '' );
48 * List deleted pages recorded in the archive table matching the
50 * Returns result wrapper with (ar_namespace, ar_title, count) fields.
52 * @return ResultWrapper
54 public static function listPagesByPrefix( $prefix ) {
55 $dbr = wfGetDB( DB_SLAVE
);
57 $title = Title
::newFromText( $prefix );
59 $ns = $title->getNamespace();
60 $encPrefix = $dbr->escapeLike( $title->getDbKey() );
62 // Prolly won't work too good
63 // @todo handle bare namespace names cleanly?
65 $encPrefix = $dbr->escapeLike( $prefix );
68 'ar_namespace' => $ns,
69 "ar_title LIKE '$encPrefix%'",
71 return self
::listPages( $dbr, $conds );
74 protected static function listPages( $dbr, $condition ) {
75 return $dbr->resultObject(
86 'GROUP BY' => 'ar_namespace,ar_title',
87 'ORDER BY' => 'ar_namespace,ar_title',
95 * List the revisions of the given page. Returns result wrapper with
96 * (ar_minor_edit, ar_timestamp, ar_user, ar_user_text, ar_comment) fields.
98 * @return ResultWrapper
100 function listRevisions( $startTime, $limit ) {
101 $whereClause = array( 'ar_namespace' => $this->title
->getNamespace(),
102 'ar_title' => $this->title
->getDBkey() );
103 if ( $startTime && is_numeric($startTime) )
104 $whereClause[] = "ar_timestamp < $startTime";
106 $optionsClause = array( 'ORDER BY' => 'ar_timestamp DESC' );
107 if ( $limit > 0 ) $optionsClause['LIMIT'] = intval($limit);
109 $dbr = wfGetDB( DB_SLAVE
);
110 $res = $dbr->select( 'archive',
111 array( 'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text', 'ar_comment', 'ar_len' ),
113 'PageArchive::listRevisions',
115 $ret = $dbr->resultObject( $res );
120 * List the deleted file revisions for this page, if it's a file page.
121 * Returns a result wrapper with various filearchive fields, or null
122 * if not a file page.
124 * @return ResultWrapper
125 * @todo Does this belong in Image for fuller encapsulation?
127 function listFiles() {
128 if( $this->title
->getNamespace() == NS_IMAGE
) {
129 $dbr = wfGetDB( DB_SLAVE
);
130 $res = $dbr->select( 'filearchive',
142 array( 'fa_name' => $this->title
->getDbKey() ),
144 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
145 $ret = $dbr->resultObject( $res );
152 * Fetch (and decompress if necessary) the stored text for the deleted
153 * revision of the page with the given timestamp.
156 * @deprecated Use getRevision() for more flexible information
158 function getRevisionText( $timestamp ) {
159 $rev = $this->getRevision( $timestamp );
160 return $rev ?
$rev->getText() : null;
164 * Return a Revision object containing data for the deleted revision.
165 * Note that the result *may* or *may not* have a null page ID.
166 * @param string $timestamp
169 function getRevision( $timestamp ) {
170 $dbr = wfGetDB( DB_SLAVE
);
171 $row = $dbr->selectRow( 'archive',
183 array( 'ar_namespace' => $this->title
->getNamespace(),
184 'ar_title' => $this->title
->getDbkey(),
185 'ar_timestamp' => $dbr->timestamp( $timestamp ) ),
188 return new Revision( array(
189 'page' => $this->title
->getArticleId(),
190 'id' => $row->ar_rev_id
,
191 'text' => ($row->ar_text_id
193 : Revision
::getRevisionText( $row, 'ar_' ) ),
194 'comment' => $row->ar_comment
,
195 'user' => $row->ar_user
,
196 'user_text' => $row->ar_user_text
,
197 'timestamp' => $row->ar_timestamp
,
198 'minor_edit' => $row->ar_minor_edit
,
199 'text_id' => $row->ar_text_id
) );
206 * Return the most-previous revision, either live or deleted, against
207 * the deleted revision given by timestamp.
209 * May produce unexpected results in case of history merges or other
210 * unusual time issues.
212 * @param string $timestamp
213 * @return Revision or null
215 function getPreviousRevision( $timestamp ) {
216 $dbr = wfGetDB( DB_SLAVE
);
218 // Check the previous deleted revision...
219 $row = $dbr->selectRow( 'archive',
221 array( 'ar_namespace' => $this->title
->getNamespace(),
222 'ar_title' => $this->title
->getDbkey(),
224 $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ),
227 'ORDER BY' => 'ar_timestamp DESC',
229 $prevDeleted = $row ?
wfTimestamp( TS_MW
, $row->ar_timestamp
) : false;
231 $row = $dbr->selectRow( array( 'page', 'revision' ),
232 array( 'rev_id', 'rev_timestamp' ),
234 'page_namespace' => $this->title
->getNamespace(),
235 'page_title' => $this->title
->getDbkey(),
236 'page_id = rev_page',
238 $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ),
241 'ORDER BY' => 'rev_timestamp DESC',
243 $prevLive = $row ?
wfTimestamp( TS_MW
, $row->rev_timestamp
) : false;
244 $prevLiveId = $row ?
intval( $row->rev_id
) : null;
246 if( $prevLive && $prevLive > $prevDeleted ) {
247 // Most prior revision was live
248 return Revision
::newFromId( $prevLiveId );
249 } elseif( $prevDeleted ) {
250 // Most prior revision was deleted
251 return $this->getRevision( $prevDeleted );
253 // No prior revision on this page.
259 * Get the text from an archive row containing ar_text, ar_flags and ar_text_id
261 function getTextFromRow( $row ) {
262 if( is_null( $row->ar_text_id
) ) {
263 // An old row from MediaWiki 1.4 or previous.
264 // Text is embedded in this row in classic compression format.
265 return Revision
::getRevisionText( $row, "ar_" );
267 // New-style: keyed to the text storage backend.
268 $dbr = wfGetDB( DB_SLAVE
);
269 $text = $dbr->selectRow( 'text',
270 array( 'old_text', 'old_flags' ),
271 array( 'old_id' => $row->ar_text_id
),
273 return Revision
::getRevisionText( $text );
279 * Fetch (and decompress if necessary) the stored text of the most
280 * recently edited deleted revision of the page.
282 * If there are no archived revisions for the page, returns NULL.
286 function getLastRevisionText() {
287 $dbr = wfGetDB( DB_SLAVE
);
288 $row = $dbr->selectRow( 'archive',
289 array( 'ar_text', 'ar_flags', 'ar_text_id' ),
290 array( 'ar_namespace' => $this->title
->getNamespace(),
291 'ar_title' => $this->title
->getDBkey() ),
292 'PageArchive::getLastRevisionText',
293 array( 'ORDER BY' => 'ar_timestamp DESC' ) );
295 return $this->getTextFromRow( $row );
302 * Quick check if any archived revisions are present for the page.
305 function isDeleted() {
306 $dbr = wfGetDB( DB_SLAVE
);
307 $n = $dbr->selectField( 'archive', 'COUNT(ar_title)',
308 array( 'ar_namespace' => $this->title
->getNamespace(),
309 'ar_title' => $this->title
->getDBkey() ) );
313 const UNDELETE_NOTHINGRESTORED
= 0; // No revisions could be restored
314 const UNDELETE_NOTAVAIL
= -1; // Not all requested revisions are available
315 const UNDELETE_UNKNOWNERR
= -2; // Unknown error
317 * Restore the given (or all) text and file revisions for the page.
318 * Once restored, the items will be removed from the archive tables.
319 * The deletion log will be updated with an undeletion notice.
321 * @param array $timestamps Pass an empty array to restore all revisions, otherwise list the ones to undelete.
322 * @param string $comment
323 * @param array $fileVersions
325 * @return array(number of revisions restored, number of file versions restored, log reason) on success or UNDELETE_* on failure
327 function undelete( $timestamps, $comment = '', $fileVersions = array() ) {
328 // If both the set of text revisions and file revisions are empty,
329 // restore everything. Otherwise, just restore the requested items.
330 $restoreAll = empty( $timestamps ) && empty( $fileVersions );
332 $restoreText = $restoreAll ||
!empty( $timestamps );
333 $restoreFiles = $restoreAll ||
!empty( $fileVersions );
335 if( $restoreFiles && $this->title
->getNamespace() == NS_IMAGE
) {
336 $img = wfLocalFile( $this->title
);
337 $this->fileStatus
= $img->restore( $fileVersions );
338 $filesRestored = $this->fileStatus
->successCount
;
344 $textRestored = $this->undeleteRevisions( $timestamps );
345 if($textRestored < 0) // It must be one of UNDELETE_*
346 return $textRestored;
353 $log = new LogPage( 'delete' );
355 if( $textRestored && $filesRestored ) {
356 $reason = wfMsgExt( 'undeletedrevisions-files', array( 'content', 'parsemag' ),
357 $wgContLang->formatNum( $textRestored ),
358 $wgContLang->formatNum( $filesRestored ) );
359 } elseif( $textRestored ) {
360 $reason = wfMsgExt( 'undeletedrevisions', array( 'content', 'parsemag' ),
361 $wgContLang->formatNum( $textRestored ) );
362 } elseif( $filesRestored ) {
363 $reason = wfMsgExt( 'undeletedfiles', array( 'content', 'parsemag' ),
364 $wgContLang->formatNum( $filesRestored ) );
366 wfDebug( "Undelete: nothing undeleted...\n" );
367 return self
::UNDELETE_NOTHINGRESTORED
;
370 if( trim( $comment ) != '' )
371 $reason .= ": {$comment}";
372 $log->addEntry( 'restore', $this->title
, $reason );
374 return array($textRestored, $filesRestored, $reason);
378 * This is the meaty bit -- restores archived revisions of the given page
379 * to the cur/old tables. If the page currently exists, all revisions will
380 * be stuffed into old, otherwise the most recent will go into cur.
382 * @param array $timestamps Pass an empty array to restore all revisions, otherwise list the ones to undelete.
383 * @param string $comment
384 * @param array $fileVersions
386 * @return int number of revisions restored on success or UNDELETE_* on failure
388 private function undeleteRevisions( $timestamps ) {
389 if ( wfReadOnly() ) return 0;
391 $restoreAll = empty( $timestamps );
393 $dbw = wfGetDB( DB_MASTER
);
395 # Does this page already exist? We'll have to update it...
396 $article = new Article( $this->title
);
397 $options = 'FOR UPDATE';
398 $page = $dbw->selectRow( 'page',
399 array( 'page_id', 'page_latest' ),
400 array( 'page_namespace' => $this->title
->getNamespace(),
401 'page_title' => $this->title
->getDBkey() ),
405 # Page already exists. Import the history, and if necessary
406 # we'll update the latest revision field in the record.
408 $pageId = $page->page_id
;
409 $previousRevId = $page->page_latest
;
411 # Have to create a new article...
412 $newid = $article->insertOn( $dbw );
418 $oldones = '1 = 1'; # All revisions...
420 $oldts = implode( ',',
421 array_map( array( &$dbw, 'addQuotes' ),
422 array_map( array( &$dbw, 'timestamp' ),
425 $oldones = "ar_timestamp IN ( {$oldts} )";
429 * Restore each revision...
431 $result = $dbw->select( 'archive',
444 'ar_namespace' => $this->title
->getNamespace(),
445 'ar_title' => $this->title
->getDBkey(),
449 'ORDER BY' => 'ar_timestamp' )
451 if( $dbw->numRows( $result ) < count( $timestamps ) ) {
452 wfDebug( __METHOD__
.": couldn't find all requested rows\n" );
453 return self
::UNDELETE_NOTAVAIL
;
459 while( $row = $dbw->fetchObject( $result ) ) {
460 if( $row->ar_text_id
) {
461 // Revision was deleted in 1.5+; text is in
462 // the regular text table, use the reference.
463 // Specify null here so the so the text is
464 // dereferenced for page length info if needed.
467 // Revision was deleted in 1.4 or earlier.
468 // Text is squashed into the archive row, and
469 // a new text table entry will be created for it.
470 $revText = Revision
::getRevisionText( $row, 'ar_' );
472 $revision = new Revision( array(
474 'id' => $row->ar_rev_id
,
476 'comment' => $row->ar_comment
,
477 'user' => $row->ar_user
,
478 'user_text' => $row->ar_user_text
,
479 'timestamp' => $row->ar_timestamp
,
480 'minor_edit' => $row->ar_minor_edit
,
481 'text_id' => $row->ar_text_id
,
482 'len' => $row->ar_len
484 $revision->insertOn( $dbw );
487 // Was anything restored at all?
492 // Attach the latest revision to the page...
493 $wasnew = $article->updateIfNewerOn( $dbw, $revision, $previousRevId );
495 if( $newid ||
$wasnew ) {
496 // Update site stats, link tables, etc
497 $article->createUpdates( $revision );
501 wfRunHooks( 'ArticleUndelete', array( &$this->title
, true ) );
502 Article
::onArticleCreate( $this->title
);
504 wfRunHooks( 'ArticleUndelete', array( &$this->title
, false ) );
505 Article
::onArticleEdit( $this->title
);
508 // Revision couldn't be created. This is very weird
509 return self
::UNDELETE_UNKNOWNERR
;
512 # Now that it's safely stored, take it out of the archive
513 $dbw->delete( 'archive',
515 'ar_namespace' => $this->title
->getNamespace(),
516 'ar_title' => $this->title
->getDBkey(),
523 function getFileStatus() { return $this->fileStatus
; }
527 * The HTML form for Special:Undelete, which allows users with the appropriate
528 * permissions to view and restore deleted content.
529 * @addtogroup SpecialPage
532 var $mAction, $mTarget, $mTimestamp, $mRestore, $mTargetObj;
533 var $mTargetTimestamp, $mAllowed, $mComment;
535 function UndeleteForm( $request, $par = "" ) {
537 $this->mAction
= $request->getVal( 'action' );
538 $this->mTarget
= $request->getVal( 'target' );
539 $this->mSearchPrefix
= $request->getText( 'prefix' );
540 $time = $request->getVal( 'timestamp' );
541 $this->mTimestamp
= $time ?
wfTimestamp( TS_MW
, $time ) : '';
542 $this->mFile
= $request->getVal( 'file' );
544 $posted = $request->wasPosted() &&
545 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
546 $this->mRestore
= $request->getCheck( 'restore' ) && $posted;
547 $this->mPreview
= $request->getCheck( 'preview' ) && $posted;
548 $this->mDiff
= $request->getCheck( 'diff' );
549 $this->mComment
= $request->getText( 'wpComment' );
552 $this->mTarget
= $par;
554 if ( $wgUser->isAllowed( 'undelete' ) && !$wgUser->isBlocked() ) {
555 $this->mAllowed
= true;
557 $this->mAllowed
= false;
558 $this->mTimestamp
= '';
559 $this->mRestore
= false;
561 if ( $this->mTarget
!== "" ) {
562 $this->mTargetObj
= Title
::newFromURL( $this->mTarget
);
564 $this->mTargetObj
= NULL;
566 if( $this->mRestore
) {
567 $timestamps = array();
568 $this->mFileVersions
= array();
569 foreach( $_REQUEST as $key => $val ) {
571 if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
572 array_push( $timestamps, $matches[1] );
575 if( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
576 $this->mFileVersions
[] = intval( $matches[1] );
579 rsort( $timestamps );
580 $this->mTargetTimestamp
= $timestamps;
586 if ( $this->mAllowed
) {
587 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
589 $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) );
592 if( is_null( $this->mTargetObj
) ) {
593 $this->showSearchForm();
595 # List undeletable articles
596 if( $this->mSearchPrefix
) {
597 $result = PageArchive
::listPagesByPrefix(
598 $this->mSearchPrefix
);
599 $this->showList( $result );
603 if( $this->mTimestamp
!== '' ) {
604 return $this->showRevision( $this->mTimestamp
);
606 if( $this->mFile
!== null ) {
607 return $this->showFile( $this->mFile
);
609 if( $this->mRestore
&& $this->mAction
== "submit" ) {
610 return $this->undelete();
612 return $this->showHistory();
615 function showSearchForm() {
616 global $wgOut, $wgScript;
617 $wgOut->addWikiText( wfMsg( 'undelete-header' ) );
620 Xml
::openElement( 'form', array(
622 'action' => $wgScript ) ) .
624 Xml
::element( 'legend', array(),
625 wfMsg( 'undelete-search-box' ) ) .
626 Xml
::hidden( 'title',
627 SpecialPage
::getTitleFor( 'Undelete' )->getPrefixedDbKey() ) .
628 Xml
::inputLabel( wfMsg( 'undelete-search-prefix' ),
629 'prefix', 'prefix', 20,
630 $this->mSearchPrefix
) .
631 Xml
::submitButton( wfMsg( 'undelete-search-submit' ) ) .
636 /* private */ function showList( $result ) {
637 global $wgLang, $wgContLang, $wgUser, $wgOut;
639 if( $result->numRows() == 0 ) {
640 $wgOut->addWikiText( wfMsg( 'undelete-no-results' ) );
644 $wgOut->addWikiText( wfMsg( "undeletepagetext" ) );
646 $sk = $wgUser->getSkin();
647 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
648 $wgOut->addHTML( "<ul>\n" );
649 while( $row = $result->fetchObject() ) {
650 $title = Title
::makeTitleSafe( $row->ar_namespace
, $row->ar_title
);
651 $link = $sk->makeKnownLinkObj( $undelete, htmlspecialchars( $title->getPrefixedText() ), 'target=' . $title->getPrefixedUrl() );
652 #$revs = wfMsgHtml( 'undeleterevisions', $wgLang->formatNum( $row->count ) );
653 $revs = wfMsgExt( 'undeleterevisions',
654 array( 'parseinline' ),
655 $wgLang->formatNum( $row->count
) );
656 $wgOut->addHtml( "<li>{$link} ({$revs})</li>\n" );
659 $wgOut->addHTML( "</ul>\n" );
664 /* private */ function showRevision( $timestamp ) {
665 global $wgLang, $wgUser, $wgOut;
666 $self = SpecialPage
::getTitleFor( 'Undelete' );
667 $skin = $wgUser->getSkin();
669 if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
671 $archive = new PageArchive( $this->mTargetObj
);
672 $rev = $archive->getRevision( $timestamp );
675 $wgOut->addWikiTexT( wfMsg( 'undeleterevision-missing' ) );
679 $wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
681 $link = $skin->makeKnownLinkObj(
682 SpecialPage
::getTitleFor( 'Undelete', $this->mTargetObj
->getPrefixedDBkey() ),
683 htmlspecialchars( $this->mTargetObj
->getPrefixedText() )
685 $time = htmlspecialchars( $wgLang->timeAndDate( $timestamp, true ) );
686 $user = $skin->userLink( $rev->getUser(), $rev->getUserText() )
687 . $skin->userToolLinks( $rev->getUser(), $rev->getUserText() );
690 $previousRev = $archive->getPreviousRevision( $timestamp );
692 $this->showDiff( $previousRev, $rev );
693 if( $wgUser->getOption( 'diffonly' ) ) {
696 $wgOut->addHtml( '<hr />' );
699 $wgOut->addHtml( wfMsgHtml( 'undelete-nodiff' ) );
703 $wgOut->addHtml( '<p>' . wfMsgHtml( 'undelete-revision', $link, $time, $user ) . '</p>' );
705 wfRunHooks( 'UndeleteShowRevision', array( $this->mTargetObj
, $rev ) );
707 if( $this->mPreview
) {
708 $wgOut->addHtml( "<hr />\n" );
709 $wgOut->addWikiTextTitleTidy( $rev->getText(), $this->mTargetObj
, false );
713 wfElement( 'textarea', array(
714 'readonly' => 'readonly',
715 'cols' => intval( $wgUser->getOption( 'cols' ) ),
716 'rows' => intval( $wgUser->getOption( 'rows' ) ) ),
717 $rev->getText() . "\n" ) .
718 wfOpenElement( 'div' ) .
719 wfOpenElement( 'form', array(
721 'action' => $self->getLocalURL( "action=submit" ) ) ) .
722 wfElement( 'input', array(
725 'value' => $this->mTargetObj
->getPrefixedDbKey() ) ) .
726 wfElement( 'input', array(
728 'name' => 'timestamp',
729 'value' => $timestamp ) ) .
730 wfElement( 'input', array(
732 'name' => 'wpEditToken',
733 'value' => $wgUser->editToken() ) ) .
734 wfElement( 'input', array(
737 'value' => wfMsg( 'showpreview' ) ) ) .
738 wfElement( 'input', array(
741 'value' => wfMsg( 'showdiff' ) ) ) .
742 wfCloseElement( 'form' ) .
743 wfCloseElement( 'div' ) );
747 * Build a diff display between this and the previous either deleted
748 * or non-deleted edit.
749 * @param Revision $previousRev
750 * @param Revision $currentRev
751 * @return string HTML
753 function showDiff( $previousRev, $currentRev ) {
754 global $wgOut, $wgUser;
756 $diffEngine = new DifferenceEngine();
757 $diffEngine->showDiffStyle();
760 "<table border='0' width='98%' cellpadding='0' cellspacing='4' class='diff'>" .
761 "<col class='diff-marker' />" .
762 "<col class='diff-content' />" .
763 "<col class='diff-marker' />" .
764 "<col class='diff-content' />" .
766 "<td colspan='2' width='50%' align='center' class='diff-otitle'>" .
767 $this->diffHeader( $previousRev ) .
769 "<td colspan='2' width='50%' align='center' class='diff-ntitle'>" .
770 $this->diffHeader( $currentRev ) .
773 $diffEngine->generateDiffBody(
774 $previousRev->getText(), $currentRev->getText() ) .
780 private function diffHeader( $rev ) {
781 global $wgUser, $wgLang, $wgLang;
782 $sk = $wgUser->getSkin();
783 $isDeleted = !( $rev->getId() && $rev->getTitle() );
785 /// @fixme $rev->getTitle() is null for deleted revs...?
786 $targetPage = SpecialPage
::getTitleFor( 'Undelete' );
787 $targetQuery = 'target=' .
788 $this->mTargetObj
->getPrefixedUrl() .
790 wfTimestamp( TS_MW
, $rev->getTimestamp() );
792 /// @fixme getId() may return non-zero for deleted revs...
793 $targetPage = $rev->getTitle();
794 $targetQuery = 'oldid=' . $rev->getId();
797 '<div id="mw-diff-otitle1"><strong>' .
798 $sk->makeLinkObj( $targetPage,
799 wfMsgHtml( 'revisionasof',
800 $wgLang->timeanddate( $rev->getTimestamp(), true ) ),
802 ( $isDeleted ?
' ' . wfMsgHtml( 'deletedrev' ) : '' ) .
804 '<div id="mw-diff-otitle2">' .
805 $sk->revUserTools( $rev ) . '<br/>' .
807 '<div id="mw-diff-otitle3">' .
808 $sk->revComment( $rev ) . '<br/>' .
813 * Show a deleted file version requested by the visitor.
815 function showFile( $key ) {
816 global $wgOut, $wgRequest;
819 # We mustn't allow the output to be Squid cached, otherwise
820 # if an admin previews a deleted image, and it's cached, then
821 # a user without appropriate permissions can toddle off and
822 # nab the image, and Squid will serve it
823 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
824 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
825 $wgRequest->response()->header( 'Pragma: no-cache' );
827 $store = FileStore
::get( 'deleted' );
828 $store->stream( $key );
831 /* private */ function showHistory() {
832 global $wgLang, $wgContLang, $wgUser, $wgOut, $wgRequest;
834 $sk = $wgUser->getSkin();
835 if ( $this->mAllowed
) {
836 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
838 $wgOut->setPagetitle( wfMsg( 'viewdeletedpage' ) );
841 $archive = new PageArchive( $this->mTargetObj
);
843 $text = $archive->getLastRevisionText();
844 if( is_null( $text ) ) {
845 $wgOut->addWikiText( wfMsg( "nohistory" ) );
849 if ( $this->mAllowed
) {
850 $wgOut->addWikiText( wfMsg( "undeletehistory" ) );
852 $wgOut->addWikiText( wfMsg( "undeletehistorynoadmin" ) );
855 # List all stored revisions
856 $tmpLimit = $wgRequest->getIntOrNull ( 'limit' );
857 $tmpLimit = (is_null($tmpLimit))?
5001 : $tmpLimit +
1;
858 $revisions = $archive->listRevisions( $wgRequest->getVal ( 'offset' ),
860 if ( $tmpLimit < 1 ) $tmpLimit = $revisions->numRows() +
1;
862 $files = $archive->listFiles();
864 $haveRevisions = $revisions && $revisions->numRows() > 0;
865 $haveFiles = $files && $files->numRows() > 0;
868 if ( $revisions && $revisions->numRows() >= $tmpLimit ) {
869 if ( $revisions->numRows() >= 2 ) {
870 $revisions->seek ( $revisions->numRows() - 2 );
871 $tmp = $revisions->fetchObject();
872 $revisions->rewind ( );
873 $offset = $tmp->ar_timestamp
;
877 $titleObj = SpecialPage
::getTitleFor ( 'Undelete' );
878 $nextLink = $sk->makeKnownLinkObj ( $titleObj, wfMsg( 'undelete-next-revs', 5000 ),
879 "target={$this->mTarget}&limit=5000&offset=$offset" );
881 $allLink = $sk->makeKnownLinkObj ( $titleObj, wfMsg( 'undelete-show-all' ),
882 "target={$this->mTarget}&limit=-1&offset=0" );
884 $wgOut->addHTML ( wfMsg ( 'undelete-more-revs', $tmpLimit - 1, $nextLink, $allLink ) );
887 # Batch existence check on user and talk pages
888 if( $haveRevisions ) {
889 $batch = new LinkBatch();
890 while( $row = $revisions->fetchObject() ) {
891 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->ar_user_text
) );
892 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->ar_user_text
) );
895 $revisions->seek( 0 );
898 $batch = new LinkBatch();
899 while( $row = $files->fetchObject() ) {
900 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->fa_user_text
) );
901 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->fa_user_text
) );
907 if ( $this->mAllowed
) {
908 $titleObj = SpecialPage
::getTitleFor( "Undelete" );
909 $action = $titleObj->getLocalURL( "action=submit" );
910 # Start the form here
911 $top = Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
912 $wgOut->addHtml( $top );
915 # Show relevant lines from the deletion log:
916 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'delete' ) ) . "</h2>\n" );
917 $logViewer = new LogViewer(
921 'page' => $this->mTargetObj
->getPrefixedText(),
925 ), LogViewer
::NO_ACTION_LINK
927 $logViewer->showList( $wgOut );
929 if( $this->mAllowed
&& ( $haveRevisions ||
$haveFiles ) ) {
930 # Format the user-visible controls (comment field, submission button)
931 # in a nice little table
932 $align = $wgContLang->isRtl() ?
'left' : 'right';
934 Xml
::openElement( 'fieldset' ) .
935 Xml
::openElement( 'table' ) .
938 wfMsgWikiHtml( 'undeleteextrahelp' ) .
942 <td align='$align'>" .
943 Xml
::label( wfMsg( 'undeletecomment' ), 'wpComment' ) .
946 Xml
::input( 'wpComment', 50, $this->mComment
) .
952 Xml
::submitButton( wfMsg( 'undeletebtn' ), array( 'name' => 'restore', 'id' => 'mw-undelete-submit' ) ) .
953 Xml
::element( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'undeletereset' ), 'id' => 'mw-undelete-reset' ) ) .
956 Xml
::closeElement( 'table' ) .
957 Xml
::closeElement( 'fieldset' );
959 $wgOut->addHtml( $table );
962 $wgOut->addHTML( "<h2>" . htmlspecialchars( wfMsg( "history" ) ) . "</h2>\n" );
964 if( $haveRevisions ) {
965 # The page's stored (deleted) history:
966 $wgOut->addHTML("<ul>");
967 $target = urlencode( $this->mTarget
);
968 $remaining = $revisions->numRows();
969 $earliestLiveTime = $this->getEarliestTime( $this->mTargetObj
);
971 if ( $hasMore ) $remaining --;
973 while( ( $row = $revisions->fetchObject() ) && $remaining-- ) {
974 $ts = wfTimestamp( TS_MW
, $row->ar_timestamp
);
975 if ( $this->mAllowed
) {
976 $checkBox = Xml
::check( "ts$ts" );
977 $pageLink = $sk->makeKnownLinkObj( $titleObj,
978 $wgLang->timeanddate( $ts, true ),
979 "target=$target×tamp=$ts" );
980 if( ($remaining > 0 ||
$hasMore ) ||
981 ($earliestLiveTime && $ts > $earliestLiveTime ) ) {
983 $sk->makeKnownLinkObj( $titleObj,
985 "target=$target×tamp=$ts&diff=prev" ) .
988 // No older revision to diff against
993 $pageLink = $wgLang->timeanddate( $ts, true );
996 $userLink = $sk->userLink( $row->ar_user
, $row->ar_user_text
) . $sk->userToolLinks( $row->ar_user
, $row->ar_user_text
);
998 if (!is_null($size = $row->ar_len
)) {
1000 $stxt = wfMsgHtml('historyempty');
1002 $stxt = wfMsgHtml('historysize', $wgLang->formatNum( $size ) );
1005 $comment = $sk->commentBlock( $row->ar_comment
);
1006 $wgOut->addHTML( "<li>$checkBox $pageLink $diffLink . . $userLink $stxt $comment</li>\n" );
1010 $wgOut->addHTML("</ul>");
1012 $wgOut->addWikiText( wfMsg( "nohistory" ) );
1016 $wgOut->addHtml( "<h2>" . wfMsgHtml( 'filehist' ) . "</h2>\n" );
1017 $wgOut->addHtml( "<ul>" );
1018 while( $row = $files->fetchObject() ) {
1019 $ts = wfTimestamp( TS_MW
, $row->fa_timestamp
);
1020 if ( $this->mAllowed
&& $row->fa_storage_key
) {
1021 $checkBox = Xml
::check( "fileid" . $row->fa_id
);
1022 $key = urlencode( $row->fa_storage_key
);
1023 $target = urlencode( $this->mTarget
);
1024 $pageLink = $sk->makeKnownLinkObj( $titleObj,
1025 $wgLang->timeanddate( $ts, true ),
1026 "target=$target&file=$key" );
1029 $pageLink = $wgLang->timeanddate( $ts, true );
1031 $userLink = $sk->userLink( $row->fa_user
, $row->fa_user_text
) . $sk->userToolLinks( $row->fa_user
, $row->fa_user_text
);
1033 wfMsgHtml( 'widthheight',
1034 $wgLang->formatNum( $row->fa_width
),
1035 $wgLang->formatNum( $row->fa_height
) ) .
1037 wfMsgHtml( 'nbytes', $wgLang->formatNum( $row->fa_size
) ) .
1039 $comment = $sk->commentBlock( $row->fa_description
);
1040 $wgOut->addHTML( "<li>$checkBox $pageLink . . $userLink $data $comment</li>\n" );
1043 $wgOut->addHTML( "</ul>" );
1046 if ( $this->mAllowed
) {
1047 # Slip in the hidden controls here
1048 $misc = Xml
::hidden( 'target', $this->mTarget
);
1049 $misc .= Xml
::hidden( 'wpEditToken', $wgUser->editToken() );
1050 $misc .= Xml
::closeElement( 'form' );
1051 $wgOut->addHtml( $misc );
1057 private function getEarliestTime( $title ) {
1058 $dbr = wfGetDB( DB_SLAVE
);
1059 if( $title->exists() ) {
1060 $min = $dbr->selectField( 'revision',
1061 'MIN(rev_timestamp)',
1062 array( 'rev_page' => $title->getArticleId() ),
1064 return wfTimestampOrNull( TS_MW
, $min );
1069 function undelete() {
1070 global $wgOut, $wgUser;
1071 if( !is_null( $this->mTargetObj
) ) {
1072 $archive = new PageArchive( $this->mTargetObj
);
1074 $ok = $archive->undelete(
1075 $this->mTargetTimestamp
,
1077 $this->mFileVersions
);
1079 if( is_array($ok) ) {
1080 $skin = $wgUser->getSkin();
1081 $link = $skin->makeKnownLinkObj( $this->mTargetObj
);
1082 $wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) );
1084 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
1087 // Show file deletion warnings and errors
1088 $status = $archive->getFileStatus();
1089 if ( $status && !$status->isGood() ) {
1090 $wgOut->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) );
1093 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );