diff --git a/Source/Source.ViewAPI.php b/Source/Source.ViewAPI.php
index c9c7760..615c4d7 100644
--- a/Source/Source.ViewAPI.php
+++ b/Source/Source.ViewAPI.php
@@ -143,3 +143,67 @@
}
}
+/**
+ * Display pagination links for changesets
+ * @param string $p_link URL to target page
+ * @param int $p_count Total number of changesets
+ * @param int $p_current Current page number
+ * @param int $p_perpage Number of changesets per page
+ */
+function Source_View_Pagination( $p_link, $p_current, $p_count, $p_perpage = 25 ) {
+ if( $p_count > $p_perpage ) {
+
+ $t_pages = ceil( $p_count / $p_perpage );
+ $t_block = max( 5, min( round( $t_pages / 10, -1 ), ceil( $t_pages / 6 ) ) );
+ $t_page_set = array();
+
+ $p_link .= '&offset=';
+
+ $t_page_link = function( $p_page, $p_text = null ) use( $p_current, $p_link ) {
+ if( is_null( $p_text ) ) {
+ $p_text = $p_page;
+ }
+ if( is_null( $p_page ) ) {
+ return '...';
+ } elseif( $p_page == $p_current ) {
+ return "$p_page";
+ } else {
+ return sprintf( '%s', $p_link . $p_page, $p_text );
+ }
+ };
+
+ if( $t_pages > 15 ) {
+ $t_used_page = false;
+ $t_pages_per_block = 3;
+ for( $i = 1; $i <= $t_pages; $i++ ) {
+ if( $i <= $t_pages_per_block
+ || $i > $t_pages - $t_pages_per_block
+ || ( $i >= $p_current - $t_pages_per_block && $i <= $p_current + $t_pages_per_block )
+ || $i % $t_block == 0)
+ {
+ $t_page_set[] = $i;
+ $t_used_page = true;
+ } else if( $t_used_page ) {
+ $t_page_set[] = null;
+ $t_used_page = false;
+ }
+ }
+
+ } else {
+ $t_page_set = range( 1, $t_pages );
+ }
+
+ if( $p_current > 1 ) {
+ echo $t_page_link( 1, lang_get( 'first' ) ), ' ';
+ echo $t_page_link( $p_current - 1, lang_get( 'prev' ) ), ' ';
+ }
+
+ $t_page_set = array_map( $t_page_link, $t_page_set );
+ echo join( ' ', $t_page_set );
+
+ if( $p_current < $t_pages ) {
+ echo ' ', $t_page_link( $p_current + 1, lang_get( 'next' ) );
+ echo ' ', $t_page_link( $t_pages, lang_get( 'last' ) );
+ }
+ }
+}
diff --git a/Source/pages/list.php b/Source/pages/list.php
index 34f9bae..25942d8 100644
--- a/Source/pages/list.php
+++ b/Source/pages/list.php
@@ -43,55 +43,17 @@
id => $t_repo ), false ) ?>
+
$f_perpage ) {
-
- $t_pages = ceil( $t_count / $f_perpage );
- $t_block = max( 5, min( 20, ceil( $t_pages / 6 ) ) );
- $t_current = $f_offset;
- $t_page_set = array();
-
- $t_page_link_body = "if ( is_null( \$t ) ) { \$t = \$p; }
- return ( is_null( \$p ) ? '...' : ( \$p == $t_current ? \"\$p\" :
- 'id' . '&offset=' . \$p . '\">' . \$t . '' ) );";
- $t_page_link = create_function( '$p, $t=null', $t_page_link_body ) or die( 'gah' );
-
- if ( $t_pages > 15 ) {
- $t_used_page = false;
- for( $i = 1; $i <= $t_pages; $i++ ) {
- if ( $i <= 3 || $i > $t_pages-3 ||
- ( $i >= $t_current-5 && $i <= $t_current+5 ) ||
- $i % $t_block == 0) {
-
- $t_page_set[] = $i;
- $t_used_page = true;
- } else if ( $t_used_page ) {
- $t_page_set[] = null;
- $t_used_page = false;
- }
- }
-
- } else {
- $t_page_set = range( 1, $t_pages );
- }
-
- if ( $t_current > 1 ) {
- echo $t_page_link( $f_offset-1, '<<' ), ' ';
- }
-
- $t_page_set = array_map( $t_page_link, $t_page_set );
- echo join( ' ', $t_page_set );
-
- if ( $t_current < $t_pages ) {
- echo ' ', $t_page_link( $f_offset+1, '>>' );
- }
-
-}
+Source_View_Pagination(
+ plugin_page('list') . '&id=' . $t_repo->id,
+ $f_offset,
+ $t_stats['changesets'],
+ $f_perpage
+);
?>
|
@@ -100,4 +62,3 @@
-
- $f_perpage ) {
-
- $t_pages = ceil( $t_count / $f_perpage );
- $t_block = max( 5, min( 20, ceil( $t_pages / 6 ) ) );
- $t_current = $f_offset;
- $t_page_set = array();
-
- $t_page_link_body = "if ( is_null( \$t ) ) { \$t = \$p; }
- return ( is_null( \$p ) ? '...' : ( \$p == $t_current ? \"
\$p\" :
- '
' . \$t . '' ) );";
- $t_page_link = create_function( '$p, $t=null', $t_page_link_body ) or die( 'gah' );
-
- if ( $t_pages > 15 ) {
- $t_used_page = false;
- for( $i = 1; $i <= $t_pages; $i++ ) {
- if ( $i <= 3 || $i > $t_pages-3 ||
- ( $i >= $t_current-4 && $i <= $t_current+4 ) ||
- $i % $t_block == 0) {
-
- $t_page_set[] = $i;
- $t_used_page = true;
- } else if ( $t_used_page ) {
- $t_page_set[] = null;
- $t_used_page = false;
- }
- }
-
- } else {
- $t_page_set = range( 1, $t_pages );
- }
-
- if ( $t_current > 1 ) {
- echo $t_page_link( $f_offset-1, '<<' ), ' ';
- }
-
- $t_page_set = array_map( $t_page_link, $t_page_set );
- echo join( ' ', $t_page_set );
-
- if ( $t_current < $t_pages ) {
- echo ' ', $t_page_link( $f_offset+1, '>>' );
- }
-
-}
-?>
+