From 39b76a628b0c485b2ec96bbd2ea1bfea91ca4da3 Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Tue, 10 Jun 2014 16:13:09 +0200
Subject: [PATCH 01/12] [ticket/12687] Add a constant to display the load time
 without DEBUG

PHPBB3-12687
---
 phpBB/includes/functions.php     | 6 +++---
 phpBB/includes/functions_acp.php | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index be032440b9..f8c40b1638 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -5062,7 +5062,7 @@ function page_footer($run_cron = true, $display_template = true, $exit_handler =
 	}
 
 	// Output page creation time
-	if (defined('DEBUG'))
+	if (defined('DISPLAY_LOAD_TIME'))
 	{
 		$mtime = explode(' ', microtime());
 		$totaltime = $mtime[0] + $mtime[1] - $starttime;
@@ -5074,7 +5074,7 @@ function page_footer($run_cron = true, $display_template = true, $exit_handler =
 
 		$debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress'] && @extension_loaded('zlib')) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime);
 
-		if ($auth->acl_get('a_') && defined('DEBUG'))
+		if ($auth->acl_get('a_') && defined('DISPLAY_LOAD_TIME'))
 		{
 			if (function_exists('memory_get_peak_usage'))
 			{
@@ -5091,7 +5091,7 @@ function page_footer($run_cron = true, $display_template = true, $exit_handler =
 	}
 
 	$template->assign_vars(array(
-		'DEBUG_OUTPUT'			=> (defined('DEBUG')) ? $debug_output : '',
+		'DEBUG_OUTPUT'			=> (defined('DISPLAY_LOAD_TIME')) ? $debug_output : '',
 		'TRANSLATION_INFO'		=> (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',
 		'CREDIT_LINE'			=> $user->lang('POWERED_BY', '<a href="https://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Limited'),
 
diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php
index 373eb57934..4d0a20ce1f 100644
--- a/phpBB/includes/functions_acp.php
+++ b/phpBB/includes/functions_acp.php
@@ -147,7 +147,7 @@ function adm_page_footer($copyright_html = true)
 	}
 
 	// Output page creation time
-	if (defined('DEBUG'))
+	if (defined('DISPLAY_LOAD_TIME'))
 	{
 		$mtime = explode(' ', microtime());
 		$totaltime = $mtime[0] + $mtime[1] - $starttime;
@@ -159,7 +159,7 @@ function adm_page_footer($copyright_html = true)
 
 		$debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime);
 
-		if ($auth->acl_get('a_') && defined('DEBUG'))
+		if ($auth->acl_get('a_') && defined('DISPLAY_LOAD_TIME'))
 		{
 			if (function_exists('memory_get_peak_usage'))
 			{
@@ -176,7 +176,7 @@ function adm_page_footer($copyright_html = true)
 	}
 
 	$template->assign_vars(array(
-		'DEBUG_OUTPUT'		=> (defined('DEBUG')) ? $debug_output : '',
+		'DEBUG_OUTPUT'		=> (defined('DISPLAY_LOAD_TIME')) ? $debug_output : '',
 		'TRANSLATION_INFO'	=> (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',
 		'S_COPYRIGHT_HTML'	=> $copyright_html,
 		'CREDIT_LINE'		=> $user->lang('POWERED_BY', '<a href="https://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Limited'),

From 1e769ba87f3b2d510ad82e11e971fc2abcf8a8d0 Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Tue, 10 Jun 2014 17:52:41 +0200
Subject: [PATCH 02/12] [ticket/12687] Display the explain link only when DEBUG
 is set

PHPBB3-12687
---
 phpBB/includes/functions.php     | 18 ++++++++++++------
 phpBB/includes/functions_acp.php | 18 ++++++++++++------
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index f8c40b1638..66c0584d67 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -5074,19 +5074,25 @@ function page_footer($run_cron = true, $display_template = true, $exit_handler =
 
 		$debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress'] && @extension_loaded('zlib')) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime);
 
-		if ($auth->acl_get('a_') && defined('DISPLAY_LOAD_TIME'))
+		if ($auth->acl_get('a_'))
 		{
-			if (function_exists('memory_get_peak_usage'))
+			if (defined('DISPLAY_LOAD_TIME'))
 			{
-				if ($memory_usage = memory_get_peak_usage())
+				if (function_exists('memory_get_peak_usage'))
 				{
-					$memory_usage = get_formatted_filesize($memory_usage);
+					if ($memory_usage = memory_get_peak_usage())
+					{
+						$memory_usage = get_formatted_filesize($memory_usage);
 
-					$debug_output .= ' | Peak Memory Usage: ' . $memory_usage;
+						$debug_output .= ' | Peak Memory Usage: ' . $memory_usage;
+					}
 				}
 			}
 
-			$debug_output .= ' | <a href="' . build_url() . '&amp;explain=1">Explain</a>';
+			if (defined('DEBUG'))
+			{
+				$debug_output .= ' | <a href="' . build_url() . '&amp;explain=1">Explain</a>';
+			}
 		}
 	}
 
diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php
index 4d0a20ce1f..357832794d 100644
--- a/phpBB/includes/functions_acp.php
+++ b/phpBB/includes/functions_acp.php
@@ -159,19 +159,25 @@ function adm_page_footer($copyright_html = true)
 
 		$debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime);
 
-		if ($auth->acl_get('a_') && defined('DISPLAY_LOAD_TIME'))
+		if ($auth->acl_get('a_'))
 		{
-			if (function_exists('memory_get_peak_usage'))
+			if (defined('DISPLAY_LOAD_TIME'))
 			{
-				if ($memory_usage = memory_get_peak_usage())
+				if (function_exists('memory_get_peak_usage'))
 				{
-					$memory_usage = get_formatted_filesize($memory_usage);
+					if ($memory_usage = memory_get_peak_usage())
+					{
+						$memory_usage = get_formatted_filesize($memory_usage);
 
-					$debug_output .= ' | Peak Memory Usage: ' . $memory_usage;
+						$debug_output .= ' | Peak Memory Usage: ' . $memory_usage;
+					}
 				}
 			}
 
-			$debug_output .= ' | <a href="' . build_url() . '&amp;explain=1">Explain</a>';
+			if (defined('DEBUG'))
+			{
+				$debug_output .= ' | <a href="' . build_url() . '&amp;explain=1">Explain</a>';
+			}
 		}
 	}
 

From 06e6c915134d11db906d0275c2a75a6280a07ab6 Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Tue, 10 Jun 2014 18:24:58 +0200
Subject: [PATCH 03/12] [ticket/12687] Rename DISPLAY_LOAD_TIME to
 PHPBB_DISPLAY_LOAD_TIME

PHPBB3-12687
---
 phpBB/includes/functions.php     | 93 ++++++++++++++++++++------------
 phpBB/includes/functions_acp.php | 36 +------------
 2 files changed, 59 insertions(+), 70 deletions(-)

diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 66c0584d67..393fe6edb7 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -5029,6 +5029,63 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
 	return;
 }
 
+/**
+* Set the DEBUG_OUTPUT template var
+*/
+function display_debug_output()
+{
+	global $starttime, $template, $db, $config, $auth, $user, $request;
+
+	if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG') && method_exists($db, 'sql_report'))
+	{
+		$db->sql_report('display');
+	}
+
+	$debug_info = array();
+
+	// Output page creation time
+	if (defined('PHPBB_DISPLAY_LOAD_TIME'))
+	{
+		$mtime = explode(' ', microtime());
+		$totaltime = $mtime[0] + $mtime[1] - $starttime;
+
+		$debug_info[] = sprintf('Time : %.3fs', $totaltime);
+		$debug_info[] = $db->sql_num_queries() . ' Queries';
+
+		if ($auth->acl_get('a_'))
+		{
+			if (function_exists('memory_get_peak_usage'))
+			{
+				if ($memory_usage = memory_get_peak_usage())
+				{
+					$memory_usage = get_formatted_filesize($memory_usage);
+
+					$debug_info[] = 'Peak Memory Usage: ' . $memory_usage;
+				}
+			}
+		}
+	}
+
+	if (defined('DEBUG'))
+	{
+		$debug_info[] = 'GZIP : ' . (($config['gzip_compress'] && @extension_loaded('zlib')) ? 'On' : 'Off');
+
+		if ($user->load)
+		{
+			$debug_info[] = 'Load : ' . $user->load;
+		}
+
+		if ($auth->acl_get('a_'))
+		{
+			$debug_info[] = '<a href="' . build_url() . '&amp;explain=1">Explain</a>';
+		}
+	}
+
+	$template->assign_vars(array(
+			'DEBUG_OUTPUT'			=> implode(' | ', $debug_info),
+	));
+}
+
 /**
 * Generate page footer
 *
@@ -5061,43 +5118,9 @@ function page_footer($run_cron = true, $display_template = true, $exit_handler =
 		return;
 	}
 
-	// Output page creation time
-	if (defined('DISPLAY_LOAD_TIME'))
-	{
-		$mtime = explode(' ', microtime());
-		$totaltime = $mtime[0] + $mtime[1] - $starttime;
-
-		if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG') && method_exists($db, 'sql_report'))
-		{
-			$db->sql_report('display');
-		}
-
-		$debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress'] && @extension_loaded('zlib')) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime);
-
-		if ($auth->acl_get('a_'))
-		{
-			if (defined('DISPLAY_LOAD_TIME'))
-			{
-				if (function_exists('memory_get_peak_usage'))
-				{
-					if ($memory_usage = memory_get_peak_usage())
-					{
-						$memory_usage = get_formatted_filesize($memory_usage);
-
-						$debug_output .= ' | Peak Memory Usage: ' . $memory_usage;
-					}
-				}
-			}
-
-			if (defined('DEBUG'))
-			{
-				$debug_output .= ' | <a href="' . build_url() . '&amp;explain=1">Explain</a>';
-			}
-		}
-	}
+	display_debug_output();
 
 	$template->assign_vars(array(
-		'DEBUG_OUTPUT'			=> (defined('DISPLAY_LOAD_TIME')) ? $debug_output : '',
 		'TRANSLATION_INFO'		=> (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',
 		'CREDIT_LINE'			=> $user->lang('POWERED_BY', '<a href="https://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Limited'),
 
diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php
index 357832794d..86eaf856de 100644
--- a/phpBB/includes/functions_acp.php
+++ b/phpBB/includes/functions_acp.php
@@ -146,43 +146,9 @@ function adm_page_footer($copyright_html = true)
 		return;
 	}
 
-	// Output page creation time
-	if (defined('DISPLAY_LOAD_TIME'))
-	{
-		$mtime = explode(' ', microtime());
-		$totaltime = $mtime[0] + $mtime[1] - $starttime;
-
-		if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG') && method_exists($db, 'sql_report'))
-		{
-			$db->sql_report('display');
-		}
-
-		$debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime);
-
-		if ($auth->acl_get('a_'))
-		{
-			if (defined('DISPLAY_LOAD_TIME'))
-			{
-				if (function_exists('memory_get_peak_usage'))
-				{
-					if ($memory_usage = memory_get_peak_usage())
-					{
-						$memory_usage = get_formatted_filesize($memory_usage);
-
-						$debug_output .= ' | Peak Memory Usage: ' . $memory_usage;
-					}
-				}
-			}
-
-			if (defined('DEBUG'))
-			{
-				$debug_output .= ' | <a href="' . build_url() . '&amp;explain=1">Explain</a>';
-			}
-		}
-	}
+	display_debug_output();
 
 	$template->assign_vars(array(
-		'DEBUG_OUTPUT'		=> (defined('DISPLAY_LOAD_TIME')) ? $debug_output : '',
 		'TRANSLATION_INFO'	=> (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',
 		'S_COPYRIGHT_HTML'	=> $copyright_html,
 		'CREDIT_LINE'		=> $user->lang('POWERED_BY', '<a href="https://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Limited'),

From ceef85ee0e4e425b5f1a79a378506752d46cef02 Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Thu, 12 Jun 2014 14:33:00 +0200
Subject: [PATCH 04/12] [ticket/12687] Return a string and move the displaying
 of the sql report

PHPBB3-12687
---
 phpBB/includes/functions.php     | 35 ++++++++++++++++++--------------
 phpBB/includes/functions_acp.php |  3 ++-
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 393fe6edb7..96c2c4132e 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -5030,16 +5030,24 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
 }
 
 /**
-* Set the DEBUG_OUTPUT template var
+* Check and display the SQL report if requested.
 */
-function display_debug_output()
+function phpbb_check_and_display_sql_report()
 {
-	global $starttime, $template, $db, $config, $auth, $user, $request;
+	global $request, $auth, $db;
 
 	if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG') && method_exists($db, 'sql_report'))
 	{
 		$db->sql_report('display');
 	}
+}
+
+/**
+* Set the DEBUG_OUTPUT template var
+*/
+function phpbb_generate_debug_output()
+{
+	global $starttime, $db, $config, $auth, $user;
 
 	$debug_info = array();
 
@@ -5052,16 +5060,14 @@ function display_debug_output()
 		$debug_info[] = sprintf('Time : %.3fs', $totaltime);
 		$debug_info[] = $db->sql_num_queries() . ' Queries';
 
-		if ($auth->acl_get('a_'))
+		if (function_exists('memory_get_peak_usage'))
 		{
-			if (function_exists('memory_get_peak_usage'))
+			$memory_usage = memory_get_peak_usage();
+			if ($memory_usage)
 			{
-				if ($memory_usage = memory_get_peak_usage())
-				{
-					$memory_usage = get_formatted_filesize($memory_usage);
+				$memory_usage = get_formatted_filesize($memory_usage);
 
-					$debug_info[] = 'Peak Memory Usage: ' . $memory_usage;
-				}
+				$debug_info[] = 'Peak Memory Usage: ' . $memory_usage;
 			}
 		}
 	}
@@ -5077,13 +5083,11 @@ function display_debug_output()
 
 		if ($auth->acl_get('a_'))
 		{
-			$debug_info[] = '<a href="' . build_url() . '&amp;explain=1">Explain</a>';
+			$debug_info[] = '<a href="' . build_url() . '&amp;explain=1">SQL Explain</a>';
 		}
 	}
 
-	$template->assign_vars(array(
-			'DEBUG_OUTPUT'			=> implode(' | ', $debug_info),
-	));
+	return implode(' | ', $debug_info);
 }
 
 /**
@@ -5118,9 +5122,10 @@ function page_footer($run_cron = true, $display_template = true, $exit_handler =
 		return;
 	}
 
-	display_debug_output();
+	phpbb_check_and_display_sql_report();
 
 	$template->assign_vars(array(
+		'DEBUG_OUTPUT'			=> phpbb_generate_debug_output(),
 		'TRANSLATION_INFO'		=> (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',
 		'CREDIT_LINE'			=> $user->lang('POWERED_BY', '<a href="https://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Limited'),
 
diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php
index 86eaf856de..037749f7e9 100644
--- a/phpBB/includes/functions_acp.php
+++ b/phpBB/includes/functions_acp.php
@@ -146,9 +146,10 @@ function adm_page_footer($copyright_html = true)
 		return;
 	}
 
-	display_debug_output();
+	phpbb_check_and_display_sql_report();
 
 	$template->assign_vars(array(
+		'DEBUG_OUTPUT'		=> phpbb_generate_debug_output(),
 		'TRANSLATION_INFO'	=> (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',
 		'S_COPYRIGHT_HTML'	=> $copyright_html,
 		'CREDIT_LINE'		=> $user->lang('POWERED_BY', '<a href="https://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Limited'),

From 6c0fd61b1df5e3c1245aa4a8d3c7e991de7a2dbf Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Thu, 12 Jun 2014 23:27:19 +0200
Subject: [PATCH 05/12] [ticket/12687] Remove globals

PHPBB3-12687
---
 phpBB/includes/functions.php     | 16 ++++++----------
 phpBB/includes/functions_acp.php |  4 ++--
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 96c2c4132e..3634e9a01c 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -5032,10 +5032,8 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
 /**
 * Check and display the SQL report if requested.
 */
-function phpbb_check_and_display_sql_report()
+function phpbb_check_and_display_sql_report($request, $auth, $db)
 {
-	global $request, $auth, $db;
-
 	if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG') && method_exists($db, 'sql_report'))
 	{
 		$db->sql_report('display');
@@ -5043,19 +5041,17 @@ function phpbb_check_and_display_sql_report()
 }
 
 /**
-* Set the DEBUG_OUTPUT template var
+* Generate the debug output string
 */
-function phpbb_generate_debug_output()
+function phpbb_generate_debug_output($db, $config, $auth, $user)
 {
-	global $starttime, $db, $config, $auth, $user;
-
 	$debug_info = array();
 
 	// Output page creation time
 	if (defined('PHPBB_DISPLAY_LOAD_TIME'))
 	{
 		$mtime = explode(' ', microtime());
-		$totaltime = $mtime[0] + $mtime[1] - $starttime;
+		$totaltime = $mtime[0] + $mtime[1] - $GLOBALS['starttime'];
 
 		$debug_info[] = sprintf('Time : %.3fs', $totaltime);
 		$debug_info[] = $db->sql_num_queries() . ' Queries';
@@ -5122,10 +5118,10 @@ function page_footer($run_cron = true, $display_template = true, $exit_handler =
 		return;
 	}
 
-	phpbb_check_and_display_sql_report();
+	phpbb_check_and_display_sql_report($request, $auth, $db);
 
 	$template->assign_vars(array(
-		'DEBUG_OUTPUT'			=> phpbb_generate_debug_output(),
+		'DEBUG_OUTPUT'			=> phpbb_generate_debug_output($db, $config, $auth, $user),
 		'TRANSLATION_INFO'		=> (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',
 		'CREDIT_LINE'			=> $user->lang('POWERED_BY', '<a href="https://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Limited'),
 
diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php
index 037749f7e9..8453da6e6e 100644
--- a/phpBB/includes/functions_acp.php
+++ b/phpBB/includes/functions_acp.php
@@ -146,10 +146,10 @@ function adm_page_footer($copyright_html = true)
 		return;
 	}
 
-	phpbb_check_and_display_sql_report();
+	phpbb_check_and_display_sql_report($request, $auth, $db);
 
 	$template->assign_vars(array(
-		'DEBUG_OUTPUT'		=> phpbb_generate_debug_output(),
+		'DEBUG_OUTPUT'		=> phpbb_generate_debug_output($db, $config, $auth, $user),
 		'TRANSLATION_INFO'	=> (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '',
 		'S_COPYRIGHT_HTML'	=> $copyright_html,
 		'CREDIT_LINE'		=> $user->lang('POWERED_BY', '<a href="https://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Limited'),

From b93269f7bbb44e162932123c5b5a59990fdb1d87 Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Thu, 12 Jun 2014 23:35:55 +0200
Subject: [PATCH 06/12] [ticket/12687] Use microtime(true)

PHPBB3-12687
---
 phpBB/includes/functions.php | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 3634e9a01c..d0445841f4 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -5050,8 +5050,7 @@ function phpbb_generate_debug_output($db, $config, $auth, $user)
 	// Output page creation time
 	if (defined('PHPBB_DISPLAY_LOAD_TIME'))
 	{
-		$mtime = explode(' ', microtime());
-		$totaltime = $mtime[0] + $mtime[1] - $GLOBALS['starttime'];
+		$totaltime = microtime(true) - $GLOBALS['starttime'];
 
 		$debug_info[] = sprintf('Time : %.3fs', $totaltime);
 		$debug_info[] = $db->sql_num_queries() . ' Queries';

From d70554760f9586f2cb0b80d713b7956c7560f916 Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Thu, 12 Jun 2014 23:43:01 +0200
Subject: [PATCH 07/12] [ticket/12687] Update doc block

PHPBB3-12687
---
 phpBB/includes/functions.php | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index d0445841f4..3bad7684bc 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -5031,10 +5031,14 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
 
 /**
 * Check and display the SQL report if requested.
+*
+* @param phpbb\request\request					$request	Request object
+* @param \phpbb\auth\auth						$auth		Auth object
+* @param \phpbb\db\driver\driver_interface		$db			Database connection
 */
-function phpbb_check_and_display_sql_report($request, $auth, $db)
+function phpbb_check_and_display_sql_report(phpbb\request\request $request, \phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db)
 {
-	if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG') && method_exists($db, 'sql_report'))
+	if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG'))
 	{
 		$db->sql_report('display');
 	}
@@ -5042,8 +5046,14 @@ function phpbb_check_and_display_sql_report($request, $auth, $db)
 
 /**
 * Generate the debug output string
+*
+* @param \phpbb\db\driver\driver_interface	$db			Database connection
+* @param \phpbb\config\config				$config		Config object
+* @param \phpbb\auth\auth					$auth		Auth object
+* @param \phpbb\user						$user		User object
+* @return string
 */
-function phpbb_generate_debug_output($db, $config, $auth, $user)
+function phpbb_generate_debug_output(phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\auth\auth $auth, \phpbb\user $user)
 {
 	$debug_info = array();
 

From f7f65fe6c2d77682214d3aca0fcfcd185566475b Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Fri, 13 Jun 2014 00:03:27 +0200
Subject: [PATCH 08/12] [ticket/12687] Fix the namespace of $request

PHPBB3-12687
---
 phpBB/includes/functions.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 3bad7684bc..e554ee8cee 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -5032,11 +5032,11 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
 /**
 * Check and display the SQL report if requested.
 *
-* @param phpbb\request\request					$request	Request object
+* @param \phpbb\request\request_interface		$request	Request object
 * @param \phpbb\auth\auth						$auth		Auth object
 * @param \phpbb\db\driver\driver_interface		$db			Database connection
 */
-function phpbb_check_and_display_sql_report(phpbb\request\request $request, \phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db)
+function phpbb_check_and_display_sql_report(\phpbb\request\request_interface $request, \phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db)
 {
 	if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG'))
 	{

From dc4132a49458b4a0ce8e8a80cf329e902108b575 Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Fri, 13 Jun 2014 14:53:30 +0200
Subject: [PATCH 09/12] [ticket/12687] Wrap $GLOBALS['starttime'] in a if

PHPBB3-12687
---
 phpBB/includes/functions.php | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index e554ee8cee..7f36062c20 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -5060,9 +5060,12 @@ function phpbb_generate_debug_output(phpbb\db\driver\driver_interface $db, \phpb
 	// Output page creation time
 	if (defined('PHPBB_DISPLAY_LOAD_TIME'))
 	{
-		$totaltime = microtime(true) - $GLOBALS['starttime'];
+		if (isset($GLOBALS['starttime']))
+		{
+			$totaltime = microtime(true) - $GLOBALS['starttime'];
+			$debug_info[] = sprintf('Time : %.3fs', $totaltime);
+		}
 
-		$debug_info[] = sprintf('Time : %.3fs', $totaltime);
 		$debug_info[] = $db->sql_num_queries() . ' Queries';
 
 		if (function_exists('memory_get_peak_usage'))

From c605e8f42368aadd23ae00169a5e5489e400fc95 Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Fri, 13 Jun 2014 14:54:13 +0200
Subject: [PATCH 10/12] [ticket/12687] Don't check if memory_get_peak_usage()
 exists

PHPBB3-12687
---
 phpBB/includes/functions.php | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 7f36062c20..d1d23ffa13 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -5068,15 +5068,12 @@ function phpbb_generate_debug_output(phpbb\db\driver\driver_interface $db, \phpb
 
 		$debug_info[] = $db->sql_num_queries() . ' Queries';
 
-		if (function_exists('memory_get_peak_usage'))
+		$memory_usage = memory_get_peak_usage();
+		if ($memory_usage)
 		{
-			$memory_usage = memory_get_peak_usage();
-			if ($memory_usage)
-			{
-				$memory_usage = get_formatted_filesize($memory_usage);
+			$memory_usage = get_formatted_filesize($memory_usage);
 
-				$debug_info[] = 'Peak Memory Usage: ' . $memory_usage;
-			}
+			$debug_info[] = 'Peak Memory Usage: ' . $memory_usage;
 		}
 	}
 

From bbc63456f9d1424cc0c3d91ac780d76828b264ef Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Fri, 13 Jun 2014 14:55:29 +0200
Subject: [PATCH 11/12] [ticket/12687] Display the number of cached queries

PHPBB3-12687
---
 phpBB/includes/functions.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index d1d23ffa13..97d582a626 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -5066,7 +5066,7 @@ function phpbb_generate_debug_output(phpbb\db\driver\driver_interface $db, \phpb
 			$debug_info[] = sprintf('Time : %.3fs', $totaltime);
 		}
 
-		$debug_info[] = $db->sql_num_queries() . ' Queries';
+		$debug_info[] = $db->sql_num_queries() . ' Queries (' . $db->sql_num_queries(true) . ' cached)';
 
 		$memory_usage = memory_get_peak_usage();
 		if ($memory_usage)

From 8e9b27314b573e6a6554a811f719567d0380dcee Mon Sep 17 00:00:00 2001
From: Tristan Darricau <github@nicofuma.fr>
Date: Fri, 13 Jun 2014 14:56:55 +0200
Subject: [PATCH 12/12] [ticket/12687] Remove french spaces

PHPBB3-12687
---
 phpBB/includes/functions.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 97d582a626..dafbb54af5 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -5063,7 +5063,7 @@ function phpbb_generate_debug_output(phpbb\db\driver\driver_interface $db, \phpb
 		if (isset($GLOBALS['starttime']))
 		{
 			$totaltime = microtime(true) - $GLOBALS['starttime'];
-			$debug_info[] = sprintf('Time : %.3fs', $totaltime);
+			$debug_info[] = sprintf('Time: %.3fs', $totaltime);
 		}
 
 		$debug_info[] = $db->sql_num_queries() . ' Queries (' . $db->sql_num_queries(true) . ' cached)';
@@ -5079,11 +5079,11 @@ function phpbb_generate_debug_output(phpbb\db\driver\driver_interface $db, \phpb
 
 	if (defined('DEBUG'))
 	{
-		$debug_info[] = 'GZIP : ' . (($config['gzip_compress'] && @extension_loaded('zlib')) ? 'On' : 'Off');
+		$debug_info[] = 'GZIP: ' . (($config['gzip_compress'] && @extension_loaded('zlib')) ? 'On' : 'Off');
 
 		if ($user->load)
 		{
-			$debug_info[] = 'Load : ' . $user->load;
+			$debug_info[] = 'Load: ' . $user->load;
 		}
 
 		if ($auth->acl_get('a_'))