Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket/8116 Add pagination for IP tables on post info #3456

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 121 additions & 7 deletions phpBB/includes/mcp/mcp_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
*/
function mcp_post_details($id, $mode, $action)
{
global $phpEx, $phpbb_root_path, $config;
global $template, $db, $user, $auth, $cache;
global $phpEx, $phpbb_root_path, $config, $request;
global $template, $db, $user, $auth, $cache, $phpbb_container;

/** @var \phpbb\pagination $pagination */
$pagination = $phpbb_container->get('pagination');

$user->add_lang('posting');

Expand Down Expand Up @@ -314,7 +317,8 @@ function mcp_post_details($id, $mode, $action)
// Get IP
if ($auth->acl_get('m_info', $post_info['forum_id']))
{
$rdns_ip_num = request_var('rdns', '');
$rdns_ip_num = $request->variable('rdns', '');
$start_users = $request->variable('start_users', 0);

if ($rdns_ip_num != 'all')
{
Expand All @@ -323,16 +327,26 @@ function mcp_post_details($id, $mode, $action)
);
}

$num_users = false;
if ($start_users)
{
$num_users = phpbb_get_num_posters_for_ip($db, $post_info['poster_ip']);
$start_users = $pagination->validate_start($start_users, $config['posts_per_page'], $num_users);
}

// 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
ORDER BY postings DESC";
$result = $db->sql_query($sql);
ORDER BY postings DESC, poster_id ASC";
$result = $db->sql_query_limit($sql, $config['posts_per_page'], $start_users);

$users = 0;
while ($row = $db->sql_fetchrow($result))
{
$users++;

// Fill the user select list with users who have posted under this IP
if ($row['poster_id'] != $post_info['poster_id'])
{
Expand All @@ -341,6 +355,23 @@ function mcp_post_details($id, $mode, $action)
}
$db->sql_freeresult($result);

if ($users == $config['posts_per_page'] || $start_users)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference between $users and $num_users is not clear.

{
if ($num_users === false)
{
$num_users = phpbb_get_num_posters_for_ip($db, $post_info['poster_ip']);
}

$pagination->generate_template_pagination(
$url . '&i=main&mode=post_details',
'pagination',
'start_users',
$num_users,
$config['posts_per_page'],
$start_users
);
}

if (sizeof($users_ary))
{
// Get the usernames
Expand Down Expand Up @@ -374,16 +405,26 @@ function mcp_post_details($id, $mode, $action)
// 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.
$start_ips = $request->variable('start_ips', 0);

$num_ips = false;
if ($start_ips)
{
$num_ips = phpbb_get_num_ips_for_poster($db, $post_info['poster_id']);
$start_ips = $pagination->validate_start($start_ips, $config['posts_per_page'], $num_ips);
}

$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 postings DESC";
$result = $db->sql_query($sql);
ORDER BY postings DESC, poster_ip ASC";
$result = $db->sql_query_limit($sql, $config['posts_per_page'], $start_ips);

$ips = 0;
while ($row = $db->sql_fetchrow($result))
{
$ips++;
$hostname = (($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') && $row['poster_ip']) ? @gethostbyaddr($row['poster_ip']) : '';

$template->assign_block_vars('iprow', array(
Expand All @@ -398,6 +439,23 @@ function mcp_post_details($id, $mode, $action)
}
$db->sql_freeresult($result);

if ($ips == $config['posts_per_page'] || $start_ips)
{
if ($num_ips === false)
{
$num_ips = phpbb_get_num_ips_for_poster($db, $post_info['poster_id']);
}

$pagination->generate_template_pagination(
$url . '&i=main&mode=post_details',
'pagination_ips',
'start_ips',
$num_ips,
$config['posts_per_page'],
$start_ips
);
}

$user_select = '';

if (sizeof($usernames_ary))
Expand All @@ -415,6 +473,62 @@ function mcp_post_details($id, $mode, $action)

}

/**
* Get the number of posters for a given ip
*
* @param \phpbb\db\driver\driver_interface $db
* @param string $poster_ip
* @return int
*/
function phpbb_get_num_posters_for_ip(\phpbb\db\driver\driver_interface $db, $poster_ip)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could try to deduplicate these methods, but without putting the column name directly into the query string, you loose the overview on them

{
if ($db->get_sql_layer() == 'sqlite' || $db->get_sql_layer() == 'sqlite3')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This construction should be in DBAL instead.

{
$sql = 'SELECT COUNT(poster_id) as num_users
FROM (SELECT DISTINCT poster_id';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"(" is never closed?

}
else
{
$sql = 'SELECT COUNT(DISTINCT poster_id) as num_users';
}

$sql .= ' FROM ' . POSTS_TABLE . "
WHERE poster_ip = '" . $db->sql_escape($poster_ip) . "'";
$result = $db->sql_query($sql);
$num_users = (int) $db->sql_fetchfield('num_users');
$db->sql_freeresult($result);

return $num_users;
}

/**
* Get the number of ips for a given poster
*
* @param \phpbb\db\driver\driver_interface $db
* @param int $poster_id
* @return int
*/
function phpbb_get_num_ips_for_poster(\phpbb\db\driver\driver_interface $db, $poster_id)
{
if ($db->get_sql_layer() == 'sqlite' || $db->get_sql_layer() == 'sqlite3')
{
$sql = 'SELECT COUNT(poster_ip) as num_ips
FROM (SELECT DISTINCT poster_ip';
}
else
{
$sql = 'SELECT COUNT(DISTINCT poster_ip) as num_ips';
}

$sql .= ' FROM ' . POSTS_TABLE . '
WHERE poster_id = ' . (int) $poster_id;
$result = $db->sql_query($sql);
$num_ips = (int) $db->sql_fetchfield('num_ips');
$db->sql_freeresult($result);

return $num_ips;
}

/**
* Change a post's poster
*/
Expand Down
44 changes: 43 additions & 1 deletion phpBB/styles/prosilver/template/mcp_post.html
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,28 @@ <h3>{L_MCP_POST_REPORTS}</h3>
</tbody>
</table>

<div class="pagination">
<ul>
<!-- BEGIN pagination -->
<!-- IF pagination.S_IS_PREV -->
<li class="previous"><a href="{pagination.PAGE_URL}" rel="prev" role="button">{L_PREVIOUS}</a></li>
<!-- ELSEIF pagination.S_IS_CURRENT -->
<li class="active"><span>{pagination.PAGE_NUMBER}</span></li>
<!-- ELSEIF pagination.S_IS_ELLIPSIS -->
<li class="ellipsis" role="separator"><span>{L_ELLIPSIS}</span></li>
<!-- ELSEIF pagination.S_IS_NEXT -->
<li class="next"><a href="{pagination.PAGE_URL}" rel="next" role="button">{L_NEXT}</a></li>
<!-- ELSE -->
<li><a href="{pagination.PAGE_URL}" role="button">{pagination.PAGE_NUMBER}</a></li>
<!-- ENDIF -->
<!-- END pagination -->
</ul>
</div>
</div>
</div>

<div class="panel">
<div class="inner">
<table class="table1">
<thead>
<tr>
Expand All @@ -313,7 +335,27 @@ <h3>{L_MCP_POST_REPORTS}</h3>
</tbody>
</table>

<p><a href="{U_LOOKUP_ALL}#ip">{L_LOOKUP_ALL}</a></p>
<div class="buttons">
<p><a href="{U_LOOKUP_ALL}#ip">{L_LOOKUP_ALL}</a></p>
</div>

<div class="pagination">
<ul>
<!-- BEGIN pagination_ips -->
<!-- IF pagination_ips.S_IS_PREV -->
<li class="previous"><a href="{pagination_ips.PAGE_URL}" rel="prev" role="button">{L_PREVIOUS}</a></li>
<!-- ELSEIF pagination_ips.S_IS_CURRENT -->
<li class="active"><span>{pagination_ips.PAGE_NUMBER}</span></li>
<!-- ELSEIF pagination_ips.S_IS_ELLIPSIS -->
<li class="ellipsis" role="separator"><span>{L_ELLIPSIS}</span></li>
<!-- ELSEIF pagination_ips.S_IS_NEXT -->
<li class="next"><a href="{pagination_ips.PAGE_URL}" rel="next" role="button">{L_NEXT}</a></li>
<!-- ELSE -->
<li><a href="{pagination_ips.PAGE_URL}" role="button">{pagination_ips.PAGE_NUMBER}</a></li>
<!-- ENDIF -->
<!-- END pagination_ips -->
</ul>
</div>

</div>
</div>
Expand Down