+ $log->addEntry( 'restore', $this->title, "" );
+
+ return true;
+ }
+}
+
+class UndeleteForm {
+ var $mAction, $mTarget, $mTimestamp, $mRestore, $mTargetObj;
+
+ function UndeleteForm( &$request, $par = "" ) {
+ $this->mAction = $request->getText( 'action' );
+ $this->mTarget = $request->getText( 'target' );
+ $this->mTimestamp = $request->getText( 'timestamp' );
+ $this->mRestore = $request->getCheck( 'restore' ) && $request->wasPosted();
+ if( $par != "" ) {
+ $this->mTarget = $par;
+ }
+ if ( $this->mTarget !== "" ) {
+ $this->mTargetObj = Title::newFromURL( $this->mTarget );
+ } else {
+ $this->mTargetObj = NULL;
+ }
+ }
+
+ function execute() {
+ if( is_null( $this->mTargetObj ) ) {
+ return $this->showList();
+ }
+ if( $this->mTimestamp !== "" ) {
+ return $this->showRevision( $this->mTimestamp );
+ }
+ if( $this->mRestore && $this->mAction == "submit" ) {
+ return $this->undelete();
+ }
+ return $this->showHistory();
+ }
+
+ /* private */ function showList() {
+ global $wgLang, $wgUser, $wgOut;
+ $fname = "UndeleteForm::showList";
+
+ # List undeletable articles
+ $result = PageArchive::listAllPages();
+
+ $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
+ $wgOut->addWikiText( wfMsg( "undeletepagetext" ) );
+
+ $sk = $wgUser->getSkin();
+ $undelete =& Title::makeTitle( NS_SPECIAL, 'Undelete' );
+ $wgOut->addHTML( "<ul>\n" );
+ while( $row = $result->fetchObject() ) {
+ $n = ($row->ar_namespace ?
+ ($wgLang->getNsText( $row->ar_namespace ) . ":") : "").
+ $row->ar_title;
+ $link = $sk->makeKnownLinkObj( $undelete,
+ htmlspecialchars( $n ), "target=" . urlencode( $n ) );
+ $revisions = htmlspecialchars( wfMsg( "undeleterevisions",
+ $wgLang->formatNum( $row->count ) ) );
+ $wgOut->addHTML( "<li>$link $revisions</li>\n" );
+ }
+ $result->free();
+ $wgOut->addHTML( "</ul>\n" );
+
+ return true;
+ }
+
+ /* private */ function showRevision( $timestamp ) {
+ global $wgLang, $wgUser, $wgOut;
+ $fname = "UndeleteForm::showRevision";
+
+ if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
+
+ $archive =& new PageArchive( $this->mTargetObj );
+ $text = $archive->getRevisionText( $timestamp );
+
+ $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
+ $wgOut->addWikiText( "(" . wfMsg( "undeleterevision",
+ $wgLang->date( $timestamp ) ) . ")\n<hr />\n" . $text );
+ }
+
+ /* private */ function showHistory() {
+ global $wgLang, $wgUser, $wgOut;
+
+ $sk = $wgUser->getSkin();
+ $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
+
+ $archive = new PageArchive( $this->mTargetObj );
+ $text = $archive->getLastRevisionText();
+ if( is_null( $text ) ) {
+ $wgOut->addWikiText( wfMsg( "nohistory" ) );
+ return;
+ }
+ $wgOut->addWikiText( wfMsg( "undeletehistory" ) . "\n----\n" . $text );
+
+ # List all stored revisions
+ $revisions = $archive->listRevisions();
+
+ $titleObj = Title::makeTitle( NS_SPECIAL, "Undelete" );
+ $action = $titleObj->escapeLocalURL( "action=submit" );
+ $encTarget = htmlspecialchars( $this->mTarget );
+ $button = htmlspecialchars( wfMsg("undeletebtn") );
+
+ $wgOut->addHTML("
+ <form id=\"undelete\" method=\"post\" action=\"{$action}\">
+ <input type=\"hidden\" name=\"target\" value=\"{$encTarget}\" />
+ <input type=\"submit\" name=\"restore\" value=\"{$button}\" />
+ </form>");
+
+ # Show relevant lines from the deletion log:
+ $wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
+ require_once( 'SpecialLog.php' );
+ $logViewer =& new LogViewer(
+ new LogReader(
+ new FauxRequest(
+ array( 'page', $this->mTargetObj->getPrefixedText() ) ) ) );
+ $logViewer->showList( $wgOut );
+
+ # The page's stored (deleted) history:
+ $wgOut->addHTML( "<h2>" . htmlspecialchars( wfMsg( "history" ) ) . "</h2>\n" );
+ $wgOut->addHTML("<ul>");
+ $target = urlencode( $this->mTarget );
+ while( $row = $revisions->fetchObject() ) {
+ $pageLink = $sk->makeKnownLinkObj( $titleObj,
+ $wgLang->timeanddate( $row->ar_timestamp, true ),
+ "target=$target×tamp={$row->ar_timestamp}" );
+ $userLink = htmlspecialchars( $row->ar_user_text );
+ if( $row->ar_user ) {
+ $userLink = $sk->makeKnownLinkObj(
+ Title::makeTitle( NS_USER, $row->ar_user_text ),
+ $userLink );
+ }
+ $comment = $sk->formatComment( $row->ar_comment );
+ $wgOut->addHTML( "<li>$pageLink . . $userLink (<i>$comment</i>)</li>\n" );
+
+ }
+ $revisions->free();
+ $wgOut->addHTML("</ul>");
+
+ return true;
+ }