Parcourir la source

Merge pull request #873 from Oldiesmann/pm_labels

+ Allow users to say why they edited a post (full edit only at the moment)
Michael Eshom il y a 11 ans
Parent
commit
1818e7e7d6

+ 6 - 1
Sources/Display.php

@@ -1305,7 +1305,8 @@ function prepareDisplayContext($reset = false)
 		'modified' => array(
 			'time' => timeformat($message['modified_time']),
 			'timestamp' => forum_time(true, $message['modified_time']),
-			'name' => $message['modified_name']
+			'name' => $message['modified_name'],
+			'reason' => $message['modified_reason']
 		),
 		'likes' => array(
 			'count' => $message['likes'],
@@ -1328,6 +1329,10 @@ function prepareDisplayContext($reset = false)
 	$output['is_message_author'] = $message['id_member'] == $user_info['id'];
 	if (!empty($output['modified']['name']))
 		$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
+	
+	// Did they give a reason for editing?
+	if (!empty($output['modified']['name']) && !empty($output['modified']['reason']))
+		$output['modified']['last_edit_text'] .= ' ' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
 
 	call_integration_hook('integrate_prepare_display_context', array(&$output, &$message));
 

+ 25 - 5
Sources/Post.php

@@ -83,7 +83,7 @@ function Post($post_errors = array())
 		$request = $smcFunc['db_query']('', '
 			SELECT
 				t.locked, IFNULL(ln.id_topic, 0) AS notify, t.is_sticky, t.id_poll, t.id_last_msg, mf.id_member,
-				t.id_first_msg, mf.subject,
+				t.id_first_msg, mf.subject, ml.modified_reason,
 				CASE WHEN ml.poster_time > ml.modified_time THEN ml.poster_time ELSE ml.modified_time END AS last_post_time
 			FROM {db_prefix}topics AS t
 				LEFT JOIN {db_prefix}log_notify AS ln ON (ln.id_topic = t.id_topic AND ln.id_member = {int:current_member})
@@ -96,7 +96,7 @@ function Post($post_errors = array())
 				'current_topic' => $topic,
 			)
 		);
-		list ($locked, $context['notify'], $sticky, $pollID, $context['topic_last_message'], $id_member_poster, $id_first_msg, $first_subject, $lastPostTime) = $smcFunc['db_fetch_row']($request);
+		list ($locked, $context['notify'], $sticky, $pollID, $context['topic_last_message'], $id_member_poster, $id_first_msg, $first_subject, $editReason, $lastPostTime) = $smcFunc['db_fetch_row']($request);
 		$smcFunc['db_free_result']($request);
 
 		// If this topic already has a poll, they sure can't add another.
