81 $__settings = array_merge( $this->
getAllGlobals(), array_keys( $this->custom ) );
82 foreach ( $__settings as $var ) {
88 if ( !is_file( $arg ) ) {
94 $vars = get_defined_vars();
95 unset( $vars[
'this'] );
96 unset( $vars[
'__settings'] );
97 $this->dir = dirname( realpath( $this->
getArg( 0 ) ) );
100 $configPrefix = $this->
getOption(
'config-prefix',
'wg' );
101 if ( $configPrefix !==
'wg' ) {
102 $this->json[
'config'][
'_prefix'] = $configPrefix;
105 foreach ( $vars as $name => $value ) {
106 $realName = substr( $name, 2 );
107 if ( $realName ===
false ) {
112 if ( is_array( $value ) && count( $value ) === 0 && in_array( $realName, $__settings ) ) {
116 if ( isset( $this->custom[$realName] ) ) {
117 call_user_func_array( [ $this, $this->custom[$realName] ],
118 [ $realName, $value, $vars ] );
119 } elseif ( in_array( $realName, $globalSettings ) ) {
120 $this->json[$realName] = $value;
121 } elseif ( array_key_exists( $realName, $this->noLongerSupportedGlobals ) ) {
122 $this->
output(
'Warning: Skipped global "' . $name .
'" (' .
123 $this->noLongerSupportedGlobals[$realName] .
'). ' .
124 "Please update the entry point before convert to registration.\n" );
125 $this->hasWarning =
true;
126 } elseif ( strpos( $name, $configPrefix ) === 0 ) {
127 $configName = substr( $name, strlen( $configPrefix ) );
130 if ( is_array( $value ) ) {
131 foreach ( $value as $k => $v ) {
132 if ( strpos( $v, $this->dir ) !==
false ) {
133 $value[$k] = $this->stripPath( $v, $this->dir );
137 } elseif ( is_string( $value ) && strpos( $value, $this->dir ) !==
false ) {
138 $value = $this->stripPath( $value, $this->dir );
143 $this->json[
'config'][$configName] = [
'value' => $value ];
146 $this->json[
'config'][$configName][
'path'] =
true;
148 } elseif ( $configPrefix !==
'wg' && strpos( $name,
'wg' ) === 0 ) {
150 $this->
output(
'Warning: Skipped global "' . $name .
'" (' .
151 'config prefix is "' . $configPrefix .
'"). ' .
152 "Please check that this setting isn't needed.\n" );
159 $this->
output(
"Detected composer dependencies, setting 'load_composer_autoloader' to true.\n" );
160 $this->json[
'load_composer_autoloader'] =
true;
165 foreach ( $this->promote as $key ) {
166 if ( isset( $this->json[$key] ) ) {
167 $out[$key] = $this->json[$key];
168 unset( $this->json[$key] );
174 ExtensionRegistry::MEDIAWIKI_CORE => ExtensionRegistry::MANIFEST_VERSION_MW_VERSION
178 $out[
'manifest_version'] = ExtensionRegistry::MANIFEST_VERSION;
179 $type = $this->
hasOption(
'skin' ) ?
'skin' :
'extension';
180 $fname =
"{$this->dir}/$type.json";
181 $prettyJSON = FormatJson::encode( $out,
"\t", FormatJson::ALL_OK );
182 file_put_contents( $fname, $prettyJSON .
"\n" );
183 $this->
output(
"Wrote output to $fname.\n" );
184 if ( $this->hasWarning ) {
185 $this->
output(
"Found warnings! Please resolve the warnings and rerun this script.\n" );
215 foreach ( $value as $key => $file ) {
216 $strippedFile = $this->stripPath( $file, $this->dir );
217 if ( isset( $vars[
'wgMessagesDirs'][$key] ) ) {
219 "Note: Ignoring PHP shim $strippedFile. " .
220 "If your extension no longer supports versions of MediaWiki " .
221 "older than 1.23.0, you can safely delete it.\n"
224 $this->json[$realName][$key] = $strippedFile;
281 foreach ( $value as $hookName => &$handlers ) {
282 if ( $hookName ===
'UnitTestsList' ) {
283 $this->
output(
"Note: the UnitTestsList hook is no longer necessary as " .
284 "long as your tests are located in the \"tests/phpunit/\" directory. " .
285 "Please see <https://www.mediawiki.org/wiki/Manual:PHP_unit_testing/" .
286 "Writing_unit_tests_for_extensions#Register_your_tests> for more details.\n"
289 foreach ( $handlers as $func ) {
290 if ( $func instanceof Closure ) {
291 $this->
fatalError(
"Error: Closures cannot be converted to JSON. " .
292 "Please move the handler for $hookName somewhere else."
294 } elseif ( function_exists( $func ) ) {
296 $this->
fatalError(
"Error: Global functions cannot be converted to JSON. " .
297 "Please move the handler for $hookName inside a class."
301 if ( count( $handlers ) === 1 ) {
302 $handlers = $handlers[0];
305 $this->json[$realName] = $value;
314 $remote = $this->
hasOption(
'skin' ) ?
'remoteSkinPath' :
'remoteExtPath';
315 foreach ( $value as $name => $data ) {
316 if ( isset( $data[
'localBasePath'] ) ) {
317 $data[
'localBasePath'] = $this->stripPath( $data[
'localBasePath'], $this->dir );
319 $defaults[
'localBasePath'] = $data[
'localBasePath'];
320 unset( $data[
'localBasePath'] );
321 if ( isset( $data[$remote] ) ) {
322 $defaults[$remote] = $data[$remote];
323 unset( $data[$remote] );
326 if ( $data[
'localBasePath'] === $defaults[
'localBasePath'] ) {
327 unset( $data[
'localBasePath'] );
329 if ( isset( $data[$remote] ) && isset( $defaults[$remote] )
330 && $data[$remote] === $defaults[$remote]
332 unset( $data[$remote] );
337 $this->json[$realName][$name] = $data;
340 $this->json[
'ResourceFileModulePaths'] = $defaults;