77 $__settings = array_merge( $this->
getAllGlobals(), array_keys( $this->custom ) );
78 foreach ( $__settings as $var ) {
84 if ( !is_file( $arg ) ) {
90 $vars = get_defined_vars();
91 unset( $vars[
'this'] );
92 unset( $vars[
'__settings'] );
93 $this->dir = dirname( realpath( $this->
getArg( 0 ) ) );
96 $configPrefix = $this->
getOption(
'config-prefix',
'wg' );
97 if ( $configPrefix !==
'wg' ) {
98 $this->json[
'config'][
'_prefix'] = $configPrefix;
101 foreach ( $vars as $name => $value ) {
102 $realName = substr( $name, 2 );
103 if ( $realName ===
false ) {
108 if ( is_array( $value ) && count( $value ) === 0 && in_array( $realName, $__settings ) ) {
112 if ( isset( $this->custom[$realName] ) ) {
113 call_user_func_array( [ $this, $this->custom[$realName] ],
114 [ $realName, $value, $vars ] );
115 } elseif ( in_array( $realName, $globalSettings ) ) {
116 $this->json[$realName] = $value;
117 } elseif ( array_key_exists( $realName, $this->noLongerSupportedGlobals ) ) {
118 $this->
output(
'Warning: Skipped global "' . $name .
'" (' .
119 $this->noLongerSupportedGlobals[$realName] .
'). ' .
120 "Please update the entry point before convert to registration.\n" );
121 $this->hasWarning =
true;
122 } elseif ( strpos( $name, $configPrefix ) === 0 ) {
123 $configName = substr( $name, strlen( $configPrefix ) );
126 if ( is_array( $value ) ) {
127 foreach ( $value as $k => $v ) {
128 if ( strpos( $v, $this->dir ) !==
false ) {
129 $value[$k] = $this->
stripPath( $v, $this->dir );
133 } elseif ( is_string( $value ) && strpos( $value, $this->dir ) !==
false ) {
134 $value = $this->
stripPath( $value, $this->dir );
139 $this->json[
'config'][$configName] = [
'value' => $value ];
142 $this->json[
'config'][$configName][
'path'] =
true;
144 } elseif ( $configPrefix !==
'wg' && strpos( $name,
'wg' ) === 0 ) {
146 $this->
output(
'Warning: Skipped global "' . $name .
'" (' .
147 'config prefix is "' . $configPrefix .
'"). ' .
148 "Please check that this setting isn't needed.\n" );
155 $this->
output(
"Detected composer dependencies, setting 'load_composer_autoloader' to true.\n" );
156 $this->json[
'load_composer_autoloader'] =
true;
161 foreach ( $this->promote as $key ) {
162 if ( isset( $this->json[$key] ) ) {
163 $out[$key] = $this->json[$key];
164 unset( $this->json[$key] );
170 ExtensionRegistry::MEDIAWIKI_CORE => ExtensionRegistry::MANIFEST_VERSION_MW_VERSION
174 $out[
'manifest_version'] = ExtensionRegistry::MANIFEST_VERSION;
176 $fname =
"{$this->dir}/$type.json";
177 $prettyJSON = FormatJson::encode( $out,
"\t", FormatJson::ALL_OK );
178 file_put_contents( $fname, $prettyJSON .
"\n" );
179 $this->
output(
"Wrote output to $fname.\n" );
180 if ( $this->hasWarning ) {
181 $this->
output(
"Found warnings! Please resolve the warnings and rerun this script.\n" );
272 foreach ( $value as $hookName => &$handlers ) {
273 if ( $hookName ===
'UnitTestsList' ) {
274 $this->
output(
"Note: the UnitTestsList hook is no longer necessary as " .
275 "long as your tests are located in the \"tests/phpunit/\" directory. " .
276 "Please see <https://www.mediawiki.org/wiki/Manual:PHP_unit_testing/" .
277 "Writing_unit_tests_for_extensions#Register_your_tests> for more details.\n"
280 foreach ( $handlers as $func ) {
281 if ( $func instanceof Closure ) {
282 $this->
fatalError(
"Error: Closures cannot be converted to JSON. " .
283 "Please move the handler for $hookName somewhere else."
285 } elseif ( function_exists( $func ) ) {
287 $this->
fatalError(
"Error: Global functions cannot be converted to JSON. " .
288 "Please move the handler for $hookName inside a class."
292 if ( count( $handlers ) === 1 ) {
293 $handlers = $handlers[0];
296 $this->json[$realName] = $value;
305 $remote = $this->
hasOption(
'skin' ) ?
'remoteSkinPath' :
'remoteExtPath';
306 foreach ( $value as $name => $data ) {
307 if ( isset( $data[
'localBasePath'] ) ) {
308 $data[
'localBasePath'] = $this->
stripPath( $data[
'localBasePath'], $this->dir );
310 $defaults[
'localBasePath'] = $data[
'localBasePath'];
311 unset( $data[
'localBasePath'] );
312 if ( isset( $data[$remote] ) ) {
313 $defaults[$remote] = $data[$remote];
314 unset( $data[$remote] );
317 if ( $data[
'localBasePath'] === $defaults[
'localBasePath'] ) {
318 unset( $data[
'localBasePath'] );
320 if ( isset( $data[$remote] ) && isset( $defaults[$remote] )
321 && $data[$remote] === $defaults[$remote]
323 unset( $data[$remote] );
328 $this->json[$realName][$name] = $data;
331 $this->json[
'ResourceFileModulePaths'] = $defaults;