aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/includes/class_content_visibility.php42
-rw-r--r--phpBB/includes/functions_posting.php8
-rw-r--r--phpBB/includes/mcp/mcp_queue.php3
-rw-r--r--phpBB/install/schemas/schema_data.sql4
-rw-r--r--phpBB/posting.php50
-rw-r--r--phpBB/styles/prosilver/template/viewtopic_body.html2
-rw-r--r--phpBB/viewtopic.php1
-rw-r--r--tests/class_visibility/class_visibility_test.php13
8 files changed, 98 insertions, 25 deletions
diff --git a/phpBB/includes/class_content_visibility.php b/phpBB/includes/class_content_visibility.php
index c7c9586e50..93643773d9 100644
--- a/phpBB/includes/class_content_visibility.php
+++ b/phpBB/includes/class_content_visibility.php
@@ -30,7 +30,7 @@ class phpbb_content_visibility
* @param $table_alias string - Table alias to prefix in SQL queries
* @return string with the appropriate combination SQL logic for topic/post_visibility
*/
- public function get_visibility_sql($mode, $forum_id, $table_alias = '')
+ static public function get_visibility_sql($mode, $forum_id, $table_alias = '')
{
global $auth, $db, $user;
@@ -67,7 +67,7 @@ class phpbb_content_visibility
* @param $table_alias string - Table alias to prefix in SQL queries
* @return string with the appropriate combination SQL logic for topic/post_visibility
*/
- public function get_visibility_sql_global($mode, $exclude_forum_ids = array(), $table_alias = '')
+ static public function get_visibility_sql_global($mode, $exclude_forum_ids = array(), $table_alias = '')
{
global $auth, $db, $user;
@@ -116,7 +116,7 @@ class phpbb_content_visibility
* @param $forum_id - int - forum ID where $topic_id resides
* @return bool true = success, false = fail
*/
- public function set_topic_visibility($visibility, $topic_id, $forum_id)
+ static public function set_topic_visibility($visibility, $topic_id, $forum_id)
{
global $db;
@@ -139,7 +139,7 @@ class phpbb_content_visibility
* @param $is_starter - bool - is this the first post of the topic
* @param $is_latest - bool - is this the last post of the topic
*/
- public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $is_starter, $is_latest)
+ static public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $is_starter, $is_latest)
{
global $db;
@@ -182,7 +182,7 @@ class phpbb_content_visibility
* @param $post_locked - bool - is the post locked?
* @return bool
*/
- public function can_soft_delete($forum_id, $poster_id, $post_locked)
+ static function can_soft_delete($forum_id, $poster_id, $post_locked)
{
global $auth, $user;
@@ -228,7 +228,7 @@ class phpbb_content_visibility
* @param $sql_data - array - populated with the SQL changes, may be empty at call time
* @return void
*/
- public function hide_topic($topic_id, $forum_id, &$topic_row, &$sql_data)
+ static public function hide_topic($topic_id, $forum_id, &$topic_row, &$sql_data)
{
global $auth, $config, $db;
@@ -266,14 +266,27 @@ class phpbb_content_visibility
* Notably, we do _not_ need the post ID to do this operation. We're only changing statistic caches
* @param $forum_id - int - the forum where the topic resides
* @param $current_time - int - passed for consistency instead of calling time() internally
+ * @param $topic_row - array - contains information from the topics table about given topic
* @param $sql_data - array - populated with the SQL changes, may be empty at call time
* @return void
*/
- public function hide_post($forum_id, $current_time, &$sql_data)
+ static public function hide_post($forum_id, $current_time, $topic_row, &$sql_data)
{
global $auth, $config, $db;
- $sql_data[TOPICS_TABLE] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time;
+ // initialize the array if needed (php throws E_NOTICE when .= is used
+ // on a non-existing array element)
+ if (empty($sql_data[TOPICS_TABLE]))
+ {
+ $sql_data[TOPICS_TABLE] = '';
+ }
+
+ if ($topic_row['topic_replies'] > 0)
+ {
+ $sql_data[TOPICS_TABLE] = 'topic_replies = topic_replies - 1,';
+ }
+ $sql_data[TOPICS_TABLE] .= ' topic_last_view_time = ' . $current_time;
+
$sql_data[FORUMS_TABLE] = 'forum_posts = forum_posts - 1';
set_config_count('num_posts', -1, true);
@@ -293,7 +306,7 @@ class phpbb_content_visibility
* the posts/topics in question
* @param $post_id_list - array of ints - the set of posts being worked on
*/
- public function unhide_posts_topics($mode, $post_info, $post_id_list)
+ static public function unhide_posts_topics($mode, $post_info, $post_id_list)
{
global $db, $config;
@@ -435,6 +448,15 @@ class phpbb_content_visibility
sync('forum', 'forum_id', array_keys($forum_id_list), true, true);
unset($topic_id_list, $forum_id_list);
- return true;
+ if ($total_topics)
+ {
+ $success_msg = ($total_topics == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS';
+ }
+ else
+ {
+ $success_msg = (sizeof($post_id_list) + sizeof($post_approved_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS';
+ }
+
+ return $success_msg;
}
}
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index 364a3e7fe2..b63a41df7d 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -1467,7 +1467,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false)
if ($is_soft)
{
phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id));
- phpbb_content_visibility::hide_post($forum_id, time(), $sql_data);
+ phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data);
}
else
{
@@ -1501,7 +1501,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false)
if ($is_soft)
{
$topic_row = array();
- phpbb_content_visibility::set_topic_visibility(POST_DELETED, $topic_id, $forum_id);
+ phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id);
phpbb_content_visibility::hide_topic($topic_id, $forum_id, $topic_row, $sql_data);
}
else
@@ -1548,8 +1548,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false)
case 'delete_last_post':
if ($is_soft)
{
- phpbb_content_visibility::hide_post($forum_id, time(), $sql_data);
- phpbb_content_visibility::set_post_visibility($post_id, $topic_id, $forum_id, false, true);
+ phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data);
+ phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, false, true);
}
else
{
diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php
index 597be855b7..6c36084e68 100644
--- a/phpBB/includes/mcp/mcp_queue.php
+++ b/phpBB/includes/mcp/mcp_queue.php
@@ -322,6 +322,7 @@ class mcp_queue
if ($mode == 'unapproved_posts' || $mode == 'deleted_posts')
{
$visibility_const = ($mode == 'unapproved_posts') ? ITEM_UNAPPROVED : ITEM_DELETED;
+ $starter_sql = ($mode == 'unapproved_posts') ? 'AND t.topic_first_post_id <> p.post_id' : '';
$sql = 'SELECT p.post_id
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . '
@@ -330,7 +331,7 @@ class mcp_queue
' . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
AND t.topic_id = p.topic_id
- AND t.topic_first_post_id <> p.post_id
+ $starter_sql
$limit_time_sql
ORDER BY $sort_order_sql";
$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql
index e70e3db4d4..56663ea11e 100644
--- a/phpBB/install/schemas/schema_data.sql
+++ b/phpBB/install/schemas/schema_data.sql
@@ -613,10 +613,10 @@ INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id,
# -- Demo Topic
-INSERT INTO phpbb_topics (topic_title, topic_poster, topic_time, topic_views, topic_replies, topic_replies_real, forum_id, topic_status, topic_type, topic_first_post_id, topic_first_poster_name, topic_first_poster_colour, topic_last_post_id, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour, topic_last_post_subject, topic_last_post_time, topic_last_view_time, poll_title) VALUES ('{L_TOPICS_TOPIC_TITLE}', 2, 972086460, 0, 0, 0, 2, 0, 0, 1, 'Admin', 'AA0000', 1, 2, 'Admin', 'AA0000', '{L_TOPICS_TOPIC_TITLE}', 972086460, 972086460, '');
+INSERT INTO phpbb_topics (topic_title, topic_poster, topic_time, topic_views, topic_replies, topic_replies_real, forum_id, topic_status, topic_type, topic_first_post_id, topic_first_poster_name, topic_first_poster_colour, topic_last_post_id, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour, topic_last_post_subject, topic_last_post_time, topic_last_view_time, poll_title, topic_visibility) VALUES ('{L_TOPICS_TOPIC_TITLE}', 2, 972086460, 0, 0, 0, 2, 0, 0, 1, 'Admin', 'AA0000', 1, 2, 'Admin', 'AA0000', '{L_TOPICS_TOPIC_TITLE}', 972086460, 972086460, '', 1);
# -- Demo Post
-INSERT INTO phpbb_posts (topic_id, forum_id, poster_id, icon_id, post_time, post_username, poster_ip, post_subject, post_text, post_checksum, bbcode_uid) VALUES (1, 2, 2, 0, 972086460, '', '127.0.0.1', '{L_TOPICS_TOPIC_TITLE}', '{L_DEFAULT_INSTALL_POST}', '5dd683b17f641daf84c040bfefc58ce9', '');
+INSERT INTO phpbb_posts (topic_id, forum_id, poster_id, icon_id, post_time, post_username, poster_ip, post_subject, post_text, post_checksum, bbcode_uid, post_visibility) VALUES (1, 2, 2, 0, 972086460, '', '127.0.0.1', '{L_TOPICS_TOPIC_TITLE}', '{L_DEFAULT_INSTALL_POST}', '5dd683b17f641daf84c040bfefc58ce9', '', 1);
# -- Admin posted to the demo topic
INSERT INTO phpbb_topics_posted (user_id, topic_id, topic_posted) VALUES (2, 1, 1);
diff --git a/phpBB/posting.php b/phpBB/posting.php
index 877ebc6404..095fc06a3f 100644
--- a/phpBB/posting.php
+++ b/phpBB/posting.php
@@ -886,9 +886,52 @@ if ($submit || $preview || $refresh)
if ($submit && $mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED && !isset($_POST['soft_delete']) && phpbb_content_visibility::can_restore($forum_id, $post_data['poster_id'], $post_data['post_edit_locked']))
{
+ // if this is the first post of the topic, restore the whole topic
+ if ($post_id == $post_data['topic_first_post_id'])
+ {
+ // that means we need to gather data for all posts in the topic, not
+ // just the one being edited
+ $sql = 'SELECT post_id, poster_id, post_subject, post_postcount
+ FROM ' . POSTS_TABLE . '
+ WHERE topic_id = ' . $post_data['topic_id'] . '
+ AND post_visibility = ' . ITEM_DELETED;
+ $result = $db->sql_query($sql);
+
+ $post_ids = array();
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $post_ids[] = $row['post_id'];
+
+ $posts_data[$row['post_id']] = array(
+ // all posts are from the same topic and forum
+ // and are deleted because of the constraints to the query above
+ 'topic_id' => $post_data['topic_id'],
+ 'forum_id' => $post_data['forum_id'],
+ 'topic_replies' => $post_data['topic_replies'],
+ 'topic_first_post_id' => $post_data['topic_first_post_id'],
+ 'post_visibility' => ITEM_DELETED,
+
+ 'poster_id' => $row['poster_id'],
+ 'post_subject' => $row['post_subject'],
+ 'post_postcount'=> $row['post_postcount'],
+ );
+ }
+
+ // No direct query is needed, just update the array
+ $post_data['post_visibility'] = $post_data['topic_visibility'] = ITEM_APPROVED;
+ }
+ else
+ {
+ $post_ids = array($post_id);
+ $posts_data = array($post_id => $post_data);
+
+ $post_data['post_visibility'] = ITEM_APPROVED;
+ }
+
// don't feel that a confirm_box is needed for this
// do not return / trigger_error after this because the post content can also be changed
- phpbb_content_visibility::unhide_posts_topics('restore', array($post_id => $post_data), array($post_id));
+ phpbb_content_visibility::unhide_posts_topics('restore', $posts_data, $post_ids);
}
// Parse subject
@@ -1429,9 +1472,9 @@ $template->assign_vars(array(
'S_LOCK_POST_ALLOWED' => ($mode == 'edit' && $auth->acl_get('m_edit', $forum_id)) ? true : false,
'S_LOCK_POST_CHECKED' => ($lock_post_checked) ? ' checked="checked"' : '',
'S_SOFT_DELETE_CHECKED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? ' checked="checked"' : '',
- 'S_SOFT_DELETE_ALLOWED' => (phpbb_content_visibility::can_soft_delete($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false,
+ 'S_SOFT_DELETE_ALLOWED' => ($mode == 'edit' && phpbb_content_visibility::can_soft_delete($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false,
'S_RESTORE_ALLOWED' => (phpbb_content_visibility::can_restore($forum_id, $post_data['poster_id'], $lock_post_checked)) ? true : false,
- 'S_IS_DELETED' => ($post_data['post_visibility'] == POST_DELETED) ? true : false,
+ 'S_IS_DELETED' => ($mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED) ? true : false,
'S_LINKS_ALLOWED' => $url_status,
'S_MAGIC_URL_CHECKED' => ($urls_checked) ? ' checked="checked"' : '',
'S_TYPE_TOGGLE' => $topic_type_toggle,
@@ -1547,6 +1590,7 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof
'topic_first_post_id' => $post_data['topic_first_post_id'],
'topic_last_post_id' => $post_data['topic_last_post_id'],
'topic_replies_real' => $post_data['topic_replies_real'],
+ 'topic_replies' => $post_data['topic_replies'],
'topic_visibility' => $post_data['topic_visibility'],
'topic_type' => $post_data['topic_type'],
'post_visibility' => $post_data['post_visibility'],
diff --git a/phpBB/styles/prosilver/template/viewtopic_body.html b/phpBB/styles/prosilver/template/viewtopic_body.html
index 60fb080da1..392eea2c0d 100644
--- a/phpBB/styles/prosilver/template/viewtopic_body.html
+++ b/phpBB/styles/prosilver/template/viewtopic_body.html
@@ -148,7 +148,7 @@
<input type="hidden" name="post_id_list[]" value="{postrow.POST_ID}" />
{S_FORM_TOKEN}
<br /><!-- ENDIF -->
- <!-- IF postrow.S_POST_DELETED -->{DELETED_IMG} <a href="{postrow.U_MCP_APPROVE}"><strong>{L_POST_DELETED_RESTORE}</strong></a><br /><!-- ENDIF -->
+ <!-- IF postrow.S_POST_DELETED -->{DELETED_IMG} <a href="{postrow.U_MCP_RESTORE}"><strong>{L_POST_DELETED_RESTORE}</strong></a><br /><!-- ENDIF -->
<!-- IF postrow.S_POST_REPORTED -->{REPORTED_IMG} <a href="{postrow.U_MCP_REPORT}"><strong>{L_POST_REPORTED}</strong></a><!-- ENDIF -->
</p>
</form>
diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php
index fde3631c56..2b52e165c1 100644
--- a/phpBB/viewtopic.php
+++ b/phpBB/viewtopic.php
@@ -1600,6 +1600,7 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i)
'U_REPORT' => ($auth->acl_get('f_report', $forum_id)) ? append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $row['post_id']) : '',
'U_MCP_REPORT' => ($auth->acl_get('m_report', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',
'U_MCP_APPROVE' => ($auth->acl_get('m_approve', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',
+ 'U_MCP_RESTORE' => ($auth->acl_get('m_restore', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=deleted_posts&amp;f=' . $forum_id . '&amp;p=' . $row['post_id'], true, $user->session_id) : '',
'U_MINI_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_id']) . '#p' . $row['post_id'],
'U_NEXT_POST_ID' => ($i < $i_total && isset($rowset[$post_list[$i + 1]])) ? $rowset[$post_list[$i + 1]]['post_id'] : '',
'U_PREV_POST_ID' => $prev_post_id,
diff --git a/tests/class_visibility/class_visibility_test.php b/tests/class_visibility/class_visibility_test.php
index 8503867b09..20aa207f46 100644
--- a/tests/class_visibility/class_visibility_test.php
+++ b/tests/class_visibility/class_visibility_test.php
@@ -181,14 +181,19 @@ class phpbb_class_visibility_test extends PHPUnit_Framework_TestCase
$GLOBALS['auth'] = new phpbb_acl_mock_founder;
$sql_data = array();
- phpbb_content_visibility::hide_post(4, 111122211, $sql_data);
+ phpbb_content_visibility::hide_post(4, 111122211, array('topic_replies' => 1), $sql_data);
$this->assertEquals(
array(FORUMS_TABLE => 'forum_posts = forum_posts - 1',
TOPICS_TABLE => 'topic_replies = topic_replies - 1, topic_last_view_time = 111122211',
USERS_TABLE => 'user_posts = user_posts - 1'),
$sql_data);
+
+ $sql_data = array();
+ phpbb_content_visibility::hide_post(4, 111122211, array('topic_replies' => 0), $sql_data);
+ $this->assertEquals(
+ array(FORUMS_TABLE => 'forum_posts = forum_posts - 1',
+ TOPICS_TABLE => 'topic_last_view_time = 111122211',
+ USERS_TABLE => 'user_posts = user_posts - 1'),
+ $sql_data);
}
}
-
-//$a = new phpbb_class_visibility_test;
-//$a->test_can_soft_delete(); \ No newline at end of file