Add pagination to ref pages
Add pagination to ref pages

--- a/include/controller/Controller_Heads.class.php
+++ b/include/controller/Controller_Heads.class.php
@@ -9,6 +9,17 @@
  */
 class GitPHP_Controller_Heads extends GitPHP_ControllerBase
 {
+
+	/**
+	 * Initialize controller
+	 */
+	public function Initialize()
+	{
+		parent::Initialize();
+
+		if (empty($this->params['page']))
+			$this->params['page'] = 0;
+	}
 
 	/**
 	 * Gets the template for this controller
@@ -52,8 +63,15 @@
 		$head = $this->GetProject()->GetHeadCommit();
 		$this->tpl->assign("head",$head);
 
-		$headlist = $this->GetProject()->GetHeadList()->GetOrderedHeads('-committerdate');
+		$this->tpl->assign('page', $this->params['page']);
+		$skip = $this->params['page'] * 100;
+
+		$headlist = $this->GetProject()->GetHeadList()->GetOrderedHeads('-committerdate', 101, $skip);
 		if (isset($headlist) && (count($headlist) > 0)) {
+			if (count($headlist) > 100) {
+				$headlist = array_slice($headlist, 0, 100);
+				$this->tpl->assign('hasmoreheads', true);
+			}
 			$this->tpl->assign("headlist", $headlist);
 		}
 	}

--- a/include/controller/Controller_Tags.class.php
+++ b/include/controller/Controller_Tags.class.php
@@ -9,6 +9,17 @@
  */
 class GitPHP_Controller_Tags extends GitPHP_ControllerBase
 {
+
+	/**
+	 * Initialize controller
+	 */
+	public function Initialize()
+	{
+		parent::Initialize();
+
+		if (empty($this->params['page']))
+			$this->params['page'] = 0;
+	}
 
 	/**
 	 * Gets the template for this controller
@@ -52,8 +63,15 @@
 		$head = $this->GetProject()->GetHeadCommit();
 		$this->tpl->assign("head",$head);
 
-		$taglist = $this->GetProject()->GetTagList()->GetOrderedTags('-creatordate');
+		$this->tpl->assign('page', $this->params['page']);
+		$skip = $this->params['page'] * 100;
+
+		$taglist = $this->GetProject()->GetTagList()->GetOrderedTags('-creatordate', 101, $skip);
 		if (isset($taglist) && (count($taglist) > 0)) {
+			if (count($taglist) > 100) {
+				$taglist = array_slice($taglist, 0, 100);
+				$this->tpl->assign('hasmoretags', true);
+			}
 			$this->tpl->assign("taglist",$taglist);
 		}
 	}

--- a/include/git/headlist/HeadListLoad_Git.class.php
+++ b/include/git/headlist/HeadListLoad_Git.class.php
@@ -27,13 +27,14 @@
 	 * @param GitPHP_HeadList $headList head list
 	 * @param string $order list order
 	 * @param integer $count number to load
+	 * @param integer $skip number to skip
 	 */
-	public function LoadOrdered($headList, $order, $count = 0)
+	public function LoadOrdered($headList, $order, $count = 0, $skip = 0)
 	{
 		if (!$headList)
 			return;
 
-		$ordered = $this->GetOrderedRefs($headList, 'heads', $order, $count);
+		$ordered = $this->GetOrderedRefs($headList, 'heads', $order, $count, $skip);
 
 		if (!$ordered)
 			return;

--- a/include/git/headlist/HeadListLoad_Raw.class.php
+++ b/include/git/headlist/HeadListLoad_Raw.class.php
@@ -26,8 +26,9 @@
 	 * @param GitPHP_HeadList $headList head list
 	 * @param string $order list order
 	 * @param integer $count number to load
+	 * @param integer $skip number to skip
 	 */
-	public function LoadOrdered($headList, $order, $count = 0)
+	public function LoadOrdered($headList, $order, $count = 0, $skip = 0)
 	{
 		if (!$headList)
 			return;
@@ -42,8 +43,11 @@
 			usort($heads, array('GitPHP_Head', 'CompareAge'));
 		}
 
-		if (($count > 0) && (count($heads) > $count)) {
-			$heads = array_slice($heads, 0, $count);
+		if ((($count > 0) && (count($heads) > $count)) || ($skip > 0)) {
+			if ($count > 0)
+				$heads = array_slice($heads, $skip, $count);
+			else
+				$heads = array_slice($heads, $skip);
 		}
 
 		return $heads;

--- a/include/git/reflist/RefListLoadStrategy.interface.php
+++ b/include/git/reflist/RefListLoadStrategy.interface.php
@@ -23,7 +23,8 @@
 	 * @param GitPHP_RefList $refList ref list
 	 * @param string $order list order
 	 * @param integer $count number to load
+	 * @param integer $skip number to skip
 	 */
-	public function LoadOrdered($refList, $order, $count = 0);
+	public function LoadOrdered($refList, $order, $count = 0, $skip = 0);
 }
 

--- a/include/git/reflist/RefListLoad_Git.class.php
+++ b/include/git/reflist/RefListLoad_Git.class.php
@@ -74,9 +74,10 @@
 	 * @param string $type type of ref
 	 * @param string $order order to use
 	 * @param int $count limit the number of results
+	 * @param int $skip skip a number of results
 	 * @return array array of refs
 	 */
-	protected function GetOrderedRefs($refList, $type, $order, $count = 0)
+	protected function GetOrderedRefs($refList, $type, $order, $count = 0, $skip = 0)
 	{
 		if (!$refList)
 			return;
@@ -88,7 +89,11 @@
 		$args[] = '--sort=' . $order;
 		$args[] = '--format="%(refname)"';
 		if ($count > 0) {
-			$args[] = '--count=' . $count;
+			if ($skip > 0) {
+				$args[] = '--count=' . ($count + $skip);
+			} else {
+				$args[] = '--count=' . $count;
+			}
 		}
 		$args[] = '--';
 		$args[] = 'refs/' . $type;
@@ -107,6 +112,10 @@
 				$refs[] = $ref;
 		}
 
+		if ($skip > 0) {
+			$refs = array_slice($refs, $skip);
+		}
+
 		return $refs;
 	}
 

--- a/include/git/taglist/TagList.class.php
+++ b/include/git/taglist/TagList.class.php
@@ -172,11 +172,12 @@
 	 *
 	 * @param string $order order to use
 	 * @param int $count limit the number of results
+	 * @param int $skip skip a number of results
 	 * @return GitPHP_Tag[] array of tags
 	 */
-	public function GetOrderedTags($order, $count = 0)
-	{
-		return $this->strategy->LoadOrdered($this, $order, $count);
+	public function GetOrderedTags($order, $count = 0, $skip = 0)
+	{
+		return $this->strategy->LoadOrdered($this, $order, $count, $skip);
 	}
 
 	/**

--- a/include/git/taglist/TagListLoad_Git.class.php
+++ b/include/git/taglist/TagListLoad_Git.class.php
@@ -26,13 +26,14 @@
 	 * @param GitPHP_TagList $tagList tag list
 	 * @param string $order list order
 	 * @param integer $count number to load
+	 * @param integer $skip number to skip
 	 */
-	public function LoadOrdered($tagList, $order, $count = 0)
+	public function LoadOrdered($tagList, $order, $count = 0, $skip = 0)
 	{
 		if (!$tagList)
 			return;
 
-		$ordered = $this->GetOrderedRefs($tagList, 'tags', $order, $count);
+		$ordered = $this->GetOrderedRefs($tagList, 'tags', $order, $count, $skip);
 
 		if (!$ordered)
 			return;

--- a/include/git/taglist/TagListLoad_Raw.class.php
+++ b/include/git/taglist/TagListLoad_Raw.class.php
@@ -26,8 +26,9 @@
 	 * @param GitPHP_TagList $tagList tag list
 	 * @param string $order list order
 	 * @param integer $count number to load
+	 * @param integer $skip number to skip
 	 */
-	public function LoadOrdered($tagList, $order, $count = 0)
+	public function LoadOrdered($tagList, $order, $count = 0, $skip = 0)
 	{
 		if (!$tagList)
 			return;
@@ -42,8 +43,11 @@
 			usort($tags, array('GitPHP_Tag', 'CompareCreationEpoch'));
 		}
 
-		if (($count > 0) && (count($tags) > $count)) {
-			$tags = array_slice($tags, 0, $count);
+		if ((($count > 0) && (count($tags) > $count)) || ($skip > 0)) {
+			if ($count > 0)
+				$tags = array_slice($tags, $skip, $count);
+			else
+				$tags = array_slice($tags, $skip);
 		}
 
 		return $tags;

--- a/templates/headlist.tpl
+++ b/templates/headlist.tpl
@@ -21,7 +21,12 @@
    {/foreach}
    {if $hasmoreheads}
        <tr>
-       <td><a href="{geturl project=$project action=heads}">&hellip;</a></td>
+       {if $source == 'summary'}
+         <td><a href="{geturl project=$project action=heads}">&hellip;</a></td>
+       {else if $source == 'heads'}
+         <td><a href="{geturl project=$project action=heads page=$page+1}" title="Alt-n">{t}next{/t}</a></td>
+	 <td></td><td></td>
+       {/if}
        </tr>
    {/if}
  </table>

--- a/templates/heads.tpl
+++ b/templates/heads.tpl
@@ -7,12 +7,38 @@
  *}
 {extends file='projectbase.tpl'}
 
+{block name=links}
+{if $page > 0}
+<link rel="prev" href="{geturl project=$project action=heads page=$page-1}" />
+{/if}
+{if $hasmoreheads}
+<link rel="next" href="{geturl project=$project action=heads page=$page+1}" />
+{/if}
+{/block}
+
 {block name=main}
 
  {* Nav *}
  <div class="page_nav">
    {include file='nav.tpl' commit=$head treecommit=$head}
-   <br /><br />
+   <br />
+   {if $page > 0}
+     <a href="{geturl project=$project action=heads}">{t}first{/t}</a>
+   {else}
+     {t}first{/t}
+   {/if}
+     &sdot;
+   {if $page > 0}
+     <a href="{geturl project=$project action=heads page=$page-1}">{t}prev{/t}</a>
+   {else}
+     {t}prev{/t}
+   {/if}
+     &sdot;
+   {if $hasmoreheads}
+     <a href="{geturl project=$project action=heads page=$page+1}">{t}next{/t}</a>
+   {else}
+     {t}next{/t}
+   {/if}
  </div>
 
  {include file='title.tpl' target='summary'}

--- a/templates/project.tpl
+++ b/templates/project.tpl
@@ -46,7 +46,7 @@
   
   {include file='title.tpl' target='tags'}
 
-  {include file='taglist.tpl'}
+  {include file='taglist.tpl' source=summary}
    
  {/if}
 
@@ -54,7 +54,7 @@
 
   {include file='title.tpl' target='heads'}
 
-  {include file='headlist.tpl'}
+  {include file='headlist.tpl' source=summary}
 
  {/if}
 

--- a/templates/taglist.tpl
+++ b/templates/taglist.tpl
@@ -46,7 +46,12 @@
      {/foreach}
      {if $hasmoretags}
        <tr>
-         <td><a href="{geturl project=$project action=tags}">&hellip;</a></td>
+         {if $source == 'summary'}
+           <td><a href="{geturl project=$project action=tags}">&hellip;</a></td>
+	 {else if $source == 'tags'}
+	   <td><a href="{geturl project=$project action=tags page=$page+1}" title="Alt-n">{t}next{/t}</a></td>
+	   <td></td><td></td><td></td>
+	 {/if}
        </tr>
      {/if}
    </table>

--- a/templates/tags.tpl
+++ b/templates/tags.tpl
@@ -7,19 +7,45 @@
  *}
 {extends file='projectbase.tpl'}
 
+{block name=links}
+{if $page > 0}
+<link rel="prev" href="{geturl project=$project action=tags page=$page-1}" />
+{/if}
+{if $hasmoretags}
+<link rel="next" href="{geturl project=$project action=tags page=$page+1}" />
+{/if}
+{/block}
+
 {block name=main}
 
  {* Nav *}
  <div class="page_nav">
    {include file='nav.tpl' commit=$head treecommit=$head}
-   <br /><br />
+   <br />
+   {if $page > 0}
+     <a href="{geturl project=$project action=tags}">{t}first{/t}</a>
+   {else}
+     {t}first{/t}
+   {/if}
+     &sdot;
+   {if $page > 0}
+     <a href="{geturl project=$project action=tags page=$page-1}">{t}prev{/t}</a>
+   {else}
+     {t}prev{/t}
+   {/if}
+     &sdot;
+   {if $hasmoretags}
+     <a href="{geturl project=$project action=tags page=$page+1}">{t}next{/t}</a>
+   {else}
+     {t}next{/t}
+   {/if}
  </div>
 
 {include file='title.tpl' target='summary'}
  
  {* Display tags *}
 
- {include file='taglist.tpl'}
+ {include file='taglist.tpl' source=tags}
 
 {/block}
 

comments