From 242f197ccf8969c87e18f13d1a525dd01219b03c Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Thu, 24 Jan 2019 18:25:10 +0000
Subject: [PATCH] Add offset & count to recent-changes action

---
 Changelog.md                       |  1 +
 build/index.php                    | 12 ++++++++++--
 module_index.json                  |  2 +-
 modules/feature-recent-changes.php | 10 +++++++++-
 4 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/Changelog.md b/Changelog.md
index 61a1661..51252dd 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -8,6 +8,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
      - Added `interwiki_index_location` setting to control the location of the interwiki index (which is a CSV file that is documented in the main _Pepperminty Wiki_ documentation), which has to be specified in order for it to activate
      - Provides new module api functions: `interwiki_pagename_parse`, `interwiki_pagename_resolve`, `interwiki_get_pagename_url`, and `is_interwiki_link`
  - Added CSV support to the `recent-changes` action.
+ - Added `count` and `offset` GET parameters to `recent-changes` action.
 
 ### Changed
  - Completely reworked the README to refactor out the documentation to its [own static site](https://starbeamrainbowlabs.com/labs/peppermint/_docpress/)
diff --git a/build/index.php b/build/index.php
index bf20fcb..7bec4f1 100644
--- a/build/index.php
+++ b/build/index.php
@@ -409,7 +409,7 @@ if($settings->sessionprefix == "auto")
 /////////////////////////////////////////////////////////////////////////////
 /** The version of Pepperminty Wiki currently running. */
 $version = "v0.18-dev";
-$commit = "6aa55c74bfe5a6dfffc96d3c7d8c041d4a707abd";
+$commit = "e715c2049f0782f46919fd2b220eac9292183075";
 /// Environment ///
 /** Holds information about the current request environment. */
 $env = new stdClass();
@@ -3701,11 +3701,13 @@ register_module([
 			file_put_contents($paths->recentchanges, "[]");
 		
 		/**
-		 * @api {get} ?action=recent-changes[&format={code}] Get a list of recent changes
+		 * @api {get} ?action=recent-changes[&offset={number}][&count={number}][&format={code}] Get a list of recent changes
 		 * @apiName RecentChanges
 		 * @apiGroup Stats
 		 * @apiPermission Anonymous
 		 *
+		 * @apiParam	{number}	offset	If specified, start returning changes from this many changes in. 0 is the beginning.
+		 * @apiParam	{number}	count	If specified, return at most this many changes. A value of 0 means no limit (the default) - apart from the limit on the number of changes stored by the server (configurable in pepppermint.json).
 		 * @apiParam	{string}	format	The format to return the recent changes in. Valid values: html, json, csv. Default: html.
 		 */
 		/*
@@ -3725,9 +3727,15 @@ register_module([
 			global $settings, $paths, $pageindex;
 			
 			$format = $_GET["format"] ?? "html";
+			$offset = intval($_GET["offset"] ?? 0);
+			$count = intval($_GET["count"] ?? 0);
 			
 			$recent_changes = json_decode(file_get_contents($paths->recentchanges));
 			
+			// Limit the number of changes displayed if requested
+			if($count > 0)
+				$recent_changes = array_slice($recent_changes, $offset, $count);
+			
 			switch($format) {
 				case "html":
 					$content = "\t\t<h1>Recent Changes</h1>\n";
diff --git a/module_index.json b/module_index.json
index 89d8835..00c6def 100755
--- a/module_index.json
+++ b/module_index.json
@@ -95,7 +95,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds recent changes. Access through the 'recent-changes' action.",
         "id": "feature-recent-changes",
-        "lastupdate": 1548353858,
+        "lastupdate": 1548354223,
         "optional": false
     },
     {
diff --git a/modules/feature-recent-changes.php b/modules/feature-recent-changes.php
index 44a3469..3dc3a57 100644
--- a/modules/feature-recent-changes.php
+++ b/modules/feature-recent-changes.php
@@ -15,11 +15,13 @@ register_module([
 			file_put_contents($paths->recentchanges, "[]");
 		
 		/**
-		 * @api {get} ?action=recent-changes[&format={code}] Get a list of recent changes
+		 * @api {get} ?action=recent-changes[&offset={number}][&count={number}][&format={code}] Get a list of recent changes
 		 * @apiName RecentChanges
 		 * @apiGroup Stats
 		 * @apiPermission Anonymous
 		 *
+		 * @apiParam	{number}	offset	If specified, start returning changes from this many changes in. 0 is the beginning.
+		 * @apiParam	{number}	count	If specified, return at most this many changes. A value of 0 means no limit (the default) - apart from the limit on the number of changes stored by the server (configurable in pepppermint.json).
 		 * @apiParam	{string}	format	The format to return the recent changes in. Valid values: html, json, csv. Default: html.
 		 */
 		/*
@@ -39,9 +41,15 @@ register_module([
 			global $settings, $paths, $pageindex;
 			
 			$format = $_GET["format"] ?? "html";
+			$offset = intval($_GET["offset"] ?? 0);
+			$count = intval($_GET["count"] ?? 0);
 			
 			$recent_changes = json_decode(file_get_contents($paths->recentchanges));
 			
+			// Limit the number of changes displayed if requested
+			if($count > 0)
+				$recent_changes = array_slice($recent_changes, $offset, $count);
+			
 			switch($format) {
 				case "html":
 					$content = "\t\t<h1>Recent Changes</h1>\n";
