MediaWiki REL1_34
generatePhpCharToUpperMappings.php
Go to the documentation of this file.
1<?php
2
26
27require_once __DIR__ . '/../Maintenance.php';
28
36
37 public function __construct() {
38 parent::__construct();
39 $this->addDescription( 'Update list of upper case differences between JS and PHP.' );
40 }
41
42 public function execute() {
43 global $wgContLang, $IP;
44
45 $data = [];
46
47 $result = Shell::command(
48 [ 'node', $IP . '/maintenance/mediawiki.Title/generateJsToUpperCaseList.js' ]
49 )
50 // Node allocates lots of memory
51 ->limits( [ 'memory' => 1024 * 1024 ] )
52 ->execute();
53
54 if ( $result->getExitcode() !== 0 ) {
55 $this->output( $result->getStderr() );
56 return;
57 }
58
59 $jsUpperChars = json_decode( $result->getStdout() );
60
61 for ( $i = 0; $i <= 0x10ffff; $i++ ) {
62 if ( $i >= 0xd800 && $i <= 0xdfff ) {
63 // Skip surrogate pairs
64 continue;
65 }
66 $char = \UtfNormal\Utils::codepointToUtf8( $i );
67 $phpUpper = $wgContLang->ucfirst( $char );
68 $jsUpper = $jsUpperChars[$i];
69 if ( $jsUpper !== $phpUpper ) {
70 if ( $char === $phpUpper ) {
71 // Optimisation: Use the empty string to signal "leave character unchanged".
72 // Reduces the transfer size by ~50%. Reduces browser memory cost as well.
73 $data[$char] = '';
74 } else {
75 $data[$char] = $phpUpper;
76 }
77 }
78 }
79
80 $mappingJson = str_replace( ' ', "\t",
81 json_encode( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE )
82 ) . "\n";
83 $outputPath = '/resources/src/mediawiki.Title/phpCharToUpper.json';
84 $file = fopen( $IP . $outputPath, 'w' );
85 if ( !$file ) {
86 $this->fatalError( "Unable to write file \"$IP$outputPath\"" );
87 }
88 fwrite( $file, $mappingJson );
89
90 $this->output( count( $data ) . " differences found.\n" );
91 $this->output( "Written to $outputPath\n" );
92 }
93}
94
95$maintClass = GeneratePhpCharToUpperMappings::class;
96require_once RUN_MAINTENANCE_IF_MAIN;
const RUN_MAINTENANCE_IF_MAIN
$wgContLang
Definition Setup.php:800
$IP
Definition WebStart.php:41
Update list of upper case differences between JS and PHP.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
addDescription( $text)
Set the description text.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Executes shell commands.
Definition Shell.php:44
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42