| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
use MediaWiki\Maintenance\Maintenance; |
| 26 |
use MediaWiki\Shell\Shell; |
| 27 |
|
| 28 |
|
| 29 |
require_once __DIR__ . '/../Maintenance.php'; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
class GeneratePhpCharToUpperMappings extends Maintenance { |
| 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 |
|
| 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 |
|
| 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 |
|
| 77 |
|
| 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 |
|
| 101 |
$maintClass = GeneratePhpCharToUpperMappings::class; |
| 102 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 103 |
|