31define(
'MW_NO_EXTENSION_MESSAGES', 1 );
33require_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.'
67 $this->
fatalError(
"Either --list-file or --extensions-dir must be provided if " .
68 "\$wgExtensionEntryPointListFiles is not set" );
71 $mmfl = [
'setupFiles' => [] ];
73 # Add setup files contained in file passed to --list-file
75 $extensionPaths = $this->readFile( $this->
getOption(
'list-file' ) );
76 $mmfl[
'setupFiles'] = array_merge(
$mmfl[
'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",
93 "$extdir/$extname/$extname.php"
96 foreach ( $possibilities as $extfile ) {
97 if ( file_exists( $extfile ) ) {
98 $mmfl[
'setupFiles'][] = $extfile;
105 $this->
error(
"Extension {$extname} in {$extdir} lacks expected entry point: " .
106 "extension.json, skin.json, or {$extname}.php." );
112 # Add setup files defined via configuration
113 foreach ( $wgExtensionEntryPointListFiles as $points ) {
114 $extensionPaths = $this->readFile( $points );
115 $mmfl[
'setupFiles'] = array_merge(
$mmfl[
'setupFiles'], $extensionPaths );
119 $mmfl[
'output'] = $this->
getOption(
'output' );
122 $mmfl[
'quiet'] =
true;
127 # This script commonly needs to be run before the l10n cache. But if
128 # LanguageCode is not 'en', it won't be able to run because there is
129 # no l10n cache. Break the cycle by forcing the LanguageCode setting to 'en'.
130 $settingsBuilder->putConfigValue( MainConfigNames::LanguageCode,
'en' );
131 parent::finalSetup( $settingsBuilder );
147 private function readFile( $fileName ) {
151 $fileLines = file( $fileName );
152 if ( $fileLines ===
false ) {
153 $this->
error(
"Unable to open list file $fileName." );
157 # Strip comments, discard empty lines, and trim leading and trailing
158 # whitespace. Comments start with '#' and extend to the end of the line.
159 foreach ( $fileLines as $extension ) {
160 $extension = trim( preg_replace(
'/#.*/',
'', $extension ) );
161 if ( $extension !==
'' ) {
162 # Paths may use the string $IP to be substituted by the actual value
163 $extension = str_replace(
'$IP',
$IP, $extension );
164 if ( file_exists( $extension ) ) {
165 $files[] = $extension;
167 $this->
error(
"Extension {$extension} doesn't exist" );
176require_once RUN_MAINTENANCE_IF_MAIN;
179'@phan-var string[][] $mmfl';
180foreach (
$mmfl[
'setupFiles'] as $fileName ) {
181 if ( strval( $fileName ) ===
'' ) {
184 if ( empty(
$mmfl[
'quiet'] ) ) {
185 fwrite( STDERR,
"Loading data from $fileName\n" );
188 if ( str_ends_with( $fileName,
'.json' ) ) {
191 require_once $fileName;
197 $data = $registry->readFromQueue(
$queue );
198 foreach ( [
'wgExtensionMessagesFiles',
'wgMessagesDirs' ] as $var ) {
199 if ( isset( $data[
'globals'][$var] ) ) {
200 $GLOBALS[$var] = array_merge( $data[
'globals'][$var], $GLOBALS[$var] );
205if ( empty(
$mmfl[
'quiet'] ) ) {
206 fwrite( STDERR,
"\n" );
210 "## This file is generated by mergeMessageFileList.php. Do not edit it directly.\n\n" .
211 "if ( defined( 'MW_NO_EXTENSION_MESSAGES' ) ) return;\n\n" .
221foreach ( $dirs as $dir ) {
222 $s = preg_replace(
"/'" . preg_quote( $dir,
'/' ) .
"([^']*)'/",
'"$IP\1"',
$s );
225if ( isset(
$mmfl[
'output'] ) ) {
226 $outputFile =
$mmfl[
'output'];
227 $res = file_put_contents( $outputFile,
$s );
228 if (
$res ===
false ) {
229 fwrite( STDERR,
"Failed to write to $outputFile\n" );
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
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.
A class containing constants representing the names of configuration variables.
Maintenance script that merges $wgExtensionMessagesFiles from various extensions to produce a single ...
getDbType()
Database access is not needed.
finalSetup(SettingsBuilder $settingsBuilder=null)
Handle some last-minute setup here.
execute()
Do the actual work.
__construct()
Default constructor.
$wgExtensionEntryPointListFiles
Config variable stub for the ExtensionEntryPointListFiles setting, for use by phpdoc and IDEs.
$wgMessagesDirs
Config variable stub for the MessagesDirs setting, for use by phpdoc and IDEs.
$wgExtensionMessagesFiles
Config variable stub for the ExtensionMessagesFiles setting, for use by phpdoc and IDEs.
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s