]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Making many of the API actions more consistent with coding style
authorMikael Nordfeldth <mmn@hethane.se>
Tue, 15 Oct 2013 00:54:10 +0000 (02:54 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Tue, 15 Oct 2013 01:07:40 +0000 (03:07 +0200)
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.

43 files changed:
actions/apiaccountupdatedeliverydevice.php
actions/apiaccountupdateprofile.php
actions/apiaccountupdateprofileimage.php
actions/apiatomservice.php
actions/apiblockcreate.php
actions/apiblockdestroy.php
actions/apidirectmessage.php
actions/apidirectmessagenew.php
actions/apifriendshipscreate.php
actions/apignusocialconfig.php
actions/apignusocialversion.php
actions/apigroupcreate.php
actions/apigroupismember.php
actions/apigroupjoin.php
actions/apigroupleave.php
actions/apigroupmembership.php
actions/apigroupprofileupdate.php
actions/apigroupshow.php
actions/apilist.php
actions/apilistmember.php
actions/apilistmembers.php
actions/apilistmemberships.php
actions/apilists.php
actions/apilistsubscriber.php
actions/apilistsubscribers.php
actions/apilistsubscriptions.php
actions/apistatusesupdate.php
actions/apisubscriptions.php
actions/apitimelinefavorites.php
actions/apitimelinefriends.php
actions/apitimelinegroup.php
actions/apitimelinehome.php
actions/apitimelinelist.php
actions/apitimelinementions.php
actions/apitimelineuser.php
actions/apiuserfollowers.php
actions/apiuserfriends.php
actions/apiuserprofileimage.php
actions/apiusershow.php
lib/action.php
lib/apiaction.php
lib/apiauthaction.php
lib/apilistusers.php

index dd0c40445647585233d0cd6945d014eb46504abf..425624707ae218995e18b81ad94139cfb872c7b5 100644 (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);
index 04151ec01eb8aacc095668eaf029d618dd3784c2..fea6064f30b7cbecf508a048424797049c0d879c 100644 (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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $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();
index 07cafbdb99bbf3f73350040d85f83123595f1215..6058d4fabd06b5d9c140dbf94efbd0649418fd95 100644 (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);
index 8267c38b839e9b8db712cb8ac756759327d3f347..9e45a30fcc2e883434254f4ddd421b2b3747b714 100644 (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;
index bb0d7228896662551194e390d4404c2d91cb1230..959323699151d9427fd643b9d0645506d72b415f 100644 (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;
+            // TRANS: Client error displayed when users try to block themselves.
+            $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);
         }
     }
 }
