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