+ 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, $wgContLang, $wgUser, $wgOut;
+ $fname = "UndeleteForm::showList";
+
+ # List undeletable articles
+ $result = PageArchive::listAllPages();
+
+ if ( $this->mAllowed ) {
+ $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
+ } else {
+ $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) );
+ }
+ $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 ?
+ ($wgContLang->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();
+ if ( $this->mAllowed ) {
+ $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
+ } else {
+ $wgOut->setPagetitle( wfMsg( 'viewdeletedpage' ) );
+ }
+
+ $archive = new PageArchive( $this->mTargetObj );
+ $text = $archive->getLastRevisionText();
+ if( is_null( $text ) ) {
+ $wgOut->addWikiText( wfMsg( "nohistory" ) );
+ return;
+ }
+ if ( $this->mAllowed ) {
+ $wgOut->addWikiText( wfMsg( "undeletehistory" ) . "\n----\n" . $text );
+ } else {
+ $wgOut->addWikiText( wfMsg( "undeletehistorynoadmin" ) );
+ }
+
+ # List all stored revisions
+ $revisions = $archive->listRevisions();
+
+ if ( $this->mAllowed ) {
+ $titleObj = Title::makeTitle( NS_SPECIAL, "Undelete" );
+ $action = $titleObj->escapeLocalURL( "action=submit" );
+ $encTarget = htmlspecialchars( $this->mTarget );
+ $button = htmlspecialchars( wfMsg("undeletebtn") );
+ $token = htmlspecialchars( $wgUser->editToken() );
+
+ $wgOut->addHTML("
+ <form id=\"undelete\" method=\"post\" action=\"{$action}\">
+ <input type=\"hidden\" name=\"target\" value=\"{$encTarget}\" />
+ <input type=\"submit\" name=\"restore\" value=\"{$button}\" />
+ <input type='hidden' name='wpEditToken' value=\"{$token}\" />
+ ");
+ }
+
+ # 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(),
+ 'type' => 'delete' ) ) ) );
+ $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() ) {
+ $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
+ if ( $this->mAllowed ) {
+ $checkBox = "<input type=\"checkbox\" name=\"ts$ts\" value=\"1\" />";
+ $pageLink = $sk->makeKnownLinkObj( $titleObj,
+ $wgLang->timeanddate( $ts, true ),
+ "target=$target×tamp=$ts" );
+ } else {
+ $checkBox = '';
+ $pageLink = $wgLang->timeanddate( $ts, true );
+ }
+ $userLink = htmlspecialchars( $row->ar_user_text );
+ if( $row->ar_user ) {
+ $userLink = $sk->makeKnownLinkObj(
+ Title::makeTitle( NS_USER, $row->ar_user_text ),
+ $userLink );
+ } else {
+ $userLink = $sk->makeKnownLinkObj(
+ Title::makeTitle( NS_SPECIAL, 'Contributions' ),
+ $userLink, 'target=' . $row->ar_user_text );
+ }
+ $comment = $sk->commentBlock( $row->ar_comment );
+ $wgOut->addHTML( "<li>$checkBox $pageLink . . $userLink $comment</li>\n" );