@@ -605,12 +605,14 @@ function Post($post_errors = array())
 	// Editing a message...
 	elseif (isset($_REQUEST['msg']) && !empty($topic))
 	{
+		$context['editing'] = true;
+
 		$_REQUEST['msg'] = (int) $_REQUEST['msg'];
 
 		// Get the existing message. Editing.
 		$request = $smcFunc['db_query']('', '
 			SELECT
-				m.id_member, m.modified_time, m.modified_name, m.smileys_enabled, m.body,
+				m.id_member, m.modified_time, m.modified_name, m.modified_reason, m.smileys_enabled, m.body,
 				m.poster_name, m.poster_email, m.subject, m.icon, m.approved,
 				IFNULL(a.size, -1) AS filesize, a.filename, a.id_attach,
 				a.approved AS attachment_approved, t.id_member_started AS id_member_poster,
@@ -663,7 +665,8 @@ function Post($post_errors = array())
 		if (!empty($row['modified_time']))
 		{
 			$context['last_modified'] = timeformat($row['modified_time']);
-			$context['last_modified_text'] = sprintf($txt['last_edit_by'], $context['last_modified'], $row['modified_name']);
+			$context['last_modified_reason'] = censorText($row['modified_reason']);
+			$context['last_modified_text'] = sprintf($txt['last_edit_by'], $context['last_modified'], $row['modified_name']) . empty($row['modified_reason']) ? '' : ' ' . $txt['last_edit_reason'] . ': ' . $row['modified_reason'];
 		}
 
 		// Get the stuff ready for the form.
@@ -1615,11 +1618,16 @@ function Post2()
 	$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
 	$_POST['guestname'] = $smcFunc['htmlspecialchars']($_POST['guestname']);
 	$_POST['email'] = $smcFunc['htmlspecialchars']($_POST['email']);
+	$_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
 
 	// At this point, we want to make sure the subject isn't too long.
 	if ($smcFunc['strlen']($_POST['subject']) > 100)
 		$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
 
+	// Same with the "why did you edit this" text.
+	if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
+		$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
+
 	// Make the poll...
 	if (isset($_REQUEST['poll']))
 	{
@@ -1813,6 +1821,7 @@ function Post2()
 		{
 			$msgOptions['modify_time'] = time();
 			$msgOptions['modify_name'] = $user_info['name'];
+			$msgOptions['modify_reason'] = $_POST['modify_reason']; 
 		}
 
 		// This will save some time...
@@ -2638,7 +2647,7 @@ function JavaScriptModify()
 		SELECT
 			t.locked, t.num_replies, t.id_member_started, t.id_first_msg,
 			m.id_msg, m.id_member, m.poster_time, m.subject, m.smileys_enabled, m.body, m.icon,
-			m.modified_time, m.modified_name, m.approved
+			m.modified_time, m.modified_name, m.modified_reason, m.approved
 		FROM {db_prefix}messages AS m
 			INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})
 		WHERE m.id_msg = {raw:id_msg}
@@ -2744,6 +2753,15 @@ function JavaScriptModify()
 	if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
 		unset($_POST['sticky']);
 
+	if (isset($_POST['modify_reason']))
+	{
+		$_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
+
+		// Maximum number of characters.
+		if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
+			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
+	}
+
 	if (empty($post_errors))
 	{
 		$msgOptions = array(
@@ -2769,6 +2787,7 @@ function JavaScriptModify()
 			{
 				$msgOptions['modify_time'] = time();
 				$msgOptions['modify_name'] = $user_info['name'];
+				$msgOptions['modify_reason'] = isset($_POST['modify_reason']) ? $_POST['modify_reason'] : '';
 			}
 		}
 		// If nothing was changed there's no need to add an entry to the moderation log.
@@ -2782,6 +2801,7 @@ function JavaScriptModify()
 		{
 			$msgOptions['modify_time'] = $row['modified_time'];
 			$msgOptions['modify_name'] = $row['modified_name'];
+			$msgOptions['modify_reason'] = $row['modified_reason'];
 		}
 
 		// Changing the first subject updates other subjects to 'Re: new_subject'.

+ 1 - 0
Sources/Subs-Post.php

@@ -2141,6 +2141,7 @@ function modifyPost(&$msgOptions, &$topicOptions, &$posterOptions)
 	{
 		$messages_columns['modified_time'] = $msgOptions['modify_time'];
 		$messages_columns['modified_name'] = $msgOptions['modify_name'];
+		$messages_columns['modified_reason'] = $msgOptions['modify_reason'];
 		$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
 	}
 	if (isset($msgOptions['smileys_enabled']))

+ 2 - 0
Themes/default/Display.template.php

@@ -926,6 +926,8 @@ function template_main()
 							sTemplateBodyNormal: ', JavaScriptEscape('%body%'), ',
 							sTemplateSubjectNormal: ', JavaScriptEscape('<a href="' . $scripturl . '?topic=' . $context['current_topic'] . '.msg%msg_id%#msg%msg_id%" rel="nofollow">%subject%</a>'), ',
 							sTemplateTopSubject: ', JavaScriptEscape($txt['topic'] . ': %subject% &nbsp;(' . $context['num_views_text'] . ')'), ',
+							sTemplateReasonEdit: ', JavaScriptEscape('<input type="text" style="width: 90%;" name="modify_reason" value="%modify_reason%" size="80" maxlength="80" tabindex="' . $context['tabindex']++ . '" class="input_text" />)
+							sTemplateReasonNormal: ', JavaScriptEscape('%modify_text'), '
 							sErrorBorderStyle: ', JavaScriptEscape('1px solid red'), ($context['can_reply'] && !empty($options['display_quick_reply'])) ? ',
 							sFormRemoveAccessKeys: \'postmodify\'' : '', '
 						});

