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