Go to the documentation of this file.
3 require_once __DIR__ .
'/Maintenance.php';
8 'MessagesDirs' =>
'handleMessagesDirs',
9 'ExtensionMessagesFiles' =>
'handleExtensionMessagesFiles',
10 'AutoloadClasses' =>
'removeAbsolutePath',
11 'ExtensionCredits' =>
'handleCredits',
12 'ResourceModules' =>
'handleResourceModules',
13 'ResourceModuleSkinStyles' =>
'handleResourceModules',
14 'Hooks' =>
'handleHooks',
15 'ExtensionFunctions' =>
'handleExtensionFunctions',
16 'ParserTestFiles' =>
'removeAbsolutePath',
34 'SpecialPageGroups' =>
'deprecated',
57 parent::__construct();
58 $this->
addDescription(
'Converts extension entry points to the new JSON registration format' );
59 $this->
addArg(
'path',
'Location to the PHP entry point you wish to convert',
61 $this->
addOption(
'skin',
'Whether to write to skin.json',
false,
false );
62 $this->
addOption(
'config-prefix',
'Custom prefix for configuration settings',
false,
true );
66 $processor =
new ReflectionClass(
'ExtensionProcessor' );
67 $settings = $processor->getProperty(
'globalSettings' );
68 $settings->setAccessible(
true );
77 $__settings = array_merge( $this->
getAllGlobals(), array_keys( $this->custom ) );
78 foreach ( $__settings
as $var ) {
84 if ( !is_file( $arg ) ) {
85 $this->
error(
"$arg is not a file.",
true );
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 $realName = substr(
$name, 2 );
102 if ( $realName ===
false ) {
107 if ( is_array(
$value ) &&
count(
$value ) === 0 && in_array( $realName, $__settings ) ) {
111 if ( isset( $this->custom[$realName] ) ) {
112 call_user_func_array( [ $this, $this->custom[$realName] ],
114 } elseif ( in_array( $realName, $globalSettings ) ) {
116 } elseif ( array_key_exists( $realName, $this->noLongerSupportedGlobals ) ) {
117 $this->
output(
'Warning: Skipped global "' .
$name .
'" (' .
118 $this->noLongerSupportedGlobals[$realName] .
'). ' .
119 "Please update the entry point before convert to registration.\n" );
120 $this->hasWarning =
true;
121 } elseif ( strpos(
$name, $configPrefix ) === 0 ) {
123 $this->
json[
'config'][substr(
$name, strlen( $configPrefix ) )] = [
'value' =>
$value ];
124 } elseif ( $configPrefix !==
'wg' && strpos(
$name,
'wg' ) === 0 ) {
126 $this->
output(
'Warning: Skipped global "' .
$name .
'" (' .
127 'config prefix is "' . $configPrefix .
'"). ' .
128 "Please check that this setting isn't needed.\n" );
135 $this->
output(
"Detected composer dependencies, setting 'load_composer_autoloader' to true.\n" );
136 $this->
json[
'load_composer_autoloader'] =
true;
141 foreach ( $this->promote
as $key ) {
142 if ( isset( $this->
json[$key] ) ) {
144 unset( $this->
json[$key] );
151 $fname =
"{$this->dir}/$type.json";
153 file_put_contents(
$fname, $prettyJSON .
"\n" );
154 $this->
output(
"Wrote output to $fname.\n" );
155 if ( $this->hasWarning ) {
156 $this->
output(
"Found warnings! Please resolve the warnings and rerun this script.\n" );
162 if ( $func instanceof Closure ) {
163 $this->
error(
"Error: Closures cannot be converted to JSON. " .
164 "Please move your extension function somewhere else.", 1
168 if ( function_exists( $func ) ) {
169 $this->
error(
"Error: Global functions cannot be converted to JSON. " .
170 "Please move your extension function ($func) into a class.", 1
181 $this->
json[$realName][$key][] = $this->
stripPath( $dir, $this->dir );
187 foreach (
$value as $key => $file ) {
188 $strippedFile = $this->
stripPath( $file, $this->dir );
189 if ( isset(
$vars[
'wgMessagesDirs'][$key] ) ) {
191 "Note: Ignoring PHP shim $strippedFile. " .
192 "If your extension no longer supports versions of MediaWiki " .
193 "older than 1.23.0, you can safely delete it.\n"
196 $this->
json[$realName][$key] = $strippedFile;
202 if ( $val ===
$dir ) {
204 } elseif ( strpos( $val,
$dir ) === 0 ) {
206 $val = substr( $val, strlen(
$dir ) + 1 );
214 foreach (
$value as $key => $val ) {
223 $values = array_values(
$value );
224 foreach ( $values[0][0]
as $name => $val ) {
225 if (
$name !==
'path' ) {
232 foreach (
$value as $hookName => &$handlers ) {
233 if ( $hookName ===
'UnitTestsList' ) {
234 $this->
output(
"Note: the UnitTestsList hook is no longer necessary as " .
235 "long as your tests are located in the \"tests/phpunit/\" directory. " .
236 "Please see <https://www.mediawiki.org/wiki/Manual:PHP_unit_testing/" .
237 "Writing_unit_tests_for_extensions#Register_your_tests> for more details.\n"
240 foreach ( $handlers
as $func ) {
241 if ( $func instanceof Closure ) {
242 $this->
error(
"Error: Closures cannot be converted to JSON. " .
243 "Please move the handler for $hookName somewhere else.", 1
247 if ( function_exists( $func ) ) {
248 $this->
error(
"Error: Global functions cannot be converted to JSON. " .
249 "Please move the handler for $hookName inside a class.", 1
253 if (
count( $handlers ) === 1 ) {
254 $handlers = $handlers[0];
262 $remote = $this->
hasOption(
'skin' ) ?
'remoteSkinPath' :
'remoteExtPath';
264 if ( isset( $data[
'localBasePath'] ) ) {
265 $data[
'localBasePath'] = $this->
stripPath( $data[
'localBasePath'], $this->dir );
267 $defaults[
'localBasePath'] = $data[
'localBasePath'];
268 unset( $data[
'localBasePath'] );
269 if ( isset( $data[$remote] ) ) {
270 $defaults[$remote] = $data[$remote];
271 unset( $data[$remote] );
274 if ( $data[
'localBasePath'] === $defaults[
'localBasePath'] ) {
275 unset( $data[
'localBasePath'] );
277 if ( isset( $data[$remote] ) && isset( $defaults[$remote] )
278 && $data[$remote] === $defaults[$remote]
280 unset( $data[$remote] );
288 $this->
json[
'ResourceFileModulePaths'] = $defaults;
293 $path .=
'/composer.json';
294 if ( file_exists(
$path ) ) {
298 if ( $composerJson->getRequiredDependencies() ) {
handleCredits( $realName, $value)
array $formerGlobals
Things that were formerly globals and should still be converted.
const MANIFEST_VERSION
Version of the highest supported manifest version.
Reads a composer.json file and provides accessors to get its hash and the required dependencies.
addDescription( $text)
Set the description text.
handleHooks( $realName, $value)
__construct()
Default constructor.
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
require_once RUN_MAINTENANCE_IF_MAIN
needsComposerAutoloader( $path)
Allows to change the fields on the form that will be generated $name
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
handleExtensionFunctions( $realName, $value)
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
handleExtensionMessagesFiles( $realName, $value, $vars)
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
handleResourceModules( $realName, $value)
removeAbsolutePath( $realName, $value)
handleMessagesDirs( $realName, $value)
getOption( $name, $default=null)
Get an option, or return the default.
addArg( $arg, $description, $required=true)
Add some args that are needed.
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
execute()
Do the actual work.
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
array $promote
Keys that should be put at the top of the generated JSON file (T86608)
hasOption( $name)
Checks to see if a particular param exists.
getArg( $argId=0, $default=null)
Get an argument.
the array() calling protocol came about after MediaWiki 1.4rc1.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
array $noLongerSupportedGlobals
No longer supported globals (with reason) should not be converted and emit a warning.