Index: trunk/phase3/includes/api/ApiRollback.php |
— | — | @@ -36,27 +36,27 @@ |
37 | 37 | parent::__construct( $main, $action ); |
38 | 38 | } |
39 | 39 | |
40 | | - private $mTitleObj = null; |
| 40 | + private $mTitleObj = null, $mUser = null; |
41 | 41 | |
42 | 42 | public function execute() { |
43 | 43 | $params = $this->extractRequestParams(); |
44 | 44 | |
45 | 45 | // User and title already validated in call to getTokenSalt from Main |
46 | | - |
47 | | - $articleObj = new Article( $this->mTitleObj ); |
| 46 | + $titleObj = $this->getTitle(); |
| 47 | + $articleObj = new Article( $titleObj ); |
48 | 48 | $summary = ( isset( $params['summary'] ) ? $params['summary'] : '' ); |
49 | 49 | $details = null; |
50 | | - $retval = $articleObj->doRollback( $this->username, $summary, $params['token'], $params['markbot'], $details ); |
| 50 | + $retval = $articleObj->doRollback( $this->getUser(), $summary, $params['token'], $params['markbot'], $details ); |
51 | 51 | |
52 | 52 | if ( $retval ) { |
53 | 53 | // We don't care about multiple errors, just report one of them |
54 | 54 | $this->dieUsageMsg( reset( $retval ) ); |
55 | 55 | } |
56 | 56 | |
57 | | - $this->setWatch( $params['watchlist'], $this->mTitleObj ); |
| 57 | + $this->setWatch( $params['watchlist'], $titleObj ); |
58 | 58 | |
59 | 59 | $info = array( |
60 | | - 'title' => $this->mTitleObj->getPrefixedText(), |
| 60 | + 'title' => $titleObj->getPrefixedText(), |
61 | 61 | 'pageid' => intval( $details['current']->getPage() ), |
62 | 62 | 'summary' => $details['summary'], |
63 | 63 | 'revid' => intval( $details['newid'] ), |
— | — | @@ -123,25 +123,43 @@ |
124 | 124 | } |
125 | 125 | |
126 | 126 | public function getTokenSalt() { |
| 127 | + return array( $this->getTitle()->getPrefixedText(), $this->getUser() ); |
| 128 | + } |
| 129 | + |
| 130 | + private function getUser() { |
| 131 | + if ( $this->mUser !== null ) { |
| 132 | + return $this->mUser; |
| 133 | + } |
| 134 | + |
127 | 135 | $params = $this->extractRequestParams(); |
128 | | - |
| 136 | + |
129 | 137 | if ( !isset( $params['user'] ) ) { |
130 | 138 | $this->dieUsageMsg( array( 'missingparam', 'user' ) ); |
131 | 139 | } |
132 | 140 | |
133 | 141 | // We need to be able to revert IPs, but getCanonicalName rejects them |
134 | | - $this->username = User::isIP( $params['user'] ) |
| 142 | + $this->mUser = User::isIP( $params['user'] ) |
135 | 143 | ? $params['user'] |
136 | 144 | : User::getCanonicalName( $params['user'] ); |
137 | | - if ( !$this->username ) { |
| 145 | + if ( !$this->mUser ) { |
138 | 146 | $this->dieUsageMsg( array( 'invaliduser', $params['user'] ) ); |
139 | 147 | } |
140 | | - |
| 148 | + |
| 149 | + return $this->mUser; |
| 150 | + } |
| 151 | + |
| 152 | + private function getTitle() { |
| 153 | + if ( $this->mTitleObj !== null ) { |
| 154 | + return $this->mTitleObj; |
| 155 | + } |
| 156 | + |
| 157 | + $params = $this->extractRequestParams(); |
141 | 158 | if ( !isset( $params['title'] ) ) { |
142 | | - $this->dieUsageMsg( array( 'missingparam', 'title' ) ); |
| 159 | + $this->dieUsageMsg( array( 'missingparam', 'title' ) ); |
143 | 160 | } |
144 | | - |
| 161 | + |
145 | 162 | $this->mTitleObj = Title::newFromText( $params['title'] ); |
| 163 | + |
146 | 164 | if ( !$this->mTitleObj ) { |
147 | 165 | $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); |
148 | 166 | } |
— | — | @@ -149,7 +167,7 @@ |
150 | 168 | $this->dieUsageMsg( array( 'notanarticle' ) ); |
151 | 169 | } |
152 | 170 | |
153 | | - return array( $this->mTitleObj->getPrefixedText(), $this->username ); |
| 171 | + return $this->mTitleObj; |
154 | 172 | } |
155 | 173 | |
156 | 174 | protected function getExamples() { |
Index: trunk/phase3/includes/api/ApiUserrights.php |
— | — | @@ -36,12 +36,12 @@ |
37 | 37 | parent::__construct( $main, $action ); |
38 | 38 | } |
39 | 39 | |
| 40 | + private $mUser = null; |
| 41 | + |
40 | 42 | public function execute() { |
41 | 43 | $params = $this->extractRequestParams(); |
42 | 44 | |
43 | | - // User already validated in call to getTokenSalt from Main |
44 | | - $form = new UserrightsPage; |
45 | | - $user = $form->fetchUser( $params['user'] ); |
| 45 | + $user = $this->getUser(); |
46 | 46 | |
47 | 47 | $r['user'] = $user->getName(); |
48 | 48 | list( $r['added'], $r['removed'] ) = |
— | — | @@ -103,6 +103,14 @@ |
104 | 104 | } |
105 | 105 | |
106 | 106 | public function getTokenSalt() { |
| 107 | + return $this->getUser()->getName(); |
| 108 | + } |
| 109 | + |
| 110 | + private function getUser() { |
| 111 | + if ( $this->mUser !== null ) { |
| 112 | + return $this->mUser; |
| 113 | + } |
| 114 | + |
107 | 115 | $params = $this->extractRequestParams(); |
108 | 116 | if ( is_null( $params['user'] ) ) { |
109 | 117 | $this->dieUsageMsg( array( 'missingparam', 'user' ) ); |
— | — | @@ -115,7 +123,8 @@ |
116 | 124 | (array)$user->getMessageKey(), $user->getMessageArgs() ) ); |
117 | 125 | } |
118 | 126 | |
119 | | - return $user->getName(); |
| 127 | + $this->mUser = $user; |
| 128 | + return $user; |
120 | 129 | } |
121 | 130 | |
122 | 131 | protected function getExamples() { |