No more undefined usage of rev{Start,End}Id warnings
[mediawiki.git] / includes / Init.php
blob5bfd3f5c4b91d1a0b235f8ea1b299353adb1e70b
1 <?php
3 /**
4 * Some functions that are useful during startup.
5 */
6 class MWInit {
7 static $compilerVersion;
9 /**
10 * Get the version of HipHop used to compile, or false if MediaWiki was not
11 * compiled. This works by having our build script insert a special function
12 * into the compiled code.
14 static function getCompilerVersion() {
15 if ( self::$compilerVersion === null ) {
16 if ( self::functionExists( 'wfHipHopCompilerVersion' ) ) {
17 self::$compilerVersion = wfHipHopCompilerVersion();
18 } else {
19 self::$compilerVersion = false;
22 return self::$compilerVersion;
25 /**
26 * Returns true if we are running under HipHop, whether in compiled or
27 * interpreted mode.
29 * @return bool
31 static function isHipHop() {
32 return function_exists( 'hphp_thread_set_warmup_enabled' );
35 /**
36 * Get a fully-qualified path for a source file relative to $IP. Including
37 * such a path under HipHop will force the file to be interpreted. This is
38 * useful for configuration files.
40 * @param $file string
42 * @return string
44 static function interpretedPath( $file ) {
45 global $IP;
46 return "$IP/$file";
49 /**
50 * If we are running code compiled by HipHop, this will pass through the
51 * input path, assumed to be relative to $IP. If the code is interpreted,
52 * it will converted to a fully qualified path. It is necessary to use a
53 * path which is relative to $IP in order to make HipHop use its compiled
54 * code.
56 * @param $file string
58 * @return string
60 static function compiledPath( $file ) {
61 global $IP;
63 if ( defined( 'MW_COMPILED' ) ) {
64 return "phase3/$file";
65 } else {
66 return "$IP/$file";
70 /**
71 * The equivalent of MWInit::interpretedPath() but for files relative to the
72 * extensions directory.
74 * @param $file string
75 * @return string
77 static function extInterpretedPath( $file ) {
78 return self::getExtensionsDirectory() . '/' . $file;
81 /**
82 * The equivalent of MWInit::compiledPath() but for files relative to the
83 * extensions directory. Any files referenced in this way must be registered
84 * for compilation by including them in $wgCompiledFiles.
85 * @param $file string
86 * @return string
88 static function extCompiledPath( $file ) {
89 if ( defined( 'MW_COMPILED' ) ) {
90 return "extensions/$file";
91 } else {
92 return self::getExtensionsDirectory() . '/' . $file;
96 /**
97 * Register an extension setup file and return its path for compiled
98 * inclusion. Use this function in LocalSettings.php to add extensions
99 * to the build. For example:
101 * require( MWInit::extSetupPath( 'ParserFunctions/ParserFunctions.php' ) );
103 * @param $extRel string The path relative to the extensions directory, as defined by
104 * $wgExtensionsDirectory.
106 * @return string
108 static function extSetupPath( $extRel ) {
109 $baseRel = "extensions/$extRel";
110 if ( defined( 'MW_COMPILED' ) ) {
111 return $baseRel;
112 } else {
113 global $wgCompiledFiles;
114 $wgCompiledFiles[] = $baseRel;
115 return self::getExtensionsDirectory() . '/' . $extRel;
120 * @return bool|string
122 static function getExtensionsDirectory() {
123 global $wgExtensionsDirectory, $IP;
124 if ( $wgExtensionsDirectory === false ) {
125 $wgExtensionsDirectory = "$IP/../extensions";
127 return $wgExtensionsDirectory;
131 * Determine whether a class exists, using a method which works under HipHop.
133 * Note that it's not possible to implement this with any variant of
134 * class_exists(), because class_exists() returns false for classes which
135 * are compiled in.
137 * Calling class_exists() on a literal string causes the class to be made
138 * "volatile", which means (as of March 2011) that the class is broken and
139 * can't be used at all. So don't do that. See
140 * https://github.com/facebook/hiphop-php/issues/314
142 * @param $class string
144 * @return bool
146 static function classExists( $class ) {
147 try {
148 $r = new ReflectionClass( $class );
149 } catch( ReflectionException $r ) {
150 $r = false;
152 return $r !== false;
156 * Determine wether a method exists within a class, using a method which works
157 * under HipHop.
159 * Note that under HipHop when method_exists is given a string for it's class
160 * such as to test for a static method has the same issues as class_exists does.
162 * @param $class string
163 * @param $method string
165 * @return bool
167 static function methodExists( $class, $method ) {
168 try {
169 $r = new ReflectionMethod( $class, $method );
170 } catch( ReflectionException $r ) {
171 $r = false;
173 return $r !== false;
177 * Determine whether a function exists, using a method which works under
178 * HipHop.
180 * @param $function string
182 * @return bool
184 static function functionExists( $function ) {
185 try {
186 $r = new ReflectionFunction( $function );
187 } catch( ReflectionException $r ) {
188 $r = false;
190 return $r !== false;
194 * Call a static method of a class with variable arguments without causing
195 * it to become volatile.
196 * @param $className string
197 * @param $methodName string
198 * @param $args array
200 * @return mixed
202 static function callStaticMethod( $className, $methodName, $args ) {
203 $r = new ReflectionMethod( $className, $methodName );
204 return $r->invokeArgs( null, $args );