From 0d35bd7fbd0e23a5912683e2fa8f6b6e98dcd6ec Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 4 Nov 2025 13:39:32 -0800 Subject: [PATCH] maintenance/getConfiguration.php: Fix null warning and serialize error When invoked without options, the default has two issues: ``` PHP Deprecated: strtolower(): Passing null to parameter of type string is deprecated in /mediawiki/maintenance/getConfiguration.php on line 135 ``` This is because despite the constructor and validateParamsAndArgs treating --format as optional with default, execute() did not. ``` Exception: Serialization of Closure is not allowed ``` ... from $wgHooks ``` LogicException: Instances of OutputPage are not serializable ``` ... directly from $wgOut, and indirectly via ContextSource from $wgUser and $wgRequest. Change-Id: I2efa7835ff47084472c7fb079f93077b736057cb (cherry picked from commit fc397136495f76f1a00e454da060d6526d6ad293) --- maintenance/getConfiguration.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/maintenance/getConfiguration.php b/maintenance/getConfiguration.php index 0015ca09a38..45e6a3264aa 100644 --- a/maintenance/getConfiguration.php +++ b/maintenance/getConfiguration.php @@ -39,6 +39,9 @@ class GetConfiguration extends Maintenance { /** @var string|null */ protected $regex = null; + /** @var string|null */ + protected $format = null; + /** @var array */ protected $settings_list = []; @@ -72,9 +75,9 @@ class GetConfiguration extends Maintenance { $error_out = false; # Get the format and make sure it is set to a valid default value - $format = strtolower( $this->getOption( 'format', 'PHP' ) ); + $this->format = strtolower( $this->getOption( 'format', 'PHP' ) ); - $validFormat = in_array( $format, self::OUT_FORMATS ); + $validFormat = in_array( $this->format, self::OUT_FORMATS ); if ( !$validFormat ) { $this->error( "--format set to an unrecognized format" ); $error_out = true; @@ -124,7 +127,13 @@ class GetConfiguration extends Maintenance { # Default: dump any wg / wmg variable if ( !$this->regex && !$this->getOption( 'settings' ) ) { - $this->regex = '/^wm?g/'; + // Avoid fatal "Exception: Serialization of Closure is not allowed" + // + // * Exclude legacy singletons that are not configuration but + // non-serializable objects, such as $wgUser. + // * Exclude config arrays such as wgHooks which may contain closures + // via LocalSettings.php. + $this->regex = '/^wm?g(?!User|Out|Request|Hooks).*$/'; } # Filter out globals based on the regex @@ -145,7 +154,7 @@ class GetConfiguration extends Maintenance { ksort( $res ); - switch ( strtolower( $this->getOption( 'format' ) ) ) { + switch ( $this->format ) { case 'serialize': case 'php': $out = serialize( $res );