3use Composer\Semver\VersionParser;
10require_once __DIR__ .
'/Maintenance.php';
16 parent::__construct();
17 $this->
addDescription(
'Updates extension.json files to the latest manifest_version' );
18 $this->
addArg(
'path',
'Location to the extension.json or skin.json you wish to convert',
23 $filename = $this->
getArg( 0 );
24 if ( !is_readable( $filename ) ) {
25 $this->
fatalError(
"Error: Unable to read $filename" );
28 $json = FormatJson::decode( file_get_contents( $filename ),
true );
29 if ( !is_array( $json ) ) {
33 if ( !isset( $json[
'manifest_version'] ) ) {
34 $json[
'manifest_version'] = 1;
37 if ( $json[
'manifest_version'] == ExtensionRegistry::MANIFEST_VERSION ) {
38 $this->
output(
"Already at the latest version: {$json['manifest_version']}\n" );
42 while ( $json[
'manifest_version'] !== ExtensionRegistry::MANIFEST_VERSION ) {
43 $json[
'manifest_version']++;
44 $func =
"updateTo{$json['manifest_version']}";
45 $this->$func( $json );
50 file_put_contents( $filename, FormatJson::encode( $json,
"\t", FormatJson::ALL_OK ) .
"\n" );
51 $this->
output(
"Updated to {$json['manifest_version']}...\n" );
58 if ( !isset( $json[
'requires'] ) ) {
59 $json[
'requires'] = [];
62 $needNewVersion =
true;
65 if ( isset( $json[
'requires'][ExtensionRegistry::MEDIAWIKI_CORE] ) ) {
66 $versionParser =
new VersionParser();
67 $currentRequired = $versionParser->parseConstraints(
69 $json[
'requires'][ExtensionRegistry::MEDIAWIKI_CORE]
71 $newRequired = $versionParser->parseConstraints(
73 str_replace(
'>=',
'==', ExtensionRegistry::MANIFEST_VERSION_MW_VERSION )
75 if ( !$currentRequired->matches( $newRequired ) ) {
76 $needNewVersion =
false;
80 if ( $needNewVersion ) {
83 $json[
'requires'][ExtensionRegistry::MEDIAWIKI_CORE] =
84 ExtensionRegistry::MANIFEST_VERSION_MW_VERSION;
89 if ( isset( $json[
'config'] ) ) {
90 $config = $json[
'config'];
92 if ( isset( $config[
'_prefix'] ) ) {
93 $json = ArrayUtils::insertAfter( $json, [
94 'config_prefix' => $config[
'_prefix']
96 unset( $config[
'_prefix'] );
99 foreach ( $config as $name => $value ) {
100 if ( $name[0] !==
'@' ) {
101 $json[
'config'][$name] = [
'value' => $value ];
102 if ( isset( $value[ExtensionRegistry::MERGE_STRATEGY] ) ) {
103 $json[
'config'][$name][
'merge_strategy'] = $value[ExtensionRegistry::MERGE_STRATEGY];
104 unset( $json[
'config'][$name][
'value'][ExtensionRegistry::MERGE_STRATEGY] );
106 if ( isset( $config[
"@$name"] ) ) {
108 $json[
'config'][$name] = array_merge(
109 [
'description' => $config[
"@$name"] ],
110 $json[
'config'][$name]
119 'CodeMirrorPluginModules' => [
'CodeMirror',
'PluginModules' ],
120 'CodeMirrorTagModes' => [
'CodeMirror',
'TagModes' ],
121 'EventLoggingSchemas' => [
'EventLogging',
'Schemas' ],
122 'SyntaxHighlightModels' => [
'SyntaxHighlight',
'Models' ],
123 'VisualEditorAvailableContentModels' => [
'VisualEditor',
'AvailableContentModels' ],
124 'VisualEditorAvailableNamespaces' => [
'VisualEditor',
'AvailableNamespaces' ],
125 'VisualEditorPreloadModules' => [
'VisualEditor',
'PreloadModules' ],
126 'VisualEditorPluginModules' => [
'VisualEditor',
'PluginModules' ],
129 foreach ( $attributes as $name => $value ) {
130 if ( !isset( $json[$name] ) ) {
134 $json[
'attributes'][$value[0]][$value[1]] = $json[$name];
135 unset( $json[$name] );
142require_once RUN_MAINTENANCE_IF_MAIN;
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.