28define(
'MW_NO_EXTENSION_MESSAGES', 1 );
30require_once __DIR__ .
'/Maintenance.php';
42 parent::__construct();
45 'A file containing a list of extension setup files, one per line.',
49 $this->
addOption(
'extensions-dir',
'Path where extensions can be found.',
false,
true );
50 $this->
addOption(
'output',
'Send output to this file (omit for stdout)',
false,
true );
51 $this->
addDescription(
'Merge $wgExtensionMessagesFiles and $wgMessagesDirs from ' .
52 ' various extensions to produce a single file listing all message files and dirs.'
64 $this->
fatalError(
"Either --list-file or --extensions-dir must be provided if " .
65 "\$wgExtensionEntryPointListFiles is not set" );
68 $mmfl = [
'setupFiles' => [] ];
70 # Add setup files contained in file passed to --list-file
73 $mmfl[
'setupFiles'] = array_merge(
$mmfl[
'setupFiles'], $extensionPaths );
76 # Now find out files in a directory
77 if ( $this->
hasOption(
'extensions-dir' ) ) {
78 $extdir = $this->
getOption(
'extensions-dir' );
79 # Allow multiple directories to be passed with ":" as delimiter
80 $extdirs = explode(
':', $extdir );
81 foreach ( $extdirs as $extdir ) {
82 $entries = scandir( $extdir );
83 foreach ( $entries as $extname ) {
84 if ( $extname ==
'.' || $extname ==
'..' || !is_dir(
"$extdir/$extname" ) ) {
88 "$extdir/$extname/extension.json",
89 "$extdir/$extname/skin.json",
90 "$extdir/$extname/$extname.php"
93 foreach ( $possibilities as $extfile ) {
94 if ( file_exists( $extfile ) ) {
95 $mmfl[
'setupFiles'][] = $extfile;
102 $this->
error(
"Extension {$extname} in {$extdir} lacks expected entry point: " .
103 "extension.json, skin.json, or {$extname}.php." );
109 # Add setup files defined via configuration
110 foreach ( $wgExtensionEntryPointListFiles as $points ) {
111 $extensionPaths = $this->
readFile( $points );
112 $mmfl[
'setupFiles'] = array_merge(
$mmfl[
'setupFiles'], $extensionPaths );
116 $mmfl[
'output'] = $this->
getOption(
'output' );
119 $mmfl[
'quiet'] =
true;
124 # This script commonly needs to be run before the l10n cache. But if
125 # $wgLanguageCode is not 'en', it won't be able to run because there is
126 # no l10n cache. Break the cycle by forcing $wgLanguageCode = 'en'.
129 parent::finalSetup();
149 $fileLines = file( $fileName );
150 if ( $fileLines ===
false ) {
151 $this->
error(
"Unable to open list file $fileName." );
155 # Strip comments, discard empty lines, and trim leading and trailing
156 # whitespace. Comments start with '#' and extend to the end of the line.
157 foreach ( $fileLines as $extension ) {
158 $extension = trim( preg_replace(
'/#.*/',
'', $extension ) );
159 if ( $extension !==
'' ) {
160 # Paths may use the string $IP to be substituted by the actual value
161 $extension = str_replace(
'$IP',
$IP, $extension );
162 if ( file_exists( $extension ) ) {
163 $files[] = $extension;
165 $this->
error(
"Extension {$extension} doesn't exist" );
174require_once RUN_MAINTENANCE_IF_MAIN;
177'@phan-var string[][] $mmfl';
178foreach (
$mmfl[
'setupFiles'] as $fileName ) {
179 if ( strval( $fileName ) ===
'' ) {
182 if ( empty(
$mmfl[
'quiet'] ) ) {
183 fwrite( STDERR,
"Loading data from $fileName\n" );
186 if ( substr( $fileName, -strlen(
'.json' ) ) ===
'.json' ) {
189 require_once $fileName;
195 $data = $registry->readFromQueue(
$queue );
196 foreach ( [
'wgExtensionMessagesFiles',
'wgMessagesDirs' ] as $var ) {
197 if ( isset( $data[
'globals'][$var] ) ) {
198 $GLOBALS[$var] = array_merge( $data[
'globals'][$var], $GLOBALS[$var] );
203if ( empty(
$mmfl[
'quiet'] ) ) {
204 fwrite( STDERR,
"\n" );
208 "## This file is generated by mergeMessageFileList.php. Do not edit it directly.\n\n" .
209 "if ( defined( 'MW_NO_EXTENSION_MESSAGES' ) ) return;\n\n" .
219foreach ( $dirs as $dir ) {
220 $s = preg_replace(
"/'" . preg_quote( $dir,
'/' ) .
"([^']*)'/",
'"$IP\1"',
$s );
223if ( isset(
$mmfl[
'output'] ) ) {
224 $outputFile =
$mmfl[
'output'];
225 $res = file_put_contents( $outputFile,
$s );
226 if (
$res ===
false ) {
227 fwrite( STDERR,
"Failed to write to $outputFile\n" );
$wgExtensionEntryPointListFiles
Array of files with list(s) of extension entry points to be used in maintenance/mergeMessageFileList....
$wgLanguageCode
Site language code.
$wgMessagesDirs
Extension messages directories.
$wgExtensionMessagesFiles
Extension messages files.
The Registry loads JSON files, and uses a Processor to extract information from them.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
const DB_NONE
Constants for DB access type.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
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.
Maintenance script that merges $wgExtensionMessagesFiles from various extensions to produce a single ...
getDbType()
Database access is not needed.
execute()
Do the actual work.
finalSetup()
Handle some last-minute setup here.
__construct()
Default constructor.
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s