From 0e054835f17aaf019ced1a7b6b4c88930b84d2b6 Mon Sep 17 00:00:00 2001 From: Sam Pearson Date: Tue, 1 Apr 2025 09:52:13 +0100 Subject: [PATCH 1/6] [PHP] Remove $context from error handler functions I think this is safe to remove completely. See: https://www.php.net/manual/en/migration80.incompatible.php --- phplib/admin.php | 2 +- phplib/error.php | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/phplib/admin.php b/phplib/admin.php index a9a48332..2ffdc7c1 100644 --- a/phplib/admin.php +++ b/phplib/admin.php @@ -13,7 +13,7 @@ // Error display require_once dirname(__FILE__) . "/error.php"; -function admin_display_error($num, $message, $file, $line, $context) { +function admin_display_error($num, $message, $file, $line) { print "

$message in $file:$line

"; } err_set_handler_display('admin_display_error'); diff --git a/phplib/error.php b/phplib/error.php index e432fe3e..27dc0452 100644 --- a/phplib/error.php +++ b/phplib/error.php @@ -58,20 +58,14 @@ function err($str, $num = E_USER_ERROR) { $i = 1; if (!array_key_exists('file', $a[$i])) $a[$i]['file'] = '(unknown file)'; if (!array_key_exists('line', $a[$i])) $a[$i]['line'] = '(unknown line)'; - err_global_handler($num, $str, $a[$i]['file'], $a[$i]['line'], - /* XXX We can't obtain the calling context AFAIK. */ - null); + err_global_handler($num, $str, $a[$i]['file'], $a[$i]['line']); exit(1); /* NOTREACHED */ } -/* err_log_webserver NUMBER STRING FILE LINE CONTEXT +/* err_log_webserver NUMBER STRING FILE LINE * Log the error with the given parameters, trying to arrange that it reach the * appropriate web server error log. */ -function err_log_webserver($num, $str, $file, $line, $context) { -#print "
";
-#print_r($context);
-#error_log(print_r($context, TRUE));
-#print "
"; +function err_log_webserver($num, $str, $file, $line) { /* Apache (and perhaps other webservers) logs errors preceded by a tag * giving the time and "severity" of the error. The time is in the format @@ -110,9 +104,9 @@ function err_log_webserver($num, $str, $file, $line, $context) { $err_handler_display = null; $err_handling_error = false; // true if currently handling an error -/* err_global_handler NUMBER STRING FILE LINE CONTEXT +/* err_global_handler NUMBER STRING FILE LINE * Handler for all categories of errors. */ -function err_global_handler($num, $str, $file, $line, $context) { +function err_global_handler($num, $str, $file, $line) { global $err_handler_log; global $err_handler_display; global $err_handling_error; @@ -120,11 +114,11 @@ function err_global_handler($num, $str, $file, $line, $context) { $err_handling_error = true; if (isset($err_handler_log) && $num != E_USER_NOTICE) - $err_handler_log($num, $str, $file, $line, $context); + $err_handler_log($num, $str, $file, $line); if (isset($err_handler_display)) - $err_handler_display($num, $str, $file, $line, $context); + $err_handler_display($num, $str, $file, $line); else - $err_handler_log($num, "no error display handler set", $file, $line, $context); + $err_handler_log($num, "no error display handler set", $file, $line); exit(1); } From 75345e466104709272503ea6c6cad652a82274d5 Mon Sep 17 00:00:00 2001 From: Sam Pearson Date: Tue, 1 Apr 2025 10:06:05 +0100 Subject: [PATCH 2/6] [PHP] Ensure userpwd is declared as dynamic properties are deprecated See: https://www.php.net/manual/en/migration82.deprecated.php --- phplib/rabx.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phplib/rabx.php b/phplib/rabx.php index 298d1320..4d79c27c 100644 --- a/phplib/rabx.php +++ b/phplib/rabx.php @@ -316,7 +316,7 @@ function microtime_float() class RABX_Client { - var $ch, $url, $use_post = FALSE; + var $ch, $url, $use_post, $userpwd = FALSE; var $lastt; /* constructor URL [USERPWD] From b74151fe26f0e41f0252195f5ded1183ba56f9dc Mon Sep 17 00:00:00 2001 From: Sam Pearson Date: Tue, 1 Apr 2025 10:11:33 +0100 Subject: [PATCH 3/6] [PHP] Fix Array and string offset access syntax with curly braces Quickform's data.php used curly braces for offset access; fixed. See: https://www.php.net/manual/en/migration80.incompatible.php --- phplib/HTML/QuickForm/date.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phplib/HTML/QuickForm/date.php b/phplib/HTML/QuickForm/date.php index 75634e7e..22c0e56c 100644 --- a/phplib/HTML/QuickForm/date.php +++ b/phplib/HTML/QuickForm/date.php @@ -326,7 +326,7 @@ function _createElements() $locale =& $this->_locale[$this->_options['language']]; $backslash = false; for ($i = 0, $length = strlen($this->_options['format']); $i < $length; $i++) { - $sign = $this->_options['format']{$i}; + $sign = $this->_options['format'][$i]; if ($backslash) { $backslash = false; $separator .= $sign; From 522217daea0dc05004a4837a2f9a5cdc1de9ce1b Mon Sep 17 00:00:00 2001 From: Sam Pearson Date: Tue, 1 Apr 2025 10:21:01 +0100 Subject: [PATCH 4/6] [PHP] Standardise breaking from `switch` in IsterSimpleXMLElement.php Using `continue` generates a warning we're not skipping the rest of the `foreach` loop but only jumping out of the `switch` block as we would if we used `break`. To explicitly move to the next iteration of the containing loop, we should use `continue 2`. However in this case it is academic as there is no more code after the `switch`, so I'm using `break` for consistency with the rest of the code. --- phplib/simplexml44-0_4_4/class/IsterSimpleXMLElement.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phplib/simplexml44-0_4_4/class/IsterSimpleXMLElement.php b/phplib/simplexml44-0_4_4/class/IsterSimpleXMLElement.php index cc3ad536..83f1ea4d 100644 --- a/phplib/simplexml44-0_4_4/class/IsterSimpleXMLElement.php +++ b/phplib/simplexml44-0_4_4/class/IsterSimpleXMLElement.php @@ -155,14 +155,14 @@ function CDATA() switch( $child->___t ) { case ISTER_XML_CDATA: if( preg_match('/^()$/', $child->___n) ) - continue; + break; $txt .= $child->___n; break; case ISTER_XML_ENTITY: $txt .= $child->___ns; break; default: - continue; + break; } } return $txt; From 020b67e1b59eb8649608ac9b445365961f615e6f Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 3 Apr 2025 10:40:10 +0100 Subject: [PATCH 5/6] allow email_get_containing to use similar to instead of like Lets you do a bit more subtle matching --- perllib/mySociety/WebTestHarness.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/perllib/mySociety/WebTestHarness.pm b/perllib/mySociety/WebTestHarness.pm index 22a873ef..9a7e8967 100644 --- a/perllib/mySociety/WebTestHarness.pm +++ b/perllib/mySociety/WebTestHarness.pm @@ -669,8 +669,8 @@ mails are found within a few seconds, or there is more than one match. The email is returned with any quoted printable characters decoded. =cut -sub email_get_containing($$) { - my ($self, $check) = @_; +sub email_get_containing($$;$) { + my ($self, $check, $regex) = @_; die "STRING must be scalar or array" if (ref($check) ne 'ARRAY' && ref($check) ne ''); $check = [ $check ] if (ref($check) eq ''); @@ -688,7 +688,8 @@ sub email_get_containing($$) { my $quoted_c = encode_qp($c, ""); push @params, $quoted_c; } - $qfragment = join($bool, map { 'content like ?' } @params); + my $match_op = defined $regex ? 'content similar to ?' : 'content like ?'; + $qfragment = join($bool, map { $match_op } @params); $qdesc = join($bool, map { "'$_'" } @params); # Provoke any sending of mails From 07ac9ea65b3a1dddf8351ed6c1b8bb25304ceebd Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 3 Apr 2025 12:28:36 +0100 Subject: [PATCH 6/6] update ratty admin class to new style constructor and properties --- phplib/admin-ratty.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/phplib/admin-ratty.php b/phplib/admin-ratty.php index 032b4ed0..989d786f 100644 --- a/phplib/admin-ratty.php +++ b/phplib/admin-ratty.php @@ -28,7 +28,15 @@ class ADMIN_PAGE_RATTY { * message field in rate-limiting rules (e.g., "HTML fragment to be * displayed to user when rule fires."). The contents of MESSAGEBLURB will * be displayed inside a
. */ - function ADMIN_PAGE_RATTY($scope, $what, $description, $messageblurb) { + + public $id; + public $navname; + public $scope; + public $scope_title; + public $scope_description; + public $scope_messageblurb; + + function __construct($scope, $what, $description, $messageblurb) { $this->id = "ratty-" . $scope; $this->navname = "$what Rules";