]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Add machine-readable pagination using HTML4.01 `<link rel="next">`, etc.
authorMeitar Moscovitz <meitarm@gmail.com>
Sun, 8 Feb 2009 13:02:51 +0000 (00:02 +1100)
committerMeitar Moscovitz <meitarm@gmail.com>
Sun, 8 Feb 2009 13:02:51 +0000 (00:02 +1100)
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.

13 files changed:
actions/all.php
actions/favorited.php
actions/groupmembers.php
actions/groups.php
actions/inbox.php
actions/outbox.php
actions/public.php
actions/replies.php
actions/showfavorites.php
actions/showgroup.php
actions/showstream.php
actions/tag.php
lib/action.php

index d75d1b94612b8f6adc42cd5f22c61490fed98a6f..76b1bbcdf8c5e1ac6a012f566cb223101b993913 100644 (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);
index fd5ff413cbbfd9cc8f0ac478c7aa084a7c0d43ca..367fb6dd698c321831cf2d73eda2347b18e0b346 100644 (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')));
+    }
 }
index 00f43a9f55e89c2e80d4a538e2fa3c62d45a6e8f..2b2bdba93d80cc8894f0748fc19ed11c9319e1e5 100644 (file)
@@ -137,4 +137,26 @@ class GroupmembersAction extends Action
                           $this->page, 'groupmembers',
                           array('nickname' => $this->group->nickname));
     }
-}
\ No newline at end of file
+
+    /**
+     * 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')));
+    }
+}
index 39dc2232bc5d82574b658b22883d8e831f11c531..b0bf7cfc2af57417f09e59940df24bbd31380fef 100644 (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')));
+    }
 }
index b553ab26ca6d082a61addf9c17764b1d3b154548..d12f3f20ae6ec8393a8e150f8fecc737c8fe2374 100644 (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
      *
index c8d7f28125e6bd539c6edd0fc1fb72379919847c..043b74edc49d55487dd2859ca0ada1abcad9bc04 100644 (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
      *
index cc6537f74f8afd4731f2bd15162fbaf176bd8bc7..25889eee5a0e2644fce6dfea67627c6dbc692b0c 100644 (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
      *
index 7eff74a6691e34505ceda2aa6dccbf9bc979bf33..5ae99e16523c14a0feac8fdb7235c224a1f80988 100644 (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
      *
index 31479e1a7891d0933e63cb8bc5735ccc99d59345..f0297172a69f27e9e7f9b09f7a0509548776b2ec 100644 (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
      *
index 7bc68fbc64a151ac377c414a4ace0e0d52997d26..7599a8de6ebb62ec10026aea1fb9e9129a0e3b89 100644 (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.
      *
index 28bb8453f8c1111dd04a44b9fcff947273fd146b..11615ebb0d564265f6e5b563c8f48c1673ea1c3b 100644 (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
index 4401f892a94603df41e2b06748bba5cca35bcb05..f71f6d342f99fca6088e9e1c685443668c285b35 100644 (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);
index c4172ada1135293fd2ce5a5d7c3487cfb7184c8a..ab51d0252ca0800b2317fea17cba893305cfa809 100644 (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
      *