Following r100264, update usages in core
[lhc/web/wiklou.git] / includes / specials / SpecialUndelete.php
index 5ee965e..1163a96 100644 (file)
@@ -116,7 +116,7 @@ class PageArchive {
                $res = $dbr->select( 'archive',
                        array(
                                'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text',
-                               'ar_comment', 'ar_len', 'ar_deleted', 'ar_rev_id'
+                               'ar_comment', 'ar_len', 'ar_deleted', 'ar_rev_id', 'ar_sha1'
                        ),
                        array( 'ar_namespace' => $this->title->getNamespace(),
                                   'ar_title' => $this->title->getDBkey() ),
@@ -398,7 +398,7 @@ class PageArchive {
                $dbw = wfGetDB( DB_MASTER );
 
                # Does this page already exist? We'll have to update it...
-               $article = new Article( $this->title );
+               $article = WikiPage::factory( $this->title );
                # Load latest data for the current page (bug 31179)
                $article->loadPageData( 'fromdbmaster' );
                $oldcountable = $article->isCountable();
@@ -460,7 +460,8 @@ class PageArchive {
                                'ar_text_id',
                                'ar_deleted',
                                'ar_page_id',
-                               'ar_len' ),
+                               'ar_len',
+                               'ar_sha1' ),
                        /* WHERE */ array(
                                'ar_namespace' => $this->title->getNamespace(),
                                'ar_title'     => $this->title->getDBkey(),
@@ -580,12 +581,20 @@ class SpecialUndelete extends SpecialPage {
                parent::__construct( 'Undelete', 'deletedhistory' );
        }
 
-       function loadRequest() {
+       function loadRequest( $par ) {
                $request = $this->getRequest();
                $user = $this->getUser();
 
                $this->mAction = $request->getVal( 'action' );
-               $this->mTarget = $request->getVal( 'target' );
+               if ( $par !== null && $par !== '' ) {
+                       $this->mTarget = $par;
+               } else {
+                       $this->mTarget = $request->getVal( 'target' );
+               }
+               $this->mTargetObj = null;
+               if ( $this->mTarget !== null && $this->mTarget !== '' ) {
+                       $this->mTargetObj = Title::newFromURL( $this->mTarget );
+               }
                $this->mSearchPrefix = $request->getText( 'prefix' );
                $time = $request->getVal( 'timestamp' );
                $this->mTimestamp = $time ? wfTimestamp( TS_MW, $time ) : '';
@@ -607,6 +616,7 @@ class SpecialUndelete extends SpecialPage {
                } elseif ( $user->isAllowed( 'deletedtext' ) ) {
                        $this->mAllowed = false; // user cannot restore
                        $this->mCanView = true; // user can view content
+                       $this->mRestore = false;
                } else { // user can only view the list of revisions
                        $this->mAllowed = false;
                        $this->mCanView = false;
@@ -633,94 +643,65 @@ class SpecialUndelete extends SpecialPage {
        }
 
        function execute( $par ) {
-               $this->setHeaders();
-
+               $this->checkPermissions();
                $user = $this->getUser();
-               if ( !$this->userCanExecute( $user ) ) {
-                       $this->displayRestrictionError();
-                       return;
-               }
 
+               $this->setHeaders();
                $this->outputHeader();
 
-               $this->loadRequest();
+               $this->loadRequest( $par );
 
                $out = $this->getOutput();
 
-               if ( $this->mAllowed ) {
-                       $out->setPageTitleMsg( 'undeletepage' );
-               } else {
-                       $out->setPageTitleMsg( 'viewdeletedpage' );
-               }
-
-               if( $par != '' ) {
-                       $this->mTarget = $par;
-               }
-               if ( $this->mTarget !== '' ) {
-                       $this->mTargetObj = Title::newFromURL( $this->mTarget );
-                       $this->getSkin()->setRelevantTitle( $this->mTargetObj );
-               } else {
-                       $this->mTargetObj = null;
-               }
-
-               if( is_null( $this->mTargetObj ) ) {
+               if ( is_null( $this->mTargetObj ) ) {
+                       $out->addWikiMsg( 'undelete-header' );
+       
                        # Not all users can just browse every deleted page from the list
-                       if( $user->isAllowed( 'browsearchive' ) ) {
+                       if ( $user->isAllowed( 'browsearchive' ) ) {
                                $this->showSearchForm();
-
-                               # List undeletable articles
-                               if( $this->mSearchPrefix ) {
-                                       $result = PageArchive::listPagesByPrefix( $this->mSearchPrefix );
-                                       $this->showList( $result );
-                               }
-                       } else {
-                               $out->addWikiMsg( 'undelete-header' );
                        }
                        return;
                }
-               if( $this->mTimestamp !== '' ) {
-                       return $this->showRevision( $this->mTimestamp );
+
+               if ( $this->mAllowed ) {
+                       $out->setPageTitle( $this->msg( 'undeletepage' ) );
+               } else {
+                       $out->setPageTitle( $this->msg( 'viewdeletedpage' ) );
                }
-               if( $this->mFilename !== null ) {
+
+               $this->getSkin()->setRelevantTitle( $this->mTargetObj );
+
+               if ( $this->mTimestamp !== '' ) {
+                       $this->showRevision( $this->mTimestamp );
+               } elseif ( $this->mFilename !== null ) {
                        $file = new ArchivedFile( $this->mTargetObj, '', $this->mFilename );
                        // Check if user is allowed to see this file
                        if ( !$file->exists() ) {
                                $out->addWikiMsg( 'filedelete-nofile', $this->mFilename );
-                               return;
-                       } elseif( !$file->userCan( File::DELETED_FILE, $user ) ) {
+                       } elseif ( !$file->userCan( File::DELETED_FILE, $user ) ) {
                                if( $file->isDeleted( File::DELETED_RESTRICTED ) ) {
-                                       $out->permissionRequired( 'suppressrevision' );
+                                       throw new PermissionsError( 'suppressrevision' );
                                } else {
-                                       $out->permissionRequired( 'deletedtext' );
+                                       throw new PermissionsError( 'deletedtext' );
                                }
-                               return false;
                        } elseif ( !$user->matchEditToken( $this->mToken, $this->mFilename ) ) {
                                $this->showFileConfirmationForm( $this->mFilename );
-                               return false;
                        } else {
-                               return $this->showFile( $this->mFilename );
+                               $this->showFile( $this->mFilename );
                        }
+               } elseif ( $this->mRestore && $this->mAction == 'submit' ) {
+                       $this->undelete();
+               } else {
+                       $this->showHistory();
                }
-               if( $this->mRestore && $this->mAction == 'submit' ) {
-                       global $wgUploadMaintenance;
-                       if( $wgUploadMaintenance && $this->mTargetObj && $this->mTargetObj->getNamespace() == NS_FILE ) {
-                               $out->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n", array( 'filedelete-maintenance' ) );
-                               return;
-                       }
-                       return $this->undelete();
-               }
-               if( $this->mInvert && $this->mAction == 'submit' ) {
-                       return $this->showHistory();
-               }
-               return $this->showHistory();
        }
 
        function showSearchForm() {
                global $wgScript;
 
-               $this->getOutput()->addWikiMsg( 'undelete-header' );
-
-               $this->getOutput()->addHTML(
+               $out = $this->getOutput();
+               $out->setPageTitle( $this->msg( 'undelete-search-title' ) );
+               $out->addHTML(
                        Xml::openElement( 'form', array(
                                'method' => 'get',
                                'action' => $wgScript ) ) .
@@ -734,6 +715,12 @@ class SpecialUndelete extends SpecialPage {
                        Xml::closeElement( 'fieldset' ) .
                        Xml::closeElement( 'form' )
                );
+
+               # List undeletable articles
+               if( $this->mSearchPrefix ) {
+                       $result = PageArchive::listPagesByPrefix( $this->mSearchPrefix );
+                       $this->showList( $result );
+               }
        }
 
        /**
@@ -801,8 +788,6 @@ class SpecialUndelete extends SpecialPage {
                        }
                }
 
-               $out->setPageTitleMsg( 'undeletepage' );
-
                if( $this->mDiff ) {
                        $previousRev = $archive->getPreviousRevision( $timestamp );
                        if( $previousRev ) {
@@ -877,7 +862,7 @@ class SpecialUndelete extends SpecialPage {
                        Xml::element( 'input', array(
                                'type' => 'hidden',
                                'name' => 'wpEditToken',
-                               'value' => $user->editToken() ) ) .
+                               'value' => $user->getEditToken() ) ) .
                        Xml::element( 'input', array(
                                'type' => 'submit',
                                'name' => 'preview',
@@ -899,7 +884,7 @@ class SpecialUndelete extends SpecialPage {
         * @return String: HTML
         */
        function showDiff( $previousRev, $currentRev ) {
-               $diffEngine = new DifferenceEngine( $previousRev->getTitle() );
+               $diffEngine = new DifferenceEngine( $this->getContext() );
                $diffEngine->showDiffStyle();
                $this->getOutput()->addHTML(
                        "<div>" .
@@ -983,7 +968,7 @@ class SpecialUndelete extends SpecialPage {
                                'action' => $this->getTitle()->getLocalURL(
                                        'target=' . urlencode( $this->mTarget ) .
                                        '&file=' . urlencode( $key ) .
-                                       '&token=' . urlencode( $this->getUser()->editToken( $key ) ) )
+                                       '&token=' . urlencode( $this->getUser()->getEditToken( $key ) ) )
                                )
                        ) .
                        Xml::submitButton( wfMsg( 'undelete-show-file-submit' ) ) .
@@ -1015,9 +1000,6 @@ class SpecialUndelete extends SpecialPage {
                $out = $this->getOutput();
                if( $this->mAllowed ) {
                        $out->addModules( 'mediawiki.special.undelete' );
-                       $out->setPageTitleMsg( 'undeletepage' );
-               } else {
-                       $out->setPageTitleMsg( 'viewdeletedpage' );
                }
                $out->wrapWikiMsg(
                        "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
@@ -1161,7 +1143,7 @@ class SpecialUndelete extends SpecialPage {
                if ( $this->mAllowed ) {
                        # Slip in the hidden controls here
                        $misc  = Html::hidden( 'target', $this->mTarget );
-                       $misc .= Html::hidden( 'wpEditToken', $this->getUser()->editToken() );
+                       $misc .= Html::hidden( 'wpEditToken', $this->getUser()->getEditToken() );
                        $misc .= Xml::closeElement( 'form' );
                        $out->addHTML( $misc );
                }
@@ -1319,7 +1301,7 @@ class SpecialUndelete extends SpecialPage {
                                array(
                                        'target' => $this->mTargetObj->getPrefixedText(),
                                        'file' => $key,
-                                       'token' => $this->getUser()->editToken( $key )
+                                       'token' => $this->getUser()->getEditToken( $key )
                                )
                        );
                        if( $file->isDeleted( File::DELETED_FILE ) ) {
@@ -1368,41 +1350,44 @@ class SpecialUndelete extends SpecialPage {
        }
 
        function undelete() {
+               global $wgUploadMaintenance;
+
+               if ( $wgUploadMaintenance && $this->mTargetObj->getNamespace() == NS_FILE ) {
+                       throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
+               }
+
                if ( wfReadOnly() ) {
                        throw new ReadOnlyError;
                }
 
-               if( !is_null( $this->mTargetObj ) ) {
-                       $archive = new PageArchive( $this->mTargetObj );
-                       wfRunHooks( 'UndeleteForm::undelete', array( &$archive, $this->mTargetObj ) );
-                       $ok = $archive->undelete(
-                               $this->mTargetTimestamp,
-                               $this->mComment,
-                               $this->mFileVersions,
-                               $this->mUnsuppress );
-
-                       if( is_array( $ok ) ) {
-                               if ( $ok[1] ) { // Undeleted file count
-                                       wfRunHooks( 'FileUndeleteComplete', array(
-                                               $this->mTargetObj, $this->mFileVersions,
-                                               $this->getUser(), $this->mComment ) );
-                               }
-
-                               $link = Linker::linkKnown( $this->mTargetObj );
-                               $this->getOutput()->addHTML( wfMessage( 'undeletedpage' )->rawParams( $link )->parse() );
-                       } else {
-                               $this->getOutput()->showFatalError( wfMsg( 'cannotundelete' ) );
-                               $this->getOutput()->addWikiMsg( 'undeleterevdel' );
+               $out = $this->getOutput();
+               $archive = new PageArchive( $this->mTargetObj );
+               wfRunHooks( 'UndeleteForm::undelete', array( &$archive, $this->mTargetObj ) );
+               $ok = $archive->undelete(
+                       $this->mTargetTimestamp,
+                       $this->mComment,
+                       $this->mFileVersions,
+                       $this->mUnsuppress );
+
+               if( is_array( $ok ) ) {
+                       if ( $ok[1] ) { // Undeleted file count
+                               wfRunHooks( 'FileUndeleteComplete', array(
+                                       $this->mTargetObj, $this->mFileVersions,
+                                       $this->getUser(), $this->mComment ) );
                        }
 
-                       // Show file deletion warnings and errors
-                       $status = $archive->getFileStatus();
-                       if( $status && !$status->isGood() ) {
-                               $this->getOutput()->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) );
-                       }
+                       $link = Linker::linkKnown( $this->mTargetObj );
+                       $out->addHTML( $this->msg( 'undeletedpage' )->rawParams( $link )->parse() );
                } else {
-                       $this->getOutput()->showFatalError( wfMsg( 'cannotundelete' ) );
+                       $out->setPageTitle( $this->msg( 'undelete-error' ) );
+                       $out->addWikiMsg( 'cannotundelete' );
+                       $out->addWikiMsg( 'undeleterevdel' );
+               }
+
+               // Show file deletion warnings and errors
+               $status = $archive->getFileStatus();
+               if( $status && !$status->isGood() ) {
+                       $out->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) );
                }
-               return false;
        }
 }