Commit b240a171 authored by Meitar Moscovitz's avatar Meitar Moscovitz

Beginning to refactor document relationship links to reduce common code.

My attempts here are to mimic the `pagination()` method shared by
actions. I'm tentatively adding the `$count` property to actions so that
we can query the number of notices ''being displayed'' per page prior to
calling the actual `pagination()` method itself, since document
relationship `<link>` elements need to be output inside of `showHead()`,
before `showContent()`, which is where `pagination()` is, gets called.
parent 35850123
......@@ -85,19 +85,8 @@ class AllAction extends Action
*/
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')));
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
$this->page, 'all', array('nickname' => $this->user->nickname));
}
function showLocalNav()
......
......@@ -203,16 +203,7 @@ class FavoritedAction extends Action
*/
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')));
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
$this->page, 'favorited');
}
}
......@@ -145,18 +145,7 @@ class GroupmembersAction extends Action
*/
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')));
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
$this->page, 'groupmembers', array('nickname' => $this->group->nickname));
}
}
......@@ -137,16 +137,7 @@ class GroupsAction extends Action
*/
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')));
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
$this->page, 'groups', array('nickname' => $this->group->nickname));
}
}
......@@ -70,19 +70,8 @@ class InboxAction extends MailboxAction
*/
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')));
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
$this->page, 'inbox', array('nickname' => $this->user->nickname));
}
/**
......
......@@ -69,19 +69,8 @@ class OutboxAction extends MailboxAction
*/
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')));
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
$this->page, 'outbox', array('nickname' => $this->user->nickname));
}
/**
......
......@@ -56,6 +56,18 @@ class PublicAction extends Action
var $page = null;
/**
* Number of notices being shown on this page.
*/
// Does this need to be here? Should it be?
// If it does, this property needs to be
// added to other actions as well, like $page.
// I'm trying to find a way to capture the
// output of the $cnt variable from this
// action's showContent() method but need
// to do so earlier, I think...?
var $count = null;
function isReadOnly()
{
return true;
......@@ -134,17 +146,8 @@ class PublicAction extends Action
*/
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')));
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
$this->page, 'public');
}
/**
......
......@@ -148,19 +148,8 @@ class RepliesAction extends Action
*/
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')));
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
$this->page, 'replies', array('nickname' => $this->user->nickname));
}
/**
......
......@@ -160,21 +160,11 @@ class ShowfavoritesAction extends Action
*/
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')));
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
$this->page, 'showfavorites', array('nickname' => $this->user->nickname));
}
/**
* show the personal group nav
*
......
......@@ -333,19 +333,8 @@ class ShowgroupAction extends Action
*/
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')));
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
$this->page, 'showgroup', array('nickname' => $this->group->nickname));
}
/**
......
......@@ -202,19 +202,8 @@ class ShowstreamAction extends Action
*/
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')));
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
$this->page, 'showstream', array('nickname' => $this->user->nickname));
}
function extraHead()
......
......@@ -76,19 +76,8 @@ class TagAction extends Action
*/
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')));
$this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
$this->page, 'tag', array('tag' => $this->tag));
}
function showPageNotice()
......
......@@ -938,4 +938,38 @@ class Action extends HTMLOutputter // lawsuit
$this->elementEnd('div');
}
}
/**
* Generate document metadata for sequential navigation
*
* @param boolean $have_before is there something before?
* @param boolean $have_after is there something after?
* @param integer $page current page
* @param string $action current action
* @param array $args rest of query arguments
*
* @return nothing
*/
function sequenceRelationships($have_next, $have_previous, $page, $action, $args=null)
{
// Outputs machine-readable pagination in <link> elements.
// Pattern taken from $this->pagination() method.
// "next" is equivalent to "after"
if ($have_next) {
$pargs = array('page' => $page-1);
$newargs = $args ? array_merge($args, $pargs) : $pargs;
$this->element('link', array('rel' => 'next',
'href' => common_local_url($action, $newargs),
'title' => _('Next')));
}
// "previous" is equivalent to "before"
if ($have_previous=true) { // FIXME
$pargs = array('page' => $page+1);
$newargs = $args ? array_merge($args, $pargs) : $pargs;
$this->element('link', array('rel' => 'prev',
'href' => common_local_url($action, $newargs),
'title' => _('Previous')));
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment