Page MenuHomePhabricator

Allow MW_CONFIG_FILE to be set as environment variable
Open, Needs TriagePublic

Description

In Webstart.php the path of LocalSettings.php is determined as follows

// If no LocalSettings file exists, try to display an error page
   60 // (use a callback because it depends on TemplateParser)
   61 if ( !defined( 'MW_CONFIG_CALLBACK' ) ) {
   62     if ( !defined( 'MW_CONFIG_FILE' ) ) {
   63         define( 'MW_CONFIG_FILE', "$IP/LocalSettings.php" );
   64     }
   65     if ( !is_readable( MW_CONFIG_FILE ) ) {
   66         function wfWebStartNoLocalSettings() {
   67             # LocalSettings.php is the per-site customization file. If it does not exist
   68             # the wiki installer needs to be launched or the generated file uploaded to
   69             # the root wiki directory. Give a hint, if it is not readable by the server.
   70             global $IP;
   71             require_once "$IP/includes/NoLocalSettings.php";
   72             die();
   73         }
   74         define( 'MW_CONFIG_CALLBACK', 'wfWebStartNoLocalSettings' );
   75     }
   76 }

Could this be extended to

if ( defined( 'MW_CONFIG_CALLBACK' ) )
{
	# Use a callback function to configure MediaWiki
	call_user_func( MW_CONFIG_CALLBACK );
} else
{
	if ( !defined( 'MW_CONFIG_FILE' ) )
	{
		$mediawiki_configuration_file = apache_getenv( 'MW_CONFIG_FILE' );
		if ( $mediawiki_configuration_file === false )
		{
			define( 'MW_CONFIG_FILE', "LocalSettings.php" );
		}
		else
		{
			define( 'MW_CONFIG_FILE', $mediawiki_configuration_file );
		}
	}

	# LocalSettings.php is the per site customization file. If it does not exist
	# the wiki installer needs to be launched or the generated file uploaded to
	# the root wiki directory. Give a hint, if it is not readable by the server.
	if ( !is_readable( MW_CONFIG_FILE ) )
	{
		require_once "$IP/includes/NoLocalSettings.php";
		die();
	}

	# Include site settings. $IP may be changed (hopefully before the AutoLoader is invoked)

	require_once MW_CONFIG_FILE;
}

This allows the configuration file to be located at a different place as specified by the webserver. This makes wiki farming also easier.

Event Timeline

Change 425583 had a related patch set uploaded (by BeeBringer; owner: BeeBringer):
[mediawiki/core@master] Allow MW_CONFIG_FILE to be set as environment variable.

https://gerrit.wikimedia.org/r/425583

Hallo, @BeeBringer,
Thanks for working on this.
I guess your patch would have a better luck of getting merged, had it been realised in Setup.php instead of Webstart.php, because the earlier is where MW_CONFIG_FILE is expected to be setup for all entry points, web, maintenance scripts, etc.

Also, PHP's getenv calls apache_getenv if running within the Apache SAPI, otherwise it asks the system. So, it's better to stick with getenv.