Merge branch 'streammode' into 1.0.x

This commit is contained in:
Evan Prodromou 2011-09-24 10:17:17 -04:00
commit 379b3f5384
15 changed files with 666 additions and 17 deletions

View File

@ -859,3 +859,12 @@ performance
high: if you need high performance, or if you're seeing bad
performance, set this to true. It will turn off some high-intensity code from
the site.
oldschool
---------
enabled: enable certain old-style user settings options, like stream-only mode,
conversation trees, and nicknames in streams. Off by default, and
may not be well supported in future versions.

View File

@ -1,7 +1,7 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
* Copyright (C) 2008-2011, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -56,7 +56,13 @@ class AllAction extends ProfileAction
{
parent::prepare($args);
$stream = new ThreadingInboxNoticeStream($this->user, Profile::current());
$user = common_current_user();
if (!empty($user) && $user->streamModeOnly()) {
$stream = new InboxNoticeStream($this->user, Profile::current());
} else {
$stream = new ThreadingInboxNoticeStream($this->user, Profile::current());
}
$this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
NOTICES_PER_PAGE + 1);
@ -176,7 +182,11 @@ class AllAction extends ProfileAction
$profile = $current_user->getProfile();
}
$nl = new ThreadedNoticeList($this->notice, $this, $profile);
if (!empty($current_user) && $current_user->streamModeOnly()) {
$nl = new NoticeList($this->notice, $this);
} else {
$nl = new ThreadedNoticeList($this->notice, $this, $profile);
}
$cnt = $nl->show();

View File

@ -123,9 +123,15 @@ class ConversationAction extends Action
*/
function showContent()
{
$tnl = new FullThreadedNoticeList($this->notices, $this, $this->userProfile);
$user = common_current_user();
$cnt = $tnl->show();
if (!empty($user) && $user->conversationTree()) {
$nl = new ConversationTree($this->notices, $this);
} else {
$nl = new FullThreadedNoticeList($this->notices, $this, $this->userProfile);
}
$cnt = $nl->show();
}
function isReadOnly()
@ -162,3 +168,4 @@ class ConversationAction extends Action
_('Conversation feed (Activity Streams JSON)')));
}
}

View File

@ -0,0 +1,228 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* Settings panel for old-school UI
*
* PHP version 5
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Oldschool
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET')) {
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
/**
* Old-school settings
*
* @category Oldschool
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
class OldschoolsettingsAction extends SettingsAction
{
/**
* Title of the page
*
* @return string Title of the page
*/
function title()
{
// TRANS: Page title for profile settings.
return _('Old school UI settings');
}
/**
* Instructions for use
*
* @return instructions for use
*/
function getInstructions()
{
// TRANS: Usage instructions for profile settings.
return _('If you like it "the old way", you can set that here.');
}
/**
* For initializing members of the class.
*
* @param array $argarray misc. arguments
*
* @return boolean true
*/
function prepare($argarray)
{
if (!common_config('oldschool', 'enabled')) {
throw new ClientException("Old-school settings not enabled.");
}
parent::prepare($argarray);
return true;
}
/**
* Handler method
*
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return void
*/
function handlePost()
{
$user = common_current_user();
$osp = Old_school_prefs::staticGet('user_id', $user->id);
$orig = null;
if (!empty($osp)) {
$orig = clone($osp);
} else {
$osp = new Old_school_prefs();
$osp->user_id = $user->id;
$osp->created = common_sql_now();
}
$osp->stream_mode_only = $this->boolean('stream_mode_only');
$osp->conversation_tree = $this->boolean('conversation_tree');
$osp->stream_nicknames = $this->boolean('stream_nicknames');
$osp->modified = common_sql_now();
if (!empty($orig)) {
$osp->update($orig);
} else {
$osp->insert();
}
// TRANS: Confirmation shown when user profile settings are saved.
$this->showForm(_('Settings saved.'), true);
return;
}
function showContent()
{
$user = common_current_user();
$form = new OldSchoolForm($this, $user);
$form->show();
}
}
class OldSchoolForm extends Form
{
var $user;
function __construct($out, $user)
{
parent::__construct($out);
$this->user = $user;
}
/**
* Visible or invisible data elements
*
* Display the form fields that make up the data of the form.
* Sub-classes should overload this to show their data.
*
* @return void
*/
function formData()
{
$this->elementStart('fieldset');
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
$this->checkbox('stream_mode_only', _('Only stream mode (no conversations) in timelines'),
$this->user->streamModeOnly());
$this->elementEnd('li');
$this->elementStart('li');
$this->checkbox('conversation_tree', _('Show conversation page as hierarchical trees'),
$this->user->conversationTree());
$this->elementEnd('li');
$this->elementStart('li');
$this->checkbox('stream_nicknames', _('Show nicknames (not full names) in timelines'),
$this->user->streamNicknames());
$this->elementEnd('li');
$this->elementEnd('fieldset');
$this->elementEnd('ul');
}
/**
* Buttons for form actions
*
* Submit and cancel buttons (or whatever)
* Sub-classes should overload this to show their own buttons.
*
* @return void
*/
function formActions()
{
$this->submit('submit', _('Save'));
}
/**
* ID of the form
*
* Should be unique on the page. Sub-classes should overload this
* to show their own IDs.
*
* @return int ID of the form
*/
function id()
{
return 'form_oldschool';
}
/**
* Action of the form.
*
* URL to post to. Should be overloaded by subclasses to give
* somewhere to post to.
*
* @return string URL to post to
*/
function action()
{
return common_local_url('oldschoolsettings');
}
/**
* Class of the form. May include space-separated list of multiple classes.
*
* @return string the form's class
*/
function formClass()
{
return 'form_settings';
}
}

