MediaWiki REL1_35
generateUcfirstOverrides.php
Go to the documentation of this file.
1<?php
36
37require_once __DIR__ . '/../Maintenance.php';
38
40
41 public function __construct() {
42 parent::__construct();
43 $this->addDescription(
44 'Generates a php source file containing a definition for mb_strtoupper overrides' );
45 $this->addOption( 'outfile', 'Output file', true, true, 'o' );
46 $this->addOption( 'override', 'Char table we want to override', true, true );
47 $this->addOption( 'with', 'Char table we want to obtain', true, true );
48 }
49
50 public function execute() {
51 $outfile = $this->getOption( 'outfile' );
52 $from = $this->loadJson( $this->getOption( 'override' ) );
53 $to = $this->loadJson( $this->getOption( 'with' ) );
54 $overrides = [];
55
56 foreach ( $from as $lc => $uc ) {
57 $ref = $to[$lc] ?? null;
58 if ( $ref !== null && $ref !== $uc ) {
59 $overrides[$lc] = $ref;
60 }
61 }
62 $writer = new StaticArrayWriter();
63 file_put_contents(
64 $outfile,
65 $writer->create( $overrides, 'File created by generateUcfirstOverrides.php' )
66 );
67 }
68
69 private function loadJson( $filename ) {
70 $data = file_get_contents( $filename );
71 if ( $data === false ) {
72 $msg = sprintf( "Could not load data from file '%s'\n", $filename );
73 $this->fatalError( $msg );
74 }
75 $json = json_decode( $data, true );
76 if ( $json === null ) {
77 $msg = sprintf( "Invalid json in the data file %s\n", $filename );
78 $this->fatalError( $msg, 2 );
79 }
80 return $json;
81 }
82}
83
84$maintClass = GenerateUcfirstOverrides::class;
85require_once RUN_MAINTENANCE_IF_MAIN;
const RUN_MAINTENANCE_IF_MAIN
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.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Format a static PHP array to be written to a file.