MediaWiki REL1_30
updateExtensionJsonSchema.php
Go to the documentation of this file.
1<?php
2
3require_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 ];
59 $json['config'][$name]['merge_strategy'] = $value[ExtensionRegistry::MERGE_STRATEGY];
61 }
62 }
63 }
64 }
65 }
66}
67
68$maintClass = 'UpdateExtensionJsonSchema';
69require_once RUN_MAINTENANCE_IF_MAIN;
wfArrayInsertAfter(array $array, array $insert, $after)
Insert array into another array after the specified KEY
const MERGE_STRATEGY
Special key that defines the merge strategy.
const MANIFEST_VERSION
Version of the highest supported manifest version.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true)
Add some args that are needed.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
Config $config
Accessible via getConfig()
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
Definition hooks.txt:2581
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302
require_once RUN_MAINTENANCE_IF_MAIN