From b0cc9292b1c771a9ef9796f45676c01fe57d3935 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sun, 18 May 2014 21:03:10 +0200 Subject: [PATCH] Notice->repeat() function takes Profile as argument now --- actions/apistatusesretweet.php | 29 ++++++++----------------- actions/repeat.php | 2 +- classes/Notice.php | 8 +++---- lib/command.php | 4 +++- plugins/SubMirror/classes/SubMirror.php | 2 +- tests/ActivityGenerationTests.php | 6 ++--- 6 files changed, 21 insertions(+), 30 deletions(-) diff --git a/actions/apistatusesretweet.php b/actions/apistatusesretweet.php index ee391fdb4a..922d395154 100644 --- a/actions/apistatusesretweet.php +++ b/actions/apistatusesretweet.php @@ -27,9 +27,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Repeat a notice through the API @@ -42,6 +40,8 @@ if (!defined('STATUSNET')) { */ class ApiStatusesRetweetAction extends ApiAuthAction { + protected $needPost = true; + var $original = null; /** @@ -51,30 +51,19 @@ class ApiStatusesRetweetAction extends ApiAuthAction * * @return boolean success flag */ - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); - if ($_SERVER['REQUEST_METHOD'] != 'POST') { - // TRANS: Client error. POST is a HTTP command. It should not be translated. - $this->clientError(_('This method requires a POST.'), - 400, $this->format); - return false; - } - $id = $this->trimmed('id'); $this->original = Notice::getKV('id', $id); - if (empty($this->original)) { + if (!$this->original instanceof Notice) { // TRANS: Client error displayed trying to repeat a non-existing notice through the API. - $this->clientError(_('No such notice.'), - 400, $this->format); - return false; + $this->clientError(_('No such notice.'), 400, $this->format); } - $this->user = $this->auth_user; - return true; } @@ -87,11 +76,11 @@ class ApiStatusesRetweetAction extends ApiAuthAction * * @return void */ - function handle($args) + protected function handle() { - parent::handle($args); + parent::handle(); - $repeat = $this->original->repeat($this->user->id, $this->source); + $repeat = $this->original->repeat($this->scoped, $this->source); $this->showNotice($repeat); } diff --git a/actions/repeat.php b/actions/repeat.php index 76104e2bbf..501570ebf0 100644 --- a/actions/repeat.php +++ b/actions/repeat.php @@ -63,7 +63,7 @@ class RepeatAction extends FormAction $this->clientError(_('Notice not found.')); } - $this->repeat = $this->notice->repeat($this->scoped->id, 'web'); + $this->repeat = $this->notice->repeat($this->scoped, 'web'); if (!$this->repeat instanceof Notice) { // TRANS: Error when unable to repeat a notice for unknown reason. $this->clientError(_('Could not repeat notice for unknown reason. Please contact the webmaster!')); diff --git a/classes/Notice.php b/classes/Notice.php index d331b111c3..54b698d62b 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1837,24 +1837,24 @@ class Notice extends Managed_DataObject /** * Convenience function for posting a repeat of an existing message. * - * @param int $repeater_id: profile ID of user doing the repeat + * @param Profile $repeater Profile which is doing the repeat * @param string $source: posting source key, eg 'web', 'api', etc * @return Notice * * @throws Exception on failure or permission problems */ - function repeat($repeater_id, $source) + function repeat(Profile $repeater, $source) { $author = $this->getProfile(); // TRANS: Message used to repeat a notice. RT is the abbreviation of 'retweet'. // TRANS: %1$s is the repeated user's name, %2$s is the repeated notice. $content = sprintf(_('RT @%1$s %2$s'), - $author->nickname, + $author->getNickname(), $this->content); // Scope is same as this one's - return self::saveNew($repeater_id, + return self::saveNew($repeater->id, $content, $source, array('repeat_of' => $this->id, diff --git a/lib/command.php b/lib/command.php index bc0dd894de..abc22ed6a8 100644 --- a/lib/command.php +++ b/lib/command.php @@ -23,10 +23,12 @@ require_once(INSTALLDIR.'/lib/channel.php'); class Command { + protected $scoped = null; // The Profile of the user performing the command var $user = null; function __construct($user=null) { + $this->scoped = $user->getProfile(); $this->user = $user; } @@ -659,7 +661,7 @@ class RepeatCommand extends Command $notice = $this->getNotice($this->other); try { - $repeat = $notice->repeat($this->user->id, $channel->source()); + $repeat = $notice->repeat($this->scoped->id, $channel->source()); $recipient = $notice->getProfile(); // TRANS: Message given having repeated a notice from another user. diff --git a/plugins/SubMirror/classes/SubMirror.php b/plugins/SubMirror/classes/SubMirror.php index 7c3e6af3ec..de63841e72 100644 --- a/plugins/SubMirror/classes/SubMirror.php +++ b/plugins/SubMirror/classes/SubMirror.php @@ -179,7 +179,7 @@ class SubMirror extends Managed_DataObject return true; } else { common_log(LOG_INFO, "SubMirror plugin auto-repeating notice $notice->id for $profile->id"); - return $notice->repeat($profile->id, 'mirror'); + return $notice->repeat($profile, 'mirror'); } } diff --git a/tests/ActivityGenerationTests.php b/tests/ActivityGenerationTests.php index bf0dcb2377..f02f1be2fc 100644 --- a/tests/ActivityGenerationTests.php +++ b/tests/ActivityGenerationTests.php @@ -362,7 +362,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase public function testRepeatLink() { $notice = $this->_fakeNotice($this->author1); - $repeat = $notice->repeat($this->author2->id, 'test'); + $repeat = $notice->repeat($this->author2->getProfile(), 'test'); $entry = $repeat->asAtomEntry(); @@ -451,7 +451,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase { $notice = $this->_fakeNotice(); - $repeat = $notice->repeat($this->author2->id, 'test'); + $repeat = $notice->repeat($this->author2->getProfile(), 'test'); $entry = $repeat->asAtomEntry(); @@ -466,7 +466,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase { $notice = $this->_fakeNotice(); - $repeat = $notice->repeat($this->author2->id, 'test'); + $repeat = $notice->repeat($this->author2->getProfile(), 'test'); $entry = $notice->asAtomEntry(false, false, false, $this->author2);