MediaWiki master
generateUpperCharTable.php
Go to the documentation of this file.
1<?php
26require_once __DIR__ . '/../Maintenance.php';
27
29
30 public function __construct() {
31 parent::__construct();
32 $this->addDescription( 'Generates the lowercase => uppercase json table' );
33 $this->addOption( 'outfile', 'Output file', true, true, 'o' );
34 $this->addOption( 'titlecase', 'Use title case instead of upper case' );
35 }
36
37 public function execute() {
38 $outfile = $this->getOption( 'outfile', 'upperchar.json' );
39 $toUpperTable = [];
40 $titlecase = $this->getOption( 'titlecase' );
41 for ( $i = 0; $i <= 0x10ffff; $i++ ) {
42 // skip all surrogate codepoints or json_encode would fail.
43 if ( $i >= 0xd800 && $i <= 0xdfff ) {
44 continue;
45 }
46 $char = UtfNormal\Utils::codepointToUtf8( $i );
47 if ( $titlecase ) {
48 $upper = mb_convert_case( $char, MB_CASE_TITLE );
49 } else {
50 $upper = mb_strtoupper( $char );
51 }
52 $toUpperTable[$char] = $upper;
53 }
54 file_put_contents( $outfile, json_encode( $toUpperTable ) );
55 }
56}
57
58$maintClass = GenerateUpperCharTable::class;
59require_once RUN_MAINTENANCE_IF_MAIN;
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.