mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-12-22 13:45:02 +00:00
Generate history revisions upon uploading a file
This commit is contained in:
parent
d7b8939b83
commit
ee1224bbe9
4 changed files with 90 additions and 68 deletions
|
@ -1791,42 +1791,46 @@ register_module([
|
|||
});
|
||||
|
||||
|
||||
register_save_preprocessor(function(&$pageinfo, &$newsource, &$oldsource) {
|
||||
global $pageindex, $paths, $env;
|
||||
if(!isset($pageinfo->history))
|
||||
$pageinfo->history = [];
|
||||
|
||||
// Save the *new source* as a revision
|
||||
// This results in 2 copies of the current source, but this is ok
|
||||
// since any time someone changes something, it create a new
|
||||
// revision
|
||||
// Note that we can't save the old source here because we'd have no
|
||||
// clue who edited it since $pageinfo has already been updated by
|
||||
// this point
|
||||
|
||||
// TODO Store tag changes here
|
||||
$nextRid = count($pageinfo->history); // The next revision id
|
||||
$ridFilename = "$pageinfo->filename.r$nextRid";
|
||||
// Insert a new entry into the history
|
||||
$pageinfo->history[] = [
|
||||
"type" => "edit", // We might want to store other types later (e.g. page moves)
|
||||
"rid" => $nextRid,
|
||||
"timestamp" => time(),
|
||||
"filename" => $ridFilename,
|
||||
"newsize" => strlen($newsource),
|
||||
"sizediff" => strlen($newsource) - strlen($oldsource),
|
||||
"editor" => $pageinfo->lasteditor
|
||||
];
|
||||
|
||||
// Save the new source as a revision
|
||||
file_put_contents("$env->storage_prefix$ridFilename", $newsource);
|
||||
|
||||
// Save the edited pageindex
|
||||
file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));
|
||||
});
|
||||
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 = [];
|
||||
|
||||
// Save the *new source* as a revision
|
||||
// This results in 2 copies of the current source, but this is ok
|
||||
// since any time someone changes something, it create a new
|
||||
// revision
|
||||
// Note that we can't save the old source here because we'd have no
|
||||
// clue who edited it since $pageinfo has already been updated by
|
||||
// this point
|
||||
|
||||
// TODO Store tag changes here
|
||||
$nextRid = count($pageinfo->history); // The next revision id
|
||||
$ridFilename = "$pageinfo->filename.r$nextRid";
|
||||
// Insert a new entry into the history
|
||||
$pageinfo->history[] = [
|
||||
"type" => "edit", // We might want to store other types later (e.g. page moves)
|
||||
"rid" => $nextRid,
|
||||
"timestamp" => time(),
|
||||
"filename" => $ridFilename,
|
||||
"newsize" => strlen($newsource),
|
||||
"sizediff" => strlen($newsource) - strlen($oldsource),
|
||||
"editor" => $pageinfo->lasteditor
|
||||
];
|
||||
|
||||
// Save the new source as a revision
|
||||
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));
|
||||
|
||||
|
|
|
@ -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
|
||||
},
|
||||
{
|
||||
|
|
|
@ -46,40 +46,44 @@ register_module([
|
|||
});
|
||||
|
||||
|
||||
register_save_preprocessor(function(&$pageinfo, &$newsource, &$oldsource) {
|
||||
global $pageindex, $paths, $env;
|
||||
if(!isset($pageinfo->history))
|
||||
$pageinfo->history = [];
|
||||
|
||||
// Save the *new source* as a revision
|
||||
// This results in 2 copies of the current source, but this is ok
|
||||
// since any time someone changes something, it create a new
|
||||
// revision
|
||||
// Note that we can't save the old source here because we'd have no
|
||||
// clue who edited it since $pageinfo has already been updated by
|
||||
// this point
|
||||
|
||||
// TODO Store tag changes here
|
||||
$nextRid = count($pageinfo->history); // The next revision id
|
||||
$ridFilename = "$pageinfo->filename.r$nextRid";
|
||||
// Insert a new entry into the history
|
||||
$pageinfo->history[] = [
|
||||
"type" => "edit", // We might want to store other types later (e.g. page moves)
|
||||
"rid" => $nextRid,
|
||||
"timestamp" => time(),
|
||||
"filename" => $ridFilename,
|
||||
"newsize" => strlen($newsource),
|
||||
"sizediff" => strlen($newsource) - strlen($oldsource),
|
||||
"editor" => $pageinfo->lasteditor
|
||||
];
|
||||
|
||||
// Save the new source as a revision
|
||||
file_put_contents("$env->storage_prefix$ridFilename", $newsource);
|
||||
|
||||
// Save the edited pageindex
|
||||
file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));
|
||||
});
|
||||
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 = [];
|
||||
|
||||
// Save the *new source* as a revision
|
||||
// This results in 2 copies of the current source, but this is ok
|
||||
// since any time someone changes something, it create a new
|
||||
// revision
|
||||
// Note that we can't save the old source here because we'd have no
|
||||
// clue who edited it since $pageinfo has already been updated by
|
||||
// this point
|
||||
|
||||
// TODO Store tag changes here
|
||||
$nextRid = count($pageinfo->history); // The next revision id
|
||||
$ridFilename = "$pageinfo->filename.r$nextRid";
|
||||
// Insert a new entry into the history
|
||||
$pageinfo->history[] = [
|
||||
"type" => "edit", // We might want to store other types later (e.g. page moves)
|
||||
"rid" => $nextRid,
|
||||
"timestamp" => time(),
|
||||
"filename" => $ridFilename,
|
||||
"newsize" => strlen($newsource),
|
||||
"sizediff" => strlen($newsource) - strlen($oldsource),
|
||||
"editor" => $pageinfo->lasteditor
|
||||
];
|
||||
|
||||
// Save the new source as a revision
|
||||
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));
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
Loading…
Reference in a new issue