action-raw: add new typeheader GET parameter

This commit is contained in:
Starbeamrainbowlabs 2020-08-08 01:18:01 +01:00
parent bbb3fc32ee
commit ddb7cd9c18
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
2 changed files with 10 additions and 5 deletions

View File

@ -27,6 +27,7 @@ Make sure you have PHP 7.3+ when you update past this point! It isn't the end of
- `comment_hide_all` determines whether the commenting system displays anything at all (if disabled, it's (almost) like the `feature-comments` doesn't exist - consider using the downloader to exclude the commenting system instead of enabling this setting) - `comment_hide_all` determines whether the commenting system displays anything at all (if disabled, it's (almost) like the `feature-comments` doesn't exist - consider using the downloader to exclude the commenting system instead of enabling this setting)
- `avatars_gravatar_enabled` determines whether redirects to [gravatar.com](https://gravatar.com/) should be performed if a user hasn't yet uploaded an avatar (if disabled then a blank image is returned instead of a redirect). - `avatars_gravatar_enabled` determines whether redirects to [gravatar.com](https://gravatar.com/) should be performed if a user hasn't yet uploaded an avatar (if disabled then a blank image is returned instead of a redirect).
- PDF previews now show the browser's UI when embedded in pages with the `![alt text](File/somefile.png)` syntax - PDF previews now show the browser's UI when embedded in pages with the `![alt text](File/somefile.png)` syntax
- [Rest API] Add new `typeheader` GET parameter to `raw` action (ref [Firefox bug 1319262](https://bugzilla.mozilla.org/show_bug.cgi?id=1319262))
### Changed ### Changed
- **New policy:** Only [officially supported](https://www.php.net/supported-versions.php) versions of PHP are officially supported by Pepperminty Wiki. - **New policy:** Only [officially supported](https://www.php.net/supported-versions.php) versions of PHP are officially supported by Pepperminty Wiki.

View File

@ -1,19 +1,20 @@
<?php <?php
register_module([ register_module([
"name" => "Raw page source", "name" => "Raw page source",
"version" => "0.7", "version" => "0.8",
"author" => "Starbeamrainbowlabs", "author" => "Starbeamrainbowlabs",
"description" => "Adds a 'raw' action that shows you the raw source of a page.", "description" => "Adds a 'raw' action that shows you the raw source of a page.",
"id" => "action-raw", "id" => "action-raw",
"code" => function() { "code" => function() {
global $settings; global $settings;
/** /**
* @api {get} ?action=raw&page={pageName} Get the raw source code of a page * @api {get} ?action=raw&page={pageName}[&typeheader={typeName}] Get the raw source code of a page
* @apiName RawSource * @apiName RawSource
* @apiGroup Page * @apiGroup Page
* @apiPermission Anonymous * @apiPermission Anonymous
* *
* @apiParam {string} page The page to return the source of. * @apiParam {string} page The page to return the source of.
* @apiParam {string} typeheader Optional; v0.22+. The content-type header to set on the response. If not set, defaults to text/markdown. Valid values: plaintext (returns text/plain). Does NOT change the content delivered. Useful for debugging if your browser doesn't display text returned with text/markdown.
*/ */
/* /*
@ -30,8 +31,11 @@ register_module([
http_response_code(404); http_response_code(404);
exit("Error: The page with the name $env->page could not be found.\n"); exit("Error: The page with the name $env->page could not be found.\n");
} }
if(isset($_GET["typeheader"]) && $_GET["typeheader"] == "plaintext")
header("content-type: text/markdown"); header("content-type: text/plain");
else
header("content-type: text/markdown");
header("content-disposition: inline");
header("content-length: " . filesize($env->page_filename)); header("content-length: " . filesize($env->page_filename));
exit(file_get_contents($env->page_filename)); exit(file_get_contents($env->page_filename));
}); });