mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 16:33:00 +00:00
Bugfix: Recent changes break when the number of changes reach $settings->max_recent_changes. Fixes #104.
This commit is contained in:
parent
2dd2c26cb5
commit
673fe033ee
5 changed files with 87 additions and 80 deletions
|
@ -46,6 +46,7 @@
|
||||||
- Fixed pressing the edit button on pages that have a single quote in their name
|
- Fixed pressing the edit button on pages that have a single quote in their name
|
||||||
- Fixed a spelling mistake on the file preview page - I'm sure I fixed that before...!
|
- Fixed a spelling mistake on the file preview page - I'm sure I fixed that before...!
|
||||||
- Fixed an issue whereby the search index wouldn't update if your pages contained special characters
|
- Fixed an issue whereby the search index wouldn't update if your pages contained special characters
|
||||||
|
- Fixed an issue with the recent changes list not updating when the number of recently changes reached setings.max_recent_changes (#104)
|
||||||
|
|
||||||
## v0.12
|
## v0.12
|
||||||
|
|
||||||
|
|
|
@ -1903,7 +1903,7 @@ register_module([
|
||||||
$content .= "<p><em>None yet! Try making a few changes and then check back here.</em></p>\n";
|
$content .= "<p><em>None yet! Try making a few changes and then check back here.</em></p>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
echo(page_renderer::render("Recent Changes - $settings->sitename", $content));
|
exit(page_renderer::render("Recent Changes - $settings->sitename", $content));
|
||||||
});
|
});
|
||||||
|
|
||||||
register_save_preprocessor(function(&$pageinfo, &$newsource, &$oldsource) {
|
register_save_preprocessor(function(&$pageinfo, &$newsource, &$oldsource) {
|
||||||
|
@ -1948,7 +1948,7 @@ function add_recent_change($rchange)
|
||||||
// Limit the number of entries in the recent changes file if we've
|
// Limit the number of entries in the recent changes file if we've
|
||||||
// been asked to.
|
// been asked to.
|
||||||
if(isset($settings->max_recent_changes))
|
if(isset($settings->max_recent_changes))
|
||||||
$recentchanges = array_slice($recentchanges, -$settings->max_recent_changes);
|
$recentchanges = array_slice($recentchanges, 0, $settings->max_recent_changes);
|
||||||
|
|
||||||
// Save the recent changes file back to disk
|
// Save the recent changes file back to disk
|
||||||
file_put_contents($paths->recentchanges, json_encode($recentchanges, JSON_PRETTY_PRINT));
|
file_put_contents($paths->recentchanges, json_encode($recentchanges, JSON_PRETTY_PRINT));
|
||||||
|
@ -3788,40 +3788,42 @@ register_module([
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for edit conflicts
|
// Check for edit conflicts
|
||||||
$existing_content_hash = sha1_file($env->storage_prefix . $pageindex->{$env->page}->filename);
|
if(!empty($pageindex->{$env->page}) && file_exists($env->storage_prefix . $pageindex->{$env->page}->filename))
|
||||||
if(isset($_POST["prev-content-hash"]) and
|
|
||||||
$existing_content_hash != $_POST["prev-content-hash"])
|
|
||||||
{
|
{
|
||||||
$existingPageData = htmlentities(file_get_contents($env->storage_prefix . $env->storage_prefix . $pageindex->{$env->page}->filename));
|
$existing_content_hash = sha1_file($env->storage_prefix . $pageindex->{$env->page}->filename);
|
||||||
// An edit conflict has occurred! We should get the user to fix it.
|
if(isset($_POST["prev-content-hash"]) and
|
||||||
$content = "<h1>Resolving edit conflict - $env->page</h1>";
|
$existing_content_hash != $_POST["prev-content-hash"])
|
||||||
if(!$env->is_logged_in and $settings->anonedits)
|
|
||||||
{
|
{
|
||||||
$content .= "<p><strong>Warning: You are not logged in! Your IP address <em>may</em> be recorded.</strong></p>";
|
$existingPageData = htmlentities(file_get_contents($env->storage_prefix . $env->storage_prefix . $pageindex->{$env->page}->filename));
|
||||||
}
|
// An edit conflict has occurred! We should get the user to fix it.
|
||||||
$content .= "<p>An edit conflict has arisen because someone else has saved an edit to $env->page since you started editing it. Both texts are shown below, along the differences between the 2 conflicting revisions. To continue, please merge your changes with the existing content. Note that only the text in the existing content box will be kept when you press the \"Resolve Conflict\" button at the bottom of the page.</p>
|
$content = "<h1>Resolving edit conflict - $env->page</h1>";
|
||||||
|
if(!$env->is_logged_in and $settings->anonedits)
|
||||||
|
{
|
||||||
|
$content .= "<p><strong>Warning: You are not logged in! Your IP address <em>may</em> be recorded.</strong></p>";
|
||||||
|
}
|
||||||
|
$content .= "<p>An edit conflict has arisen because someone else has saved an edit to $env->page since you started editing it. Both texts are shown below, along the differences between the 2 conflicting revisions. To continue, please merge your changes with the existing content. Note that only the text in the existing content box will be kept when you press the \"Resolve Conflict\" button at the bottom of the page.</p>
|
||||||
|
|
||||||
<form method='post' action='index.php?action=save&page=" . rawurlencode($page) . "&action=save' class='editform'>
|
<form method='post' action='index.php?action=save&page=" . rawurlencode($page) . "&action=save' class='editform'>
|
||||||
<h2>Existing content</h2>
|
<h2>Existing content</h2>
|
||||||
<textarea id='original-content' name='content' autofocus tabindex='1'>$existingPageData</textarea>
|
<textarea id='original-content' name='content' autofocus tabindex='1'>$existingPageData</textarea>
|
||||||
|
|
||||||
<h2>Differences</h2>
|
<h2>Differences</h2>
|
||||||
<div id='highlighted-diff' class='highlighted-diff'></div>
|
<div id='highlighted-diff' class='highlighted-diff'></div>
|
||||||
<!--<pre class='highlighted-diff-wrapper'><code id='highlighted-diff'></code></pre>-->
|
<!--<pre class='highlighted-diff-wrapper'><code id='highlighted-diff'></code></pre>-->
|
||||||
|
|
||||||
<h2>Your content</h2>
|
<h2>Your content</h2>
|
||||||
<textarea id='new-content'>$pagedata</textarea>
|
<textarea id='new-content'>$pagedata</textarea>
|
||||||
<input type='text' name='tags' value='" . $_POST["tags"] . "' placeholder='Enter some tags for the page here. Separate them with commas.' title='Enter some tags for the page here. Separate them with commas.' tabindex='2' />
|
<input type='text' name='tags' value='" . $_POST["tags"] . "' placeholder='Enter some tags for the page here. Separate them with commas.' title='Enter some tags for the page here. Separate them with commas.' tabindex='2' />
|
||||||
<p class='editing_message'>$settings->editing_message</p>
|
<p class='editing_message'>$settings->editing_message</p>
|
||||||
<input name='submit-edit' type='submit' value='Resolve Conflict' tabindex='3' />
|
<input name='submit-edit' type='submit' value='Resolve Conflict' tabindex='3' />
|
||||||
</form>";
|
</form>";
|
||||||
|
|
||||||
// Insert a reference to jsdiff to generate the diffs
|
// Insert a reference to jsdiff to generate the diffs
|
||||||
$diffScript = <<<'DIFFSCRIPT'
|
$diffScript = <<<'DIFFSCRIPT'
|
||||||
window.addEventListener("load", function(event) {
|
window.addEventListener("load", function(event) {
|
||||||
var destination = document.getElementById("highlighted-diff"),
|
var destination = document.getElementById("highlighted-diff"),
|
||||||
diff = JsDiff.diffWords(document.getElementById("original-content").value, document.getElementById("new-content").value),
|
diff = JsDiff.diffWords(document.getElementById("original-content").value, document.getElementById("new-content").value),
|
||||||
output = "";
|
output = "";
|
||||||
diff.forEach(function(change) {
|
diff.forEach(function(change) {
|
||||||
var classes = "token";
|
var classes = "token";
|
||||||
if(change.added) classes += " diff-added";
|
if(change.added) classes += " diff-added";
|
||||||
|
@ -3832,10 +3834,11 @@ window.addEventListener("load", function(event) {
|
||||||
});
|
});
|
||||||
DIFFSCRIPT;
|
DIFFSCRIPT;
|
||||||
|
|
||||||
$content .= "\n<script src='https://cdnjs.cloudflare.com/ajax/libs/jsdiff/2.2.2/diff.min.js'></script>
|
$content .= "\n<script src='https://cdnjs.cloudflare.com/ajax/libs/jsdiff/2.2.2/diff.min.js'></script>
|
||||||
<script>$diffScript</script>\n";
|
<script>$diffScript</script>\n";
|
||||||
|
|
||||||
exit(page_renderer::render_main("Edit Conflict - $env->page - $settings->sitename", $content));
|
exit(page_renderer::render_main("Edit Conflict - $env->page - $settings->sitename", $content));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----~~~==~~~-----
|
// -----~~~==~~~-----
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
"author": "Starbeamrainbowlabs",
|
"author": "Starbeamrainbowlabs",
|
||||||
"description": "Adds a 'raw' action that shows you the raw source of a page.",
|
"description": "Adds a 'raw' action that shows you the raw source of a page.",
|
||||||
"id": "action-raw",
|
"id": "action-raw",
|
||||||
"lastupdate": 1476812825,
|
"lastupdate": 1476813024,
|
||||||
"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": 1476809773,
|
"lastupdate": 1476813024,
|
||||||
"optional": false
|
"optional": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -68,7 +68,7 @@
|
||||||
"author": "Starbeamrainbowlabs",
|
"author": "Starbeamrainbowlabs",
|
||||||
"description": "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
|
"description": "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
|
||||||
"id": "feature-search",
|
"id": "feature-search",
|
||||||
"lastupdate": 1476809773,
|
"lastupdate": 1476813024,
|
||||||
"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": 1476809773,
|
"lastupdate": 1476813024,
|
||||||
"optional": false
|
"optional": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -113,7 +113,7 @@
|
||||||
"author": "Starbeamrainbowlabs",
|
"author": "Starbeamrainbowlabs",
|
||||||
"description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
|
"description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
|
||||||
"id": "page-edit",
|
"id": "page-edit",
|
||||||
"lastupdate": 1476809773,
|
"lastupdate": 1476813024,
|
||||||
"optional": false
|
"optional": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -167,7 +167,7 @@
|
||||||
"author": "Starbeamrainbowlabs",
|
"author": "Starbeamrainbowlabs",
|
||||||
"description": "Adds an action to allow administrators to move pages.",
|
"description": "Adds an action to allow administrators to move pages.",
|
||||||
"id": "page-move",
|
"id": "page-move",
|
||||||
"lastupdate": 1476809773,
|
"lastupdate": 1476813024,
|
||||||
"optional": false
|
"optional": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -185,7 +185,7 @@
|
||||||
"author": "Starbeamrainbowlabs",
|
"author": "Starbeamrainbowlabs",
|
||||||
"description": "Allows you to view pages. You really should include this one.",
|
"description": "Allows you to view pages. You really should include this one.",
|
||||||
"id": "page-view",
|
"id": "page-view",
|
||||||
"lastupdate": 1476812765,
|
"lastupdate": 1476813024,
|
||||||
"optional": false
|
"optional": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -203,7 +203,7 @@
|
||||||
"author": "Emanuil Rusev & Starbeamrainbowlabs",
|
"author": "Emanuil Rusev & Starbeamrainbowlabs",
|
||||||
"description": "An upgraded (now default!) parser based on Emanuil Rusev's Parsedown Extra PHP library (https:\/\/github.com\/erusev\/parsedown-extra), which is licensed MIT. Please be careful, as this module adds some weight to your installation, and also *requires* write access to the disk on first load.",
|
"description": "An upgraded (now default!) parser based on Emanuil Rusev's Parsedown Extra PHP library (https:\/\/github.com\/erusev\/parsedown-extra), which is licensed MIT. Please be careful, as this module adds some weight to your installation, and also *requires* write access to the disk on first load.",
|
||||||
"id": "parser-parsedown",
|
"id": "parser-parsedown",
|
||||||
"lastupdate": 1476809773,
|
"lastupdate": 1476813024,
|
||||||
"optional": false
|
"optional": false
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -50,7 +50,7 @@ register_module([
|
||||||
$content .= "<p><em>None yet! Try making a few changes and then check back here.</em></p>\n";
|
$content .= "<p><em>None yet! Try making a few changes and then check back here.</em></p>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
echo(page_renderer::render("Recent Changes - $settings->sitename", $content));
|
exit(page_renderer::render("Recent Changes - $settings->sitename", $content));
|
||||||
});
|
});
|
||||||
|
|
||||||
register_save_preprocessor(function(&$pageinfo, &$newsource, &$oldsource) {
|
register_save_preprocessor(function(&$pageinfo, &$newsource, &$oldsource) {
|
||||||
|
@ -95,7 +95,7 @@ function add_recent_change($rchange)
|
||||||
// Limit the number of entries in the recent changes file if we've
|
// Limit the number of entries in the recent changes file if we've
|
||||||
// been asked to.
|
// been asked to.
|
||||||
if(isset($settings->max_recent_changes))
|
if(isset($settings->max_recent_changes))
|
||||||
$recentchanges = array_slice($recentchanges, -$settings->max_recent_changes);
|
$recentchanges = array_slice($recentchanges, 0, $settings->max_recent_changes);
|
||||||
|
|
||||||
// Save the recent changes file back to disk
|
// Save the recent changes file back to disk
|
||||||
file_put_contents($paths->recentchanges, json_encode($recentchanges, JSON_PRETTY_PRINT));
|
file_put_contents($paths->recentchanges, json_encode($recentchanges, JSON_PRETTY_PRINT));
|
||||||
|
|
|
@ -183,40 +183,42 @@ register_module([
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for edit conflicts
|
// Check for edit conflicts
|
||||||
$existing_content_hash = sha1_file($env->storage_prefix . $pageindex->{$env->page}->filename);
|
if(!empty($pageindex->{$env->page}) && file_exists($env->storage_prefix . $pageindex->{$env->page}->filename))
|
||||||
if(isset($_POST["prev-content-hash"]) and
|
|
||||||
$existing_content_hash != $_POST["prev-content-hash"])
|
|
||||||
{
|
{
|
||||||
$existingPageData = htmlentities(file_get_contents($env->storage_prefix . $env->storage_prefix . $pageindex->{$env->page}->filename));
|
$existing_content_hash = sha1_file($env->storage_prefix . $pageindex->{$env->page}->filename);
|
||||||
// An edit conflict has occurred! We should get the user to fix it.
|
if(isset($_POST["prev-content-hash"]) and
|
||||||
$content = "<h1>Resolving edit conflict - $env->page</h1>";
|
$existing_content_hash != $_POST["prev-content-hash"])
|
||||||
if(!$env->is_logged_in and $settings->anonedits)
|
|
||||||
{
|
{
|
||||||
$content .= "<p><strong>Warning: You are not logged in! Your IP address <em>may</em> be recorded.</strong></p>";
|
$existingPageData = htmlentities(file_get_contents($env->storage_prefix . $env->storage_prefix . $pageindex->{$env->page}->filename));
|
||||||
}
|
// An edit conflict has occurred! We should get the user to fix it.
|
||||||
$content .= "<p>An edit conflict has arisen because someone else has saved an edit to $env->page since you started editing it. Both texts are shown below, along the differences between the 2 conflicting revisions. To continue, please merge your changes with the existing content. Note that only the text in the existing content box will be kept when you press the \"Resolve Conflict\" button at the bottom of the page.</p>
|
$content = "<h1>Resolving edit conflict - $env->page</h1>";
|
||||||
|
if(!$env->is_logged_in and $settings->anonedits)
|
||||||
|
{
|
||||||
|
$content .= "<p><strong>Warning: You are not logged in! Your IP address <em>may</em> be recorded.</strong></p>";
|
||||||
|
}
|
||||||
|
$content .= "<p>An edit conflict has arisen because someone else has saved an edit to $env->page since you started editing it. Both texts are shown below, along the differences between the 2 conflicting revisions. To continue, please merge your changes with the existing content. Note that only the text in the existing content box will be kept when you press the \"Resolve Conflict\" button at the bottom of the page.</p>
|
||||||
|
|
||||||
<form method='post' action='index.php?action=save&page=" . rawurlencode($page) . "&action=save' class='editform'>
|
<form method='post' action='index.php?action=save&page=" . rawurlencode($page) . "&action=save' class='editform'>
|
||||||
<h2>Existing content</h2>
|
<h2>Existing content</h2>
|
||||||
<textarea id='original-content' name='content' autofocus tabindex='1'>$existingPageData</textarea>
|
<textarea id='original-content' name='content' autofocus tabindex='1'>$existingPageData</textarea>
|
||||||
|
|
||||||
<h2>Differences</h2>
|
<h2>Differences</h2>
|
||||||
<div id='highlighted-diff' class='highlighted-diff'></div>
|
<div id='highlighted-diff' class='highlighted-diff'></div>
|
||||||
<!--<pre class='highlighted-diff-wrapper'><code id='highlighted-diff'></code></pre>-->
|
<!--<pre class='highlighted-diff-wrapper'><code id='highlighted-diff'></code></pre>-->
|
||||||
|
|
||||||
<h2>Your content</h2>
|
<h2>Your content</h2>
|
||||||
<textarea id='new-content'>$pagedata</textarea>
|
<textarea id='new-content'>$pagedata</textarea>
|
||||||
<input type='text' name='tags' value='" . $_POST["tags"] . "' placeholder='Enter some tags for the page here. Separate them with commas.' title='Enter some tags for the page here. Separate them with commas.' tabindex='2' />
|
<input type='text' name='tags' value='" . $_POST["tags"] . "' placeholder='Enter some tags for the page here. Separate them with commas.' title='Enter some tags for the page here. Separate them with commas.' tabindex='2' />
|
||||||
<p class='editing_message'>$settings->editing_message</p>
|
<p class='editing_message'>$settings->editing_message</p>
|
||||||
<input name='submit-edit' type='submit' value='Resolve Conflict' tabindex='3' />
|
<input name='submit-edit' type='submit' value='Resolve Conflict' tabindex='3' />
|
||||||
</form>";
|
</form>";
|
||||||
|
|
||||||
// Insert a reference to jsdiff to generate the diffs
|
// Insert a reference to jsdiff to generate the diffs
|
||||||
$diffScript = <<<'DIFFSCRIPT'
|
$diffScript = <<<'DIFFSCRIPT'
|
||||||
window.addEventListener("load", function(event) {
|
window.addEventListener("load", function(event) {
|
||||||
var destination = document.getElementById("highlighted-diff"),
|
var destination = document.getElementById("highlighted-diff"),
|
||||||
diff = JsDiff.diffWords(document.getElementById("original-content").value, document.getElementById("new-content").value),
|
diff = JsDiff.diffWords(document.getElementById("original-content").value, document.getElementById("new-content").value),
|
||||||
output = "";
|
output = "";
|
||||||
diff.forEach(function(change) {
|
diff.forEach(function(change) {
|
||||||
var classes = "token";
|
var classes = "token";
|
||||||
if(change.added) classes += " diff-added";
|
if(change.added) classes += " diff-added";
|
||||||
|
@ -227,10 +229,11 @@ window.addEventListener("load", function(event) {
|
||||||
});
|
});
|
||||||
DIFFSCRIPT;
|
DIFFSCRIPT;
|
||||||
|
|
||||||
$content .= "\n<script src='https://cdnjs.cloudflare.com/ajax/libs/jsdiff/2.2.2/diff.min.js'></script>
|
$content .= "\n<script src='https://cdnjs.cloudflare.com/ajax/libs/jsdiff/2.2.2/diff.min.js'></script>
|
||||||
<script>$diffScript</script>\n";
|
<script>$diffScript</script>\n";
|
||||||
|
|
||||||
exit(page_renderer::render_main("Edit Conflict - $env->page - $settings->sitename", $content));
|
exit(page_renderer::render_main("Edit Conflict - $env->page - $settings->sitename", $content));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----~~~==~~~-----
|
// -----~~~==~~~-----
|
||||||
|
|
Loading…
Reference in a new issue