32define(
'MW_NO_EXTENSION_MESSAGES', 1 );
34require_once __DIR__ .
'/Maintenance.php';
45 parent::__construct();
48 'A file containing a list of extension setup files, one per line.',
52 $this->
addOption(
'extensions-dir',
'Path where extensions can be found.',
false,
true );
53 $this->
addOption(
'output',
'Send output to this file (omit for stdout)',
false,
true );
54 $this->
addDescription(
'Merge $wgExtensionMessagesFiles and $wgMessagesDirs from ' .
55 ' various extensions to produce a single file listing all message files and dirs.'
61 $extensionEntryPointListFiles = $config->get( MainConfigNames::ExtensionEntryPointListFiles );
63 if ( !count( $extensionEntryPointListFiles )
67 $this->
fatalError(
"Either --list-file or --extensions-dir must be provided if " .
68 "\$wgExtensionEntryPointListFiles is not set" );
73 # Add setup files contained in file passed to --list-file
75 $extensionPaths = $this->readFile( $this->
getOption(
'list-file' ) );
76 $setupFiles = array_merge( $setupFiles, $extensionPaths );
79 # Now find out files in a directory
80 if ( $this->
hasOption(
'extensions-dir' ) ) {
81 $extdir = $this->
getOption(
'extensions-dir' );
82 # Allow multiple directories to be passed with ":" as delimiter
83 $extdirs = explode(
':', $extdir );
84 foreach ( $extdirs as $extdir ) {
85 $entries = scandir( $extdir );
86 foreach ( $entries as $extname ) {
87 if ( $extname ==
'.' || $extname ==
'..' || !is_dir(
"$extdir/$extname" ) ) {
91 "$extdir/$extname/extension.json",
92 "$extdir/$extname/skin.json",
95 foreach ( $possibilities as $extfile ) {
96 if ( file_exists( $extfile ) ) {
97 $setupFiles[] = $extfile;
104 $this->
error(
"Extension {$extname} in {$extdir} lacks expected entry point: " .
105 "extension.json or skin.json " .
106 "(PHP entry points are no longer supported by this script)." );
112 # Add setup files defined via configuration
113 foreach ( $extensionEntryPointListFiles as $points ) {
114 $extensionPaths = $this->readFile( $points );
115 $setupFiles = array_merge( $setupFiles, $extensionPaths );
118 $this->generateMessageFileList( $setupFiles );
122 # This script commonly needs to be run before the l10n cache. But if
123 # LanguageCode is not 'en', it won't be able to run because there is
124 # no l10n cache. Break the cycle by forcing the LanguageCode setting to 'en'.
125 $settingsBuilder->
putConfigValue( MainConfigNames::LanguageCode,
'en' );
126 parent::finalSetup( $settingsBuilder );
135 return Maintenance::DB_NONE;
142 private function readFile( $fileName ) {
143 $IP = MW_INSTALL_PATH;
146 $fileLines = file( $fileName );
147 if ( $fileLines ===
false ) {
148 $this->
error(
"Unable to open list file $fileName." );
152 # Strip comments, discard empty lines, and trim leading and trailing
153 # whitespace. Comments start with '#' and extend to the end of the line.
154 foreach ( $fileLines as $extension ) {
155 $extension = trim( preg_replace(
'/#.*/',
'', $extension ) );
156 if ( $extension !==
'' ) {
157 # Paths may use the string $IP to be substituted by the actual value
158 $extension = str_replace(
'$IP',
$IP, $extension );
159 if ( !str_ends_with( $extension,
'.json' ) ) {
160 $this->
error(
"Extension {$extension} does not end with .json " .
161 "(PHP entry points are no longer supported by this script)" );
162 } elseif ( file_exists( $extension ) ) {
163 $files[] = $extension;
165 $this->
error(
"Extension {$extension} doesn't exist" );
173 private function generateMessageFileList( array $setupFiles ) {
174 $IP = MW_INSTALL_PATH;
176 $outputFile = $this->
getOption(
'output' );
181 foreach ( $setupFiles as $fileName ) {
182 if ( strval( $fileName ) ===
'' ) {
186 fwrite( STDERR,
"Loading data from $fileName\n" );
188 $queue[$fileName] = 1;
193 'wgExtensionMessagesFiles' => $config->get( MainConfigNames::ExtensionMessagesFiles ),
194 'wgMessagesDirs' => $config->get( MainConfigNames::MessagesDirs ),
199 $data = $registry->readFromQueue( $queue );
200 foreach ( [
'wgExtensionMessagesFiles',
'wgMessagesDirs' ] as $var ) {
201 if ( isset( $data[
'globals'][$var] ) ) {
202 $vars[$var] = array_merge( $data[
'globals'][$var], $vars[$var] );
208 fwrite( STDERR,
"\n" );
212 "## This file is generated by mergeMessageFileList.php. Do not edit it directly.\n\n" .
213 "if ( defined( 'MW_NO_EXTENSION_MESSAGES' ) ) return;\n\n" .
214 '$wgExtensionMessagesFiles = ' . var_export( $vars[
'wgExtensionMessagesFiles'],
true ) .
";\n\n" .
215 '$wgMessagesDirs = ' . var_export( $vars[
'wgMessagesDirs'],
true ) .
";\n\n";
223 foreach ( $dirs as $dir ) {
224 $s = preg_replace(
"/'" . preg_quote( $dir,
'/' ) .
"([^']*)'/",
'"$IP\1"', $s );
227 if ( $outputFile !==
null ) {
228 $res = file_put_contents( $outputFile, $s );
229 if ( $res ===
false ) {
230 fwrite( STDERR,
"Failed to write to $outputFile\n" );
241require_once RUN_MAINTENANCE_IF_MAIN;
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
A class containing constants representing the names of configuration variables.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
addDescription( $text)
Set the description text.
Maintenance script that merges $wgExtensionMessagesFiles from various extensions to produce a single ...
getDbType()
Database access is not needed.
execute()
Do the actual work.
finalSetup(SettingsBuilder $settingsBuilder)
Handle some last-minute setup here.
__construct()
Default constructor.