Merge "resourceloader: Un-deprecate makeLoaderConditionalScript()"
[lhc/web/wiklou.git] / maintenance / language / generateCollationData.php
index 550f4a3..fafc1c6 100644 (file)
@@ -131,16 +131,14 @@ class GenerateCollationData extends Maintenance {
                                $error .= "* $ucdallURL\n";
                        }
 
-                       $this->error( $error );
-                       exit( 1 );
+                       $this->fatalError( $error );
                }
 
                $debugOutFileName = $this->getOption( 'debug-output' );
                if ( $debugOutFileName ) {
                        $this->debugOutFile = fopen( $debugOutFileName, 'w' );
                        if ( !$this->debugOutFile ) {
-                               $this->error( "Unable to open debug output file for writing" );
-                               exit( 1 );
+                               $this->fatalError( "Unable to open debug output file for writing" );
                        }
                }
                $this->loadUcd();
@@ -149,7 +147,7 @@ class GenerateCollationData extends Maintenance {
 
        function loadUcd() {
                $uxr = new UcdXmlReader( "{$this->dataDir}/ucd.all.grouped.xml" );
-               $uxr->readChars( array( $this, 'charCallback' ) );
+               $uxr->readChars( [ $this, 'charCallback' ] );
        }
 
        function charCallback( $data ) {
@@ -205,17 +203,15 @@ class GenerateCollationData extends Maintenance {
        function generateFirstChars() {
                $file = fopen( "{$this->dataDir}/allkeys.txt", 'r' );
                if ( !$file ) {
-                       $this->error( "Unable to open allkeys.txt" );
-                       exit( 1 );
+                       $this->fatalError( "Unable to open allkeys.txt" );
                }
                global $IP;
                $outFile = fopen( "$IP/serialized/first-letters-root.ser", 'w' );
                if ( !$outFile ) {
-                       $this->error( "Unable to open output file first-letters-root.ser" );
-                       exit( 1 );
+                       $this->fatalError( "Unable to open output file first-letters-root.ser" );
                }
 
-               $goodTertiaryChars = array();
+               $goodTertiaryChars = [];
 
                // For each character with an entry in allkeys.txt, overwrite the implicit
                // entry in $this->weights that came from the UCD.
@@ -257,10 +253,10 @@ class GenerateCollationData extends Maintenance {
                fclose( $file );
 
                // Identify groups of characters with the same primary weight
-               $this->groups = array();
+               $this->groups = [];
                asort( $this->weights, SORT_STRING );
                $prevWeight = reset( $this->weights );
-               $group = array();
+               $group = [];
                foreach ( $this->weights as $cp => $weight ) {
                        if ( $weight !== $prevWeight ) {
                                $this->groups[$prevWeight] = $group;
@@ -268,7 +264,7 @@ class GenerateCollationData extends Maintenance {
                                if ( isset( $this->groups[$weight] ) ) {
                                        $group = $this->groups[$weight];
                                } else {
-                                       $group = array();
+                                       $group = [];
                                }
                        }
                        $group[] = $cp;
@@ -294,15 +290,15 @@ class GenerateCollationData extends Maintenance {
                ksort( $this->groups, SORT_STRING );
 
                // Identify the header character in each group
-               $headerChars = array();
+               $headerChars = [];
                $prevChar = "\000";
                $tertiaryCollator = new Collator( 'root' );
                $primaryCollator = new Collator( 'root' );
                $primaryCollator->setStrength( Collator::PRIMARY );
                $numOutOfOrder = 0;
                foreach ( $this->groups as $weight => $group ) {
-                       $uncomposedChars = array();
-                       $goodChars = array();
+                       $uncomposedChars = [];
+                       $goodChars = [];
                        foreach ( $group as $cp ) {
                                if ( isset( $goodTertiaryChars[$cp] ) ) {
                                        $goodChars[] = $cp;
@@ -327,11 +323,6 @@ class GenerateCollationData extends Maintenance {
                        $headerChars[] = $char;
                        if ( $primaryCollator->compare( $char, $prevChar ) <= 0 ) {
                                $numOutOfOrder++;
-                               /*
-                               printf( "Out of order: U+%05X > U+%05X\n",
-                                       utf8ToCodepoint( $prevChar ),
-                                       utf8ToCodepoint( $char ) );
-                                */
                        }
                        $prevChar = $char;
 
@@ -352,7 +343,7 @@ class UcdXmlReader {
        public $callback;
        public $groupAttrs;
        public $xml;
-       public $blocks = array();
+       public $blocks = [];
        public $currentBlock;
 
        function __construct( $fileName ) {
@@ -376,7 +367,7 @@ class UcdXmlReader {
                                }
                        } elseif ( $xml->nodeType === XMLReader::END_ELEMENT ) {
                                if ( $xml->name === 'group' ) {
-                                       $this->groupAttrs = array();
+                                       $this->groupAttrs = [];
                                }
                        }
                }
@@ -401,7 +392,7 @@ class UcdXmlReader {
         * @return array
         */
        protected function readAttributes() {
-               $attrs = array();
+               $attrs = [];
                while ( $this->xml->moveToNextAttribute() ) {
                        $attrs[$this->xml->name] = $this->xml->value;
                }
@@ -422,7 +413,7 @@ class UcdXmlReader {
 
                for ( $cp = $first; $cp <= $last; $cp++ ) {
                        $hexCp = sprintf( "%04X", $cp );
-                       foreach ( array( 'na', 'na1' ) as $nameProp ) {
+                       foreach ( [ 'na', 'na1' ] as $nameProp ) {
                                if ( isset( $attrs[$nameProp] ) ) {
                                        $attrs[$nameProp] = str_replace( '#', $hexCp, $attrs[$nameProp] );
                                }
@@ -458,7 +449,7 @@ class UcdXmlReader {
                                        $attrs = $this->readAttributes();
                                        $first = hexdec( $attrs['first-cp'] );
                                        $last = hexdec( $attrs['last-cp'] );
-                                       $this->blocks[$attrs['name']] = array( $first, $last );
+                                       $this->blocks[$attrs['name']] = [ $first, $last ];
                                }
                        }
                }
@@ -468,5 +459,5 @@ class UcdXmlReader {
        }
 }
 
-$maintClass = 'GenerateCollationData';
+$maintClass = GenerateCollationData::class;
 require_once RUN_MAINTENANCE_IF_MAIN;