3use Composer\Semver\VersionParser;
9require_once __DIR__ .
'/Maintenance.php';
15 parent::__construct();
16 $this->
addDescription(
'Updates extension.json files to the latest manifest_version' );
17 $this->
addArg(
'path',
'Location to the extension.json or skin.json you wish to convert',
22 $filename = $this->
getArg( 0 );
23 if ( !is_readable( $filename ) ) {
24 $this->
fatalError(
"Error: Unable to read $filename" );
27 $json = FormatJson::decode( file_get_contents( $filename ),
true );
28 if ( !is_array( $json ) ) {
32 if ( !isset( $json[
'manifest_version'] ) ) {
33 $json[
'manifest_version'] = 1;
36 if ( $json[
'manifest_version'] == ExtensionRegistry::MANIFEST_VERSION ) {
37 $this->
output(
"Already at the latest version: {$json['manifest_version']}\n" );
41 while ( $json[
'manifest_version'] !== ExtensionRegistry::MANIFEST_VERSION ) {
42 $json[
'manifest_version']++;
43 $func =
"updateTo{$json['manifest_version']}";
44 $this->$func( $json );
49 file_put_contents( $filename, FormatJson::encode( $json,
"\t", FormatJson::ALL_OK ) .
"\n" );
50 $this->
output(
"Updated to {$json['manifest_version']}...\n" );
57 if ( !isset( $json[
'requires'] ) ) {
58 $json[
'requires'] = [];
61 $needNewVersion =
true;
64 if ( isset( $json[
'requires'][ExtensionRegistry::MEDIAWIKI_CORE] ) ) {
65 $versionParser =
new VersionParser();
66 $currentRequired = $versionParser->parseConstraints(
68 $json[
'requires'][ExtensionRegistry::MEDIAWIKI_CORE]
70 $newRequired = $versionParser->parseConstraints(
72 str_replace(
'>=',
'==', ExtensionRegistry::MANIFEST_VERSION_MW_VERSION )
74 if ( !$currentRequired->matches( $newRequired ) ) {
75 $needNewVersion =
false;
79 if ( $needNewVersion ) {
82 $json[
'requires'][ExtensionRegistry::MEDIAWIKI_CORE] =
83 ExtensionRegistry::MANIFEST_VERSION_MW_VERSION;
88 if ( isset( $json[
'config'] ) ) {
89 $config = $json[
'config'];
91 if ( isset( $config[
'_prefix'] ) ) {
93 'config_prefix' => $config[
'_prefix']
95 unset( $config[
'_prefix'] );
98 foreach ( $config as $name => $value ) {
99 if ( $name[0] !==
'@' ) {
100 $json[
'config'][$name] = [
'value' => $value ];
101 if ( isset( $value[ExtensionRegistry::MERGE_STRATEGY] ) ) {
102 $json[
'config'][$name][
'merge_strategy'] = $value[ExtensionRegistry::MERGE_STRATEGY];
103 unset( $json[
'config'][$name][
'value'][ExtensionRegistry::MERGE_STRATEGY] );
105 if ( isset( $config[
"@$name"] ) ) {
107 $json[
'config'][$name] = array_merge(
108 [
'description' => $config[
"@$name"] ],
109 $json[
'config'][$name]
118 'CodeMirrorPluginModules' => [
'CodeMirror',
'PluginModules' ],
119 'CodeMirrorTagModes' => [
'CodeMirror',
'TagModes' ],
120 'EventLoggingSchemas' => [
'EventLogging',
'Schemas' ],
121 'SyntaxHighlightModels' => [
'SyntaxHighlight',
'Models' ],
122 'VisualEditorAvailableContentModels' => [
'VisualEditor',
'AvailableContentModels' ],
123 'VisualEditorAvailableNamespaces' => [
'VisualEditor',
'AvailableNamespaces' ],
124 'VisualEditorPreloadModules' => [
'VisualEditor',
'PreloadModules' ],
125 'VisualEditorPluginModules' => [
'VisualEditor',
'PluginModules' ],
128 foreach ( $attributes as $name => $value ) {
129 if ( !isset( $json[$name] ) ) {
133 $json[
'attributes'][$value[0]][$value[1]] = $json[$name];
134 unset( $json[$name] );
141require_once RUN_MAINTENANCE_IF_MAIN;
wfArrayInsertAfter(array $array, array $insert, $after)
Insert an array into another array after the specified key.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
getArg( $argId=0, $default=null)
Get an argument.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addDescription( $text)
Set the description text.
updateRequiredMwVersion(&$json)
__construct()
Default constructor.
execute()
Do the actual work.