On 29/06/10 11:30, Samuel Lampa wrote:
Is it possible to include LocalSettings.php in an external PHP script without just getting as output:
"This file is part of MediaWiki and is not a valid entry point"
(I would like to avoid duplication of some configurations, like database settings)
Unfortunately LocalSettings.php mixes MediaWiki-specific setup code with configuration data. The easiest way to fix it would be to replace this:
require_once( "$IP/includes/DefaultSettings.php" );
With this:
if ( !defined( 'MY_EXTERNAL_SCRIPT' ) ) { require_once( "$IP/includes/DefaultSettings.php" ); }
Then in your external script:
define( 'MY_EXTERNAL_SCRIPT', 1 ); require( "$wiki/LocalSettings.php" );
This maintains security while skipping most of the setup code, including default settings. If you decide you need the default settings, or if that method gives you an error due to nonexistent classes, then you should probably use WebStart.php instead of LocalSettings.php. Then in your external script you would have:
define( 'MW_NO_SETUP', 1 ); require( "$wiki/includes/WebStart.php" );
This initialises MediaWiki properly, including reading all configuration. It's more intrusive than just reading LocalSettings.php, it defines functions and classes which could potentially conflict with your external script.
-- Tim Starling