28require_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 );
82 foreach ( $iterator as $path => $fileObject ) {
83 if ( fnmatch(
"*.i18n.php", $fileObject->getFilename() ) ) {
84 $this->
output(
"Converting $path.\n" );
98 $jsondir = dirname( $phpfile ) .
"/i18n";
100 if ( !is_dir( $jsondir ) ) {
101 $this->
output(
"Creating directory $jsondir.\n" );
104 $this->
fatalError(
"Could not create directory $jsondir" );
108 if ( !is_readable( $phpfile ) ) {
109 $this->
fatalError(
"Error reading $phpfile" );
113 $phpfileContents = file_get_contents( $phpfile );
116 $this->
fatalError(
"PHP file $phpfile does not define \$messages array" );
120 $this->
fatalError(
"PHP file $phpfile contains an empty \$messages array. " .
121 "Maybe it was already converted?" );
125 $this->
fatalError(
"PHP file $phpfile does not set language codes" );
128 foreach (
$messages as $langcode => $langmsgs ) {
130 "\$messages['$langcode'] =",
134 $langmsgs = array_merge(
135 [
'@metadata' => [
'authors' => $authors ] ],
139 $jsonfile =
"$jsondir/$langcode.json";
142 FormatJson::encode( $langmsgs,
"\t", FormatJson::ALL_OK ) .
"\n"
145 $this->
fatalError(
"FAILED to write $jsonfile" );
147 $this->
output(
"$jsonfile\n" );
151 "All done. To complete the conversion, please do the following:\n" .
152 "* Add \$wgMessagesDirs['YourExtension'] = __DIR__ . '/i18n';\n" .
153 "* Remove \$wgExtensionMessagesFiles['YourExtension']\n" .
154 "* Delete the old PHP message file\n" .
155 "This script no longer generates backward compatibility shims! If you need\n" .
156 "compatibility with MediaWiki 1.22 and older, use the MediaWiki 1.23 version\n" .
157 "of this script instead, or create a shim manually.\n"
168 $needlePos = strpos( $haystack, $needle );
169 if ( $needlePos ===
false ) {
174 $startPos = strrpos( $haystack,
'
187 protected function getAuthorsFromComment( $comment ) {
189 preg_match_all( '/@author (.*?)$/m
', $comment, $matches );
191 return $matches && $matches[1] ? $matches[1] : [];
195$maintClass = GenerateJsonI18n::class;
196require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script to generate JSON i18n files from a PHP i18n file.
__construct()
Default constructor.
getAuthorsFromComment( $comment)
Get an array of author names from a documentation comment containing.
transformI18nFile( $phpfile, $jsondir=null)
findCommentBefore( $needle, $haystack)
Find the documentation comment immediately before a given search string.
execute()
Do the actual work.
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.
hasOption( $name)
Checks to see if a particular param exists.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
maybeHelp( $force=false)
Maybe show the help.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
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