4 * Update list of upper case differences between JS and PHP
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
22 * @ingroup Maintenance
25 use MediaWiki\Shell\Shell
;
27 require_once __DIR__
. '/../Maintenance.php';
30 * Update list of upper case differences between JS and PHP
32 * @ingroup Maintenance
35 class GeneratePhpCharToUpperMappings
extends Maintenance
{
37 public function __construct() {
38 parent
::__construct();
39 $this->addDescription( 'Update list of upper case differences between JS and PHP.' );
42 public function execute() {
43 global $wgContLang, $IP;
47 $result = Shell
::command(
48 [ 'node', $IP . '/maintenance/mediawiki.Title/generateJsToUpperCaseList.js' ]
50 // Node allocates lots of memory
51 ->limits( [ 'memory' => 1024 * 1024 ] )
54 if ( $result->getExitcode() !== 0 ) {
55 $this->output( $result->getStderr() );
59 $jsUpperChars = json_decode( $result->getStdout() );
61 for ( $i = 0; $i <= 0x10ffff; $i++
) {
62 if ( $i >= 0xd800 && $i <= 0xdfff ) {
63 // Skip surrogate pairs
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.
75 $data[$char] = $phpUpper;
80 $mappingJson = str_replace( ' ', "\t",
81 json_encode( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE
)
83 $outputPath = '/resources/src/mediawiki.Title/phpCharToUpper.json';
84 $file = fopen( $IP . $outputPath, 'w' );
85 fwrite( $file, $mappingJson );
87 $this->output( count( $data ) . " differences found.\n" );
88 $this->output( "Written to $outputPath\n" );
92 $maintClass = GeneratePhpCharToUpperMappings
::class;
93 require_once RUN_MAINTENANCE_IF_MAIN
;