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() {
101 $dbr = wfGetDB( DB_SLAVE
);
102 $res = $dbr->select( 'archive',
103 array( 'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text', 'ar_comment', 'ar_len' ),
104 array( 'ar_namespace' => $this->title
->getNamespace(),
105 'ar_title' => $this->title
->getDBkey() ),
106 'PageArchive::listRevisions',
107 array( 'ORDER BY' => 'ar_timestamp DESC' ) );
108 $ret = $dbr->resultObject( $res );
113 * List the deleted file revisions for this page, if it's a file page.
114 * Returns a result wrapper with various filearchive fields, or null
115 * if not a file page.
117 * @return ResultWrapper
118 * @todo Does this belong in Image for fuller encapsulation?
120 function listFiles() {
121 if( $this->title
->getNamespace() == NS_IMAGE
) {
122 $dbr = wfGetDB( DB_SLAVE
);
123 $res = $dbr->select( 'filearchive',
135 array( 'fa_name' => $this->title
->getDbKey() ),
137 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
138 $ret = $dbr->resultObject( $res );
145 * Fetch (and decompress if necessary) the stored text for the deleted
146 * revision of the page with the given timestamp.
149 * @deprecated Use getRevision() for more flexible information
151 function getRevisionText( $timestamp ) {
152 $rev = $this->getRevision( $timestamp );
153 return $rev ?
$rev->getText() : null;
157 * Return a Revision object containing data for the deleted revision.
158 * Note that the result *may* or *may not* have a null page ID.
159 * @param string $timestamp
162 function getRevision( $timestamp ) {
163 $dbr = wfGetDB( DB_SLAVE
);
164 $row = $dbr->selectRow( 'archive',
176 array( 'ar_namespace' => $this->title
->getNamespace(),
177 'ar_title' => $this->title
->getDbkey(),
178 'ar_timestamp' => $dbr->timestamp( $timestamp ) ),
181 return new Revision( array(
182 'page' => $this->title
->getArticleId(),
183 'id' => $row->ar_rev_id
,
184 'text' => ($row->ar_text_id
186 : Revision
::getRevisionText( $row, 'ar_' ) ),
187 'comment' => $row->ar_comment
,
188 'user' => $row->ar_user
,
189 'user_text' => $row->ar_user_text
,
190 'timestamp' => $row->ar_timestamp
,
191 'minor_edit' => $row->ar_minor_edit
,
192 'text_id' => $row->ar_text_id
) );
199 * Return the most-previous revision, either live or deleted, against
200 * the deleted revision given by timestamp.
202 * May produce unexpected results in case of history merges or other
203 * unusual time issues.
205 * @param string $timestamp
206 * @return Revision or null
208 function getPreviousRevision( $timestamp ) {
209 $dbr = wfGetDB( DB_SLAVE
);
211 // Check the previous deleted revision...
212 $row = $dbr->selectRow( 'archive',
214 array( 'ar_namespace' => $this->title
->getNamespace(),
215 'ar_title' => $this->title
->getDbkey(),
217 $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ),
220 'ORDER BY' => 'ar_timestamp DESC',
222 $prevDeleted = $row ?
wfTimestamp( TS_MW
, $row->ar_timestamp
) : false;
224 $row = $dbr->selectRow( array( 'page', 'revision' ),
225 array( 'rev_id', 'rev_timestamp' ),
227 'page_namespace' => $this->title
->getNamespace(),
228 'page_title' => $this->title
->getDbkey(),
229 'page_id = rev_page',
231 $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ),
234 'ORDER BY' => 'rev_timestamp DESC',
236 $prevLive = $row ?
wfTimestamp( TS_MW
, $row->rev_timestamp
) : false;
237 $prevLiveId = $row ?
intval( $row->rev_id
) : null;
239 if( $prevLive && $prevLive > $prevDeleted ) {
240 // Most prior revision was live
241 return Revision
::newFromId( $prevLiveId );
242 } elseif( $prevDeleted ) {
243 // Most prior revision was deleted
244 return $this->getRevision( $prevDeleted );
246 // No prior revision on this page.
252 * Get the text from an archive row containing ar_text, ar_flags and ar_text_id
254 function getTextFromRow( $row ) {
255 if( is_null( $row->ar_text_id
) ) {
256 // An old row from MediaWiki 1.4 or previous.
257 // Text is embedded in this row in classic compression format.
258 return Revision
::getRevisionText( $row, "ar_" );
260 // New-style: keyed to the text storage backend.
261 $dbr = wfGetDB( DB_SLAVE
);
262 $text = $dbr->selectRow( 'text',
263 array( 'old_text', 'old_flags' ),
264 array( 'old_id' => $row->ar_text_id
),
266 return Revision
::getRevisionText( $text );
272 * Fetch (and decompress if necessary) the stored text of the most
273 * recently edited deleted revision of the page.
275 * If there are no archived revisions for the page, returns NULL.
279 function getLastRevisionText() {
280 $dbr = wfGetDB( DB_SLAVE
);
281 $row = $dbr->selectRow( 'archive',
282 array( 'ar_text', 'ar_flags', 'ar_text_id' ),
283 array( 'ar_namespace' => $this->title
->getNamespace(),
284 'ar_title' => $this->title
->getDBkey() ),
285 'PageArchive::getLastRevisionText',
286 array( 'ORDER BY' => 'ar_timestamp DESC' ) );
288 return $this->getTextFromRow( $row );
295 * Quick check if any archived revisions are present for the page.
298 function isDeleted() {
299 $dbr = wfGetDB( DB_SLAVE
);
300 $n = $dbr->selectField( 'archive', 'COUNT(ar_title)',
301 array( 'ar_namespace' => $this->title
->getNamespace(),
302 'ar_title' => $this->title
->getDBkey() ) );
307 * Restore the given (or all) text and file revisions for the page.
308 * Once restored, the items will be removed from the archive tables.
309 * The deletion log will be updated with an undeletion notice.
311 * @param array $timestamps Pass an empty array to restore all revisions, otherwise list the ones to undelete.
312 * @param string $comment
313 * @param array $fileVersions
315 * @return true on success.
317 function undelete( $timestamps, $comment = '', $fileVersions = array() ) {
318 // If both the set of text revisions and file revisions are empty,
319 // restore everything. Otherwise, just restore the requested items.
320 $restoreAll = empty( $timestamps ) && empty( $fileVersions );
322 $restoreText = $restoreAll ||
!empty( $timestamps );
323 $restoreFiles = $restoreAll ||
!empty( $fileVersions );
325 if( $restoreFiles && $this->title
->getNamespace() == NS_IMAGE
) {
326 $img = wfLocalFile( $this->title
);
327 $this->fileStatus
= $img->restore( $fileVersions );
328 $filesRestored = $this->fileStatus
->successCount
;
334 $textRestored = $this->undeleteRevisions( $timestamps );
341 $log = new LogPage( 'delete' );
343 if( $textRestored && $filesRestored ) {
344 $reason = wfMsgExt( 'undeletedrevisions-files', array( 'content', 'parsemag' ),
345 $wgContLang->formatNum( $textRestored ),
346 $wgContLang->formatNum( $filesRestored ) );
347 } elseif( $textRestored ) {
348 $reason = wfMsgExt( 'undeletedrevisions', array( 'content', 'parsemag' ),
349 $wgContLang->formatNum( $textRestored ) );
350 } elseif( $filesRestored ) {
351 $reason = wfMsgExt( 'undeletedfiles', array( 'content', 'parsemag' ),
352 $wgContLang->formatNum( $filesRestored ) );
354 wfDebug( "Undelete: nothing undeleted...\n" );
358 if( trim( $comment ) != '' )
359 $reason .= ": {$comment}";
360 $log->addEntry( 'restore', $this->title
, $reason );
362 if ( $this->fileStatus
&& !$this->fileStatus
->ok
) {
370 * This is the meaty bit -- restores archived revisions of the given page
371 * to the cur/old tables. If the page currently exists, all revisions will
372 * be stuffed into old, otherwise the most recent will go into cur.
374 * @param array $timestamps Pass an empty array to restore all revisions, otherwise list the ones to undelete.
375 * @param string $comment
376 * @param array $fileVersions
378 * @return int number of revisions restored
380 private function undeleteRevisions( $timestamps ) {
381 if ( wfReadOnly() ) return 0;
383 $restoreAll = empty( $timestamps );
385 $dbw = wfGetDB( DB_MASTER
);
387 # Does this page already exist? We'll have to update it...
388 $article = new Article( $this->title
);
389 $options = 'FOR UPDATE';
390 $page = $dbw->selectRow( 'page',
391 array( 'page_id', 'page_latest' ),
392 array( 'page_namespace' => $this->title
->getNamespace(),
393 'page_title' => $this->title
->getDBkey() ),
397 # Page already exists. Import the history, and if necessary
398 # we'll update the latest revision field in the record.
400 $pageId = $page->page_id
;
401 $previousRevId = $page->page_latest
;
403 # Have to create a new article...
404 $newid = $article->insertOn( $dbw );
410 $oldones = '1 = 1'; # All revisions...
412 $oldts = implode( ',',
413 array_map( array( &$dbw, 'addQuotes' ),
414 array_map( array( &$dbw, 'timestamp' ),
417 $oldones = "ar_timestamp IN ( {$oldts} )";
421 * Restore each revision...
423 $result = $dbw->select( 'archive',
436 'ar_namespace' => $this->title
->getNamespace(),
437 'ar_title' => $this->title
->getDBkey(),
441 'ORDER BY' => 'ar_timestamp' )
443 if( $dbw->numRows( $result ) < count( $timestamps ) ) {
444 wfDebug( __METHOD__
.": couldn't find all requested rows\n" );
451 while( $row = $dbw->fetchObject( $result ) ) {
452 if( $row->ar_text_id
) {
453 // Revision was deleted in 1.5+; text is in
454 // the regular text table, use the reference.
455 // Specify null here so the so the text is
456 // dereferenced for page length info if needed.
459 // Revision was deleted in 1.4 or earlier.
460 // Text is squashed into the archive row, and
461 // a new text table entry will be created for it.
462 $revText = Revision
::getRevisionText( $row, 'ar_' );
464 $revision = new Revision( array(
466 'id' => $row->ar_rev_id
,
468 'comment' => $row->ar_comment
,
469 'user' => $row->ar_user
,
470 'user_text' => $row->ar_user_text
,
471 'timestamp' => $row->ar_timestamp
,
472 'minor_edit' => $row->ar_minor_edit
,
473 'text_id' => $row->ar_text_id
,
474 'len' => $row->ar_len
476 $revision->insertOn( $dbw );
481 // Attach the latest revision to the page...
482 $wasnew = $article->updateIfNewerOn( $dbw, $revision, $previousRevId );
484 if( $newid ||
$wasnew ) {
485 // Update site stats, link tables, etc
486 $article->createUpdates( $revision );
490 wfRunHooks( 'ArticleUndelete', array( &$this->title
, true ) );
491 Article
::onArticleCreate( $this->title
);
493 wfRunHooks( 'ArticleUndelete', array( &$this->title
, false ) );
494 Article
::onArticleEdit( $this->title
);
497 # Something went terribly wrong!
500 # Now that it's safely stored, take it out of the archive
501 $dbw->delete( 'archive',
503 'ar_namespace' => $this->title
->getNamespace(),
504 'ar_title' => $this->title
->getDBkey(),
511 function getFileStatus() { return $this->fileStatus
; }
515 * The HTML form for Special:Undelete, which allows users with the appropriate
516 * permissions to view and restore deleted content.
517 * @addtogroup SpecialPage
520 var $mAction, $mTarget, $mTimestamp, $mRestore, $mTargetObj;
521 var $mTargetTimestamp, $mAllowed, $mComment;
523 function UndeleteForm( $request, $par = "" ) {
525 $this->mAction
= $request->getVal( 'action' );
526 $this->mTarget
= $request->getVal( 'target' );
527 $this->mSearchPrefix
= $request->getText( 'prefix' );
528 $time = $request->getVal( 'timestamp' );
529 $this->mTimestamp
= $time ?
wfTimestamp( TS_MW
, $time ) : '';
530 $this->mFile
= $request->getVal( 'file' );
532 $posted = $request->wasPosted() &&
533 $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
534 $this->mRestore
= $request->getCheck( 'restore' ) && $posted;
535 $this->mPreview
= $request->getCheck( 'preview' ) && $posted;
536 $this->mDiff
= $request->getCheck( 'diff' );
537 $this->mComment
= $request->getText( 'wpComment' );
540 $this->mTarget
= $par;
542 if ( $wgUser->isAllowed( 'delete' ) && !$wgUser->isBlocked() ) {
543 $this->mAllowed
= true;
545 $this->mAllowed
= false;
546 $this->mTimestamp
= '';
547 $this->mRestore
= false;
549 if ( $this->mTarget
!== "" ) {
550 $this->mTargetObj
= Title
::newFromURL( $this->mTarget
);
552 $this->mTargetObj
= NULL;
554 if( $this->mRestore
) {
555 $timestamps = array();
556 $this->mFileVersions
= array();
557 foreach( $_REQUEST as $key => $val ) {
559 if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
560 array_push( $timestamps, $matches[1] );
563 if( preg_match( '/^fileid(\d+)$/', $key, $matches ) ) {
564 $this->mFileVersions
[] = intval( $matches[1] );
567 rsort( $timestamps );
568 $this->mTargetTimestamp
= $timestamps;
574 if ( $this->mAllowed
) {
575 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
577 $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) );
580 if( is_null( $this->mTargetObj
) ) {
581 $this->showSearchForm();
583 # List undeletable articles
584 if( $this->mSearchPrefix
) {
585 $result = PageArchive
::listPagesByPrefix(
586 $this->mSearchPrefix
);
587 $this->showList( $result );
591 if( $this->mTimestamp
!== '' ) {
592 return $this->showRevision( $this->mTimestamp
);
594 if( $this->mFile
!== null ) {
595 return $this->showFile( $this->mFile
);
597 if( $this->mRestore
&& $this->mAction
== "submit" ) {
598 return $this->undelete();
600 return $this->showHistory();
603 function showSearchForm() {
604 global $wgOut, $wgScript;
605 $wgOut->addWikiText( wfMsg( 'undelete-header' ) );
608 Xml
::openElement( 'form', array(
610 'action' => $wgScript ) ) .
612 Xml
::element( 'legend', array(),
613 wfMsg( 'undelete-search-box' ) ) .
614 Xml
::hidden( 'title',
615 SpecialPage
::getTitleFor( 'Undelete' )->getPrefixedDbKey() ) .
616 Xml
::inputLabel( wfMsg( 'undelete-search-prefix' ),
617 'prefix', 'prefix', 20,
618 $this->mSearchPrefix
) .
619 Xml
::submitButton( wfMsg( 'undelete-search-submit' ) ) .
624 /* private */ function showList( $result ) {
625 global $wgLang, $wgContLang, $wgUser, $wgOut;
627 if( $result->numRows() == 0 ) {
628 $wgOut->addWikiText( wfMsg( 'undelete-no-results' ) );
632 $wgOut->addWikiText( wfMsg( "undeletepagetext" ) );
634 $sk = $wgUser->getSkin();
635 $undelete = SpecialPage
::getTitleFor( 'Undelete' );
636 $wgOut->addHTML( "<ul>\n" );
637 while( $row = $result->fetchObject() ) {
638 $title = Title
::makeTitleSafe( $row->ar_namespace
, $row->ar_title
);
639 $link = $sk->makeKnownLinkObj( $undelete, htmlspecialchars( $title->getPrefixedText() ), 'target=' . $title->getPrefixedUrl() );
640 #$revs = wfMsgHtml( 'undeleterevisions', $wgLang->formatNum( $row->count ) );
641 $revs = wfMsgExt( 'undeleterevisions',
642 array( 'parseinline' ),
643 $wgLang->formatNum( $row->count
) );
644 $wgOut->addHtml( "<li>{$link} ({$revs})</li>\n" );
647 $wgOut->addHTML( "</ul>\n" );
652 /* private */ function showRevision( $timestamp ) {
653 global $wgLang, $wgUser, $wgOut;
654 $self = SpecialPage
::getTitleFor( 'Undelete' );
655 $skin = $wgUser->getSkin();
657 if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
659 $archive = new PageArchive( $this->mTargetObj
);
660 $rev = $archive->getRevision( $timestamp );
663 $wgOut->addWikiTexT( wfMsg( 'undeleterevision-missing' ) );
667 $wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
669 $link = $skin->makeKnownLinkObj(
671 htmlspecialchars( $this->mTargetObj
->getPrefixedText() ),
672 'target=' . $this->mTargetObj
->getPrefixedUrl()
674 $time = htmlspecialchars( $wgLang->timeAndDate( $timestamp, true ) );
675 $user = $skin->userLink( $rev->getUser(), $rev->getUserText() )
676 . $skin->userToolLinks( $rev->getUser(), $rev->getUserText() );
679 $previousRev = $archive->getPreviousRevision( $timestamp );
681 $this->showDiff( $previousRev, $rev );
682 if( $wgUser->getOption( 'diffonly' ) ) {
685 $wgOut->addHtml( '<hr />' );
688 $wgOut->addHtml( 'No previous revision found.' );
692 $wgOut->addHtml( '<p>' . wfMsgHtml( 'undelete-revision', $link, $time, $user ) . '</p>' );
694 wfRunHooks( 'UndeleteShowRevision', array( $this->mTargetObj
, $rev ) );
696 if( $this->mPreview
) {
697 $wgOut->addHtml( "<hr />\n" );
698 $wgOut->addWikiTextTitleTidy( $rev->getText(), $this->mTargetObj
, false );
702 wfElement( 'textarea', array(
703 'readonly' => 'readonly',
704 'cols' => intval( $wgUser->getOption( 'cols' ) ),
705 'rows' => intval( $wgUser->getOption( 'rows' ) ) ),
706 $rev->getText() . "\n" ) .
707 wfOpenElement( 'div' ) .
708 wfOpenElement( 'form', array(
710 'action' => $self->getLocalURL( "action=submit" ) ) ) .
711 wfElement( 'input', array(
714 'value' => $this->mTargetObj
->getPrefixedDbKey() ) ) .
715 wfElement( 'input', array(
717 'name' => 'timestamp',
718 'value' => $timestamp ) ) .
719 wfElement( 'input', array(
721 'name' => 'wpEditToken',
722 'value' => $wgUser->editToken() ) ) .
723 wfElement( 'input', array(
726 'value' => wfMsg( 'showpreview' ) ) ) .
727 wfElement( 'input', array(
730 'value' => wfMsg( 'showdiff' ) ) ) .
731 wfCloseElement( 'form' ) .
732 wfCloseElement( 'div' ) );
736 * Build a diff display between this and the previous either deleted
737 * or non-deleted edit.
738 * @param Revision $previousRev
739 * @param Revision $currentRev
740 * @return string HTML
742 function showDiff( $previousRev, $currentRev ) {
743 global $wgOut, $wgUser;
745 $diffEngine = new DifferenceEngine();
746 $diffEngine->showDiffStyle();
749 "<table border='0' width='98%' cellpadding='0' cellspacing='4' class='diff'>" .
750 "<col class='diff-marker' />" .
751 "<col class='diff-content' />" .
752 "<col class='diff-marker' />" .
753 "<col class='diff-content' />" .
755 "<td colspan='2' width='50%' align='center' class='diff-otitle'>" .
756 $this->diffHeader( $previousRev ) .
758 "<td colspan='2' width='50%' align='center' class='diff-ntitle'>" .
759 $this->diffHeader( $currentRev ) .
762 $diffEngine->generateDiffBody(
763 $previousRev->getText(), $currentRev->getText() ) .
769 private function diffHeader( $rev ) {
770 global $wgUser, $wgLang, $wgLang;
771 $sk = $wgUser->getSkin();
772 $isDeleted = !( $rev->getId() && $rev->getTitle() );
774 /// @fixme $rev->getTitle() is null for deleted revs...?
775 $targetPage = SpecialPage
::getTitleFor( 'Undelete' );
776 $targetQuery = 'target=' .
777 $this->mTargetObj
->getPrefixedUrl() .
779 wfTimestamp( TS_MW
, $rev->getTimestamp() );
781 /// @fixme getId() may return non-zero for deleted revs...
782 $targetPage = $rev->getTitle();
783 $targetQuery = 'oldid=' . $rev->getId();
786 '<div id="mw-diff-otitle1"><strong>' .
787 $sk->makeLinkObj( $targetPage,
788 wfMsgHtml( 'revisionasof',
789 $wgLang->timeanddate( $rev->getTimestamp(), true ) ),
791 ( $isDeleted ?
' ' . wfMsgHtml( 'deletedrev' ) : '' ) .
793 '<div id="mw-diff-otitle2">' .
794 $sk->revUserTools( $rev ) . '<br/>' .
796 '<div id="mw-diff-otitle3">' .
797 $sk->revComment( $rev ) . '<br/>' .
802 * Show a deleted file version requested by the visitor.
804 function showFile( $key ) {
805 global $wgOut, $wgRequest;
808 # We mustn't allow the output to be Squid cached, otherwise
809 # if an admin previews a deleted image, and it's cached, then
810 # a user without appropriate permissions can toddle off and
811 # nab the image, and Squid will serve it
812 $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
813 $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
814 $wgRequest->response()->header( 'Pragma: no-cache' );
816 $store = FileStore
::get( 'deleted' );
817 $store->stream( $key );
820 /* private */ function showHistory() {
821 global $wgLang, $wgContLang, $wgUser, $wgOut;
823 $sk = $wgUser->getSkin();
824 if ( $this->mAllowed
) {
825 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
827 $wgOut->setPagetitle( wfMsg( 'viewdeletedpage' ) );
830 $archive = new PageArchive( $this->mTargetObj
);
832 $text = $archive->getLastRevisionText();
833 if( is_null( $text ) ) {
834 $wgOut->addWikiText( wfMsg( "nohistory" ) );
838 if ( $this->mAllowed
) {
839 $wgOut->addWikiText( wfMsg( "undeletehistory" ) );
841 $wgOut->addWikiText( wfMsg( "undeletehistorynoadmin" ) );
844 # List all stored revisions
845 $revisions = $archive->listRevisions();
846 $files = $archive->listFiles();
848 $haveRevisions = $revisions && $revisions->numRows() > 0;
849 $haveFiles = $files && $files->numRows() > 0;
851 # Batch existence check on user and talk pages
852 if( $haveRevisions ) {
853 $batch = new LinkBatch();
854 while( $row = $revisions->fetchObject() ) {
855 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->ar_user_text
) );
856 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->ar_user_text
) );
859 $revisions->seek( 0 );
862 $batch = new LinkBatch();
863 while( $row = $files->fetchObject() ) {
864 $batch->addObj( Title
::makeTitleSafe( NS_USER
, $row->fa_user_text
) );
865 $batch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->fa_user_text
) );
871 if ( $this->mAllowed
) {
872 $titleObj = SpecialPage
::getTitleFor( "Undelete" );
873 $action = $titleObj->getLocalURL( "action=submit" );
874 # Start the form here
875 $top = Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
876 $wgOut->addHtml( $top );
879 # Show relevant lines from the deletion log:
880 $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage
::logName( 'delete' ) ) . "</h2>\n" );
881 $logViewer = new LogViewer(
885 'page' => $this->mTargetObj
->getPrefixedText(),
889 ), LogViewer
::NO_ACTION_LINK
891 $logViewer->showList( $wgOut );
893 if( $this->mAllowed
&& ( $haveRevisions ||
$haveFiles ) ) {
894 # Format the user-visible controls (comment field, submission button)
895 # in a nice little table
896 $align = $wgContLang->isRtl() ?
'left' : 'right';
898 Xml
::openElement( 'fieldset' ) .
899 Xml
::openElement( 'table' ) .
902 wfMsgWikiHtml( 'undeleteextrahelp' ) .
906 <td align='$align'>" .
907 Xml
::label( wfMsg( 'undeletecomment' ), 'wpComment' ) .
910 Xml
::input( 'wpComment', 50, $this->mComment
) .
916 Xml
::submitButton( wfMsg( 'undeletebtn' ), array( 'name' => 'restore', 'id' => 'mw-undelete-submit' ) ) .
917 Xml
::element( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'undeletereset' ), 'id' => 'mw-undelete-reset' ) ) .
920 Xml
::closeElement( 'table' ) .
921 Xml
::closeElement( 'fieldset' );
923 $wgOut->addHtml( $table );
926 $wgOut->addHTML( "<h2>" . htmlspecialchars( wfMsg( "history" ) ) . "</h2>\n" );
928 if( $haveRevisions ) {
929 # The page's stored (deleted) history:
930 $wgOut->addHTML("<ul>");
931 $target = urlencode( $this->mTarget
);
932 $remaining = $revisions->numRows();
933 $earliestLiveTime = $this->getEarliestTime( $this->mTargetObj
);
935 while( $row = $revisions->fetchObject() ) {
937 $ts = wfTimestamp( TS_MW
, $row->ar_timestamp
);
938 if ( $this->mAllowed
) {
939 $checkBox = Xml
::check( "ts$ts" );
940 $pageLink = $sk->makeKnownLinkObj( $titleObj,
941 $wgLang->timeanddate( $ts, true ),
942 "target=$target×tamp=$ts" );
943 if( ($remaining > 0) ||
944 ($earliestLiveTime && $ts > $earliestLiveTime ) ) {
946 $sk->makeKnownLinkObj( $titleObj,
948 "target=$target×tamp=$ts&diff=prev" ) .
951 // No older revision to diff against
956 $pageLink = $wgLang->timeanddate( $ts, true );
959 $userLink = $sk->userLink( $row->ar_user
, $row->ar_user_text
) . $sk->userToolLinks( $row->ar_user
, $row->ar_user_text
);
961 if (!is_null($size = $row->ar_len
)) {
963 $stxt = wfMsgHtml('historyempty');
965 $stxt = wfMsgHtml('historysize', $wgLang->formatNum( $size ) );
968 $comment = $sk->commentBlock( $row->ar_comment
);
969 $wgOut->addHTML( "<li>$checkBox $pageLink $diffLink . . $userLink $stxt $comment</li>\n" );
973 $wgOut->addHTML("</ul>");
975 $wgOut->addWikiText( wfMsg( "nohistory" ) );
979 $wgOut->addHtml( "<h2>" . wfMsgHtml( 'filehist' ) . "</h2>\n" );
980 $wgOut->addHtml( "<ul>" );
981 while( $row = $files->fetchObject() ) {
982 $ts = wfTimestamp( TS_MW
, $row->fa_timestamp
);
983 if ( $this->mAllowed
&& $row->fa_storage_key
) {
984 $checkBox = Xml
::check( "fileid" . $row->fa_id
);
985 $key = urlencode( $row->fa_storage_key
);
986 $target = urlencode( $this->mTarget
);
987 $pageLink = $sk->makeKnownLinkObj( $titleObj,
988 $wgLang->timeanddate( $ts, true ),
989 "target=$target&file=$key" );
992 $pageLink = $wgLang->timeanddate( $ts, true );
994 $userLink = $sk->userLink( $row->fa_user
, $row->fa_user_text
) . $sk->userToolLinks( $row->fa_user
, $row->fa_user_text
);
996 wfMsgHtml( 'widthheight',
997 $wgLang->formatNum( $row->fa_width
),
998 $wgLang->formatNum( $row->fa_height
) ) .
1000 wfMsgHtml( 'nbytes', $wgLang->formatNum( $row->fa_size
) ) .
1002 $comment = $sk->commentBlock( $row->fa_description
);
1003 $wgOut->addHTML( "<li>$checkBox $pageLink . . $userLink $data $comment</li>\n" );
1006 $wgOut->addHTML( "</ul>" );
1009 if ( $this->mAllowed
) {
1010 # Slip in the hidden controls here
1011 $misc = Xml
::hidden( 'target', $this->mTarget
);
1012 $misc .= Xml
::hidden( 'wpEditToken', $wgUser->editToken() );
1013 $misc .= Xml
::closeElement( 'form' );
1014 $wgOut->addHtml( $misc );
1020 private function getEarliestTime( $title ) {
1021 $dbr = wfGetDB( DB_SLAVE
);
1022 if( $title->exists() ) {
1023 $min = $dbr->selectField( 'revision',
1024 'MIN(rev_timestamp)',
1025 array( 'rev_page' => $title->getArticleId() ),
1027 return wfTimestampOrNull( TS_MW
, $min );
1032 function undelete() {
1033 global $wgOut, $wgUser;
1034 if( !is_null( $this->mTargetObj
) ) {
1035 $archive = new PageArchive( $this->mTargetObj
);
1037 $ok = $archive->undelete(
1038 $this->mTargetTimestamp
,
1040 $this->mFileVersions
);
1043 $skin = $wgUser->getSkin();
1044 $link = $skin->makeKnownLinkObj( $this->mTargetObj
);
1045 $wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) );
1047 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
1050 // Show file deletion warnings and errors
1051 $status = $archive->getFileStatus();
1052 if ( $status && !$status->isGood() ) {
1053 $wgOut->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) );
1056 $wgOut->showFatalError( wfMsg( "cannotundelete" ) );