24require_once __DIR__ .
'/../Maintenance.php';
56 parent::__construct();
57 $this->
addOption(
'data-dir',
'A directory on the local filesystem ' .
58 'containing allkeys.txt and ucd.all.grouped.xml from unicode.org',
60 $this->
addOption(
'debug-output',
'Filename for sending debug output to',
65 $this->dataDir = $this->
getOption(
'data-dir',
'.' );
67 $allkeysPresent = file_exists(
"{$this->dataDir}/allkeys.txt" );
68 $ucdallPresent = file_exists(
"{$this->dataDir}/ucd.all.grouped.xml" );
72 $allkeysURL =
"https://www.unicode.org/Public/UCA/<Unicode version>/allkeys.txt";
73 $ucdallURL =
"https://www.unicode.org/Public/<Unicode version>/ucdxml/ucd.all.grouped.zip";
75 if ( !$allkeysPresent || !$ucdallPresent ) {
76 $icuVersion = INTL_ICU_VERSION;
81 if ( !$allkeysPresent ) {
82 $error .=
"Unable to find allkeys.txt. "
83 .
"Download it and specify its location with --data-dir=<DIR>. "
86 if ( !$ucdallPresent ) {
87 $error .=
"Unable to find ucd.all.grouped.xml. "
88 .
"Download it, unzip, and specify its location with --data-dir=<DIR>. "
92 $versionKnown =
false;
93 if ( version_compare( $icuVersion,
"4.0",
"<" ) ) {
95 $error .=
"You are using outdated version of ICU ($icuVersion), intended for "
96 . ( $unicodeVersion ?
"Unicode $unicodeVersion" :
"an unknown version of Unicode" )
97 .
"; this file might not be avalaible for it, and it's not supported by MediaWiki. "
98 .
" You are on your own; consider upgrading PHP's intl extension or try "
99 .
"one of the files available at:";
100 } elseif ( version_compare( $icuVersion,
"51.0",
">=" ) ) {
102 $error .=
"You are using ICU $icuVersion, released after this script was last updated. "
103 .
"Check what is the Unicode version it is using at http://site.icu-project.org/download . "
104 .
"It can't be guaranteed everything will work, but appropriate file(s) should "
105 .
"be available at:";
108 $versionKnown =
true;
109 $error .=
"You are using ICU $icuVersion, intended for "
110 . ( $unicodeVersion ?
"Unicode $unicodeVersion" :
"an unknown version of Unicode" )
111 .
". Appropriate file(s) should be available at:";
115 if ( $versionKnown && $unicodeVersion ) {
116 $allkeysURL = str_replace(
"<Unicode version>",
"$unicodeVersion.0", $allkeysURL );
117 $ucdallURL = str_replace(
"<Unicode version>",
"$unicodeVersion.0", $ucdallURL );
120 if ( !$allkeysPresent ) {
121 $error .=
"* $allkeysURL\n";
123 if ( !$ucdallPresent ) {
124 $error .=
"* $ucdallURL\n";
130 $debugOutFileName = $this->
getOption(
'debug-output' );
131 if ( $debugOutFileName ) {
132 $this->debugOutFile = fopen( $debugOutFileName,
'w' );
133 if ( !$this->debugOutFile ) {
134 $this->
fatalError(
"Unable to open debug output file for writing" );
142 $uxr =
new UcdXmlReader(
"{$this->dataDir}/ucd.all.grouped.xml" );
143 $uxr->readChars( [ $this,
'charCallback' ] );
150 $category = substr( $data[
'gc'], 0, 1 );
151 if ( strpos(
'LNPS', $category ) ===
false
152 && $data[
'cp'] !==
'0020'
156 $cp = hexdec( $data[
'cp'] );
166 if ( $data[
'block'] ==
'Hangul Syllables' ) {
171 if ( $data[
'UIdeo'] ===
'Y' ) {
172 if ( $data[
'block'] ==
'CJK Unified Ideographs'
173 || $data[
'block'] ==
'CJK Compatibility Ideographs'
182 $a =
$base + ( $cp >> 15 );
183 $b = ( $cp & 0x7fff ) | 0x8000;
185 $this->weights[$cp] = sprintf(
".%04X.%04X", $a, $b );
187 if ( $data[
'dm'] !==
'#' ) {
188 $this->mappedChars[$cp] =
true;
191 if ( $cp % 4096 == 0 ) {
192 print "{$data['cp']}\n";
197 $file = fopen(
"{$this->dataDir}/allkeys.txt",
'r' );
199 $this->
fatalError(
"Unable to open allkeys.txt" );
202 $goodTertiaryChars = [];
207 while (
false !== (
$line = fgets( $file ) ) ) {
210 if ( !preg_match(
'/^([0-9A-F]+)\s*;\s*([^#]*)/',
$line, $m ) ) {
214 $cp = hexdec( $m[1] );
215 $allWeights = trim( $m[2] );
219 if ( !isset( $this->weights[$cp] ) ) {
224 preg_match_all(
'/[*.]([0-9A-F]+)/', $weightStr, $m );
225 if ( !empty( $m[1] ) ) {
226 if ( $m[1][0] !==
'0000' ) {
227 $primary .=
'.' . $m[1][0];
229 if ( $m[1][2] !==
'0000' ) {
230 $tertiary .=
'.' . $m[1][2];
234 $this->weights[$cp] = $primary;
235 if ( $tertiary ===
'.0008'
236 || $tertiary ===
'.000E'
238 $goodTertiaryChars[$cp] =
true;
245 asort( $this->weights, SORT_STRING );
246 $prevWeight = reset( $this->weights );
248 foreach ( $this->weights
as $cp => $weight ) {
249 if ( $weight !== $prevWeight ) {
250 $this->
groups[$prevWeight] = $group;
251 $prevWeight = $weight;
252 if ( isset( $this->
groups[$weight] ) ) {
253 $group = $this->
groups[$weight];
261 $this->
groups[$prevWeight] = $group;
270 foreach ( $this->
groups as $weight => $group ) {
271 if ( preg_match(
'/(\.[0-9A-F]*)\./', $weight, $m ) ) {
272 if ( isset( $this->
groups[$m[1]] ) ) {
273 unset( $this->
groups[$weight] );
278 ksort( $this->
groups, SORT_STRING );
283 $tertiaryCollator =
new Collator(
'root' );
284 $primaryCollator =
new Collator(
'root' );
285 $primaryCollator->setStrength( Collator::PRIMARY );
287 foreach ( $this->
groups as $weight => $group ) {
288 $uncomposedChars = [];
290 foreach ( $group
as $cp ) {
291 if ( isset( $goodTertiaryChars[$cp] ) ) {
294 if ( !isset( $this->mappedChars[$cp] ) ) {
295 $uncomposedChars[] = $cp;
298 $x = array_intersect( $goodChars, $uncomposedChars );
300 $x = $uncomposedChars;
307 $tertiaryCollator->sort( $x );
310 $char = UtfNormal\Utils::codepointToUtf8( $cp );
311 $headerChars[] = $char;
312 if ( $primaryCollator->compare( $char, $prevChar ) <= 0 ) {
317 if ( $this->debugOutFile ) {
318 fwrite( $this->debugOutFile, sprintf(
"%05X %s %s (%s)\n", $cp, $weight, $char,
319 implode(
' ', array_map(
'UtfNormal\Utils::codepointToUtf8', $group ) ) ) );
323 print "Out of order: $numOutOfOrder / " . count( $headerChars ) .
"\n";
328 "$IP/includes/collation/data/first-letters-root.php",
329 $writer->create( $headerChars,
'File created by generateCollationData.php' )
331 echo
"first-letters-root: file written.\n";
349 $this->currentBlock = reset( $this->blocks );
353 while (
$xml->name !==
'repertoire' &&
$xml->next() );
355 while (
$xml->read() ) {
356 if (
$xml->nodeType == XMLReader::ELEMENT ) {
357 if (
$xml->name ===
'group' ) {
359 } elseif (
$xml->name ===
'char' ) {
362 } elseif (
$xml->nodeType === XMLReader::END_ELEMENT ) {
363 if (
$xml->name ===
'group' ) {
364 $this->groupAttrs = [];
372 $this->xml =
new XMLReader;
373 $this->xml->open( $this->fileName );
375 throw new MWException( __METHOD__ .
": unable to open {$this->fileName}" );
377 while ( $this->xml->name !==
'ucd' && $this->xml->read() );
390 while ( $this->xml->moveToNextAttribute() ) {
391 $attrs[$this->xml->name] = $this->xml->value;
399 if ( isset( $attrs[
'cp'] ) ) {
400 $first =
$last = hexdec( $attrs[
'cp'] );
402 $first = hexdec( $attrs[
'first-cp'] );
403 $last = hexdec( $attrs[
'last-cp'] );
404 unset( $attrs[
'first-cp'] );
405 unset( $attrs[
'last-cp'] );
408 for ( $cp = $first; $cp <=
$last; $cp++ ) {
409 $hexCp = sprintf(
"%04X", $cp );
410 foreach ( [
'na',
'na1' ]
as $nameProp ) {
411 if ( isset( $attrs[$nameProp] ) ) {
412 $attrs[$nameProp] = str_replace(
'#', $hexCp, $attrs[$nameProp] );
416 while ( $this->currentBlock ) {
417 if ( $cp < $this->currentBlock[0] ) {
419 } elseif ( $cp <= $this->currentBlock[1] ) {
420 $attrs[
'block'] =
key( $this->blocks );
423 $this->currentBlock = next( $this->blocks );
427 $attrs[
'cp'] = $hexCp;
428 call_user_func( $this->callback, $attrs );
433 if ( $this->blocks ) {
438 while (
$xml->name !==
'blocks' &&
$xml->read() );
440 while (
$xml->read() ) {
441 if (
$xml->nodeType == XMLReader::ELEMENT ) {
442 if (
$xml->name ===
'block' ) {
444 $first = hexdec( $attrs[
'first-cp'] );
445 $last = hexdec( $attrs[
'last-cp'] );
446 $this->blocks[$attrs[
'name']] = [ $first,
$last ];
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Generate first letter data files for Collation.php.
__construct()
Default constructor.
$weights
The primary weights, indexed by codepoint.
execute()
Do the actual work.
$dataDir
The directory with source data files in it.
$mappedChars
A hashtable keyed by codepoint, where presence indicates that a character has a decomposition mapping...
const NORMAL_UPPERCASE
Important tertiary weights from UTS #10 section 7.2.
static isCjk( $codepoint)
Test if a code point is a CJK (Chinese, Japanese, Korean) character.
static getUnicodeVersionForICU()
Return the version of Unicode appropriate for the version of ICU library currently in use,...
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
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.
static explode( $separator, $subject)
Workalike for explode() with limited memory usage.
readAttributes()
Read the attributes of the current element node and return them as an array.
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
while(( $__line=Maintenance::readconsole()) !==false) print
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message key
this hook is for auditing only RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing groups(accessed through $special->getFilterGroup)
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
require_once RUN_MAINTENANCE_IF_MAIN