25require_once __DIR__ .
'/../Maintenance.php';
45 parent::__construct();
46 $this->
addDescription(
'Generate the normalizer data file for Arabic' );
47 $this->
addOption(
'unicode-data-file',
'The local location of the data file ' .
48 'from https://unicode.org/Public/6.0.0/ucd/UnicodeData.txt',
false,
true );
53 return Maintenance::DB_NONE;
57 if ( !$this->
hasOption(
'unicode-data-file' ) ) {
58 $dataFile =
'UnicodeData.txt';
59 if ( !file_exists( $dataFile ) ) {
60 $this->
fatalError(
"Unable to find UnicodeData.txt. Please specify " .
61 "its location with --unicode-data-file=<FILE>" );
64 $dataFile = $this->
getOption(
'unicode-data-file' );
65 if ( !file_exists( $dataFile ) ) {
66 $this->
fatalError(
'Unable to find the specified data file.' );
70 $file = fopen( $dataFile,
'r' );
72 $this->
fatalError(
'Unable to open the data file.' );
80 'Canonical_Combining_Class',
82 'Decomposition_Type_Mapping',
83 'Numeric_Type_Value_6',
84 'Numeric_Type_Value_7',
85 'Numeric_Type_Value_8',
89 'Simple_Uppercase_Mapping',
90 'Simple_Lowercase_Mapping',
91 'Simple_Titlecase_Mapping'
98 while ( ( $line = fgets( $file ) ) !==
false ) {
102 $line = trim( substr( $line, 0, strcspn( $line,
'#' ) ) );
103 if ( $line ===
'' ) {
108 $numberedData = explode(
';', $line );
110 foreach ( $fieldNames as $number => $name ) {
111 $data[$name] = $numberedData[$number];
114 $code = base_convert( $data[
'Code'], 16, 10 );
115 if ( ( $code >= 0xFB50 && $code <= 0xFDFF ) # Arabic presentation forms A
116 || ( $code >= 0xFE70 && $code <= 0xFEFF ) # Arabic presentation forms B
118 if ( $data[
'Decomposition_Type_Mapping'] ===
'' ) {
122 if ( !preg_match(
'/^ *(<\w*>) +([0-9A-F ]*)$/',
123 $data[
'Decomposition_Type_Mapping'], $m )
125 $this->
error(
"Can't parse Decomposition_Type/Mapping on line $lineNum" );
126 $this->
error( $line );
130 $source = UtfNormal\Utils::hexSequenceToUtf8( $data[
'Code'] );
131 $dest = UtfNormal\Utils::hexSequenceToUtf8( $m[2] );
138 file_put_contents(
"$IP/includes/languages/data/NormalizeAr.php", $writer->writeClass(
141 'header' =>
'Generated by generateNormalizerDataAr.php. Do not modify!',
142 'namespace' =>
'MediaWiki\\Languages\\Data',
143 'class' =>
'NormalizeAr',
148 echo
"ar: " . count( $pairs ) .
" pairs written.\n";
154require_once RUN_MAINTENANCE_IF_MAIN;
if(!defined('MEDIAWIKI')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Generates the normalizer data file for Arabic.
__construct()
Default constructor.
execute()
Do the actual work.
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
addDescription( $text)
Set the description text.