index 535c7a10ab6e902d997c4264e016e746d3932504..692e10f7279fcf2bf91d0ef988edac4412610cdf 100644 (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)) {
index 308d143f27a68102a9e0deb7982f900fca10c3a6..e971a7d4eed9953434481dc2f324aa8def2694d1 100644 (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();
index 6d637fcb46461c9b27839460841f4ef155d78ead..41039cf0df12759d780186415f56fb2fce11903e 100644 (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
-            );
+            // TRANS: Client error displayed when no message text was submitted (406).
+            $this->clientError(_('No message text!'), 406);
         } else {
             $content_shortened = $this->auth_user->shortenLinks($this->content);
             if (Message::contentTooLong($content_shortened)) {
+                // TRANS: Client error displayed when message content is too long.
+                // TRANS: %d is the maximum number of characters for a message.
                 $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;
+                    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;
+            // TRANS: Client error displayed trying to direct message another user who's not a friend (403).
+            $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(
index 9c410f379a08f648beb098ceb7e88564b0418989..500610563e3aaf62580b6922709e23f6a169176d 100644 (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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $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;
+            // TRANS: Client error displayed when trying follow who's profile could not be found.
+            $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);
index a6105006b4dcdfb03a5e0d8cee8dd2b18bf3ff5f..813073a9edcb4bf959b4e713bb77b365734c81b0 100644 (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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $this->clientError(_('API method not found.'), 404);
         }
     }
 
index e50e2d59da6f07c7313735c40285bef0895b0874..88fb5c51a62c2521c57414b6f17fdf3701ed5508 100644 (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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $this->clientError(_('API method not found.'), 404);
         }
     }
 
index ea23fdf3bae205e039a12b629fb4ecd706c9bd96..2dd0e9db1b570a9f31ed25a5e1f63b740b50544e 100644 (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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $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(
-                // TRANS: Client error in form for group creation.
-                _('Not a valid nickname.'),
-                403,
-                $this->format
-            );
-            return false;
+            // TRANS: Client error trying to create a group with a nickname this is already in use.
+            $this->clientError(_('Nickname already in use. Try another one.'), 403);
+
+        } elseif (!User_group::allowedNickname($this->nickname)) {
+            // TRANS: Client error in form for group creation.
+            $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;
+            // TRANS: Client error in form for group creation.
+            $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;
+                !is_null($this->fullname)
+                && mb_strlen($this->fullname) > 255) {
+            // TRANS: Client error in form for group creation.
+            $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).',
-                      'Description is too long (maximum %d characters).',
-                      User_group::maxDescription()),
-                    User_group::maxDescription()
-                ),
-                403,
-                $this->format
-            );
-            return false;
-        } 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;
+            // TRANS: Client error shown when providing too long a description during group creation.
+            // TRANS: %d is the maximum number of allowed characters.
+            $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);
+
+        } elseif (!is_null($this->location)
+                && mb_strlen($this->location) > 255) {
+            // TRANS: Client error shown when providing too long a location during group creation.
+            $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;
+                // TRANS: Client error shown when providing an invalid alias during group creation.
+                // TRANS: %s is the invalid alias.
+                $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;
+                // 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.
+                $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;
+                // TRANS: Client error displayed when trying to use an alias during group creation that is the same as the group's nickname.
+                $this->clientError(_('Alias can\'t be the same as nickname.'), 403);
             }
         }
 
index c9a363582b75b4f8bda6bb6f555c585dd8f155dc..530da577294e290f11ecad0049ff2566ecc17400 100644 (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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $this->clientError(_('API method not found.'));
         }
     }
 
index e18e20c5dd3bc2496cc02af15d0cdc5b22b279a9..f95c55f8457a0245a527a3e6c491c741f5cd7622 100644 (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;
+            // TRANS: Server error displayed when trying to join a group the user is already a member of.
+            $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;
+            // TRANS: Server error displayed when trying to join a group the user is blocked from joining.
+            $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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $this->clientError(_('API method not found.'), 404);
         }
     }
 }
index bdfa36aa432bf682623a09bd6e82f9e44a80e32f..0850ee2e641a8ffd0a2fd14f567e5e18ec1d9a6f 100644 (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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $this->clientError(_('API method not found.'), 404);
         }
     }
 }
index ed78d9eda8a27d588618b82cd0cd7e89ac41ebf8..3fdac2f4ce09f5f4f8f0d284b41aa95c0d2c0cce 100644 (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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $this->clientError(_('API method not found.'), 404);
         }
     }
 
index 05fd3ab57f7498ee43c1efd586fbf59c8387fd49..14ec84326967ccafc8a2ba667579e2ad1fa3ad5d 100644 (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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $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);
         }
     }
 
index 15b9edb975543937c5ed178df2d8d425e26cbb9e..2384c19b569ffa0776858bc7adae0cb976f717ad 100644 (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
-                );
+                // TRANS: Client error displayed when trying to show a group that could not be found.
+                $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);
         }
     }
 
index 56d0f0f1bc14452d3eeea54d9566c77242f1f20e..21466954e1936d890b523b93b4476c2ceddf9678 100644 (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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $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
-            );
+            // TRANS: Client error displayed when trying to update another user's list.
+            $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
-            );
+            // TRANS: Client error displayed when an unknown error occurs updating a list.
+            $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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $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
-            );
+            // TRANS: Client error displayed when trying to delete another user's list.
+            $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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $this->clientError(_('API method not found.'), 404);
         }
     }
 
