80 $__settings = array_merge( $this->
getAllGlobals(), array_keys( self::CUSTOM_GLOBALS ) );
81 foreach ( $__settings as $var ) {
87 if ( !is_file( $arg ) ) {
93 $vars = get_defined_vars();
94 unset( $vars[
'this'] );
95 unset( $vars[
'__settings'] );
96 $this->dir = dirname( realpath( $this->
getArg( 0 ) ) );
99 $configPrefix = $this->
getOption(
'config-prefix',
'wg' );
100 if ( $configPrefix !==
'wg' ) {
101 $this->json[
'config'][
'_prefix'] = $configPrefix;
104 foreach ( $vars as $name => $value ) {
105 $realName = substr( $name, 2 );
106 if ( $realName ===
false ) {
111 if ( is_array( $value ) && count( $value ) === 0 && in_array( $realName, $__settings ) ) {
115 if ( isset( self::CUSTOM_GLOBALS[$realName] ) ) {
116 call_user_func_array( [ $this, self::CUSTOM_GLOBALS[$realName] ],
117 [ $realName, $value, $vars ] );
118 } elseif ( in_array( $realName, $globalSettings ) ) {
119 $this->json[$realName] = $value;
120 } elseif ( array_key_exists( $realName, self::NO_LONGER_SUPPORTED_GLOBALS ) ) {
121 $this->
output(
'Warning: Skipped global "' . $name .
'" (' .
122 self::NO_LONGER_SUPPORTED_GLOBALS[$realName] .
'). ' .
123 "Please update the entry point before convert to registration.\n" );
124 $this->hasWarning =
true;
125 } elseif ( strpos( $name, $configPrefix ) === 0 ) {
126 $configName = substr( $name, strlen( $configPrefix ) );
129 if ( is_array( $value ) ) {
130 foreach ( $value as $k => $v ) {
131 if ( strpos( $v, $this->dir ) !==
false ) {
132 $value[$k] = $this->stripPath( $v, $this->dir );
136 } elseif ( is_string( $value ) && strpos( $value, $this->dir ) !==
false ) {
137 $value = $this->stripPath( $value, $this->dir );
142 $this->json[
'config'][$configName] = [
'value' => $value ];
145 $this->json[
'config'][$configName][
'path'] =
true;
147 } elseif ( $configPrefix !==
'wg' && strpos( $name,
'wg' ) === 0 ) {
149 $this->
output(
'Warning: Skipped global "' . $name .
'" (' .
150 'config prefix is "' . $configPrefix .
'"). ' .
151 "Please check that this setting isn't needed.\n" );
158 $this->
output(
"Detected composer dependencies, setting 'load_composer_autoloader' to true.\n" );
159 $this->json[
'load_composer_autoloader'] =
true;
164 foreach ( self::PROMOTE_ATTRIBUTES as $key ) {
165 if ( isset( $this->json[$key] ) ) {
166 $out[$key] = $this->json[$key];
167 unset( $this->json[$key] );
173 ExtensionRegistry::MEDIAWIKI_CORE => ExtensionRegistry::MANIFEST_VERSION_MW_VERSION
177 $out[
'manifest_version'] = ExtensionRegistry::MANIFEST_VERSION;
178 $type = $this->
hasOption(
'skin' ) ?
'skin' :
'extension';
179 $fname =
"{$this->dir}/$type.json";
180 $prettyJSON = FormatJson::encode( $out,
"\t", FormatJson::ALL_OK );
181 file_put_contents( $fname, $prettyJSON .
"\n" );
182 $this->
output(
"Wrote output to $fname.\n" );
183 if ( $this->hasWarning ) {
184 $this->
output(
"Found warnings! Please resolve the warnings and rerun this script.\n" );
214 foreach ( $value as $key => $file ) {
215 $strippedFile = $this->stripPath( $file, $this->dir );
216 if ( isset( $vars[
'wgMessagesDirs'][$key] ) ) {
218 "Note: Ignoring PHP shim $strippedFile. " .
219 "If your extension no longer supports versions of MediaWiki " .
220 "older than 1.23.0, you can safely delete it.\n"
223 $this->json[$realName][$key] = $strippedFile;
280 foreach ( $value as $hookName => &$handlers ) {
281 if ( $hookName ===
'UnitTestsList' ) {
282 $this->
output(
"Note: the UnitTestsList hook is no longer necessary as " .
283 "long as your tests are located in the \"tests/phpunit/\" directory. " .
284 "Please see <https://www.mediawiki.org/wiki/Manual:PHP_unit_testing/" .
285 "Writing_unit_tests_for_extensions#Register_your_tests> for more details.\n"
288 foreach ( $handlers as $func ) {
289 if ( $func instanceof Closure ) {
290 $this->
fatalError(
"Error: Closures cannot be converted to JSON. " .
291 "Please move the handler for $hookName somewhere else."
293 } elseif ( function_exists( $func ) ) {
295 $this->
fatalError(
"Error: Global functions cannot be converted to JSON. " .
296 "Please move the handler for $hookName inside a class."
300 if ( count( $handlers ) === 1 ) {
301 $handlers = $handlers[0];
304 $this->json[$realName] = $value;
313 $remote = $this->
hasOption(
'skin' ) ?
'remoteSkinPath' :
'remoteExtPath';
314 foreach ( $value as $name => $data ) {
315 if ( isset( $data[
'localBasePath'] ) ) {
316 $data[
'localBasePath'] = $this->stripPath( $data[
'localBasePath'], $this->dir );
318 $defaults[
'localBasePath'] = $data[
'localBasePath'];
319 unset( $data[
'localBasePath'] );
320 if ( isset( $data[$remote] ) ) {
321 $defaults[$remote] = $data[$remote];
322 unset( $data[$remote] );
325 if ( $data[
'localBasePath'] === $defaults[
'localBasePath'] ) {
326 unset( $data[
'localBasePath'] );
328 if ( isset( $data[$remote] ) && isset( $defaults[$remote] )
329 && $data[$remote] === $defaults[$remote]
331 unset( $data[$remote] );
336 $this->json[$realName][$name] = $data;
339 $this->json[
'ResourceFileModulePaths'] = $defaults;