X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=maintenance%2Fmediawiki.Title%2FgeneratePhpCharToUpperMappings.php;h=9fc5513e3746f2307a0546ecaab84eab58097415;hp=8073c7c1290b950a56929e8d8f7636593c4e321c;hb=8c30c3704fa144f6d09cd27b127cef507d59d753;hpb=5b3106f12b95e7509e66301a62ae8c6198c5fda0 diff --git a/maintenance/mediawiki.Title/generatePhpCharToUpperMappings.php b/maintenance/mediawiki.Title/generatePhpCharToUpperMappings.php index 8073c7c129..9fc5513e37 100755 --- a/maintenance/mediawiki.Title/generatePhpCharToUpperMappings.php +++ b/maintenance/mediawiki.Title/generatePhpCharToUpperMappings.php @@ -40,11 +40,13 @@ class GeneratePhpCharToUpperMappings extends Maintenance { } public function execute() { - global $wgContLang; + global $wgContLang, $IP; $data = []; - $result = Shell::command( [ 'node', __DIR__ . '/generateJsToUpperCaseList.js' ] ) + $result = Shell::command( + [ 'node', $IP . '/maintenance/mediawiki.Title/generateJsToUpperCaseList.js' ] + ) // Node allocates lots of memory ->limits( [ 'memory' => 1024 * 1024 ] ) ->execute(); @@ -65,13 +67,28 @@ class GeneratePhpCharToUpperMappings extends Maintenance { $phpUpper = $wgContLang->ucfirst( $char ); $jsUpper = $jsUpperChars[$i]; if ( $jsUpper !== $phpUpper ) { - $data[$char] = $phpUpper; + if ( $char === $phpUpper ) { + // Optimisation: Use the empty string to signal "leave character unchanged". + // Reduces the transfer size by ~50%. Reduces browser memory cost as well. + $data[$char] = ''; + } else { + $data[$char] = $phpUpper; + } } } - $this->output( str_replace( ' ', "\t", + $mappingJson = str_replace( ' ', "\t", json_encode( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE ) - ) . "\n" ); + ) . "\n"; + $outputPath = '/resources/src/mediawiki.Title/phpCharToUpper.json'; + $file = fopen( $IP . $outputPath, 'w' ); + if ( !$file ) { + $this->fatalError( "Unable to write file \"$IP$outputPath\"" ); + } + fwrite( $file, $mappingJson ); + + $this->output( count( $data ) . " differences found.\n" ); + $this->output( "Written to $outputPath\n" ); } }