1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-06 07:35:29 +02:00

Another feature: Detect when a post has been altered by someone else while editing.

Authorised by: acydburn

git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9731 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Andreas Fischer 2009-07-08 10:22:36 +00:00
parent 8750fdf3f5
commit f368e0ec09
4 changed files with 49 additions and 1 deletions

View File

@ -186,7 +186,7 @@
<li>[Feature] Ability to define minimum number of characters for posts/pms</li>
<li>[Feature] Store signature configuration options in database (Bug #45115 - Patch by rxu)</li>
<li>[Feature] Add bare-bones quick-reply editor to viewtopic.</li>
<li>[Feature] Detect when a post has been altered by someone else while editing. (Patch by bantu)</li>
</ul>
<a name="v304"></a><h3>1.ii. Changes since 3.0.4</h3>

View File

@ -944,6 +944,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id
WHERE p.topic_id = $topic_id
" . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . '
' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . '
' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . '
ORDER BY p.post_time ';
$sql .= ($mode == 'post_review') ? 'ASC' : 'DESC';
$result = $db->sql_query_limit($sql, $config['posts_per_page']);
@ -962,6 +963,12 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id
return false;
}
// Handle 'post_review_edit' like 'post_review' from now on
if ($mode == 'post_review_edit')
{
$mode = 'post_review';
}
$sql = $db->sql_build_query('SELECT', array(
'SELECT' => 'u.username, u.user_id, u.user_colour, p.*, z.friend, z.foe',

View File

@ -167,6 +167,7 @@ $lang = array_merge($lang, array(
'POST_ICON' => 'Post icon',
'POST_NORMAL' => 'Normal',
'POST_REVIEW' => 'Post review',
'POST_REVIEW_EDIT_EXPLAIN' => 'This post has been altered by another user while you were editing it. You may wish to review the current version of this post and adjust your edits.',
'POST_REVIEW_EXPLAIN' => 'At least one new post has been made to this topic. You may wish to review your post in light of this.',
'POST_STORED' => 'This message has been posted successfully.',
'POST_STORED_MOD' => 'This message has been submitted successfully, but it will need to be approved by a moderator before it is publicly viewable.',

View File

@ -370,6 +370,7 @@ else
}
$post_data['post_edit_locked'] = (isset($post_data['post_edit_locked'])) ? (int) $post_data['post_edit_locked'] : 0;
$post_data['post_subject_md5'] = (isset($post_data['post_subject']) && $mode == 'edit') ? md5($post_data['post_subject']) : '';
$post_data['post_subject'] = (in_array($mode, array('quote', 'edit'))) ? $post_data['post_subject'] : ((isset($post_data['topic_title'])) ? $post_data['topic_title'] : '');
$post_data['topic_time_limit'] = (isset($post_data['topic_time_limit'])) ? (($post_data['topic_time_limit']) ? (int) $post_data['topic_time_limit'] / 86400 : (int) $post_data['topic_time_limit']) : 0;
$post_data['poll_length'] = (!empty($post_data['poll_length'])) ? (int) $post_data['poll_length'] / 86400 : 0;
@ -704,6 +705,37 @@ if ($submit || $preview || $refresh)
// Grab md5 'checksum' of new message
$message_md5 = md5($message_parser->message);
// If editing and checksum has changed we know the post was edited while we're editing
// Notify and show user the changed post
if ($mode == 'edit' && $post_data['forum_flags'] & FORUM_FLAG_POST_REVIEW)
{
$edit_post_message_checksum = request_var('edit_post_message_checksum', '');
$edit_post_subject_checksum = request_var('edit_post_subject_checksum', '');
// $post_data['post_checksum'] is the checksum of the post submitted in the meantime
// $message_md5 is the checksum of the post we're about to submit
// $edit_post_message_checksum is the checksum of the post we're editing
// ...
// We make sure nobody else made exactly the same change
// we're about to submit by also checking $message_md5 != $post_data['post_checksum']
if (($edit_post_message_checksum !== '' && $edit_post_message_checksum != $post_data['post_checksum'] && $message_md5 != $post_data['post_checksum'])
|| ($edit_post_subject_checksum !== '' && $edit_post_subject_checksum != $post_data['post_subject_md5'] && md5($post_data['post_subject']) != $post_data['post_subject_md5']))
{
if (topic_review($topic_id, $forum_id, 'post_review_edit', $post_id))
{
$template->assign_vars(array(
'S_POST_REVIEW' => true,
'L_POST_REVIEW_EXPLAIN' => $user->lang['POST_REVIEW_EDIT_EXPLAIN'],
));
}
$submit = false;
$refresh = true;
}
}
// Check checksum ... don't re-parse message if the same
$update_message = ($mode != 'edit' || $message_md5 != $post_data['post_checksum'] || $status_switch || strlen($post_data['bbcode_uid']) < BBCODE_UID_LEN) ? true : false;
@ -1261,6 +1293,14 @@ $s_hidden_fields = ($mode == 'reply' || $mode == 'quote') ? '<input type="hidden
$s_hidden_fields .= '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
$s_hidden_fields .= ($draft_id || isset($_REQUEST['draft_loaded'])) ? '<input type="hidden" name="draft_loaded" value="' . request_var('draft_loaded', $draft_id) . '" />' : '';
if ($mode == 'edit')
{
$s_hidden_fields .= build_hidden_fields(array(
'edit_post_message_checksum' => $post_data['post_checksum'],
'edit_post_subject_checksum' => $post_data['post_subject_md5'],
));
}
// Add the confirm id/code pair to the hidden fields, else an error is displayed on next submit/preview
if (isset($captcha) && $captcha->is_solved() !== false)
{