We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit daea9887 authored by Evan Prodromou's avatar Evan Prodromou

Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing

parents f5ec7c27 07214f13
...@@ -501,7 +501,11 @@ class Memcached_DataObject extends Safe_DataObject ...@@ -501,7 +501,11 @@ class Memcached_DataObject extends Safe_DataObject
function raiseError($message, $type = null, $behaviour = null) function raiseError($message, $type = null, $behaviour = null)
{ {
throw new ServerException("DB_DataObject error [$type]: $message"); $id = get_class($this);
if ($this->id) {
$id .= ':' . $this->id;
}
throw new ServerException("[$id] DB_DataObject error [$type]: $message");
} }
static function cacheGet($keyPart) static function cacheGet($keyPart)
......
...@@ -54,7 +54,8 @@ var SN = { // StatusNet ...@@ -54,7 +54,8 @@ var SN = { // StatusNet
NoticeGeoName: 'notice_data-geo_name', NoticeGeoName: 'notice_data-geo_name',
NoticeDataGeo: 'notice_data-geo', NoticeDataGeo: 'notice_data-geo',
NoticeDataGeoCookie: 'notice_data-geo_cookie', NoticeDataGeoCookie: 'notice_data-geo_cookie',
NoticeDataGeoSelected: 'notice_data-geo_selected' NoticeDataGeoSelected: 'notice_data-geo_selected',
StatusNetInstance:'StatusNetInstance'
} }
}, },
...@@ -670,6 +671,35 @@ var SN = { // StatusNet ...@@ -670,6 +671,35 @@ var SN = { // StatusNet
date.setFullYear(year, month, day); date.setFullYear(year, month, day);
return date; return date;
},
StatusNetInstance: {
Set: function(value) {
var SNI = SN.U.StatusNetInstance.Get();
if (SNI !== null) {
value = $.extend(SNI, value);
}
$.cookie(
SN.C.S.StatusNetInstance,
JSON.stringify(value),
{
path: '/',
expires: SN.U.GetFullYear(2029, 0, 1)
});
},
Get: function() {
var cookieValue = $.cookie(SN.C.S.StatusNetInstance);
if (cookieValue !== null) {
return JSON.parse(cookieValue);
}
return null;
},
Delete: function() {
$.cookie(SN.C.S.StatusNetInstance, null);
}
} }
}, },
...@@ -707,6 +737,20 @@ var SN = { // StatusNet ...@@ -707,6 +737,20 @@ var SN = { // StatusNet
SN.U.NewDirectMessage(); SN.U.NewDirectMessage();
} }
},
Login: function() {
if (SN.U.StatusNetInstance.Get() !== null) {
var nickname = SN.U.StatusNetInstance.Get().Nickname;
if (nickname !== null) {
$('#form_login #nickname').val(nickname);
}
}
$('#form_login').bind('submit', function() {
SN.U.StatusNetInstance.Set({Nickname: $('#form_login #nickname').val()});
return true;
});
} }
} }
}; };
...@@ -721,5 +765,8 @@ $(document).ready(function(){ ...@@ -721,5 +765,8 @@ $(document).ready(function(){
if ($('#content .entity_actions').length > 0) { if ($('#content .entity_actions').length > 0) {
SN.Init.EntityActions(); SN.Init.EntityActions();
} }
if ($('#form_login').length > 0) {
SN.Init.Login();
}
}); });
...@@ -34,6 +34,7 @@ if (!defined('STATUSNET')) { ...@@ -34,6 +34,7 @@ if (!defined('STATUSNET')) {
class PoCoURL class PoCoURL
{ {
const URLS = 'urls';
const TYPE = 'type'; const TYPE = 'type';
const VALUE = 'value'; const VALUE = 'value';
const PRIMARY = 'primary'; const PRIMARY = 'primary';
...@@ -55,7 +56,7 @@ class PoCoURL ...@@ -55,7 +56,7 @@ class PoCoURL
$xs->elementStart('poco:urls'); $xs->elementStart('poco:urls');
$xs->element('poco:type', null, $this->type); $xs->element('poco:type', null, $this->type);
$xs->element('poco:value', null, $this->value); $xs->element('poco:value', null, $this->value);
if ($this->primary) { if (!empty($this->primary)) {
$xs->element('poco:primary', null, 'true'); $xs->element('poco:primary', null, 'true');
} }
$xs->elementEnd('poco:urls'); $xs->elementEnd('poco:urls');
...@@ -70,21 +71,19 @@ class PoCoAddress ...@@ -70,21 +71,19 @@ class PoCoAddress
public $formatted; public $formatted;
function __construct($formatted) // @todo Other address fields
{
if (empty($formatted)) {
return null;
}
$this->formatted = $formatted;
}
function asString() function asString()
{ {
$xs = new XMLStringer(true); if (!empty($this->formatted)) {
$xs->elementStart('poco:address'); $xs = new XMLStringer(true);
$xs->element('poco:formatted', null, $this->formatted); $xs->elementStart('poco:address');
$xs->elementEnd('poco:address'); $xs->element('poco:formatted', null, $this->formatted);
return $xs->getString(); $xs->elementEnd('poco:address');
return $xs->getString();
}
return null;
} }
} }
...@@ -92,25 +91,117 @@ class PoCo ...@@ -92,25 +91,117 @@ class PoCo
{ {
const NS = 'http://portablecontacts.net/spec/1.0'; const NS = 'http://portablecontacts.net/spec/1.0';
const USERNAME = 'preferredUsername'; const USERNAME = 'preferredUsername';
const NOTE = 'note'; const DISPLAYNAME = 'displayName';
const URLS = 'urls'; const NOTE = 'note';
public $preferredUsername; public $preferredUsername;
public $displayName;
public $note; public $note;
public $address; public $address;
public $urls = array(); public $urls = array();
function __construct($profile) function __construct($element = null)
{
if (empty($element)) {
return;
}
$this->preferredUsername = ActivityUtils::childContent(
$element,
self::USERNAME,
self::NS
);
$this->displayName = ActivityUtils::childContent(
$element,
self::DISPLAYNAME,
self::NS
);
$this->note = ActivityUtils::childContent(
$element,
self::NOTE,
self::NS
);
$this->address = $this->_getAddress($element);
$this->urls = $this->_getURLs($element);
}
private function _getURLs($element)
{
$urlEls = $element->getElementsByTagnameNS(self::NS, PoCoURL::URLS);
$urls = array();
foreach ($urlEls as $urlEl) {
$type = ActivityUtils::childContent(
$urlEl,
PoCoURL::TYPE,
PoCo::NS
);
$value = ActivityUtils::childContent(
$urlEl,
PoCoURL::VALUE,
PoCo::NS
);
$primary = ActivityUtils::childContent(
$urlEl,
PoCoURL::PRIMARY,
PoCo::NS
);
array_push($urls, new PoCoURL($type, $value, $primary));
}
return $urls;
}
private function _getAddress($element)
{ {
$this->preferredUsername = $profile->nickname; $addressEl = ActivityUtils::child(
$element,
PoCoAddress::ADDRESS,
PoCo::NS
);
$formatted = ActivityUtils::childContent(
$addressEl,
PoCoAddress::FORMATTED,
self::NS
);
if (!empty($formatted)) {
$address = new PoCoAddress();
$address->formatted = $formatted;
return $address;
}
return null;
}
function fromProfile($profile)
{
if (empty($profile)) {
return null;
}
$poco = new PoCo();
$poco->preferredUsername = $profile->nickname;
$poco->displayName = $profile->getBestName();
$this->note = $profile->bio; $poco->note = $profile->bio;
$this->address = new PoCoAddress($profile->location);
$paddy = new PoCoAddress();
$paddy->formatted = $profile->location;
$poco->address = $paddy;
if (!empty($profile->homepage)) { if (!empty($profile->homepage)) {
array_push( array_push(
$this->urls, $poco->urls,
new PoCoURL( new PoCoURL(
'homepage', 'homepage',
$profile->homepage, $profile->homepage,
...@@ -118,6 +209,8 @@ class PoCo ...@@ -118,6 +209,8 @@ class PoCo
) )
); );
} }
return $poco;
} }
function asString() function asString()
...@@ -129,6 +222,12 @@ class PoCo ...@@ -129,6 +222,12 @@ class PoCo
$this->preferredUsername $this->preferredUsername
); );
$xs->element(
'poco:displayName',
null,
$this->displayName
);
if (!empty($this->note)) { if (!empty($this->note)) {
$xs->element('poco:note', null, $this->note); $xs->element('poco:note', null, $this->note);
} }
...@@ -374,6 +473,8 @@ class ActivityObject ...@@ -374,6 +473,8 @@ class ActivityObject
public $source; public $source;
public $avatar; public $avatar;
public $geopoint; public $geopoint;
public $poco;
public $displayName;
/** /**
* Constructor * Constructor
...@@ -426,7 +527,6 @@ class ActivityObject ...@@ -426,7 +527,6 @@ class ActivityObject
$this->link = ActivityUtils::getPermalink($element); $this->link = ActivityUtils::getPermalink($element);
// XXX: grab PoCo stuff
} }
// Some per-type attributes... // Some per-type attributes...
...@@ -434,8 +534,9 @@ class ActivityObject ...@@ -434,8 +534,9 @@ class ActivityObject
$this->displayName = $this->title; $this->displayName = $this->title;
// @fixme we may have multiple avatars with different resolutions specified // @fixme we may have multiple avatars with different resolutions specified
$this->avatar = ActivityUtils::getLink($element, 'avatar'); $this->avatar = ActivityUtils::getLink($element, 'avatar');
$this->nickname = ActivityUtils::childContent($element, PoCo::USERNAME, PoCo::NS);
$this->poco = new PoCo($element);
} }
} }
...@@ -490,7 +591,7 @@ class ActivityObject ...@@ -490,7 +591,7 @@ class ActivityObject
$object->geopoint = (float)$profile->lat . ' ' . (float)$profile->lon; $object->geopoint = (float)$profile->lat . ' ' . (float)$profile->lon;
} }
$object->poco = new PoCo($profile); $object->poco = PoCo::fromProfile($profile);
return $object; return $object;
} }
...@@ -519,11 +620,19 @@ class ActivityObject ...@@ -519,11 +620,19 @@ class ActivityObject
} }
if (!empty($this->link)) { if (!empty($this->link)) {
$xs->element('link', array('rel' => 'alternate', 'type' => 'text/html'), $xs->element(
$this->link); 'link',
array(
'rel' => 'alternate',
'type' => 'text/html',
'href' => $this->link
),
null
);
} }
if ($this->type == ActivityObject::PERSON) { if ($this->type == ActivityObject::PERSON
|| $this->type == ActivityObject::GROUP) {
$xs->element( $xs->element(
'link', array( 'link', array(
'type' => empty($this->avatar) ? 'image/png' : $this->avatar->mediatype, 'type' => empty($this->avatar) ? 'image/png' : $this->avatar->mediatype,
...@@ -532,7 +641,7 @@ class ActivityObject ...@@ -532,7 +641,7 @@ class ActivityObject
? Avatar::defaultImage(AVATAR_PROFILE_SIZE) ? Avatar::defaultImage(AVATAR_PROFILE_SIZE)
: $this->avatar->displayUrl() : $this->avatar->displayUrl()
), ),
'' null
); );
} }
...@@ -848,11 +957,24 @@ class Activity ...@@ -848,11 +957,24 @@ class Activity
} }
// XXX: add context // XXX: add context
// XXX: add target
$xs->elementStart('author');
$xs->element('uri', array(), $this->actor->id);
if ($this->actor->title) {
$xs->element('name', array(), $this->actor->title);
}
$xs->elementEnd('author');
$xs->raw($this->actor->asString('activity:actor')); $xs->raw($this->actor->asString('activity:actor'));
$xs->element('activity:verb', null, $this->verb); $xs->element('activity:verb', null, $this->verb);
$xs->raw($this->object->asString());
if ($this->object) {
$xs->raw($this->object->asString());
}
if ($this->target) {
$xs->raw($this->target->asString('activity:target'));
}
$xs->elementEnd('entry'); $xs->elementEnd('entry');
......
...@@ -438,14 +438,15 @@ class NoticeListItem extends Widget ...@@ -438,14 +438,15 @@ class NoticeListItem extends Widget
$this->out->text(_('at')); $this->out->text(_('at'));
$this->out->text(' '); $this->out->text(' ');
if (empty($url)) { if (empty($url)) {
$this->out->element('span', array('class' => 'geo', $this->out->element('abbr', array('class' => 'geo',
'title' => $latlon), 'title' => $latlon),
$name); $name);
} else { } else {
$this->out->element('a', array('class' => 'geo', $this->out->elementStart('a', array('href' => $url));
'title' => $latlon, $this->out->element('abbr', array('class' => 'geo',
'href' => $url), 'title' => $latlon),
$name); $name);
$this->out->elementEnd('a');
} }
$this->out->elementEnd('span'); $this->out->elementEnd('span');
} }
......
...@@ -78,11 +78,16 @@ class OStatusPlugin extends Plugin ...@@ -78,11 +78,16 @@ class OStatusPlugin extends Plugin
*/ */
function onEndInitializeQueueManager(QueueManager $qm) function onEndInitializeQueueManager(QueueManager $qm)
{ {
// Prepare outgoing distributions after notice save.
$qm->connect('ostatus', 'OStatusQueueHandler');
// Outgoing from our internal PuSH hub // Outgoing from our internal PuSH hub
$qm->connect('hubverify', 'HubVerifyQueueHandler'); $qm->connect('hubverify', 'HubVerifyQueueHandler');
$qm->connect('hubdistrib', 'HubDistribQueueHandler');
$qm->connect('hubout', 'HubOutQueueHandler'); $qm->connect('hubout', 'HubOutQueueHandler');
// Outgoing Salmon replies (when we don't need a return value)
$qm->connect('salmonout', 'SalmonOutQueueHandler');
// Incoming from a foreign PuSH hub // Incoming from a foreign PuSH hub
$qm->connect('pushinput', 'PushInputQueueHandler'); $qm->connect('pushinput', 'PushInputQueueHandler');
return true; return true;
...@@ -93,7 +98,7 @@ class OStatusPlugin extends Plugin ...@@ -93,7 +98,7 @@ class OStatusPlugin extends Plugin
*/ */
function onStartEnqueueNotice($notice, &$transports) function onStartEnqueueNotice($notice, &$transports)
{ {
$transports[] = 'hubdistrib'; $transports[] = 'ostatus';
return true; return true;
} }
...@@ -199,25 +204,6 @@ class OStatusPlugin extends Plugin ...@@ -199,25 +204,6 @@ class OStatusPlugin extends Plugin
function onEndNoticeSave($notice) function onEndNoticeSave($notice)
{ {
$mentioned = $notice->getReplies();
foreach ($mentioned as $profile_id) {
$oprofile = Ostatus_profile::staticGet('profile_id', $profile_id);
if (!empty($oprofile) && !empty($oprofile->salmonuri)) {
common_log(LOG_INFO, "Sending notice '{$notice->uri}' to remote profile '{$oprofile->uri}'.");
// FIXME: this needs to go out in a queue handler
$xml = '<?xml version="1.0" encoding="UTF-8" ?' . '>';
$xml .= $notice->asAtomEntry(true, true);
$salmon = new Salmon();
$salmon->post($oprofile->salmonuri, $xml);
}
}
} }
/** /**
...@@ -295,13 +281,19 @@ class OStatusPlugin extends Plugin ...@@ -295,13 +281,19 @@ class OStatusPlugin extends Plugin
function onStartNoticeSourceLink($notice, &$name, &$url, &$title) function onStartNoticeSourceLink($notice, &$name, &$url, &$title)
{ {
if ($notice->source == 'ostatus') { if ($notice->source == 'ostatus') {
$bits = parse_url($notice->uri); if ($notice->url) {
$domain = $bits['host']; $bits = parse_url($notice->url);
$domain = $bits['host'];
$name = $domain; if (substr($domain, 0, 4) == 'www.') {
$url = $notice->uri; $name = substr($domain, 4);
$title = sprintf(_m("Sent from %s via OStatus"), $domain); } else {
return false; $name = $domain;
}
$url = $notice->url;
$title = sprintf(_m("Sent from %s via OStatus"), $domain);
return false;
}
} }
} }
...@@ -316,7 +308,7 @@ class OStatusPlugin extends Plugin ...@@ -316,7 +308,7 @@ class OStatusPlugin extends Plugin
{ {
$oprofile = Ostatus_profile::staticGet('feeduri', $feedsub->uri); $oprofile = Ostatus_profile::staticGet('feeduri', $feedsub->uri);
if ($oprofile) { if ($oprofile) {
$oprofile->processFeed($feed); $oprofile->processFeed($feed, 'push');
} else { } else {
common_log(LOG_DEBUG, "No ostatus profile for incoming feed $feedsub->uri"); common_log(LOG_DEBUG, "No ostatus profile for incoming feed $feedsub->uri");
} }
...@@ -517,12 +509,8 @@ class OStatusPlugin extends Plugin ...@@ -517,12 +509,8 @@ class OStatusPlugin extends Plugin
$oprofile = Ostatus_profile::staticGet('group_id', $group->id); $oprofile = Ostatus_profile::staticGet('group_id', $group->id);
if ($oprofile) { if ($oprofile) {
// Drop the PuSH subscription if there are no other subscribers. // Drop the PuSH subscription if there are no other subscribers.
$oprofile->garbageCollect();
$members = $group->getMembers(0, 1);
if ($members->N == 0) {
common_log(LOG_INFO, "Unsubscribing from now-unused group feed $oprofile->feeduri");
$oprofile->unsubscribe();
}
$member = Profile::staticGet($user->id); $member = Profile::staticGet($user->id);
......
...@@ -46,6 +46,11 @@ class GroupsalmonAction extends SalmonAction ...@@ -46,6 +46,11 @@ class GroupsalmonAction extends SalmonAction
$this->clientError(_('No such group.')); $this->clientError(_('No such group.'));
} }
$oprofile = Ostatus_profile::staticGet('group_id', $id);
if ($oprofile) {
$this->clientError(_m("Can't accept remote posts for a remote group."));
}
return true; return true;
} }
</