r107711 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107710‎ | r107711 | r107712 >
Date:07:53, 31 December 2011
Author:varnent
Status:deferred (Comments)
Tags:
Comment:
had to switch back to tmhOAuth 0.58 due to glitch I couldn't pinpoint (presumably in changes in 0.60 outside of Reedy's improvements) - also tweaked references to tmhOAuth in extension's body file
Modified paths:
  • /trunk/extensions/TweetANew/TweetANew.body.php (modified) (history)
  • /trunk/extensions/TweetANew/lib/tmhOAuth.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TweetANew/TweetANew.body.php
@@ -245,7 +245,7 @@
246246 }
247247
248248 # Make connection to Twitter
249 - $connection = new tmhOAuth( array(
 249+ $tmhOAuth = new tmhOAuth( array(
250250 'consumer_key' => $wgTweetANewTwitter['ConsumerKey'],
251251 'consumer_secret' => $wgTweetANewTwitter['ConsumerSecret'],
252252 'user_token' => $wgTweetANewTwitter['AccessToken'],
@@ -253,8 +253,8 @@
254254 ) );
255255
256256 # Make tweet message
257 - $connection->request( 'POST',
258 - $connection->url( '1/statuses/update' ),
 257+ $tmhOAuth->request( 'POST',
 258+ $tmhOAuth->url( '1/statuses/update' ),
259259 array( 'status' => $tweet_text )
260260 );
261261 return true;
Index: trunk/extensions/TweetANew/lib/tmhOAuth.php
@@ -7,12 +7,12 @@
88 * REST requests. OAuth authentication is sent using the an Authorization Header.
99 *
1010 * @author themattharris
11 - * @version 0.60
 11+ * @version 0.57
1212 *
13 - * 29 December 2011
 13+ * 11 December 2011
1414 */
1515 class tmhOAuth {
16 - const VERSION = 0.60;
 16+ const VERSION = 0.57;
1717
1818 /**
1919 * Creates a new tmhOAuth object
@@ -28,40 +28,27 @@
2929 // default configuration options
3030 $this->config = array_merge(
3131 array(
32 - // leave 'user_agent' blank for default, otherwise set this to
33 - // something that clearly identifies your app
34 - 'user_agent' => '',
35 -
36 - 'use_ssl' => true,
37 - 'host' => 'api.twitter.com',
38 -
 32+ 'user_agent' => 'tmhOAuth ' . self::VERSION . ' - //github.com/themattharris/tmhOAuth',
3933 'consumer_key' => '',
4034 'consumer_secret' => '',
4135 'user_token' => '',
4236 'user_secret' => '',
 37+ 'use_ssl' => true,
 38+ 'host' => 'api.twitter.com',
 39+ 'debug' => false,
4340 'force_nonce' => false,
4441 'nonce' => false, // used for checking signatures. leave as false for auto
4542 'force_timestamp' => false,
4643 'timestamp' => false, // used for checking signatures. leave as false for auto
47 -
48 - // oauth signing variables that are not dynamic
4944 'oauth_version' => '1.0',
50 - 'oauth_signature_method' => 'HMAC-SHA1',
5145
5246 // you probably don't want to change any of these curl values
5347 'curl_connecttimeout' => 30,
5448 'curl_timeout' => 10,
55 -
56 - // for security these should always be set to true.
57 - 'curl_ssl_verifyhost' => true,
58 - 'curl_ssl_verifypeer' => true,
59 -
60 - // you can get the latest cacert.pem from here http://curl.haxx.se/ca/cacert.pem
61 - 'curl_cainfo' => dirname(__FILE__) . '/cacert.pem',
62 - 'curl_capath' => dirname(__FILE__),
63 -
 49+ // for security you may want to set this to TRUE. If you do you need
 50+ // to install the servers certificate in your local certificate store.
 51+ 'curl_ssl_verifypeer' => false,
6452 'curl_followlocation' => false, // whether to follow redirects or not
65 -
6653 // support for proxy servers
6754 'curl_proxy' => false, // really you don't want to use this if you are using streaming
6855 'curl_proxyuserpwd' => false, // format username:password for proxy, if required
@@ -72,30 +59,15 @@
7360 'streaming_eol' => "\r\n",
7461 'streaming_metrics_interval' => 60,
7562
76 - // header or querystring. You should always use header!
77 - // this is just to help me debug other developers implementations
 63+ // header or querystring. You should always use header
 64+ // this is just to help me debug other developers
 65+ // implementations
7866 'as_header' => true,
79 - 'debug' => false,
8067 ),
8168 $config
8269 );
83 - $this->set_user_agent();
8470 }
8571
86 - function set_user_agent() {
87 - if (!empty($this->config['user_agent']))
88 - return;
89 -
90 - if ($this->config['curl_ssl_verifyhost'] && $this->config['curl_ssl_verifypeer']) {
91 - $ssl = '+SSL';
92 - } else {
93 - $ssl = '-SSL';
94 - }
95 -
96 - $ua = 'tmhOAuth ' . self::VERSION . $ssl . ' - //github.com/themattharris/tmhOAuth';
97 - $this->config['user_agent'] = $ua;
98 - }
99 -
10072 /**
10173 * Generates a random OAuth nonce.
10274 * If 'force_nonce' is true a nonce is not generated and the value in the configuration will be retained.
@@ -111,7 +83,7 @@
11284 shuffle($sequence);
11385
11486 $prefix = $include_time ? microtime() : '';
115 - $this->config['nonce'] = md5(substr($prefix . implode('', $sequence), 0, $length));
 87+ $this->config['nonce'] = md5(substr($prefix . implode($sequence), 0, $length));
11688 }
11789 }
11890
@@ -174,7 +146,7 @@
175147 'oauth_nonce' => $this->config['nonce'],
176148 'oauth_timestamp' => $this->config['timestamp'],
177149 'oauth_consumer_key' => $this->config['consumer_key'],
178 - 'oauth_signature_method' => $this->config['oauth_signature_method'],
 150+ 'oauth_signature_method' => 'HMAC-SHA1',
179151 );
180152
181153 // include the user token if it exists
@@ -289,11 +261,6 @@
290262 unset($_signing_params['oauth_callback']);
291263 }
292264
293 - if (isset($_signing_params['oauth_verifier'])) {
294 - $this->auth_params['oauth_verifier'] = $_signing_params['oauth_verifier'];
295 - unset($_signing_params['oauth_verifier']);
296 - }
297 -
298265 // request_params is already set if we're doing multipart, if not we need to set them now
299266 if ( ! $this->config['multipart'])
300267 $this->request_params = array_diff_key($_signing_params, $this->get_defaults());
@@ -568,26 +535,18 @@
569536 CURLOPT_USERAGENT => $this->config['user_agent'],
570537 CURLOPT_CONNECTTIMEOUT => $this->config['curl_connecttimeout'],
571538 CURLOPT_TIMEOUT => $this->config['curl_timeout'],
572 - CURLOPT_RETURNTRANSFER => true,
 539+ CURLOPT_RETURNTRANSFER => TRUE,
573540 CURLOPT_SSL_VERIFYPEER => $this->config['curl_ssl_verifypeer'],
574 - CURLOPT_SSL_VERIFYHOST => $this->config['curl_ssl_verifyhost'],
575 -
576541 CURLOPT_FOLLOWLOCATION => $this->config['curl_followlocation'],
577542 CURLOPT_PROXY => $this->config['curl_proxy'],
578543 CURLOPT_ENCODING => $this->config['curl_encoding'],
579544 CURLOPT_URL => $this->url,
580545 // process the headers
581546 CURLOPT_HEADERFUNCTION => array($this, 'curlHeader'),
582 - CURLOPT_HEADER => false,
 547+ CURLOPT_HEADER => FALSE,
583548 CURLINFO_HEADER_OUT => true,
584549 ));
585550
586 - if ($this->config['curl_cainfo'] !== false)
587 - curl_setopt($c, CURLOPT_CAINFO, $this->config['curl_cainfo']);
588 -
589 - if ($this->config['curl_capath'] !== false)
590 - curl_setopt($c, CURLOPT_CAPATH, $this->config['curl_capath']);
591 -
592551 if ($this->config['curl_proxyuserpwd'] !== false)
593552 curl_setopt($c, CURLOPT_PROXYUSERPWD, $this->config['curl_proxyuserpwd']);
594553
@@ -602,7 +561,7 @@
603562 case 'GET':
604563 break;
605564 case 'POST':
606 - curl_setopt($c, CURLOPT_POST, true);
 565+ curl_setopt($c, CURLOPT_POST, TRUE);
607566 break;
608567 default:
609568 curl_setopt($c, CURLOPT_CUSTOMREQUEST, $this->method);
@@ -640,16 +599,12 @@
641600 $response = curl_exec($c);
642601 $code = curl_getinfo($c, CURLINFO_HTTP_CODE);
643602 $info = curl_getinfo($c);
644 - $error = curl_error($c);
645 - $errno = curl_errno($c);
646603 curl_close($c);
647604
648605 // store the response
649606 $this->response['code'] = $code;
650607 $this->response['response'] = $response;
651608 $this->response['info'] = $info;
652 - $this->response['error'] = $error;
653 - $this->response['errno'] = $errno;
654609 return $code;
655610 }
656611 }

Comments

#Comment by Reedy (talk | contribs)   18:41, 31 December 2011

The guy seems nice and responsive on github, so certainly worth opening an issue for him to look at if you can narrow it down :)

Status & tagging log