1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 16:33:00 +00:00

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; global $pageindex, $paths, $env;
if(!isset($pageinfo->history)) if(!isset($pageinfo->history))
$pageinfo->history = []; $pageinfo->history = [];
@ -1822,10 +1827,9 @@ register_module([
file_put_contents("$env->storage_prefix$ridFilename", $newsource); file_put_contents("$env->storage_prefix$ridFilename", $newsource);
// Save the edited pageindex // Save the edited pageindex
if($save_pageindex)
file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT)); file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));
}); }
}
]);
@ -2799,6 +2803,13 @@ register_module([
// should be the page name. // should be the page name.
$pageindex->$new_filename = $entry; $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 // Save the pageindex
file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT)); file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));

View file

@ -41,7 +41,7 @@
"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). Currently depends on feature-recent-changes for rendering of the history page.", "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": 1464941758, "lastupdate": 1465044619,
"optional": false "optional": false
}, },
{ {
@ -77,7 +77,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": 1465043901, "lastupdate": 1465044741,
"optional": false "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; global $pageindex, $paths, $env;
if(!isset($pageinfo->history)) if(!isset($pageinfo->history))
$pageinfo->history = []; $pageinfo->history = [];
@ -77,9 +82,8 @@ register_module([
file_put_contents("$env->storage_prefix$ridFilename", $newsource); file_put_contents("$env->storage_prefix$ridFilename", $newsource);
// Save the edited pageindex // Save the edited pageindex
if($save_pageindex)
file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT)); file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));
}); }
}
]);
?> ?>

View file

@ -153,6 +153,13 @@ register_module([
// should be the page name. // should be the page name.
$pageindex->$new_filename = $entry; $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 // Save the pageindex
file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT)); file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));