Index: trunk/extensions/Push/includes/Push_Functions.php |
— | — | @@ -136,4 +136,22 @@ |
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
| 140 | + /** |
| 141 | + * Returns a new instance of the (MW)HttpRequest class. |
| 142 | + * This is needed to take care of the rename that happened in MediaWiki 1.17. |
| 143 | + * |
| 144 | + * @since 0.5 |
| 145 | + * |
| 146 | + * @param string $target |
| 147 | + * @param array $args |
| 148 | + * |
| 149 | + * @return (MW)HttpRequest |
| 150 | + */ |
| 151 | + public static function getHttpRequest( $target, $args ) { |
| 152 | + return call_user_func_array( |
| 153 | + array( ( class_exists( 'MWHttpRequest' ) ? 'MWHttpRequest' : 'HttpRequest' ), 'factory' ), |
| 154 | + array( $target, $args ) |
| 155 | + ); |
| 156 | + } |
| 157 | + |
140 | 158 | } |
\ No newline at end of file |
Index: trunk/extensions/Push/api/ApiPush.php |
— | — | @@ -108,8 +108,9 @@ |
109 | 109 | * @param string $target |
110 | 110 | * @param string $token |
111 | 111 | * @param CookieJar $cookie |
| 112 | + * @param integer $attemtNr |
112 | 113 | */ |
113 | | - protected function doLogin( $user, $password, $target, $token = null, $cookieJar = null ) { |
| 114 | + protected function doLogin( $user, $password, $target, $token = null, $cookieJar = null, $attemtNr = 0 ) { |
114 | 115 | $requestData = array( |
115 | 116 | 'action' => 'login', |
116 | 117 | 'format' => 'json', |
— | — | @@ -121,28 +122,30 @@ |
122 | 123 | $requestData['lgtoken'] = $token; |
123 | 124 | } |
124 | 125 | |
125 | | - $req = MWHttpRequest::factory( $target, |
| 126 | + $req = PushFunctions::getHttpRequest( $target, |
126 | 127 | array( |
127 | 128 | 'postData' => $requestData, |
128 | 129 | 'method' => 'POST', |
129 | 130 | 'timeout' => 'default' |
130 | 131 | ) |
131 | 132 | ); |
132 | | - |
| 133 | + |
133 | 134 | if ( !is_null( $cookieJar ) ) { |
134 | 135 | $req->setCookieJar( $cookieJar ); |
135 | | - } |
| 136 | + } |
136 | 137 | |
137 | 138 | $status = $req->execute(); |
138 | 139 | |
| 140 | + $attemtNr++; |
| 141 | + |
139 | 142 | if ( $status->isOK() ) { |
140 | 143 | $response = FormatJson::decode( $req->getContent() ); |
141 | 144 | |
142 | 145 | if ( property_exists( $response, 'login' ) |
143 | 146 | && property_exists( $response->login, 'result' ) ) { |
144 | 147 | |
145 | | - if ( $response->login->result == 'NeedToken' ) { |
146 | | - $this->doLogin( $user, $password, $target, $response->login->token, $req->getCookieJar() ); |
| 148 | + if ( $response->login->result == 'NeedToken' && $attemtNr < 3 ) { |
| 149 | + $this->doLogin( $user, $password, $target, $response->login->token, $req->getCookieJar(), $attemtNr ); |
147 | 150 | } |
148 | 151 | else if ( $response->login->result == 'Success' ) { |
149 | 152 | $this->cookieJars[$target] = $req->getCookieJar(); |
— | — | @@ -258,7 +261,7 @@ |
259 | 262 | $parts[] = $key . '=' . urlencode( $value ); |
260 | 263 | } |
261 | 264 | |
262 | | - $req = MWHttpRequest::factory( $target . '?' . implode( '&', $parts ), |
| 265 | + $req = PushFunctions::getHttpRequest( $target . '?' . implode( '&', $parts ), |
263 | 266 | array( |
264 | 267 | 'method' => 'GET', |
265 | 268 | 'timeout' => 'default' |
— | — | @@ -332,7 +335,7 @@ |
333 | 336 | 'token' => $token, |
334 | 337 | ); |
335 | 338 | |
336 | | - $req = MWHttpRequest::factory( $target, |
| 339 | + $req = PushFunctions::getHttpRequest( $target, |
337 | 340 | array( |
338 | 341 | 'method' => 'POST', |
339 | 342 | 'timeout' => 'default', |
Index: trunk/extensions/Push/api/ApiPushImages.php |
— | — | @@ -84,8 +84,9 @@ |
85 | 85 | * @param string $target |
86 | 86 | * @param string $token |
87 | 87 | * @param CookieJar $cookie |
| 88 | + * @param integer $attemtNr |
88 | 89 | */ |
89 | | - protected function doLogin( $user, $password, $target, $token = null, $cookieJar = null ) { |
| 90 | + protected function doLogin( $user, $password, $target, $token = null, $cookieJar = null, $attemtNr = 0 ) { |
90 | 91 | $requestData = array( |
91 | 92 | 'action' => 'login', |
92 | 93 | 'format' => 'json', |
— | — | @@ -97,7 +98,7 @@ |
98 | 99 | $requestData['lgtoken'] = $token; |
99 | 100 | } |
100 | 101 | |
101 | | - $req = MWHttpRequest::factory( $target, |
| 102 | + $req = PushFunctions::getHttpRequest( $target, |
102 | 103 | array( |
103 | 104 | 'postData' => $requestData, |
104 | 105 | 'method' => 'POST', |
— | — | @@ -111,14 +112,16 @@ |
112 | 113 | |
113 | 114 | $status = $req->execute(); |
114 | 115 | |
| 116 | + $attemtNr++; |
| 117 | + |
115 | 118 | if ( $status->isOK() ) { |
116 | 119 | $response = FormatJson::decode( $req->getContent() ); |
117 | 120 | |
118 | 121 | if ( property_exists( $response, 'login' ) |
119 | 122 | && property_exists( $response->login, 'result' ) ) { |
120 | 123 | |
121 | | - if ( $response->login->result == 'NeedToken' ) { |
122 | | - $this->doLogin( $user, $password, $target, $response->login->token, $req->getCookieJar() ); |
| 124 | + if ( $response->login->result == 'NeedToken' && $attemtNr < 3 ) { |
| 125 | + $this->doLogin( $user, $password, $target, $response->login->token, $req->getCookieJar(), $attemtNr ); |
123 | 126 | } |
124 | 127 | else if ( $response->login->result == 'Success' ) { |
125 | 128 | $this->cookieJars[$target] = $req->getCookieJar(); |
— | — | @@ -180,7 +183,7 @@ |
181 | 184 | $parts[] = $key . '=' . urlencode( $value ); |
182 | 185 | } |
183 | 186 | |
184 | | - $req = MWHttpRequest::factory( $target . '?' . implode( '&', $parts ), |
| 187 | + $req = PushFunctions::getHttpRequest( $target . '?' . implode( '&', $parts ), |
185 | 188 | array( |
186 | 189 | 'method' => 'GET', |
187 | 190 | 'timeout' => 'default' |
— | — | @@ -245,7 +248,7 @@ |
246 | 249 | 'ignorewarnings' => '1' |
247 | 250 | ); |
248 | 251 | |
249 | | - $req = MWHttpRequest::factory( $target, |
| 252 | + $req = PushFunctions::getHttpRequest( $target, |
250 | 253 | array( |
251 | 254 | 'method' => 'POST', |
252 | 255 | 'timeout' => 'default', |