Capitalization fix in memcached setting
[lhc/web/wiklou.git] / includes / SpecialUndelete.php
index 8da3764..d450960 100644 (file)
 <?php
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
 
-function wfSpecialUndelete( $par )
-{
+/**
+ *
+ */
+function wfSpecialUndelete( $par ) {
     global $wgRequest;
 
        $form = new UndeleteForm( $wgRequest, $par );
        $form->execute();
 }
 
-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' );
-               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 ) ) {
-                       $title = $this->mTargetObj->mDbkeyform;
-                       $namespace = $this->mTargetObj->mNamespace;
-                       if( $this->mTimestamp !== "" ) {
-                               return $this->showRevision( $namespace, $title, $this->mTimestamp );
-                       }
-                       if( $this->mRestore and $this->mAction == "submit" ) {
-                               return $this->undelete( $namespace, $title );
-                       }
-                       return $this->showHistory( $namespace, $title );
-               } else {
-                       return $this->showList();
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+class PageArchive {
+       var $title;
+       
+       function PageArchive( &$title ) {
+               if( is_null( $title ) ) {
+                       wfDebugDieBacktrace( 'Archiver() given a null title.');
                }
+               $this->title =& $title;
        }
-
-       /* private */ function showList() {
-               global $wgLang, $wgUser, $wgOut;
-               $fname = "UndeleteForm::showList";
-               
-               # List undeletable articles    
+       
+       /**
+        * List all deleted pages recorded in the archive table. Returns result
+        * wrapper with (ar_namespace, ar_title, count) fields, ordered by page
+        * namespace/title. Can be called staticaly.
+        *
+        * @return ResultWrapper
+        */
+       /* static */ function &listAllPages() {
                $dbr =& wfGetDB( DB_SLAVE );
                $archive = $dbr->tableName( 'archive' );
 
                $sql = "SELECT ar_namespace,ar_title, COUNT(*) AS count FROM $archive " . 
                  "GROUP BY ar_namespace,ar_title ORDER BY ar_namespace,ar_title";
 
-               $res = $dbr->query( $sql, $fname );
-               
-               $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
-               $wgOut->addWikiText( wfMsg( "undeletepagetext" ) );
-
-               $special = $wgLang->getNsText( Namespace::getSpecial() );
-               $sk = $wgUser->getSkin();
-               $wgOut->addHTML( "<ul>\n" );
-               while ($row = $dbr->fetchObject( $res )) {
-                       $n = ($row->ar_namespace ? 
-                               ($wgLang->getNsText( $row->ar_namespace ) . ":") : "").
-                               $row->ar_title;
-
-                       $wgOut->addHTML( "<li>" .
-                         $sk->makeKnownLink( $wgLang->specialPage( "Undelete" ),
-                         $n, "target=" . urlencode($n) ) . " " .
-                         wfMsg( "undeleterevisions", $row->count ) );
-               }
-               $wgOut->addHTML( "</ul>\n" );
-               
-               return 0;
+               return $dbr->resultObject( $dbr->query( $sql, 'PageArchive::listAllPages' ) );
        }
        
-       /* private */ function showRevision( $namespace, $title, $timestamp ) {
-               global $wgLang, $wgUser, $wgOut;
-               $fname = "UndeleteForm::showRevision";
-
-               if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
-
+       /**
+        * List the revisions of the given page. Returns result wrapper with
+        * (ar_minor_edit, ar_timestamp, ar_user, ar_user_text, ar_comment) fields.
+        *
+        * @return ResultWrapper
+        */
+       function &listRevisions() {
                $dbr =& wfGetDB( DB_SLAVE );
-               $archive = $dbr->tableName( 'archive' );
-               $sql = "SELECT ar_text,ar_flags FROM $archive ". 
-                 "WHERE ar_namespace={$namespace} AND ar_title='" .
-                 $dbr->strencode( $title ) . "' AND ar_timestamp='" . $dbr->strencode( $timestamp ) ."'";
-               $ret = $dbr->query( $sql, $fname );
-               $row = $dbr->fetchObject( $ret );
-               
-               $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
-               $wgOut->addWikiText( "(" . wfMsg( "undeleterevision", $wgLang->date($timestamp, true) )
-                 . ")\n<hr>\n" . Article::getRevisionText( $row, "ar_" ) );
-
-               return 0;
+               return $dbr->resultObject( $dbr->select( 'archive',
+                       array( 'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text', 'ar_comment' ),
+                       array( 'ar_namespace' => $this->title->getNamespace(),
+                              'ar_title' => $this->title->getDBkey() ),
+                       'PageArchive::listRevisions',
+                       array( 'ORDER BY' => 'ar_timestamp DESC' ) ) );
        }
-
-       /* private */ function showHistory( $namespace, $title ) {
-               global $wgLang, $wgUser, $wgOut;
-               
-               $sk = $wgUser->getSkin();
-               $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
+       
+       /**
+        * Fetch (and decompress if necessary) the stored text for the deleted
+        * revision of the page with the given timestamp.
+        *
+        * @return string
+        */
+       function getRevisionText( $timestamp ) {
                $dbr =& wfGetDB( DB_SLAVE );
-               $archive = $dbr->tableName( 'archive' );
-               
-               # Get text of first revision
-               $sql = "SELECT ar_text FROM $archive WHERE ar_namespace={$namespace} AND ar_title='" .
-                 $dbr->strencode( $title ) . "' ORDER BY ar_timestamp DESC LIMIT 1";
-               $ret = $dbr->query( $sql );
-
-               if( $dbr->numRows( $ret ) == 0 ) {
-                       $wgOut->addWikiText( wfMsg( "nohistory" ) );
-                       return 0;
-               }
-               $row = $dbr->fetchObject( $ret );
-               $wgOut->addWikiText( wfMsg( "undeletehistory" ) . "\n<hr>\n" . $row->ar_text );
-
-               # List all stored revisions
-               $sql = "SELECT ar_minor_edit,ar_timestamp,ar_user,ar_user_text,ar_comment
-                 FROM archive WHERE ar_namespace={$namespace} AND ar_title='" . $dbr->strencode( $title ) .
-                 "' ORDER BY ar_timestamp DESC";
-               $ret = $dbr->query( $sql );
-
-               $titleObj = Title::makeTitle( NS_SPECIAL, "Undelete" );
-               $action = $titleObj->escapeLocalURL( "action=submit" );
-               $encTarget = htmlspecialchars( $this->mTarget );
-               
-               $wgOut->addHTML("<p>
-       <form id=\"undelete\" method=\"post\" action=\"{$action}\">
-       <input type=hidden name=\"target\" value=\"{$encTarget}\">
-       <input type=submit name=\"restore\" value=\"".wfMsg("undeletebtn")."\">
-       </form>");
-
-               $log = $dbr->selectField( "cur", "cur_text", 
-                       array( 'cur_namespace' => NS_PROJECT, 'cur_title' => wfMsg("dellogpage") ) );
-               if(preg_match("/^(.*".
-                       preg_quote( ($namespace ? ($wgLang->getNsText($namespace) . ":") : "")
-                       . str_replace("_", " ", $title), "/" ).".*)$/m", $log, $m)) {
-                       $wgOut->addWikiText( $m[1] );
-               }
-               
-               $special = $wgLang->getNsText( Namespace::getSpecial() );
-               $wgOut->addHTML("<ul>");
-               while( $row = $dbr->fetchObject( $ret ) ) {
-                       $wgOut->addHTML( "<li>" .
-                         $sk->makeKnownLink( $wgLang->specialPage( "Undelete" ),
-                         $wgLang->timeanddate( $row->ar_timestamp, true ),
-                         "target=" . urlencode($this->mTarget) . "&timestamp={$row->ar_timestamp}" ) . " " .
-                         ". . " . htmlspecialchars( $row->ar_user_text )  .
-                         " <i>(" . htmlspecialchars($row->ar_comment) . "</i>)\n");
-
+               $row = $dbr->selectRow( 'archive',
+                       array( 'ar_text', 'ar_flags' ),
+                       array( 'ar_namespace' => $this->title->getNamespace(),
+                              'ar_title' => $this->title->getDbkey(),
+                              'ar_timestamp' => $dbr->timestamp( $timestamp ) ) );
+               return Article::getRevisionText( $row, "ar_" );
+       }
+       
+       /**
+        * Fetch (and decompress if necessary) the stored text of the most
+        * recently edited deleted revision of the page.
+        *
+        * If there are no archived revisions for the page, returns NULL.
+        *
+        * @return string
+        */
+       function getLastRevisionText() {
+               $dbr =& wfGetDB( DB_SLAVE );
+               $row = $dbr->selectRow( 'archive',
+                       array( 'ar_text', 'ar_flags' ),
+                       array( 'ar_namespace' => $this->title->getNamespace(),
+                              'ar_title' => $this->title->getDBkey() ),
+                       'PageArchive::getLastRevisionText',
+                       'ORDER BY ar_timestamp DESC LIMIT 1' );
+               if( $row ) {
+                       return Article::getRevisionText( $row, "ar_" );
+               } else {
+                       return NULL;
                }
-               $wgOut->addHTML("</ul>");
-               
-               return 0;
-       }       
-
-       /* private */ function undelete( $namespace, $title )
-       {
+       }
+       
+       /**
+        * Quick check if any archived revisions are present for the page.
+        * @return bool
+        */
+       function isDeleted() {
+               $dbr =& wfGetDB( DB_SLAVE );
+               $n = $dbr->selectField( 'archive', 'COUNT(ar_title)',
+                       array( 'ar_namespace' => $this->title->getNamespace(),
+                              'ar_title' => $this->title->getDBkey() ) );
+               return ($n > 0);
+       }
+       
+       /**
+        * This is the meaty bit -- restores archived revisions of the given page
+        * to the cur/old tables. If the page currently exists, all revisions will
+        * be stuffed into old, otherwise the most recent will go into cur.
+        * The deletion log will be updated with an undeletion notice.
+        *
+        * Returns true on success.
+        *
+        * @param array $timestamps Pass an empty array to restore all revisions, otherwise list the ones to undelete.
+        * @return bool
+        */
+       function undelete( $timestamps ) {
                global $wgUser, $wgOut, $wgLang, $wgDeferredUpdateList;
-               global  $wgUseSquid, $wgInternalServer, $wgLinkCache;
+               global $wgUseSquid, $wgInternalServer, $wgLinkCache;
 
                $fname = "doUndeleteArticle";
+               $restoreAll = empty( $timestamps );
+               $restoreRevisions = count( $timestamps );
 
-               if ( "" == $title ) {
-                       $wgOut->fatalError( wfMsg( "cannotundelete" ) );
-                       return;
-               }
                $dbw =& wfGetDB( DB_MASTER );
                extract( $dbw->tableNames( 'cur', 'archive', 'old' ) );
-               $t = $dbw->strencode($title);
+               $namespace = $this->title->getNamespace();
+               $ttl = $this->title->getDBkey();
+               $t = $dbw->strencode( $ttl );
 
                # Move article and history from the "archive" table
-               $sql = "SELECT COUNT(*) AS count FROM $cur WHERE cur_namespace={$namespace} AND cur_title='{$t}' FOR UPDATE";
+               $sql = "SELECT COUNT(*) AS count FROM $cur WHERE cur_namespace={$namespace} AND cur_title='{$t}'";
+               global $wgDBtype;
+               if( $wgDBtype != 'PostgreSQL' ) { # HACKHACKHACKHACK
+                       $sql .= ' FOR UPDATE';
+               }
                $res = $dbw->query( $sql, $fname );
                $row = $dbw->fetchObject( $res );
                $now = wfTimestampNow();
 
                if( $row->count == 0) {
                        # Have to create new article...
-                       $sql = "SELECT ar_text,ar_timestamp,ar_flags FROM $archive WHERE ar_namespace={$namespace} AND ar_title='{$t}' " .
-                               "ORDER BY ar_timestamp DESC LIMIT 1 FOR UPDATE";
+                       $sql = "SELECT ar_text,ar_comment,ar_user,ar_user_text,ar_timestamp,ar_minor_edit,ar_flags FROM $archive WHERE ar_namespace={$namespace} AND ar_title='{$t}' ";
+                       if( !$restoreAll ) {
+                               $max = $dbw->addQuotes( $dbw->timestamp( array_shift( $timestamps ) ) );
+                               $sql .= "AND ar_timestamp={$max} ";
+                       }
+                       $sql .= "ORDER BY ar_timestamp DESC LIMIT 1 FOR UPDATE";
                        $res = $dbw->query( $sql, $fname );
                        $s = $dbw->fetchObject( $res );
-                       $max = $s->ar_timestamp;
+                       if( $restoreAll ) {
+                               $max = $s->ar_timestamp;
+                       }
+                       $text = Article::getRevisionText( $s, "ar_" );
+                       
                        $redirect = MagicWord::get( MAG_REDIRECT );
-                       $redir = $redirect->matchStart( $s->ar_text ) ? 1 : 0;
+                       $redir = $redirect->matchStart( $text ) ? 1 : 0;
+                       
+                       $rand = wfRandom();
+                       $dbw->insert( 'cur', array(
+                               'cur_id' => $dbw->nextSequenceValue( 'cur_cur_id_seq' ),
+                               'cur_namespace' => $namespace,
+                               'cur_title' => $ttl,
+                               'cur_text' => $text,
+                               'cur_comment' => $s->ar_comment,
+                               'cur_user' => $s->ar_user,
+                               'cur_timestamp' => $s->ar_timestamp,
+                               'cur_minor_edit' => $s->ar_minor_edit,
+                               'cur_user_text' => $s->ar_user_text,
+                               'cur_is_redirect' => $redir,
+                               'cur_random' => $rand,
+                               'cur_touched' => $dbw->timestamp( $now ),
+                               'inverse_timestamp' => wfInvertTimestamp( wfTimestamp( TS_MW, $s->ar_timestamp ) ),
+                       ), $fname );
                        
-                       $seqVal = $dbw->addQuotes( $dbw->nextSequenceValue( 'cur_cur_id_seq' ) );
-
-                       $sql = "INSERT INTO $cur (cur_id,cur_namespace,cur_title,cur_text," .
-                         "cur_comment,cur_user,cur_user_text,cur_timestamp,inverse_timestamp,cur_minor_edit,cur_is_redirect,cur_random,cur_touched)" .
-                         "SELECT $seqVal,ar_namespace,ar_title,ar_text,ar_comment," .
-                         "ar_user,ar_user_text,ar_timestamp,99999999999999-ar_timestamp,ar_minor_edit,{$redir},RAND(),'{$now}' FROM $archive " .
-                         "WHERE ar_namespace={$namespace} AND ar_title='{$t}' AND ar_timestamp={$max}";
-                       $dbw->query( $sql, $fname );
                        $newid = $dbw->insertId();
-                       $oldones = "AND ar_timestamp<{$max}";
+                       if( $restoreAll ) {
+                               $oldones = "AND ar_timestamp<" . $dbw->addQuotes( $dbw->timestamp( $max ) );
+                       }
                } else {
                        # If already exists, put history entirely into old table
                        $oldones = "";
@@ -211,12 +201,22 @@ class UndeleteForm {
                        # We should merge.
                }
                
+               if( !$restoreAll ) {
+                       $oldts = array();
+                       foreach( $timestamps as $ts ) {
+                               array_push( $oldts, $dbw->addQuotes( $dbw->timestamp( $ts ) ) );
+                       }
+                       $oldts = join( ",", $oldts );
+                       $oldones = "AND ar_timestamp IN ( {$oldts} )";
+               }
                $sql = "INSERT INTO $old (old_namespace,old_title,old_text," .
                  "old_comment,old_user,old_user_text,old_timestamp,inverse_timestamp,old_minor_edit," .
                  "old_flags) SELECT ar_namespace,ar_title,ar_text,ar_comment," .
                  "ar_user,ar_user_text,ar_timestamp,99999999999999-ar_timestamp,ar_minor_edit,ar_flags " .
                  "FROM $archive WHERE ar_namespace={$namespace} AND ar_title='{$t}' {$oldones}";
-               $dbw->query( $sql, $fname );
+               if( $restoreAll || !empty( $oldts ) ) {
+                       $dbw->query( $sql, $fname );
+               }
 
                # Finally, clean up the link tables 
                if( $newid ) {
@@ -225,17 +225,12 @@ class UndeleteForm {
                        $wgLinkCache->forUpdate( true );
                        # Create a dummy OutputPage to update the outgoing links
                        $dummyOut = new OutputPage();
-                       # Get the text
-                       $text = $dbw->selectField( 'cur', 'cur_text', 
-                               array( 'cur_id' => $newid, 'cur_namespace' => $namespace ), 
-                               $fname, 'FOR UPDATE' 
-                       );
                        $dummyOut->addWikiText( $text );
 
-                       $u = new LinksUpdate( $newid, $this->mTargetObj->getPrefixedDBkey() );
+                       $u = new LinksUpdate( $newid, $this->title->getPrefixedDBkey() );
                        array_push( $wgDeferredUpdateList, $u );
                        
-                       Article::onArticleCreate( $this->mTargetObj );
+                       Article::onArticleCreate( $this->title );
 
                        #TODO: SearchUpdate, etc.
                }
@@ -243,15 +238,196 @@ class UndeleteForm {
                # Now that it's safely stored, take it out of the archive
                $sql = "DELETE FROM $archive WHERE ar_namespace={$namespace} AND " .
                  "ar_title='{$t}'";
+               if( !$restoreAll ) {
+                       $sql .= " AND ar_timestamp IN ( {$oldts}";
+                       if( $newid ) {
+                               if( !empty( $oldts ) ) $sql .= ",";
+                               $sql .= $max;
+                       }
+                       $sql .= ")";
+               }
                $dbw->query( $sql, $fname );
 
                
                # Touch the log?
                $log = new LogPage( 'delete' );
-               $log->addEntry( 'restore', Title::makeTitle( $namespace, $title ), "" );
+               if( $restoreAll ) {
+                       $reason = "";
+               } else {
+                       $reason = wfMsg( 'undeletedrevisions', $restoreRevisions );
+               }
+               $log->addEntry( 'restore', $this->title, $reason );
+               
+               return true;
+       }
+}
+
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+class UndeleteForm {
+       var $mAction, $mTarget, $mTimestamp, $mRestore, $mTargetObj;
+       var $mTargetTimestamp;
+
+       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;
+               }
+               if( $this->mRestore ) {
+                       $timestamps = array();
+                       foreach( $_REQUEST as $key => $val ) {
+                               if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
+                                       array_push( $timestamps, $matches[1] );
+                               }
+                       }
+                       rsort( $timestamps );
+                       $this->mTargetTimestamp = $timestamps;
+               }
+       }
 
-               $wgOut->addWikiText( wfMsg( "undeletedtext", $this->mTarget ) );
-               return 0;
+       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, $wgContLang, $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 ? 
+                               ($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();
+               $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}\" />
+       ");
+
+               # 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 );
+                       $checkBox = "<input type=\"checkbox\" name=\"ts$ts\" value=\"1\" />";
+                       $pageLink = $sk->makeKnownLinkObj( $titleObj,
+                               $wgLang->timeanddate( $row->ar_timestamp, true ),
+                               "target=$target&timestamp=$ts" );
+                       $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>$checkBox $pageLink . . $userLink (<i>$comment</i>)</li>\n" );
+
+               }
+               $revisions->free();
+               $wgOut->addHTML("</ul>\n</form>");
+               
+               return true;
+       }
+
+       function undelete() {
+               global $wgOut;
+               if( !is_null( $this->mTargetObj ) ) {
+                       $archive = new PageArchive( $this->mTargetObj );
+                       if( $archive->undelete( $this->mTargetTimestamp ) ) {
+                               $wgOut->addWikiText( wfMsg( "undeletedtext", $this->mTarget ) );
+                               return true;
+                       }
+               }
+               $wgOut->fatalError( wfMsg( "cannotundelete" ) );
+               return false;
        }
 }
+
 ?>