79 $__settings = array_merge( $this->
getAllGlobals(), array_keys( $this->custom ) );
80 foreach ( $__settings as $var ) {
86 if ( !is_file( $arg ) ) {
92 $vars = get_defined_vars();
93 unset( $vars[
'this'] );
94 unset( $vars[
'__settings'] );
95 $this->dir = dirname( realpath( $this->
getArg( 0 ) ) );
98 $configPrefix = $this->
getOption(
'config-prefix',
'wg' );
99 if ( $configPrefix !==
'wg' ) {
100 $this->json[
'config'][
'_prefix'] = $configPrefix;
103 foreach ( $vars as $name => $value ) {
104 $realName = substr( $name, 2 );
105 if ( $realName ===
false ) {
110 if ( is_array( $value ) && count( $value ) === 0 && in_array( $realName, $__settings ) ) {
114 if ( isset( $this->custom[$realName] ) ) {
115 call_user_func_array( [ $this, $this->custom[$realName] ],
116 [ $realName, $value, $vars ] );
117 } elseif ( in_array( $realName, $globalSettings ) ) {
118 $this->json[$realName] = $value;
119 } elseif ( array_key_exists( $realName, $this->noLongerSupportedGlobals ) ) {
120 $this->
output(
'Warning: Skipped global "' . $name .
'" (' .
121 $this->noLongerSupportedGlobals[$realName] .
'). ' .
122 "Please update the entry point before convert to registration.\n" );
123 $this->hasWarning =
true;
124 } elseif ( strpos( $name, $configPrefix ) === 0 ) {
125 $configName = substr( $name, strlen( $configPrefix ) );
128 if ( is_array( $value ) ) {
129 foreach ( $value as $k => $v ) {
130 if ( strpos( $v, $this->dir ) !==
false ) {
131 $value[$k] = $this->stripPath( $v, $this->dir );
135 } elseif ( is_string( $value ) && strpos( $value, $this->dir ) !==
false ) {
136 $value = $this->stripPath( $value, $this->dir );
141 $this->json[
'config'][$configName] = [
'value' => $value ];
144 $this->json[
'config'][$configName][
'path'] =
true;
146 } elseif ( $configPrefix !==
'wg' && strpos( $name,
'wg' ) === 0 ) {
148 $this->
output(
'Warning: Skipped global "' . $name .
'" (' .
149 'config prefix is "' . $configPrefix .
'"). ' .
150 "Please check that this setting isn't needed.\n" );
157 $this->
output(
"Detected composer dependencies, setting 'load_composer_autoloader' to true.\n" );
158 $this->json[
'load_composer_autoloader'] =
true;
163 foreach ( $this->promote as $key ) {
164 if ( isset( $this->json[$key] ) ) {
165 $out[$key] = $this->json[$key];
166 unset( $this->json[$key] );
172 ExtensionRegistry::MEDIAWIKI_CORE => ExtensionRegistry::MANIFEST_VERSION_MW_VERSION
176 $out[
'manifest_version'] = ExtensionRegistry::MANIFEST_VERSION;
177 $type = $this->
hasOption(
'skin' ) ?
'skin' :
'extension';
178 $fname =
"{$this->dir}/$type.json";
179 $prettyJSON = FormatJson::encode( $out,
"\t", FormatJson::ALL_OK );
180 file_put_contents( $fname, $prettyJSON .
"\n" );
181 $this->
output(
"Wrote output to $fname.\n" );
182 if ( $this->hasWarning ) {
183 $this->
output(
"Found warnings! Please resolve the warnings and rerun this script.\n" );
213 foreach ( $value as $key => $file ) {
214 $strippedFile = $this->stripPath( $file, $this->dir );
215 if ( isset( $vars[
'wgMessagesDirs'][$key] ) ) {
217 "Note: Ignoring PHP shim $strippedFile. " .
218 "If your extension no longer supports versions of MediaWiki " .
219 "older than 1.23.0, you can safely delete it.\n"
222 $this->json[$realName][$key] = $strippedFile;
279 foreach ( $value as $hookName => &$handlers ) {
280 if ( $hookName ===
'UnitTestsList' ) {
281 $this->
output(
"Note: the UnitTestsList hook is no longer necessary as " .
282 "long as your tests are located in the \"tests/phpunit/\" directory. " .
283 "Please see <https://www.mediawiki.org/wiki/Manual:PHP_unit_testing/" .
284 "Writing_unit_tests_for_extensions#Register_your_tests> for more details.\n"
287 foreach ( $handlers as $func ) {
288 if ( $func instanceof Closure ) {
289 $this->
fatalError(
"Error: Closures cannot be converted to JSON. " .
290 "Please move the handler for $hookName somewhere else."
292 } elseif ( function_exists( $func ) ) {
294 $this->
fatalError(
"Error: Global functions cannot be converted to JSON. " .
295 "Please move the handler for $hookName inside a class."
299 if ( count( $handlers ) === 1 ) {
300 $handlers = $handlers[0];
303 $this->json[$realName] = $value;
312 $remote = $this->
hasOption(
'skin' ) ?
'remoteSkinPath' :
'remoteExtPath';
313 foreach ( $value as $name => $data ) {
314 if ( isset( $data[
'localBasePath'] ) ) {
315 $data[
'localBasePath'] = $this->stripPath( $data[
'localBasePath'], $this->dir );
317 $defaults[
'localBasePath'] = $data[
'localBasePath'];
318 unset( $data[
'localBasePath'] );
319 if ( isset( $data[$remote] ) ) {
320 $defaults[$remote] = $data[$remote];
321 unset( $data[$remote] );
324 if ( $data[
'localBasePath'] === $defaults[
'localBasePath'] ) {
325 unset( $data[
'localBasePath'] );
327 if ( isset( $data[$remote] ) && isset( $defaults[$remote] )
328 && $data[$remote] === $defaults[$remote]
330 unset( $data[$remote] );
335 $this->json[$realName][$name] = $data;
338 $this->json[
'ResourceFileModulePaths'] = $defaults;