GitHost.io will be shut down on June 1, 2019. At that point this instance will be unreachable and all data will be irrevocably deleted. More details at https://about.gitlab.com/gitlab-hosted/#githost-is-shutting-down-on-june-1st-2019

Commit 4b0cf99e authored by Evan Prodromou's avatar Evan Prodromou

Convert use of common_server_error and common_user_error to methods on Action

parent eaa81d25
......@@ -38,7 +38,7 @@ class AccesstokenAction extends Action
common_debug('printing the access token', __FILE__);
print $token;
} catch (OAuthException $e) {
common_server_error($e->getMessage());
$this->serverError($e->getMessage());
}
}
}
......@@ -33,14 +33,14 @@ class AllAction extends StreamAction
$user = User::staticGet('nickname', $nickname);
if (!$user) {
$this->client_error(_('No such user.'));
$this->clientError(_('No such user.'));
return;
}
$profile = $user->getProfile();
if (!$profile) {
common_server_error(_('User has no profile.'));
$this->serverError(_('User has no profile.'));
return;
}
......
......@@ -34,7 +34,7 @@ class AllrssAction extends Rss10Action
$this->user = User::staticGet('nickname', $nickname);
if (!$this->user) {
common_user_error(_('No such user.'));
$this->clientError(_('No such user.'));
return false;
} else {
return true;
......
......@@ -103,10 +103,10 @@ class ApiAction extends Action
call_user_func(array($action_obj, $this->api_method), $_REQUEST, $apidata);
} else {
common_user_error("API method not found!", $code=404);
$this->clientError("API method not found!", $code=404);
}
} else {
common_user_error("API method not found!", $code=404);
$this->clientError("API method not found!", $code=404);
}
}
......
......@@ -26,28 +26,28 @@ class AvatarbynicknameAction extends Action
parent::handle($args);
$nickname = $this->trimmed('nickname');
if (!$nickname) {
$this->client_error(_('No nickname.'));
$this->clientError(_('No nickname.'));
return;
}
$size = $this->trimmed('size');
if (!$size) {
$this->client_error(_('No size.'));
$this->clientError(_('No size.'));
return;
}
$size = strtolower($size);
if (!in_array($size, array('original', '96', '48', '24'))) {
$this->client_error(_('Invalid size.'));
$this->clientError(_('Invalid size.'));
return;
}
$user = User::staticGet('nickname', $nickname);
if (!$user) {
$this->client_error(_('No such user.'));
$this->clientError(_('No such user.'));
return;
}
$profile = $user->getProfile();
if (!$profile) {
$this->client_error(_('User has no profile.'));
$this->clientError(_('User has no profile.'));
return;
}
if ($size == 'original') {
......
......@@ -30,28 +30,28 @@ class BlockAction extends Action
parent::prepare($args);
if (!common_logged_in()) {
$this->client_error(_('Not logged in.'));
$this->clientError(_('Not logged in.'));
return false;
}
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
$this->client_error(_('There was a problem with your session token. Try again, please.'));
$this->clientError(_('There was a problem with your session token. Try again, please.'));
return;
}
$id = $this->trimmed('blockto');
if (!$id) {
$this->client_error(_('No profile specified.'));
$this->clientError(_('No profile specified.'));
return false;
}
$this->profile = Profile::staticGet('id', $id);
if (!$this->profile) {
$this->client_error(_('No profile with that ID.'));
$this->clientError(_('No profile with that ID.'));
return false;
}
......@@ -119,14 +119,14 @@ class BlockAction extends Action
$cur = common_current_user();
if ($cur->hasBlocked($this->profile)) {
$this->client_error(_('You have already blocked this user.'));
$this->clientError(_('You have already blocked this user.'));
return;
}
$result = $cur->block($this->profile);
if (!$result) {
$this->server_error(_('Failed to save block information.'));
$this->serverError(_('Failed to save block information.'));
return;
}
......
......@@ -32,26 +32,26 @@ class ConfirmaddressAction extends Action
}
$code = $this->trimmed('code');
if (!$code) {
$this->client_error(_('No confirmation code.'));
$this->clientError(_('No confirmation code.'));
return;
}
$confirm = Confirm_address::staticGet('code', $code);
if (!$confirm) {
$this->client_error(_('Confirmation code not found.'));
$this->clientError(_('Confirmation code not found.'));
return;
}
$cur = common_current_user();
if ($cur->id != $confirm->user_id) {
$this->client_error(_('That confirmation code is not for you!'));
$this->clientError(_('That confirmation code is not for you!'));
return;
}
$type = $confirm->address_type;
if (!in_array($type, array('email', 'jabber', 'sms'))) {
$this->server_error(sprintf(_('Unrecognized address type %s'), $type));
$this->serverError(sprintf(_('Unrecognized address type %s'), $type));
return;
}
if ($cur->$type == $confirm->address) {
$this->client_error(_('That address has already been confirmed.'));
$this->clientError(_('That address has already been confirmed.'));
return;
}
......@@ -71,7 +71,7 @@ class ConfirmaddressAction extends Action
if (!$result) {
common_log_db_error($cur, 'UPDATE', __FILE__);
$this->server_error(_('Couldn\'t update user.'));
$this->serverError(_('Couldn\'t update user.'));
return;
}
......@@ -83,7 +83,7 @@ class ConfirmaddressAction extends Action
if (!$result) {
common_log_db_error($confirm, 'DELETE', __FILE__);
$this->server_error(_('Couldn\'t delete email confirmation.'));
$this->serverError(_('Couldn\'t delete email confirmation.'));
return;
}
......
......@@ -24,7 +24,7 @@ class DeleteprofileAction extends Action
function handle($args)
{
parent::handle($args);
$this->server_error(_('Code not yet ready.'));
$this->serverError(_('Code not yet ready.'));
return;
if ('POST' === $_SERVER['REQUEST_METHOD']) {
$this->handle_post();
......
......@@ -28,7 +28,7 @@ class DisfavorAction extends Action
parent::handle($args);
if (!common_logged_in()) {
common_user_error(_('Not logged in.'));
$this->clientError(_('Not logged in.'));
return;
}
......@@ -46,7 +46,7 @@ class DisfavorAction extends Action
$token = $this->trimmed('token-'.$notice->id);
if (!$token || $token != common_session_token()) {
$this->client_error(_("There was a problem with your session token. Try again, please."));
$this->clientError(_("There was a problem with your session token. Try again, please."));
return;
}
......@@ -54,7 +54,7 @@ class DisfavorAction extends Action
$fave->user_id = $this->id;
$fave->notice_id = $notice->id;
if (!$fave->find(true)) {
$this->client_error(_('This notice is not a favorite!'));
$this->clientError(_('This notice is not a favorite!'));
return;
}
......@@ -62,7 +62,7 @@ class DisfavorAction extends Action
if (!$result) {
common_log_db_error($fave, 'DELETE', __FILE__);
$this->server_error(_('Could not delete favorite.'));
$this->serverError(_('Could not delete favorite.'));
return;
}
......
......@@ -28,7 +28,7 @@ class DocAction extends Action
$title = $this->trimmed('title');
$filename = INSTALLDIR.'/doc/'.$title;
if (!file_exists($filename)) {
common_user_error(_('No such document.'));
$this->clientError(_('No such document.'));
return;
}
$c = file_get_contents($filename);
......
......@@ -182,7 +182,7 @@ class EmailsettingsAction extends SettingsAction
if ($result === false) {
common_log_db_error($user, 'UPDATE', __FILE__);
common_server_error(_('Couldn\'t update user.'));
$this->serverError(_('Couldn\'t update user.'));
return;
}
......@@ -232,7 +232,7 @@ class EmailsettingsAction extends SettingsAction
if ($result === false) {
common_log_db_error($confirm, 'INSERT', __FILE__);
common_server_error(_('Couldn\'t insert confirmation code.'));
$this->serverError(_('Couldn\'t insert confirmation code.'));
return;
}
......@@ -260,7 +260,7 @@ class EmailsettingsAction extends SettingsAction
if (!$result) {
common_log_db_error($confirm, 'DELETE', __FILE__);
$this->server_error(_('Couldn\'t delete email confirmation.'));
$this->serverError(_('Couldn\'t delete email confirmation.'));
return;
}
......@@ -286,7 +286,7 @@ class EmailsettingsAction extends SettingsAction
$result = $user->updateKeys($original);
if (!$result) {
common_log_db_error($user, 'UPDATE', __FILE__);
common_server_error(_('Couldn\'t update user.'));
$this->serverError(_('Couldn\'t update user.'));
return;
}
$user->query('COMMIT');
......@@ -308,7 +308,7 @@ class EmailsettingsAction extends SettingsAction
if (!$user->updateKeys($orig)) {
common_log_db_error($user, 'UPDATE', __FILE__);
$this->server_error(_("Couldn't update user record."));
$this->serverError(_("Couldn't update user record."));
}
$this->show_form(_('Incoming email address removed.'), true);
......@@ -323,7 +323,7 @@ class EmailsettingsAction extends SettingsAction
if (!$user->updateKeys($orig)) {
common_log_db_error($user, 'UPDATE', __FILE__);
$this->server_error(_("Couldn't update user record."));
$this->serverError(_("Couldn't update user record."));
}
$this->show_form(_('New incoming email address added.'), true);
......
......@@ -53,7 +53,7 @@ class FacebookremoveAction extends FacebookAction
if (!$result) {
common_log_db_error($flink, 'DELETE', __FILE__);
common_server_error(_('Couldn\'t remove Facebook user.'));
$this->serverError(_('Couldn\'t remove Facebook user.'));
return;
}
......
......@@ -29,7 +29,7 @@ class FavorAction extends Action
parent::handle($args);
if (!common_logged_in()) {
common_user_error(_('Not logged in.'));
$this->clientError(_('Not logged in.'));
return;
}
......@@ -48,19 +48,19 @@ class FavorAction extends Action
$token = $this->trimmed('token-'.$notice->id);
if (!$token || $token != common_session_token()) {
$this->client_error(_("There was a problem with your session token. Try again, please."));
$this->clientError(_("There was a problem with your session token. Try again, please."));
return;
}
if ($user->hasFave($notice)) {
$this->client_error(_('This notice is already a favorite!'));
$this->clientError(_('This notice is already a favorite!'));
return;
}
$fave = Fave::addNew($user, $notice);
if (!$fave) {
$this->server_error(_('Could not create favorite.'));
$this->serverError(_('Could not create favorite.'));
return;
}
......
......@@ -34,7 +34,7 @@ class FavoritesrssAction extends Rss10Action
$this->user = User::staticGet('nickname', $nickname);
if (!$this->user) {
common_user_error(_('No such user.'));
$this->clientError(_('No such user.'));
return false;
} else {
return true;
......
......@@ -28,7 +28,7 @@ class FinishaddopenidAction extends Action
{
parent::handle($args);
if (!common_logged_in()) {
common_user_error(_('Not logged in.'));
$this->clientError(_('Not logged in.'));
} else {
$this->try_login();
}
......
......@@ -28,7 +28,7 @@ class FinishopenidloginAction extends Action
{
parent::handle($args);
if (common_logged_in()) {
common_user_error(_('Already logged in.'));
$this->clientError(_('Already logged in.'));
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
......@@ -179,7 +179,7 @@ class FinishopenidloginAction extends Action
# FIXME: save invite code before redirect, and check here
if (common_config('site', 'closed') || common_config('site', 'inviteonly')) {
common_user_error(_('Registration not allowed.'));
$this->clientError(_('Registration not allowed.'));
return;
}
......@@ -205,7 +205,7 @@ class FinishopenidloginAction extends Action
list($display, $canonical, $sreg) = $this->get_saved_values();
if (!$display || !$canonical) {
common_server_error(_('Stored OpenID not found.'));
$this->serverError(_('Stored OpenID not found.'));
return;
}
......@@ -214,7 +214,7 @@ class FinishopenidloginAction extends Action
$other = oid_get_user($canonical);
if ($other) {
common_server_error(_('Creating new account for OpenID that already has a user.'));
$this->serverError(_('Creating new account for OpenID that already has a user.'));
return;
}
......@@ -274,14 +274,14 @@ class FinishopenidloginAction extends Action
list($display, $canonical, $sreg) = $this->get_saved_values();
if (!$display || !$canonical) {
common_server_error(_('Stored OpenID not found.'));
$this->serverError(_('Stored OpenID not found.'));
return;
}
$result = oid_link_user($user->id, $canonical, $display);
if (!$result) {
common_server_error(_('Error connecting user to OpenID.'));
$this->serverError(_('Error connecting user to OpenID.'));
return;
}
......
......@@ -30,14 +30,14 @@ class FinishremotesubscribeAction extends Action
parent::handle($args);
if (common_logged_in()) {
common_user_error(_('You can use the local subscription!'));
$this->clientError(_('You can use the local subscription!'));
return;
}
$omb = $_SESSION['oauth_authorization_request'];
if (!$omb) {
common_user_error(_('Not expecting this response!'));
$this->clientError(_('Not expecting this response!'));
return;
}
......@@ -51,38 +51,38 @@ class FinishremotesubscribeAction extends Action
# I think this is the success metric
if ($token != $omb['token']) {
common_user_error(_('Not authorized.'));
$this->clientError(_('Not authorized.'));
return;
}
$version = $req->get_parameter('omb_version');
if ($version != OMB_VERSION_01) {
common_user_error(_('Unknown version of OMB protocol.'));
$this->clientError(_('Unknown version of OMB protocol.'));
return;
}
$nickname = $req->get_parameter('omb_listener_nickname');
if (!$nickname) {
common_user_error(_('No nickname provided by remote server.'));
$this->clientError(_('No nickname provided by remote server.'));
return;
}
$profile_url = $req->get_parameter('omb_listener_profile');
if (!$profile_url) {
common_user_error(_('No profile URL returned by server.'));
$this->clientError(_('No profile URL returned by server.'));
return;
}
if (!Validate::uri($profile_url, array('allowed_schemes' => array('http', 'https')))) {
common_user_error(_('Invalid profile URL returned by server.'));
$this->clientError(_('Invalid profile URL returned by server.'));
return;
}
if ($profile_url == common_local_url('showstream', array('nickname' => $nickname))) {
common_user_error(_('You can use the local subscription!'));
$this->clientError(_('You can use the local subscription!'));
return;
}
......@@ -91,14 +91,14 @@ class FinishremotesubscribeAction extends Action
$user = User::staticGet('nickname', $omb['listenee']);
if (!$user) {
common_user_error(_('User being listened to doesn\'t exist.'));
$this->clientError(_('User being listened to doesn\'t exist.'));
return;
}
$other = User::staticGet('uri', $omb['listener']);
if ($other) {
common_user_error(_('You can use the local subscription!'));
$this->clientError(_('You can use the local subscription!'));
return;
}
......@@ -111,7 +111,7 @@ class FinishremotesubscribeAction extends Action
list($newtok, $newsecret) = $this->access_token($omb);
if (!$newtok || !$newsecret) {
common_user_error(_('Couldn\'t convert request tokens to access tokens.'));
$this->clientError(_('Couldn\'t convert request tokens to access tokens.'));
return;
}
......@@ -155,7 +155,7 @@ class FinishremotesubscribeAction extends Action
$profile->created = DB_DataObject_Cast::dateTime(); # current time
$id = $profile->insert();
if (!$id) {
common_server_error(_('Error inserting new profile'));
$this->serverError(_('Error inserting new profile'));
return;
}
$remote->id = $id;
......@@ -163,7 +163,7 @@ class FinishremotesubscribeAction extends Action
if ($avatar_url) {
if (!$this->add_avatar($profile, $avatar_url)) {
common_server_error(_('Error inserting avatar'));
$this->serverError(_('Error inserting avatar'));
return;
}
}
......@@ -173,19 +173,19 @@ class FinishremotesubscribeAction extends Action
if ($exists) {
if (!$remote->update($orig_remote)) {
common_server_error(_('Error updating remote profile'));
$this->serverError(_('Error updating remote profile'));
return;
}
} else {
$remote->created = DB_DataObject_Cast::dateTime(); # current time
if (!$remote->insert()) {
common_server_error(_('Error inserting remote profile'));
$this->serverError(_('Error inserting remote profile'));
return;
}
}
if ($user->hasBlocked($profile)) {
$this->client_error(_('That user has blocked you from subscribing.'));
$this->clientError(_('That user has blocked you from subscribing.'));
return;
}
......@@ -215,7 +215,7 @@ class FinishremotesubscribeAction extends Action
if (!$result) {
common_log_db_error($sub, ($sub_exists) ? 'UPDATE' : 'INSERT', __FILE__);
common_user_error(_('Couldn\'t insert new subscription.'));
$this->clientError(_('Couldn\'t insert new subscription.'));
return;
}
......
......@@ -40,14 +40,14 @@ class FoafAction extends Action
$user = User::staticGet('nickname', $nickname);
if (!$user) {
common_user_error(_('No such user.'), 404);
$this->clientError(_('No such user.'), 404);
return;
}
$profile = $user->getProfile();
if (!$profile) {
common_server_error(_('User has no profile.'), 500);
$this->serverError(_('User has no profile.'), 500);
return;
}
......
......@@ -149,7 +149,7 @@ class ImsettingsAction extends SettingsAction
if ($result === false) {
common_log_db_error($user, 'UPDATE', __FILE__);
common_server_error(_('Couldn\'t update user.'));
$this->serverError(_('Couldn\'t update user.'));
return;
}
......@@ -199,7 +199,7 @@ class ImsettingsAction extends SettingsAction
if ($result === false) {
common_log_db_error($confirm, 'INSERT', __FILE__);
common_server_error(_('Couldn\'t insert confirmation code.'));
$this->serverError(_('Couldn\'t insert confirmation code.'));
return;
}
......@@ -231,7 +231,7 @@ class ImsettingsAction extends SettingsAction
if (!$result) {
common_log_db_error($confirm, 'DELETE', __FILE__);
$this->server_error(_('Couldn\'t delete email confirmation.'));
$this->serverError(_('Couldn\'t delete email confirmation.'));
return;
}
......@@ -257,7 +257,7 @@ class ImsettingsAction extends SettingsAction
$result = $user->updateKeys($original);
if (!$result) {
common_log_db_error($user, 'UPDATE', __FILE__);
common_server_error(_('Couldn\'t update user.'));
$this->serverError(_('Couldn\'t update user.'));
return;
}
$user->query('COMMIT');
......
......@@ -31,7 +31,7 @@ class InviteAction extends Action
{
parent::handle($args);
if (!common_logged_in()) {
$this->client_error(sprintf(_('You must be logged in to invite other users to use %s'),
$this->clientError(sprintf(_('You must be logged in to invite other users to use %s'),
common_config('site', 'name')));
return;
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
......
......@@ -31,7 +31,7 @@ class LoginAction extends Action
{
parent::handle($args);
if (common_is_real_login()) {
common_user_error(_('Already logged in.'));
$this->clientError(_('Already logged in.'));
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->check_login();
} else {
......@@ -46,7 +46,7 @@ class LoginAction extends Action
# CSRF protection - token set in common_notice_form()
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
$this->client_error(_('There was a problem with your session token. Try again, please.'));
$this->clientError(_('There was a problem with your session token. Try again, please.'));
return;
}
......@@ -55,7 +55,7 @@ class LoginAction extends Action
if (common_check_user($nickname, $password)) {
# success!
if (!common_set_user($nickname)) {
common_server_error(_('Error setting user.'));
$this->serverError(_('Error setting user.'));
return;
}
common_real_login(true);
......@@ -81,7 +81,7 @@ class LoginAction extends Action
# success!
if (!common_set_user($user)) {
common_server_error(_('Error setting user.'));
$this->serverError(_('Error setting user.'));
return;
}
......
......@@ -33,7 +33,7 @@ class LogoutAction extends Action
{
parent::handle($args);
if (!common_logged_in()) {
common_user_error(_('Not logged in.'));
$this->clientError(_('Not logged in.'));
} else {
common_set_user(null);
common_real_login(false); # not logged in
......
......@@ -31,14 +31,14 @@ class MicrosummaryAction extends Action
$user = User::staticGet('nickname', $nickname);
if (!$user) {
$this->client_error(_('No such user'), 404);
$this->clientError(_('No such user'), 404);
return;
}
$notice = $user->getCurrentNotice();
if (!$notice) {
$this->client_error(_('No current status'), 404);
$this->clientError(_('No current status'), 404);
}
header('Content-Type: text/plain');
......
......@@ -27,7 +27,7 @@ class NewmessageAction extends Action
parent::handle($args);
if (!common_logged_in()) {
$this->client_error(_('Not logged in.'), 403);
$this->clientError(_('Not logged in.'), 403);
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->save_new_message();
} else {
......@@ -71,10 +71,10 @@ class NewmessageAction extends Action
$this->show_form(_('No recipient specified.'));
return;
} else if (!$user->mutuallySubscribed($other)) {
$this->client_error(_('You can\'t send a message to this user.'), 404);
$this->clientError(_('You can\'t send a message to this user.'), 404);
return;
} else if ($user->id == $other->id) {
$this->client_error(_('Don\'t send a message to yourself; just say it to yourself quietly instead.'), 403);
$this->clientError(_('Don\'t send a message to yourself; just say it to yourself quietly instead.'), 403);
return;
}
......@@ -113,12 +113,12 @@ class NewmessageAction extends Action
$other = User::staticGet('id', $to);
if (!$other) {
$this->client_error(_('No such user'), 404);
$this->clientError(_('No such user'), 404);
return;
}
if (!$user->mutuallySubscribed($other)) {
$this->client_error(_('You can\'t send a message to this user.'), 404);
$this->clientError(_('You can\'t send a message to this user.'), 404);
return;
}
......
......@@ -29,13 +29,13 @@ class NewnoticeAction extends Action
parent::handle($args);
if (!common_logged_in()) {
common_user_error(_('Not logged in.'));
$this->clientError(_('Not logged in.'));
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {