Add stacked bar to show where your space has gone

This commit is contained in:
Starbeamrainbowlabs 2017-04-17 14:01:19 +01:00
parent 477e065375
commit e2661a5ebb
4 changed files with 110 additions and 13 deletions

View File

@ -299,6 +299,9 @@ textarea ~ input[type=submit] { margin: 0.5rem 0; padding: 0.5rem; font-weight:
.help-section-header::after { content: "#" attr(id); float: right; color: rgba(0, 0, 0, 0.4); font-size: 0.8rem; font-weight: normal; }
.stacked-bar { display: flex; }
.stacked-bar-part { break-inside: avoid; white-space: pre; padding: 0.2em 0.3em; }
.cursor-query { cursor: help; }
summary { cursor: pointer; }
@ -684,6 +687,15 @@ function mb_stripos_all($haystack, $needle) {
return false;
}
/**
* Tests whether a string starts with a specified substring.
* @param string $haystack The string to check against.
* @param string $needle The substring to look for.
* @return bool Whether the string starts with the specified substring.
*/
function startsWith($haystack, $needle) {
return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false;
}
/**
* Tests whether a string ends with a given substring.
* @param string $whole The string to test against.
@ -4944,17 +4956,58 @@ register_module([
$content .= "<li>The id index is currently " . human_filesize(filesize($paths->idindex)) . " in size, and took " . $env->perfdata->idindex_decode_time . "ms to decode.</li>";
$wikiSize = 0;
$content .= "</ul>\n";
$content .= "<h3>Data</h3>\n";
$wikiSize = new stdClass();
$wikiSize->all = 0;
$wikiSize->images = 0;
$wikiSize->audio = 0;
$wikiSize->videos = 0;
$wikiSize->pages = 0;
$wikiSize->history = 0;
$wikiSize->indexes = 0;
$wikiSize->other = 0;
$wikiFiles = glob_recursive($env->storage_prefix . "*");
foreach($wikiFiles as $filename)
{
if(endsWith($filename, ".php")) continue; // Skip php files
$wikiSize += filesize($filename);
$extension = strtolower(substr($filename, strrpos($filename, ".") + 1));
if($extension === "php") continue; // Skip php files
$nextFilesize = filesize($filename);
$wikiSize->all += $nextFilesize;
if($extension[0] === "r") // It's a revision of a page
$wikiSize->history += $nextFilesize;
else if($extension == "md") // It's a page
$wikiSize->pages += $nextFilesize;
else if($extension == "json") // It's an index
$wikiSize->indexes += $nextFilesize;
else if(in_array($extension, [ // It's an uploaded image
"jpg", "jpeg", "png", "gif", "webp", "svg"
]))
$wikiSize->images += $nextFilesize;
else if(in_array($extension, [ "mp3", "ogg", "wav", "aac", "m4a" ])) // It's an audio file
$wikiSize->audio += $nextFilesize;
else if(in_array($extension, [ "avi", "mp4", "m4v", "webm" ])) // It's a video file
$wikiSize->videos += $nextFilesize;
else
$wikiSize->other += $nextFilesize;
}
$content .= "<li>$settings->sitename is currently " . human_filesize($wikiSize) . " in size.</li>\n";
$content .= "</ul>";
$content .= "<p>$settings->sitename is currently " . human_filesize($wikiSize->all) . " in size.</p>\n";
$content .= "<div class='stacked-bar'>
<div class='stacked-bar-part' style='flex: $wikiSize->indexes; background: hsla(191, 100%, 41%, 0.6)'>Indexes: " . human_filesize($wikiSize->indexes) . "</div>
<div class='stacked-bar-part' style='flex: $wikiSize->pages; background: hsla(112, 83%, 40%, 0.6)'>Pages: " . human_filesize($wikiSize->pages) . "</div>
<div class='stacked-bar-part' style='flex: $wikiSize->history; background: hsla(116, 84%, 25%, 0.68)'>Page History: " . human_filesize($wikiSize->history) . "</div>
<div class='stacked-bar-part' style='flex: $wikiSize->images; background: hsla(266, 88%, 47%, 0.6)'>Images: " . human_filesize($wikiSize->images) . "</div>\n";
if($wikiSize->audio > 0)
$content .= "<div class='stacked-bar-part' style='flex: $wikiSize->audio; background: hsla(237, 68%, 38%, 0.64)'>Audio: " . human_filesize($wikiSize->audio) . "</div>\n";
if($wikiSize->videos > 0)
$content .= "<div class='stacked-bar-part' style='flex: $wikiSize->videos; background: hsla(338, 79%, 54%, 0.64)'>Videos: " . human_filesize($wikiSize->videos) . "</div>\n";
if($wikiSize->other > 0)
$content .= "<div class='stacked-bar-part' style='flex: $wikiSize->other; background: hsla(62, 55%, 90%, 0.6)'>Other: " . human_filesize($wikiSize->other) . "</div>\n";
$content .= "</div>";
}
else
{

View File

@ -158,7 +158,7 @@
"author": "Starbeamrainbowlabs",
"description": "Adds a rather useful help page. Access through the 'help' action. This module also exposes help content added to Pepperminty Wiki's inbuilt invisible help section system.",
"id": "page-help",
"lastupdate": 1492429520,
"lastupdate": 1492433537,
"optional": false
},
{

View File

@ -66,17 +66,58 @@ register_module([
$content .= "<li>The id index is currently " . human_filesize(filesize($paths->idindex)) . " in size, and took " . $env->perfdata->idindex_decode_time . "ms to decode.</li>";
$wikiSize = 0;
$content .= "</ul>\n";
$content .= "<h3>Data</h3>\n";
$wikiSize = new stdClass();
$wikiSize->all = 0;
$wikiSize->images = 0;
$wikiSize->audio = 0;
$wikiSize->videos = 0;
$wikiSize->pages = 0;
$wikiSize->history = 0;
$wikiSize->indexes = 0;
$wikiSize->other = 0;
$wikiFiles = glob_recursive($env->storage_prefix . "*");
foreach($wikiFiles as $filename)
{
if(endsWith($filename, ".php")) continue; // Skip php files
$wikiSize += filesize($filename);
$extension = strtolower(substr($filename, strrpos($filename, ".") + 1));
if($extension === "php") continue; // Skip php files
$nextFilesize = filesize($filename);
$wikiSize->all += $nextFilesize;
if($extension[0] === "r") // It's a revision of a page
$wikiSize->history += $nextFilesize;
else if($extension == "md") // It's a page
$wikiSize->pages += $nextFilesize;
else if($extension == "json") // It's an index
$wikiSize->indexes += $nextFilesize;
else if(in_array($extension, [ // It's an uploaded image
"jpg", "jpeg", "png", "gif", "webp", "svg"
]))
$wikiSize->images += $nextFilesize;
else if(in_array($extension, [ "mp3", "ogg", "wav", "aac", "m4a" ])) // It's an audio file
$wikiSize->audio += $nextFilesize;
else if(in_array($extension, [ "avi", "mp4", "m4v", "webm" ])) // It's a video file
$wikiSize->videos += $nextFilesize;
else
$wikiSize->other += $nextFilesize;
}
$content .= "<li>$settings->sitename is currently " . human_filesize($wikiSize) . " in size.</li>\n";
$content .= "</ul>";
$content .= "<p>$settings->sitename is currently " . human_filesize($wikiSize->all) . " in size.</p>\n";
$content .= "<div class='stacked-bar'>
<div class='stacked-bar-part' style='flex: $wikiSize->indexes; background: hsla(191, 100%, 41%, 0.6)'>Indexes: " . human_filesize($wikiSize->indexes) . "</div>
<div class='stacked-bar-part' style='flex: $wikiSize->pages; background: hsla(112, 83%, 40%, 0.6)'>Pages: " . human_filesize($wikiSize->pages) . "</div>
<div class='stacked-bar-part' style='flex: $wikiSize->history; background: hsla(116, 84%, 25%, 0.68)'>Page History: " . human_filesize($wikiSize->history) . "</div>
<div class='stacked-bar-part' style='flex: $wikiSize->images; background: hsla(266, 88%, 47%, 0.6)'>Images: " . human_filesize($wikiSize->images) . "</div>\n";
if($wikiSize->audio > 0)
$content .= "<div class='stacked-bar-part' style='flex: $wikiSize->audio; background: hsla(237, 68%, 38%, 0.64)'>Audio: " . human_filesize($wikiSize->audio) . "</div>\n";
if($wikiSize->videos > 0)
$content .= "<div class='stacked-bar-part' style='flex: $wikiSize->videos; background: hsla(338, 79%, 54%, 0.64)'>Videos: " . human_filesize($wikiSize->videos) . "</div>\n";
if($wikiSize->other > 0)
$content .= "<div class='stacked-bar-part' style='flex: $wikiSize->other; background: hsla(62, 55%, 90%, 0.6)'>Other: " . human_filesize($wikiSize->other) . "</div>\n";
$content .= "</div>";
}
else
{

View File

@ -93,6 +93,9 @@ textarea ~ input[type=submit] { margin: 0.5rem 0; padding: 0.5rem; font-weight:
.help-section-header::after { content: "#" attr(id); float: right; color: rgba(0, 0, 0, 0.4); font-size: 0.8rem; font-weight: normal; }
.stacked-bar { display: flex; }
.stacked-bar-part { break-inside: avoid; white-space: pre; padding: 0.2em 0.3em; }
.cursor-query { cursor: help; }
summary { cursor: pointer; }