Localisation updates for core and extension messages from translatewiki.net (2010...
[lhc/web/wiklou.git] / includes / api / ApiRollback.php
index 920f564..27ce389 100644 (file)
@@ -36,27 +36,27 @@ class ApiRollback extends ApiBase {
                parent::__construct( $main, $action );
        }
 
-       private $mTitleObj = null;
+       private $mTitleObj = null, $mUser = null;
 
        public function execute() {
                $params = $this->extractRequestParams();
 
                // User and title already validated in call to getTokenSalt from Main
-
-               $articleObj = new Article( $this->mTitleObj );
+               $titleObj = $this->getTitle();
+               $articleObj = new Article( $titleObj );
                $summary = ( isset( $params['summary'] ) ? $params['summary'] : '' );
                $details = null;
-               $retval = $articleObj->doRollback( $this->username, $summary, $params['token'], $params['markbot'], $details );
+               $retval = $articleObj->doRollback( $this->getUser(), $summary, $params['token'], $params['markbot'], $details );
 
                if ( $retval ) {
                        // We don't care about multiple errors, just report one of them
                        $this->dieUsageMsg( reset( $retval ) );
                }
 
-               $this->setWatch( $params['watchlist'], $this->mTitleObj );
+               $this->setWatch( $params['watchlist'], $titleObj );
 
                $info = array(
-                       'title' => $this->mTitleObj->getPrefixedText(),
+                       'title' => $titleObj->getPrefixedText(),
                        'pageid' => intval( $details['current']->getPage() ),
                        'summary' => $details['summary'],
                        'revid' => intval( $details['newid'] ),
@@ -123,25 +123,43 @@ class ApiRollback extends ApiBase {
        }
 
        public function getTokenSalt() {
+               return array( $this->getTitle()->getPrefixedText(), $this->getUser() );
+       }
+
+       private function getUser() {
+               if ( $this->mUser !== null ) {
+                       return $this->mUser;
+               }
+
                $params = $this->extractRequestParams();
-               
+
                if ( !isset( $params['user'] ) ) {
                        $this->dieUsageMsg( array( 'missingparam', 'user' ) );
                }
                
                // We need to be able to revert IPs, but getCanonicalName rejects them
-               $this->username = User::isIP( $params['user'] )
+               $this->mUser = User::isIP( $params['user'] )
                        ? $params['user']
                        : User::getCanonicalName( $params['user'] );
-               if ( !$this->username ) {
+               if ( !$this->mUser ) {
                        $this->dieUsageMsg( array( 'invaliduser', $params['user'] ) );
                }
-               
+
+               return $this->mUser;
+       }
+
+       private function getTitle() {
+               if ( $this->mTitleObj !== null ) {
+                       return $this->mTitleObj;
+               }
+
+               $params = $this->extractRequestParams();
                if ( !isset( $params['title'] ) ) {
-                       $this->dieUsageMsg( array( 'missingparam', 'title' ) );
+                       $this->dieUsageMsg( array( 'missingparam', 'title' ) ); 
                }
-               
+
                $this->mTitleObj = Title::newFromText( $params['title'] );
+
                if ( !$this->mTitleObj ) {
                        $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
                }
@@ -149,7 +167,7 @@ class ApiRollback extends ApiBase {
                        $this->dieUsageMsg( array( 'notanarticle' ) );
                }
                
-               return array( $this->mTitleObj->getPrefixedText(), $this->username );
+               return $this->mTitleObj;
        }
 
        protected function getExamples() {