+ 12 - 0
Themes/default/Post.template.php

@@ -357,6 +357,18 @@ function template_main()
 	echo '
 					', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');
 
+	// If we're editing and displaying edit details, show a box where they can say why
+	if (isset($context['editing']) && $settings['show_last_edit'])
+		echo '
+					<dl>
+						<dt class="clear">
+							<span id="caption_edit_reason">', $txt['reason_for_edit'], ':</span>
+						</dt>
+						<dd>
+							<input type="text" name="modify_reason"', $context['last_modified_reason'] == '' ? '' : ' value="' . $context['modified_reason'] . '"', ' tabindex="', $context['tabindex']++, '" size="80" maxlength="80" class="input_text" />
+						</dd>
+					</dl>';
+
 	// If this message has been edited in the past - display when it was.
 	if (isset($context['last_modified']))
 		echo '

+ 10 - 2
Themes/default/Xml.template.php

@@ -51,8 +51,12 @@ function template_modifydone()
 	<message id="msg_', $context['message']['id'], '">';
 	if (empty($context['message']['errors']))
 	{
+		// Build our string of info about when and why it was modified
+		$modified = empty($context['message']['modified']['time']) ? '' : sprintf($txt['last_edit_by'], $context['message']['modified']['time'], $context['message']['modified']['name']);
+		$modified .= empty($context['message']['modified']['reason']) ? '' : sprintf($txt['last_edit_reason'], $context['message']['modified']['reason']);
+
 		echo '
-		<modified><![CDATA[', empty($context['message']['modified']['time']) ? '' : cleanXml('&#171; <em>' . sprintf($txt['last_edit_by'], $context['message']['modified']['time'], $context['message']['modified']['name']) . '</em> &#187;'), ']]></modified>
+		<modified><![CDATA[', empty($modified) ? '' : cleanXml('&#171; <em>' . $modified . '</em>&#187;'), ']]></modified>
 		<subject is_first="', $context['message']['first_in_topic'] ? '1' : '0', '"><![CDATA[', cleanXml($context['message']['subject']), ']]></subject>
 		<body><![CDATA[', $context['message']['body'], ']]></body>';
 	}
@@ -73,8 +77,12 @@ function template_modifytopicdone()
 	<message id="msg_', $context['message']['id'], '">';
 	if (empty($context['message']['errors']))
 	{
+		// Build our string of info about when and why it was modified
+		$modified = empty($context['message']['modified']['time']) ? '' : sprintf($txt['last_edit_by'], $context['message']['modified']['time'], $context['message']['modified']['name']);
+		$modified .= empty($context['message']['modified']['reason']) ? '' : sprintf($txt['last_edit_reason'], $context['message']['modified']['reason']);
+
 		echo '
-		<modified><![CDATA[', empty($context['message']['modified']['time']) ? '' : cleanXml('&#171; <em>' . sprintf($txt['last_edit_by'], $context['message']['modified']['time'], $context['message']['modified']['name']) . '</em> &#187;'), ']]></modified>';
+		<modified><![CDATA[', empty($modified) ? '' : cleanXml('&#171; <em>' . $modified . '</em>&#187;'), ']]></modified>';
 		if (!empty($context['message']['subject']))
 			echo '
 		<subject><![CDATA[', cleanXml($context['message']['subject']), ']]></subject>';

+ 2 - 0
Themes/default/languages/index.english.php

@@ -76,6 +76,7 @@ $txt['subject'] = 'Subject';
 $txt['message'] = 'Message';
 $txt['redirects'] = 'Redirects';
 $txt['quick_modify'] = 'Modify Inline';
+$txt['reason_for_edit'] = 'Reason for editing';
 
 $txt['choose_pass'] = 'Choose password';
 $txt['verify_pass'] = 'Verify password';
@@ -188,6 +189,7 @@ $txt['memberlist_searchable'] = 'Searchable list of all registered members.';
 $txt['welcome_newest_member'] = 'Please welcome %1$s, our newest member.';
 $txt['admin_center'] = 'Administration Center';
 $txt['last_edit_by'] = '<span class="lastedit">Last Edit</span>: %1$s by %2$s';
+$txt['last_edit_reason'] = '<span class="lastedit">Reason</span>: %1$s';
 $txt['notify_deactivate'] = 'Would you like to deactivate notification on this topic?';
 
 $txt['recent_posts'] = 'Recent Posts';

+ 1 - 0
other/install_2-1_mysql.sql

@@ -1364,6 +1364,7 @@ CREATE TABLE {$db_prefix}messages (
   smileys_enabled tinyint(4) NOT NULL default '1',
   modified_time int(10) unsigned NOT NULL default '0',
   modified_name varchar(255) NOT NULL default '',
+  modified_reason varchar(255) NOT NULL default '',
   body text NOT NULL,
   icon varchar(16) NOT NULL default 'xx',
   approved tinyint(3) NOT NULL default '1',

+ 1 - 0
other/install_2-1_postgresql.sql

@@ -1793,6 +1793,7 @@ CREATE TABLE {$db_prefix}messages (
   smileys_enabled smallint NOT NULL default '1',
   modified_time int NOT NULL default '0',
   modified_name varchar(255) NOT NULL,
+  modified_reason varchar(255) NOT NULL,
   body text NOT NULL,
   icon varchar(16) NOT NULL default 'xx',
   approved smallint NOT NULL default '1',

+ 1 - 0
other/install_2-1_sqlite.sql

@@ -1481,6 +1481,7 @@ CREATE TABLE {$db_prefix}messages (
   smileys_enabled smallint NOT NULL default '1',
   modified_time int NOT NULL default '0',
   modified_name varchar(255) NOT NULL,
+  modified_reason varchar(255) NOT NULL,
   body text NOT NULL,
   icon varchar(16) NOT NULL default 'xx',
   approved smallint NOT NULL default '1',

+ 1 - 0
other/install_2-1_sqlite3.sql

@@ -1481,6 +1481,7 @@ CREATE TABLE {$db_prefix}messages (
   smileys_enabled smallint NOT NULL default '1',
   modified_time int NOT NULL default '0',
   modified_name varchar(255) NOT NULL,
+  modified_reason varchar(255) NOT NULL,
   body text NOT NULL,
   icon varchar(16) NOT NULL default 'xx',
   approved smallint NOT NULL default '1',

+ 8 - 0
other/upgrade_2-1_mysql.sql

@@ -759,4 +759,12 @@ ADD COLUMN in_inbox tinyint(3) NOT NULL default '1';
 		$smcFunc['db_remove_column']('{db_prefix}pm_recipients', 'labels');
 	}
 ---}
+---#
+
+/******************************************************************************/
+--- Adding support for edit reasons
+/******************************************************************************/
+---# Adding "modified_reason" column to messages
+ALTER TABLE {$db_prefix}messages
+ADD COLUMN modified_reason varchar(255) NOT NULL;
 ---#

+ 8 - 0
other/upgrade_2-1_postgresql.sql

@@ -842,3 +842,11 @@ ADD COLUMN in_inbox smallint NOT NULL default '1';
 		$smcFunc['db_remove_column']('{db_prefix}pm_recipients', 'labels');
 	}
 }
+
+/******************************************************************************/
+--- Adding support for edit reasons
+/******************************************************************************/
+---# Adding "modified_reason" column to messages
+ALTER TABLE {$db_prefix}messages
+ADD COLUMN modified_reason varchar(255) NOT NULL default '';
+---#

+ 8 - 0
other/upgrade_2-1_sqlite.sql

@@ -819,3 +819,11 @@ ADD COLUMN in_inbox tinyint(3) NOT NULL default '1';
 		$smcFunc['db_remove_column']('{db_prefix}pm_recipients', 'labels');
 	}
 }
+
+******************************************************************************/
+--- Adding support for edit reasons
+/******************************************************************************/
+---# Adding "modified_reason" column to messages
+ALTER TABLE {$db_prefix}messages
+ADD COLUMN modified_reason varchar(255) NOT NULL default '';
+---#