Index: trunk/phase3/includes/api/ApiRollback.php |
— | — | @@ -35,35 +35,15 @@ |
36 | 36 | public function __construct( $main, $action ) { |
37 | 37 | parent::__construct( $main, $action ); |
38 | 38 | } |
| 39 | + |
| 40 | + private $mTitleObj = null; |
39 | 41 | |
40 | 42 | public function execute() { |
41 | 43 | $params = $this->extractRequestParams(); |
42 | 44 | |
43 | | - $titleObj = null; |
44 | | - if ( !isset( $params['title'] ) ) { |
45 | | - $this->dieUsageMsg( array( 'missingparam', 'title' ) ); |
46 | | - } |
47 | | - if ( !isset( $params['user'] ) ) { |
48 | | - $this->dieUsageMsg( array( 'missingparam', 'user' ) ); |
49 | | - } |
| 45 | + // User and title already validated in call to getTokenSalt from Main |
50 | 46 | |
51 | | - $titleObj = Title::newFromText( $params['title'] ); |
52 | | - if ( !$titleObj ) { |
53 | | - $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); |
54 | | - } |
55 | | - if ( !$titleObj->exists() ) { |
56 | | - $this->dieUsageMsg( array( 'notanarticle' ) ); |
57 | | - } |
58 | | - |
59 | | - // We need to be able to revert IPs, but getCanonicalName rejects them |
60 | | - $username = User::isIP( $params['user'] ) |
61 | | - ? $params['user'] |
62 | | - : User::getCanonicalName( $params['user'] ); |
63 | | - if ( !$username ) { |
64 | | - $this->dieUsageMsg( array( 'invaliduser', $params['user'] ) ); |
65 | | - } |
66 | | - |
67 | | - $articleObj = new Article( $titleObj ); |
| 47 | + $articleObj = new Article( $this->mTitleObj ); |
68 | 48 | $summary = ( isset( $params['summary'] ) ? $params['summary'] : '' ); |
69 | 49 | $details = null; |
70 | 50 | $retval = $articleObj->doRollback( $username, $summary, $params['token'], $params['markbot'], $details ); |
— | — | @@ -73,7 +53,7 @@ |
74 | 54 | $this->dieUsageMsg( reset( $retval ) ); |
75 | 55 | } |
76 | 56 | |
77 | | - $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ); |
| 57 | + $watch = $this->getWatchlistValue( $params['watchlist'], $this->mTitleObj ); |
78 | 58 | |
79 | 59 | if ( $watch !== null) { |
80 | 60 | if ( $watch ) { |
— | — | @@ -84,7 +64,7 @@ |
85 | 65 | } |
86 | 66 | |
87 | 67 | $info = array( |
88 | | - 'title' => $titleObj->getPrefixedText(), |
| 68 | + 'title' => $this->mTitleObj->getPrefixedText(), |
89 | 69 | 'pageid' => intval( $details['current']->getPage() ), |
90 | 70 | 'summary' => $details['summary'], |
91 | 71 | 'revid' => intval( $details['newid'] ), |
— | — | @@ -151,7 +131,33 @@ |
152 | 132 | } |
153 | 133 | |
154 | 134 | public function getTokenSalt() { |
155 | | - return ''; |
| 135 | + $params = $this->extractRequestParams(); |
| 136 | + |
| 137 | + if ( !isset( $params['user'] ) ) { |
| 138 | + $this->dieUsageMsg( array( 'missingparam', 'user' ) ); |
| 139 | + } |
| 140 | + |
| 141 | + // We need to be able to revert IPs, but getCanonicalName rejects them |
| 142 | + $this->username = User::isIP( $params['user'] ) |
| 143 | + ? $params['user'] |
| 144 | + : User::getCanonicalName( $params['user'] ); |
| 145 | + if ( !$this->username ) { |
| 146 | + $this->dieUsageMsg( array( 'invaliduser', $params['user'] ) ); |
| 147 | + } |
| 148 | + |
| 149 | + if ( !isset( $params['title'] ) ) { |
| 150 | + $this->dieUsageMsg( array( 'missingparam', 'title' ) ); |
| 151 | + } |
| 152 | + |
| 153 | + $this->mTitleObj = Title::newFromText( $params['title'] ); |
| 154 | + if ( !$this->mTitleObj ) { |
| 155 | + $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); |
| 156 | + } |
| 157 | + if ( !$this->mTitleObj->exists() ) { |
| 158 | + $this->dieUsageMsg( array( 'notanarticle' ) ); |
| 159 | + } |
| 160 | + |
| 161 | + return array( $this->mTitleObj->getPrefixedText(), $this->username ); |
156 | 162 | } |
157 | 163 | |
158 | 164 | protected function getExamples() { |