From 21474a311d99fa354303afd4d0e34492c8ead1e4 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sun, 22 Apr 2018 15:55:14 +0100 Subject: [PATCH] Add acquire-edit-lock action & update docs --- Changelog.md | 1 + build/index.php | 72 +++- .../classes/PeppermintParsedown.html | 10 +- docs/ModuleApi/classes/Slimdown.html | 10 +- docs/ModuleApi/classes/ids.html | 10 +- docs/ModuleApi/classes/page_renderer.html | 10 +- docs/ModuleApi/classes/search.html | 10 +- docs/ModuleApi/files/core.html | 64 +--- docs/ModuleApi/files/core.php.txt | 24 +- docs/ModuleApi/files/download.html | 10 +- docs/ModuleApi/files/modules.action-hash.html | 10 +- .../files/modules.action-protect.html | 10 +- .../files/modules.action-random.html | 10 +- docs/ModuleApi/files/modules.action-raw.html | 10 +- docs/ModuleApi/files/modules.api-status.html | 10 +- .../files/modules.extra-sidebar.html | 10 +- .../files/modules.feature-comments.html | 10 +- .../files/modules.feature-guiconfig.html | 10 +- .../files/modules.feature-history.html | 10 +- .../files/modules.feature-recent-changes.html | 10 +- .../files/modules.feature-redirect.html | 10 +- .../files/modules.feature-search.html | 10 +- .../files/modules.feature-stats.html | 10 +- .../files/modules.feature-upload.html | 10 +- .../modules.feature-user-preferences.html | 10 +- .../ModuleApi/files/modules.page-credits.html | 10 +- .../files/modules.page-debug-info.html | 10 +- docs/ModuleApi/files/modules.page-delete.html | 10 +- docs/ModuleApi/files/modules.page-edit.html | 10 +- docs/ModuleApi/files/modules.page-export.html | 10 +- docs/ModuleApi/files/modules.page-help.html | 10 +- docs/ModuleApi/files/modules.page-list.html | 10 +- docs/ModuleApi/files/modules.page-login.html | 10 +- docs/ModuleApi/files/modules.page-logout.html | 10 +- docs/ModuleApi/files/modules.page-move.html | 10 +- docs/ModuleApi/files/modules.page-update.html | 10 +- .../files/modules.page-user-list.html | 10 +- docs/ModuleApi/files/modules.page-view.html | 10 +- .../files/modules.parser-default-old.html | 10 +- .../files/modules.parser-parsedown.html | 10 +- .../files/modules/api-status.php.txt | 17 +- .../files/modules/feature-comments.php.txt | 42 +++ .../files/modules/feature-guiconfig.php.txt | 4 +- .../modules/feature-recent-changes.php.txt | 43 ++- .../files/modules/feature-search.php.txt | 2 +- .../files/modules/feature-upload.php.txt | 5 +- .../files/modules/page-credits.php.txt | 2 +- .../ModuleApi/files/modules/page-edit.php.txt | 72 +++- .../files/modules/page-login.php.txt | 14 +- .../files/modules/parser-parsedown.php.txt | 3 +- docs/ModuleApi/files/pack.html | 10 +- .../files/peppermint-config-info.html | 250 ++++++++++++++ .../files/peppermint-config-info.php.txt | 121 +++++++ docs/ModuleApi/files/settings.fragment.html | 10 +- docs/ModuleApi/graphs/class.html | 6 +- docs/ModuleApi/index.html | 64 +--- docs/ModuleApi/namespaces/default.html | 64 +--- docs/ModuleApi/reports/deprecated.html | 6 +- docs/ModuleApi/reports/errors.html | 35 +- docs/ModuleApi/reports/markers.html | 14 +- docs/RestApi/api_data.js | 324 ++++++++++++------ docs/RestApi/api_data.json | 324 ++++++++++++------ docs/RestApi/api_project.js | 2 +- docs/RestApi/api_project.json | 2 +- module_index.json | 2 +- modules/page-edit.php | 72 +++- 66 files changed, 1345 insertions(+), 686 deletions(-) create mode 100644 docs/ModuleApi/files/peppermint-config-info.html create mode 100644 docs/ModuleApi/files/peppermint-config-info.php.txt diff --git a/Changelog.md b/Changelog.md index ae62426..f0231e3 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,6 +10,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t - [Rest API] Added support for the `mode` parameter to the `random` action - [Rest API] Added `format` parameter to `recentchanges` action - [Rest API] Added `comments-fetch` action to return a page's comments as JSON + - [Rest API] Added `acquire-edit-key` action to allow scripts and other automated services (e.g. bots and [mobile apps](https://github.com/sbrl/Pepperminty-Wiki-Client-Android)) to fetch an edit key for a specified page name. ### Fixed - Fixed various issues with both the module api & the rest api docs. diff --git a/build/index.php b/build/index.php index a408af3..5cd448a 100644 --- a/build/index.php +++ b/build/index.php @@ -6191,12 +6191,12 @@ register_module([ "local_filename" => "diff.min.js", "remote_url" => "https://cdnjs.cloudflare.com/ajax/libs/jsdiff/2.2.2/diff.min.js" ]); - + /** * @api {get} ?action=edit&page={pageName}[&newpage=yes] Get an editing page * @apiDescription Gets an editing page for a given page. If you don't have permission to edit the page in question, a view source pagee is returned instead. * @apiName EditPage - * @apiGroup Page + * @apiGroup Editing * @apiPermission Anonymous * * @apiUse PageParameter @@ -6316,7 +6316,7 @@ register_module([ } $content .= "
- +

@@ -6427,11 +6427,71 @@ window.addEventListener("load", function(event) {
 			
 		});
 		
+		/**
+		 * @api {post} ?action=acquire-edit-key&page={pageName}		Acquire an edit key for a page
+		 * @apiDescription	Returns an edit key that can be used to programmatically save an edit to a page. It does _not_ necessarily mean that such an edit will be saved. For example, editing might be disabled, or you might not have permission to save an edit on a particular page.
+		 * @apiName 		AcquireEditKey
+		 * @apiGroup		Editing
+		 * @apiPermission	Anonymous
+		 * 
+		 * @apiUse	PageParameter
+		 * @apiPara	{string}	format	The format ot return the edit key in. Possible values: text, json. Default: text.
+		 */
+		
+		/*
+ 		 *  █████   ██████  ██████  ██    ██ ██ ██████  ███████
+ 		 * ██   ██ ██      ██    ██ ██    ██ ██ ██   ██ ██
+ 		 * ███████ ██      ██    ██ ██    ██ ██ ██████  █████ █████
+ 		 * ██   ██ ██      ██ ▄▄ ██ ██    ██ ██ ██   ██ ██
+ 		 * ██   ██  ██████  ██████   ██████  ██ ██   ██ ███████
+ 		 *                     ▀▀
+ 		 * 
+ 		 * ███████ ██████  ██ ████████
+ 		 * ██      ██   ██ ██    ██
+ 		 * █████   ██   ██ ██    ██ █████
+ 		 * ██      ██   ██ ██    ██
+ 		 * ███████ ██████  ██    ██
+ 		 * 
+ 		 * ██   ██ ███████ ██    ██
+ 		 * ██  ██  ██       ██  ██
+ 		 * █████   █████     ████
+ 		 * ██  ██  ██         ██
+ 		 * ██   ██ ███████    ██
+		 */
+		add_action("acquire-edit-key", function() {
+			global $env;
+			
+			if(!file_exists($env->page_filename)) {
+				http_response_code(404);
+				header("content-type: text/plain");
+				exit("Error: The page '$env->page' couldn't be found.");
+			}
+			
+			$format = $_GET["format"] ?? "text";
+			$page_hash = generate_page_hash(file_get_contents($env->page_filename));
+			
+			switch($format) {
+				case "text":
+					header("content-type: text/plain");
+					exit("$env->page\t$page_hash");
+				case "json":
+					$result = new stdClass();
+					$result->page = $env->page;
+					$result->key = $page_hash;
+					header("content-type: application/json");
+					exit(json_encode($result));
+				default:
+					http_response_code(406);
+					header("content-type: text/plain");
+					exit("Error: The format $format is not currently known. Supported formats: text, json. Default: text.\nThink this is a bug? Open an issue at https://github.com/sbrl/Pepperminty-Wiki/issues/new");
+			}
+		});
+		
 		/**
 		 * @api {post} ?action=save&page={pageName}	Save an edit to a page.
 		 * @apiDescription	Saves an edit to a page. If an edit conflict is encountered, then a conflict resolution page is returned instead.
 		 * @apiName			EditPage
-		 * @apiGroup		Page
+		 * @apiGroup		Editing
 		 * @apiPermission	Anonymous
 		 * 
 		 * @apiUse	PageParameter
@@ -6648,6 +6708,10 @@ DIFFSCRIPT;
 	}
 ]);
 
+function generate_page_hash($page_data) {
+	return sha1($page_data);
+}
+
 
 
 
diff --git a/docs/ModuleApi/classes/PeppermintParsedown.html b/docs/ModuleApi/classes/PeppermintParsedown.html
index 3a6003f..67b8399 100644
--- a/docs/ModuleApi/classes/PeppermintParsedown.html
+++ b/docs/ModuleApi/classes/PeppermintParsedown.html
@@ -106,12 +106,12 @@