1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-25 17:23:00 +00:00

Add mode parameter support to random action

This commit is contained in:
Starbeamrainbowlabs 2018-02-14 22:36:29 +00:00
parent 2109a5fd7d
commit 5b20df5b3d
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
9 changed files with 74 additions and 29 deletions

View file

@ -3,6 +3,10 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
## v0.16-dev ## v0.16-dev
### Added
- [Rest API] Added support for the `mode` parameter to the `random` action.
- Fixed various issues with both the module api & the rest api docs.
### Fixed ### Fixed
- Properly escaped content of short code box on file pages - Properly escaped content of short code box on file pages
- Display a more meaningful message to a logged in user if editing is disabled - Display a more meaningful message to a logged in user if editing is disabled

View file

@ -2271,11 +2271,15 @@ register_module([
* @apiName RawSource * @apiName RawSource
* @apiGroup Page * @apiGroup Page
* @apiPermission Anonymous * @apiPermission Anonymous
*
* @apiParam {string} mode The view mode to redirect to. This parameter is basically just passed through to the direct - it works in the same way as the mode parameter on the _view_ action does.
*/ */
add_action("random", function() { add_action("random", function() {
global $pageindex; global $pageindex;
$mode = preg_replace("/[^a-z-_]/i", "", $_GET["mode"] ?? "");
$pageNames = array_keys(get_object_vars($pageindex)); $pageNames = array_keys(get_object_vars($pageindex));
// Filter out pages we shouldn't send the user to // Filter out pages we shouldn't send the user to
@ -2287,7 +2291,9 @@ register_module([
$randomPageName = $pageNames[array_rand($pageNames)]; $randomPageName = $pageNames[array_rand($pageNames)];
http_response_code(307); http_response_code(307);
header("location: ?page=" . rawurlencode($randomPageName)); $redirect_url = "?page=" . rawurlencode($randomPageName);
if(!empty($mode)) $redirect_url .= "&mode=$mode";
header("location: $redirect_url");
}); });
add_help_section("26-random-redirect", "Jumping to a random page", "<p>$settings->sitename has a function that can send you to a random page. To use it, click <a href='?action=random'>here</a>. $settings->admindetails_name ($settings->sitename's adminstrator) may have added it to one of the menus.</p>"); add_help_section("26-random-redirect", "Jumping to a random page", "<p>$settings->sitename has a function that can send you to a random page. To use it, click <a href='?action=random'>here</a>. $settings->admindetails_name ($settings->sitename's adminstrator) may have added it to one of the menus.</p>");
@ -3156,13 +3162,13 @@ SCRIPT;
register_module([ register_module([
"name" => "Page History", "name" => "Page History",
"version" => "0.3", "version" => "0.3.1",
"author" => "Starbeamrainbowlabs", "author" => "Starbeamrainbowlabs",
"description" => "Adds the ability to keep unlimited page history, limited only by your disk space. Note that this doesn't store file history (yet). Currently depends on feature-recent-changes for rendering of the history page.", "description" => "Adds the ability to keep unlimited page history, limited only by your disk space. Note that this doesn't store file history (yet). Currently depends on feature-recent-changes for rendering of the history page.",
"id" => "feature-history", "id" => "feature-history",
"code" => function() { "code" => function() {
/** /**
* @api {get} ?action=history&page={pageName} Get a list of revisions for a page * @api {get} ?action=history&page={pageName}[&format={format}] Get a list of revisions for a page
* @apiName History * @apiName History
* @apiGroup Page * @apiGroup Page
* @apiPermission Anonymous * @apiPermission Anonymous
@ -3590,7 +3596,7 @@ register_module([
register_module([ register_module([
"name" => "Search", "name" => "Search",
"version" => "0.6", "version" => "0.6.1",
"author" => "Starbeamrainbowlabs", "author" => "Starbeamrainbowlabs",
"description" => "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.", "description" => "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
"id" => "feature-search", "id" => "feature-search",
@ -5159,7 +5165,7 @@ register_module([
header("content-disposition: inline; filename=\"$shortFilename\""); header("content-disposition: inline; filename=\"$shortFilename\"");
header("last-modified: " . gmdate('D, d M Y H:i:s T', $pageindex->{$env->page}->lastmodified)); header("last-modified: " . gmdate('D, d M Y H:i:s T', $pageindex->{$env->page}->lastmodified));
// If the size is set or original, then send (or redirect to) the original image // If the size is set to original, then send (or redirect to) the original image
// Also do the same for SVGs if svg rendering is disabled. // Also do the same for SVGs if svg rendering is disabled.
if(isset($_GET["size"]) and $_GET["size"] == "original" or if(isset($_GET["size"]) and $_GET["size"] == "original" or
(empty($settings->render_svg_previews) && $mime_type == "image/svg+xml")) (empty($settings->render_svg_previews) && $mime_type == "image/svg+xml"))
@ -6321,6 +6327,7 @@ window.addEventListener("load", function(event) {
* @api {post} ?action=preview-edit&page={pageName}[&newpage=yes] Get a preview of the page * @api {post} ?action=preview-edit&page={pageName}[&newpage=yes] Get a preview of the page
* @apiDescription Gets a preview of the current edit state of a given page * @apiDescription Gets a preview of the current edit state of a given page
* @apiName PreviewPage * @apiName PreviewPage
* @apiGroup Editing
* @apiPermission Anonymous * @apiPermission Anonymous
* *
* @apiUse PageParameter * @apiUse PageParameter
@ -6823,11 +6830,13 @@ register_module([
global $settings; global $settings;
/** /**
* @api {get} ?action=list List all pages * @api {get} ?action=list[&format={format}] List all pages
* @apiDescription Gets a list of all the pages currently stored on the wiki. * @apiDescription Gets a list of all the pages currently stored on the wiki.
* @apiName ListPages * @apiName ListPages
* @apiGroup Page * @apiGroup Page
* @apiPermission Anonymous * @apiPermission Anonymous
*
* @apiParam {string} format The format to return the page list in. Default: html. Other foramts available: json, text
*/ */
/* /*
@ -7596,14 +7605,14 @@ register_module([
"id" => "page-view", "id" => "page-view",
"code" => function() { "code" => function() {
/** /**
* @api {get} ?action=view[&page={pageName}][&revision=rid][&printable=yes] View a page * @api {get} ?action=view[&page={pageName}][&revision=rid][&printable=yes][&mode={mode}] View a page
* @apiName View * @apiName View
* @apiGroup Page * @apiGroup Page
* @apiPermission Anonymous * @apiPermission Anonymous
* *
* @apiUse PageParameter * @apiUse PageParameter
* @apiParam {number} revision The revision number to display. * @apiParam {number} revision The revision number to display.
* @apiParam {string} mode Optional. The display mode to use. Can hld the following values: 'normal' - The default. Sends a normal page. 'printable' - Sends a printable version of the page. 'contentonly' - Sends only the content of the page, not the extra stuff around it. 'parsedsourceonly' - Sends only the raw rendered source of the page, as it appears just after it has come out of the page parser. Useful for writing external tools (see also the `raw` action). * @apiParam {string} mode Optional. The display mode to use. Can hold the following values: 'normal' - The default. Sends a normal page. 'printable' - Sends a printable version of the page. 'contentonly' - Sends only the content of the page, not the extra stuff around it. 'parsedsourceonly' - Sends only the raw rendered source of the page, as it appears just after it has come out of the page parser. Useful for writing external tools (see also the `raw` action).
* *
* @apiError NonExistentPageError The page doesn't exist and editing is disabled in the wiki's settings. If editing isn't disabled, you will be redirected to the edit page instead. * @apiError NonExistentPageError The page doesn't exist and editing is disabled in the wiki's settings. If editing isn't disabled, you will be redirected to the edit page instead.
* @apiError NonExistentRevisionError The specified revision was not found. * @apiError NonExistentRevisionError The specified revision was not found.

View file

@ -616,7 +616,7 @@ define({ "api": [
}, },
{ {
"type": "get", "type": "get",
"url": "?action=random", "url": "?action=random[&mode={mode}]",
"title": "Redirects to a random page.", "title": "Redirects to a random page.",
"name": "RawSource", "name": "RawSource",
"group": "Page", "group": "Page",
@ -627,6 +627,19 @@ define({ "api": [
"description": "" "description": ""
} }
], ],
"parameter": {
"fields": {
"Parameter": [
{
"group": "Parameter",
"type": "string",
"optional": false,
"field": "mode",
"description": "<p>The view mode to redirect to. This parameter is basically just passed through to the direct - it works in the same way as the mode parameter on the <em>view</em> action does.</p>"
}
]
}
},
"version": "0.0.0", "version": "0.0.0",
"filename": "./modules/action-random.php", "filename": "./modules/action-random.php",
"groupTitle": "Page" "groupTitle": "Page"
@ -663,7 +676,7 @@ define({ "api": [
}, },
{ {
"type": "get", "type": "get",
"url": "?action=view[&page={pageName}][&revision=rid][&printable=yes]", "url": "?action=view[&page={pageName}][&revision=rid][&printable=yes][&mode={mode}]",
"title": "View a page", "title": "View a page",
"name": "View", "name": "View",
"group": "Page", "group": "Page",
@ -689,7 +702,7 @@ define({ "api": [
"type": "string", "type": "string",
"optional": false, "optional": false,
"field": "mode", "field": "mode",
"description": "<p>Optional. The display mode to use. Can hld the following values: 'normal' - The default. Sends a normal page. 'printable' - Sends a printable version of the page. 'contentonly' - Sends only the content of the page, not the extra stuff around it. 'parsedsourceonly' - Sends only the raw rendered source of the page, as it appears just after it has come out of the page parser. Useful for writing external tools (see also the <code>raw</code> action).</p>" "description": "<p>Optional. The display mode to use. Can hold the following values: 'normal' - The default. Sends a normal page. 'printable' - Sends a printable version of the page. 'contentonly' - Sends only the content of the page, not the extra stuff around it. 'parsedsourceonly' - Sends only the raw rendered source of the page, as it appears just after it has come out of the page parser. Useful for writing external tools (see also the <code>raw</code> action).</p>"
}, },
{ {
"group": "Parameter", "group": "Parameter",

View file

@ -616,7 +616,7 @@
}, },
{ {
"type": "get", "type": "get",
"url": "?action=random", "url": "?action=random[&mode={mode}]",
"title": "Redirects to a random page.", "title": "Redirects to a random page.",
"name": "RawSource", "name": "RawSource",
"group": "Page", "group": "Page",
@ -627,6 +627,19 @@
"description": "" "description": ""
} }
], ],
"parameter": {
"fields": {
"Parameter": [
{
"group": "Parameter",
"type": "string",
"optional": false,
"field": "mode",
"description": "<p>The view mode to redirect to. This parameter is basically just passed through to the direct - it works in the same way as the mode parameter on the <em>view</em> action does.</p>"
}
]
}
},
"version": "0.0.0", "version": "0.0.0",
"filename": "./modules/action-random.php", "filename": "./modules/action-random.php",
"groupTitle": "Page" "groupTitle": "Page"
@ -663,7 +676,7 @@
}, },
{ {
"type": "get", "type": "get",
"url": "?action=view[&page={pageName}][&revision=rid][&printable=yes]", "url": "?action=view[&page={pageName}][&revision=rid][&printable=yes][&mode={mode}]",
"title": "View a page", "title": "View a page",
"name": "View", "name": "View",
"group": "Page", "group": "Page",
@ -689,7 +702,7 @@
"type": "string", "type": "string",
"optional": false, "optional": false,
"field": "mode", "field": "mode",
"description": "<p>Optional. The display mode to use. Can hld the following values: 'normal' - The default. Sends a normal page. 'printable' - Sends a printable version of the page. 'contentonly' - Sends only the content of the page, not the extra stuff around it. 'parsedsourceonly' - Sends only the raw rendered source of the page, as it appears just after it has come out of the page parser. Useful for writing external tools (see also the <code>raw</code> action).</p>" "description": "<p>Optional. The display mode to use. Can hold the following values: 'normal' - The default. Sends a normal page. 'printable' - Sends a printable version of the page. 'contentonly' - Sends only the content of the page, not the extra stuff around it. 'parsedsourceonly' - Sends only the raw rendered source of the page, as it appears just after it has come out of the page parser. Useful for writing external tools (see also the <code>raw</code> action).</p>"
}, },
{ {
"group": "Parameter", "group": "Parameter",

View file

@ -8,7 +8,7 @@ define({
"apidoc": "0.3.0", "apidoc": "0.3.0",
"generator": { "generator": {
"name": "apidoc", "name": "apidoc",
"time": "2018-02-14T22:22:08.521Z", "time": "2018-02-14T22:36:20.697Z",
"url": "http://apidocjs.com", "url": "http://apidocjs.com",
"version": "0.17.6" "version": "0.17.6"
} }

View file

@ -8,7 +8,7 @@
"apidoc": "0.3.0", "apidoc": "0.3.0",
"generator": { "generator": {
"name": "apidoc", "name": "apidoc",
"time": "2018-02-14T22:22:08.521Z", "time": "2018-02-14T22:36:20.697Z",
"url": "http://apidocjs.com", "url": "http://apidocjs.com",
"version": "0.17.6" "version": "0.17.6"
} }

View file

@ -23,7 +23,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds an action called 'random' that redirects you to a random page.", "description": "Adds an action called 'random' that redirects you to a random page.",
"id": "action-random", "id": "action-random",
"lastupdate": 1508968415, "lastupdate": 1518647615,
"optional": false "optional": false
}, },
{ {
@ -73,11 +73,11 @@
}, },
{ {
"name": "Page History", "name": "Page History",
"version": "0.3", "version": "0.3.1",
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds the ability to keep unlimited page history, limited only by your disk space. Note that this doesn't store file history (yet). Currently depends on feature-recent-changes for rendering of the history page.", "description": "Adds the ability to keep unlimited page history, limited only by your disk space. Note that this doesn't store file history (yet). Currently depends on feature-recent-changes for rendering of the history page.",
"id": "feature-history", "id": "feature-history",
"lastupdate": 1508967873, "lastupdate": 1518645062,
"optional": false "optional": false
}, },
{ {
@ -100,11 +100,11 @@
}, },
{ {
"name": "Search", "name": "Search",
"version": "0.6", "version": "0.6.1",
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.", "description": "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
"id": "feature-search", "id": "feature-search",
"lastupdate": 1517751847, "lastupdate": 1517752177,
"optional": false "optional": false
}, },
{ {
@ -122,7 +122,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds the ability to upload files to Pepperminty Wiki. Uploaded files act as pages and have the special 'File\/' prefix.", "description": "Adds the ability to upload files to Pepperminty Wiki. Uploaded files act as pages and have the special 'File\/' prefix.",
"id": "feature-upload", "id": "feature-upload",
"lastupdate": 1517061220, "lastupdate": 1518645569,
"optional": false "optional": false
}, },
{ {
@ -167,7 +167,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.", "description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
"id": "page-edit", "id": "page-edit",
"lastupdate": 1514762051, "lastupdate": 1518645807,
"optional": false "optional": false
}, },
{ {
@ -194,7 +194,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds a page that lists all the pages in the index along with their metadata.", "description": "Adds a page that lists all the pages in the index along with their metadata.",
"id": "page-list", "id": "page-list",
"lastupdate": 1505769119, "lastupdate": 1518645476,
"optional": false "optional": false
}, },
{ {
@ -248,7 +248,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Allows you to view pages. You really should include this one.", "description": "Allows you to view pages. You really should include this one.",
"id": "page-view", "id": "page-view",
"lastupdate": 1505491849, "lastupdate": 1518647294,
"optional": false "optional": false
}, },
{ {

View file

@ -8,15 +8,19 @@ register_module([
"code" => function() { "code" => function() {
global $settings; global $settings;
/** /**
* @api {get} ?action=random Redirects to a random page. * @api {get} ?action=random[&mode={mode}] Redirects to a random page.
* @apiName RawSource * @apiName RawSource
* @apiGroup Page * @apiGroup Page
* @apiPermission Anonymous * @apiPermission Anonymous
*
* @apiParam {string} mode The view mode to redirect to. This parameter is basically just passed through to the direct - it works in the same way as the mode parameter on the _view_ action does.
*/ */
add_action("random", function() { add_action("random", function() {
global $pageindex; global $pageindex;
$mode = preg_replace("/[^a-z-_]/i", "", $_GET["mode"] ?? "");
$pageNames = array_keys(get_object_vars($pageindex)); $pageNames = array_keys(get_object_vars($pageindex));
// Filter out pages we shouldn't send the user to // Filter out pages we shouldn't send the user to
@ -28,7 +32,9 @@ register_module([
$randomPageName = $pageNames[array_rand($pageNames)]; $randomPageName = $pageNames[array_rand($pageNames)];
http_response_code(307); http_response_code(307);
header("location: ?page=" . rawurlencode($randomPageName)); $redirect_url = "?page=" . rawurlencode($randomPageName);
if(!empty($mode)) $redirect_url .= "&mode=$mode";
header("location: $redirect_url");
}); });
add_help_section("26-random-redirect", "Jumping to a random page", "<p>$settings->sitename has a function that can send you to a random page. To use it, click <a href='?action=random'>here</a>. $settings->admindetails_name ($settings->sitename's adminstrator) may have added it to one of the menus.</p>"); add_help_section("26-random-redirect", "Jumping to a random page", "<p>$settings->sitename has a function that can send you to a random page. To use it, click <a href='?action=random'>here</a>. $settings->admindetails_name ($settings->sitename's adminstrator) may have added it to one of the menus.</p>");

View file

@ -7,14 +7,14 @@ register_module([
"id" => "page-view", "id" => "page-view",
"code" => function() { "code" => function() {
/** /**
* @api {get} ?action=view[&page={pageName}][&revision=rid][&printable=yes] View a page * @api {get} ?action=view[&page={pageName}][&revision=rid][&printable=yes][&mode={mode}] View a page
* @apiName View * @apiName View
* @apiGroup Page * @apiGroup Page
* @apiPermission Anonymous * @apiPermission Anonymous
* *
* @apiUse PageParameter * @apiUse PageParameter
* @apiParam {number} revision The revision number to display. * @apiParam {number} revision The revision number to display.
* @apiParam {string} mode Optional. The display mode to use. Can hld the following values: 'normal' - The default. Sends a normal page. 'printable' - Sends a printable version of the page. 'contentonly' - Sends only the content of the page, not the extra stuff around it. 'parsedsourceonly' - Sends only the raw rendered source of the page, as it appears just after it has come out of the page parser. Useful for writing external tools (see also the `raw` action). * @apiParam {string} mode Optional. The display mode to use. Can hold the following values: 'normal' - The default. Sends a normal page. 'printable' - Sends a printable version of the page. 'contentonly' - Sends only the content of the page, not the extra stuff around it. 'parsedsourceonly' - Sends only the raw rendered source of the page, as it appears just after it has come out of the page parser. Useful for writing external tools (see also the `raw` action).
* *
* @apiError NonExistentPageError The page doesn't exist and editing is disabled in the wiki's settings. If editing isn't disabled, you will be redirected to the edit page instead. * @apiError NonExistentPageError The page doesn't exist and editing is disabled in the wiki's settings. If editing isn't disabled, you will be redirected to the edit page instead.
* @apiError NonExistentRevisionError The specified revision was not found. * @apiError NonExistentRevisionError The specified revision was not found.