Add machine-readable pagination using HTML4.01 <link rel="next">, etc.

These extra `<link>` elements only appear on pages where pagination
makes sense. They trigger functionality in some user agents, such as
Opera's Navigation Bar for more easily navigating forward and backwards
across a paged set of notices, messages, or group lists, etc.
This commit is contained in:
Meitar Moscovitz 2009-02-09 00:02:51 +11:00
parent e85f0ae4c8
commit 6e2f045837
13 changed files with 273 additions and 1 deletions

View File

@ -78,6 +78,28 @@ class AllAction extends Action
'title' => sprintf(_('Feed for friends of %s'), $this->user->nickname)));
}
/**
* Output document relationship links
*
* @return void
*/
function showRelationshipLinks()
{
// Machine-readable pagination
if ($this->page > 1) {
$this->element('link', array('rel' => 'next',
'href' => common_local_url('all',
array('nickname' => $this->user->nickname,
'page' => $this->page - 1)),
'title' => _('Next Notices')));
}
$this->element('link', array('rel' => 'prev',
'href' => common_local_url('all',
array('nickname' => $this->user->nickname,
'page' => $this->page + 1)),
'title' => _('Previous Notices')));
}
function showLocalNav()
{
$nav = new PersonalGroupNav($this);

View File

@ -195,4 +195,24 @@ class FavoritedAction extends Action
$this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
$this->page, 'favorited');
}
/**
* Output document relationship links
*
* @return void
*/
function showRelationshipLinks()
{
// Machine-readable pagination
if ($this->page > 1) {
$this->element('link', array('rel' => 'next',
'href' => common_local_url('favorited',
array('page' => $this->page - 1)),
'title' => _('Next Notices')));
}
$this->element('link', array('rel' => 'prev',
'href' => common_local_url('favorited',
array('page' => $this->page + 1)),
'title' => _('Previous Notices')));
}
}

View File

@ -137,4 +137,26 @@ class GroupmembersAction extends Action
$this->page, 'groupmembers',
array('nickname' => $this->group->nickname));
}
}
/**
* Output document relationship links
*
* @return void
*/
function showRelationshipLinks()
{
// Machine-readable pagination
if ($this->page > 1) {
$this->element('link', array('rel' => 'next',
'href' => common_local_url('groupmembers',
array('nickname' => $this->group->nickname,
'page' => $this->page - 1)),
'title' => _('Next Group Members')));
}
$this->element('link', array('rel' => 'prev',
'href' => common_local_url('groupmembers',
array('nickname' => $this->group->nickname,
'page' => $this->page + 1)),
'title' => _('Previous Group Members')));
}
}

View File

@ -129,4 +129,24 @@ class GroupsAction extends Action
$gbm = new GroupsByMembersSection($this);
$gbm->show();
}
/**
* Output document relationship links
*
* @return void
*/
function showRelationshipLinks()
{
// Machine-readable pagination
if ($this->page > 1) {
$this->element('link', array('rel' => 'next',
'href' => common_local_url('groups',
array('page' => $this->page - 1)),
'title' => _('Next Groups')));
}
$this->element('link', array('rel' => 'prev',
'href' => common_local_url('groups',
array('page' => $this->page + 1)),
'title' => _('Previous Groups')));
}
}

View File

