r56581 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56580‎ | r56581 | r56582 >
Date:04:27, 18 September 2009
Author:tstarling
Status:ok
Tags:
Comment:
Was too slow. Trying different approach.
Modified paths:
  • /trunk/phase3/maintenance/mergeMessageFileList.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/mergeMessageFileList.php
@@ -2,23 +2,18 @@
33
44 require_once( dirname( __FILE__ ).'/Maintenance.php' );
55 $maintClass = 'MergeMessageFileList';
6 -
 6+$mmfl = false;
77 class MergeMessageFileList extends Maintenance {
88
99 function __construct() {
10 - $this->addOption( 'list-file', 'A file containing a list of wikis, one per line.', false, true );
11 - $this->addOption( 'get', 'Get the message files for a single wiki (for internal use).' );
 10+ $this->addOption( 'list-file', 'A file containing a list of extension setup files, one per line.', false, true );
1211 $this->addOption( 'output', 'Send output to this file (omit for stdout)', false, true );
13 - $this->mDescription = 'Merge $wgExtensionMessagesFiles from various wikis to produce a ' .
 12+ $this->mDescription = 'Merge $wgExtensionMessagesFiles from various extensions to produce a ' .
1413 'single array containing all message files.';
1514 }
1615
1716 public function execute() {
18 - if ( $this->hasOption( 'get' ) ) {
19 - var_export( $GLOBALS['wgExtensionMessagesFiles'] );
20 - return;
21 - }
22 -
 17+ global $IP, $mmfl;
2318 if ( !$this->hasOption( 'list-file' ) ) {
2419 $this->error( 'The --list-file option must be specified.' );
2520 return;
@@ -28,32 +23,31 @@
2924 if ( $lines === false ) {
3025 $this->error( 'Unable to open list file.' );
3126 }
32 - $wikis = array_map( 'trim', $lines );
33 -
34 - # Find PHP
35 - $php = readlink( '/proc/' . posix_getpid() . '/exe' );
36 - $allFiles = array();
37 -
38 - foreach ( $wikis as $wiki ) {
39 - $s = wfShellExec( wfEscapeShellArg( $php, __FILE__, '--get',
40 - '--wiki', $wiki ) );
41 - if ( !$s ) {
42 - $this->error( 'Unable to get messages for wiki '. $wiki );
43 - continue;
44 - }
45 - $files = eval( "return $s;" );
46 - $allFiles += $files;
47 - }
48 - $s = '$wgExtensionMessagesFiles = ' .
49 - var_export( $allFiles, true ) .
50 - ";\n";
 27+ $mmfl = array( 'setupFiles' => array_map( 'trim', $lines ) );
5128 if ( $this->hasOption( 'output' ) ) {
52 - file_put_contents( $this->getOption( 'output' ), $s );
53 - } else {
54 - echo $s;
 29+ $mmfl['output'] = $this->getOption( 'output' );
5530 }
5631 }
5732 }
5833
5934 require_once( DO_MAINTENANCE );
6035
 36+foreach ( $mmfl['setupFiles'] as $fileName ) {
 37+ if ( strval( $fileName ) === '' ) {
 38+ continue;
 39+ }
 40+ $fileName = str_replace( '$IP', $IP, $fileName );
 41+ include_once( $fileName );
 42+}
 43+fwrite( STDERR, "\n" );
 44+$s = '$wgExtensionMessagesFiles = ' . var_export( $wgExtensionMessagesFiles, true ) . ";\n\n" .
 45+ '$wgExtensionAliasesFiles = ' . var_export( $wgExtensionAliasesFiles, true ) . ";\n";
 46+
 47+$s = preg_replace( "/'" . preg_quote( $IP, '/' ) . "([^']*)'/",
 48+ '"$IP/\1"', $s );
 49+if ( isset( $mmfl['output'] ) ) {
 50+ file_put_contents( $mmfl['output'], $s );
 51+} else {
 52+ echo $s;
 53+}
 54+

Status & tagging log