Making many of the API actions more consistent with coding style

clientError and serverError exit after they're done so no need for
break or return. Also, $this->format is default.

We also got rid of the incredibly verbose version of $this->isPost()
which was spread all over the place.

Not all of this cleaning up is done yet.
This commit is contained in:
Mikael Nordfeldth 2013-10-15 02:54:10 +02:00
parent 8202e922aa
commit 29d0871e5a
43 changed files with 427 additions and 1022 deletions

View File

@ -45,6 +45,8 @@ if (!defined('STATUSNET')) {
*/ */
class ApiAccountUpdateDeliveryDeviceAction extends ApiAuthAction class ApiAccountUpdateDeliveryDeviceAction extends ApiAuthAction
{ {
protected $needPost = true;
/** /**
* Take arguments for running * Take arguments for running
* *
@ -75,15 +77,6 @@ class ApiAccountUpdateDeliveryDeviceAction extends ApiAuthAction
{ {
parent::handle($args); parent::handle($args);
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
// TRANS: Client error message. POST is a HTTP command. It should not be translated.
_('This method requires a POST.'),
400, $this->format
);
return;
}
if (!in_array($this->format, array('xml', 'json'))) { if (!in_array($this->format, array('xml', 'json'))) {
$this->clientError( $this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
@ -105,8 +98,7 @@ class ApiAccountUpdateDeliveryDeviceAction extends ApiAuthAction
if (empty($this->user)) { if (empty($this->user)) {
// TRANS: Client error displayed when no existing user is provided for a user's delivery device setting. // TRANS: Client error displayed when no existing user is provided for a user's delivery device setting.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
$original = clone($this->user); $original = clone($this->user);

View File

@ -43,6 +43,8 @@ if (!defined('STATUSNET')) {
*/ */
class ApiAccountUpdateProfileAction extends ApiAuthAction class ApiAccountUpdateProfileAction extends ApiAuthAction
{ {
protected $needPost = true;
/** /**
* Take arguments for running * Take arguments for running
* *
@ -50,7 +52,7 @@ class ApiAccountUpdateProfileAction extends ApiAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
@ -69,37 +71,20 @@ class ApiAccountUpdateProfileAction extends ApiAuthAction
* *
* See which request params have been set, and update the profile * See which request params have been set, and update the profile
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
// TRANS: Client error. POST is a HTTP command. It should not be translated.
_('This method requires a POST.'),
400, $this->format
);
return;
}
if (!in_array($this->format, array('xml', 'json'))) { if (!in_array($this->format, array('xml', 'json'))) {
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
return;
} }
if (empty($this->user)) { if (empty($this->user)) {
// TRANS: Client error displayed if a user could not be found. // TRANS: Client error displayed if a user could not be found.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
$profile = $this->user->getProfile(); $profile = $this->user->getProfile();

View File

@ -43,43 +43,18 @@ if (!defined('STATUSNET')) {
*/ */
class ApiAccountUpdateProfileImageAction extends ApiAuthAction class ApiAccountUpdateProfileImageAction extends ApiAuthAction
{ {
/** protected $needPost = true;
* Take arguments for running
*
* @param array $args $_REQUEST args
*
* @return boolean success flag
*/
function prepare($args)
{
parent::prepare($args);
$this->user = $this->auth_user;
return true;
}
/** /**
* Handle the request * Handle the request
* *
* Check whether the credentials are valid and output the result * Check whether the credentials are valid and output the result
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
// TRANS: Client error. POST is a HTTP command. It should not be translated.
_('This method requires a POST.'),
400, $this->format
);
return;
}
// Workaround for PHP returning empty $_POST and $_FILES when POST // Workaround for PHP returning empty $_POST and $_FILES when POST
// length > post_max_size in php.ini // length > post_max_size in php.ini
@ -94,20 +69,17 @@ class ApiAccountUpdateProfileImageAction extends ApiAuthAction
'The server was unable to handle that much POST data (%s bytes) due to its current configuration.', 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.',
intval($_SERVER['CONTENT_LENGTH'])); intval($_SERVER['CONTENT_LENGTH']));
$this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH'])); $this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
return;
} }
if (empty($this->user)) { if (empty($this->user)) {
// TRANS: Client error displayed updating profile image without having a user object. // TRANS: Client error displayed updating profile image without having a user object.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
try { try {
$imagefile = ImageFile::fromUpload('image'); $imagefile = ImageFile::fromUpload('image');
} catch (Exception $e) { } catch (Exception $e) {
$this->clientError($e->getMessage(), 400, $this->format); $this->clientError($e->getMessage());
return;
} }
$type = $imagefile->preferredType(); $type = $imagefile->preferredType();
@ -123,13 +95,6 @@ class ApiAccountUpdateProfileImageAction extends ApiAuthAction
$imagefile->copyTo($filepath); $imagefile->copyTo($filepath);
$profile = $this->user->getProfile(); $profile = $this->user->getProfile();
if (empty($profile)) {
// TRANS: Error message displayed when referring to a user without a profile.
$this->clientError(_('User has no profile.'));
return;
}
$profile->setOriginal($filename); $profile->setOriginal($filename);
common_broadcast_profile($profile); common_broadcast_profile($profile);

View File

@ -58,8 +58,7 @@ class ApiAtomServiceAction extends ApiBareAuthAction
if (empty($this->user)) { if (empty($this->user)) {
// TRANS: Client error displayed when making an Atom API request for an unknown user. // TRANS: Client error displayed when making an Atom API request for an unknown user.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
return true; return true;

View File

@ -46,6 +46,8 @@ if (!defined('STATUSNET')) {
*/ */
class ApiBlockCreateAction extends ApiAuthAction class ApiBlockCreateAction extends ApiAuthAction
{ {
protected $needPost = true;
var $other = null; var $other = null;
/** /**
@ -56,11 +58,10 @@ class ApiBlockCreateAction extends ApiAuthAction
* @return boolean success flag * @return boolean success flag
* *
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->user = $this->auth_user;
$this->other = $this->getTargetProfile($this->arg('id')); $this->other = $this->getTargetProfile($this->arg('id'));
return true; return true;
@ -75,36 +76,20 @@ class ApiBlockCreateAction extends ApiAuthAction
* *
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
// TRANS: Client error. POST is a HTTP command. It should not be translated.
_('This method requires a POST.'),
400,
$this->format
);
return;
}
if (empty($this->user) || empty($this->other)) { if (empty($this->user) || empty($this->other)) {
// TRANS: Client error displayed when trying to block a non-existing user or a user from another site. // TRANS: Client error displayed when trying to block a non-existing user or a user from another site.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
// Don't allow blocking yourself! // Don't allow blocking yourself!
if ($this->user->id == $this->other->id) { if ($this->user->id == $this->other->id) {
$this->clientError(
// TRANS: Client error displayed when users try to block themselves. // TRANS: Client error displayed when users try to block themselves.
_("You cannot block yourself!"), $this->clientError(_("You cannot block yourself!"), 403);
403,
$this->format
);
return;
} }
if (!$this->user->hasBlocked($this->other)) { if (!$this->user->hasBlocked($this->other)) {
@ -122,7 +107,7 @@ class ApiBlockCreateAction extends ApiAuthAction
$this->endDocument($this->format); $this->endDocument($this->format);
} else { } else {
// TRANS: Server error displayed when blocking a user has failed. // TRANS: Server error displayed when blocking a user has failed.
$this->serverError(_('Block user failed.'), 500, $this->format); $this->serverError(_('Block user failed.'), 500);
} }
} }
} }

View File

@ -45,6 +45,8 @@ if (!defined('STATUSNET')) {
*/ */
class ApiBlockDestroyAction extends ApiAuthAction class ApiBlockDestroyAction extends ApiAuthAction
{ {
protected $needPost = true;
var $other = null; var $other = null;
/** /**
@ -54,11 +56,10 @@ class ApiBlockDestroyAction extends ApiAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->user = $this->auth_user;
$this->other = $this->getTargetProfile($this->arg('id')); $this->other = $this->getTargetProfile($this->arg('id'));
return true; return true;
@ -69,28 +70,15 @@ class ApiBlockDestroyAction extends ApiAuthAction
* *
* Save the new message * Save the new message
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
// TRANS: Client error. POST is a HTTP command. It should not be translated.
_('This method requires a POST.'),
400,
$this->format
);
return;
}
if (empty($this->user) || empty($this->other)) { if (empty($this->user) || empty($this->other)) {
// TRANS: Client error when user not found for an API action to remove a block for a user. // TRANS: Client error when user not found for an API action to remove a block for a user.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
if ($this->user->hasBlocked($this->other)) { if ($this->user->hasBlocked($this->other)) {

View File

@ -70,8 +70,7 @@ class ApiDirectMessageAction extends ApiAuthAction
if (empty($this->user)) { if (empty($this->user)) {
// TRANS: Client error given when a user was not found (404). // TRANS: Client error given when a user was not found (404).
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
$server = common_root_url(); $server = common_root_url();

View File

@ -49,6 +49,8 @@ if (!defined('STATUSNET')) {
*/ */
class ApiDirectMessageNewAction extends ApiAuthAction class ApiDirectMessageNewAction extends ApiAuthAction
{ {
protected $needPost = true;
var $other = null; var $other = null;
var $content = null; var $content = null;
@ -59,22 +61,17 @@ class ApiDirectMessageNewAction extends ApiAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->user = $this->auth_user;
if (empty($this->user)) { if (empty($this->user)) {
// TRANS: Client error when user not found for an API direct message action. // TRANS: Client error when user not found for an API direct message action.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
$this->content = $this->trimmed('text'); $this->content = $this->trimmed('text');
$this->user = $this->auth_user;
$user_param = $this->trimmed('user'); $user_param = $this->trimmed('user');
$user_id = $this->arg('user_id'); $user_id = $this->arg('user_id');
$screen_name = $this->trimmed('screen_name'); $screen_name = $this->trimmed('screen_name');
@ -91,67 +88,38 @@ class ApiDirectMessageNewAction extends ApiAuthAction
* *
* Save the new message * Save the new message
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
// TRANS: Client error. POST is a HTTP command. It should not be translated.
_('This method requires a POST.'),
400,
$this->format
);
return;
}
if (empty($this->content)) { if (empty($this->content)) {
$this->clientError(
// TRANS: Client error displayed when no message text was submitted (406). // TRANS: Client error displayed when no message text was submitted (406).
_('No message text!'), $this->clientError(_('No message text!'), 406);
406,
$this->format
);
} else { } else {
$content_shortened = $this->auth_user->shortenLinks($this->content); $content_shortened = $this->auth_user->shortenLinks($this->content);
if (Message::contentTooLong($content_shortened)) { if (Message::contentTooLong($content_shortened)) {
$this->clientError(
// TRANS: Client error displayed when message content is too long. // TRANS: Client error displayed when message content is too long.
// TRANS: %d is the maximum number of characters for a message. // TRANS: %d is the maximum number of characters for a message.
sprintf(_m('That\'s too long. Maximum message size is %d character.', 'That\'s too long. Maximum message size is %d characters.', Message::maxContent()), $this->clientError(
Message::maxContent() sprintf(_m('That\'s too long. Maximum message size is %d character.', 'That\'s too long. Maximum message size is %d characters.', Message::maxContent()), Message::maxContent()),
), 406);
406,
$this->format
);
return;
} }
} }
if (empty($this->other)) { if (empty($this->other)) {
// TRANS: Client error displayed if a recipient user could not be found (403). // TRANS: Client error displayed if a recipient user could not be found (403).
$this->clientError(_('Recipient user not found.'), 403, $this->format); $this->clientError(_('Recipient user not found.'), 403);
return;
} else if (!$this->user->mutuallySubscribed($this->other)) { } else if (!$this->user->mutuallySubscribed($this->other)) {
$this->clientError(
// TRANS: Client error displayed trying to direct message another user who's not a friend (403). // TRANS: Client error displayed trying to direct message another user who's not a friend (403).
_('Cannot send direct messages to users who aren\'t your friend.'), $this->clientError(_('Cannot send direct messages to users who aren\'t your friend.'), 403);
403,
$this->format
);
return;
} else if ($this->user->id == $this->other->id) { } else if ($this->user->id == $this->other->id) {
// Note: sending msgs to yourself is allowed by Twitter // Note: sending msgs to yourself is allowed by Twitter
// TRANS: Client error displayed trying to direct message self (403). // TRANS: Client error displayed trying to direct message self (403).
$this->clientError(_('Do not send a message to yourself; ' . $this->clientError(_('Do not send a message to yourself; just say it to yourself quietly instead.'), 403);
'just say it to yourself quietly instead.'), 403, $this->format);
return;
} }
$message = Message::saveNew( $message = Message::saveNew(

View File

@ -48,6 +48,8 @@ if (!defined('STATUSNET')) {
*/ */
class ApiFriendshipsCreateAction extends ApiAuthAction class ApiFriendshipsCreateAction extends ApiAuthAction
{ {
protected $needPost = true;
var $other = null; var $other = null;
/** /**
@ -58,11 +60,10 @@ class ApiFriendshipsCreateAction extends ApiAuthAction
* @return boolean success flag * @return boolean success flag
* *
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->user = $this->auth_user;
$this->other = $this->getTargetProfile($this->arg('id')); $this->other = $this->getTargetProfile($this->arg('id'));
return true; return true;
@ -73,42 +74,20 @@ class ApiFriendshipsCreateAction extends ApiAuthAction
* *
* Check the format and show the user info * Check the format and show the user info
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
// TRANS: Client error. POST is a HTTP command. It should not be translated.
_('This method requires a POST.'),
400,
$this->format
);
return;
}
if (!in_array($this->format, array('xml', 'json'))) { if (!in_array($this->format, array('xml', 'json'))) {
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
return;
} }
if (empty($this->other)) { if (empty($this->other)) {
$this->clientError(
// TRANS: Client error displayed when trying follow who's profile could not be found. // TRANS: Client error displayed when trying follow who's profile could not be found.
_('Could not follow user: profile not found.'), $this->clientError(_('Could not follow user: profile not found.'), 403);
403,
$this->format
);
return;
} }
if ($this->user->isSubscribed($this->other)) { if ($this->user->isSubscribed($this->other)) {
@ -118,14 +97,13 @@ class ApiFriendshipsCreateAction extends ApiAuthAction
_('Could not follow user: %s is already on your list.'), _('Could not follow user: %s is already on your list.'),
$this->other->nickname $this->other->nickname
); );
$this->clientError($errmsg, 403, $this->format); $this->clientError($errmsg, 403);
return;
} }
try { try {
Subscription::start($this->user->getProfile(), $this->other); Subscription::start($this->user->getProfile(), $this->other);
} catch (Exception $e) { } catch (Exception $e) {
$this->clientError($e->getMessage(), 403, $this->format); $this->clientError($e->getMessage(), 403);
} }
$this->initDocument($this->format); $this->initDocument($this->format);

View File

@ -113,13 +113,8 @@ class ApiGNUsocialConfigAction extends ApiAction
$this->endDocument('json'); $this->endDocument('json');
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
break;
} }
} }

View File

@ -61,13 +61,8 @@ class ApiGNUsocialVersionAction extends ApiPrivateAuthAction
$this->endDocument('json'); $this->endDocument('json');
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
break;
} }
} }

View File

@ -49,6 +49,8 @@ if (!defined('STATUSNET')) {
*/ */
class ApiGroupCreateAction extends ApiAuthAction class ApiGroupCreateAction extends ApiAuthAction
{ {
protected $needPost = true;
var $group = null; var $group = null;
var $nickname = null; var $nickname = null;
var $fullname = null; var $fullname = null;
@ -65,12 +67,10 @@ class ApiGroupCreateAction extends ApiAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->user = $this->auth_user;
$this->nickname = Nickname::normalize($this->arg('nickname')); $this->nickname = Nickname::normalize($this->arg('nickname'));
$this->fullname = $this->arg('full_name'); $this->fullname = $this->arg('full_name');
$this->homepage = $this->arg('homepage'); $this->homepage = $this->arg('homepage');
@ -86,28 +86,15 @@ class ApiGroupCreateAction extends ApiAuthAction
* *
* Save the new group * Save the new group
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
// TRANS: Client error. POST is a HTTP command. It should not be translated.
_('This method requires a POST.'),
400,
$this->format
);
return;
}
if (empty($this->user)) { if (empty($this->user)) {
// TRANS: Client error given when a user was not found (404). // TRANS: Client error given when a user was not found (404).
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
if ($this->validateParams() == false) { if ($this->validateParams() == false) {
@ -131,13 +118,8 @@ class ApiGroupCreateAction extends ApiAuthAction
$this->showSingleJsonGroup($group); $this->showSingleJsonGroup($group);
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
break;
} }
} }
@ -149,66 +131,36 @@ class ApiGroupCreateAction extends ApiAuthAction
function validateParams() function validateParams()
{ {
if ($this->groupNicknameExists($this->nickname)) { if ($this->groupNicknameExists($this->nickname)) {
$this->clientError(
// TRANS: Client error trying to create a group with a nickname this is already in use. // TRANS: Client error trying to create a group with a nickname this is already in use.
_('Nickname already in use. Try another one.'), $this->clientError(_('Nickname already in use. Try another one.'), 403);
403,
$this->format
);
return false;
} elseif (!User_group::allowedNickname($this->nickname)) { } elseif (!User_group::allowedNickname($this->nickname)) {
$this->clientError(
// TRANS: Client error in form for group creation. // TRANS: Client error in form for group creation.
_('Not a valid nickname.'), $this->clientError(_('Not a valid nickname.'), 403);
403,
$this->format
);
return false;
} elseif (!is_null($this->homepage) } elseif (!is_null($this->homepage)
&& strlen($this->homepage) > 0 && strlen($this->homepage) > 0
&& !common_valid_http_url($this->homepage)) { && !common_valid_http_url($this->homepage)) {
$this->clientError(
// TRANS: Client error in form for group creation. // TRANS: Client error in form for group creation.
_('Homepage is not a valid URL.'), $this->clientError(_('Homepage is not a valid URL.'), 403);
403,
$this->format
);
return false;
} elseif ( } elseif (
!is_null($this->fullname) !is_null($this->fullname)
&& mb_strlen($this->fullname) > 255) { && mb_strlen($this->fullname) > 255) {
$this->clientError(
// TRANS: Client error in form for group creation. // TRANS: Client error in form for group creation.
_('Full name is too long (maximum 255 characters).'), $this->clientError(_('Full name is too long (maximum 255 characters).'), 403);
403,
$this->format
);
return false;
} elseif (User_group::descriptionTooLong($this->description)) { } elseif (User_group::descriptionTooLong($this->description)) {
$this->clientError(
sprintf(
// TRANS: Client error shown when providing too long a description during group creation. // TRANS: Client error shown when providing too long a description during group creation.
// TRANS: %d is the maximum number of allowed characters. // TRANS: %d is the maximum number of allowed characters.
_m('Description is too long (maximum %d character).', $this->clientError(sprintf(_m('Description is too long (maximum %d character).',
'Description is too long (maximum %d characters).', 'Description is too long (maximum %d characters).',
User_group::maxDescription()), User_group::maxDescription()), User_group::maxDescription()), 403);
User_group::maxDescription()
), } elseif (!is_null($this->location)
403,
$this->format
);
return false;
} elseif (
!is_null($this->location)
&& mb_strlen($this->location) > 255) { && mb_strlen($this->location) > 255) {
$this->clientError(
// TRANS: Client error shown when providing too long a location during group creation. // TRANS: Client error shown when providing too long a location during group creation.
_('Location is too long (maximum 255 characters).'), $this->clientError(_('Location is too long (maximum 255 characters).'), 403);
403,
$this->format
);
return false;
} }
if (!empty($this->aliasstring)) { if (!empty($this->aliasstring)) {
@ -221,57 +173,34 @@ class ApiGroupCreateAction extends ApiAuthAction
} }
if (count($this->aliases) > common_config('group', 'maxaliases')) { if (count($this->aliases) > common_config('group', 'maxaliases')) {
$this->clientError( $this->clientError(sprintf(
sprintf(
// TRANS: Client error shown when providing too many aliases during group creation. // TRANS: Client error shown when providing too many aliases during group creation.
// TRANS: %d is the maximum number of allowed aliases. // TRANS: %d is the maximum number of allowed aliases.
_m('Too many aliases! Maximum %d allowed.', _m('Too many aliases! Maximum %d allowed.',
'Too many aliases! Maximum %d allowed.', 'Too many aliases! Maximum %d allowed.',
common_config('group', 'maxaliases')), common_config('group', 'maxaliases')),
common_config('group', 'maxaliases') common_config('group', 'maxaliases')),
), 403);
403,
$this->format
);
return false;
} }
foreach ($this->aliases as $alias) { foreach ($this->aliases as $alias) {
if (!Nickname::isValid($alias)) { if (!Nickname::isValid($alias)) {
$this->clientError(
// TRANS: Client error shown when providing an invalid alias during group creation. // TRANS: Client error shown when providing an invalid alias during group creation.
// TRANS: %s is the invalid alias. // TRANS: %s is the invalid alias.
sprintf(_('Invalid alias: "%s".'), $alias), $this->clientError(sprintf(_('Invalid alias: "%s".'), $alias), 403);
403,
$this->format
);
return false;
} }
if ($this->groupNicknameExists($alias)) { if ($this->groupNicknameExists($alias)) {
$this->clientError(
sprintf(
// TRANS: Client error displayed when trying to use an alias during group creation that is already in use. // TRANS: Client error displayed when trying to use an alias during group creation that is already in use.
// TRANS: %s is the alias that is already in use. // TRANS: %s is the alias that is already in use.
_('Alias "%s" already in use. Try another one.'), $this->clientError(sprintf(_('Alias "%s" already in use. Try another one.'), $alias), 403);
$alias
),
403,
$this->format
);
return false;
} }
// XXX assumes alphanum nicknames // XXX assumes alphanum nicknames
if (strcmp($alias, $this->nickname) == 0) { if (strcmp($alias, $this->nickname) == 0) {
$this->clientError(
// TRANS: Client error displayed when trying to use an alias during group creation that is the same as the group's nickname. // TRANS: Client error displayed when trying to use an alias during group creation that is the same as the group's nickname.
_('Alias can\'t be the same as nickname.'), $this->clientError(_('Alias can\'t be the same as nickname.'), 403);
403,
$this->format
);
return false;
} }
} }

View File

@ -59,11 +59,11 @@ class ApiGroupIsMemberAction extends ApiBareAuthAction
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->user = $this->getTargetUser(null); $this->target = $this->getTargetProfile(null);
$this->group = $this->getTargetGroup(null); $this->group = $this->getTargetGroup(null);
return true; return true;
@ -74,27 +74,23 @@ class ApiGroupIsMemberAction extends ApiBareAuthAction
* *
* Save the new message * Save the new message
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if (empty($this->user)) { if (empty($this->target)) {
// TRANS: Client error displayed when checking group membership for a non-existing user. // TRANS: Client error displayed when checking group membership for a non-existing user.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
if (empty($this->group)) { if (empty($this->group)) {
// TRANS: Client error displayed when checking group membership for a non-existing group. // TRANS: Client error displayed when checking group membership for a non-existing group.
$this->clientError(_('Group not found.'), 404, $this->format); $this->clientError(_('Group not found.'), 404);
return false;
} }
$is_member = $this->user->isMember($this->group); $is_member = $this->target->isMember($this->group);
switch($this->format) { switch($this->format) {
case 'xml': case 'xml':
@ -108,13 +104,8 @@ class ApiGroupIsMemberAction extends ApiBareAuthAction
$this->endDocument('json'); $this->endDocument('json');
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'));
400,
$this->format
);
break;
} }
} }

View File

@ -49,6 +49,8 @@ if (!defined('STATUSNET')) {
*/ */
class ApiGroupJoinAction extends ApiAuthAction class ApiGroupJoinAction extends ApiAuthAction
{ {
protected $needPost = true;
var $group = null; var $group = null;
/** /**
@ -58,11 +60,10 @@ class ApiGroupJoinAction extends ApiAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->user = $this->auth_user;
$this->group = $this->getTargetGroup($this->arg('id')); $this->group = $this->getTargetGroup($this->arg('id'));
return true; return true;
@ -73,54 +74,30 @@ class ApiGroupJoinAction extends ApiAuthAction
* *
* Save the new message * Save the new message
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
// TRANS: Client error. POST is a HTTP command. It should not be translated.
_('This method requires a POST.'),
400,
$this->format
);
return;
}
if (empty($this->user)) { if (empty($this->user)) {
// TRANS: Client error displayed when trying to have a non-existing user join a group. // TRANS: Client error displayed when trying to have a non-existing user join a group.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
if (empty($this->group)) { if (empty($this->group)) {
// TRANS: Client error displayed when trying to join a group that does not exist. // TRANS: Client error displayed when trying to join a group that does not exist.
$this->clientError(_('Group not found.'), 404, $this->format); $this->clientError(_('Group not found.'), 404);
return false;
} }
if ($this->user->isMember($this->group)) { if ($this->user->isMember($this->group)) {
$this->clientError(
// TRANS: Server error displayed when trying to join a group the user is already a member of. // TRANS: Server error displayed when trying to join a group the user is already a member of.
_('You are already a member of that group.'), $this->clientError(_('You are already a member of that group.'), 403);
403,
$this->format
);
return;
} }
if (Group_block::isBlocked($this->group, $this->user->getProfile())) { if (Group_block::isBlocked($this->group, $this->user->getProfile())) {
$this->clientError(
// TRANS: Server error displayed when trying to join a group the user is blocked from joining. // TRANS: Server error displayed when trying to join a group the user is blocked from joining.
_('You have been blocked from that group by the admin.'), $this->clientError(_('You have been blocked from that group by the admin.'), 403);
403,
$this->format
);
return;
} }
try { try {
@ -130,7 +107,6 @@ class ApiGroupJoinAction extends ApiAuthAction
// TRANS: %1$s is the joining user's nickname, $2$s is the group nickname for which the join failed. // TRANS: %1$s is the joining user's nickname, $2$s is the group nickname for which the join failed.
$this->serverError(sprintf(_('Could not join user %1$s to group %2$s.'), $this->serverError(sprintf(_('Could not join user %1$s to group %2$s.'),
$cur->nickname, $this->group->nickname)); $cur->nickname, $this->group->nickname));
return;
} }
switch($this->format) { switch($this->format) {
@ -141,13 +117,8 @@ class ApiGroupJoinAction extends ApiAuthAction
$this->showSingleJsonGroup($this->group); $this->showSingleJsonGroup($this->group);
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
break;
} }
} }
} }

View File

@ -49,6 +49,8 @@ if (!defined('STATUSNET')) {
*/ */
class ApiGroupLeaveAction extends ApiAuthAction class ApiGroupLeaveAction extends ApiAuthAction
{ {
protected $needPost = true;
var $group = null; var $group = null;
/** /**
@ -58,11 +60,10 @@ class ApiGroupLeaveAction extends ApiAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->user = $this->auth_user;
$this->group = $this->getTargetGroup($this->arg('id')); $this->group = $this->getTargetGroup($this->arg('id'));
return true; return true;
@ -73,34 +74,20 @@ class ApiGroupLeaveAction extends ApiAuthAction
* *
* Save the new message * Save the new message
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
// TRANS: Client error. POST is a HTTP command. It should not be translated.
_('This method requires a POST.'),
400,
$this->format
);
return;
}
if (empty($this->user)) { if (empty($this->user)) {
// TRANS: Client error displayed when trying to have a non-existing user leave a group. // TRANS: Client error displayed when trying to have a non-existing user leave a group.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
if (empty($this->group)) { if (empty($this->group)) {
// TRANS: Client error displayed when trying to leave a group that does not exist. // TRANS: Client error displayed when trying to leave a group that does not exist.
$this->clientError(_('Group not found.'), 404, $this->format); $this->clientError(_('Group not found.'), 404);
return false;
} }
$member = new Group_member(); $member = new Group_member();
@ -111,7 +98,6 @@ class ApiGroupLeaveAction extends ApiAuthAction
if (!$member->find(true)) { if (!$member->find(true)) {
// TRANS: Server error displayed when trying to leave a group the user is not a member of. // TRANS: Server error displayed when trying to leave a group the user is not a member of.
$this->serverError(_('You are not a member of this group.')); $this->serverError(_('You are not a member of this group.'));
return;
} }
try { try {
@ -121,7 +107,6 @@ class ApiGroupLeaveAction extends ApiAuthAction
// TRANS: %1$s is the leaving user's nickname, $2$s is the group nickname for which the leave failed. // TRANS: %1$s is the leaving user's nickname, $2$s is the group nickname for which the leave failed.
$this->serverError(sprintf(_('Could not remove user %1$s from group %2$s.'), $this->serverError(sprintf(_('Could not remove user %1$s from group %2$s.'),
$cur->nickname, $this->group->nickname)); $cur->nickname, $this->group->nickname));
return;
} }
switch($this->format) { switch($this->format) {
case 'xml': case 'xml':
@ -131,13 +116,8 @@ class ApiGroupLeaveAction extends ApiAuthAction
$this->showSingleJsonGroup($this->group); $this->showSingleJsonGroup($this->group);
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
break;
} }
} }
} }

View File

@ -59,15 +59,14 @@ class ApiGroupMembershipAction extends ApiPrivateAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->group = $this->getTargetGroup($this->arg('id')); $this->group = $this->getTargetGroup($this->arg('id'));
if (empty($this->group)) { if (empty($this->group)) {
// TRANS: Client error displayed trying to show group membership on a non-existing group. // TRANS: Client error displayed trying to show group membership on a non-existing group.
$this->clientError(_('Group not found.'), 404, $this->format); $this->clientError(_('Group not found.'), 404);
return false;
} }
$this->profiles = $this->getProfiles(); $this->profiles = $this->getProfiles();
@ -80,13 +79,11 @@ class ApiGroupMembershipAction extends ApiPrivateAuthAction
* *
* Show the members of the group * Show the members of the group
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
// XXX: RSS and Atom // XXX: RSS and Atom
@ -98,13 +95,8 @@ class ApiGroupMembershipAction extends ApiPrivateAuthAction
$this->showJsonUsers($this->profiles); $this->showJsonUsers($this->profiles);
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
break;
} }
} }

View File

@ -42,6 +42,7 @@ if (!defined('STATUSNET')) {
*/ */
class ApiGroupProfileUpdateAction extends ApiAuthAction class ApiGroupProfileUpdateAction extends ApiAuthAction
{ {
protected $needPost = true;
/** /**
* Take arguments for running * Take arguments for running
* *
@ -50,7 +51,7 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
* @return boolean success flag * @return boolean success flag
* *
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
@ -73,49 +74,30 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
* *
* See which request params have been set, and update the profile * See which request params have been set, and update the profile
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
// TRANS: Client error message. POST is a HTTP command. It should not be translated.
_('This method requires a POST.'),
400, $this->format
);
return;
}
if (!in_array($this->format, array('xml', 'json'))) { if (!in_array($this->format, array('xml', 'json'))) {
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
return;
} }
if (empty($this->user)) { if (empty($this->user)) {
// TRANS: Client error displayed when not providing a user or an invalid user. // TRANS: Client error displayed when not providing a user or an invalid user.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
if (empty($this->group)) { if (empty($this->group)) {
// TRANS: Client error displayed when not providing a group or an invalid group. // TRANS: Client error displayed when not providing a group or an invalid group.
$this->clientError(_('Group not found.'), 404, $this->format); $this->clientError(_('Group not found.'), 404);
return false;
} }
if (!$this->user->isAdmin($this->group)) { if (!$this->user->isAdmin($this->group)) {
// TRANS: Client error displayed when trying to edit a group without being an admin. // TRANS: Client error displayed when trying to edit a group without being an admin.
$this->clientError(_('You must be an admin to edit the group.'), 403); $this->clientError(_('You must be an admin to edit the group.'), 403);
return false;
} }
$this->group->query('BEGIN'); $this->group->query('BEGIN');
@ -155,12 +137,7 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
} }
} catch (ApiValidationException $ave) { } catch (ApiValidationException $ave) {
$this->clientError( $this->clientError($ave->getMessage(), 403);
$ave->getMessage(),
403,
$this->format
);
return;
} }
$result = $this->group->update($orig); $result = $this->group->update($orig);
@ -179,12 +156,7 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
} }
} catch (ApiValidationException $ave) { } catch (ApiValidationException $ave) {
$this->clientError( $this->clientError($ave->getMessage(), 403);
$ave->getMessage(),
403,
$this->format
);
return;
} }
$result = $this->group->setAliases($aliases); $result = $this->group->setAliases($aliases);
@ -211,8 +183,7 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
break; break;
default: default:
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
$this->clientError(_('API method not found.'), 404, $this->format); $this->clientError(_('API method not found.'), 404);
break;
} }
} }

View File

@ -59,7 +59,7 @@ class ApiGroupShowAction extends ApiPrivateAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
@ -74,12 +74,8 @@ class ApiGroupShowAction extends ApiPrivateAuthAction
$args = array('id' => $alias->group_id, 'format' => $this->format); $args = array('id' => $alias->group_id, 'format' => $this->format);
common_redirect(common_local_url('ApiGroupShow', $args), 301); common_redirect(common_local_url('ApiGroupShow', $args), 301);
} else { } else {
$this->clientError(
// TRANS: Client error displayed when trying to show a group that could not be found. // TRANS: Client error displayed when trying to show a group that could not be found.
_('Group not found.'), $this->clientError(_('Group not found.'), 404);
404,
$this->format
);
} }
return; return;
} }
@ -92,13 +88,11 @@ class ApiGroupShowAction extends ApiPrivateAuthAction
* *
* Check the format and show the user info * Check the format and show the user info
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
switch($this->format) { switch($this->format) {
case 'xml': case 'xml':
@ -109,8 +103,7 @@ class ApiGroupShowAction extends ApiPrivateAuthAction
break; break;
default: default:
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
$this->clientError(_('API method not found.'), 404, $this->format); $this->clientError(_('API method not found.'), 404);
break;
} }
} }

View File

@ -59,7 +59,7 @@ class ApiListAction extends ApiBareAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
@ -76,8 +76,7 @@ class ApiListAction extends ApiBareAuthAction
if (empty($this->list)) { if (empty($this->list)) {
// TRANS: Client error displayed when referring to a non-existing list. // TRANS: Client error displayed when referring to a non-existing list.
$this->clientError(_('List not found.'), 404, $this->format); $this->clientError(_('List not found.'), 404);
return false;
} }
return true; return true;
@ -88,9 +87,9 @@ class ApiListAction extends ApiBareAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if($this->delete) { if($this->delete) {
$this->handleDelete(); $this->handleDelete();
@ -110,13 +109,8 @@ class ApiListAction extends ApiBareAuthAction
$this->showSingleJsonList($this->list); $this->showSingleJsonList($this->list);
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
break;
} }
} }
@ -138,12 +132,8 @@ class ApiListAction extends ApiBareAuthAction
function handlePut() function handlePut()
{ {
if($this->auth_user->id != $this->list->tagger) { if($this->auth_user->id != $this->list->tagger) {
$this->clientError(
// TRANS: Client error displayed when trying to update another user's list. // TRANS: Client error displayed when trying to update another user's list.
_('You cannot update lists that do not belong to you.'), $this->clientError(_('You cannot update lists that do not belong to you.'), 401);
401,
$this->format
);
} }
$new_list = clone($this->list); $new_list = clone($this->list);
@ -154,12 +144,8 @@ class ApiListAction extends ApiBareAuthAction
$result = $new_list->update($this->list); $result = $new_list->update($this->list);
if(!$result) { if(!$result) {
$this->clientError(
// TRANS: Client error displayed when an unknown error occurs updating a list. // TRANS: Client error displayed when an unknown error occurs updating a list.
_('An error occured.'), $this->clientError(_('An error occured.'), 503);
503,
$this->format
);
} }
switch($this->format) { switch($this->format) {
@ -170,13 +156,8 @@ class ApiListAction extends ApiBareAuthAction
$this->showSingleJsonList($new_list); $this->showSingleJsonList($new_list);
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
break;
} }
} }
@ -188,12 +169,8 @@ class ApiListAction extends ApiBareAuthAction
function handleDelete() function handleDelete()
{ {
if($this->auth_user->id != $this->list->tagger) { if($this->auth_user->id != $this->list->tagger) {
$this->clientError(
// TRANS: Client error displayed when trying to delete another user's list. // TRANS: Client error displayed when trying to delete another user's list.
_('You cannot delete lists that do not belong to you.'), $this->clientError(_('You cannot delete lists that do not belong to you.'), 401);
401,
$this->format
);
} }
$record = clone($this->list); $record = clone($this->list);
@ -207,13 +184,8 @@ class ApiListAction extends ApiBareAuthAction
$this->showSingleJsonList($record); $this->showSingleJsonList($record);
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
break;
} }
} }

View File

@ -56,23 +56,21 @@ class ApiListMemberAction extends ApiBareAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->user = $this->getTargetUser($this->arg('id')); $this->target = $this->getTargetProfile($this->arg('id'));
$this->list = $this->getTargetList($this->arg('user'), $this->arg('list_id')); $this->list = $this->getTargetList($this->arg('user'), $this->arg('list_id'));
if (empty($this->list)) { if (empty($this->list)) {
// TRANS: Client error displayed when referring to a non-existing list. // TRANS: Client error displayed when referring to a non-existing list.
$this->clientError(_('List not found.'), 404, $this->format); $this->clientError(_('List not found.'), 404);
return false;
} }
if (empty($this->user)) { if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed when referring to a non-existing user. // TRANS: Client error displayed when referring to a non-existing user.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return false;
} }
return true; return true;
} }
@ -82,25 +80,21 @@ class ApiListMemberAction extends ApiBareAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
$arr = array('tagger' => $this->list->tagger, $arr = array('tagger' => $this->list->tagger,
'tag' => $this->list->tag, 'tag' => $this->list->tag,
'tagged' => $this->user->id); 'tagged' => $this->target->id);
$ptag = Profile_tag::pkeyGet($arr); $ptag = Profile_tag::pkeyGet($arr);
if(empty($ptag)) { if(empty($ptag)) {
$this->clientError(
// TRANS: Client error displayed when referring to a non-list member. // TRANS: Client error displayed when referring to a non-list member.
_('The specified user is not a member of this list.'), $this->clientError(_('The specified user is not a member of this list.'));
400,
$this->format
);
} }
$user = $this->twitterUserArray($this->user->getProfile(), true); $user = $this->twitterUserArray($this->target, true);
switch($this->format) { switch($this->format) {
case 'xml': case 'xml':
@ -110,13 +104,8 @@ class ApiListMemberAction extends ApiBareAuthAction
$this->showSingleJsonUser($user); $this->showSingleJsonUser($user);
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
break;
} }
return true; return true;
} }

View File

@ -42,36 +42,21 @@ class ApiListMembersAction extends ApiListUsersAction
function handlePost() function handlePost()
{ {
if($this->auth_user->id != $this->list->tagger) { if($this->auth_user->id != $this->list->tagger) {
$this->clientError(
// TRANS: Client error displayed when trying to add members to a list without having the right to do so. // TRANS: Client error displayed when trying to add members to a list without having the right to do so.
_('You are not allowed to add members to this list.'), $this->clientError(_('You are not allowed to add members to this list.'), 401);
401,
$this->format
);
return false;
} }
if($this->user === false) { if (!($this->target instanceof Profile)) {
$this->clientError(
// TRANS: Client error displayed when trying to modify list members without specifying them. // TRANS: Client error displayed when trying to modify list members without specifying them.
_('You must specify a member.'), $this->clientError(_('You must specify a member.'));
400,
$this->format
);
return false;
} }
$result = Profile_tag::setTag($this->auth_user->id, $result = Profile_tag::setTag($this->auth_user->id,
$this->user->id, $this->list->tag); $this->target->id, $this->list->tag);
if(empty($result)) { if(empty($result)) {
$this->clientError(
// TRANS: Client error displayed when an unknown error occurs viewing list members. // TRANS: Client error displayed when an unknown error occurs viewing list members.
_('An error occured.'), $this->clientError(_('An error occured.'), 500);
500,
$this->format
);
return false;
} }
switch($this->format) { switch($this->format) {
@ -82,14 +67,8 @@ class ApiListMembersAction extends ApiListUsersAction
$this->showSingleJsonList($this->list); $this->showSingleJsonList($this->list);
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
return false;
break;
} }
} }
@ -101,50 +80,28 @@ class ApiListMembersAction extends ApiListUsersAction
function handleDelete() function handleDelete()
{ {
if($this->auth_user->id != $this->list->tagger) { if($this->auth_user->id != $this->list->tagger) {
$this->clientError(
// TRANS: Client error displayed when trying to remove members from a list without having the right to do so. // TRANS: Client error displayed when trying to remove members from a list without having the right to do so.
_('You are not allowed to remove members from this list.'), $this->clientError(_('You are not allowed to remove members from this list.'), 401);
401,
$this->format
);
return false;
} }
if($this->user === false) { if (!($this->target instanceof Profile)) {
$this->clientError(
// TRANS: Client error displayed when trying to modify list members without specifying them. // TRANS: Client error displayed when trying to modify list members without specifying them.
_('You must specify a member.'), $this->clientError(_('You must specify a member.'));
400,
$this->format
);
return false;
} }
$args = array('tagger' => $this->auth_user->id, $args = array('tagger' => $this->auth_user->id,
'tagged' => $this->user->id, 'tagged' => $this->target->id,
'tag' => $this->list->tag); 'tag' => $this->list->tag);
$ptag = Profile_tag::pkeyGet($args); $ptag = Profile_tag::pkeyGet($args);
if (empty($ptag)) { if (empty($ptag)) {
$this->clientError(
// TRANS: Client error displayed when trying to remove a list member that is not part of a list. // TRANS: Client error displayed when trying to remove a list member that is not part of a list.
_('The user you are trying to remove from the list is not a member.'), $this->clientError(_('The user you are trying to remove from the list is not a member.'));
400,
$this->format
);
return false;
} }
$result = $ptag->delete(); if (!$ptag->delete()) {
if(empty($result)) {
$this->clientError(
// TRANS: Client error displayed when an unknown error occurs viewing list members. // TRANS: Client error displayed when an unknown error occurs viewing list members.
_('An error occured.'), $this->clientError(_('An error occured.'), 500);
500,
$this->format
);
return false;
} }
switch($this->format) { switch($this->format) {
@ -155,15 +112,10 @@ class ApiListMembersAction extends ApiListUsersAction
$this->showSingleJsonList($this->list); $this->showSingleJsonList($this->list);
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
return false;
break;
} }
return true; return true;
} }

View File

@ -57,18 +57,18 @@ class ApiListMembershipsAction extends ApiBareAuthAction
* @return boolean success flag * @return boolean success flag
* *
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->cursor = (int) $this->arg('cursor', -1); $this->cursor = (int) $this->arg('cursor', -1);
$this->user = $this->getTargetUser($this->arg('user')); $user = $this->getTargetUser($this->arg('user'));
if (empty($this->user)) { if (!($user instanceof User)) {
// TRANS: Client error displayed trying to perform an action related to a non-existing user. // TRANS: Client error displayed trying to perform an action related to a non-existing user.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
$this->target = $user->getProfile();
$this->getLists(); $this->getLists();
@ -80,13 +80,11 @@ class ApiListMembershipsAction extends ApiBareAuthAction
* *
* Show the lists * Show the lists
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
switch($this->format) { switch($this->format) {
case 'xml': case 'xml':
@ -96,13 +94,8 @@ class ApiListMembershipsAction extends ApiBareAuthAction
$this->showJsonLists($this->lists, $this->next_cursor, $this->prev_cursor); $this->showJsonLists($this->lists, $this->next_cursor, $this->prev_cursor);
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'));
400,
$this->format
);
break;
} }
} }
@ -122,7 +115,7 @@ class ApiListMembershipsAction extends ApiBareAuthAction
function getLists() function getLists()
{ {
$profile = $this->user->getProfile(); $profile = $this->target;
$fn = array($profile, 'getOtherTags'); $fn = array($profile, 'getOtherTags');
# 20 lists # 20 lists

View File

@ -61,7 +61,7 @@ class ApiListsAction extends ApiBareAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
@ -71,11 +71,11 @@ class ApiListsAction extends ApiBareAuthAction
$this->user = $this->getTargetUser($this->arg('user')); $this->user = $this->getTargetUser($this->arg('user'));
if (empty($this->user)) { if (!($user instanceof User)) {
// TRANS: Client error displayed trying to perform an action related to a non-existing user. // TRANS: Client error displayed trying to perform an action related to a non-existing user.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return false;
} }
$this->target = $user->getProfile();
$this->getLists(); $this->getLists();
} }
@ -97,9 +97,9 @@ class ApiListsAction extends ApiBareAuthAction
* Show the lists the user has created if the request method is GET * Show the lists the user has created if the request method is GET
* Create a new list by diferring to handlePost() if it is POST. * Create a new list by diferring to handlePost() if it is POST.
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if($this->create) { if($this->create) {
return $this->handlePost(); return $this->handlePost();
@ -165,13 +165,8 @@ class ApiListsAction extends ApiBareAuthAction
$this->showSingleJsonList($list); $this->showSingleJsonList($list);
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
break;
} }
return true; return true;
} }
@ -186,8 +181,7 @@ class ApiListsAction extends ApiBareAuthAction
// twitter fixes count at 20 // twitter fixes count at 20
// there is no argument named count // there is no argument named count
$count = 20; $count = 20;
$profile = $this->user->getProfile(); $fn = array($this->target, 'getLists');
$fn = array($profile, 'getLists');
list($this->lists, list($this->lists,
$this->next_cursor, $this->next_cursor,
@ -226,7 +220,7 @@ class ApiListsAction extends ApiBareAuthAction
':', ':',
array($this->arg('action'), array($this->arg('action'),
common_language(), common_language(),
$this->user->id, $this->target->id,
strtotime($this->lists[0]->created), strtotime($this->lists[0]->created),
strtotime($this->lists[$last]->created)) strtotime($this->lists[$last]->created))
) )

View File

@ -37,19 +37,17 @@ class ApiListSubscriberAction extends ApiBareAuthAction
{ {
parent::prepare($args); parent::prepare($args);
$this->user = $this->getTargetUser($this->arg('id')); $this->target = $this->getTargetProfile($this->arg('id'));
$this->list = $this->getTargetList($this->arg('user'), $this->arg('list_id')); $this->list = $this->getTargetList($this->arg('user'), $this->arg('list_id'));
if (empty($this->list)) { if (empty($this->list)) {
// TRANS: Client error displayed trying to perform an action related to a non-existing list. // TRANS: Client error displayed trying to perform an action related to a non-existing list.
$this->clientError(_('List not found.'), 404, $this->format); $this->clientError(_('List not found.'), 404);
return false;
} }
if (empty($this->user)) { if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed trying to perform an action related to a non-existing user. // TRANS: Client error displayed trying to perform an action related to a non-existing user.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return false;
} }
return true; return true;
} }
@ -59,19 +57,15 @@ class ApiListSubscriberAction extends ApiBareAuthAction
parent::handle($args); parent::handle($args);
$arr = array('profile_tag_id' => $this->list->id, $arr = array('profile_tag_id' => $this->list->id,
'profile_id' => $this->user->id); 'profile_id' => $this->target->id);
$sub = Profile_tag_subscription::pkeyGet($arr); $sub = Profile_tag_subscription::pkeyGet($arr);
if(empty($sub)) { if(empty($sub)) {
$this->clientError(
// TRANS: Client error displayed when a membership check for a user is nagative. // TRANS: Client error displayed when a membership check for a user is nagative.
_('The specified user is not a subscriber of this list.'), $this->clientError(_('The specified user is not a subscriber of this list.'));
400,
$this->format
);
} }
$user = $this->twitterUserArray($this->user->getProfile(), true); $user = $this->twitterUserArray($this->target, true);
switch($this->format) { switch($this->format) {
case 'xml': case 'xml':

View File

@ -44,13 +44,8 @@ class ApiListSubscribersAction extends ApiListUsersAction
$this->auth_user); $this->auth_user);
if(empty($result)) { if(empty($result)) {
$this->clientError(
// TRANS: Client error displayed when an unknown error occurs in the list subscribers action. // TRANS: Client error displayed when an unknown error occurs in the list subscribers action.
_('An error occured.'), $this->clientError(_('An error occured.'), 500);
500,
$this->format
);
return false;
} }
switch($this->format) { switch($this->format) {
@ -61,14 +56,8 @@ class ApiListSubscribersAction extends ApiListUsersAction
$this->showSingleJsonList($this->list); $this->showSingleJsonList($this->list);
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
return false;
break;
} }
} }
@ -79,25 +68,15 @@ class ApiListSubscribersAction extends ApiListUsersAction
$ptag = Profile_tag_subscription::pkeyGet($args); $ptag = Profile_tag_subscription::pkeyGet($args);
if(empty($ptag)) { if(empty($ptag)) {
$this->clientError(
// TRANS: Client error displayed when trying to unsubscribe from a non-subscribed list. // TRANS: Client error displayed when trying to unsubscribe from a non-subscribed list.
_('You are not subscribed to this list.'), $this->clientError(_('You are not subscribed to this list.'));
400,
$this->format
);
return false;
} }
Profile_tag_subscription::remove($this->list, $this->auth_user); $result = Profile_tag_subscription::remove($this->list, $this->auth_user);
if (empty($result)) { if (empty($result)) {
$this->clientError(
// TRANS: Client error displayed when an unknown error occurs unsubscribing from a list. // TRANS: Client error displayed when an unknown error occurs unsubscribing from a list.
_('An error occured.'), $this->clientError(_('An error occured.'), 500);
500,
$this->format
);
return false;
} }
switch($this->format) { switch($this->format) {
@ -108,14 +87,8 @@ class ApiListSubscribersAction extends ApiListUsersAction
$this->showSingleJsonList($this->list); $this->showSingleJsonList($this->list);
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
return false;
break;
} }
return true; return true;
} }

View File

@ -46,12 +46,17 @@ class ApiListSubscriptionsAction extends ApiBareAuthAction
* @return boolean success flag * @return boolean success flag
* *
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->cursor = (int) $this->arg('cursor', -1); $this->cursor = (int) $this->arg('cursor', -1);
$this->user = $this->getTargetUser($this->arg('user')); $user = $this->getTargetUser($this->arg('user'));
if (!($user instanceof User)) {
// TRANS: Client error displayed trying to perform an action related to a non-existing user.
$this->clientError(_('No such user.'), 404);
}
$this->target = $user->getProfile();
$this->getLists(); $this->getLists();
return true; return true;
@ -62,19 +67,11 @@ class ApiListSubscriptionsAction extends ApiBareAuthAction
* *
* Show the lists * Show the lists
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if (empty($this->user)) {
// TRANS: Client error displayed trying to perform an action related to a non-existing user.
$this->clientError(_('No such user.'), 404, $this->format);
return;
}
switch($this->format) { switch($this->format) {
case 'xml': case 'xml':
@ -84,13 +81,8 @@ class ApiListSubscriptionsAction extends ApiBareAuthAction
$this->showJsonLists($this->lists, $this->next_cursor, $this->prev_cursor); $this->showJsonLists($this->lists, $this->next_cursor, $this->prev_cursor);
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'));
400,
$this->format
);
break;
} }
} }
@ -110,12 +102,7 @@ class ApiListSubscriptionsAction extends ApiBareAuthAction
function getLists() function getLists()
{ {
if(empty($this->user)) { $fn = array($this->target, 'getTagSubscriptions');
return;
}
$profile = $this->user->getProfile();
$fn = array($profile, 'getTagSubscriptions');
# 20 lists # 20 lists
list($this->lists, $this->next_cursor, $this->prev_cursor) = list($this->lists, $this->next_cursor, $this->prev_cursor) =
Profile_list::getAtCursor($fn, array(), $this->cursor, 20); Profile_list::getAtCursor($fn, array(), $this->cursor, 20);

View File

@ -146,6 +146,8 @@ if (!defined('STATUSNET')) {
*/ */
class ApiStatusesUpdateAction extends ApiAuthAction class ApiStatusesUpdateAction extends ApiAuthAction
{ {
protected $needPost = true;
var $status = null; var $status = null;
var $in_reply_to_status_id = null; var $in_reply_to_status_id = null;
var $lat = null; var $lat = null;
@ -177,24 +179,12 @@ class ApiStatusesUpdateAction extends ApiAuthAction
* *
* Make a new notice for the update, save it, and show it * Make a new notice for the update, save it, and show it
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
protected function handle() protected function handle()
{ {
parent::handle(); parent::handle();
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
// TRANS: Client error. POST is a HTTP command. It should not be translated.
_('This method requires a POST.'),
400,
$this->format
);
return;
}
// Workaround for PHP returning empty $_POST and $_FILES when POST // Workaround for PHP returning empty $_POST and $_FILES when POST
// length > post_max_size in php.ini // length > post_max_size in php.ini
@ -209,23 +199,16 @@ class ApiStatusesUpdateAction extends ApiAuthAction
intval($_SERVER['CONTENT_LENGTH'])); intval($_SERVER['CONTENT_LENGTH']));
$this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH'])); $this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
return;
} }
if (empty($this->status)) { if (empty($this->status)) {
$this->clientError(
// TRANS: Client error displayed when the parameter "status" is missing. // TRANS: Client error displayed when the parameter "status" is missing.
_('Client must provide a \'status\' parameter with a value.'), $this->clientError(_('Client must provide a \'status\' parameter with a value.'));
400,
$this->format
);
return;
} }
if (is_null($this->scoped)) { if (is_null($this->scoped)) {
// TRANS: Client error displayed when updating a status for a non-existing user. // TRANS: Client error displayed when updating a status for a non-existing user.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
/* Do not call shortenlinks until the whole notice has been build */ /* Do not call shortenlinks until the whole notice has been build */
@ -256,13 +239,8 @@ class ApiStatusesUpdateAction extends ApiAuthAction
if ($reply) { if ($reply) {
$reply_to = $this->in_reply_to_status_id; $reply_to = $this->in_reply_to_status_id;
} else { } else {
$this->clientError(
// TRANS: Client error displayed when replying to a non-existing notice. // TRANS: Client error displayed when replying to a non-existing notice.
_('Parent notice not found.'), $this->clientError(_('Parent notice not found.'), 404);
$code = 404,
$this->format
);
return;
} }
} }
@ -271,8 +249,7 @@ class ApiStatusesUpdateAction extends ApiAuthAction
try { try {
$upload = MediaFile::fromUpload('media', $this->scoped); $upload = MediaFile::fromUpload('media', $this->scoped);
} catch (Exception $e) { } catch (Exception $e) {
$this->clientError($e->getMessage(), $e->getCode(), $this->format); $this->clientError($e->getMessage(), $e->getCode());
return;
} }
if (isset($upload)) { if (isset($upload)) {
@ -296,9 +273,7 @@ class ApiStatusesUpdateAction extends ApiAuthAction
/* Use HTTP 413 error code (Request Entity Too Large) /* Use HTTP 413 error code (Request Entity Too Large)
* instead of basic 400 for better understanding * instead of basic 400 for better understanding
*/ */
$this->clientError(sprintf($msg, Notice::maxContent()), $this->clientError(sprintf($msg, Notice::maxContent()), 413);
413,
$this->format);
} }
@ -325,8 +300,7 @@ class ApiStatusesUpdateAction extends ApiAuthAction
$options $options
); );
} catch (Exception $e) { } catch (Exception $e) {
$this->clientError($e->getMessage(), $e->getCode(), $this->format); $this->clientError($e->getMessage(), $e->getCode());
return;
} }
if (isset($upload)) { if (isset($upload)) {

View File

@ -46,7 +46,7 @@ if (!defined('STATUSNET')) {
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/ * @link http://status.net/
*/ */
class ApiSubscriptionsAction extends ApiBareAuthAction abstract class ApiSubscriptionsAction extends ApiBareAuthAction
{ {
var $profiles = null; var $profiles = null;
var $tag = null; var $tag = null;
@ -60,7 +60,7 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
@ -76,12 +76,11 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
$this->count = isset($this->ids_only) ? $this->count = isset($this->ids_only) ?
5000 : (int)$this->arg('count', 100); 5000 : (int)$this->arg('count', 100);
$this->user = $this->getTargetUser($this->arg('id')); $this->target = $this->getTargetProfile($this->arg('id'));
if (empty($this->user)) { if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed when requesting a list of followers for a non-existing user. // TRANS: Client error displayed when requesting a list of followers for a non-existing user.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return false;
} }
$this->profiles = $this->getProfiles(); $this->profiles = $this->getProfiles();
@ -94,18 +93,15 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
* *
* Show the profiles * Show the profiles
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if (!in_array($this->format, array('xml', 'json'))) { if (!in_array($this->format, array('xml', 'json'))) {
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
$this->clientError(_('API method not found.'), $code = 404); $this->clientError(_('API method not found.'), 404);
return;
} }
$this->initDocument($this->format); $this->initDocument($this->format);
@ -120,13 +116,11 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
} }
/** /**
* Get profiles - should get overrrided * Get profiles related to the type of subscriber/subscription action
* *
* @return array Profiles * @return array Profiles
*/ */
function getProfiles() abstract protected function getProfiles();
{
}
/** /**
* Is this action read only? * Is this action read only?
@ -175,7 +169,7 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
array($this->arg('action'), array($this->arg('action'),
common_user_cache_hash($this->auth_user), common_user_cache_hash($this->auth_user),
common_language(), common_language(),
$this->user->id, $this->target->id,
// Caching tags. // Caching tags.
isset($this->ids_only) ? 'IDs' : 'Profiles', isset($this->ids_only) ? 'IDs' : 'Profiles',
strtotime($this->profiles[0]->created), strtotime($this->profiles[0]->created),

View File

@ -57,16 +57,15 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->user = $this->getTargetUser($this->arg('id')); $this->target = $this->getTargetProfile($this->arg('id'));
if (empty($this->user)) { if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed when requesting most recent favourite notices by a user for a non-existing user. // TRANS: Client error displayed when requesting most recent favourite notices by a user for a non-existing user.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
$this->notices = $this->getNotices(); $this->notices = $this->getNotices();
@ -79,13 +78,11 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction
* *
* Just show the notices * Just show the notices
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
$this->showTimeline(); $this->showTimeline();
} }
@ -96,19 +93,17 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction
*/ */
function showTimeline() function showTimeline()
{ {
$profile = $this->user->getProfile();
$sitename = common_config('site', 'name'); $sitename = common_config('site', 'name');
$title = sprintf( $title = sprintf(
// TRANS: Title for timeline of most recent favourite notices by a user. // TRANS: Title for timeline of most recent favourite notices by a user.
// TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname. // TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname.
_('%1$s / Favorites from %2$s'), _('%1$s / Favorites from %2$s'),
$sitename, $sitename,
$this->user->nickname $this->target->nickname
); );
$taguribase = TagURI::base(); $taguribase = TagURI::base();
$id = "tag:$taguribase:Favorites:" . $this->user->id; $id = "tag:$taguribase:Favorites:" . $this->target->id;
$subtitle = sprintf( $subtitle = sprintf(
// TRANS: Subtitle for timeline of most recent favourite notices by a user. // TRANS: Subtitle for timeline of most recent favourite notices by a user.
@ -116,13 +111,13 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction
// TRANS: %3$s is a user nickname. // TRANS: %3$s is a user nickname.
_('%1$s updates favorited by %2$s / %3$s.'), _('%1$s updates favorited by %2$s / %3$s.'),
$sitename, $sitename,
$profile->getBestName(), $this->target->getBestName(),
$this->user->nickname $this->target->nickname
); );
$logo = $profile->avatarUrl(AVATAR_PROFILE_SIZE); $logo = $this->target->avatarUrl(AVATAR_PROFILE_SIZE);
$link = common_local_url('showfavorites', $link = common_local_url('showfavorites',
array('nickname' => $this->user->nickname)); array('nickname' => $this->target->nickname));
$self = $this->getSelfUri(); $self = $this->getSelfUri();
switch($this->format) { switch($this->format) {
@ -171,8 +166,7 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction
break; break;
default: default:
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
$this->clientError(_('API method not found.'), $code = 404); $this->clientError(_('API method not found.'), 404);
break;
} }
} }
@ -187,8 +181,8 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction
common_debug("since id = " . $this->since_id . " max id = " . $this->max_id); common_debug("since id = " . $this->since_id . " max id = " . $this->max_id);
if (!empty($this->auth_user) && $this->auth_user->id == $this->user->id) { if (!empty($this->auth_user) && $this->auth_user->id == $this->target->id) {
$notice = $this->user->favoriteNotices( $notice = $this->target->favoriteNotices(
true, true,
($this->page-1) * $this->count, ($this->page-1) * $this->count,
$this->count, $this->count,
@ -196,7 +190,7 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction
$this->max_id $this->max_id
); );
} else { } else {
$notice = $this->user->favoriteNotices( $notice = $this->target->favoriteNotices(
false, false,
($this->page-1) * $this->count, ($this->page-1) * $this->count,
$this->count, $this->count,
@ -257,7 +251,7 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction
array($this->arg('action'), array($this->arg('action'),
common_user_cache_hash($this->auth_user), common_user_cache_hash($this->auth_user),
common_language(), common_language(),
$this->user->id, $this->target->id,
strtotime($this->notices[0]->created), strtotime($this->notices[0]->created),
strtotime($this->notices[$last]->created)) strtotime($this->notices[$last]->created))
) )

View File

@ -161,15 +161,14 @@ class ApiTimelineFriendsAction extends ApiBareAuthAction
* @return boolean success flag * @return boolean success flag
* *
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->user = $this->getTargetUser($this->arg('id')); $this->target = $this->getTargetProfile($this->arg('id'));
if (empty($this->user)) { if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed when requesting dents of a user and friends for a user that does not exist. // TRANS: Client error displayed when requesting dents of a user and friends for a user that does not exist.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
$this->notices = $this->getNotices(); $this->notices = $this->getNotices();
@ -182,13 +181,11 @@ class ApiTimelineFriendsAction extends ApiBareAuthAction
* *
* Just show the notices * Just show the notices
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
$this->showTimeline(); $this->showTimeline();
} }
@ -199,24 +196,23 @@ class ApiTimelineFriendsAction extends ApiBareAuthAction
*/ */
function showTimeline() function showTimeline()
{ {
$profile = $this->user->getProfile();
$sitename = common_config('site', 'name'); $sitename = common_config('site', 'name');
// TRANS: Title of API timeline for a user and friends. // TRANS: Title of API timeline for a user and friends.
// TRANS: %s is a username. // TRANS: %s is a username.
$title = sprintf(_("%s and friends"), $this->user->nickname); $title = sprintf(_("%s and friends"), $this->target->nickname);
$taguribase = TagURI::base(); $taguribase = TagURI::base();
$id = "tag:$taguribase:FriendsTimeline:" . $this->user->id; $id = "tag:$taguribase:FriendsTimeline:" . $this->target->id;
$subtitle = sprintf( $subtitle = sprintf(
// TRANS: Message is used as a subtitle. %1$s is a user nickname, %2$s is a site name. // TRANS: Message is used as a subtitle. %1$s is a user nickname, %2$s is a site name.
_('Updates from %1$s and friends on %2$s!'), _('Updates from %1$s and friends on %2$s!'),
$this->user->nickname, $this->target->nickname,
$sitename $sitename
); );
$logo = $profile->avatarUrl(AVATAR_PROFILE_SIZE); $logo = $this->target->avatarUrl(AVATAR_PROFILE_SIZE);
$link = common_local_url('all', $link = common_local_url('all',
array('nickname' => $this->user->nickname)); array('nickname' => $this->target->nickname));
$self = $this->getSelfUri(); $self = $this->getSelfUri();
switch($this->format) { switch($this->format) {
@ -266,7 +262,6 @@ class ApiTimelineFriendsAction extends ApiBareAuthAction
default: default:
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
$this->clientError(_('API method not found.'), 404); $this->clientError(_('API method not found.'), 404);
break;
} }
} }
@ -279,13 +274,7 @@ class ApiTimelineFriendsAction extends ApiBareAuthAction
{ {
$notices = array(); $notices = array();
$profile = null; $stream = new InboxNoticeStream($this->target->getUser(), $this->scoped);
if (isset($this->auth_user)) {
$profile = $this->auth_user->getProfile();
}
$stream = new InboxNoticeStream($this->user, $profile);
$notice = $stream->getNotices(($this->page-1) * $this->count, $notice = $stream->getNotices(($this->page-1) * $this->count,
$this->count, $this->count,
@ -343,7 +332,7 @@ class ApiTimelineFriendsAction extends ApiBareAuthAction
array($this->arg('action'), array($this->arg('action'),
common_user_cache_hash($this->auth_user), common_user_cache_hash($this->auth_user),
common_language(), common_language(),
$this->user->id, $this->target->id,
strtotime($this->notices[0]->created), strtotime($this->notices[0]->created),
strtotime($this->notices[$last]->created)) strtotime($this->notices[$last]->created))
) )

View File

@ -60,7 +60,7 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction
* @return boolean success flag * @return boolean success flag
* *
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
@ -74,18 +74,15 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction
* *
* Just show the notices * Just show the notices
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if (empty($this->group)) { if (empty($this->group)) {
// TRANS: Client error displayed requesting most recent notices to a group for a non-existing group. // TRANS: Client error displayed requesting most recent notices to a group for a non-existing group.
$this->clientError(_('Group not found.'), 404, $this->format); $this->clientError(_('Group not found.'), 404);
return false;
} }
$this->notices = $this->getNotices(); $this->notices = $this->getNotices();
@ -139,13 +136,8 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction
$this->raw($doc->asString()); $this->raw($doc->asString());
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when trying to handle an unknown API method. // TRANS: Client error displayed when trying to handle an unknown API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
break;
} }
} }

View File

@ -65,16 +65,15 @@ class ApiTimelineHomeAction extends ApiBareAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->user = $this->getTargetUser($this->arg('id')); $this->target = $this->getTargetProfile($this->arg('id'));
if (empty($this->user)) { if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed when requesting most recent dents by user and friends for a non-existing user. // TRANS: Client error displayed when requesting most recent dents by user and friends for a non-existing user.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
$this->notices = $this->getNotices(); $this->notices = $this->getNotices();
@ -87,13 +86,11 @@ class ApiTimelineHomeAction extends ApiBareAuthAction
* *
* Just show the notices * Just show the notices
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
$this->showTimeline(); $this->showTimeline();
} }
@ -104,22 +101,21 @@ class ApiTimelineHomeAction extends ApiBareAuthAction
*/ */
function showTimeline() function showTimeline()
{ {
$profile = $this->user->getProfile();
$sitename = common_config('site', 'name'); $sitename = common_config('site', 'name');
// TRANS: Timeline title for user and friends. %s is a user nickname. // TRANS: Timeline title for user and friends. %s is a user nickname.
$title = sprintf(_("%s and friends"), $this->user->nickname); $title = sprintf(_("%s and friends"), $this->target->nickname);
$taguribase = TagURI::base(); $taguribase = TagURI::base();
$id = "tag:$taguribase:HomeTimeline:" . $this->user->id; $id = "tag:$taguribase:HomeTimeline:" . $this->target->id;
$subtitle = sprintf( $subtitle = sprintf(
// TRANS: Message is used as a subtitle. %1$s is a user nickname, %2$s is a site name. // TRANS: Message is used as a subtitle. %1$s is a user nickname, %2$s is a site name.
_('Updates from %1$s and friends on %2$s!'), _('Updates from %1$s and friends on %2$s!'),
$this->user->nickname, $sitename $this->target->nickname, $sitename
); );
$logo = $profile->avatarUrl(AVATAR_PROFILE_SIZE); $logo = $this->target->avatarUrl(AVATAR_PROFILE_SIZE);
$link = common_local_url('all', $link = common_local_url('all',
array('nickname' => $this->user->nickname)); array('nickname' => $this->target->nickname));
$self = $this->getSelfUri(); $self = $this->getSelfUri();
switch($this->format) { switch($this->format) {
@ -169,8 +165,7 @@ class ApiTimelineHomeAction extends ApiBareAuthAction
break; break;
default: default:
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
$this->clientError(_('API method not found.'), $code = 404); $this->clientError(_('API method not found.'), 404);
break;
} }
} }
@ -183,13 +178,7 @@ class ApiTimelineHomeAction extends ApiBareAuthAction
{ {
$notices = array(); $notices = array();
$profile = null; $stream = new InboxNoticeStream($this->target->getUser(), $this->scoped);
if (isset($this->auth_user)) {
$profile = $this->auth_user->getProfile();
}
$stream = new InboxNoticeStream($this->user, $profile);
$notice = $stream->getNotices(($this->page-1) * $this->count, $notice = $stream->getNotices(($this->page-1) * $this->count,
$this->count, $this->count,
@ -248,7 +237,7 @@ class ApiTimelineHomeAction extends ApiBareAuthAction
array($this->arg('action'), array($this->arg('action'),
common_user_cache_hash($this->auth_user), common_user_cache_hash($this->auth_user),
common_language(), common_language(),
$this->user->id, $this->target->id,
strtotime($this->notices[0]->created), strtotime($this->notices[0]->created),
strtotime($this->notices[$last]->created)) strtotime($this->notices[$last]->created))
) )

View File

@ -66,7 +66,7 @@ class ApiTimelineListAction extends ApiPrivateAuthAction
* @return boolean success flag * @return boolean success flag
* *
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
@ -81,18 +81,15 @@ class ApiTimelineListAction extends ApiPrivateAuthAction
* *
* Just show the notices * Just show the notices
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if (empty($this->list)) { if (empty($this->list)) {
// TRANS: Client error displayed trying to perform an action related to a non-existing list. // TRANS: Client error displayed trying to perform an action related to a non-existing list.
$this->clientError(_('List not found.'), 404, $this->format); $this->clientError(_('List not found.'), 404);
return false;
} }
$this->getNotices(); $this->getNotices();
@ -152,7 +149,6 @@ class ApiTimelineListAction extends ApiPrivateAuthAction
// TRANS: Server error displayed whe trying to get a timeline fails. // TRANS: Server error displayed whe trying to get a timeline fails.
// TRANS: %s is the error message. // TRANS: %s is the error message.
$this->serverError(sprintf(_('Could not generate feed for list - %s'), $e->getMessage())); $this->serverError(sprintf(_('Could not generate feed for list - %s'), $e->getMessage()));
return;
} }
break; break;
@ -176,13 +172,8 @@ class ApiTimelineListAction extends ApiPrivateAuthAction
$this->initDocument('json'); $this->initDocument('json');
break; break;
default: default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'), $this->clientError(_('API method not found.'), 404);
404,
$this->format
);
break;
} }
} }

View File

@ -64,16 +64,15 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->user = $this->getTargetUser($this->arg('id')); $this->target = $this->getTargetProfile($this->arg('id'));
if (empty($this->user)) { if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed when requesting most recent mentions for a non-existing user. // TRANS: Client error displayed when requesting most recent mentions for a non-existing user.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
$this->notices = $this->getNotices(); $this->notices = $this->getNotices();
@ -86,13 +85,11 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
* *
* Just show the notices * Just show the notices
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
$this->showTimeline(); $this->showTimeline();
} }
@ -103,21 +100,19 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
*/ */
function showTimeline() function showTimeline()
{ {
$profile = $this->user->getProfile();
$sitename = common_config('site', 'name'); $sitename = common_config('site', 'name');
$title = sprintf( $title = sprintf(
// TRANS: Title for timeline of most recent mentions of a user. // TRANS: Title for timeline of most recent mentions of a user.
// TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname. // TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname.
_('%1$s / Updates mentioning %2$s'), _('%1$s / Updates mentioning %2$s'),
$sitename, $this->user->nickname $sitename, $this->target->nickname
); );
$taguribase = TagURI::base(); $taguribase = TagURI::base();
$id = "tag:$taguribase:Mentions:" . $this->user->id; $id = "tag:$taguribase:Mentions:" . $this->target->id;
$logo = $profile->avatarUrl(AVATAR_PROFILE_SIZE); $logo = $this->target->avatarUrl(AVATAR_PROFILE_SIZE);
$link = common_local_url('replies', $link = common_local_url('replies',
array('nickname' => $this->user->nickname)); array('nickname' => $this->target->nickname));
$self = $this->getSelfUri(); $self = $this->getSelfUri();
$subtitle = sprintf( $subtitle = sprintf(
@ -125,7 +120,7 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
// TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname, // TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname,
// TRANS: %3$s is a user's full name. // TRANS: %3$s is a user's full name.
_('%1$s updates that reply to updates from %2$s / %3$s.'), _('%1$s updates that reply to updates from %2$s / %3$s.'),
$sitename, $this->user->nickname, $profile->getBestName() $sitename, $this->target->getBestName(), $this->target->nickname
); );
switch($this->format) { switch($this->format) {
@ -188,13 +183,7 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
{ {
$notices = array(); $notices = array();
if (empty($this->auth_user)) { $stream = new ReplyNoticeStream($this->target->id, $this->scoped);
$profile = null;
} else {
$profile = $this->auth_user->getProfile();
}
$stream = new ReplyNoticeStream($this->user->id, $profile);
$notice = $stream->getNotices(($this->page - 1) * $this->count, $notice = $stream->getNotices(($this->page - 1) * $this->count,
$this->count, $this->count,
@ -253,7 +242,7 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
array($this->arg('action'), array($this->arg('action'),
common_user_cache_hash($this->auth_user), common_user_cache_hash($this->auth_user),
common_language(), common_language(),
$this->user->id, $this->target->id,
strtotime($this->notices[0]->created), strtotime($this->notices[0]->created),
strtotime($this->notices[$last]->created)) strtotime($this->notices[$last]->created))
) )

View File

@ -66,16 +66,15 @@ class ApiTimelineUserAction extends ApiBareAuthAction
* *
* @return boolean success flag * @return boolean success flag
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->user = $this->getTargetUser($this->arg('id')); $this->target = $this->getTargetProfile($this->arg('id'));
if (empty($this->user)) { if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed requesting most recent notices for a non-existing user. // TRANS: Client error displayed requesting most recent notices for a non-existing user.
$this->clientError(_('No such user.'), 404, $this->format); $this->clientError(_('No such user.'), 404);
return;
} }
$this->notices = $this->getNotices(); $this->notices = $this->getNotices();
@ -88,13 +87,11 @@ class ApiTimelineUserAction extends ApiBareAuthAction
* *
* Just show the notices * Just show the notices
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if ($this->isPost()) { if ($this->isPost()) {
$this->handlePost(); $this->handlePost();
@ -110,15 +107,13 @@ class ApiTimelineUserAction extends ApiBareAuthAction
*/ */
function showTimeline() function showTimeline()
{ {
$profile = $this->user->getProfile();
// We'll use the shared params from the Atom stub // We'll use the shared params from the Atom stub
// for other feed types. // for other feed types.
$atom = new AtomUserNoticeFeed($this->user, $this->auth_user); $atom = new AtomUserNoticeFeed($this->target->getUser(), $this->auth_user);
$link = common_local_url( $link = common_local_url(
'showstream', 'showstream',
array('nickname' => $this->user->nickname) array('nickname' => $this->target->nickname)
); );
$self = $this->getSelfUri(); $self = $this->getSelfUri();
@ -126,7 +121,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
// FriendFeed's SUP protocol // FriendFeed's SUP protocol
// Also added RSS and Atom feeds // Also added RSS and Atom feeds
$suplink = common_local_url('sup', null, null, $this->user->id); $suplink = common_local_url('sup', null, null, $this->target->id);
header('X-SUP-ID: ' . $suplink); header('X-SUP-ID: ' . $suplink);
switch($this->format) { switch($this->format) {
@ -157,7 +152,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
if (!empty($this->next_id)) { if (!empty($this->next_id)) {
$nextUrl = common_local_url('ApiTimelineUser', $nextUrl = common_local_url('ApiTimelineUser',
array('format' => 'atom', array('format' => 'atom',
'id' => $this->user->id), 'id' => $this->target->id),
array('max_id' => $this->next_id)); array('max_id' => $this->next_id));
$atom->addLink($nextUrl, $atom->addLink($nextUrl,
@ -172,7 +167,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
$prevUrl = common_local_url('ApiTimelineUser', $prevUrl = common_local_url('ApiTimelineUser',
array('format' => 'atom', array('format' => 'atom',
'id' => $this->user->id), 'id' => $this->target->id),
array('since_id' => $lastId)); array('since_id' => $lastId));
$atom->addLink($prevUrl, $atom->addLink($prevUrl,
@ -184,7 +179,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
$firstUrl = common_local_url('ApiTimelineUser', $firstUrl = common_local_url('ApiTimelineUser',
array('format' => 'atom', array('format' => 'atom',
'id' => $this->user->id)); 'id' => $this->target->id));
$atom->addLink($firstUrl, $atom->addLink($firstUrl,
array('rel' => 'first', array('rel' => 'first',
@ -213,7 +208,6 @@ class ApiTimelineUserAction extends ApiBareAuthAction
default: default:
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
$this->clientError(_('API method not found.'), $code = 404); $this->clientError(_('API method not found.'), $code = 404);
break;
} }
} }
@ -226,7 +220,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
{ {
$notices = array(); $notices = array();
$notice = $this->user->getNotices(($this->page-1) * $this->count, $notice = $this->target->getNotices(($this->page-1) * $this->count,
$this->count + 1, $this->count + 1,
$this->since_id, $this->since_id,
$this->max_id, $this->max_id,
@ -289,7 +283,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
array($this->arg('action'), array($this->arg('action'),
common_user_cache_hash($this->auth_user), common_user_cache_hash($this->auth_user),
common_language(), common_language(),
$this->user->id, $this->target->id,
strtotime($this->notices[0]->created), strtotime($this->notices[0]->created),
strtotime($this->notices[$last]->created)) strtotime($this->notices[$last]->created))
) )
@ -302,17 +296,15 @@ class ApiTimelineUserAction extends ApiBareAuthAction
function handlePost() function handlePost()
{ {
if (empty($this->auth_user) || if (empty($this->auth_user) ||
$this->auth_user->id != $this->user->id) { $this->auth_user->id != $this->target->id) {
// TRANS: Client error displayed trying to add a notice to another user's timeline. // TRANS: Client error displayed trying to add a notice to another user's timeline.
$this->clientError(_('Only the user can add to their own timeline.')); $this->clientError(_('Only the user can add to their own timeline.'));
return;
} }
// Only handle posts for Atom // Only handle posts for Atom
if ($this->format != 'atom') { if ($this->format != 'atom') {
// TRANS: Client error displayed when using another format than AtomPub. // TRANS: Client error displayed when using another format than AtomPub.
$this->clientError(_('Only accept AtomPub for Atom feeds.')); $this->clientError(_('Only accept AtomPub for Atom feeds.'));
return;
} }
$xml = trim(file_get_contents('php://input')); $xml = trim(file_get_contents('php://input'));
@ -334,18 +326,16 @@ class ApiTimelineUserAction extends ApiBareAuthAction
$dom->documentElement->localName != 'entry') { $dom->documentElement->localName != 'entry') {
// TRANS: Client error displayed when not using an Atom entry. // TRANS: Client error displayed when not using an Atom entry.
$this->clientError(_('Atom post must be an Atom entry.')); $this->clientError(_('Atom post must be an Atom entry.'));
return;
} }
$activity = new Activity($dom->documentElement); $activity = new Activity($dom->documentElement);
$saved = null; $saved = null;
if (Event::handle('StartAtomPubNewActivity', array(&$activity, $this->user, &$saved))) { if (Event::handle('StartAtomPubNewActivity', array(&$activity, $this->target->getUser(), &$saved))) {
if ($activity->verb != ActivityVerb::POST) { if ($activity->verb != ActivityVerb::POST) {
// TRANS: Client error displayed when not using the POST verb. Do not translate POST. // TRANS: Client error displayed when not using the POST verb. Do not translate POST.
$this->clientError(_('Can only handle POST activities.')); $this->clientError(_('Can only handle POST activities.'));
return;
} }
$note = $activity->objects[0]; $note = $activity->objects[0];
@ -357,12 +347,11 @@ class ApiTimelineUserAction extends ApiBareAuthAction
// TRANS: %s is the unsupported activity object type. // TRANS: %s is the unsupported activity object type.
$this->clientError(sprintf(_('Cannot handle activity object type "%s".'), $this->clientError(sprintf(_('Cannot handle activity object type "%s".'),
$note->type)); $note->type));
return;
} }
$saved = $this->postNote($activity); $saved = $this->postNote($activity);
Event::handle('EndAtomPubNewActivity', array($activity, $this->user, $saved)); Event::handle('EndAtomPubNewActivity', array($activity, $this->target->getUser(), $saved));
} }
if (!empty($saved)) { if (!empty($saved)) {
@ -389,9 +378,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
// @fixme fetch from $sourceUrl? // @fixme fetch from $sourceUrl?
// TRANS: Client error displayed when posting a notice without content through the API. // TRANS: Client error displayed when posting a notice without content through the API.
// TRANS: %d is the notice ID (number). // TRANS: %d is the notice ID (number).
$this->clientError(sprintf(_('No content for notice %d.'), $this->clientError(sprintf(_('No content for notice %d.'), $note->id));
$note->id));
return;
} }
// Get (safe!) HTML and text versions of the content // Get (safe!) HTML and text versions of the content
@ -418,9 +405,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
if (!empty($notice)) { if (!empty($notice)) {
// TRANS: Client error displayed when using another format than AtomPub. // TRANS: Client error displayed when using another format than AtomPub.
// TRANS: %s is the notice URI. // TRANS: %s is the notice URI.
$this->clientError(sprintf(_('Notice with URI "%s" already exists.'), $this->clientError(sprintf(_('Notice with URI "%s" already exists.'), $note->id));
$note->id));
return;
} }
common_log(LOG_NOTICE, "Saving client-supplied notice URI '$note->id'"); common_log(LOG_NOTICE, "Saving client-supplied notice URI '$note->id'");
$options['uri'] = $note->id; $options['uri'] = $note->id;
@ -494,7 +479,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
$options['urls'][] = $href; $options['urls'][] = $href;
} }
$saved = Notice::saveNew($this->user->id, $saved = Notice::saveNew($this->target->id,
$content, $content,
'atompub', // TODO: deal with this 'atompub', // TODO: deal with this
$options); $options);

View File

@ -29,9 +29,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET')) { if (!defined('GNUSOCIAL')) { exit(1); }
exit(1);
}
/** /**
* Ouputs the authenticating user's followers (subscribers), each with * Ouputs the authenticating user's followers (subscribers), each with
@ -53,7 +51,7 @@ class ApiUserFollowersAction extends ApiSubscriptionsAction
* *
* @return array Profiles * @return array Profiles
*/ */
function getProfiles() protected function getProfiles()
{ {
$offset = ($this->page - 1) * $this->count; $offset = ($this->page - 1) * $this->count;
$limit = $this->count + 1; $limit = $this->count + 1;
@ -61,11 +59,11 @@ class ApiUserFollowersAction extends ApiSubscriptionsAction
$subs = null; $subs = null;
if (isset($this->tag)) { if (isset($this->tag)) {
$subs = $this->user->getTaggedSubscribers( $subs = $this->target->getTaggedSubscribers(
$this->tag, $offset, $limit $this->tag, $offset, $limit
); );
} else { } else {
$subs = $this->user->getSubscribers( $subs = $this->target->getSubscribers(
$offset, $offset,
$limit $limit
); );
@ -73,11 +71,9 @@ class ApiUserFollowersAction extends ApiSubscriptionsAction
$profiles = array(); $profiles = array();
if (!empty($subs)) {
while ($subs->fetch()) { while ($subs->fetch()) {
$profiles[] = clone($subs); $profiles[] = clone($subs);
} }
}
return $profiles; return $profiles;
} }

View File

@ -29,9 +29,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET')) { if (!defined('GNUSOCIAL')) { exit(1); }
exit(1);
}
/** /**
* Ouputs the authenticating user's friends (subscriptions), each with * Ouputs the authenticating user's friends (subscriptions), each with
@ -53,7 +51,7 @@ class ApiUserFriendsAction extends ApiSubscriptionsAction
* *
* @return array Profiles * @return array Profiles
*/ */
function getProfiles() protected function getProfiles()
{ {
$offset = ($this->page - 1) * $this->count; $offset = ($this->page - 1) * $this->count;
$limit = $this->count + 1; $limit = $this->count + 1;
@ -61,11 +59,11 @@ class ApiUserFriendsAction extends ApiSubscriptionsAction
$subs = null; $subs = null;
if (isset($this->tag)) { if (isset($this->tag)) {
$subs = $this->user->getTaggedSubscriptions( $subs = $this->target->getTaggedSubscriptions(
$this->tag, $offset, $limit $this->tag, $offset, $limit
); );
} else { } else {
$subs = $this->user->getSubscribed( $subs = $this->target->getSubscribed(
$offset, $offset,
$limit $limit
); );
@ -73,11 +71,9 @@ class ApiUserFriendsAction extends ApiSubscriptionsAction
$profiles = array(); $profiles = array();
if (!empty($subs)) {
while ($subs->fetch()) { while ($subs->fetch()) {
$profiles[] = clone($subs); $profiles[] = clone($subs);
} }
}
return $profiles; return $profiles;
} }

View File

@ -51,10 +51,15 @@ class ApiUserProfileImageAction extends ApiPrivateAuthAction
* @return boolean success flag * @return boolean success flag
* *
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
$this->user = User::getKV('nickname', $this->arg('screen_name')); $user = User::getKV('nickname', $this->arg('screen_name'));
if (!($user instanceof User)) {
// TRANS: Client error displayed when requesting user information for a non-existing user.
$this->clientError(_('User not found.'), 404);
}
$this->target = $user->getProfile();
$this->size = $this->arg('size'); $this->size = $this->arg('size');
return true; return true;
@ -65,30 +70,14 @@ class ApiUserProfileImageAction extends ApiPrivateAuthAction
* *
* Check the format and show the user info * Check the format and show the user info
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if (empty($this->user)) {
// TRANS: Client error displayed when requesting user information for a non-existing user.
$this->clientError(_('User not found.'), 404, $this->format);
return;
}
$profile = $this->user->getProfile();
if (empty($profile)) {
// TRANS: Error message displayed when referring to a user without a profile.
$this->clientError(_('User has no profile.'));
return;
}
$size = $this->avatarSize(); $size = $this->avatarSize();
$url = $profile->avatarUrl($size); $url = $this->target->avatarUrl($size);
// We don't actually output JSON or XML data -- redirect! // We don't actually output JSON or XML data -- redirect!
common_redirect($url, 302); common_redirect($url, 302);

View File

@ -57,7 +57,7 @@ class ApiUserShowAction extends ApiPrivateAuthAction
* @return boolean success flag * @return boolean success flag
* *
*/ */
function prepare($args) protected function prepare($args)
{ {
parent::prepare($args); parent::prepare($args);
@ -66,11 +66,17 @@ class ApiUserShowAction extends ApiPrivateAuthAction
// XXX: email field deprecated in Twitter's API // XXX: email field deprecated in Twitter's API
if (!empty($email)) { if (!empty($email)) {
$this->user = User::getKV('email', $email); $user = User::getKV('email', $email);
} else { } else {
$this->user = $this->getTargetUser($this->arg('id')); $user = $this->getTargetUser($this->arg('id'));
} }
if (!($user instanceof User)) {
// TRANS: Client error displayed when requesting user information for a non-existing user.
$this->clientError(_('User not found.'), 404);
}
$this->target = $user->getProfile();
return true; return true;
} }
@ -79,35 +85,18 @@ class ApiUserShowAction extends ApiPrivateAuthAction
* *
* Check the format and show the user info * Check the format and show the user info
* *
* @param array $args $_REQUEST data (unused)
*
* @return void * @return void
*/ */
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if (empty($this->user)) {
// TRANS: Client error displayed when requesting user information for a non-existing user.
$this->clientError(_('User not found.'), 404, $this->format);
return;
}
if (!in_array($this->format, array('xml', 'json'))) { if (!in_array($this->format, array('xml', 'json'))) {
// TRANS: Client error displayed when coming across a non-supported API method. // TRANS: Client error displayed when coming across a non-supported API method.
$this->clientError(_('API method not found.'), $code = 404); $this->clientError(_('API method not found.'), 404);
return;
} }
$profile = $this->user->getProfile(); $twitter_user = $this->twitterUserArray($this->target, true);
if (empty($profile)) {
// TRANS: Error message displayed when referring to a user without a profile.
$this->clientError(_('User has no profile.'));
return;
}
$twitter_user = $this->twitterUserArray($this->user->getProfile(), true);
if ($this->format == 'xml') { if ($this->format == 'xml') {
$this->initDocument('xml'); $this->initDocument('xml');

View File

@ -135,6 +135,7 @@ class Action extends HTMLOutputter // lawsuit
protected function prepare(array $args=array()) protected function prepare(array $args=array())
{ {
if ($this->needPost && !$this->isPost()) { if ($this->needPost && !$this->isPost()) {
// TRANS: Client error. POST is a HTTP command. It should not be translated.
$this->clientError(_('This method requires a POST.'), 405); $this->clientError(_('This method requires a POST.'), 405);
} }

View File

@ -1464,6 +1464,9 @@ class ApiAction extends Action
$nickname = common_canonical_nickname($this->arg('screen_name')); $nickname = common_canonical_nickname($this->arg('screen_name'));
$user = User::getKV('nickname', $nickname); $user = User::getKV('nickname', $nickname);
return $user ? $user->getProfile() : null; return $user ? $user->getProfile() : null;
} else {
// Fall back to trying the currently authenticated user
return $this->scoped;
} }
} else if (self::is_decimal($id)) { } else if (self::is_decimal($id)) {
return Profile::getKV($id); return Profile::getKV($id);

View File

@ -106,6 +106,10 @@ class ApiAuthAction extends ApiAction
$this->scoped = null; $this->scoped = null;
} }
// legacy user transferral
// TODO: remove when sure no extended classes need it
$this->user = $this->auth_user;
// Reject API calls with the wrong access level // Reject API calls with the wrong access level
if ($this->isReadOnly($args) == false) { if ($this->isReadOnly($args) == false) {

View File

@ -40,7 +40,7 @@ class ApiListUsersAction extends ApiBareAuthAction
var $prev_cursor = 0; var $prev_cursor = 0;
var $users = null; var $users = null;
function prepare($args) protected function prepare($args)
{ {
// delete list member if method is DELETE or if method is POST and an argument // delete list member if method is DELETE or if method is POST and an argument
// _method is set to DELETE // _method is set to DELETE
@ -53,7 +53,7 @@ class ApiListUsersAction extends ApiBareAuthAction
$_SERVER['REQUEST_METHOD'] == 'POST'); $_SERVER['REQUEST_METHOD'] == 'POST');
if ($this->arg('id')) { if ($this->arg('id')) {
$this->user = $this->getTargetUser($this->arg('id')); $this->target = $this->getTargetProfile($this->arg('id'));
} }
parent::prepare($args); parent::prepare($args);
@ -78,9 +78,9 @@ class ApiListUsersAction extends ApiBareAuthAction
$this->create || $this->delete; $this->create || $this->delete;
} }
function handle($args) protected function handle()
{ {
parent::handle($args); parent::handle();
if($this->delete) { if($this->delete) {
return $this->handleDelete(); return $this->handleDelete();