index 1d56a3dbc7a22a4f1b5f225fc8afb1e609bc30cd..e631d710d28ffd376392c95808c07bba2fce57fa 100644 (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
-            );
+            // TRANS: Client error displayed when referring to a non-list member.
+            $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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $this->clientError(_('API method not found.'), 404);
         }
         return true;
     }
index 0c003fd6dccb18763efe56ec729515e0e5c797cc..bd78451d5ee76c180d2995ddb996b936647b9ae0 100644 (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;
+            // TRANS: Client error displayed when trying to add members to a list without having the right to do so.
+            $this->clientError(_('You are not allowed to add members to this list.'), 401);
         }
 
-        if($this->user === false) {
-            $this->clientError(
-                // TRANS: Client error displayed when trying to modify list members without specifying them.
-                _('You must specify a member.'),
-                400,
-                $this->format
-            );
-            return false;
+        if (!($this->target instanceof Profile)) {
+            // TRANS: Client error displayed when trying to modify list members without specifying them.
+            $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;
+            // TRANS: Client error displayed when an unknown error occurs viewing list members.
+            $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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $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;
+            // TRANS: Client error displayed when trying to remove members from a list without having the right to do so.
+            $this->clientError(_('You are not allowed to remove members from this list.'), 401);
         }
 
-        if($this->user === false) {
-            $this->clientError(
-                // TRANS: Client error displayed when trying to modify list members without specifying them.
-                _('You must specify a member.'),
-                400,
-                $this->format
-            );
-            return false;
+        if (!($this->target instanceof Profile)) {
+            // TRANS: Client error displayed when trying to modify list members without specifying them.
+            $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(
-                // 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;
+        if (empty($ptag)) {
+            // TRANS: Client error displayed when trying to remove a list member that is not part of a list.
+            $this->clientError(_('The user you are trying to remove from the list is not a member.'));
         }
 
-        $result = $ptag->delete();
-
-        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;
+        if (!$ptag->delete()) {
+            // TRANS: Client error displayed when an unknown error occurs viewing list members.
+            $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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $this->clientError(_('API method not found.'), 404);
         }
+
         return true;
     }
 
index 9dc48fa8d45d0b13482313144c962daa288ab786..d897853444883b2e2ce2406ff71effc5713a950f 100644 (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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $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
index 529bdd67856e0616d8d896bf8b73be8519c60dfd..ac76c744d7b7baf9988e3f32457d85b5a002f8b7 100644 (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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $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))
             )
index 9d7fde329f3ec6a474ea14b65dac42f4f7aa691a..f5cda15ae94aa8ce17d47b74f1d797ac722536f8 100644 (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
-            );
+            // TRANS: Client error displayed when a membership check for a user is nagative.
+            $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':
index 480f9b4a5f2fd2d70d76bcff08d53ee273f4a957..66cb5f17d7434d720cfc75aab55571d1773f88df 100644 (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;
+            // TRANS: Client error displayed when an unknown error occurs in the list subscribers action.
+            $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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $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;
+            // TRANS: Client error displayed when trying to unsubscribe from a non-subscribed list.
+            $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(
-                // TRANS: Client error displayed when an unknown error occurs unsubscribing from a list.
-                _('An error occured.'),
-                500,
-                $this->format
-            );
-            return false;
+        if (empty($result)) {
+            // TRANS: Client error displayed when an unknown error occurs unsubscribing from a list.
+            $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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $this->clientError(_('API method not found.'), 404);
         }
         return true;
     }
index 263d00ca3009a82751365c925415ca3c87c5d196..d61b0e856e2ef7382305a3bd2d80fef4b268a837 100644 (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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $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);
index ac93d58e33d6b697f3afbc5729bfcab2941c2985..73b87cac988de4f596433441fe6d5819ddb3b9f8 100644 (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;
+            // TRANS: Client error displayed when the parameter "status" is missing.
+            $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;
+                    // TRANS: Client error displayed when replying to a non-existing notice.
+                    $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)) {
index be53086ee4001f46a54c079613f3117e1c1026c5..6d50de95061b0a2d505eed37b7166c8320ecb761 100644 (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),
index 85f22d910bf514102183683d72ae1b5d7c4b6c35..6a57219163c3ce05d6d0abecc26beb0e66dd7a69 100644 (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))
             )
