MediaWiki  1.30.0
updateExtensionJsonSchema.php
Go to the documentation of this file.
1 <?php
2 
3 require_once __DIR__ . '/Maintenance.php';
4 
6 
7  public function __construct() {
8  parent::__construct();
9  $this->addDescription( 'Updates extension.json files to the latest manifest_version' );
10  $this->addArg( 'path', 'Location to the extension.json or skin.json you wish to convert',
11  /* $required = */ true );
12  }
13 
14  public function execute() {
15  $filename = $this->getArg( 0 );
16  if ( !is_readable( $filename ) ) {
17  $this->error( "Error: Unable to read $filename", 1 );
18  }
19 
20  $json = FormatJson::decode( file_get_contents( $filename ), true );
21  if ( $json === null ) {
22  $this->error( "Error: Invalid JSON", 1 );
23  }
24 
25  if ( !isset( $json['manifest_version'] ) ) {
26  $json['manifest_version'] = 1;
27  }
28 
29  if ( $json['manifest_version'] == ExtensionRegistry::MANIFEST_VERSION ) {
30  $this->output( "Already at the latest version: {$json['manifest_version']}\n" );
31  return;
32  }
33 
34  while ( $json['manifest_version'] !== ExtensionRegistry::MANIFEST_VERSION ) {
35  $json['manifest_version'] += 1;
36  $func = "updateTo{$json['manifest_version']}";
37  $this->$func( $json );
38  }
39 
40  file_put_contents( $filename, FormatJson::encode( $json, "\t", FormatJson::ALL_OK ) . "\n" );
41  $this->output( "Updated to {$json['manifest_version']}...\n" );
42  }
43 
44  protected function updateTo2( &$json ) {
45  if ( isset( $json['config'] ) ) {
46  $config = $json['config'];
47  $json['config'] = [];
48  if ( isset( $config['_prefix'] ) ) {
49  $json = wfArrayInsertAfter( $json, [
50  'config_prefix' => $config['_prefix']
51  ], 'config' );
52  unset( $config['_prefix'] );
53  }
54 
55  foreach ( $config as $name => $value ) {
56  if ( $name[0] !== '@' ) {
57  $json['config'][$name] = [ 'value' => $value ];
58  if ( isset( $value[ExtensionRegistry::MERGE_STRATEGY] ) ) {
59  $json['config'][$name]['merge_strategy'] = $value[ExtensionRegistry::MERGE_STRATEGY];
61  }
62  }
63  }
64  }
65  }
66 }
67 
68 $maintClass = 'UpdateExtensionJsonSchema';
69 require_once RUN_MAINTENANCE_IF_MAIN;
wfArrayInsertAfter
wfArrayInsertAfter(array $array, array $insert, $after)
Insert array into another array after the specified KEY
Definition: GlobalFunctions.php:303
ExtensionRegistry\MANIFEST_VERSION
const MANIFEST_VERSION
Version of the highest supported manifest version.
Definition: ExtensionRegistry.php:24
UpdateExtensionJsonSchema\updateTo2
updateTo2(&$json)
Definition: updateExtensionJsonSchema.php:44
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:287
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
FormatJson\ALL_OK
const ALL_OK
Skip escaping as many characters as reasonably possible.
Definition: FormatJson.php:55
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ExtensionRegistry\MERGE_STRATEGY
const MERGE_STRATEGY
Special key that defines the merge strategy.
Definition: ExtensionRegistry.php:41
FormatJson\decode
static decode( $value, $assoc=false)
Decodes a JSON string.
Definition: FormatJson.php:187
FormatJson\encode
static encode( $value, $pretty=false, $escaping=0)
Returns the JSON representation of a value.
Definition: FormatJson.php:127
UpdateExtensionJsonSchema
Definition: updateExtensionJsonSchema.php:5
UpdateExtensionJsonSchema\__construct
__construct()
Default constructor.
Definition: updateExtensionJsonSchema.php:7
$value
$value
Definition: styleTest.css.php:45
Maintenance\$config
Config $config
Accessible via getConfig()
Definition: Maintenance.php:130
$maintClass
$maintClass
Definition: updateExtensionJsonSchema.php:68
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:267
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:392
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:373
UpdateExtensionJsonSchema\execute
execute()
Do the actual work.
Definition: updateExtensionJsonSchema.php:14
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:306