Merge "rdbms: add IDatabase::UNION_* constants for readability"
[lhc/web/wiklou.git] / maintenance / mediawiki.Title / generatePhpCharToUpperMappings.php
1 #!/usr/bin/env php
2 <?php
3 /**
4 * Utility to generate mapping file used in phpCharToUpper.js
5 *
6 * Compares output of String.toUpperCase in JavaScript with
7 * mb_strtoupper in PHP, and outputs a list of lower:upper
8 * mappings where they differ. This is then used by Title.js
9 * to provide the same normalization in the client as on
10 * the server.
11 */
12
13 $data = [];
14
15 // phpcs:disable MediaWiki.Usage.ForbiddenFunctions.exec
16 $jsUpperChars = json_decode( exec( 'node generateJsToUpperCaseList.js' ) );
17 // phpcs:enable MediaWiki.Usage.ForbiddenFunctions.exec
18
19 for ( $i = 0; $i < 65536; $i++ ) {
20 if ( $i >= 0xd800 && $i <= 0xdfff ) {
21 // Skip surrogate pairs
22 continue;
23 }
24 $char = mb_convert_encoding( '&#' . $i . ';', 'UTF-8', 'HTML-ENTITIES' );
25 $phpUpper = mb_strtoupper( $char );
26 $jsUpper = $jsUpperChars[$i];
27 if ( $jsUpper !== $phpUpper ) {
28 $data[$char] = $phpUpper;
29 }
30 }
31
32 echo 'var toUpperMapping = ' . str_replace( '"', "'",
33 str_replace( ' ', "\t",
34 json_encode( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE )
35 )
36 ) . ";\n";