@ -63,6 +63,28 @@ class InboxAction extends MailboxAction
}
}
/**
* Output document relationship links
*
* @return void
*/
function showRelationshipLinks()
{
// Machine-readable pagination
if ($this->page > 1) {
$this->element('link', array('rel' => 'next',
'href' => common_local_url('inbox',
array('nickname' => $this->user->nickname,
'page' => $this->page - 1)),
'title' => _('Next Messages')));
}
$this->element('link', array('rel' => 'prev',
'href' => common_local_url('inbox',
array('nickname' => $this->user->nickname,
'page' => $this->page + 1)),
'title' => _('Previous Messages')));
}
/**
* Retrieve the messages for this user and this page
*

View File

@ -62,6 +62,28 @@ class OutboxAction extends MailboxAction
}
}
/**
* Output document relationship links
*
* @return void
*/
function showRelationshipLinks()
{
// Machine-readable pagination
if ($this->page > 1) {
$this->element('link', array('rel' => 'next',
'href' => common_local_url('outbox',
array('nickname' => $this->user->nickname,
'page' => $this->page - 1)),
'title' => _('Next Messages')));
}
$this->element('link', array('rel' => 'prev',
'href' => common_local_url('outbox',
array('nickname' => $this->user->nickname,
'page' => $this->page + 1)),
'title' => _('Previous Messages')));
}
/**
* retrieve the messages for this user and this page
*

View File

@ -127,6 +127,26 @@ class PublicAction extends Action
'title' => _('Public Stream Feed')));
}
/**
* Output document relationship links
*
* @return void
*/
function showRelationshipLinks()
{
// Machine-readable pagination
if ($this->page > 1) {
$this->element('link', array('rel' => 'next',
'href' => common_local_url('public',
array('page' => $this->page - 1)),
'title' => _('Next Notices')));
}
$this->element('link', array('rel' => 'prev',
'href' => common_local_url('public',
array('page' => $this->page + 1)),
'title' => _('Previous Notices')));
}
/**
* Extra head elements
*

View File

@ -141,6 +141,28 @@ class RepliesAction extends Action
'title' => $rsstitle));
}
/**
* Output document relationship links
*
* @return void
*/
function showRelationshipLinks()
{
// Machine-readable pagination
if ($this->page > 1) {
$this->element('link', array('rel' => 'next',
'href' => common_local_url('replies',
array('nickname' => $this->user->nickname,
'page' => $this->page - 1)),
'title' => _('Next Notices')));
}
$this->element('link', array('rel' => 'prev',
'href' => common_local_url('replies',
array('nickname' => $this->user->nickname,
'page' => $this->page + 1)),
'title' => _('Previous Notices')));
}
/**
* show the personal group nav
*

View File

@ -153,6 +153,28 @@ class ShowfavoritesAction extends Action
'title' => $feedtitle));
}
/**
* Output document relationship links
*
* @return void
*/
function showRelationshipLinks()
{
// Machine-readable pagination
if ($this->page > 1) {
$this->element('link', array('rel' => 'next',
'href' => common_local_url('showfavorites',
array('nickname' => $this->user->nickname,
'page' => $this->page - 1)),
'title' => _('Next Favorite Notices')));
}
$this->element('link', array('rel' => 'prev',
'href' => common_local_url('showfavorites',
array('nickname' => $this->user->nickname,
'page' => $this->page + 1)),
'title' => _('Previous Favorite Notices')));
}
/**
* show the personal group nav
*

View File

@ -326,6 +326,28 @@ class ShowgroupAction extends Action
$this->group->nickname)));
}
/**
* Output document relationship links
*
* @return void
*/
function showRelationshipLinks()
{
// Machine-readable pagination
if ($this->page > 1) {
$this->element('link', array('rel' => 'next',
'href' => common_local_url('showgroup',
array('nickname' => $this->group->nickname,
'page' => $this->page - 1)),
'title' => _('Next Notices')));
}
$this->element('link', array('rel' => 'prev',
'href' => common_local_url('showgroup',
array('nickname' => $this->group->nickname,
'page' => $this->page + 1)),
'title' => _('Previous Notices')));
}
/**
* Fill in the sidebar.
*

View File

@ -195,6 +195,28 @@ class ShowstreamAction extends Action
$this->user->nickname)));
}
/**
* Output document relationship links
*
* @return void
*/
function showRelationshipLinks()
{
// Machine-readable pagination
if ($this->page > 1) {
$this->element('link', array('rel' => 'next',
'href' => common_local_url('showstream',
array('nickname' => $this->user->nickname,
'page' => $this->page - 1)),
'title' => _('Next Notices')));
}
$this->element('link', array('rel' => 'prev',
'href' => common_local_url('showstream',
array('nickname' => $this->user->nickname,
'page' => $this->page + 1)),
'title' => _('Previous Notices')));
}
function extraHead()
{
// FOAF

View File

@ -69,6 +69,28 @@ class TagAction extends Action
'title' => sprintf(_('Feed for tag %s'), $this->tag)));
}
/**
* Output document relationship links
*
* @return void
*/
function showRelationshipLinks()
{
// Machine-readable pagination
if ($this->page > 1) {
$this->element('link', array('rel' => 'next',
'href' => common_local_url('tag',
array('tag' => $this->tag,
'page' => $this->page - 1)),
'title' => _('Next Notices')));
}
$this->element('link', array('rel' => 'prev',
'href' => common_local_url('tag',
array('tag' => $this->tag,
'page' => $this->page + 1)),
'title' => _('Previous Notices')));
}
function showPageNotice()
{
return sprintf(_('Messages tagged "%s", most recent first'), $this->tag);

View File

@ -111,6 +111,7 @@ class Action extends HTMLOutputter // lawsuit
$this->showTitle();
$this->showStylesheets();
$this->showScripts();
$this->showRelationshipLinks();
$this->showOpenSearch();
$this->showFeeds();
$this->showDescription();
@ -193,6 +194,19 @@ class Action extends HTMLOutputter // lawsuit
' ');
}
/**
* Show document relationship links
*
* SHOULD overload
*
* @return nothing
*/
function showRelationshipLinks()
{
// output <link> elements with appropriate HTML4.01 link types:
// http://www.w3.org/TR/html401/types.html#type-links
}
/**
* Show OpenSearch headers
*