Generate history revisions upon uploading a file

This commit is contained in:
Starbeamrainbowlabs 2016-06-04 13:52:45 +01:00
parent d7b8939b83
commit ee1224bbe9
4 changed files with 90 additions and 68 deletions

View File

@ -1791,8 +1791,13 @@ register_module([
});
register_save_preprocessor(function(&$pageinfo, &$newsource, &$oldsource) {
register_save_preprocessor("history_add_revision");
}
]);
function history_add_revision(&$pageinfo, &$newsource, &$oldsource, $save_pageindex = true) {
global $pageindex, $paths, $env;
if(!isset($pageinfo->history))
$pageinfo->history = [];
@ -1822,10 +1827,9 @@ register_module([
file_put_contents("$env->storage_prefix$ridFilename", $newsource);
// Save the edited pageindex
if($save_pageindex)
file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));
});
}
]);
@ -2799,6 +2803,13 @@ register_module([
// should be the page name.
$pageindex->$new_filename = $entry;
// Generate a revision to keep the apge history up to date
if(module_exists("feature-history"))
{
$oldsource = ""; // Only variables can be passed by reference, not literals
history_add_revision($entry, $description, $oldsource, false);
}
// Save the pageindex
file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));

View File

@ -41,7 +41,7 @@
"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.",
"id": "feature-history",
"lastupdate": 1464941758,
"lastupdate": 1465044619,
"optional": false
},
{
@ -77,7 +77,7 @@
"author": "Starbeamrainbowlabs",
"description": "Adds the ability to upload files to Pepperminty Wiki. Uploaded files act as pages and have the special 'File\/' prefix.",
"id": "feature-upload",
"lastupdate": 1465043901,
"lastupdate": 1465044741,
"optional": false
},
{

View File

@ -46,8 +46,13 @@ register_module([
});
register_save_preprocessor(function(&$pageinfo, &$newsource, &$oldsource) {
register_save_preprocessor("history_add_revision");
}
]);
function history_add_revision(&$pageinfo, &$newsource, &$oldsource, $save_pageindex = true) {
global $pageindex, $paths, $env;
if(!isset($pageinfo->history))
$pageinfo->history = [];
@ -77,9 +82,8 @@ register_module([
file_put_contents("$env->storage_prefix$ridFilename", $newsource);
// Save the edited pageindex
if($save_pageindex)
file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));
});
}
]);
?>

View File

@ -153,6 +153,13 @@ register_module([
// should be the page name.
$pageindex->$new_filename = $entry;
// Generate a revision to keep the apge history up to date
if(module_exists("feature-history"))
{
$oldsource = ""; // Only variables can be passed by reference, not literals
history_add_revision($entry, $description, $oldsource, false);
}
// Save the pageindex
file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));