FastLizard4 has submitted this change and it was merged. Change subject: Update twitteroauth for API v1.1, minor fixes ......................................................................
Update twitteroauth for API v1.1, minor fixes Recently Twitter discontinued version 1.0 of its API in favor of version 1.1. This commit introduces the patches made at https://github.com/abraham/twitteroauth to allow tweeting again. In patchset 2, minor edits were made to CommunityTwitter_body.php to improve functionality. Proper deletion POSTs and deleted tweet splicing were introduced, along with better handling of form URLs. Change-Id: Ie7f2aa7a5875c1e9636f40156d314d6d4c420d0e --- M CommunityTwitter_body.php M includes/OAuth.php M includes/TWITTEROAUTH-LICENSE M includes/twitteroauth.php 4 files changed, 30 insertions(+), 28 deletions(-) Approvals: FastLizard4: Verified; Looks good to me, approved RAN1: Verified; Looks good to me, but someone else must approve diff --git a/CommunityTwitter_body.php b/CommunityTwitter_body.php index 6a20363..257cbd5 100755 --- a/CommunityTwitter_body.php +++ b/CommunityTwitter_body.php @@ -141,7 +141,7 @@ if (!communitytwitter::checkConnections($connections)) { $wgOut->addHTML("<strong class=\"ct-error\">".wfMsg("communitytwitter-connection-failure")."</strong>"); } else { - + // Get Twitter timeline from default account $timeline = $connections[$ctDefaultAccount]->get("statuses/user_timeline", array("include_rts" => "true")); $twitterStatuses = array_values(array_filter(array_map(array("CommunityTwitter", "getOwnTweets"), $timeline))); @@ -203,17 +203,17 @@ $currTimeline = array_values(array_filter(array_map(array("CommunityTwitter", "getOwnTweets"), $currTimeline))); $hashId = communitytwitter::hashIds($twitterStatuses, $currTimeline); if (array_key_exists($wgRequest->getText("deleteId"), $hashId)) { - $responses[$appName] = $connections[$appName]->post("statuses/destroy", array("id" => $hashId[$wgRequest->getText("deleteId")])); + $responses[$appName] = $connections[$appName]->post("statuses/destroy/" . $hashId[$wgRequest->getText("deleteId")]); } } // Delete Tweet via OAuth - $responses[$ctDefaultAccount] = $connections[$ctDefaultAccount]->post("statuses/destroy", array("id" => $wgRequest->getText("deleteId"))); + $responses[$ctDefaultAccount] = $connections[$ctDefaultAccount]->post("statuses/destroy/" . $wgRequest->getText("deleteId")); if (communitytwitter::checkResponses($responses)) { $wgOut->addHTML("<strong class=\"ct-success\">".wfMsg("communitytwitter-deletion-success")."</strong>\n"); // Update timeline array to display updated "your last tweets" section - unset($twitterStatuses[$i]); + array_splice($twitterStatuses, $i, 1); } else { $wgOut->addHTML("<strong class=\"ct-error\">".wfMsg("communitytwitter-unknown-error-request")."</strong>\n"); } @@ -241,13 +241,13 @@ } else { // Tweet textarea; javascript ResourceLoader module enables an updating counter with button disabling if tweet is too long (for convenience, Twitter won't allow a >140 char post anyways) $wgOut->addModules( 'ext.CommunityTwitter.updatecount' ); - $wgOut->addHTML("<form action=\"".$wgScriptPath."/../wiki/Special:CommunityTwitter\" method=\"post\" id=\"status_update_form\">\n". + $wgOut->addHTML("<form action=\"".$wgOut->getTitle()->getLinkURL()."\" method=\"post\" id=\"status_update_form\">\n". "<span class=\"ct-tweet\">".wfMsg("communitytwitter-remaining-chars").": <strong id=\"stringlength\">140</strong><br/>\n". "<textarea tabindex=\"1\" autocomplete=\"off\" accesskey=\"u\" name=\"status\" id=\"status\" rows=\"2\" cols=\"40\" class=\"ct-tweet-input\"></textarea>\n". "<br/><input type=\"submit\" id=\"tweetbutton\" value=\" Tweet \"></span>\n". "</form><br /><br /><br /><br /><br /><br />\n". "<span class=\"ct-tweet\">". - "<form action=\"".$wgScriptPath."/../wiki/Special:CommunityTwitter\" method=\"post\">Tweet-ID: <input type=\"text\" name=\"tweetid\" />". + "<form action=\"".$wgOut->getTitle()->getLinkURL()."\" method=\"post\">Tweet-ID: <input type=\"text\" name=\"tweetid\" />". "<br /><a href=\"javascript:alert('".wfMsg("communitytwitter-id-help-text")."')\">". wfMsg("communitytwitter-id-help-link")."</a> <input type=\"submit\" value=\"Retweet\"></form></span>"); } @@ -257,8 +257,8 @@ // Display users' last tweets to give him the opportunity to delete his own tweets if (count($twitterStatuses) > 0) { for ($i=0; $i < min(5,count($twitterStatuses)); $i++) { - if ($twitterStatuses[$i]->text != "") { - $wgOut->addHTML("<form action=\"".$wgScriptPath."/../wiki/Special:CommunityTwitter\" method=\"post\"><input type=\"hidden\" name=\"deleteId\" value=\"".($twitterStatuses[$i]->id_str)."\" /><li>[<input class=\"submit\" type=\"submit\" value=\"".wfMsg("communitytwitter-delete-tweet-link-name")."\" title=\"".wfMsg("communitytwitter-delete-tweet-title-tag")."\" />] ".$twitterStatuses[$i]->text."</li></form>\n"); + if (isset($twitterStatuses[$i]) && $twitterStatuses[$i]->text != "") { + $wgOut->addHTML("<form action=\"".$wgOut->getTitle()->getLinkURL()."\" method=\"post\"><input type=\"hidden\" name=\"deleteId\" value=\"".($twitterStatuses[$i]->id_str)."\" /><li>[<input class=\"submit\" type=\"submit\" value=\"".wfMsg("communitytwitter-delete-tweet-link-name")."\" title=\"".wfMsg("communitytwitter-delete-tweet-title-tag")."\" />] ".$twitterStatuses[$i]->text."</li></form>\n"); } } } else { diff --git a/includes/OAuth.php b/includes/OAuth.php index 22f8816..4570013 100644 --- a/includes/OAuth.php +++ b/includes/OAuth.php @@ -3,8 +3,10 @@ /* Generic exception class */ -class OAuthException extends Exception { - // pass +if (!class_exists('OAuthException')) { + class OAuthException extends Exception { + // pass + } } class OAuthConsumer { @@ -90,9 +92,9 @@ } /** - * The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104] - * where the Signature Base String is the text and the key is the concatenated values (each first - * encoded per Parameter Encoding) of the Consumer Secret and Token Secret, separated by an '&' + * The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104] + * where the Signature Base String is the text and the key is the concatenated values (each first + * encoded per Parameter Encoding) of the Consumer Secret and Token Secret, separated by an '&' * character (ASCII code 38) even if empty. * - Chapter 9.2 ("HMAC-SHA1") */ @@ -118,7 +120,7 @@ } /** - * The PLAINTEXT method does not provide any security protection and SHOULD only be used + * The PLAINTEXT method does not provide any security protection and SHOULD only be used * over a secure channel such as HTTPS. It does not use the Signature Base String. * - Chapter 9.4 ("PLAINTEXT") */ @@ -128,8 +130,8 @@ } /** - * oauth_signature is set to the concatenated encoded values of the Consumer Secret and - * Token Secret, separated by a '&' character (ASCII code 38), even if either secret is + * oauth_signature is set to the concatenated encoded values of the Consumer Secret and + * Token Secret, separated by a '&' character (ASCII code 38), even if either secret is * empty. The result MUST be encoded again. * - Chapter 9.4.1 ("Generating Signatures") * @@ -151,10 +153,10 @@ } /** - * The RSA-SHA1 signature method uses the RSASSA-PKCS1-v1_5 signature algorithm as defined in - * [RFC3447] section 8.2 (more simply known as PKCS#1), using SHA-1 as the hash function for - * EMSA-PKCS1-v1_5. It is assumed that the Consumer has provided its RSA public key in a - * verified way to the Service Provider, in a manner which is beyond the scope of this + * The RSA-SHA1 signature method uses the RSASSA-PKCS1-v1_5 signature algorithm as defined in + * [RFC3447] section 8.2 (more simply known as PKCS#1), using SHA-1 as the hash function for + * EMSA-PKCS1-v1_5. It is assumed that the Consumer has provided its RSA public key in a + * verified way to the Service Provider, in a manner which is beyond the scope of this * specification. * - Chapter 9.3 ("RSA-SHA1") */ @@ -556,7 +558,7 @@ private function get_version(&$request) { $version = $request->get_parameter("oauth_version"); if (!$version) { - // Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present. + // Service Providers MUST assume the protocol version to be 1.0 if this parameter is not present. // Chapter 7.0 ("Accessing Protected Ressources") $version = '1.0'; } @@ -656,7 +658,7 @@ throw new OAuthException( 'Missing timestamp parameter. The parameter is required' ); - + // verify that timestamp is recentish $now = time(); if (abs($now - $timestamp) > $this->timestamp_threshold) { diff --git a/includes/TWITTEROAUTH-LICENSE b/includes/TWITTEROAUTH-LICENSE index e60f470..3a631e0 100644 --- a/includes/TWITTEROAUTH-LICENSE +++ b/includes/TWITTEROAUTH-LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009 Abraham Williams - http://abrah.am - [email protected] +Copyright (c) 2009 Abraham Williams - http://abrah.am - [email protected] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/includes/twitteroauth.php b/includes/twitteroauth.php index 1603ed3..3fb5052 100644 --- a/includes/twitteroauth.php +++ b/includes/twitteroauth.php @@ -18,11 +18,11 @@ /* Contains the last API call. */ public $url; /* Set up the API root URL. */ - public $host = "https://api.twitter.com/1/"; + public $host = "https://api.twitter.com/1.1/"; /* Set timeout default. */ public $timeout = 30; /* Set connect timeout. */ - public $connecttimeout = 30; + public $connecttimeout = 30; /* Verify SSL Cert. */ public $ssl_verifypeer = FALSE; /* Respons format. */ @@ -74,7 +74,7 @@ */ function getRequestToken($oauth_callback) { $parameters = array(); - $parameters['oauth_callback'] = $oauth_callback; + $parameters['oauth_callback'] = $oauth_callback; $request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters); $token = OAuthUtil::parse_parameters($request); $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']); @@ -123,7 +123,7 @@ * "user_id" => "9436992", * "screen_name" => "abraham", * "x_auth_expires" => "0") - */ + */ function getXAuthToken($username, $password) { $parameters = array(); $parameters['x_auth_username'] = $username; @@ -145,7 +145,7 @@ } return $response; } - + /** * POST wrapper for oAuthRequest. */ -- To view, visit https://gerrit.wikimedia.org/r/70029 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ie7f2aa7a5875c1e9636f40156d314d6d4c420d0e Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/CommunityTwitter Gerrit-Branch: master Gerrit-Owner: RAN1 <[email protected]> Gerrit-Reviewer: Basti2342 <[email protected]> Gerrit-Reviewer: FastLizard4 <[email protected]> Gerrit-Reviewer: RAN1 <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
