From 418b3c3c53194040022c4b56bd0c0b04fd6fd4d7 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Tue, 15 Apr 2014 10:49:20 +0200 Subject: [PATCH] Some files got updated coding style Actions have $this->scoped as the current profile which we can gladly replace all the $cur=common_current_user() with. And we want the prepare/handle functions to be protected. Plus only the prepare function uses $args (which _must_ be an array). --- actions/attachment.php | 8 +++----- actions/attachment_ajax.php | 6 ++---- actions/attachment_thumbnail.php | 8 ++------ actions/joingroup.php | 28 ++++++++++------------------ actions/leavegroup.php | 26 +++++++++----------------- 5 files changed, 26 insertions(+), 50 deletions(-) diff --git a/actions/attachment.php b/actions/attachment.php index 56ecceb860..b532b81d88 100644 --- a/actions/attachment.php +++ b/actions/attachment.php @@ -60,7 +60,7 @@ class AttachmentAction extends Action * @return success flag */ - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); @@ -123,13 +123,11 @@ class AttachmentAction extends Action * * Only handles get, so just show the page. * - * @param array $args $_REQUEST data (unused) - * * @return void */ - function handle($args) + protected function handle() { - parent::handle($args); + parent::handle(); if (empty($this->attachment->filename)) { diff --git a/actions/attachment_ajax.php b/actions/attachment_ajax.php index fb7d15f8a2..24ecabacf2 100644 --- a/actions/attachment_ajax.php +++ b/actions/attachment_ajax.php @@ -27,9 +27,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); } require_once INSTALLDIR.'/actions/attachment.php'; @@ -57,7 +55,7 @@ class Attachment_ajaxAction extends AttachmentAction } } - function handle($args) + protected function handle() { $this->showPage(); } diff --git a/actions/attachment_thumbnail.php b/actions/attachment_thumbnail.php index a90f8fd5f8..93df840d56 100644 --- a/actions/attachment_thumbnail.php +++ b/actions/attachment_thumbnail.php @@ -27,11 +27,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} - -require_once INSTALLDIR.'/actions/attachment.php'; +if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); } /** * Show notice attachments @@ -44,7 +40,7 @@ require_once INSTALLDIR.'/actions/attachment.php'; */ class Attachment_thumbnailAction extends AttachmentAction { - function handle($args) + protected function handle() { $this->showPage(); } diff --git a/actions/joingroup.php b/actions/joingroup.php index c533ebdedb..065a0ac9a4 100644 --- a/actions/joingroup.php +++ b/actions/joingroup.php @@ -27,9 +27,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Join a group @@ -50,7 +48,7 @@ class JoingroupAction extends Action /** * Prepare to run */ - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); @@ -91,14 +89,12 @@ class JoingroupAction extends Action $this->clientError(_('No such group.'), 404); } - $cur = common_current_user(); - - if ($cur->isMember($this->group)) { + if ($this->scoped->isMember($this->group)) { // TRANS: Client error displayed when trying to join a group while already a member. $this->clientError(_('You are already a member of that group.'), 403); } - if (Group_block::isBlocked($this->group, $cur->getProfile())) { + if (Group_block::isBlocked($this->group, $this->scoped)) { // TRANS: Client error displayed when trying to join a group while being blocked form joining it. $this->clientError(_('You have been blocked from that group by the admin.'), 403); } @@ -111,27 +107,23 @@ class JoingroupAction extends Action * * On POST, add the current user to the group * - * @param array $args unused - * * @return void */ - function handle($args) + protected function handle() { - parent::handle($args); - - $cur = common_current_user(); + parent::handle(); try { - $result = $cur->joinGroup($this->group); + $result = $this->scoped->joinGroup($this->group); } catch (Exception $e) { common_log(LOG_ERR, sprintf("Couldn't join user %s to group %s: '%s'", - $cur->nickname, + $this->scoped->nickname, $this->group->nickname, $e->getMessage())); // TRANS: Server error displayed when joining a group failed in the database. // 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)); + $this->scoped->nickname, $this->group->nickname)); return; } @@ -140,7 +132,7 @@ class JoingroupAction extends Action $this->elementStart('head'); // TRANS: Title for join group page after joining. $this->element('title', null, sprintf(_m('TITLE','%1$s joined group %2$s'), - $cur->nickname, + $this->scoped->nickname, $this->group->nickname)); $this->elementEnd('head'); $this->elementStart('body'); diff --git a/actions/leavegroup.php b/actions/leavegroup.php index e0e2c27890..f2182c58d2 100644 --- a/actions/leavegroup.php +++ b/actions/leavegroup.php @@ -27,9 +27,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Leave a group @@ -50,7 +48,7 @@ class LeavegroupAction extends Action /** * Prepare to run */ - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); @@ -91,9 +89,7 @@ class LeavegroupAction extends Action $this->clientError(_('No such group.'), 404); } - $cur = common_current_user(); - - if (!$cur->isMember($this->group)) { + if (!$this->scoped->isMember($this->group)) { // TRANS: Client error displayed when trying to join a group while already a member. $this->clientError(_('You are not a member of that group.'), 403); } @@ -106,24 +102,20 @@ class LeavegroupAction extends Action * * On POST, add the current user to the group * - * @param array $args unused - * * @return void */ - function handle($args) + protected function handle() { - parent::handle($args); - - $cur = common_current_user(); + parent::handle(); try { - $cur->leaveGroup($this->group); + $this->scoped->leaveGroup($this->group); } catch (Exception $e) { - common_log(LOG_ERR, "Error when {$cur->nickname} tried to leave {$this->group->nickname}: " . $e->getMessage()); + common_log(LOG_ERR, "Error when {$this->scoped->nickname} tried to leave {$this->group->nickname}: " . $e->getMessage()); // TRANS: Server error displayed when leaving a group failed in the database. // 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)); + $this->scoped->nickname, $this->group->nickname)); return; } @@ -132,7 +124,7 @@ class LeavegroupAction extends Action $this->elementStart('head'); // TRANS: Title for leave group page after leaving. $this->element('title', null, sprintf(_m('TITLE','%1$s left group %2$s'), - $cur->nickname, + $this->scoped->nickname, $this->group->nickname)); $this->elementEnd('head'); $this->elementStart('body');