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'] ),
}
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'] ) );
}
$this->dieUsageMsg( array( 'notanarticle' ) );
}
- return array( $this->mTitleObj->getPrefixedText(), $this->username );
+ return $this->mTitleObj;
}
protected function getExamples() {
parent::__construct( $main, $action );
}
+ private $mUser = null;
+
public function execute() {
$params = $this->extractRequestParams();
- // User already validated in call to getTokenSalt from Main
- $form = new UserrightsPage;
- $user = $form->fetchUser( $params['user'] );
+ $user = $this->getUser();
$r['user'] = $user->getName();
list( $r['added'], $r['removed'] ) =
}
public function getTokenSalt() {
+ return $this->getUser()->getName();
+ }
+
+ private function getUser() {
+ if ( $this->mUser !== null ) {
+ return $this->mUser;
+ }
+
$params = $this->extractRequestParams();
if ( is_null( $params['user'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'user' ) );
(array)$user->getMessageKey(), $user->getMessageArgs() ) );
}
- return $user->getName();
+ $this->mUser = $user;
+ return $user;
}
protected function getExamples() {