Added ['reuse_query_string'] to Pagination.
This allows automatic repopulation of query string arguments, combined with normal URI segments.
diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php
index 5a4ca8f..75745dd 100644
--- a/system/libraries/Pagination.php
+++ b/system/libraries/Pagination.php
@@ -36,39 +36,40 @@
  */
 class CI_Pagination {
 
-	public $base_url		= ''; // The page we are linking to
-	public $prefix			= ''; // A custom prefix added to the path.
-	public $suffix			= ''; // A custom suffix added to the path.
-	public $total_rows		= 0; // Total number of items (database results)
-	public $per_page		= 10; // Max number of items you want shown per page
-	public $num_links		= 2; // Number of "digit" links to show before/after the currently viewed page
-	public $cur_page		= 0; // The current page being viewed
-	public $use_page_numbers	= FALSE; // Use page number for segment instead of offset
-	public $first_link		= '‹ First';
-	public $next_link		= '>';
-	public $prev_link		= '<';
-	public $last_link		= 'Last ›';
-	public $uri_segment		= 3;
-	public $full_tag_open		= '';
-	public $full_tag_close		= '';
-	public $first_tag_open		= '';
-	public $first_tag_close		= ' ';
-	public $last_tag_open		= ' ';
-	public $last_tag_close		= '';
-	public $first_url		= ''; // Alternative URL for the First Page.
-	public $cur_tag_open		= '&nbsp;<strong>';
-	public $cur_tag_close		= '</strong>';
-	public $next_tag_open		= '&nbsp;';
-	public $next_tag_close		= '&nbsp;';
-	public $prev_tag_open		= '&nbsp;';
-	public $prev_tag_close		= '';
-	public $num_tag_open		= '&nbsp;';
-	public $num_tag_close		= '';
-	public $page_query_string	= FALSE;
-	public $query_string_segment 	= 'per_page';
-	public $display_pages		= TRUE;
-	protected $_attributes		= '';
-	protected $_link_types		= array();
+	protected $base_url				= ''; // The page we are linking to
+	protected $prefix				= ''; // A custom prefix added to the path.
+	protected $suffix				= ''; // A custom suffix added to the path.
+	protected $total_rows			= 0; // Total number of items (database results)
+	protected $per_page				= 10; // Max number of items you want shown per page
+	protected $num_links			= 2; // Number of "digit" links to show before/after the currently viewed page
+	protected $cur_page				= 0; // The current page being viewed
+	protected $use_page_numbers		= FALSE; // Use page number for segment instead of offset
+	protected $first_link			= '&lsaquo; First';
+	protected $next_link			= '&gt;';
+	protected $prev_link			= '&lt;';
+	protected $last_link			= 'Last &rsaquo;';
+	protected $uri_segment			= 3;
+	protected $full_tag_open		= '';
+	protected $full_tag_close		= '';
+	protected $first_tag_open		= '';
+	protected $first_tag_close		= '&nbsp;';
+	protected $last_tag_open		= '&nbsp;';
+	protected $last_tag_close		= '';
+	protected $first_url			= ''; // Alternative URL for the First Page.
+	protected $cur_tag_open			= '&nbsp;<strong>';
+	protected $cur_tag_close		= '</strong>';
+	protected $next_tag_open		= '&nbsp;';
+	protected $next_tag_close		= '&nbsp;';
+	protected $prev_tag_open		= '&nbsp;';
+	protected $prev_tag_close		= '';
+	protected $num_tag_open			= '&nbsp;';
+	protected $num_tag_close		= '';
+	protected $page_query_string	= FALSE;
+	protected $query_string_segment 	= 'per_page';
+	protected $display_pages		= TRUE;
+	protected $_attributes			= '';
+	protected $_link_types			= array();
+	protected $reuse_query_string   = FALSE;
 
 	/**
 	 * Constructor
@@ -222,6 +223,23 @@
 
 		// And here we go...
 		$output = '';
+		$query_string = '';
+
+		// Add anything in the query string back to the links
+		// Note: Nothing to do with query_string_segment or any other query string options
+		if ($this->reuse_query_string === TRUE)
+		{
+			$get = $CI->input->get();
+			
+			// Unset the controll, method, old-school routing options
+			unset($get['c'], $get['m'], $get[$this->query_string_segment]);
+
+			// Put everything else onto the end
+			$query_string = (strpos($this->base_url, '&amp;') !== FALSE ? '&amp;' : '?') . http_build_query($get, '', '&amp;');
+
+			// Add this after the suffix to put it into more links easily
+			$this->suffix .= $query_string;
+		}
 
 		// Render the "First" link
 		if ($this->first_link !== FALSE && $this->cur_page > ($this->num_links + 1))
@@ -232,19 +250,19 @@
 		}
 
 		// Render the "previous" link
-		if  ($this->prev_link !== FALSE && $this->cur_page !== 1)
+		if ($this->prev_link !== FALSE && $this->cur_page !== 1)
 		{
 			$i = ($this->use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this->per_page;
 
 			if ($i === $base_page && $this->first_url !== '')
 			{
-				$output .= $this->prev_tag_open.'<a href="'.$this->first_url.'"'.$this->_attributes.$this->_attr_rel('prev').'>'
+				$output .= $this->prev_tag_open.'<a href="'.$this->first_url.$query_string.'"'.$this->_attributes.$this->_attr_rel('prev').'>'
 					.$this->prev_link.'</a>'.$this->prev_tag_close;
 			}
 			else
 			{
-				$i = ($i === $base_page) ? '' : $this->prefix.$i.$this->suffix;
-				$output .= $this->prev_tag_open.'<a href="'.$this->base_url.$i.'"'.$this->_attributes.$this->_attr_rel('prev').'>'
+				$append = ($i === $base_page) ? $query_string : $this->prefix.$i.$this->suffix;
+				$output .= $this->prev_tag_open.'<a href="'.$this->base_url.$append.'"'.$this->_attributes.$this->_attr_rel('prev').'>'
 					.$this->prev_link.'</a>'.$this->prev_tag_close;
 			}
 
@@ -268,13 +286,13 @@
 						$n = ($i === $base_page) ? '' : $i;
 						if ($n === '' && ! empty($this->first_url))
 						{
-							$output .= $this->num_tag_open.'<a href="'.$this->first_url.'"'.$this->_attributes.$this->_attr_rel('start').'>'
+							$output .= $this->num_tag_open.'<a href="'.$this->first_url.$query_string.'"'.$this->_attributes.$this->_attr_rel('start').'>'
 								.$loop.'</a>'.$this->num_tag_close;
 						}
 						else
 						{
-							$n = ($n === '') ? '' : $this->prefix.$n.$this->suffix;
-							$output .= $this->num_tag_open.'<a href="'.$this->base_url.$n.'"'.$this->_attributes.$this->_attr_rel('start').'>'
+							$append = ($n === '') ? $query_string : $this->prefix.$n.$this->suffix;
+							$output .= $this->num_tag_open.'<a href="'.$this->base_url.$append.'"'.$this->_attributes.$this->_attr_rel('start').'>'
 								.$loop.'</a>'.$this->num_tag_close;
 						}
 					}