mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 16:33:00 +00:00
Implement conflict resolution.
This commit is contained in:
parent
5b067fefec
commit
3961c4977a
3 changed files with 57 additions and 3 deletions
|
@ -3276,10 +3276,11 @@ register_module([
|
||||||
$content .= "<p><strong>Warning: You are not logged in! Your IP address <em>may</em> be recorded.</strong></p>";
|
$content .= "<p><strong>Warning: You are not logged in! Your IP address <em>may</em> be recorded.</strong></p>";
|
||||||
}
|
}
|
||||||
$content .= "<form method='post' action='index.php?action=save&page=" . rawurlencode($page) . "&action=save' class='editform'>
|
$content .= "<form method='post' action='index.php?action=save&page=" . rawurlencode($page) . "&action=save' class='editform'>
|
||||||
|
<input type='hidden' name='prev-content-hash' value='" . sha1($pagetext) . "' />
|
||||||
<textarea name='content' autofocus tabindex='1'>$pagetext</textarea>
|
<textarea name='content' autofocus tabindex='1'>$pagetext</textarea>
|
||||||
<input type='text' name='tags' value='$page_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='$page_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 type='submit' value='Save Page' tabindex='3' />
|
<input name='submit-edit' type='submit' value='Save Page' tabindex='3' />
|
||||||
</form>";
|
</form>";
|
||||||
exit(page_renderer::render_main("$title - $settings->sitename", $content));
|
exit(page_renderer::render_main("$title - $settings->sitename", $content));
|
||||||
});
|
});
|
||||||
|
@ -3294,6 +3295,7 @@ register_module([
|
||||||
*/
|
*/
|
||||||
add_action("save", function() {
|
add_action("save", function() {
|
||||||
global $pageindex, $settings, $env, $save_preprocessors, $paths;
|
global $pageindex, $settings, $env, $save_preprocessors, $paths;
|
||||||
|
|
||||||
if(!$settings->editing)
|
if(!$settings->editing)
|
||||||
{
|
{
|
||||||
header("location: index.php?page=$env->page");
|
header("location: index.php?page=$env->page");
|
||||||
|
@ -3355,6 +3357,31 @@ register_module([
|
||||||
$tag = trim($tag);
|
$tag = trim($tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for edit conflicts
|
||||||
|
$existing_content_hash = sha1_file($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));
|
||||||
|
// An edit conflict has occurred! We should get the user to fix it.
|
||||||
|
$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. To continue, please merge your changes with the existing content. Note that only the text in the existing content box will be saved.</p>
|
||||||
|
<form method='post' action='index.php?action=save&page=" . rawurlencode($page) . "&action=save' class='editform'>
|
||||||
|
<h2>Existing content</h2>
|
||||||
|
<textarea name='content' autofocus tabindex='1'>$existingPageData</textarea>
|
||||||
|
<h2>Your content</h2>
|
||||||
|
<textarea>$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' />
|
||||||
|
<p class='editing_message'>$settings->editing_message</p>
|
||||||
|
<input name='submit-edit' type='submit' value='Resolve Conflict' tabindex='3' />
|
||||||
|
</form>";
|
||||||
|
exit(page_renderer::render_main("Edit Conflict - $env->page - $settings->sitename", $content));
|
||||||
|
}
|
||||||
|
|
||||||
// Update the inverted search index
|
// Update the inverted search index
|
||||||
|
|
||||||
// Construct an index for the old and new page content
|
// Construct an index for the old and new page content
|
||||||
|
|
|
@ -104,7 +104,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": 1460196076,
|
"lastupdate": 1460201129,
|
||||||
"optional": false
|
"optional": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -71,10 +71,11 @@ register_module([
|
||||||
$content .= "<p><strong>Warning: You are not logged in! Your IP address <em>may</em> be recorded.</strong></p>";
|
$content .= "<p><strong>Warning: You are not logged in! Your IP address <em>may</em> be recorded.</strong></p>";
|
||||||
}
|
}
|
||||||
$content .= "<form method='post' action='index.php?action=save&page=" . rawurlencode($page) . "&action=save' class='editform'>
|
$content .= "<form method='post' action='index.php?action=save&page=" . rawurlencode($page) . "&action=save' class='editform'>
|
||||||
|
<input type='hidden' name='prev-content-hash' value='" . sha1($pagetext) . "' />
|
||||||
<textarea name='content' autofocus tabindex='1'>$pagetext</textarea>
|
<textarea name='content' autofocus tabindex='1'>$pagetext</textarea>
|
||||||
<input type='text' name='tags' value='$page_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='$page_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 type='submit' value='Save Page' tabindex='3' />
|
<input name='submit-edit' type='submit' value='Save Page' tabindex='3' />
|
||||||
</form>";
|
</form>";
|
||||||
exit(page_renderer::render_main("$title - $settings->sitename", $content));
|
exit(page_renderer::render_main("$title - $settings->sitename", $content));
|
||||||
});
|
});
|
||||||
|
@ -89,6 +90,7 @@ register_module([
|
||||||
*/
|
*/
|
||||||
add_action("save", function() {
|
add_action("save", function() {
|
||||||
global $pageindex, $settings, $env, $save_preprocessors, $paths;
|
global $pageindex, $settings, $env, $save_preprocessors, $paths;
|
||||||
|
|
||||||
if(!$settings->editing)
|
if(!$settings->editing)
|
||||||
{
|
{
|
||||||
header("location: index.php?page=$env->page");
|
header("location: index.php?page=$env->page");
|
||||||
|
@ -150,6 +152,31 @@ register_module([
|
||||||
$tag = trim($tag);
|
$tag = trim($tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for edit conflicts
|
||||||
|
$existing_content_hash = sha1_file($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));
|
||||||
|
// An edit conflict has occurred! We should get the user to fix it.
|
||||||
|
$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. To continue, please merge your changes with the existing content. Note that only the text in the existing content box will be saved.</p>
|
||||||
|
<form method='post' action='index.php?action=save&page=" . rawurlencode($page) . "&action=save' class='editform'>
|
||||||
|
<h2>Existing content</h2>
|
||||||
|
<textarea name='content' autofocus tabindex='1'>$existingPageData</textarea>
|
||||||
|
<h2>Your content</h2>
|
||||||
|
<textarea>$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' />
|
||||||
|
<p class='editing_message'>$settings->editing_message</p>
|
||||||
|
<input name='submit-edit' type='submit' value='Resolve Conflict' tabindex='3' />
|
||||||
|
</form>";
|
||||||
|
exit(page_renderer::render_main("Edit Conflict - $env->page - $settings->sitename", $content));
|
||||||
|
}
|
||||||
|
|
||||||
// Update the inverted search index
|
// Update the inverted search index
|
||||||
|
|
||||||
// Construct an index for the old and new page content
|
// Construct an index for the old and new page content
|
||||||
|
|
Loading…
Reference in a new issue