wiki.techinc.nl/includes/Init.php
Tim Starling ff1dc8a175 HipHop improvements:
* Added the ability to compile extensions. The build process is bootstrapped by running MediaWiki in interpreted mode. Extension setup file inclusions are slightly modified in a way that makes them register themselves for compilation. Then the same LocalSettings.php uses the compiled extension setup file when the compiled binary runs.
* Tested with Cite and ParserFunctions. The code which lets you have an extensions directory in a place other than $IP/../extensions is untested.
* Simplified WebStart.php slightly by using a custom $_SERVER variable to mark compiled mode. It will break if you don't use the supplied server.conf, but that will break a lot of things so don't do that.
* Fixed the core web entry points to include WebStart.php in compiled mode instead of interpreted.
* Made the build directory configurable. This is mostly so that I can grep the source tree without seeing loads of generated C++.
* In server.conf, added a rewrite rule allowing a /wiki/$1 article path.
* Removed server.conf log file location "/dev/stdout", breaks when you switch user
* Disable static content cache, breaks horribly when you set SourceRoot to a directory containing 7GB of files.
* Rewrote the run-server script in PHP, mostly to support the configurable build directory feature.
* Added an option to the run-server script to allow running in interpreted (hphpi) mode.
2011-05-30 13:49:09 +00:00

170 lines
4.4 KiB
PHP

<?php
/**
* Some functions that are useful during startup.
*/
class MWInit {
static $compilerVersion;
/**
* Get the version of HipHop used to compile, or false if MediaWiki was not
* compiled. This works by having our build script insert a special function
* into the compiled code.
*/
static function getCompilerVersion() {
if ( self::$compilerVersion === null ) {
if ( self::functionExists( 'wfHipHopCompilerVersion' ) ) {
self::$compilerVersion = wfHipHopCompilerVersion();
} else {
self::$compilerVersion = false;
}
}
return self::$compilerVersion;
}
/**
* Returns true if we are running under HipHop, whether in compiled or
* interpreted mode.
*
* @return bool
*/
static function isHipHop() {
return function_exists( 'hphp_thread_set_warmup_enabled' );
}
/**
* Get a fully-qualified path for a source file relative to $IP. Including
* such a path under HipHop will force the file to be interpreted. This is
* useful for configuration files.
*
* @param $file string
*
* @return string
*/
static function interpretedPath( $file ) {
global $IP;
return "$IP/$file";
}
/**
* If we are running code compiled by HipHop, this will pass through the
* input path, assumed to be relative to $IP. If the code is interpreted,
* it will converted to a fully qualified path. It is necessary to use a
* path which is relative to $IP in order to make HipHop use its compiled
* code.
*
* @param $file string
*
* @return string
*/
static function compiledPath( $file ) {
global $IP;
if ( defined( 'MW_COMPILED' ) ) {
return "phase3/$file";
} else {
return "$IP/$file";
}
}
/**
* The equivalent of MWInit::interpretedPath() but for files relative to the
* extensions directory.
*/
static function extInterpretedPath( $file ) {
return getExtensionsDirectory() . '/' . $file;
}
/**
* The equivalent of MWInit::compiledPath() but for files relative to the
* extensions directory. Any files referenced in this way must be registered
* for compilation by including them in $wgCompiledFiles.
*/
static function extCompiledPath( $file ) {
if ( defined( 'MW_COMPILED' ) ) {
return "extensions/$file";
} else {
return getExtensionsDirectory() . '/' . $file;
}
}
/**
* Register an extension setup file and return its path for compiled
* inclusion. Use this function in LocalSettings.php to add extensions
* to the build. For example:
*
* require( MWInit::extSetupPath( 'ParserFunctions/ParserFunctions.php' ) );
*
* @param $path The path relative to the extensions directory, as defined by
* $wgExtensionsDirectory.
*/
static function extSetupPath( $extRel ) {
$baseRel = "extensions/$extRel";
if ( defined( 'MW_COMPILED' ) ) {
return $baseRel;
} else {
global $wgCompiledFiles;
$wgCompiledFiles[] = $baseRel;
return self::getExtensionsDirectory() . '/' . $extRel;
}
}
static function getExtensionsDirectory() {
global $wgExtensionsDirectory, $IP;
if ( $wgExtensionsDirectory === false ) {
$wgExtensionsDirectory = "$IP/../extensions";
}
return $wgExtensionsDirectory;
}
/**
* Determine whether a class exists, using a method which works under HipHop.
*
* Note that it's not possible to implement this with any variant of
* class_exists(), because class_exists() returns false for classes which
* are compiled in.
*
* Calling class_exists() on a literal string causes the class to be made
* "volatile", which means (as of March 2011) that the class is broken and
* can't be used at all. So don't do that. See
* https://github.com/facebook/hiphop-php/issues/314
*
* @param $class string
*
* @return bool
*/
static function classExists( $class ) {
try {
$r = new ReflectionClass( $class );
} catch( ReflectionException $r ) {
$r = false;
}
return $r !== false;
}
/**
* Determine whether a function exists, using a method which works under
* HipHop.
*
* @param $function string
*
* @return bool
*/
static function functionExists( $function ) {
try {
$r = new ReflectionFunction( $function );
} catch( ReflectionException $r ) {
$r = false;
}
return $r !== false;
}
/**
* Call a static method of a class with variable arguments without causing
* it to become volatile.
*/
static function callStaticMethod( $className, $methodName, $args ) {
$r = new ReflectionMethod( $className, $methodName );
return $r->invokeArgs( null, $args );
}
}