MediaWiki  1.23.6
generateUtf8Case.php
Go to the documentation of this file.
1 <?php
28 require_once __DIR__ . '/../Maintenance.php';
29 
37 
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 );
44  }
45 
46  public function getDbType() {
47  return Maintenance::DB_NONE;
48  }
49 
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>" );
56  exit( 1 );
57  }
58  } else {
59  $dataFile = $this->getOption( 'unicode-data-file' );
60  if ( !file_exists( $dataFile ) ) {
61  $this->error( 'Unable to find the specified data file.' );
62  exit( 1 );
63  }
64  }
65 
66  $file = fopen( $dataFile, 'r' );
67  if ( !$file ) {
68  $this->error( 'Unable to open the data file.' );
69  exit( 1 );
70  }
71 
72  // For the file format, see http://www.unicode.org/reports/tr44/
73  $fieldNames = array(
74  'Code',
75  'Name',
76  'General_Category',
77  'Canonical_Combining_Class',
78  'Bidi_Class',
79  'Decomposition_Type_Mapping',
80  'Numeric_Type_Value_6',
81  'Numeric_Type_Value_7',
82  'Numeric_Type_Value_8',
83  'Bidi_Mirrored',
84  'Unicode_1_Name',
85  'ISO_Comment',
86  'Simple_Uppercase_Mapping',
87  'Simple_Lowercase_Mapping',
88  'Simple_Titlecase_Mapping'
89  );
90 
91  $upper = array();
92  $lower = array();
93 
94  $lineNum = 0;
95  while ( false !== ( $line = fgets( $file ) ) ) {
96  ++$lineNum;
97 
98  # Strip comments
99  $line = trim( substr( $line, 0, strcspn( $line, '#' ) ) );
100  if ( $line === '' ) {
101  continue;
102  }
103 
104  # Split fields
105  $numberedData = explode( ';', $line );
106  $data = array();
107  foreach ( $fieldNames as $number => $name ) {
108  $data[$name] = $numberedData[$number];
109  }
110 
111  $source = hexSequenceToUtf8( $data['Code'] );
112  if ( $data['Simple_Uppercase_Mapping'] ) {
113  $upper[$source] = hexSequenceToUtf8( $data['Simple_Uppercase_Mapping'] );
114  }
115  if ( $data['Simple_Lowercase_Mapping'] ) {
116  $lower[$source] = hexSequenceToUtf8( $data['Simple_Lowercase_Mapping'] );
117  }
118  }
119 
120  global $IP;
121  file_put_contents( "$IP/serialized/Utf8Case.ser", serialize( array(
122  'wikiUpperChars' => $upper,
123  'wikiLowerChars' => $lower,
124  ) ) );
125  }
126 }
127 
128 $maintClass = 'GenerateUtf8Case';
129 require_once RUN_MAINTENANCE_IF_MAIN;
GenerateUtf8Case\execute
execute()
Do the actual work.
Definition: generateUtf8Case.php:50
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
GenerateUtf8Case\getDbType
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition: generateUtf8Case.php:46
GenerateUtf8Case
Generates Utf8Case.ser from the Unicode Character Database and supplementary files.
Definition: generateUtf8Case.php:36
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$line
$line
Definition: cdb.php:57
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
Maintenance\DB_NONE
const DB_NONE
Constants for DB access type.
Definition: Maintenance.php:57
hexSequenceToUtf8
hexSequenceToUtf8( $sequence)
Take a series of space-separated hexadecimal numbers representing Unicode code points and return a UT...
Definition: UtfNormalUtil.php:61
$maintClass
$maintClass
Definition: generateUtf8Case.php:128
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
GenerateUtf8Case\__construct
__construct()
Default constructor.
Definition: generateUtf8Case.php:38
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$source
if(PHP_SAPI !='cli') $source
Definition: mwdoc-filter.php:18
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:333
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:181
$IP
$IP
Definition: WebStart.php:88