3 * Some functions that are useful during startup.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Some functions that are useful during startup.
27 static $compilerVersion;
30 * Get the version of HipHop used to compile, or false if MediaWiki was not
31 * compiled. This works by having our build script insert a special function
32 * into the compiled code.
34 static function getCompilerVersion() {
35 if ( self
::$compilerVersion === null ) {
36 if ( self
::functionExists( 'wfHipHopCompilerVersion' ) ) {
37 self
::$compilerVersion = wfHipHopCompilerVersion();
39 self
::$compilerVersion = false;
42 return self
::$compilerVersion;
46 * Returns true if we are running under HipHop, whether in compiled or
51 static function isHipHop() {
52 return function_exists( 'hphp_thread_set_warmup_enabled' );
56 * Get a fully-qualified path for a source file relative to $IP. Including
57 * such a path under HipHop will force the file to be interpreted. This is
58 * useful for configuration files.
64 static function interpretedPath( $file ) {
70 * If we are running code compiled by HipHop, this will pass through the
71 * input path, assumed to be relative to $IP. If the code is interpreted,
72 * it will converted to a fully qualified path. It is necessary to use a
73 * path which is relative to $IP in order to make HipHop use its compiled
80 static function compiledPath( $file ) {
83 if ( defined( 'MW_COMPILED' ) ) {
84 return "phase3/$file";
91 * The equivalent of MWInit::interpretedPath() but for files relative to the
92 * extensions directory.
97 static function extInterpretedPath( $file ) {
98 return self
::getExtensionsDirectory() . '/' . $file;
102 * The equivalent of MWInit::compiledPath() but for files relative to the
103 * extensions directory. Any files referenced in this way must be registered
104 * for compilation by including them in $wgCompiledFiles.
105 * @param $file string
108 static function extCompiledPath( $file ) {
109 if ( defined( 'MW_COMPILED' ) ) {
110 return "extensions/$file";
112 return self
::getExtensionsDirectory() . '/' . $file;
117 * Register an extension setup file and return its path for compiled
118 * inclusion. Use this function in LocalSettings.php to add extensions
119 * to the build. For example:
121 * require( MWInit::extSetupPath( 'ParserFunctions/ParserFunctions.php' ) );
123 * @param string $extRel The path relative to the extensions directory, as defined by
124 * $wgExtensionsDirectory.
128 static function extSetupPath( $extRel ) {
129 $baseRel = "extensions/$extRel";
130 if ( defined( 'MW_COMPILED' ) ) {
133 global $wgCompiledFiles;
134 $wgCompiledFiles[] = $baseRel;
135 return self
::getExtensionsDirectory() . '/' . $extRel;
140 * @return bool|string
142 static function getExtensionsDirectory() {
143 global $wgExtensionsDirectory, $IP;
144 if ( $wgExtensionsDirectory === false ) {
145 $wgExtensionsDirectory = "$IP/../extensions";
147 return $wgExtensionsDirectory;
151 * Determine whether a class exists, using a method which works under HipHop.
153 * Note that it's not possible to implement this with any variant of
154 * class_exists(), because class_exists() returns false for classes which
157 * Calling class_exists() on a literal string causes the class to be made
158 * "volatile", which means (as of March 2011) that the class is broken and
159 * can't be used at all. So don't do that. See
160 * https://github.com/facebook/hiphop-php/issues/314
162 * @param $class string
166 static function classExists( $class ) {
168 $r = new ReflectionClass( $class );
169 } catch( ReflectionException
$r ) {
176 * Determine whether a method exists within a class, using a method which works
179 * Note that under HipHop when method_exists is given a string for it's class
180 * such as to test for a static method has the same issues as class_exists does.
182 * @param $class string
183 * @param $method string
187 static function methodExists( $class, $method ) {
189 $r = new ReflectionMethod( $class, $method );
190 } catch( ReflectionException
$r ) {
197 * Determine whether a function exists, using a method which works under
200 * @param $function string
204 static function functionExists( $function ) {
206 $r = new ReflectionFunction( $function );
207 } catch( ReflectionException
$r ) {
214 * Call a static method of a class with variable arguments without causing
215 * it to become volatile.
216 * @param $className string
217 * @param $methodName string
222 static function callStaticMethod( $className, $methodName, $args ) {
223 $r = new ReflectionMethod( $className, $methodName );
224 return $r->invokeArgs( null, $args );