View File

@ -88,7 +88,13 @@ class PublicAction extends Action
$this->userProfile = Profile::current();
$stream = new ThreadingPublicNoticeStream($this->userProfile);
$user = common_current_user();
if (!empty($user) && $user->streamModeOnly()) {
$stream = new PublicNoticeStream($this->userProfile);
} else {
$stream = new ThreadingPublicNoticeStream($this->userProfile);
}
$this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
NOTICES_PER_PAGE + 1);
@ -213,7 +219,13 @@ class PublicAction extends Action
*/
function showContent()
{
$nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile);
$user = common_current_user();
if (!empty($user) && $user->streamModeOnly()) {
$nl = new NoticeList($this->notice, $this);
} else {
$nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile);
}
$cnt = $nl->show();

View File

@ -97,10 +97,15 @@ class ShowgroupAction extends GroupAction
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
$this->userProfile = Profile::current();
$stream = new ThreadingGroupNoticeStream($this->group, $this->userProfile);
$user = common_current_user();
if (!empty($user) && $user->streamModeOnly()) {
$stream = new GroupNoticeStream($this->group, $this->userProfile);
} else {
$stream = new ThreadingGroupNoticeStream($this->group, $this->userProfile);
}
$this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
NOTICES_PER_PAGE + 1);
@ -140,7 +145,14 @@ class ShowgroupAction extends GroupAction
*/
function showGroupNotices()
{
$nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile);
$user = common_current_user();
if (!empty($user) && $user->streamModeOnly()) {
$nl = new NoticeList($this->notice, $this);
} else {
$nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile);
}
$cnt = $nl->show();
$this->pagination($this->page > 1,

View File

@ -0,0 +1,88 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* Older-style UI preferences
*
* PHP version 5
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category UI
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET')) {
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
/**
* Separate table for storing UI preferences
*
* @category UI
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
class Old_school_prefs extends Managed_DataObject
{
public $__table = 'old_school_prefs'; // table name
public $user_id;
public $stream_mode_only;
public $conversation_tree;
public $stream_nicknames;
public $created;
public $modified;
public static function schemaDef()
{
return array(
'fields' => array(
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who has the preference'),
'stream_mode_only' => array('type' => 'int',
'size' => 'tiny',
'default' => 1,
'description' => 'No conversation streams'),
'conversation_tree' => array('type' => 'int',
'size' => 'tiny',
'default' => 1,
'description' => 'Hierarchical tree view for conversations'),
'stream_nicknames' => array('type' => 'int',
'size' => 'tiny',
'default' => 1,
'description' => 'Show nicknames for authors and addressees in streams'),
'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
),
'primary key' => array('user_id'),
'foreign keys' => array(
'old_school_prefs_user_id_fkey' => array('user', array('user_id' => 'id')),
),
);
}
function staticGet($k,$v=NULL) {
return Memcached_DataObject::staticGet('Old_school_prefs',$k,$v);
}
}

View File

@ -1420,14 +1420,18 @@ class Profile extends Managed_DataObject
{
$ids = array();
foreach ($profiles as $profile) {
$ids[] = $profile->id;
if (!empty($profile)) {
$ids[] = $profile->id;
}
}
$avatars = Avatar::pivotGet('profile_id', $ids, array('width' => $width,
'height' => $width));
foreach ($profiles as $profile) {
$profile->_fillAvatar($width, $avatars[$profile->id]);
if (!empty($profile)) { // ???
$profile->_fillAvatar($width, $avatars[$profile->id]);
}
}
}

View File

@ -1145,4 +1145,39 @@ class User extends Managed_DataObject
// TRANS: Subject for password recovery e-mail.
mail_to_user($user, _('Password recovery requested'), $body, $headers, $confirm->address);
}
function streamModeOnly()
{
if (common_config('oldschool', 'enabled')) {
$osp = Old_school_prefs::staticGet('user_id', $this->id);
if (!empty($osp)) {
return $osp->stream_mode_only;
}
}
return false;
}
function conversationTree()
{
if (common_config('oldschool', 'enabled')) {
$osp = Old_school_prefs::staticGet('user_id', $this->id);
if (!empty($osp)) {
return $osp->conversation_tree;
}
}
return false;
}
function streamNicknames()
{
if (common_config('oldschool', 'enabled')) {
$osp = Old_school_prefs::staticGet('user_id', $this->id);
if (!empty($osp)) {
return $osp->stream_nicknames;
}
}
return false;
}
}

View File

@ -86,6 +86,7 @@ $classes = array('Profile',
'Local_group',
'User_urlshortener_prefs',
'Schema_version',
'Old_school_prefs',
);
foreach ($classes as $cls) {

215
lib/conversationtree.php Normal file
View File

@ -0,0 +1,215 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* Conversation tree widget for oooooold school playas
*
* PHP version 5
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Widget
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET')) {
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
/**
* Conversation tree
*
* The widget class for displaying a hierarchical list of notices.
*
* @category Widget
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*/
class ConversationTree extends NoticeList
{
var $tree = null;
var $table = null;
/**
* Show the tree of notices
*
* @return void
*/
function show()
{
$cnt = $this->_buildTree();
$this->out->elementStart('div', array('id' =>'notices_primary'));
// TRANS: Header on conversation page. Hidden by default (h2).
$this->out->element('h2', null, _('Notices'));
$this->out->elementStart('ol', array('class' => 'notices xoxo'));
if (array_key_exists('root', $this->tree)) {
$rootid = $this->tree['root'][0];
$this->showNoticePlus($rootid);
}
$this->out->elementEnd('ol');
$this->out->elementEnd('div');
return $cnt;
}
function _buildTree()
{
$cnt = 0;
$this->tree = array();
$this->table = array();
while ($this->notice->fetch()) {
$cnt++;
$id = $this->notice->id;
$notice = clone($this->notice);
$this->table[$id] = $notice;
if (is_null($notice->reply_to)) {
$this->tree['root'] = array($notice->id);
} else if (array_key_exists($notice->reply_to, $this->tree)) {
$this->tree[$notice->reply_to][] = $notice->id;
} else {
$this->tree[$notice->reply_to] = array($notice->id);
}
}
return $cnt;
}
/**
* Shows a notice plus its list of children.
*
* @param integer $id ID of the notice to show
*
* @return void
*/
function showNoticePlus($id)
{
$notice = $this->table[$id];
$this->out->elementStart('li', array('class' => 'hentry notice',
'id' => 'notice-' . $id));
$item = $this->newListItem($notice);
$item->show();
if (array_key_exists($id, $this->tree)) {
$children = $this->tree[$id];
$this->out->elementStart('ol', array('class' => 'notices'));
sort($children);
foreach ($children as $child) {
$this->showNoticePlus($child);
}
$this->out->elementEnd('ol');
}
$this->out->elementEnd('li');
}
/**
* Override parent class to return our preferred item.
*
* @param Notice $notice Notice to display
*
* @return NoticeListItem a list item to show
*/
function newListItem($notice)
{
return new ConversationTreeItem($notice, $this->out);
}
}
/**
* Conversation tree list item
*
* Special class of NoticeListItem for use inside conversation trees.
*
* @category Widget
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*/
class ConversationTreeItem extends NoticeListItem
{
/**
* start a single notice.
*
* The default creates the <li>; we skip, since the ConversationTree
* takes care of that.
*
* @return void
*/
function showStart()
{
return;
}
/**
* finish the notice
*
* The default closes the <li>; we skip, since the ConversationTree
* takes care of that.
*
* @return void
*/
function showEnd()
{
return;
}
/**
* show link to notice conversation page
*
* Since we're only used on the conversation page, we skip this
*
* @return void
*/
function showContext()
{
return;
}
/**
* show people this notice is in reply to
*
* Tree context shows this, so we skip it.
*
* @return void
*/
function showAddressees()
{
return;
}
}

View File

@ -352,5 +352,6 @@ $default =
array('cache' => true), // whether to cache the router object. Defaults to true, turn off for devel
'discovery' =>
array('cors' => false), // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
'performance' => array('high' => false) // disable some features for higher performance; default false
'performance' => array('high' => false), // disable some features for higher performance; default false
'oldschool' => array('enabled' => false) // enable users to use old-style UI
);

