3 * Generates Utf8Case.ser from the Unicode Character Database and
6 * Copyright © 2004, 2008 Brion Vibber <brion@pobox.com>
7 * https://www.mediawiki.org/
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
25 * @ingroup MaintenanceLanguage
28 require_once __DIR__
. '/../Maintenance.php';
31 * Generates Utf8Case.ser from the Unicode Character Database and
32 * supplementary files.
34 * @ingroup MaintenanceLanguage
36 class GenerateUtf8Case
extends Maintenance
{
38 public function __construct() {
39 parent
::__construct();
40 $this->mDescription
= 'Generate Utf8Case.ser from the Unicode Character Database ' .
41 'and supplementary files';
42 $this->addOption( 'unicode-data-file', 'The local location of the data file ' .
43 'from http://unicode.org/Public/UNIDATA/UnicodeData.txt', false, true );
46 public function getDbType() {
47 return Maintenance
::DB_NONE
;
50 public function execute() {
51 if ( !$this->hasOption( 'unicode-data-file' ) ) {
52 $dataFile = 'UnicodeData.txt';
53 if ( !file_exists( $dataFile ) ) {
54 $this->error( "Unable to find UnicodeData.txt. Please specify " .
55 "its location with --unicode-data-file=<FILE>" );
59 $dataFile = $this->getOption( 'unicode-data-file' );
60 if ( !file_exists( $dataFile ) ) {
61 $this->error( 'Unable to find the specified data file.' );
66 $file = fopen( $dataFile, 'r' );
68 $this->error( 'Unable to open the data file.' );
72 // For the file format, see http://www.unicode.org/reports/tr44/
77 'Canonical_Combining_Class',
79 'Decomposition_Type_Mapping',
80 'Numeric_Type_Value_6',
81 'Numeric_Type_Value_7',
82 'Numeric_Type_Value_8',
86 'Simple_Uppercase_Mapping',
87 'Simple_Lowercase_Mapping',
88 'Simple_Titlecase_Mapping'
95 while ( false !== ( $line = fgets( $file ) ) ) {
99 $line = trim( substr( $line, 0, strcspn( $line, '#' ) ) );
100 if ( $line === '' ) {
105 $numberedData = explode( ';', $line );
107 foreach ( $fieldNames as $number => $name ) {
108 $data[$name] = $numberedData[$number];
111 $source = hexSequenceToUtf8( $data['Code'] );
112 if ( $data['Simple_Uppercase_Mapping'] ) {
113 $upper[$source] = hexSequenceToUtf8( $data['Simple_Uppercase_Mapping'] );
115 if ( $data['Simple_Lowercase_Mapping'] ) {
116 $lower[$source] = hexSequenceToUtf8( $data['Simple_Lowercase_Mapping'] );
121 file_put_contents( "$IP/serialized/Utf8Case.ser", serialize( array(
122 'wikiUpperChars' => $upper,
123 'wikiLowerChars' => $lower,
128 $maintClass = 'GenerateUtf8Case';
129 require_once RUN_MAINTENANCE_IF_MAIN
;