Implement UI for page history.

This commit is contained in:
Starbeamrainbowlabs 2016-06-03 09:16:16 +01:00
parent eb8daf2ce6
commit 51d4749915
3 changed files with 66 additions and 16 deletions

View File

@ -1743,9 +1743,9 @@ function render_sidebar($pageindex, $root_pagename = "")
register_module([ register_module([
"name" => "Page History", "name" => "Page History",
"version" => "0.1", "version" => "0.2",
"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).", "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() {
@ -1757,10 +1757,34 @@ register_module([
* ██ ██ ██ ███████ ██ ██████ ██ ██ ██ * ██ ██ ██ ███████ ██ ██████ ██ ██ ██
*/ */
add_action("history", function() { add_action("history", function() {
global $settings; global $settings, $env, $pageindex;
http_response_code(501);
exit(page_renderer::render_main("Coming soon", "<p>Page history is coming soon!</p>")); $content = "<h1>History for $env->page</h1>\n";
if(!empty($pageindex->{$env->page}->history))
{
$content .= "\t\t<ul class='page-list'>\n";
foreach($pageindex->{$env->page}->history as $revisionData)
{
// Only display edits for now
if($revisionData->type != "edit")
continue;
// The number (and the sign) of the size difference to display
$size_display = ($revisionData->sizediff > 0 ? "+" : "") . $revisionData->sizediff;
$size_display_class = $revisionData->sizediff > 0 ? "larger" : ($revisionData->sizediff < 0 ? "smaller" : "nochange");
if($revisionData->sizediff > 500 or $revisionData->sizediff < -500)
$size_display_class .= " significant";
$size_title_display = human_filesize($revisionData->newsize - $revisionData->sizediff) . " -> " . human_filesize($revisionData->newsize);
$content .= "<li>#$revisionData->rid " . render_rchange_editor($revisionData->editor) . " " . render_rchange_timestamp($revisionData->timestamp) . " <span class='cursor-query $size_display_class' title='$size_title_display'>($size_display)</span>";
}
}
else
{
$content .= "<p style='text-align: center;'><em>(None yet! Try editing this page and then coming back here.)</em></p>\n";
}
exit(page_renderer::render_main("$env->page - History - $settings->sitename", $content));
}); });
@ -1786,7 +1810,8 @@ register_module([
"rid" => $nextRid, "rid" => $nextRid,
"timestamp" => time(), "timestamp" => time(),
"filename" => $ridFilename, "filename" => $ridFilename,
"bytechange" => strlen($newsource) - strlen($oldsource), "newsize" => strlen($newsource),
"sizediff" => strlen($newsource) - strlen($oldsource),
"editor" => $pageinfo->lasteditor "editor" => $pageinfo->lasteditor
]; ];

View File

@ -37,11 +37,11 @@
}, },
{ {
"name": "Page History", "name": "Page History",
"version": "0.1", "version": "0.2",
"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).", "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": 1464939567, "lastupdate": 1464941758,
"optional": false "optional": false
}, },
{ {
@ -50,7 +50,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds recent changes. Access through the 'recent-changes' action.", "description": "Adds recent changes. Access through the 'recent-changes' action.",
"id": "feature-recent-changes", "id": "feature-recent-changes",
"lastupdate": 1459954970, "lastupdate": 1464940989,
"optional": false "optional": false
}, },
{ {

View File

@ -1,9 +1,9 @@
<?php <?php
register_module([ register_module([
"name" => "Page History", "name" => "Page History",
"version" => "0.1", "version" => "0.2",
"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).", "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() {
@ -15,10 +15,34 @@ register_module([
* ██ ██ ██ ███████ ██ ██████ ██ ██ ██ * ██ ██ ██ ███████ ██ ██████ ██ ██ ██
*/ */
add_action("history", function() { add_action("history", function() {
global $settings; global $settings, $env, $pageindex;
http_response_code(501);
exit(page_renderer::render_main("Coming soon", "<p>Page history is coming soon!</p>")); $content = "<h1>History for $env->page</h1>\n";
if(!empty($pageindex->{$env->page}->history))
{
$content .= "\t\t<ul class='page-list'>\n";
foreach($pageindex->{$env->page}->history as $revisionData)
{
// Only display edits for now
if($revisionData->type != "edit")
continue;
// The number (and the sign) of the size difference to display
$size_display = ($revisionData->sizediff > 0 ? "+" : "") . $revisionData->sizediff;
$size_display_class = $revisionData->sizediff > 0 ? "larger" : ($revisionData->sizediff < 0 ? "smaller" : "nochange");
if($revisionData->sizediff > 500 or $revisionData->sizediff < -500)
$size_display_class .= " significant";
$size_title_display = human_filesize($revisionData->newsize - $revisionData->sizediff) . " -> " . human_filesize($revisionData->newsize);
$content .= "<li>#$revisionData->rid " . render_rchange_editor($revisionData->editor) . " " . render_rchange_timestamp($revisionData->timestamp) . " <span class='cursor-query $size_display_class' title='$size_title_display'>($size_display)</span>";
}
}
else
{
$content .= "<p style='text-align: center;'><em>(None yet! Try editing this page and then coming back here.)</em></p>\n";
}
exit(page_renderer::render_main("$env->page - History - $settings->sitename", $content));
}); });
@ -44,7 +68,8 @@ register_module([
"rid" => $nextRid, "rid" => $nextRid,
"timestamp" => time(), "timestamp" => time(),
"filename" => $ridFilename, "filename" => $ridFilename,
"bytechange" => strlen($newsource) - strlen($oldsource), "newsize" => strlen($newsource),
"sizediff" => strlen($newsource) - strlen($oldsource),
"editor" => $pageinfo->lasteditor "editor" => $pageinfo->lasteditor
]; ];