MediaWiki REL1_39
generatePhpCharToUpperMappings.php
Go to the documentation of this file.
1<?php
2
27
28require_once __DIR__ . '/../Maintenance.php';
29
37
38 public function __construct() {
39 parent::__construct();
40 $this->addDescription( 'Update list of upper case differences between JS and PHP.' );
41 }
42
43 public function execute() {
44 global $IP;
45
46 $data = [];
47
48 $result = Shell::command(
49 [ 'node', $IP . '/maintenance/mediawiki.Title/generateJsToUpperCaseList.js' ]
50 )
51 // Node allocates lots of memory
52 ->limits( [ 'memory' => 1024 * 1024 ] )
53 ->execute();
54
55 if ( $result->getExitCode() !== 0 ) {
56 $this->output( $result->getStderr() );
57 return;
58 }
59
60 $jsUpperChars = json_decode( $result->getStdout() );
61 '@phan-var string[] $jsUpperChars';
62
63 for ( $i = 0; $i <= 0x10ffff; $i++ ) {
64 if ( $i >= 0xd800 && $i <= 0xdfff ) {
65 // Skip surrogate pairs
66 continue;
67 }
68 $char = \UtfNormal\Utils::codepointToUtf8( $i );
69 $phpUpper = MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $char );
70 $jsUpper = $jsUpperChars[$i];
71 if ( $jsUpper !== $phpUpper ) {
72 if ( $char === $phpUpper ) {
73 // Optimisation: Use 0 to signal "leave character unchanged".
74 // Reduces the transfer size by ~50%. Reduces browser memory cost as well.
75 $data[$char] = 0;
76 } else {
77 $data[$char] = $phpUpper;
78 }
79 }
80 }
81
82 $mappingJson = str_replace( ' ', "\t",
83 json_encode( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE )
84 ) . "\n";
85 $outputPath = '/resources/src/mediawiki.Title/phpCharToUpper.json';
86 $file = fopen( $IP . $outputPath, 'w' );
87 if ( !$file ) {
88 $this->fatalError( "Unable to write file \"$IP$outputPath\"" );
89 }
90 fwrite( $file, $mappingJson );
91
92 $this->output( count( $data ) . " differences found.\n" );
93 $this->output( "Written to $outputPath\n" );
94 }
95}
96
97$maintClass = GeneratePhpCharToUpperMappings::class;
98require_once RUN_MAINTENANCE_IF_MAIN;
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition Setup.php:91
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.
Service locator for MediaWiki core services.
Executes shell commands.
Definition Shell.php:46
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42