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/16904] Fix regression in MCP for topics selection #6323

Merged
merged 4 commits into from Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 29 additions & 41 deletions phpBB/includes/functions_mcp.php
Expand Up @@ -35,42 +35,26 @@ function phpbb_module_notes_url($mode, $module_row)
}

global $user_id;
return ($user_id) ? "&u=$user_id" : '';
return phpbb_extra_url();
}

function phpbb_module_warn_url($mode, $module_row)
{
if ($mode == 'front' || $mode == 'list')
{
global $forum_id;

return ($forum_id) ? "&f=$forum_id" : '';
return phpbb_extra_url();
}

if ($mode == 'warn_post')
{
global $forum_id, $post_id;

if ($post_id)
{
$url_extra = "&p=$post_id";
}
else if ($forum_id)
{
$url_extra = "&f=$forum_id";
}
else
{
$url_extra = '';
}

return $url_extra;
return phpbb_extra_url();
}
else
{
global $user_id;

return ($user_id) ? "&u=$user_id" : '';
return phpbb_extra_url();
}
}

Expand Down Expand Up @@ -99,30 +83,34 @@ function phpbb_module_reports_url($mode, $module_row)
return phpbb_extra_url();
}

function phpbb_extra_url()
/**
* Generate URL parameters for MCP modules
*
* @param array $additional_parameters Array with additional parameters in format of ['key' => 'parameter_name']
*
* @return string String with URL parameters (empty string if not any)
*/
function phpbb_extra_url($additional_parameters = [])
{
global $forum_id, $topic_id, $post_id, $report_id, $user_id;

if ($post_id)
{
$url_extra = "&p=$post_id";
}
else if ($topic_id)
{
$url_extra = "&t=$topic_id";
}
else if ($forum_id)
{
$url_extra = "&f=$forum_id";
}
else
{
$url_extra = '';
$url_extra = [];
$url_parameters = array_merge([
'f' => 'forum_id',
't' => 'topic_id',
'p' => 'post_id',
'r' => 'report_id',
'u' => 'user_id',
], $additional_parameters);

foreach ($url_parameters as $key => $value)
{
global $$value;
if (isset($$value) && $parameter = $$value)
{
$url_extra[] = "$key=$parameter";
}
}
$url_extra .= ($user_id) ? "&u=$user_id" : '';
$url_extra .= ($report_id) ? "&r=$report_id" : '';

return $url_extra;
return implode('&', $url_extra);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions phpBB/includes/functions_module.php
Expand Up @@ -662,7 +662,7 @@ function load_active($mode = false, $module_url = false, $execute_module = true)
// Add url_extra parameter to u_action url
if (!empty($this->module_ary) && $this->active_module !== false && $this->module_ary[$this->active_module_row_id]['url_extra'])
{
$this->module->u_action .= $this->module_ary[$this->active_module_row_id]['url_extra'];
$this->module->u_action .= '&' . $this->module_ary[$this->active_module_row_id]['url_extra'];
}

// Assign the module path for re-usage
Expand Down Expand Up @@ -920,7 +920,7 @@ function assign_tpl_vars($module_url)
}

// Was not allowed in categories before - /*!$item_ary['cat'] && */
$u_title .= (isset($item_ary['url_extra'])) ? $item_ary['url_extra'] : '';
$u_title .= (isset($item_ary['url_extra']) && $item_ary['url_extra']) ? '&' . $item_ary['url_extra'] : '';

// Only output a categories items if it's currently selected
if (!$depth || ($depth && (in_array($item_ary['parent'], array_values($this->module_cache['parents'])) || $item_ary['parent'] == $this->p_parent)))
Expand Down
35 changes: 35 additions & 0 deletions tests/functional/mcp/mcp_logs_test.php
@@ -0,0 +1,35 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/

/**
* @group functional
*/
class phpbb_functional_mcp_logs_test extends phpbb_functional_test_case
{
public function test_delete_logs()
{
$this->add_lang(['mcp', 'common']);

$this->login();
$crawler = self::request('GET', "mcp.php?i=mcp_logs&mode=front&sid={$this->sid}");
$this->assertGreaterThanOrEqual(1, $crawler->filter('input[type=checkbox]')->count());

$form = $crawler->selectButton($this->lang('DELETE_ALL'))->form();
$crawler = self::submit($form);

$form = $crawler->selectButton($this->lang('YES'))->form();
$crawler = self::submit($form);

$this->assertCount(0, $crawler->filter('input[type=checkbox]'));
}
}