aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2006-09-26 19:59:41 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2006-09-26 19:59:41 +0000
commit734492958eaa2f193db304fd5d4cf050390eff1a (patch)
tree37f19f2dd765fd45024bcd9180e729b79c9a430a /phpBB
parente339c36ec035520ce6f3ae4c8ad69bff35eabde6 (diff)
downloadforums-734492958eaa2f193db304fd5d4cf050390eff1a.tar
forums-734492958eaa2f193db304fd5d4cf050390eff1a.tar.gz
forums-734492958eaa2f193db304fd5d4cf050390eff1a.tar.bz2
forums-734492958eaa2f193db304fd5d4cf050390eff1a.tar.xz
forums-734492958eaa2f193db304fd5d4cf050390eff1a.zip
These changes should let olympus scale a little bit better.
i haven't adjusted the schemas but added the details to create_schema_files - david is able to build them then in line with his changes. :) git-svn-id: file:///svn/phpbb/trunk@6411 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/develop/create_schema_files.php4
-rw-r--r--phpBB/includes/db/dbal.php2
-rw-r--r--phpBB/includes/functions_admin.php43
-rw-r--r--phpBB/includes/functions_display.php11
-rw-r--r--phpBB/includes/functions_posting.php8
-rw-r--r--phpBB/includes/functions_privmsgs.php13
-rw-r--r--phpBB/includes/mcp/mcp_forum.php2
-rw-r--r--phpBB/includes/mcp/mcp_post.php85
-rw-r--r--phpBB/includes/mcp/mcp_queue.php18
-rw-r--r--phpBB/includes/ucp/ucp_main.php1
-rw-r--r--phpBB/mcp.php16
-rw-r--r--phpBB/memberlist.php1
-rw-r--r--phpBB/styles/subSilver/template/mcp_forum.html1
-rw-r--r--phpBB/viewtopic.php39
14 files changed, 153 insertions, 91 deletions
diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php
index cad8c7fbe6..7a0bec11e2 100644
--- a/phpBB/develop/create_schema_files.php
+++ b/phpBB/develop/create_schema_files.php
@@ -1237,8 +1237,7 @@ function get_schema_struct()
'poster_ip' => array('INDEX', 'poster_ip'),
'poster_id' => array('INDEX', 'poster_id'),
'post_approved' => array('INDEX', 'post_approved'),
- 'post_postcount' => array('INDEX', 'post_postcount'),
- 'post_time' => array('INDEX', 'post_time'),
+ 'tid_post_time' => array('INDEX', array('topic_id', 'post_time')),
),
);
@@ -1739,6 +1738,7 @@ function get_schema_struct()
'forum_id' => array('INDEX', 'forum_id'),
'forum_id_type' => array('INDEX', array('forum_id', 'topic_type')),
'last_post_time' => array('INDEX', 'topic_last_post_time'),
+ 'topic_approved' => array('INDEX', 'topic_approved'),
'fid_time_moved' => array('INDEX', array('forum_id', 'topic_last_post_time', 'topic_moved_id')),
),
);
diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php
index 6f6b5ddce4..6e89c6f908 100644
--- a/phpBB/includes/db/dbal.php
+++ b/phpBB/includes/db/dbal.php
@@ -409,7 +409,7 @@ class dbal
{
global $cache, $starttime, $phpbb_root_path, $user;
- if (empty($_GET['explain']))
+ if (empty($_REQUEST['explain']))
{
return false;
}
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index 1d5ec9ee68..7ce428a2b7 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -1388,6 +1388,8 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
break;
}
+ $forum_ids = array_values($forum_ids);
+
// 2: Get topic counts for each forum
$sql = 'SELECT forum_id, topic_approved, COUNT(topic_id) AS forum_topics
FROM ' . TOPICS_TABLE . '
@@ -1408,16 +1410,27 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$db->sql_freeresult($result);
// 3: Get post count and last_post_id for each forum
- $sql = 'SELECT forum_id, COUNT(post_id) AS forum_posts, MAX(post_id) AS last_post_id
- FROM ' . POSTS_TABLE . '
- WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . '
- AND post_approved = 1
- GROUP BY forum_id';
+ if (sizeof($forum_ids) == 1)
+ {
+ $sql = 'SELECT COUNT(post_id) AS forum_posts, MAX(post_id) AS last_post_id
+ FROM ' . POSTS_TABLE . '
+ WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . '
+ AND post_approved = 1';
+ }
+ else
+ {
+ $sql = 'SELECT forum_id, COUNT(post_id) AS forum_posts, MAX(post_id) AS last_post_id
+ FROM ' . POSTS_TABLE . '
+ WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . '
+ AND post_approved = 1
+ GROUP BY forum_id';
+ }
+
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
- $forum_id = (int) $row['forum_id'];
+ $forum_id = (sizeof($forum_ids) == 1) ? (int) $forum_ids[0] : (int) $row['forum_id'];
$forum_data[$forum_id]['posts'] = (int) $row['forum_posts'];
$forum_data[$forum_id]['last_post_id'] = (int) $row['last_post_id'];
@@ -1519,6 +1532,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$topic_id = (int) $row['topic_id'];
$topic_data[$topic_id] = $row;
$topic_data[$topic_id]['replies_real'] = -1;
+ $topic_data[$topic_id]['replies'] = 0;
$topic_data[$topic_id]['first_post_id'] = 0;
$topic_data[$topic_id]['last_post_id'] = 0;
unset($topic_data[$topic_id]['topic_id']);
@@ -1538,19 +1552,8 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
// NOTE: 't.post_approved' in the GROUP BY is causing a major slowdown.
$sql = 'SELECT t.topic_id, t.post_approved, COUNT(t.post_id) AS total_posts, MIN(t.post_id) AS first_post_id, MAX(t.post_id) AS last_post_id
FROM ' . POSTS_TABLE . " t
- $where_sql";
-
- switch (SQL_LAYER)
- {
- case 'mssql':
- case 'mssql_odbc':
- $sql .= ' GROUP BY t.topic_id, t.post_approved';
- break;
-
- default:
- $sql .= ' GROUP BY t.topic_id';
- break;
- }
+ $where_sql
+ GROUP BY t.topic_id, t.post_approved";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@@ -1755,7 +1758,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
// batch processing.
if ($resync_parents && sizeof($resync_forums) && $where_type != 'range')
{
- sync('forum', 'forum_id', $resync_forums, true);
+ sync('forum', 'forum_id', array_values($resync_forums), true);
}
break;
}
diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php
index 2c82fda5ed..fccefa0552 100644
--- a/phpBB/includes/functions_display.php
+++ b/phpBB/includes/functions_display.php
@@ -1018,6 +1018,12 @@ function display_user_activity(&$userdata)
global $auth, $template, $db, $user;
global $phpbb_root_path, $phpEx;
+ // Do not display user activity for users having more than 5000 posts...
+ if ($userdata['user_posts'] > 5000)
+ {
+ return;
+ }
+
$forum_ary = array();
// Do not include those forums the user is not having read access to...
@@ -1070,7 +1076,7 @@ function display_user_activity(&$userdata)
}
// Obtain active topic
- $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
+ $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
FROM ' . POSTS_TABLE . '
WHERE poster_id = ' . $userdata['user_id'] . "
AND post_postcount = 1
@@ -1133,7 +1139,8 @@ function display_user_activity(&$userdata)
'ACTIVE_TOPIC_POSTS' => ($active_t_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_t_count),
'ACTIVE_TOPIC_PCT' => sprintf($user->lang['POST_PCT_ACTIVE'], $active_t_pct),
'U_ACTIVE_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),
- 'U_ACTIVE_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id))
+ 'U_ACTIVE_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id),
+ 'S_SHOW_ACTIVITY' => true)
);
}
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index 1518f1d1e5..50b1a138c4 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -117,15 +117,15 @@ function update_post_information($type, $ids, $return_update_sql = false)
{
$sql = 'SELECT MAX(post_id) as last_post_id
FROM ' . POSTS_TABLE . '
- WHERE post_approved = 1
- AND ' . $db->sql_in_set($type . '_id', $ids);
+ WHERE ' . $db->sql_in_set($type . '_id', $ids) . '
+ AND post_approved = 1';
}
else
{
$sql = 'SELECT ' . $type . '_id, MAX(post_id) as last_post_id
FROM ' . POSTS_TABLE . '
- WHERE post_approved = 1
- AND ' . $db->sql_in_set($type . '_id', $ids) . "
+ WHERE ' . $db->sql_in_set($type . '_id', $ids) . "
+ AND post_approved = 1
GROUP BY {$type}_id";
}
$result = $db->sql_query($sql);
diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php
index 1f53dc4511..a28a290a7b 100644
--- a/phpBB/includes/functions_privmsgs.php
+++ b/phpBB/includes/functions_privmsgs.php
@@ -611,13 +611,12 @@ function place_pm_into_folder(&$global_privmsgs_rules, $release = false)
}
else if ($full_folder_action == FULL_FOLDER_DELETE)
{
- // Delete some messages ;)
- $sql = 'SELECT t.msg_id
- FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . " p
- WHERE t.msg_id = p.msg_id
- AND t.user_id = $user_id
- AND t.folder_id = $dest_folder
- ORDER BY p.message_time ASC";
+ // Delete some messages. NOTE: Ordered by msg_id here instead of message_time!
+ $sql = 'SELECT msg_id
+ FROM ' . PRIVMSGS_TO_TABLE . "
+ WHERE user_id = $user_id
+ AND folder_id = $dest_folder
+ ORDER BY msg_id ASC";
$result = $db->sql_query_limit($sql, (($folder[$dest_folder] + sizeof($msg_ary)) - $user->data['message_limit']));
$delete_ids = array();
diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php
index a6df7c2c87..71573586f5 100644
--- a/phpBB/includes/mcp/mcp_forum.php
+++ b/phpBB/includes/mcp/mcp_forum.php
@@ -191,7 +191,7 @@ function mcp_resync_topics($topic_ids)
$redirect = request_var('redirect', $user->data['session_page']);
- meta_refresh(2, $redirect);
+ meta_refresh(3, $redirect);
trigger_error($msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
return;
diff --git a/phpBB/includes/mcp/mcp_post.php b/phpBB/includes/mcp/mcp_post.php
index fc8220828c..4e931d2d9c 100644
--- a/phpBB/includes/mcp/mcp_post.php
+++ b/phpBB/includes/mcp/mcp_post.php
@@ -89,7 +89,7 @@ function mcp_post_details($id, $mode, $action)
}
// Set some vars
- $users_ary = array();
+ $users_ary = $usernames_ary = array();
$post_id = $post_info['post_id'];
$poster = ($post_info['user_colour']) ? '<span style="color:#' . $post_info['user_colour'] . '">' . $post_info['username'] . '</span>' : $post_info['username'];
@@ -217,69 +217,83 @@ function mcp_post_details($id, $mode, $action)
}
// Get other users who've posted under this IP
+ $sql = 'SELECT poster_id, COUNT(poster_id) as postings
+ FROM ' . POSTS_TABLE . "
+ WHERE poster_ip = '" . $db->sql_escape($post_info['poster_ip']) . "'
+ GROUP BY poster_id";
// Firebird does not support ORDER BY on aliased columns
// MySQL does not support ORDER BY on functions
switch (SQL_LAYER)
{
case 'firebird':
- $sql = 'SELECT u.user_id, u.username, COUNT(*) as postings
- FROM ' . USERS_TABLE . ' u, ' . POSTS_TABLE . " p
- WHERE p.poster_id = u.user_id
- AND p.poster_ip = '" . $db->sql_escape($post_info['poster_ip']) . "'
- AND p.poster_id <> {$post_info['user_id']}
- GROUP BY u.user_id, u.username
- ORDER BY COUNT(*) DESC";
+ $sql .= ' ORDER BY COUNT(poster_id) DESC';
break;
default:
- $sql = 'SELECT u.user_id, u.username, COUNT(*) as postings
- FROM ' . USERS_TABLE . ' u, ' . POSTS_TABLE . " p
- WHERE p.poster_id = u.user_id
- AND p.poster_ip = '" . $db->sql_escape($post_info['poster_ip']) . "'
- AND p.poster_id <> {$post_info['user_id']}
- GROUP BY u.user_id, u.username
- ORDER BY postings DESC";
+ $sql .= ' ORDER BY postings DESC';
break;
}
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
- // Fill the user select list with users who have posted
- // under this IP
- if ($row['user_id'] != $post_info['poster_id'])
+ // Fill the user select list with users who have posted under this IP
+ if ($row['poster_id'] != $post_info['poster_id'])
{
- $users_ary[strtolower($row['username'])] = $row;
+ $users_ary[$row['poster_id']] = $row;
}
+ }
+ $db->sql_freeresult($result);
- $template->assign_block_vars('userrow', array(
- 'USERNAME' => ($row['user_id'] == ANONYMOUS) ? $user->lang['GUEST'] : $row['username'],
- 'NUM_POSTS' => $row['postings'],
- 'L_POST_S' => ($row['postings'] == 1) ? $user->lang['POST'] : $user->lang['POSTS'],
+ if (sizeof($users_ary))
+ {
+ // Get the usernames
+ $sql = 'SELECT user_id, username
+ FROM ' . USERS_TABLE . '
+ WHERE ' . $db->sql_in_set('user_id', array_keys($users_ary));
+ $result = $db->sql_query($sql);
- 'U_PROFILE' => ($row['user_id'] == ANONYMOUS) ? '' : append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id']),
- 'U_SEARCHPOSTS' => append_sid("{$phpbb_root_path}search.$phpEx", 'author=' . urlencode($row['username']) . '&amp;sr=topics'))
- );
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $users_ary[$row['user_id']]['username'] = strtolower($row['username']);
+ $usernames_ary[strtolower($row['username'])] = $users_ary[$row['user_id']];
+ }
+ $db->sql_freeresult($result);
+
+ foreach ($users_ary as $user_id => $user_row)
+ {
+ $template->assign_block_vars('userrow', array(
+ 'USERNAME' => ($user_id == ANONYMOUS) ? $user->lang['GUEST'] : $user_row['username'],
+ 'NUM_POSTS' => $user_row['postings'],
+ 'L_POST_S' => ($user_row['postings'] == 1) ? $user->lang['POST'] : $user->lang['POSTS'],
+
+ 'U_PROFILE' => ($user_id == ANONYMOUS) ? '' : append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $user_id),
+ 'U_SEARCHPOSTS' => append_sid("{$phpbb_root_path}search.$phpEx", 'author=' . urlencode($user_row['username']) . '&amp;sr=topics'))
+ );
+ }
}
- $db->sql_freeresult($result);
// Get other IP's this user has posted under
+ // A compound index on poster_id, poster_ip (posts table) would help speed up this query a lot,
+ // but the extra size is only valuable if there are persons having more than a thousands posts.
+ // This is better left to the really really big forums.
+
// Firebird does not support ORDER BY on aliased columns
// MySQL does not support ORDER BY on functions
switch (SQL_LAYER)
{
case 'firebird':
- $sql = 'SELECT poster_ip, COUNT(*) AS postings
+ $sql = 'SELECT poster_ip, COUNT(poster_ip) AS postings
FROM ' . POSTS_TABLE . '
WHERE poster_id = ' . $post_info['poster_id'] . '
GROUP BY poster_ip
- ORDER BY COUNT(*) DESC';
+ ORDER BY COUNT(poster_ip) DESC';
break;
default:
- $sql = 'SELECT poster_ip, COUNT(*) AS postings
+ $sql = 'SELECT poster_ip, COUNT(poster_ip) AS postings
FROM ' . POSTS_TABLE . '
WHERE poster_id = ' . $post_info['poster_id'] . '
GROUP BY poster_ip
@@ -305,12 +319,17 @@ function mcp_post_details($id, $mode, $action)
$db->sql_freeresult($result);
$user_select = '';
- ksort($users_ary);
- foreach ($users_ary as $row)
+ if (sizeof($usernames_ary))
{
- $user_select .= '<option value="' . $row['user_id'] . '">' . $row['username'] . "</option>\n";
+ ksort($usernames_ary);
+
+ foreach ($usernames_ary as $row)
+ {
+ $user_select .= '<option value="' . $row['poster_id'] . '">' . $row['username'] . "</option>\n";
+ }
}
+
$template->assign_var('S_USER_SELECT', $user_select);
}
diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php
index 1dc2ab122e..d714c9879f 100644
--- a/phpBB/includes/mcp/mcp_queue.php
+++ b/phpBB/includes/mcp/mcp_queue.php
@@ -286,8 +286,8 @@ class mcp_queue
{
$sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_title AS post_subject, t.topic_time AS post_time, t.topic_poster AS poster_id, t.topic_first_post_id AS post_id, t.topic_first_poster_name AS username
FROM ' . TOPICS_TABLE . " t
- WHERE topic_approved = 0
- AND forum_id IN (0, $forum_list)
+ WHERE forum_id IN (0, $forum_list)
+ AND topic_approved = 0
$limit_time_sql
ORDER BY $sort_order_sql";
$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
@@ -412,6 +412,8 @@ function approve_post($post_id_list, $mode)
$total_topics = $total_posts = $forum_topics = $forum_posts = 0;
$topic_approve_sql = $topic_replies_sql = $post_approve_sql = $topic_id_list = array();
+ $update_forum_information = false;
+
foreach ($post_info as $post_id => $post_data)
{
$topic_id_list[$post_data['topic_id']] = 1;
@@ -446,6 +448,12 @@ function approve_post($post_id_list, $mode)
}
$post_approve_sql[] = $post_id;
+
+ // If the post is newer than the last post information stored we need to update the forum information
+ if ($post_data['post_time'] >= $post_data['forum_last_post_time'])
+ {
+ $update_forum_information = true;
+ }
}
if (sizeof($topic_approve_sql))
@@ -499,7 +507,11 @@ function approve_post($post_id_list, $mode)
unset($topic_approve_sql, $topic_replies_sql, $post_approve_sql);
update_post_information('topic', array_keys($topic_id_list));
- update_post_information('forum', $forum_id);
+
+ if ($update_forum_information)
+ {
+ update_post_information('forum', $forum_id);
+ }
unset($topic_id_list);
$messenger = new messenger();
diff --git a/phpBB/includes/ucp/ucp_main.php b/phpBB/includes/ucp/ucp_main.php
index 5b21e5a35a..7e7def27fe 100644
--- a/phpBB/includes/ucp/ucp_main.php
+++ b/phpBB/includes/ucp/ucp_main.php
@@ -177,7 +177,6 @@ class ucp_main
'INTERESTS' => (!empty($row['user_interests'])) ? $row['user_interests'] : '',
// 'S_GROUP_OPTIONS' => $group_options,
- 'S_SHOW_ACTIVITY' => ($config['load_user_activity']) ? true : false,
'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $user->data['user_id'] . '&amp;sr=posts') : '')
);
diff --git a/phpBB/mcp.php b/phpBB/mcp.php
index 1b09eb1e2c..b9df35c7a7 100644
--- a/phpBB/mcp.php
+++ b/phpBB/mcp.php
@@ -467,8 +467,12 @@ function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql,
$sql = 'SELECT COUNT(post_id) AS total
FROM ' . POSTS_TABLE . "
$where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : get_forum_list('m_approve')) . '
- AND post_approved = 0
- AND post_time >= ' . $min_time;
+ AND post_approved = 0';
+
+ if ($min_time)
+ {
+ $sql .= ' AND post_time >= ' . $min_time;
+ }
break;
case 'unapproved_topics':
@@ -479,8 +483,12 @@ function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql,
$sql = 'SELECT COUNT(topic_id) AS total
FROM ' . TOPICS_TABLE . "
$where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : get_forum_list('m_approve')) . '
- AND topic_approved = 0
- AND topic_time >= ' . $min_time;
+ AND topic_approved = 0';
+
+ if ($min_time)
+ {
+ $sql .= ' AND topic_time >= ' . $min_time;
+ }
break;
case 'reports':
diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php
index 9a0a7be418..dc83e00666 100644
--- a/phpBB/memberlist.php
+++ b/phpBB/memberlist.php
@@ -479,7 +479,6 @@ switch ($mode)
'S_PROFILE_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group'),
'S_GROUP_OPTIONS' => $group_options,
'S_CUSTOM_FIELDS' => (isset($profile_fields['row']) && sizeof($profile_fields['row'])) ? true : false,
- 'S_SHOW_ACTIVITY' => ($config['load_user_activity']) ? true : false,
'U_USER_ADMIN' => ($auth->acl_get('a_user')) ? append_sid("{$phpbb_root_path}adm/index.$phpEx", 'i=users&amp;mode=overview&amp;u=' . $user_id, true, $user->session_id) : '',
'U_SWITCH_PERMISSIONS' => ($auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_id) ? append_sid("{$phpbb_root_path}ucp.$phpEx", "mode=switch_perm&amp;u={$user_id}") : '',
diff --git a/phpBB/styles/subSilver/template/mcp_forum.html b/phpBB/styles/subSilver/template/mcp_forum.html
index a3dd7a3d98..5d45eb17a3 100644
--- a/phpBB/styles/subSilver/template/mcp_forum.html
+++ b/phpBB/styles/subSilver/template/mcp_forum.html
@@ -46,6 +46,7 @@
<tr>
<td class="cat" colspan="6" align="right">
<select name="action">
+ <option value="" checked="checked">{L_SELECT_ACTION}</option>
<!-- IF S_CAN_DELETE --><option value="delete_topic">{L_DELETE}</option><!-- ENDIF -->
<!-- IF S_CAN_MOVE --><option value="move">{L_MOVE}</option><!-- ENDIF -->
<!-- IF S_CAN_FORK --><option value="fork">{L_FORK}</option><!-- ENDIF -->
diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php
index a22aedf651..534e72780d 100644
--- a/phpBB/viewtopic.php
+++ b/phpBB/viewtopic.php
@@ -238,19 +238,34 @@ if (!$topic_data)
// This is for determining where we are (page)
if ($post_id)
{
- /**
- * @todo adjust for using post_time? Generally adjust query... it is not called very often though
- */
- $sql = 'SELECT COUNT(post_id) AS prev_posts
- FROM ' . POSTS_TABLE . "
- WHERE topic_id = {$topic_data['topic_id']}
- " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND post_approved = 1' : '') . "
- AND " . (($sort_dir == 'd') ? "post_id >= $post_id" : "post_id <= $post_id");
- $result = $db->sql_query($sql);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
+ if ($post_id == $topic_data['topic_first_post_id'] || $post_id == $topic_data['topic_last_post_id'])
+ {
+ $check_sort = ($post_id == $topic_data['topic_first_post_id']) ? 'd' : 'a';
+
+ if ($sort_dir == $check_sort)
+ {
+ $topic_data['prev_posts'] = ($auth->acl_get('m_approve', $forum_id)) ? $topic_data['topic_replies_real'] + 1 : $topic_data['topic_replies'] + 1;
+ }
+ else
+ {
+ $topic_data['prev_posts'] = 1;
+ }
+ }
+ else
+ {
+ $sql = 'SELECT COUNT(p1.post_id) AS prev_posts
+ FROM ' . POSTS_TABLE . ' p1, ' . POSTS_TABLE . " p2
+ WHERE p1.topic_id = {$topic_data['topic_id']}
+ AND p2.post_id = {$post_id}
+ " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p1.post_approved = 1' : '') . '
+ AND ' . (($sort_dir == 'd') ? 'p1.post_time >= p2.post_time' : 'p1.post_time <= p2.post_time');
- $topic_data['prev_posts'] = $row['prev_posts'];
+ $result = $db->sql_query($sql);
+ $row = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+
+ $topic_data['prev_posts'] = $row['prev_posts'];
+ }
}
$forum_id = (int) $topic_data['forum_id'];