$wgStyleVersion!
[lhc/web/wiklou.git] / includes / SpecialUndelete.php
index 2175b66..c08a777 100644 (file)
@@ -57,7 +57,7 @@ class PageArchive {
                $title = Title::newFromText( $prefix );
                if( $title ) {
                        $ns = $title->getNamespace();
-                       $encPrefix = $dbr->escapeLike( $title->getDbKey() );
+                       $encPrefix = $dbr->escapeLike( $title->getDBkey() );
                } else {
                        // Prolly won't work too good
                        // @todo handle bare namespace names cleanly?
@@ -97,19 +97,14 @@ class PageArchive {
         *
         * @return ResultWrapper
         */
-       function listRevisions( $startTime, $limit ) {
-               $whereClause = array( 'ar_namespace' => $this->title->getNamespace(),
-                       'ar_title' => $this->title->getDBkey() );
-               if ( $startTime && is_numeric($startTime) )
-                       $whereClause[] = "ar_timestamp < $startTime";
-       
+       function listRevisions() {
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select( 'archive',
                        array( 'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text', 'ar_comment', 'ar_len' ),
-                       $whereClause,
+                       array( 'ar_namespace' => $this->title->getNamespace(),
+                              'ar_title' => $this->title->getDBkey() ),
                        'PageArchive::listRevisions',
-                       array( 'ORDER BY' => 'ar_timestamp DESC',
-                                       'LIMIT'   => intval($limit) ) );
+                       array( 'ORDER BY' => 'ar_timestamp DESC' ) );
                $ret = $dbr->resultObject( $res );
                return $ret;
        }
@@ -137,7 +132,7 @@ class PageArchive {
                                        'fa_user',
                                        'fa_user_text',
                                        'fa_timestamp' ),
-                               array( 'fa_name' => $this->title->getDbKey() ),
+                               array( 'fa_name' => $this->title->getDBkey() ),
                                __METHOD__,
                                array( 'ORDER BY' => 'fa_timestamp DESC' ) );
                        $ret = $dbr->resultObject( $res );
@@ -179,7 +174,7 @@ class PageArchive {
                                'ar_text_id',
                                'ar_len' ),
                        array( 'ar_namespace' => $this->title->getNamespace(),
-                              'ar_title' => $this->title->getDbkey(),
+                              'ar_title' => $this->title->getDBkey(),
                               'ar_timestamp' => $dbr->timestamp( $timestamp ) ),
                        __METHOD__ );
                if( $row ) {
@@ -217,7 +212,7 @@ class PageArchive {
                $row = $dbr->selectRow( 'archive',
                        'ar_timestamp',
                        array( 'ar_namespace' => $this->title->getNamespace(),
-                              'ar_title' => $this->title->getDbkey(),
+                              'ar_title' => $this->title->getDBkey(),
                               'ar_timestamp < ' .
                                                $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ),
                        __METHOD__,
@@ -230,7 +225,7 @@ class PageArchive {
                        array( 'rev_id', 'rev_timestamp' ),
                        array(
                                'page_namespace' => $this->title->getNamespace(),
-                               'page_title' => $this->title->getDbkey(),
+                               'page_title' => $this->title->getDBkey(),
                                'page_id = rev_page',
                                'rev_timestamp < ' .
                                                $dbr->addQuotes( $dbr->timestamp( $timestamp ) ) ),
@@ -308,9 +303,6 @@ class PageArchive {
                return ($n > 0);
        }
 
-       const UNDELETE_NOTHINGRESTORED = 0; // No revisions could be restored
-       const UNDELETE_NOTAVAIL = -1; // Not all requested revisions are available
-       const UNDELETE_UNKNOWNERR = -2; // Unknown error
        /**
         * Restore the given (or all) text and file revisions for the page.
         * Once restored, the items will be removed from the archive tables.
@@ -320,7 +312,8 @@ class PageArchive {
         * @param string $comment
         * @param array $fileVersions
         *
-        * @return array(number of revisions restored, number of file versions restored, log reason) on success or UNDELETE_* on failure
+        * @return array(number of file revisions restored, number of image revisions restored, log message)
+        * on success, false on failure
         */
        function undelete( $timestamps, $comment = '', $fileVersions = array() ) {
                // If both the set of text revisions and file revisions are empty,
@@ -340,8 +333,8 @@ class PageArchive {
                
                if( $restoreText ) {
                        $textRestored = $this->undeleteRevisions( $timestamps );
-                       if($textRestored < 0) // It must be one of UNDELETE_*
-                               return $textRestored;
+                       if($textRestored === false) // It must be one of UNDELETE_*
+                               return false;
                } else {
                        $textRestored = 0;
                }
@@ -362,7 +355,7 @@ class PageArchive {
                                $wgContLang->formatNum( $filesRestored ) );
                } else {
                        wfDebug( "Undelete: nothing undeleted...\n" );
-                       return self::UNDELETE_NOTHINGRESTORED;
+                       return false;
                }
                
                if( trim( $comment ) != '' )
@@ -381,10 +374,11 @@ class PageArchive {
         * @param string $comment
         * @param array $fileVersions
         *
-        * @return int number of revisions restored on success or UNDELETE_* on failure
+        * @return mixed number of revisions restored or false on failure
         */
        private function undeleteRevisions( $timestamps ) {
-               if ( wfReadOnly() ) return 0;
+               if ( wfReadOnly() )
+                       return false;
 
                $restoreAll = empty( $timestamps );
                
@@ -437,6 +431,7 @@ class PageArchive {
                                'ar_minor_edit',
                                'ar_flags',
                                'ar_text_id',
+                               'ar_page_id',
                                'ar_len' ),
                        /* WHERE */ array(
                                'ar_namespace' => $this->title->getNamespace(),
@@ -448,7 +443,7 @@ class PageArchive {
                        );
                if( $dbw->numRows( $result ) < count( $timestamps ) ) {
                        wfDebug( __METHOD__.": couldn't find all requested rows\n" );
-                       return self::UNDELETE_NOTAVAIL;
+                       return false;
                }
                
                $revision = null;
@@ -481,6 +476,8 @@ class PageArchive {
                                ) );
                        $revision->insertOn( $dbw );
                        $restored++;
+                       
+                       wfRunHooks( 'ArticleRevisionUndeleted', array( &$this->title, $revision, $row->ar_page_id ) );
                }
                // Was anything restored at all?
                if($restored == 0)
@@ -827,7 +824,7 @@ class UndeleteForm {
        }
 
        /* private */ function showHistory() {
-               global $wgLang, $wgContLang, $wgUser, $wgOut, $wgRequest;
+               global $wgLang, $wgContLang, $wgUser, $wgOut;
 
                $sk = $wgUser->getSkin();
                if ( $this->mAllowed ) {
@@ -851,32 +848,12 @@ class UndeleteForm {
                }
 
                # List all stored revisions
-               $tmpLimit = $wgRequest->getIntOrNull ( 'limit' );
-               $tmpLimit = (is_null($tmpLimit))? 5001 : $tmpLimit + 1;
-               $revisions = $archive->listRevisions( $wgRequest->getVal ( 'offset' ),
-                       $tmpLimit );
+               $revisions = $archive->listRevisions();
                $files = $archive->listFiles();
 
                $haveRevisions = $revisions && $revisions->numRows() > 0;
                $haveFiles = $files && $files->numRows() > 0;
 
-               $hasMore = false;
-               if ( $revisions && $revisions->numRows() >= $tmpLimit ) {
-                       if ( $revisions->numRows() >= 2 ) {
-                               $revisions->seek ( $revisions->numRows() - 2 );
-                               $tmp = $revisions->fetchObject();
-                               $revisions->rewind ( );
-                               $offset = $tmp->ar_timestamp;
-                       } else
-                               $offset = 0;
-
-                       $titleObj = SpecialPage::getTitleFor ( 'Undelete' );
-                       $tmplink = $sk->makeKnownLinkObj ( $titleObj, wfMsg( 'undelete-next-revs', 5000 ), 
-                               "target={$this->mTarget}&limit=5000&offset=$offset" );
-       
-                       $wgOut->addHTML ( wfMsg ( 'undelete-more-revs', $tmpLimit - 1, $tmplink ) );
-                       $hasMore = true;
-               }
                # Batch existence check on user and talk pages
                if( $haveRevisions ) {
                        $batch = new LinkBatch();
@@ -960,17 +937,16 @@ class UndeleteForm {
                        $target = urlencode( $this->mTarget );
                        $remaining = $revisions->numRows();
                        $earliestLiveTime = $this->getEarliestTime( $this->mTargetObj );
-
-                       if ( $hasMore ) $remaining --;
-
-                       while( ( $row = $revisions->fetchObject() ) && $remaining-- ) {
+                       
+                       while( $row = $revisions->fetchObject() ) {
+                               $remaining--;
                                $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
                                if ( $this->mAllowed ) {
                                        $checkBox = Xml::check( "ts$ts" );
                                        $pageLink = $sk->makeKnownLinkObj( $titleObj,
                                                $wgLang->timeanddate( $ts, true ),
                                                "target=$target&timestamp=$ts" );
-                                       if( ($remaining > 0 || $hasMore ) ||
+                                       if( ($remaining > 0) ||
                                                        ($earliestLiveTime && $ts > $earliestLiveTime ) ) {
                                                $diffLink = '(' .
                                                        $sk->makeKnownLinkObj( $titleObj,
@@ -1061,6 +1037,10 @@ class UndeleteForm {
 
        function undelete() {
                global $wgOut, $wgUser;
+               if ( wfReadOnly() ) {
+                       $wgOut->readOnlyPage();
+                       return;
+               }
                if( !is_null( $this->mTargetObj ) ) {
                        $archive = new PageArchive( $this->mTargetObj );