X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%20%22id_auteur=%24id%22%29%20.%20%22?a=blobdiff_plain;f=maintenance%2Flanguage%2FgenerateCollationData.php;h=fcf2c960c67e9313ad5bbba6899eec0952dc68ec;hb=beb1c4a0eced04ce2098433c383f1fbe469569c9;hp=e2ad6a71123feeeec683d658f625346830564ae6;hpb=5abe15bb9daa6197544087688d73ba11eb7fa801;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/language/generateCollationData.php b/maintenance/language/generateCollationData.php index e2ad6a7112..fcf2c960c6 100644 --- a/maintenance/language/generateCollationData.php +++ b/maintenance/language/generateCollationData.php @@ -21,7 +21,7 @@ * @ingroup MaintenanceLanguage */ -require_once( __DIR__ .'/../Maintenance.php' ); +require_once __DIR__ . '/../Maintenance.php'; /** * Generate first letter data files for Collation.php @@ -61,18 +61,80 @@ class GenerateCollationData extends Maintenance { public function execute() { $this->dataDir = $this->getOption( 'data-dir', '.' ); - if ( !file_exists( "{$this->dataDir}/allkeys.txt" ) ) { - $this->error( "Unable to find allkeys.txt. Please download it from " . - "http://www.unicode.org/Public/UCA/latest/allkeys.txt and specify " . - "its location with --data-dir=" ); - exit( 1 ); - } - if ( !file_exists( "{$this->dataDir}/ucd.all.grouped.xml" ) ) { - $this->error( "Unable to find ucd.all.grouped.xml. Please download it " . - "from http://www.unicode.org/Public/6.0.0/ucdxml/ucd.all.grouped.zip " . - "and specify its location with --data-dir=" ); + + $allkeysPresent = file_exists( "{$this->dataDir}/allkeys.txt" ); + $ucdallPresent = file_exists( "{$this->dataDir}/ucd.all.grouped.xml" ); + + // As of January 2013, these links work for all versions of Unicode + // between 5.1 and 6.2, inclusive. + $allkeysURL = "http://www.unicode.org/Public/UCA//allkeys.txt"; + $ucdallURL = "http://www.unicode.org/Public//ucdxml/ucd.all.grouped.zip"; + + if ( !$allkeysPresent || !$ucdallPresent ) { + $icuVersion = IcuCollation::getICUVersion(); + $unicodeVersion = IcuCollation::getUnicodeVersionForICU(); + + $error = ""; + + if ( !$allkeysPresent ) { + $error .= "Unable to find allkeys.txt. " + . "Download it and specify its location with --data-dir=. " + . "\n\n"; + } + if ( !$ucdallPresent ) { + $error .= "Unable to find ucd.all.grouped.xml. " + . "Download it, unzip, and specify its location with --data-dir=. " + . "\n\n"; + } + + $versionKnown = false; + if ( !$icuVersion ) { + // Unknown version - either very old intl, + // or PHP < 5.3.7 which does not expose this information + $error .= "As MediaWiki could not determine the version of ICU library used by your PHP's " + . "intl extension it can't suggest which file version to download. " + . "This can be caused by running a very old version of intl or PHP < 5.3.7. " + . "If you are sure everything is all right, find out the ICU version " + . "by running phpinfo(), check what is the Unicode version it is using " + . "at http://site.icu-project.org/download, then try finding appropriate data file(s) at:"; + } elseif ( version_compare( $icuVersion, "4.0", "<" ) ) { + // Extra old version + $error .= "You are using outdated version of ICU ($icuVersion), intended for " + . ( $unicodeVersion ? "Unicode $unicodeVersion" : "an unknown version of Unicode" ) + . "; this file might not be avalaible for it, and it's not supported by MediaWiki. " + . " You are on your own; consider upgrading PHP's intl extension or try " + . "one of the files available at:"; + } elseif ( version_compare( $icuVersion, "51.0", ">=" ) ) { + // Extra recent version + $error .= "You are using ICU $icuVersion, released after this script was last updated. " + . "Check what is the Unicode version it is using at http://site.icu-project.org/download . " + . "It can't be guaranteed everything will work, but appropriate file(s) should " + . "be available at:"; + } else { + // ICU 4.0 to 50.x + $versionKnown = true; + $error .= "You are using ICU $icuVersion, intended for " + . ( $unicodeVersion ? "Unicode $unicodeVersion" : "an unknown version of Unicode" ) + . ". Appropriate file(s) should be available at:"; + } + $error .= "\n"; + + if ( $versionKnown && $unicodeVersion ) { + $allkeysURL = str_replace( "", "$unicodeVersion.0", $allkeysURL ); + $ucdallURL = str_replace( "", "$unicodeVersion.0", $ucdallURL ); + } + + if ( !$allkeysPresent ) { + $error .= "* $allkeysURL\n"; + } + if ( !$ucdallPresent ) { + $error .= "* $ucdallURL\n"; + } + + $this->error( $error ); exit( 1 ); } + $debugOutFileName = $this->getOption( 'debug-output' ); if ( $debugOutFileName ) { $this->debugOutFile = fopen( $debugOutFileName, 'w' ); @@ -324,7 +386,7 @@ class UcdXmlReader { $this->xml = new XMLReader; $this->xml->open( $this->fileName ); if ( !$this->xml ) { - throw new MWException( __METHOD__.": unable to open {$this->fileName}" ); + throw new MWException( __METHOD__ . ": unable to open {$this->fileName}" ); } while ( $this->xml->name !== 'ucd' && $this->xml->read() ); $this->xml->read(); @@ -404,4 +466,4 @@ class UcdXmlReader { } $maintClass = 'GenerateCollationData'; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN;