ShowprofiletagAction now extends ShowstreamAction

This commit is contained in:
Mikael Nordfeldth 2015-09-27 23:46:30 +02:00
parent 0e24709989
commit ad3b62cf2f
10 changed files with 63 additions and 121 deletions

View File

@ -24,88 +24,29 @@
if (!defined('GNUSOCIAL')) { exit(1); } if (!defined('GNUSOCIAL')) { exit(1); }
class ShowprofiletagAction extends Action class ShowprofiletagAction extends ShowstreamAction
{ {
var $notice, $tagger, $peopletag, $userProfile; var $notice, $peopletag;
function isReadOnly($args) protected function doStreamPreparation()
{ {
return true; $tag = common_canonical_tag($this->arg('tag'));
} try {
$this->peopletag = Profile_list::getByPK(array('tagger' => $this->target->getID(), 'tag' => $tag));
function prepare($args) } catch (NoResultException $e) {
{
parent::prepare($args);
if (common_config('singleuser', 'enabled')) {
$tagger_arg = User::singleUserNickname();
} else {
$tagger_arg = $this->arg('tagger');
}
$tag_arg = $this->arg('tag');
$tagger = common_canonical_nickname($tagger_arg);
$tag = common_canonical_tag($tag_arg);
// Permanent redirect on non-canonical nickname
if ($tagger_arg != $tagger || $tag_arg != $tag) {
$args = array('tagger' => $nickname, 'tag' => $tag);
if ($this->page != 1) {
$args['page'] = $this->page;
}
common_redirect(common_local_url('showprofiletag', $args), 301);
}
if (!$tagger) {
// TRANS: Client error displayed when a tagger is expected but not provided.
$this->clientError(_('No tagger.'), 404);
}
$user = User::getKV('nickname', $tagger);
if (!$user) {
// TRANS: Client error displayed trying to perform an action related to a non-existing user.
$this->clientError(_('No such user.'), 404);
}
$this->tagger = $user->getProfile();
$this->peopletag = Profile_list::pkeyGet(array('tagger' => $user->id, 'tag' => $tag));
$current = common_current_user();
$can_see = !empty($this->peopletag) && (!$this->peopletag->private ||
($this->peopletag->private && $this->peopletag->tagger === $current->id));
if (!$can_see) {
// TRANS: Client error displayed trying to reference a non-existing list. // TRANS: Client error displayed trying to reference a non-existing list.
$this->clientError(_('No such list.'), 404); throw new ClientException('No such list.');
} }
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; if ($this->peopletag->private && !$this->peopletag->getTagger()->sameAs($this->scoped)) {
$this->userProfile = Profile::current(); // TRANS: Client error displayed trying to reference a non-existing list.
throw new AuthorizationException('You do not have permission to see this list.');
$stream = new PeopletagNoticeStream($this->peopletag, $this->userProfile);
$this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
NOTICES_PER_PAGE + 1);
if ($this->page > 1 && $this->notice->N == 0) {
// TRANS: Client error when page not found (404).
$this->clientError(_('No such page.'), 404);
} }
return true;
} }
function handle($args) public function getStream()
{ {
parent::handle($args); return new PeopletagNoticeStream($this->peopletag, $this->scoped);
if (!$this->peopletag) {
// TRANS: Client error displayed trying to perform an action related to a non-existing user.
$this->clientError(_('No such user.'));
}
$this->showPage();
} }
function title() function title()
@ -130,7 +71,7 @@ class ShowprofiletagAction extends Action
// TRANS: %1$s is a list, %2$s is the tagger's nickname, %3$d is a page number. // TRANS: %1$s is a list, %2$s is the tagger's nickname, %3$d is a page number.
return sprintf(_('Timeline for %1$s list by %2$s, page %3$d'), return sprintf(_('Timeline for %1$s list by %2$s, page %3$d'),
$this->peopletag->tag, $this->peopletag->tag,
$this->tagger->nickname, $this->target->getNickname(),
$this->page $this->page
); );
} else { } else {
@ -153,7 +94,7 @@ class ShowprofiletagAction extends Action
// TRANS: %1$s is a list, %2$s is the tagger's nickname. // TRANS: %1$s is a list, %2$s is the tagger's nickname.
return sprintf(_('Timeline for %1$s list by %2$s'), return sprintf(_('Timeline for %1$s list by %2$s'),
$this->peopletag->tag, $this->peopletag->tag,
$this->tagger->nickname $this->target->getNickname()
); );
} }
} }
@ -164,29 +105,29 @@ class ShowprofiletagAction extends Action
return array(new Feed(Feed::JSON, return array(new Feed(Feed::JSON,
common_local_url( common_local_url(
'ApiTimelineList', array( 'ApiTimelineList', array(
'user' => $this->tagger->id, 'user' => $this->target->id,
'id' => $this->peopletag->id, 'id' => $this->peopletag->id,
'format' => 'as' 'format' => 'as'
) )
), ),
// TRANS: Feed title. // TRANS: Feed title.
// TRANS: %s is tagger's nickname. // TRANS: %s is tagger's nickname.
sprintf(_('Feed for friends of %s (Activity Streams JSON)'), $this->tagger->nickname)), sprintf(_('Feed for friends of %s (Activity Streams JSON)'), $this->target->getNickname())),
new Feed(Feed::RSS2, new Feed(Feed::RSS2,
common_local_url( common_local_url(
'ApiTimelineList', array( 'ApiTimelineList', array(
'user' => $this->tagger->id, 'user' => $this->target->id,
'id' => $this->peopletag->id, 'id' => $this->peopletag->id,
'format' => 'rss' 'format' => 'rss'
) )
), ),
// TRANS: Feed title. // TRANS: Feed title.
// TRANS: %s is tagger's nickname. // TRANS: %s is tagger's nickname.
sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->tagger->nickname)), sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->target->getNickname())),
new Feed(Feed::ATOM, new Feed(Feed::ATOM,
common_local_url( common_local_url(
'ApiTimelineList', array( 'ApiTimelineList', array(
'user' => $this->tagger->id, 'user' => $this->target->id,
'id' => $this->peopletag->id, 'id' => $this->peopletag->id,
'format' => 'atom' 'format' => 'atom'
) )
@ -194,7 +135,7 @@ class ShowprofiletagAction extends Action
// TRANS: Feed title. // TRANS: Feed title.
// TRANS: %1$s is a list, %2$s is tagger's nickname. // TRANS: %1$s is a list, %2$s is tagger's nickname.
sprintf(_('Feed for %1$s list by %2$s (Atom)'), sprintf(_('Feed for %1$s list by %2$s (Atom)'),
$this->peopletag->tag, $this->tagger->nickname $this->peopletag->tag, $this->target->getNickname()
) )
) )
); );
@ -212,11 +153,10 @@ class ShowprofiletagAction extends Action
// TRANS: %1$s is a list, %2$s is a tagger's nickname. // TRANS: %1$s is a list, %2$s is a tagger's nickname.
$message = sprintf(_('This is the timeline for %1$s list by %2$s but no one has posted anything yet.'), $message = sprintf(_('This is the timeline for %1$s list by %2$s but no one has posted anything yet.'),
$this->peopletag->tag, $this->peopletag->tag,
$this->tagger->nickname) . ' '; $this->target->getNickname()) . ' ';
if (common_logged_in()) { if (common_logged_in()) {
$current_user = common_current_user(); if ($this->target->sameAs($this->scoped)) {
if ($this->tagger->id == $current_user->id) {
// TRANS: Additional empty list message for list timeline for currently logged in user tagged tags. // TRANS: Additional empty list message for list timeline for currently logged in user tagged tags.
$message .= _('Try tagging more people.'); $message .= _('Try tagging more people.');
} }
@ -231,16 +171,15 @@ class ShowprofiletagAction extends Action
$this->elementEnd('div'); $this->elementEnd('div');
} }
function showContent() protected function showContent()
{ {
$this->showPeopletag(); $this->showPeopletag();
$this->showNotices(); parent::showContent();
} }
function showPeopletag() function showPeopletag()
{ {
$cur = common_current_user(); $tag = new Peopletag($this->peopletag, $this->scoped, $this);
$tag = new Peopletag($this->peopletag, $cur, $this);
$tag->show(); $tag->show();
} }
@ -260,7 +199,7 @@ class ShowprofiletagAction extends Action
$this->page, $this->page,
'showprofiletag', 'showprofiletag',
array('tag' => $this->peopletag->tag, array('tag' => $this->peopletag->tag,
'tagger' => $this->tagger->nickname) 'nickname' => $this->target->getNickname())
); );
Event::handle('EndShowProfileTagContent', array($this)); Event::handle('EndShowProfileTagContent', array($this));
@ -276,11 +215,6 @@ class ShowprofiletagAction extends Action
# $this->showStatistics(); # $this->showStatistics();
} }
function showPageTitle()
{
$this->element('h1', null, $this->title());
}
function showTagged() function showTagged()
{ {
$profile = $this->peopletag->getTagged(0, PROFILES_PER_MINILIST + 1); $profile = $this->peopletag->getTagged(0, PROFILES_PER_MINILIST + 1);
@ -307,7 +241,7 @@ class ShowprofiletagAction extends Action
if ($cnt > PROFILES_PER_MINILIST) { if ($cnt > PROFILES_PER_MINILIST) {
$this->elementStart('p'); $this->elementStart('p');
$this->element('a', array('href' => common_local_url('taggedprofiles', $this->element('a', array('href' => common_local_url('taggedprofiles',
array('nickname' => $this->tagger->nickname, array('nickname' => $this->target->getNickname(),
'profiletag' => $this->peopletag->tag)), 'profiletag' => $this->peopletag->tag)),
'class' => 'more'), 'class' => 'more'),
// TRANS: Link for more "People in list x by a user" // TRANS: Link for more "People in list x by a user"

View File

@ -85,7 +85,7 @@ class ShowstreamAction extends NoticestreamAction
} }
} }
function showContent() protected function showContent()
{ {
$this->showNotices(); $this->showNotices();
} }

View File

@ -1593,8 +1593,20 @@ class Profile extends Managed_DataObject
return $this; return $this;
} }
public function sameAs(Profile $other) /**
* Test whether the given profile is the same as the current class,
* for testing identities.
*
* @param Profile $other The other profile, usually from Action's $this->scoped
*
* @return boolean
*/
public function sameAs(Profile $other=null)
{ {
if (is_null($other)) {
// In case $this->scoped is null or something, i.e. not a current/legitimate profile.
return false;
}
return $this->getID() === $other->getID(); return $this->getID() === $other->getID();
} }

View File

@ -21,20 +21,10 @@
* @license GNU Affero General Public License http://www.gnu.org/licenses/ * @license GNU Affero General Public License http://www.gnu.org/licenses/
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { if (!defined('GNUSOCIAL')) { exit(1); }
exit(1);
}
/**
* Table Definition for profile_list
*/
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
class Profile_list extends Managed_DataObject class Profile_list extends Managed_DataObject
{ {
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $__table = 'profile_list'; // table name public $__table = 'profile_list'; // table name
public $id; // int(4) primary_key not_null public $id; // int(4) primary_key not_null
public $tagger; // int(4) public $tagger; // int(4)
@ -48,9 +38,6 @@ class Profile_list extends Managed_DataObject
public $tagged_count; // smallint public $tagged_count; // smallint
public $subscriber_count; // smallint public $subscriber_count; // smallint
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
public static function schemaDef() public static function schemaDef()
{ {
return array( return array(
@ -94,7 +81,7 @@ class Profile_list extends Managed_DataObject
function getTagger() function getTagger()
{ {
return Profile::getKV('id', $this->tagger); return Profile::getByID($this->tagger);
} }
/** /**
@ -145,7 +132,7 @@ class Profile_list extends Managed_DataObject
$url = $this->mainpage; $url = $this->mainpage;
} else { } else {
$url = common_local_url('showprofiletag', $url = common_local_url('showprofiletag',
array('tagger' => $this->getTagger()->nickname, array('nickname' => $this->getTagger()->nickname,
'tag' => $this->tag)); 'tag' => $this->tag));
} }
} }
@ -659,7 +646,7 @@ class Profile_list extends Managed_DataObject
$orig = clone($ptag); $orig = clone($ptag);
$user = User::getKV('id', $ptag->tagger); $user = User::getKV('id', $ptag->tagger);
if(!empty($user)) { if(!empty($user)) {
$ptag->mainpage = common_local_url('showprofiletag', array('tag' => $ptag->tag, 'tagger' => $user->nickname)); $ptag->mainpage = common_local_url('showprofiletag', array('tag' => $ptag->tag, 'nickname' => $user->getNickname()));
} else { } else {
$ptag->mainpage = $uri; // assume this is a remote peopletag and the uri works $ptag->mainpage = $uri; // assume this is a remote peopletag and the uri works
} }

View File

@ -66,7 +66,7 @@ class ListsNav extends MoreMenu
while ($this->lists->fetch()) { while ($this->lists->fetch()) {
$mode = $this->lists->private ? 'private' : 'public'; $mode = $this->lists->private ? 'private' : 'public';
$items[] = array('showprofiletag', $items[] = array('showprofiletag',
array('tagger' => $this->profile->nickname, array('nickname' => $this->profile->getNickname(),
'tag' => $this->lists->tag), 'tag' => $this->lists->tag),
$this->lists->tag, $this->lists->tag,
''); '');

View File

@ -9,6 +9,9 @@ abstract class NoticestreamAction extends ProfileAction
protected function prepare(array $args=array()) { protected function prepare(array $args=array()) {
parent::prepare($args); parent::prepare($args);
// In case we need more info than ProfileAction->doPreparation() gives us
$this->doStreamPreparation();
// fetch the actual stream stuff // fetch the actual stream stuff
$stream = $this->getStream(); $stream = $this->getStream();
$this->notice = $stream->getNotices(($this->page-1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); $this->notice = $stream->getNotices(($this->page-1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
@ -21,6 +24,11 @@ abstract class NoticestreamAction extends ProfileAction
return true; return true;
} }
protected function doStreamPreparation()
{
// pass by default
}
// this fetches the NoticeStream // this fetches the NoticeStream
abstract public function getStream(); abstract public function getStream();
} }

View File

@ -76,7 +76,7 @@ class PeopletagGroupNav extends Widget
{ {
$user = null; $user = null;
// FIXME: we should probably pass this in // FIXME: we should probably pass this in and check when PeopletagGroupNav is actually loaded etc.
$action = $this->action->trimmed('action'); $action = $this->action->trimmed('action');
@ -107,7 +107,7 @@ class PeopletagGroupNav extends Widget
if (Event::handle('StartPeopletagGroupNav', array($this))) { if (Event::handle('StartPeopletagGroupNav', array($this))) {
// People tag timeline // People tag timeline
$this->out->menuItem(common_local_url('showprofiletag', array('tagger' => $user_profile->nickname, $this->out->menuItem(common_local_url('showprofiletag', array('nickname' => $user_profile->nickname,
'tag' => $tag->tag)), 'tag' => $tag->tag)),
// TRANS: Menu item in list navigation panel. // TRANS: Menu item in list navigation panel.
_m('MENU','List'), _m('MENU','List'),

View File

@ -315,7 +315,7 @@ abstract class ProfileAction extends ManagedAction
$url = $lists->mainpage; $url = $lists->mainpage;
} else { } else {
$url = common_local_url('showprofiletag', $url = common_local_url('showprofiletag',
array('tagger' => $this->target->getNickname(), array('nickname' => $this->target->getNickname(),
'tag' => $lists->tag)); 'tag' => $lists->tag));
} }
if (!$first) { if (!$first) {

View File

@ -921,6 +921,7 @@ class Router
$m->connect('all/:tag', $m->connect('all/:tag',
array('action' => 'showprofiletag', array('action' => 'showprofiletag',
'nickname' => $nickname,
'tag' => self::REGEX_TAG)); 'tag' => self::REGEX_TAG));
foreach (array('subscriptions', 'subscribers') as $a) { foreach (array('subscriptions', 'subscribers') as $a) {
@ -1003,9 +1004,9 @@ class Router
'tagger_id' => '[0-9]+', 'tagger_id' => '[0-9]+',
'id' => '[0-9]+')); 'id' => '[0-9]+'));
$m->connect(':tagger/all/:tag', $m->connect(':nickname/all/:tag',
array('action' => 'showprofiletag', array('action' => 'showprofiletag'),
'tagger' => Nickname::DISPLAY_FMT, array('nickname' => Nickname::DISPLAY_FMT,
'tag' => self::REGEX_TAG)); 'tag' => self::REGEX_TAG));
foreach (array('subscriptions', 'subscribers') as $a) { foreach (array('subscriptions', 'subscribers') as $a) {

View File

@ -786,7 +786,7 @@ function common_find_mentions($text, Notice $notice)
$tagged = $sender->getTaggedSubscribers($tag); $tagged = $sender->getTaggedSubscribers($tag);
$url = common_local_url('showprofiletag', $url = common_local_url('showprofiletag',
array('tagger' => $sender->nickname, array('nickname' => $sender->getNickname(),
'tag' => $tag)); 'tag' => $tag));
$mentions[] = array('mentioned' => $tagged, $mentions[] = array('mentioned' => $tagged,