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)
This commit is contained in:
parent
e182ebd8bf
commit
0d35bd7fbd
1 changed files with 13 additions and 4 deletions
|
|
@ -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 );
|
||||
|
|
|
|||
Loading…
Reference in a new issue