Go to the documentation of this file.
28 require_once __DIR__ .
'/Maintenance.php';
37 parent::__construct();
38 $this->
addDescription(
'Build JSON messages files from a PHP messages file' );
40 $this->
addArg(
'phpfile',
'PHP file defining a $messages array',
false );
41 $this->
addArg(
'jsondir',
'Directory to write JSON files to',
false );
42 $this->
addOption(
'extension',
'Perform default conversion on an extension',
44 $this->
addOption(
'supplementary',
'Find supplementary i18n files in subdirs and convert those',
51 $phpfile = $this->
getArg( 0 );
52 $jsondir = $this->
getArg( 1 );
53 $extension = $this->
getOption(
'extension' );
54 $convertSupplementaryI18nFiles = $this->
hasOption(
'supplementary' );
58 $this->
fatalError(
"The phpfile is already specified, conflicts with --extension." );
60 $phpfile =
"$IP/extensions/$extension/$extension.i18n.php";
64 $this->
error(
"I'm here for an argument!" );
69 if ( $convertSupplementaryI18nFiles ) {
70 if ( is_readable( $phpfile ) ) {
76 $this->
error(
"Warning: no primary i18n file was found." );
78 $this->
output(
"Searching for supplementary i18n files...\n" );
79 $dir_iterator =
new RecursiveDirectoryIterator( dirname( $phpfile ) );
80 $iterator =
new RecursiveIteratorIterator(
81 $dir_iterator, RecursiveIteratorIterator::LEAVES_ONLY );
83 foreach ( $iterator
as $path => $fileObject ) {
84 if ( fnmatch(
"*.i18n.php", $fileObject->getFilename() ) ) {
85 $this->
output(
"Converting $path.\n" );
99 $jsondir = dirname( $phpfile ) .
"/i18n";
101 if ( !is_dir( $jsondir ) ) {
102 $this->
output(
"Creating directory $jsondir.\n" );
105 $this->
fatalError(
"Could not create directory $jsondir" );
109 if ( !is_readable( $phpfile ) ) {
110 $this->
fatalError(
"Error reading $phpfile" );
114 $phpfileContents = file_get_contents( $phpfile );
117 $this->
fatalError(
"PHP file $phpfile does not define \$messages array" );
121 $this->
fatalError(
"PHP file $phpfile contains an empty \$messages array. " .
122 "Maybe it was already converted?" );
126 $this->
fatalError(
"PHP file $phpfile does not set language codes" );
131 "\$messages['$langcode'] =",
135 $langmsgs = array_merge(
136 [
'@metadata' => [
'authors' => $authors ] ],
140 $jsonfile =
"$jsondir/$langcode.json";
146 $this->
fatalError(
"FAILED to write $jsonfile" );
148 $this->
output(
"$jsonfile\n" );
152 "All done. To complete the conversion, please do the following:\n" .
153 "* Add \$wgMessagesDirs['YourExtension'] = __DIR__ . '/i18n';\n" .
154 "* Remove \$wgExtensionMessagesFiles['YourExtension']\n" .
155 "* Delete the old PHP message file\n" .
156 "This script no longer generates backward compatibility shims! If you need\n" .
157 "compatibility with MediaWiki 1.22 and older, use the MediaWiki 1.23 version\n" .
158 "of this script instead, or create a shim manually.\n"
169 $needlePos = strpos( $haystack, $needle );
170 if ( $needlePos ===
false ) {
175 $startPos = strrpos( $haystack,
'
188 protected function getAuthorsFromComment( $comment ) {
190 preg_match_all( '/@author (.*?)$/m
', $comment, $matches );
192 return $matches && $matches[1] ? $matches[1] : [];
196 $maintClass = GenerateJsonI18n::class;
197 require_once RUN_MAINTENANCE_IF_MAIN;
__construct()
Default constructor.
maybeHelp( $force=false)
Maybe show the help.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addDescription( $text)
Set the description text.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
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
execute()
Do the actual work.
getAuthorsFromComment( $comment)
Get an array of author names from a documentation comment containing.
Maintenance script to generate JSON i18n files from a PHP i18n file.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
findCommentBefore( $needle, $haystack)
Find the documentation comment immediately before a given search string.
transformI18nFile( $phpfile, $jsondir=null)
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might include
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
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option exists.
getArg( $argId=0, $default=null)
Get an argument.