From 1710082f0459d7acc130697d14476faf01ecfa2d Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Sat, 19 Sep 2009 18:34:07 -0700 Subject: [PATCH 01/11] Make statuses/home_timeline return the same thing as statuses/friends_timeline to support apps trying to use the new retweet API method. --- actions/twitapistatuses.php | 5 +++++ lib/router.php | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index edee239a03..5e2867ea81 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -136,6 +136,11 @@ class TwitapistatusesAction extends TwitterapiAction } + function home_timeline($args, $apidata) + { + call_user_func(array($this, 'friends_timeline'), $args, $apidata); + } + function user_timeline($args, $apidata) { parent::handle($args); diff --git a/lib/router.php b/lib/router.php index 00e728f557..5309fe7530 100644 --- a/lib/router.php +++ b/lib/router.php @@ -268,12 +268,12 @@ class Router $m->connect('api/statuses/:method', array('action' => 'api', 'apiaction' => 'statuses'), - array('method' => '(public_timeline|friends_timeline|user_timeline|update|replies|mentions|show|friends|followers|featured)(\.(atom|rss|xml|json))?')); + array('method' => '(public_timeline|home_timeline|friends_timeline|user_timeline|update|replies|mentions|show|friends|followers|featured)(\.(atom|rss|xml|json))?')); $m->connect('api/statuses/:method/:argument', array('action' => 'api', 'apiaction' => 'statuses'), - array('method' => '(|user_timeline|friends_timeline|replies|mentions|show|destroy|friends|followers)')); + array('method' => '(user_timeline|home_timeline|friends_timeline|replies|mentions|show|destroy|friends|followers)')); // users @@ -432,7 +432,7 @@ class Router $m->connect('api/statuses/:method/:argument', array('action' => 'api', 'apiaction' => 'statuses'), - array('method' => '(|user_timeline|friends_timeline|replies|mentions|show|destroy|friends|followers)')); + array('method' => '(user_timeline|home_timeline|friends_timeline|replies|mentions|show|destroy|friends|followers)')); $m->connect('api/statusnet/groups/:method/:argument', array('action' => 'api', From bf3699105a010a291db283f1058df6ea064f0a56 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Sun, 27 Sep 2009 20:21:16 -0700 Subject: [PATCH 02/11] Forgot to add home_timeline to the list of methods that only require bareauth. --- actions/api.php | 1 + 1 file changed, 1 insertion(+) diff --git a/actions/api.php b/actions/api.php index f425a8dcd7..dc1bdbeacb 100644 --- a/actions/api.php +++ b/actions/api.php @@ -139,6 +139,7 @@ class ApiAction extends Action static $bareauth = array('statuses/user_timeline', 'statuses/friends_timeline', + 'statuses/home_timeline', 'statuses/friends', 'statuses/replies', 'statuses/mentions', From 120a84593e5155d1243ab47bfad604311729c698 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Sun, 27 Sep 2009 20:21:16 -0700 Subject: [PATCH 03/11] Forgot to add home_timeline to the list of methods that only require bareauth. --- actions/api.php | 1 + 1 file changed, 1 insertion(+) diff --git a/actions/api.php b/actions/api.php index f425a8dcd7..dc1bdbeacb 100644 --- a/actions/api.php +++ b/actions/api.php @@ -139,6 +139,7 @@ class ApiAction extends Action static $bareauth = array('statuses/user_timeline', 'statuses/friends_timeline', + 'statuses/home_timeline', 'statuses/friends', 'statuses/replies', 'statuses/mentions', From 92ac156cbe588f2fdf86ac8c3391e4057852ac77 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Fri, 28 Aug 2009 16:18:05 -0400 Subject: [PATCH 04/11] Add % and ~ as valid characters in the path, querystring, and fragment parts of URLs --- lib/util.php | 10 +++++----- tests/URLDetectionTest.php | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/util.php b/lib/util.php index 0b696662c1..0bb943ad86 100644 --- a/lib/util.php +++ b/lib/util.php @@ -421,7 +421,7 @@ function common_replace_urls_callback($text, $callback, $notice_id = null) { '|'. '(?:(?:mailto|aim|tel|xmpp):)'. ')'. - '(?:[\pN\pL\-\_\+]+(?::[\pN\pL\-\_\+]+)?\@)?'. //user:pass@ + '(?:[\pN\pL\-\_\+\%\~]+(?::[\pN\pL\-\_\+\%\~]+)?\@)?'. //user:pass@ '(?:'. '(?:'. '\[[\pN\pL\-\_\:\.]+(?127.0.0.1:99'), array('127.0.0.1/test.php', '127.0.0.1/test.php'), + array('127.0.0.1/~test', + '127.0.0.1/~test'), + array('127.0.0.1/test%20stuff', + '127.0.0.1/test%20stuff'), array('http://[::1]:99/test.php', 'http://[::1]:99/test.php'), array('http://::1/test.php', From 4312ea90aa46299bfd77454e441f9ecb867fadd1 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 29 Sep 2009 09:12:44 -0400 Subject: [PATCH 05/11] stop overwriting created timestamp on group edit --- actions/editgroup.php | 1 - 1 file changed, 1 deletion(-) diff --git a/actions/editgroup.php b/actions/editgroup.php index cac910e9bc..652719a33d 100644 --- a/actions/editgroup.php +++ b/actions/editgroup.php @@ -244,7 +244,6 @@ class EditgroupAction extends GroupDesignAction $this->group->homepage = $homepage; $this->group->description = $description; $this->group->location = $location; - $this->group->created = common_sql_now(); $result = $this->group->update($orig); From b0ce2add41877091ba750b36387b45a476127526 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 29 Sep 2009 17:43:45 -0400 Subject: [PATCH 06/11] move HTTP error code strings to class variables --- lib/clienterroraction.php | 43 +++++++++++++++++---------------------- lib/error.php | 6 ++++-- lib/servererroraction.php | 19 +++++++---------- 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/lib/clienterroraction.php b/lib/clienterroraction.php index 7d007a7567..1b98a10645 100644 --- a/lib/clienterroraction.php +++ b/lib/clienterroraction.php @@ -46,28 +46,28 @@ require_once INSTALLDIR.'/lib/error.php'; */ class ClientErrorAction extends ErrorAction { + static $status = array(400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Request Entity Too Large', + 414 => 'Request-URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Requested Range Not Satisfiable', + 417 => 'Expectation Failed'); + function __construct($message='Error', $code=400) { parent::__construct($message, $code); - - $this->status = array(400 => 'Bad Request', - 401 => 'Unauthorized', - 402 => 'Payment Required', - 403 => 'Forbidden', - 404 => 'Not Found', - 405 => 'Method Not Allowed', - 406 => 'Not Acceptable', - 407 => 'Proxy Authentication Required', - 408 => 'Request Timeout', - 409 => 'Conflict', - 410 => 'Gone', - 411 => 'Length Required', - 412 => 'Precondition Failed', - 413 => 'Request Entity Too Large', - 414 => 'Request-URI Too Long', - 415 => 'Unsupported Media Type', - 416 => 'Requested Range Not Satisfiable', - 417 => 'Expectation Failed'); $this->default = 400; } @@ -91,9 +91,4 @@ class ClientErrorAction extends ErrorAction $this->showPage(); } - - function title() - { - return $this->status[$this->code]; - } } diff --git a/lib/error.php b/lib/error.php index 0c521db081..6a9b76be11 100644 --- a/lib/error.php +++ b/lib/error.php @@ -44,9 +44,10 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { */ class ErrorAction extends Action { + static $status = array(); + var $code = null; var $message = null; - var $status = null; var $default = null; function __construct($message, $code, $output='php://output', $indent=true) @@ -88,9 +89,10 @@ class ErrorAction extends Action * * @return page title */ + function title() { - return $this->message; + return self::$status[$this->code]; } function isReadOnly($args) diff --git a/lib/servererroraction.php b/lib/servererroraction.php index c6400605ea..0993a63bca 100644 --- a/lib/servererroraction.php +++ b/lib/servererroraction.php @@ -55,17 +55,17 @@ require_once INSTALLDIR.'/lib/error.php'; class ServerErrorAction extends ErrorAction { + static $status = array(500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported'); + function __construct($message='Error', $code=500) { parent::__construct($message, $code); - $this->status = array(500 => 'Internal Server Error', - 501 => 'Not Implemented', - 502 => 'Bad Gateway', - 503 => 'Service Unavailable', - 504 => 'Gateway Timeout', - 505 => 'HTTP Version Not Supported'); - $this->default = 500; // Server errors must be logged. @@ -93,9 +93,4 @@ class ServerErrorAction extends ErrorAction $this->showPage(); } - - function title() - { - return $this->status[$this->code]; - } } From f46084309b72e647ee6552669a009cf5b3fbff5a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 29 Sep 2009 17:57:31 -0400 Subject: [PATCH 07/11] Twitter API returns server errors in preferred format --- actions/twitapistatuses.php | 2 +- lib/twitterapi.php | 56 ++++++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index 5e2867ea81..41887a68f4 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -297,7 +297,7 @@ class TwitapistatusesAction extends TwitterapiAction $source, 1, $reply_to); if (is_string($notice)) { - $this->serverError($notice); + $this->serverError($notice, 500, $apidata['content-type']); return; } diff --git a/lib/twitterapi.php b/lib/twitterapi.php index 638efba241..3bac400e2f 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -501,7 +501,7 @@ class TwitterapiAction extends Action $enclosure = $entry['enclosures'][0]; $this->element('enclosure', array('url'=>$enclosure['url'],'type'=>$enclosure['mimetype'],'length'=>$enclosure['size']), null); } - + if(array_key_exists('tags', $entry)){ foreach($entry['tags'] as $tag){ $this->element('category', null,$tag); @@ -939,35 +939,16 @@ class TwitterapiAction extends Action function clientError($msg, $code = 400, $content_type = 'json') { - - static $status = array(400 => 'Bad Request', - 401 => 'Unauthorized', - 402 => 'Payment Required', - 403 => 'Forbidden', - 404 => 'Not Found', - 405 => 'Method Not Allowed', - 406 => 'Not Acceptable', - 407 => 'Proxy Authentication Required', - 408 => 'Request Timeout', - 409 => 'Conflict', - 410 => 'Gone', - 411 => 'Length Required', - 412 => 'Precondition Failed', - 413 => 'Request Entity Too Large', - 414 => 'Request-URI Too Long', - 415 => 'Unsupported Media Type', - 416 => 'Requested Range Not Satisfiable', - 417 => 'Expectation Failed'); - $action = $this->trimmed('action'); common_debug("User error '$code' on '$action': $msg", __FILE__); - if (!array_key_exists($code, $status)) { + if (!array_key_exists($code, ClientErrorAction::$status)) { $code = 400; } - $status_string = $status[$code]; + $status_string = ClientErrorAction::$status[$code]; + header('HTTP/1.1 '.$code.' '.$status_string); if ($content_type == 'xml') { @@ -986,6 +967,35 @@ class TwitterapiAction extends Action } + function serverError($msg, $code = 500, $content_type = 'json') + { + $action = $this->trimmed('action'); + + common_debug("Server error '$code' on '$action': $msg", __FILE__); + + if (!array_key_exists($code, ServerErrorAction::$status)) { + $code = 400; + } + + $status_string = ServerErrorAction::$status[$code]; + + header('HTTP/1.1 '.$code.' '.$status_string); + + if ($content_type == 'xml') { + $this->init_document('xml'); + $this->elementStart('hash'); + $this->element('error', null, $msg); + $this->element('request', null, $_SERVER['REQUEST_URI']); + $this->elementEnd('hash'); + $this->end_document('xml'); + } else { + $this->init_document('json'); + $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']); + print(json_encode($error_array)); + $this->end_document('json'); + } + } + function init_twitter_rss() { $this->startXML(); From 3727b17c39a9dba97b08f15211e3631c82162fdf Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 9 Oct 2009 10:39:56 -0400 Subject: [PATCH 08/11] don't write session if it's unchanged --- classes/Session.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/classes/Session.php b/classes/Session.php index d641edbbe4..79a69a96ea 100644 --- a/classes/Session.php +++ b/classes/Session.php @@ -85,9 +85,18 @@ class Session extends Memcached_DataObject return $session->insert(); } else { - $session->session_data = $session_data; + if (strcmp($session->session_data, $session_data) == 0) { + self::logdeb("Not writing session '$id'; unchanged"); + return true; + } else { + self::logdeb("Session '$id' data changed; updating"); - return $session->update(); + $orig = clone($session); + + $session->session_data = $session_data; + + return $session->update($orig); + } } } From ed1ff81e948ca576ed439178c7d6482a09dc4140 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 13 Oct 2009 16:54:57 +0000 Subject: [PATCH 09/11] Include long-form attachment URL in notice if URL shortening is disabled. Previously, the attachment URL would simply be dropped when shortening returned false instead of a short URL... the attachment was present if you clicked through to notice details but didn't appear in the timeline, making it nigh-impossible to see the attachment. --- actions/newnotice.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/actions/newnotice.php b/actions/newnotice.php index 00a822860e..115cfd580f 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -239,6 +239,10 @@ class NewnoticeAction extends Action $this->maybeAddRedir($fileRecord->id, $fileurl); $short_fileurl = common_shorten_url($fileurl); + if (!$short_fileurl) { + // todo -- Consider forcing default shortener if none selected? + $short_fileurl = $fileurl; + } $content_shortened .= ' ' . $short_fileurl; if (mb_strlen($content_shortened) > 140) { From d1e70b4e37149e09b2189957e2a869b4014a05c5 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 13 Oct 2009 14:51:23 -0700 Subject: [PATCH 10/11] Commit upstream updates to php-gettext after the 1.0.7 release (but in 2006! :P) Fixes file magic checks on 64-bit systems. http://bazaar.launchpad.net/~danilo/php-gettext/trunk/revision/17 http://bazaar.launchpad.net/~danilo/php-gettext/trunk/revision/18 http://bazaar.launchpad.net/~danilo/php-gettext/trunk/revision/19 --- extlib/php-gettext/ChangeLog | 16 ++++++++++++++++ extlib/php-gettext/gettext.inc | 6 +++--- extlib/php-gettext/gettext.php | 6 +++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/extlib/php-gettext/ChangeLog b/extlib/php-gettext/ChangeLog index 5e0949dfd7..ab77d80810 100644 --- a/extlib/php-gettext/ChangeLog +++ b/extlib/php-gettext/ChangeLog @@ -1,3 +1,19 @@ +2006-02-28 Danilo Šegan + + * gettext.php: Added some comments about these workarounds for + different PHP versions and architectures. + +2006-02-28 Danilo Šegan + + Fixes bug #15923. + + * gettext.php (gettext_reader): make magic check work on 64-bit + platforms as well (by Steffen Pingel). + +2006-02-20 Danilo Šegan + + * gettext.inc (_bindtextdomain): Use php_uname to detect Windows. + 2006-02-07 Danilo Šegan * examples/pigs_dropin.php: comment-out bind_textdomain_codeset diff --git a/extlib/php-gettext/gettext.inc b/extlib/php-gettext/gettext.inc index eb94b256a6..fcaafe7c9e 100644 --- a/extlib/php-gettext/gettext.inc +++ b/extlib/php-gettext/gettext.inc @@ -148,9 +148,9 @@ function _setlocale($category, $locale) { */ function _bindtextdomain($domain, $path) { global $text_domains; - // ensure $path ends with a slash - if ($path[strlen($path) - 1] != '/') $path .= '/'; - elseif ($path[strlen($path) - 1] != '\\') $path .= '\\'; + // ensure $path ends with a slash + if ($path[strlen($path) - 1] != '/') $path .= '/'; + elseif ($path[strlen($path) - 1] != '\\') $path .= '\\'; $text_domains[$domain]->path = $path; } diff --git a/extlib/php-gettext/gettext.php b/extlib/php-gettext/gettext.php index ad94a987b7..cd080444ca 100644 --- a/extlib/php-gettext/gettext.php +++ b/extlib/php-gettext/gettext.php @@ -102,16 +102,16 @@ class gettext_reader { // Caching can be turned off $this->enable_cache = $enable_cache; - // $MAGIC1 = (int)0x950412de; //bug in PHP 5 + // $MAGIC1 = (int)0x950412de; //bug in PHP 5.0.2, see https://savannah.nongnu.org/bugs/?func=detailitem&item_id=10565 $MAGIC1 = (int) - 1794895138; // $MAGIC2 = (int)0xde120495; //bug $MAGIC2 = (int) - 569244523; $this->STREAM = $Reader; $magic = $this->readint(); - if ($magic == $MAGIC1) { + if ($magic == ($MAGIC1 & 0xFFFFFFFF)) { // to make sure it works for 64-bit platforms $this->BYTEORDER = 0; - } elseif ($magic == $MAGIC2) { + } elseif ($magic == ($MAGIC2 & 0xFFFFFFFF)) { $this->BYTEORDER = 1; } else { $this->error = 1; // not MO file From d3bbf3ad24c27522694bfaed437897273069a1e8 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 12 Oct 2009 22:36:17 +0000 Subject: [PATCH 11/11] Workaround for Facebook data store API behavior regression, fixes saving of empty notice prefix text in facebook settings. Filed bug upstream at http://bugs.developers.facebook.com/show_bug.cgi?id=7110 Per documentation, saving a pref value of "" or "0" will delete the pref key: http://wiki.developers.facebook.com/index.php/Data.setUserPreference which used to do what we want... Now Facebook throws back an error "Parameter value is required" when we do this. Workaround appends a space to empty string or "0" at save time, then trims the string when we load it. The input string was already trimmed at pref save time, so this won't alter any user-visible behavior. Thanks to ^demon in #mediawiki for pointing out the behavior regression after testing the identi.ca Facebook app! --- actions/facebooksettings.php | 11 +++++++++-- lib/facebookutil.php | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/actions/facebooksettings.php b/actions/facebooksettings.php index 84bdde9101..b2b1d68071 100644 --- a/actions/facebooksettings.php +++ b/actions/facebooksettings.php @@ -58,8 +58,15 @@ class FacebooksettingsAction extends FacebookAction $this->flink->set_flags($noticesync, $replysync, false, false); $result = $this->flink->update($original); + if ($prefix == '' || $prefix == '0') { + // Facebook bug: saving empty strings to prefs now fails + // http://bugs.developers.facebook.com/show_bug.cgi?id=7110 + $trimmed = $prefix . ' '; + } else { + $trimmed = substr($prefix, 0, 128); + } $this->facebook->api_client->data_setUserPreference(FACEBOOK_NOTICE_PREFIX, - substr($prefix, 0, 128)); + $trimmed); if ($result === false) { $this->showForm(_('There was a problem saving your sync preferences!')); @@ -101,7 +108,7 @@ class FacebooksettingsAction extends FacebookAction $this->elementStart('li'); - $prefix = $this->facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX); + $prefix = trim($this->facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX)); $this->input('prefix', _('Prefix'), ($prefix) ? $prefix : null, diff --git a/lib/facebookutil.php b/lib/facebookutil.php index ad61b6f0a5..c29576b64c 100644 --- a/lib/facebookutil.php +++ b/lib/facebookutil.php @@ -99,8 +99,8 @@ function facebookBroadcastNotice($notice) // XXX: Does this call count against our per user FB request limit? // If so we should consider storing verb elsewhere or not storing - $prefix = $facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX, - $fbuid); + $prefix = trim($facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX, + $fbuid)); $status = "$prefix $notice->content";