View File

@ -219,8 +219,14 @@ class NoticeListItem extends Widget
$this->out->elementStart('a', $attrs);
$this->showAvatar();
$this->out->text(' ');
$this->out->element('span',array('class' => 'fn'),
$this->profile->getBestName());
$user = common_current_user();
if (!empty($user) && $user->streamNicknames()) {
$this->out->element('span',array('class' => 'fn'),
$this->profile->nickname);
} else {
$this->out->element('span',array('class' => 'fn'),
$this->profile->getBestName());
}
$this->out->elementEnd('a');
$this->out->elementEnd('span');
@ -262,11 +268,15 @@ class NoticeListItem extends Widget
$groups = $this->getGroups();
$user = common_current_user();
$streamNicknames = !empty($user) && $user->streamNicknames();
foreach ($groups as $group) {
$ga[] = array('href' => $group->homeUrl(),
'title' => $group->nickname,
'class' => 'addressee group',
'text' => $group->getBestName());
'text' => ($streamNicknames) ? $group->nickname : $group->getBestName());
}
return $ga;
@ -283,11 +293,15 @@ class NoticeListItem extends Widget
$replies = $this->getReplyProfiles();
$user = common_current_user();
$streamNicknames = !empty($user) && $user->streamNicknames();
foreach ($replies as $reply) {
$pa[] = array('href' => $reply->profileurl,
'title' => $reply->nickname,
'class' => 'addressee account',
'text' => $reply->getBestName());
'text' => ($streamNicknames) ? $reply->nickname : $reply->getBestName());
}
return $pa;

View File

@ -184,6 +184,10 @@ class Router
$m->connect('settings/'.$s, array('action' => $s.'settings'));
}
if (common_config('oldschool', 'enabled')) {
$m->connect('settings/oldschool', array('action' => 'oldschoolsettings'));
}
$m->connect('settings/oauthapps/show/:id',
array('action' => 'showapplication'),
array('id' => '[0-9]+')

View File

@ -150,6 +150,15 @@ class SettingsNav extends Menu
_('Authorized connected applications'),
$actionName == 'oauthconnectionsettings');
if (common_config('oldschool', 'enabled')) {
$this->action->menuItem(common_local_url('oldschoolsettings'),
// TRANS: Menu item in settings navigation panel.
_m('MENU','Old school'),
// TRANS: Menu item title in settings navigation panel.
_('UI tweaks for old-school users'),
$actionName == 'oldschoolsettings');
}
Event::handle('EndConnectSettingsNav', array(&$this->action));
}