Index: trunk/extensions/Push/Push_Settings.php |
— | — | @@ -29,8 +29,8 @@ |
30 | 30 | $egPushIncTemplates = false; |
31 | 31 | |
32 | 32 | $egPushAllowLogin = true; |
33 | | -$egPushLodignUser = ''; |
34 | | -$egPushLodignPass = ''; |
| 33 | +$egPushLoginUser = ''; |
| 34 | +$egPushLoginPass = ''; |
35 | 35 | |
36 | 36 | $egPushBulkWorkers = 3; |
37 | 37 | $egPushBatchSize = 3; |
Index: trunk/extensions/Push/includes/Push_Tab.php |
— | — | @@ -294,7 +294,7 @@ |
295 | 295 | $wgOut->addHTML( |
296 | 296 | Html::rawElement( |
297 | 297 | 'div', |
298 | | - array( 'id' => 'divIncTemplates' ), |
| 298 | + array( 'id' => 'divIncTemplates', 'style' => 'display: table-cell' ), |
299 | 299 | Xml::check( 'checkIncTemplates', $egPushIncTemplates, array( 'id' => 'checkIncTemplates' ) ) . |
300 | 300 | Html::element( |
301 | 301 | 'label', |
Index: trunk/extensions/Push/api/ApiPush.php |
— | — | @@ -14,6 +14,16 @@ |
15 | 15 | |
16 | 16 | protected $editResponses = array(); |
17 | 17 | |
| 18 | + /** |
| 19 | + * Associative array containing CookieJar objects (values) to be passed in |
| 20 | + * order to autenticate to the targets (keys). |
| 21 | + * |
| 22 | + * @since 0.4 |
| 23 | + * |
| 24 | + * @var array |
| 25 | + */ |
| 26 | + protected $cookieJars = array(); |
| 27 | + |
18 | 28 | public function __construct( $main, $action ) { |
19 | 29 | parent::__construct( $main, $action ); |
20 | 30 | } |
— | — | @@ -29,6 +39,17 @@ |
30 | 40 | $this->dieUsageMsg( array( 'missingparam', 'targets' ) ); |
31 | 41 | } |
32 | 42 | |
| 43 | + foreach ( $params['targets'] as &$target ) { |
| 44 | + if ( substr( $target, -1 ) !== '/' ) { |
| 45 | + $target .= '/'; |
| 46 | + } |
| 47 | + |
| 48 | + $target .= 'api.php'; |
| 49 | + } |
| 50 | + |
| 51 | + global $egPushLoginUser, $egPushLoginPass; |
| 52 | + $this->doLogin( $egPushLoginUser, $egPushLoginPass, $params['targets'] ); |
| 53 | + |
33 | 54 | foreach ( $params['page'] as $page ) { |
34 | 55 | $title = Title::newFromText( $page ); |
35 | 56 | |
— | — | @@ -68,6 +89,70 @@ |
69 | 90 | } |
70 | 91 | |
71 | 92 | /** |
| 93 | + * Logs in into the target wiki using the provided username and password. |
| 94 | + * |
| 95 | + * @since 0.4 |
| 96 | + * |
| 97 | + * @param string $user |
| 98 | + * @param string $password |
| 99 | + * @param array $targets |
| 100 | + * @param string $token |
| 101 | + * @param CookieJar $cookie |
| 102 | + */ |
| 103 | + protected function doLogin( $user, $password, array $targets, $token = null, $cookieJar = null ) { |
| 104 | + $requestData = array( |
| 105 | + 'action' => 'login', |
| 106 | + 'format' => 'json', |
| 107 | + 'lgname' => $user, |
| 108 | + 'lgpassword' => $password |
| 109 | + ); |
| 110 | + |
| 111 | + if ( !is_null( $token ) ) { |
| 112 | + $requestData['lgtoken'] = $token; |
| 113 | + } |
| 114 | + |
| 115 | + foreach ( $targets as $target ) { |
| 116 | + $req = MWHttpRequest::factory( $target, |
| 117 | + array( |
| 118 | + 'postData' => $requestData, |
| 119 | + 'method' => 'POST', |
| 120 | + 'timeout' => 'default' |
| 121 | + ) |
| 122 | + ); |
| 123 | + |
| 124 | + if ( !is_null( $cookieJar ) ) { |
| 125 | + $req->setCookieJar( $cookieJar ); |
| 126 | + } |
| 127 | + |
| 128 | + $status = $req->execute(); |
| 129 | + |
| 130 | + if ( $status->isOK() ) { |
| 131 | + $response = FormatJson::decode( $req->getContent() ); |
| 132 | + |
| 133 | + if ( property_exists( $response, 'login' ) |
| 134 | + && property_exists( $response->login, 'result' ) ) { |
| 135 | + |
| 136 | + if ( $response->login->result == 'NeedToken' ) { |
| 137 | + $this->doLogin( $user, $password, array( $target ), $response->login->token, $req->getCookieJar() ); |
| 138 | + } |
| 139 | + else if ( $response->login->result == 'Success' ) { |
| 140 | + $this->cookieJars[$target] = $req->getCookieJar(); |
| 141 | + } |
| 142 | + else { |
| 143 | + var_dump($response->login);exit; |
| 144 | + } |
| 145 | + } |
| 146 | + else { |
| 147 | + // TODO |
| 148 | + } |
| 149 | + } |
| 150 | + else { |
| 151 | + // TODO |
| 152 | + } |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + /** |
72 | 157 | * Makes an internal request to the API to get the needed revision. |
73 | 158 | * |
74 | 159 | * @since 0.3 |
— | — | @@ -130,13 +215,7 @@ |
131 | 216 | * @param array $targets |
132 | 217 | */ |
133 | 218 | protected function doPush( Title $title, array $revision, array $targets ) { |
134 | | - foreach ( $targets as $target ) { |
135 | | - if ( substr( $target, -1 ) !== '/' ) { |
136 | | - $target .= '/'; |
137 | | - } |
138 | | - |
139 | | - $target .= 'api.php'; |
140 | | - |
| 219 | + foreach ( $targets as $target ) { |
141 | 220 | $token = $this->getEditToken( $title, $target ); |
142 | 221 | |
143 | 222 | if ( $token !== false ) { |
— | — | @@ -171,7 +250,21 @@ |
172 | 251 | $parts[] = $key . '=' . urlencode( $value ); |
173 | 252 | } |
174 | 253 | |
175 | | - $response = FormatJson::decode( Http::get( $target . '?' . implode( '&', $parts ) ) ); |
| 254 | + $req = MWHttpRequest::factory( $target . '?' . implode( '&', $parts ), |
| 255 | + array( |
| 256 | + 'method' => 'GET', |
| 257 | + 'timeout' => 'default' |
| 258 | + ) |
| 259 | + ); |
| 260 | + |
| 261 | + if ( array_key_exists( $target, $this->cookieJars ) ) { |
| 262 | + $req->setCookieJar( $this->cookieJars[$target] ); |
| 263 | + } |
| 264 | + |
| 265 | + $status = $req->execute(); |
| 266 | + |
| 267 | + $response = $status->isOK() ? FormatJson::decode( $req->getContent() ) : null; |
| 268 | + |
176 | 269 | $token = false; |
177 | 270 | |
178 | 271 | if ( !is_null( $response ) |
— | — | @@ -231,12 +324,27 @@ |
232 | 325 | 'token' => $token, |
233 | 326 | ); |
234 | 327 | |
235 | | - $response = Http::post( $target, array( 'postData' => $requestData ) ); |
236 | | - |
237 | | - if ( $response !== false ) { |
238 | | - $this->editResponses[] = $response; |
| 328 | + $req = MWHttpRequest::factory( $target, |
| 329 | + array( |
| 330 | + 'method' => 'POST', |
| 331 | + 'timeout' => 'default', |
| 332 | + 'postData' => $requestData |
| 333 | + ) |
| 334 | + ); |
| 335 | + |
| 336 | + if ( array_key_exists( $target, $this->cookieJars ) ) { |
| 337 | + $req->setCookieJar( $this->cookieJars[$target] ); |
239 | 338 | } |
240 | 339 | else { |
| 340 | + var_dump($this->cookieJars);exit; |
| 341 | + } |
| 342 | + |
| 343 | + $status = $req->execute(); |
| 344 | + |
| 345 | + if ( $status->isOK() ) { |
| 346 | + $this->editResponses[] = $req->getContent(); |
| 347 | + } |
| 348 | + else { |
241 | 349 | $this->dieUsage( wfMsg( 'push-special-err-push-failed' ), 'page-push-failed' ); |
242 | 350 | } |
243 | 351 | } |