index 42cdde4c513d44e37f32ab8af155419372a5cdad..cab9f37808c8311fa69569bc9a9c488adcd3af81 100644 (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))
                                  )
index c238f3a989f005205bb63a86ebe4c87fa3cc986f..b2b549557cfd9c87d62db6c89a51c65201cf0d68 100644 (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;
+            // TRANS: Client error displayed when trying to handle an unknown API method.
+            $this->clientError(_('API method not found.'), 404);
         }
     }
 
index 7ef3da79f0de65c11471623fd693d392c5dcfd31..1eb7341ef0fb9d2a47a251598af0e8743e7c7443 100644 (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))
             )
index 6a3f6bfcc8346c1cc5d5acda52da8908cac19d9a..fc61e7ce2dab6cb12a228934626043f3f42ad02d 100644 (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;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $this->clientError(_('API method not found.'), 404);
         }
     }
 
index aff4f318e945cf0ae940cc63e399d422b3696e7d..f0113bb5ff836bc210c83e78b80f14742f0d61be 100644 (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))
             )
index 10771fad73972f0d93f153a57690bdf70ab0c0bf..005769306812a91914de2833051c52b29540abcf 100644 (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);
index 61d743e27c1356919183f960fe730fb55b57ebb0..ebad0e5e813c059ac5496dbea801ef1ea63bfc3d 100644 (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,10 +71,8 @@ class ApiUserFollowersAction extends ApiSubscriptionsAction
 
         $profiles = array();
 
-        if (!empty($subs)) {
-            while ($subs->fetch()) {
-                $profiles[] = clone($subs);
-            }
+        while ($subs->fetch()) {
+            $profiles[] = clone($subs);
         }
 
         return $profiles;
index 2508f49c98abac0091abe84727038e79120b69fa..89a90239a1bbc267a6ac65b9f65f20c1fb4d123e 100644 (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,10 +71,8 @@ class ApiUserFriendsAction extends ApiSubscriptionsAction
 
         $profiles = array();
 
-        if (!empty($subs)) {
-            while ($subs->fetch()) {
-                $profiles[] = clone($subs);
-            }
+        while ($subs->fetch()) {
+            $profiles[] = clone($subs);
         }
 
         return $profiles;
index a996fe171806c1f618d5131c7e4aafb9d5ff20ce..cb5c959d085adf71025ff4a0a9d3f1e87f32d325 100644 (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);
index e68047eb2946fcdd66bdb8f90d648afb593d1018..4785c83f0eb9db6637cc302a5d455af89e613517 100644 (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;
-        }
-
-        $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;
+            $this->clientError(_('API method not found.'), 404);
         }
 
-        $twitter_user = $this->twitterUserArray($this->user->getProfile(), true);
+        $twitter_user = $this->twitterUserArray($this->target, true);
 
         if ($this->format == 'xml') {
             $this->initDocument('xml');
index 26afd7bfbe0667c085aad99144084f9957a27cf3..d89a8b07ac9fda44bdf413ff4e79a79b2a68b553 100644 (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);
         }
 
index 538b172203c6cb92811e9eb137323e73b54323d3..354e1887bb8d06c0532cd2e2e04ecbe7adb41c90 100644 (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);
index 56100cd49453babbf18226832f93d6c40d568c96..ce02f55702e2937f823594b99aa4322563d77983 100644 (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) {
index 0838228ba0248c345a18fb1c5a33ea98af97240c..0312510ef6fd89f6b8ca595bc32d9475b498d647 100644 (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();