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
{
protected $needPost = true;
/**
* Take arguments for running
*
@ -75,15 +77,6 @@ class ApiAccountUpdateDeliveryDeviceAction extends ApiAuthAction
{
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'))) {
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method.
@ -105,8 +98,7 @@ class ApiAccountUpdateDeliveryDeviceAction extends ApiAuthAction
if (empty($this->user)) {
// 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);
return;
$this->clientError(_('No such user.'), 404);
}
$original = clone($this->user);

View File

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

View File

@ -43,43 +43,18 @@ if (!defined('STATUSNET')) {
*/
class ApiAccountUpdateProfileImageAction extends ApiAuthAction
{
/**
* 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;
}
protected $needPost = true;
/**
* Handle the request
*
* Check whether the credentials are valid and output the result
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
function handle($args)
protected function handle()
{
parent::handle($args);
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;
}
parent::handle();
// Workaround for PHP returning empty $_POST and $_FILES when POST
// 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.',
intval($_SERVER['CONTENT_LENGTH']));
$this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
return;
}
if (empty($this->user)) {
// TRANS: Client error displayed updating profile image without having a user object.
$this->clientError(_('No such user.'), 404, $this->format);
return;
$this->clientError(_('No such user.'), 404);
}
try {
$imagefile = ImageFile::fromUpload('image');
} catch (Exception $e) {
$this->clientError($e->getMessage(), 400, $this->format);
return;
$this->clientError($e->getMessage());
}
$type = $imagefile->preferredType();
@ -123,13 +95,6 @@ class ApiAccountUpdateProfileImageAction extends ApiAuthAction
$imagefile->copyTo($filepath);
$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);
common_broadcast_profile($profile);

View File

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

View File

@ -46,6 +46,8 @@ if (!defined('STATUSNET')) {
*/
class ApiBlockCreateAction extends ApiAuthAction
{
protected $needPost = true;
var $other = null;
/**
@ -56,11 +58,10 @@ class ApiBlockCreateAction extends ApiAuthAction
* @return boolean success flag
*
*/
function prepare($args)
protected function prepare($args)
{
parent::prepare($args);
$this->user = $this->auth_user;
$this->other = $this->getTargetProfile($this->arg('id'));
return true;
@ -75,36 +76,20 @@ class ApiBlockCreateAction extends ApiAuthAction
*
* @return void
*/
function handle($args)
protected function handle()
{
parent::handle($args);
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;
}
parent::handle();
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.
$this->clientError(_('No such user.'), 404, $this->format);
return;
$this->clientError(_('No such user.'), 404);
}
// Don't allow blocking yourself!
if ($this->user->id == $this->other->id) {
$this->clientError(
// TRANS: Client error displayed when users try to block themselves.
_("You cannot block yourself!"),
403,
$this->format
);
return;
$this->clientError(_("You cannot block yourself!"), 403);
}
if (!$this->user->hasBlocked($this->other)) {
@ -122,7 +107,7 @@ class ApiBlockCreateAction extends ApiAuthAction
$this->endDocument($this->format);
} else {
// 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
{
protected $needPost = true;
var $other = null;
/**
@ -54,11 +56,10 @@ class ApiBlockDestroyAction extends ApiAuthAction
*
* @return boolean success flag
*/
function prepare($args)
protected function prepare($args)
{
parent::prepare($args);
$this->user = $this->auth_user;
$this->other = $this->getTargetProfile($this->arg('id'));
return true;
@ -69,28 +70,15 @@ class ApiBlockDestroyAction extends ApiAuthAction
*
* Save the new message
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
function handle($args)
protected function handle()
{
parent::handle($args);
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;
}
parent::handle();
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.
$this->clientError(_('No such user.'), 404, $this->format);
return;
$this->clientError(_('No such user.'), 404);
}
if ($this->user->hasBlocked($this->other)) {

View File

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

View File

@ -49,6 +49,8 @@ if (!defined('STATUSNET')) {
*/
class ApiDirectMessageNewAction extends ApiAuthAction
{
protected $needPost = true;
var $other = null;
var $content = null;
@ -59,22 +61,17 @@ class ApiDirectMessageNewAction extends ApiAuthAction
*
* @return boolean success flag
*/
function prepare($args)
protected function prepare($args)
{
parent::prepare($args);
$this->user = $this->auth_user;
if (empty($this->user)) {
// TRANS: Client error when user not found for an API direct message action.
$this->clientError(_('No such user.'), 404, $this->format);
return;
$this->clientError(_('No such user.'), 404);
}
$this->content = $this->trimmed('text');
$this->user = $this->auth_user;
$user_param = $this->trimmed('user');
$user_id = $this->arg('user_id');
$screen_name = $this->trimmed('screen_name');
@ -91,67 +88,38 @@ class ApiDirectMessageNewAction extends ApiAuthAction
*
* Save the new message
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
function handle($args)
protected function handle()
{
parent::handle($args);
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;
}
parent::handle();
if (empty($this->content)) {
$this->clientError(
// TRANS: Client error displayed when no message text was submitted (406).
_('No message text!'),
406,
$this->format
);
$this->clientError(_('No message text!'), 406);
} else {
$content_shortened = $this->auth_user->shortenLinks($this->content);
if (Message::contentTooLong($content_shortened)) {
$this->clientError(
// TRANS: Client error displayed when message content is too long.
// 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()),
Message::maxContent()
),
406,
$this->format
);
return;
$this->clientError(
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);
}
}
if (empty($this->other)) {
// TRANS: Client error displayed if a recipient user could not be found (403).
$this->clientError(_('Recipient user not found.'), 403, $this->format);
return;
$this->clientError(_('Recipient user not found.'), 403);
} 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).
_('Cannot send direct messages to users who aren\'t your friend.'),
403,
$this->format
);
return;
$this->clientError(_('Cannot send direct messages to users who aren\'t your friend.'), 403);
} else if ($this->user->id == $this->other->id) {
// Note: sending msgs to yourself is allowed by Twitter
// TRANS: Client error displayed trying to direct message self (403).
$this->clientError(_('Do not send a message to yourself; ' .
'just say it to yourself quietly instead.'), 403, $this->format);
return;
$this->clientError(_('Do not send a message to yourself; just say it to yourself quietly instead.'), 403);
}
$message = Message::saveNew(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -49,6 +49,8 @@ if (!defined('STATUSNET')) {
*/
class ApiGroupJoinAction extends ApiAuthAction
{
protected $needPost = true;
var $group = null;
/**
@ -58,11 +60,10 @@ class ApiGroupJoinAction extends ApiAuthAction
*
* @return boolean success flag
*/
function prepare($args)
protected function prepare($args)
{
parent::prepare($args);
$this->user = $this->auth_user;
$this->group = $this->getTargetGroup($this->arg('id'));
return true;
@ -73,54 +74,30 @@ class ApiGroupJoinAction extends ApiAuthAction
*
* Save the new message
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
function handle($args)
protected function handle()
{
parent::handle($args);
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;
}
parent::handle();
if (empty($this->user)) {
// TRANS: Client error displayed when trying to have a non-existing user join a group.
$this->clientError(_('No such user.'), 404, $this->format);
return;
$this->clientError(_('No such user.'), 404);
}
if (empty($this->group)) {
// TRANS: Client error displayed when trying to join a group that does not exist.
$this->clientError(_('Group not found.'), 404, $this->format);
return false;
$this->clientError(_('Group not found.'), 404);
}
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.
_('You are already a member of that group.'),
403,
$this->format
);
return;
$this->clientError(_('You are already a member of that group.'), 403);
}
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.
_('You have been blocked from that group by the admin.'),
403,
$this->format
);
return;
$this->clientError(_('You have been blocked from that group by the admin.'), 403);
}
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.
$this->serverError(sprintf(_('Could not join user %1$s to group %2$s.'),
$cur->nickname, $this->group->nickname));
return;
}
switch($this->format) {
@ -141,13 +117,8 @@ class ApiGroupJoinAction extends ApiAuthAction
$this->showSingleJsonGroup($this->group);
break;
default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'),
404,
$this->format
);
break;
$this->clientError(_('API method not found.'), 404);
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -61,7 +61,7 @@ class ApiListsAction extends ApiBareAuthAction
*
* @return boolean success flag
*/
function prepare($args)
protected function prepare($args)
{
parent::prepare($args);
@ -71,11 +71,11 @@ class ApiListsAction extends ApiBareAuthAction
$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.
$this->clientError(_('No such user.'), 404, $this->format);
return false;
$this->clientError(_('No such user.'), 404);
}
$this->target = $user->getProfile();
$this->getLists();
}
@ -97,9 +97,9 @@ class ApiListsAction extends ApiBareAuthAction
* 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.
*/
function handle($args)
protected function handle()
{
parent::handle($args);
parent::handle();
if($this->create) {
return $this->handlePost();
@ -165,13 +165,8 @@ class ApiListsAction extends ApiBareAuthAction
$this->showSingleJsonList($list);
break;
default:
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method.
_('API method not found.'),
404,
$this->format
);
break;
$this->clientError(_('API method not found.'), 404);
}
return true;
}
@ -186,8 +181,7 @@ class ApiListsAction extends ApiBareAuthAction
// twitter fixes count at 20
// there is no argument named count
$count = 20;
$profile = $this->user->getProfile();
$fn = array($profile, 'getLists');
$fn = array($this->target, 'getLists');
list($this->lists,
$this->next_cursor,
@ -226,7 +220,7 @@ class ApiListsAction extends ApiBareAuthAction
':',
array($this->arg('action'),
common_language(),
$this->user->id,
$this->target->id,
strtotime($this->lists[0]->created),
strtotime($this->lists[$last]->created))
)

View File

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

View File

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

View File

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

View File

@ -146,6 +146,8 @@ if (!defined('STATUSNET')) {
*/
class ApiStatusesUpdateAction extends ApiAuthAction
{
protected $needPost = true;
var $status = null;
var $in_reply_to_status_id = null;
var $lat = null;
@ -177,24 +179,12 @@ class ApiStatusesUpdateAction extends ApiAuthAction
*
* Make a new notice for the update, save it, and show it
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
protected function 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
// length > post_max_size in php.ini
@ -209,23 +199,16 @@ class ApiStatusesUpdateAction extends ApiAuthAction
intval($_SERVER['CONTENT_LENGTH']));
$this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
return;
}
if (empty($this->status)) {
$this->clientError(
// TRANS: Client error displayed when the parameter "status" is missing.
_('Client must provide a \'status\' parameter with a value.'),
400,
$this->format
);
return;
$this->clientError(_('Client must provide a \'status\' parameter with a value.'));
}
if (is_null($this->scoped)) {
// TRANS: Client error displayed when updating a status for a non-existing user.
$this->clientError(_('No such user.'), 404, $this->format);
return;
$this->clientError(_('No such user.'), 404);
}
/* Do not call shortenlinks until the whole notice has been build */
@ -256,13 +239,8 @@ class ApiStatusesUpdateAction extends ApiAuthAction
if ($reply) {
$reply_to = $this->in_reply_to_status_id;
} else {
$this->clientError(
// TRANS: Client error displayed when replying to a non-existing notice.
_('Parent notice not found.'),
$code = 404,
$this->format
);
return;
$this->clientError(_('Parent notice not found.'), 404);
}
}
@ -271,8 +249,7 @@ class ApiStatusesUpdateAction extends ApiAuthAction
try {
$upload = MediaFile::fromUpload('media', $this->scoped);
} catch (Exception $e) {
$this->clientError($e->getMessage(), $e->getCode(), $this->format);
return;
$this->clientError($e->getMessage(), $e->getCode());
}
if (isset($upload)) {
@ -296,9 +273,7 @@ class ApiStatusesUpdateAction extends ApiAuthAction
/* Use HTTP 413 error code (Request Entity Too Large)
* instead of basic 400 for better understanding
*/
$this->clientError(sprintf($msg, Notice::maxContent()),
413,
$this->format);
$this->clientError(sprintf($msg, Notice::maxContent()), 413);
}
@ -325,8 +300,7 @@ class ApiStatusesUpdateAction extends ApiAuthAction
$options
);
} catch (Exception $e) {
$this->clientError($e->getMessage(), $e->getCode(), $this->format);
return;
$this->clientError($e->getMessage(), $e->getCode());
}
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
* @link http://status.net/
*/
class ApiSubscriptionsAction extends ApiBareAuthAction
abstract class ApiSubscriptionsAction extends ApiBareAuthAction
{
var $profiles = null;
var $tag = null;
@ -60,7 +60,7 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
*
* @return boolean success flag
*/
function prepare($args)
protected function prepare($args)
{
parent::prepare($args);
@ -76,12 +76,11 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
$this->count = isset($this->ids_only) ?
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.
$this->clientError(_('No such user.'), 404, $this->format);
return false;
$this->clientError(_('No such user.'), 404);
}
$this->profiles = $this->getProfiles();
@ -94,18 +93,15 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
*
* Show the profiles
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
function handle($args)
protected function handle()
{
parent::handle($args);
parent::handle();
if (!in_array($this->format, array('xml', 'json'))) {
// TRANS: Client error displayed when coming across a non-supported API method.
$this->clientError(_('API method not found.'), $code = 404);
return;
$this->clientError(_('API method not found.'), 404);
}
$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
*/
function getProfiles()
{
}
abstract protected function getProfiles();
/**
* Is this action read only?
@ -175,7 +169,7 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
array($this->arg('action'),
common_user_cache_hash($this->auth_user),
common_language(),
$this->user->id,
$this->target->id,
// Caching tags.
isset($this->ids_only) ? 'IDs' : 'Profiles',
strtotime($this->profiles[0]->created),

View File

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

View File

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

View File

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

View File

@ -65,16 +65,15 @@ class ApiTimelineHomeAction extends ApiBareAuthAction
*
* @return boolean success flag
*/
function prepare($args)
protected function 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.
$this->clientError(_('No such user.'), 404, $this->format);
return;
$this->clientError(_('No such user.'), 404);
}
$this->notices = $this->getNotices();
@ -87,13 +86,11 @@ class ApiTimelineHomeAction extends ApiBareAuthAction
*
* Just show the notices
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
function handle($args)
protected function handle()
{
parent::handle($args);
parent::handle();
$this->showTimeline();
}
@ -104,22 +101,21 @@ class ApiTimelineHomeAction extends ApiBareAuthAction
*/
function showTimeline()
{
$profile = $this->user->getProfile();
$sitename = common_config('site', 'name');
// 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();
$id = "tag:$taguribase:HomeTimeline:" . $this->user->id;
$id = "tag:$taguribase:HomeTimeline:" . $this->target->id;
$subtitle = sprintf(
// 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!'),
$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',
array('nickname' => $this->user->nickname));
array('nickname' => $this->target->nickname));
$self = $this->getSelfUri();
switch($this->format) {
@ -169,8 +165,7 @@ class ApiTimelineHomeAction extends ApiBareAuthAction
break;
default:
// TRANS: Client error displayed when coming across a non-supported API method.
$this->clientError(_('API method not found.'), $code = 404);
break;
$this->clientError(_('API method not found.'), 404);
}
}
@ -183,13 +178,7 @@ class ApiTimelineHomeAction extends ApiBareAuthAction
{
$notices = array();
$profile = null;
if (isset($this->auth_user)) {
$profile = $this->auth_user->getProfile();
}
$stream = new InboxNoticeStream($this->user, $profile);
$stream = new InboxNoticeStream($this->target->getUser(), $this->scoped);
$notice = $stream->getNotices(($this->page-1) * $this->count,
$this->count,
@ -248,7 +237,7 @@ class ApiTimelineHomeAction extends ApiBareAuthAction
array($this->arg('action'),
common_user_cache_hash($this->auth_user),
common_language(),
$this->user->id,
$this->target->id,
strtotime($this->notices[0]->created),
strtotime($this->notices[$last]->created))
)

View File

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

View File

@ -64,16 +64,15 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
*
* @return boolean success flag
*/
function prepare($args)
protected function 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.
$this->clientError(_('No such user.'), 404, $this->format);
return;
$this->clientError(_('No such user.'), 404);
}
$this->notices = $this->getNotices();
@ -86,13 +85,11 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
*
* Just show the notices
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
function handle($args)
protected function handle()
{
parent::handle($args);
parent::handle();
$this->showTimeline();
}
@ -103,21 +100,19 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
*/
function showTimeline()
{
$profile = $this->user->getProfile();
$sitename = common_config('site', 'name');
$title = sprintf(
// TRANS: Title for timeline of most recent mentions of a user.
// TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname.
_('%1$s / Updates mentioning %2$s'),
$sitename, $this->user->nickname
$sitename, $this->target->nickname
);
$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',
array('nickname' => $this->user->nickname));
array('nickname' => $this->target->nickname));
$self = $this->getSelfUri();
$subtitle = sprintf(
@ -125,7 +120,7 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
// TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname,
// TRANS: %3$s is a user's full name.
_('%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) {
@ -188,13 +183,7 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
{
$notices = array();
if (empty($this->auth_user)) {
$profile = null;
} else {
$profile = $this->auth_user->getProfile();
}
$stream = new ReplyNoticeStream($this->user->id, $profile);
$stream = new ReplyNoticeStream($this->target->id, $this->scoped);
$notice = $stream->getNotices(($this->page - 1) * $this->count,
$this->count,
@ -253,7 +242,7 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
array($this->arg('action'),
common_user_cache_hash($this->auth_user),
common_language(),
$this->user->id,
$this->target->id,
strtotime($this->notices[0]->created),
strtotime($this->notices[$last]->created))
)

View File

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

View File

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

View File

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

View File

@ -51,10 +51,15 @@ class ApiUserProfileImageAction extends ApiPrivateAuthAction
* @return boolean success flag
*
*/
function prepare($args)
protected function 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');
return true;
@ -65,30 +70,14 @@ class ApiUserProfileImageAction extends ApiPrivateAuthAction
*
* Check the format and show the user info
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
function handle($args)
protected function handle()
{
parent::handle($args);
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;
}
parent::handle();
$size = $this->avatarSize();
$url = $profile->avatarUrl($size);
$url = $this->target->avatarUrl($size);
// We don't actually output JSON or XML data -- redirect!
common_redirect($url, 302);

View File

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

View File

@ -135,6 +135,7 @@ class Action extends HTMLOutputter // lawsuit
protected function prepare(array $args=array())
{
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);
}

View File

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

View File

@ -106,6 +106,10 @@ class ApiAuthAction extends ApiAction
$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
if ($this->isReadOnly($args) == false) {

View File

@ -40,7 +40,7 @@ class ApiListUsersAction extends ApiBareAuthAction
var $prev_cursor = 0;
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
// _method is set to DELETE
@ -52,8 +52,8 @@ class ApiListUsersAction extends ApiBareAuthAction
$this->create = (!$this->delete &&
$_SERVER['REQUEST_METHOD'] == 'POST');
if($this->arg('id')) {
$this->user = $this->getTargetUser($this->arg('id'));
if ($this->arg('id')) {
$this->target = $this->getTargetProfile($this->arg('id'));
}
parent::prepare($args);
@ -78,9 +78,9 @@ class ApiListUsersAction extends ApiBareAuthAction
$this->create || $this->delete;
}
function handle($args)
protected function handle()
{
parent::handle($args);
parent::handle();
if($this->delete) {
return $this->handleDelete();