$wgStyleVersion!
[lhc/web/wiklou.git] / includes / SpecialUndelete.php
index 786b4c9..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?
@@ -132,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 );
@@ -174,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 ) {
@@ -212,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__,
@@ -225,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 ) ) ),
@@ -312,7 +312,8 @@ class PageArchive {
         * @param string $comment
         * @param array $fileVersions
         *
-        * @return true on success.
+        * @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,
@@ -332,6 +333,8 @@ class PageArchive {
                
                if( $restoreText ) {
                        $textRestored = $this->undeleteRevisions( $timestamps );
+                       if($textRestored === false) // It must be one of UNDELETE_*
+                               return false;
                } else {
                        $textRestored = 0;
                }
@@ -359,11 +362,7 @@ class PageArchive {
                        $reason .= ": {$comment}";
                $log->addEntry( 'restore', $this->title, $reason );
 
-               if ( $this->fileStatus && !$this->fileStatus->ok ) {
-                       return false;
-               } else {
-                       return true;
-               }
+               return array($textRestored, $filesRestored, $reason);
        }
        
        /**
@@ -375,10 +374,11 @@ class PageArchive {
         * @param string $comment
         * @param array $fileVersions
         *
-        * @return int number of revisions restored
+        * @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 );
                
@@ -431,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(),
@@ -475,7 +476,12 @@ class PageArchive {
                                ) );
                        $revision->insertOn( $dbw );
                        $restored++;
+                       
+                       wfRunHooks( 'ArticleRevisionUndeleted', array( &$this->title, $revision, $row->ar_page_id ) );
                }
+               // Was anything restored at all?
+               if($restored == 0)
+                       return 0;
 
                if( $revision ) {
                        // Attach the latest revision to the page...
@@ -494,7 +500,8 @@ class PageArchive {
                                Article::onArticleEdit( $this->title );
                        }
                } else {
-                       # Something went terribly wrong!
+                       // Revision couldn't be created. This is very weird
+                       return self::UNDELETE_UNKNOWNERR;
                }
 
                # Now that it's safely stored, take it out of the archive
@@ -539,7 +546,7 @@ class UndeleteForm {
                if( $par != "" ) {
                        $this->mTarget = $par;
                }
-               if ( $wgUser->isAllowed( 'delete' ) && !$wgUser->isBlocked() ) {
+               if ( $wgUser->isAllowed( 'undelete' ) && !$wgUser->isBlocked() ) {
                        $this->mAllowed = true;
                } else {
                        $this->mAllowed = false;
@@ -667,9 +674,8 @@ class UndeleteForm {
                $wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
                
                $link = $skin->makeKnownLinkObj(
-                       $self,
-                       htmlspecialchars( $this->mTargetObj->getPrefixedText() ),
-                       'target=' . $this->mTargetObj->getPrefixedUrl()
+                       SpecialPage::getTitleFor( 'Undelete', $this->mTargetObj->getPrefixedDBkey() ),
+                       htmlspecialchars( $this->mTargetObj->getPrefixedText() )
                );
                $time = htmlspecialchars( $wgLang->timeAndDate( $timestamp, true ) );
                $user = $skin->userLink( $rev->getUser(), $rev->getUserText() )
@@ -685,7 +691,7 @@ class UndeleteForm {
                                        $wgOut->addHtml( '<hr />' );
                                }
                        } else {
-                               $wgOut->addHtml( 'No previous revision found.' );
+                               $wgOut->addHtml( wfMsgHtml( 'undelete-nodiff' ) );
                        }
                }
                
@@ -1031,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 );
                        
@@ -1039,7 +1049,7 @@ class UndeleteForm {
                                $this->mComment,
                                $this->mFileVersions );
 
-                       if( $ok ) {
+                       if( is_array($ok) ) {
                                $skin = $wgUser->getSkin();
                                $link = $skin->makeKnownLinkObj( $this->mTargetObj );
                                $wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) );