1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-26 05:32:59 +00:00

Add untested etag code. Also tweak help page some more.

This commit is contained in:
Starbeamrainbowlabs 2016-04-07 10:18:58 +01:00
parent d4769658f7
commit 62310039ec
4 changed files with 49 additions and 3 deletions

View file

@ -351,7 +351,7 @@ textarea ~ input[type=submit] { margin: 0.5rem 0.8rem; padding: 0.5rem; font-wei
.tag-list li { display: inline-block; margin: 1rem; } .tag-list li { display: inline-block; margin: 1rem; }
.mini-tag { background: #d2c3dd; padding: 0.2rem 0.4rem; color: #fb701a; text-decoration: none; } .mini-tag { background: #d2c3dd; padding: 0.2rem 0.4rem; color: #fb701a; text-decoration: none; }
.help-section-header::after { content: attr(id); float: right; color: rgba(0, 0, 0, 0.4); font-size: 0.8rem; font-weight: normal; } .help-section-header::after { content: \"#\" attr(id); float: right; color: rgba(0, 0, 0, 0.4); font-size: 0.8rem; font-weight: normal; }
.cursor-query { cursor: help; } .cursor-query { cursor: help; }
@ -2628,6 +2628,29 @@ register_module([
if(isset($_GET["type"]) and in_array($_GET["type"], [ "image/png", "image/jpeg", "image/webp" ])) if(isset($_GET["type"]) and in_array($_GET["type"], [ "image/png", "image/jpeg", "image/webp" ]))
$output_mime = $_GET["type"]; $output_mime = $_GET["type"];
/// ETag handling ///
// TODO: Test this
error_log("Note to self: Please remember to test this etag code!");
// Generate the etag and send it to the client
$preview_etag = sha1("$output_mime|$target_size|$filepath|$mime_type");
$allheaders = getallheaders();
$allheaders = array_change_key_case($allheaders, CASE_LOWER);
error_log(var_export($allheaders, true));
if(!isset($allheaders["if-none-match"]))
{
header("etag: $preview_etag");
}
else
{
if($allheaders["if-none-match"] === $preview_etag)
{
http_response_code(304);
header("x-generation-time: " . (microtime(true) - $start_time));
exit();
}
}
/// ETag handling end ///
$preview_image = new Imagick(); $preview_image = new Imagick();
switch(substr($mime_type, 0, strpos($mime_type, "/"))) switch(substr($mime_type, 0, strpos($mime_type, "/")))
{ {

View file

@ -68,7 +68,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": 1459963545, "lastupdate": 1459973604,
"optional": false "optional": false
}, },
{ {

View file

@ -215,6 +215,29 @@ register_module([
if(isset($_GET["type"]) and in_array($_GET["type"], [ "image/png", "image/jpeg", "image/webp" ])) if(isset($_GET["type"]) and in_array($_GET["type"], [ "image/png", "image/jpeg", "image/webp" ]))
$output_mime = $_GET["type"]; $output_mime = $_GET["type"];
/// ETag handling ///
// TODO: Test this
error_log("Note to self: Please remember to test this etag code!");
// Generate the etag and send it to the client
$preview_etag = sha1("$output_mime|$target_size|$filepath|$mime_type");
$allheaders = getallheaders();
$allheaders = array_change_key_case($allheaders, CASE_LOWER);
error_log(var_export($allheaders, true));
if(!isset($allheaders["if-none-match"]))
{
header("etag: $preview_etag");
}
else
{
if($allheaders["if-none-match"] === $preview_etag)
{
http_response_code(304);
header("x-generation-time: " . (microtime(true) - $start_time));
exit();
}
}
/// ETag handling end ///
$preview_image = new Imagick(); $preview_image = new Imagick();
switch(substr($mime_type, 0, strpos($mime_type, "/"))) switch(substr($mime_type, 0, strpos($mime_type, "/")))
{ {

View file

@ -348,7 +348,7 @@ textarea ~ input[type=submit] { margin: 0.5rem 0.8rem; padding: 0.5rem; font-wei
.tag-list li { display: inline-block; margin: 1rem; } .tag-list li { display: inline-block; margin: 1rem; }
.mini-tag { background: #d2c3dd; padding: 0.2rem 0.4rem; color: #fb701a; text-decoration: none; } .mini-tag { background: #d2c3dd; padding: 0.2rem 0.4rem; color: #fb701a; text-decoration: none; }
.help-section-header::after { content: attr(id); float: right; color: rgba(0, 0, 0, 0.4); font-size: 0.8rem; font-weight: normal; } .help-section-header::after { content: \"#\" attr(id); float: right; color: rgba(0, 0, 0, 0.4); font-size: 0.8rem; font-weight: normal; }
.cursor-query { cursor: help; } .cursor-query { cursor: help; }