示例#1
0
 public function execute()
 {
     // Prevent the script from timing out
     set_time_limit(0);
     ini_set("max_execution_time", 0);
     ini_set('memory_limit', -1);
     global $wgExtensionMessagesFiles, $IP;
     global $wgLocalisationUpdateRepositories;
     global $wgLocalisationUpdateRepository;
     $dir = LocalisationUpdate::getDirectory();
     if (!$dir) {
         $this->error("No cache directory configured", true);
         return;
     }
     $lc = Language::getLocalisationCache();
     if (is_callable(array($lc, 'getMessagesDirs'))) {
         // Introduced in 1.25
         $messagesDirs = $lc->getMessagesDirs();
     } else {
         global $wgMessagesDirs;
         $messagesDirs = $wgMessagesDirs;
     }
     $finder = new LU_Finder($wgExtensionMessagesFiles, $messagesDirs, $IP);
     $readerFactory = new LU_ReaderFactory();
     $fetcherFactory = new LU_FetcherFactory();
     $repoid = $this->getOption('repoid', $wgLocalisationUpdateRepository);
     if (!isset($wgLocalisationUpdateRepositories[$repoid])) {
         $known = implode(', ', array_keys($wgLocalisationUpdateRepositories));
         $this->error("Unknown repoid {$repoid}; known: {$known}", true);
         return;
     }
     $repos = $wgLocalisationUpdateRepositories[$repoid];
     // Do it ;)
     $updater = new LU_Updater();
     $updatedMessages = $updater->execute($finder, $readerFactory, $fetcherFactory, $repos);
     // Store it ;)
     $count = array_sum(array_map('count', $updatedMessages));
     if (!$count) {
         $this->output("Found no new translations\n");
         return;
     }
     foreach ($updatedMessages as $language => $messages) {
         $filename = "{$dir}/" . LocalisationUpdate::getFilename($language);
         file_put_contents($filename, FormatJson::encode($messages, true));
     }
     $this->output("Saved {$count} new translations\n");
 }
 /**
  * Hook: LocalisationCacheRecache
  */
 public static function onRecache(LocalisationCache $lc, $code, array &$cache)
 {
     $dir = LocalisationUpdate::getDirectory();
     if (!$dir) {
         return true;
     }
     $codeSequence = array_merge(array($code), $cache['fallbackSequence']);
     foreach ($codeSequence as $csCode) {
         $fileName = "{$dir}/" . self::getFilename($csCode);
         if (is_readable($fileName)) {
             $data = FormatJson::decode(file_get_contents($fileName), true);
             $cache['messages'] = array_merge($cache['messages'], $data);
         }
         $cache['deps'][] = new FileDependency($fileName);
     }
     return true;
 }
 /**
  * Hook: LocalisationCacheRecache
  */
 public static function onRecache(LocalisationCache $lc, $code, array &$cache)
 {
     $dir = LocalisationUpdate::getDirectory();
     if (!$dir) {
         return true;
     }
     $codeSequence = array_merge(array($code), $cache['fallbackSequence']);
     foreach ($codeSequence as $csCode) {
         $fileName = "{$dir}/" . self::getFilename($csCode);
         if (!self::$onRecacheFallbackCalled && is_readable($fileName)) {
             // We're on an old version of MW that doesn't have the hook
             // needed to do things correctly. L10n will be broken here in
             // certain reasonably-common situations (see bug 68781), but
             // there's nothing we can do about it.
             $data = FormatJson::decode(file_get_contents($fileName), true);
             $cache['messages'] = array_merge($cache['messages'], $data);
         }
         $cache['deps'][] = new FileDependency($fileName);
     }
     return true;
 }
 /**
  * @param $file
  * @param $hash
  */
 public static function saveHash($file, $hash)
 {
     if (is_null(self::$newHashes)) {
         self::$newHashes = self::readFile('hashes');
     }
     self::$newHashes[$file] = $hash;
 }
示例#5
0
    return $reader->getVar($varname);
}
if (count($args)) {
    $sources = $args;
} else {
    $sources = array_merge(glob("{$IP}/extensions/*/*.i18n.php"), glob("{$IP}/languages/messages/Messages*.php"));
}
foreach ($sources as $sourceFile) {
    $rel = basename($sourceFile);
    $out = str_replace('/', '-', $rel);
    $sourceData = file_get_contents($sourceFile);
    if (preg_match('!extensions/!', $sourceFile)) {
        $sourceData = LocalisationUpdate::cleanupExtensionFile($sourceData);
        $items = 'langs';
    } else {
        $sourceData = LocalisationUpdate::cleanupFile($sourceData);
        $items = 'messages';
    }
    file_put_contents("{$out}.txt", $sourceData);
    $start = microtime(true);
    $eval = evalExtractArray($sourceData, 'messages');
    $deltaEval = microtime(true) - $start;
    $start = microtime(true);
    $quick = quickTokenExtractArray($sourceData, 'messages');
    $deltaQuick = microtime(true) - $start;
    $start = microtime(true);
    $token = confExtractArray($sourceData, 'messages');
    $deltaToken = microtime(true) - $start;
    $hashEval = md5(serialize($eval));
    $hashToken = md5(serialize($token));
    $hashQuick = md5(serialize($quick));
示例#6
0
<?php

$IP = strval(getenv('MW_INSTALL_PATH')) !== '' ? getenv('MW_INSTALL_PATH') : realpath(dirname(__FILE__) . "/../../");
// TODO: migrate to maintenance class
require_once "{$IP}/maintenance/commandLine.inc";
if (isset($options['help'])) {
    print "Fetches updated localisation files from MediaWiki development SVN\n";
    print "and saves into local database to merge with release defaults.\n";
    print "\n";
    print "Usage: php extensions/LocalisationUpdate/update.php\n";
    print "Options:\n";
    print "  --quiet           Suppress progress output\n";
    print "  --skip-core       Don't fetch MediaWiki core files\n";
    print "  --skip-extensions Don't fetch any extension files\n";
    print "  --all             Fetch all present extensions, not just those enabled\n";
    print "  --outdir=<dir>    Override output directory for serialized update files\n";
    print "  --svnurl=<url>    URL to SVN repository, or path to local SVN checkout. Default: {$wgLocalisationUpdateSVNURL}\n";
    print "\n";
    exit(0);
}
$starttime = microtime(true);
// Prevent the script from timing out
set_time_limit(0);
ini_set("max_execution_time", 0);
ini_set('memory_limit', -1);
LocalisationUpdate::updateMessages($options);
$endtime = microtime(true);
$totaltime = $endtime - $starttime;
print "All done in " . $totaltime . " seconds\n";