MediaWiki REL1_33
mergeMessageFileList.php
Go to the documentation of this file.
1<?php
25# Start from scratch
26define( 'MW_NO_EXTENSION_MESSAGES', 1 );
27
28require_once __DIR__ . '/Maintenance.php';
29$maintClass = MergeMessageFileList::class;
30$mmfl = false;
31
39 function __construct() {
40 parent::__construct();
41 $this->addOption(
42 'list-file',
43 'A file containing a list of extension setup files, one per line.',
44 false,
45 true
46 );
47 $this->addOption( 'extensions-dir', 'Path where extensions can be found.', false, true );
48 $this->addOption( 'output', 'Send output to this file (omit for stdout)', false, true );
49 $this->addDescription( 'Merge $wgExtensionMessagesFiles and $wgMessagesDirs from ' .
50 ' various extensions to produce a single file listing all message files and dirs.'
51 );
52 }
53
54 public function execute() {
55 // phpcs:ignore MediaWiki.NamingConventions.ValidGlobalName.wgPrefix
56 global $mmfl;
58
60 && !$this->hasOption( 'list-file' )
61 && !$this->hasOption( 'extensions-dir' )
62 ) {
63 $this->fatalError( "Either --list-file or --extensions-dir must be provided if " .
64 "\$wgExtensionEntryPointListFiles is not set" );
65 }
66
67 $mmfl = [ 'setupFiles' => [] ];
68
69 # Add setup files contained in file passed to --list-file
70 if ( $this->hasOption( 'list-file' ) ) {
71 $extensionPaths = $this->readFile( $this->getOption( 'list-file' ) );
72 $mmfl['setupFiles'] = array_merge( $mmfl['setupFiles'], $extensionPaths );
73 }
74
75 # Now find out files in a directory
76 if ( $this->hasOption( 'extensions-dir' ) ) {
77 $extdir = $this->getOption( 'extensions-dir' );
78 # Allow multiple directories to be passed with ":" as delimiter
79 $extdirs = explode( ':', $extdir );
80 foreach ( $extdirs as $extdir ) {
81 $entries = scandir( $extdir );
82 foreach ( $entries as $extname ) {
83 if ( $extname == '.' || $extname == '..' || !is_dir( "$extdir/$extname" ) ) {
84 continue;
85 }
86 $possibilities = [
87 "$extdir/$extname/extension.json",
88 "$extdir/$extname/skin.json",
89 "$extdir/$extname/$extname.php"
90 ];
91 $found = false;
92 foreach ( $possibilities as $extfile ) {
93 if ( file_exists( $extfile ) ) {
94 $mmfl['setupFiles'][] = $extfile;
95 $found = true;
96 break;
97 }
98 }
99
100 if ( !$found ) {
101 $this->error( "Extension {$extname} in {$extdir} lacks expected entry point: " .
102 "extension.json, skin.json, or {$extname}.php." );
103 }
104 }
105 }
106 }
107
108 # Add setup files defined via configuration
109 foreach ( $wgExtensionEntryPointListFiles as $points ) {
110 $extensionPaths = $this->readFile( $points );
111 $mmfl['setupFiles'] = array_merge( $mmfl['setupFiles'], $extensionPaths );
112 }
113
114 if ( $this->hasOption( 'output' ) ) {
115 $mmfl['output'] = $this->getOption( 'output' );
116 }
117 if ( $this->hasOption( 'quiet' ) ) {
118 $mmfl['quiet'] = true;
119 }
120 }
121
126 private function readFile( $fileName ) {
127 global $IP;
128
129 $files = [];
130 $fileLines = file( $fileName );
131 if ( $fileLines === false ) {
132 $this->hasError = true;
133 $this->error( "Unable to open list file $fileName." );
134
135 return $files;
136 }
137 # Strip comments, discard empty lines, and trim leading and trailing
138 # whitespace. Comments start with '#' and extend to the end of the line.
139 foreach ( $fileLines as $extension ) {
140 $extension = trim( preg_replace( '/#.*/', '', $extension ) );
141 if ( $extension !== '' ) {
142 # Paths may use the string $IP to be substituted by the actual value
143 $extension = str_replace( '$IP', $IP, $extension );
144 if ( file_exists( $extension ) ) {
145 $files[] = $extension;
146 } else {
147 $this->hasError = true;
148 $this->error( "Extension {$extension} doesn't exist" );
149 }
150 }
151 }
152
153 return $files;
154 }
155}
156
157require_once RUN_MAINTENANCE_IF_MAIN;
158
160foreach ( $mmfl['setupFiles'] as $fileName ) {
161 if ( strval( $fileName ) === '' ) {
162 continue;
163 }
164 if ( empty( $mmfl['quiet'] ) ) {
165 fwrite( STDERR, "Loading data from $fileName\n" );
166 }
167 // Using extension.json or skin.json
168 if ( substr( $fileName, -strlen( '.json' ) ) === '.json' ) {
169 $queue[$fileName] = 1;
170 } else {
171 require_once $fileName;
172 }
173}
174
175if ( $queue ) {
176 $registry = new ExtensionRegistry();
177 $data = $registry->readFromQueue( $queue );
178 foreach ( [ 'wgExtensionMessagesFiles', 'wgMessagesDirs' ] as $var ) {
179 if ( isset( $data['globals'][$var] ) ) {
180 $GLOBALS[$var] = array_merge( $data['globals'][$var], $GLOBALS[$var] );
181 }
182 }
183}
184
185fwrite( STDERR, "\n" );
187 "<?php\n" .
188 "## This file is generated by mergeMessageFileList.php. Do not edit it directly.\n\n" .
189 "if ( defined( 'MW_NO_EXTENSION_MESSAGES' ) ) return;\n\n" .
190 '$wgExtensionMessagesFiles = ' . var_export( $wgExtensionMessagesFiles, true ) . ";\n\n" .
191 '$wgMessagesDirs = ' . var_export( $wgMessagesDirs, true ) . ";\n\n";
192
193$dirs = [
194 $IP,
195 dirname( __DIR__ ),
196 realpath( $IP )
197];
198
199foreach ( $dirs as $dir ) {
200 $s = preg_replace( "/'" . preg_quote( $dir, '/' ) . "([^']*)'/", '"$IP\1"', $s );
201}
202
203if ( isset( $mmfl['output'] ) ) {
204 file_put_contents( $mmfl['output'], $s );
205} else {
206 echo $s;
207}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$GLOBALS['IP']
$wgExtensionEntryPointListFiles
Array of files with list(s) of extension entry points to be used in maintenance/mergeMessageFileList....
$wgMessagesDirs['ReplaceText']
ExtensionRegistry class.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
hasOption( $name)
Checks to see if a particular option exists.
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 ...
execute()
Do the actual work.
__construct()
Default constructor.
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
Definition hooks.txt:2644
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going and make changes or fix bugs In we can take all the code that deals with the little used title reversing we can concentrate it all in an extension file
Definition hooks.txt:106
$IP
Definition update.php:3
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
$wgExtensionMessagesFiles['ExtensionNameMagic']
Definition magicword.txt:43
require_once RUN_MAINTENANCE_IF_MAIN
$points