82 $__settings = array_merge( $this->
getAllGlobals(), array_keys( $this->custom ) );
83 foreach ( $__settings as $var ) {
89 if ( !is_file( $arg ) ) {
95 $vars = get_defined_vars();
96 unset( $vars[
'this'] );
97 unset( $vars[
'__settings'] );
98 $this->dir = dirname( realpath( $this->
getArg( 0 ) ) );
101 $configPrefix = $this->
getOption(
'config-prefix',
'wg' );
102 if ( $configPrefix !==
'wg' ) {
103 $this->json[
'config'][
'_prefix'] = $configPrefix;
106 foreach ( $vars as $name => $value ) {
107 $realName = substr( $name, 2 );
108 if ( $realName ===
false ) {
113 if ( is_array( $value ) && count( $value ) === 0 && in_array( $realName, $__settings ) ) {
117 if ( isset( $this->custom[$realName] ) ) {
118 call_user_func_array( [ $this, $this->custom[$realName] ],
119 [ $realName, $value, $vars ] );
120 } elseif ( in_array( $realName, $globalSettings ) ) {
121 $this->json[$realName] = $value;
122 } elseif ( array_key_exists( $realName, $this->noLongerSupportedGlobals ) ) {
123 $this->
output(
'Warning: Skipped global "' . $name .
'" (' .
124 $this->noLongerSupportedGlobals[$realName] .
'). ' .
125 "Please update the entry point before convert to registration.\n" );
126 $this->hasWarning =
true;
127 } elseif ( strpos( $name, $configPrefix ) === 0 ) {
128 $configName = substr( $name, strlen( $configPrefix ) );
131 if ( is_array( $value ) ) {
132 foreach ( $value as $k => $v ) {
133 if ( strpos( $v, $this->dir ) !==
false ) {
134 $value[$k] = $this->stripPath( $v, $this->dir );
138 } elseif ( is_string( $value ) && strpos( $value, $this->dir ) !==
false ) {
139 $value = $this->stripPath( $value, $this->dir );
144 $this->json[
'config'][$configName] = [
'value' => $value ];
147 $this->json[
'config'][$configName][
'path'] =
true;
149 } elseif ( $configPrefix !==
'wg' && strpos( $name,
'wg' ) === 0 ) {
151 $this->
output(
'Warning: Skipped global "' . $name .
'" (' .
152 'config prefix is "' . $configPrefix .
'"). ' .
153 "Please check that this setting isn't needed.\n" );
160 $this->
output(
"Detected composer dependencies, setting 'load_composer_autoloader' to true.\n" );
161 $this->json[
'load_composer_autoloader'] =
true;
166 foreach ( $this->promote as $key ) {
167 if ( isset( $this->json[$key] ) ) {
168 $out[$key] = $this->json[$key];
169 unset( $this->json[$key] );
175 ExtensionRegistry::MEDIAWIKI_CORE => ExtensionRegistry::MANIFEST_VERSION_MW_VERSION
179 $out[
'manifest_version'] = ExtensionRegistry::MANIFEST_VERSION;
180 $type = $this->
hasOption(
'skin' ) ?
'skin' :
'extension';
181 $fname =
"{$this->dir}/$type.json";
182 $prettyJSON = FormatJson::encode( $out,
"\t", FormatJson::ALL_OK );
183 file_put_contents( $fname, $prettyJSON .
"\n" );
184 $this->
output(
"Wrote output to $fname.\n" );
185 if ( $this->hasWarning ) {
186 $this->
output(
"Found warnings! Please resolve the warnings and rerun this script.\n" );
216 foreach ( $value as $key => $file ) {
217 $strippedFile = $this->stripPath( $file, $this->dir );
218 if ( isset( $vars[
'wgMessagesDirs'][$key] ) ) {
220 "Note: Ignoring PHP shim $strippedFile. " .
221 "If your extension no longer supports versions of MediaWiki " .
222 "older than 1.23.0, you can safely delete it.\n"
225 $this->json[$realName][$key] = $strippedFile;
282 foreach ( $value as $hookName => &$handlers ) {
283 if ( $hookName ===
'UnitTestsList' ) {
284 $this->
output(
"Note: the UnitTestsList hook is no longer necessary as " .
285 "long as your tests are located in the \"tests/phpunit/\" directory. " .
286 "Please see <https://www.mediawiki.org/wiki/Manual:PHP_unit_testing/" .
287 "Writing_unit_tests_for_extensions#Register_your_tests> for more details.\n"
290 foreach ( $handlers as $func ) {
291 if ( $func instanceof Closure ) {
292 $this->
fatalError(
"Error: Closures cannot be converted to JSON. " .
293 "Please move the handler for $hookName somewhere else."
295 } elseif ( function_exists( $func ) ) {
297 $this->
fatalError(
"Error: Global functions cannot be converted to JSON. " .
298 "Please move the handler for $hookName inside a class."
302 if ( count( $handlers ) === 1 ) {
303 $handlers = $handlers[0];
306 $this->json[$realName] = $value;
315 $remote = $this->
hasOption(
'skin' ) ?
'remoteSkinPath' :
'remoteExtPath';
316 foreach ( $value as $name => $data ) {
317 if ( isset( $data[
'localBasePath'] ) ) {
318 $data[
'localBasePath'] = $this->stripPath( $data[
'localBasePath'], $this->dir );
320 $defaults[
'localBasePath'] = $data[
'localBasePath'];
321 unset( $data[
'localBasePath'] );
322 if ( isset( $data[$remote] ) ) {
323 $defaults[$remote] = $data[$remote];
324 unset( $data[$remote] );
327 if ( $data[
'localBasePath'] === $defaults[
'localBasePath'] ) {
328 unset( $data[
'localBasePath'] );
330 if ( isset( $data[$remote] ) && isset( $defaults[$remote] )
331 && $data[$remote] === $defaults[$remote]
333 unset( $data[$remote] );
338 $this->json[$realName][$name] = $data;
341 $this->json[
'ResourceFileModulePaths'] = $defaults;