r78361 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78360‎ | r78361 | r78362 >
Date:09:38, 14 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added bc with MW 1.16 and prevent infinite loop in authentication method when token request goes wrong
Modified paths:
  • /trunk/extensions/Push/api/ApiPush.php (modified) (history)
  • /trunk/extensions/Push/api/ApiPushImages.php (modified) (history)
  • /trunk/extensions/Push/includes/Push_Functions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Push/includes/Push_Functions.php
@@ -136,4 +136,22 @@
137137 }
138138 }
139139
 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+
140158 }
\ No newline at end of file
Index: trunk/extensions/Push/api/ApiPush.php
@@ -108,8 +108,9 @@
109109 * @param string $target
110110 * @param string $token
111111 * @param CookieJar $cookie
 112+ * @param integer $attemtNr
112113 */
113 - protected function doLogin( $user, $password, $target, $token = null, $cookieJar = null ) {
 114+ protected function doLogin( $user, $password, $target, $token = null, $cookieJar = null, $attemtNr = 0 ) {
114115 $requestData = array(
115116 'action' => 'login',
116117 'format' => 'json',
@@ -121,28 +122,30 @@
122123 $requestData['lgtoken'] = $token;
123124 }
124125
125 - $req = MWHttpRequest::factory( $target,
 126+ $req = PushFunctions::getHttpRequest( $target,
126127 array(
127128 'postData' => $requestData,
128129 'method' => 'POST',
129130 'timeout' => 'default'
130131 )
131132 );
132 -
 133+
133134 if ( !is_null( $cookieJar ) ) {
134135 $req->setCookieJar( $cookieJar );
135 - }
 136+ }
136137
137138 $status = $req->execute();
138139
 140+ $attemtNr++;
 141+
139142 if ( $status->isOK() ) {
140143 $response = FormatJson::decode( $req->getContent() );
141144
142145 if ( property_exists( $response, 'login' )
143146 && property_exists( $response->login, 'result' ) ) {
144147
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 );
147150 }
148151 else if ( $response->login->result == 'Success' ) {
149152 $this->cookieJars[$target] = $req->getCookieJar();
@@ -258,7 +261,7 @@
259262 $parts[] = $key . '=' . urlencode( $value );
260263 }
261264
262 - $req = MWHttpRequest::factory( $target . '?' . implode( '&', $parts ),
 265+ $req = PushFunctions::getHttpRequest( $target . '?' . implode( '&', $parts ),
263266 array(
264267 'method' => 'GET',
265268 'timeout' => 'default'
@@ -332,7 +335,7 @@
333336 'token' => $token,
334337 );
335338
336 - $req = MWHttpRequest::factory( $target,
 339+ $req = PushFunctions::getHttpRequest( $target,
337340 array(
338341 'method' => 'POST',
339342 'timeout' => 'default',
Index: trunk/extensions/Push/api/ApiPushImages.php
@@ -84,8 +84,9 @@
8585 * @param string $target
8686 * @param string $token
8787 * @param CookieJar $cookie
 88+ * @param integer $attemtNr
8889 */
89 - protected function doLogin( $user, $password, $target, $token = null, $cookieJar = null ) {
 90+ protected function doLogin( $user, $password, $target, $token = null, $cookieJar = null, $attemtNr = 0 ) {
9091 $requestData = array(
9192 'action' => 'login',
9293 'format' => 'json',
@@ -97,7 +98,7 @@
9899 $requestData['lgtoken'] = $token;
99100 }
100101
101 - $req = MWHttpRequest::factory( $target,
 102+ $req = PushFunctions::getHttpRequest( $target,
102103 array(
103104 'postData' => $requestData,
104105 'method' => 'POST',
@@ -111,14 +112,16 @@
112113
113114 $status = $req->execute();
114115
 116+ $attemtNr++;
 117+
115118 if ( $status->isOK() ) {
116119 $response = FormatJson::decode( $req->getContent() );
117120
118121 if ( property_exists( $response, 'login' )
119122 && property_exists( $response->login, 'result' ) ) {
120123
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 );
123126 }
124127 else if ( $response->login->result == 'Success' ) {
125128 $this->cookieJars[$target] = $req->getCookieJar();
@@ -180,7 +183,7 @@
181184 $parts[] = $key . '=' . urlencode( $value );
182185 }
183186
184 - $req = MWHttpRequest::factory( $target . '?' . implode( '&', $parts ),
 187+ $req = PushFunctions::getHttpRequest( $target . '?' . implode( '&', $parts ),
185188 array(
186189 'method' => 'GET',
187190 'timeout' => 'default'
@@ -245,7 +248,7 @@
246249 'ignorewarnings' => '1'
247250 );
248251
249 - $req = MWHttpRequest::factory( $target,
 252+ $req = PushFunctions::getHttpRequest( $target,
250253 array(
251254 'method' => 'POST',
252255 'timeout' => 'default',

Status & tagging log