예제 #1
0
 protected function setUp()
 {
     parent::setUp();
     if (!CdbReader::haveExtension()) {
         $this->markTestSkipped('Native CDB support is not available');
     }
 }
예제 #2
0
 /**
  * Close the cache from reading.
  */
 protected function close()
 {
     if ($this->cache !== null) {
         $this->cache->close();
         $this->cache = null;
     }
 }
 /**
  * Take a code as input, and search a language name for it in
  * a given language via Language::fetchLanguageNames() or
  * else via the Babel language names CDB
  *
  * @param $code String: Code to get name for.
  * @param $language String: Code of language to attempt to get name in,
  *                  defaults to language of code.
  * @return String (name of language) or false (invalid language code).
  */
 public static function getName($code, $language = null)
 {
     wfProfileIn(__METHOD__);
     global $wgBabelLanguageNamesCdb;
     // Get correct code, even though it should already be correct.
     $code = self::getCode($code);
     if ($code === false) {
         wfProfileOut(__METHOD__);
         return false;
     }
     $language = $language === null ? $code : $language;
     $names = Language::fetchLanguageNames($language, 'all');
     if (isset($names[$code])) {
         wfProfileOut(__METHOD__);
         return $names[$code];
     }
     $codes = false;
     try {
         $namesCdb = CdbReader::open($wgBabelLanguageNamesCdb);
         $codes = $namesCdb->get($code);
     } catch (CdbException $e) {
         wfDebug(__METHOD__ . ": CdbException caught, error message was " . $e->getMessage());
     }
     wfProfileOut(__METHOD__);
     return $codes;
 }
예제 #4
0
파일: Cdb.php 프로젝트: Tjorriemorrie/app
 /**
  * Open a writer and return a subclass instance.
  * The user must have write access to the directory, for temporary file creation.
  *
  * @param $fileName string
  *
  * @return CdbWriter_DBA|CdbWriter_PHP
  */
 public static function open($fileName)
 {
     if (CdbReader::haveExtension()) {
         return new CdbWriter_DBA($fileName);
     } else {
         wfDebug("Warning: no dba extension found, using emulation.\n");
         return new CdbWriter_PHP($fileName);
     }
 }
 /**
  * Take a code as input, and attempt to find a language name for it in
  * a a given language, uses the order:
  *     - CLDR extension
  *     - MediaWiki language names
  *     - Babel language names CDB
  *
  * @param $code String: Code to get name for.
  * @param $language String: Code of language to attempt to get name in,
  *                  defaults to language of code.
  * @return String (name of language) or false (invalid language code).
  */
 public static function getName($code, $language = null)
 {
     global $wgBabelLanguageNamesCdb;
     // Get correct code, even though it should already be correct.
     $code = self::getCode($code);
     if ($code === false) {
         return false;
     }
     $language = $language === null ? $code : $language;
     $names = Language::getTranslatedLanguageNames($language);
     if (isset($names[$code])) {
         return $names[$code];
     }
     $names = CdbReader::open($wgBabelLanguageNamesCdb);
     return $names->get($code);
 }
 /**
  * Take a code as input, and search a language name for it in
  * a given language via Language::fetchLanguageNames() or 
  * else via the Babel language names CDB
  *
  * @param $code String: Code to get name for.
  * @param $language String: Code of language to attempt to get name in,
  *                  defaults to language of code.
  * @return String (name of language) or false (invalid language code).
  */
 public static function getName($code, $language = null)
 {
     wfProfileIn(__METHOD__);
     global $wgBabelLanguageNamesCdb;
     // Get correct code, even though it should already be correct.
     $code = self::getCode($code);
     if ($code === false) {
         wfProfileOut(__METHOD__);
         return false;
     }
     $language = $language === null ? $code : $language;
     $names = Language::fetchLanguageNames($language, 'all');
     if (isset($names[$code])) {
         wfProfileOut(__METHOD__);
         return $names[$code];
     }
     $namesCdb = CdbReader::open($wgBabelLanguageNamesCdb);
     $codes = $namesCdb->get($code);
     wfProfileOut(__METHOD__);
     return $codes;
 }
예제 #7
0
 public function get($code, $key)
 {
     if (!isset($this->readers[$code])) {
         $fileName = $this->getFileName($code);
         $this->readers[$code] = false;
         if (file_exists($fileName)) {
             try {
                 $this->readers[$code] = CdbReader::open($fileName);
             } catch (CdbException $e) {
                 wfDebug(__METHOD__ . ": unable to open cdb file for reading\n");
             }
         }
     }
     if (!$this->readers[$code]) {
         return null;
     } else {
         $value = false;
         try {
             $value = $this->readers[$code]->get($key);
         } catch (CdbException $e) {
             wfDebug(__METHOD__ . ": CdbException caught, error message was " . $e->getMessage() . "\n");
         }
         if ($value === false) {
             return null;
         }
         return unserialize($value);
     }
 }
예제 #8
0
파일: CdbTest.php 프로젝트: yusufchang/app
 public function setUp()
 {
     if (!CdbReader::haveExtension()) {
         $this->markTestIncomplete('This test requires native CDB support to be present.');
     }
 }
 public function get($code, $key)
 {
     if (!isset($this->readers[$code])) {
         $fileName = $this->getFileName($code);
         if (!file_exists($fileName)) {
             $this->readers[$code] = false;
         } else {
             $this->readers[$code] = CdbReader::open($fileName);
         }
     }
     if (!$this->readers[$code]) {
         return null;
     } else {
         $value = $this->readers[$code]->get($key);
         if ($value === false) {
             return null;
         }
         return unserialize($value);
     }
 }
예제 #10
0
파일: cdb.php 프로젝트: mangowi/mediawiki
 $args = explode(' ', $line);
 $command = array_shift($args);
 // process command
 switch ($command) {
     case 'help':
         // show an help message
         cdbShowHelp(array_shift($args));
         break;
     case 'load':
         if (!isset($args[0])) {
             print "Need a filename there buddy\n";
             break;
         }
         $file = $args[0];
         print "Loading cdb file {$file}...";
         $fileHandle = CdbReader::open($file);
         if (!$fileHandle) {
             print "not a cdb file or unable to read it\n";
         } else {
             print "ok\n";
         }
         break;
     case 'get':
         if (!$fileHandle) {
             print "Need to load a cdb file first\n";
             break;
         }
         if (!isset($args[0])) {
             print "Need to specify a key, Luke\n";
             break;
         }
 protected function processSubmit()
 {
     $req = $this->getRequest();
     $out = $this->getOutput();
     $jobs = array();
     $jobs[] = MessageIndexRebuildJob::newJob();
     $changefile = TranslateUtils::cacheFile(self::CHANGEFILE);
     $reader = CdbReader::open($changefile);
     $groups = unserialize($reader->get('#keys'));
     $postponed = array();
     foreach ($groups as $groupId) {
         $group = MessageGroups::getGroup($groupId);
         $changes = unserialize($reader->get($groupId));
         foreach ($changes as $code => $subchanges) {
             foreach ($subchanges as $type => $messages) {
                 foreach ($messages as $index => $params) {
                     $id = self::changeId($groupId, $code, $type, $params['key']);
                     if ($req->getVal($id) === null) {
                         // We probably hit the limit with number of post parameters.
                         $postponed[$groupId][$code][$type][$index] = $params;
                         continue;
                     }
                     if ($type === 'deletion' || $req->getCheck("i/{$id}")) {
                         continue;
                     }
                     $fuzzy = $req->getCheck("f/{$id}") ? 'fuzzy' : false;
                     $key = $params['key'];
                     $title = Title::makeTitleSafe($group->getNamespace(), "{$key}/{$code}");
                     $jobs[] = MessageUpdateJob::newJob($title, $params['content'], $fuzzy);
                 }
             }
             if (!isset($postponed[$groupId][$code])) {
                 $cache = new MessageGroupCache($groupId, $code);
                 $cache->create();
             }
         }
     }
     JobQueueGroup::singleton()->push($jobs);
     $reader->close();
     rename($changefile, $changefile . '-' . wfTimestamp());
     if (count($postponed)) {
         $changefile = TranslateUtils::cacheFile(self::CHANGEFILE);
         $writer = CdbWriter::open($changefile);
         $keys = array_keys($postponed);
         $writer->set('#keys', serialize($keys));
         foreach ($postponed as $groupId => $changes) {
             $writer->set($groupId, serialize($changes));
         }
         $writer->close();
         $this->showChanges(true, $this->getLimit());
     } else {
         $out->addWikiMsg('translate-smg-submitted');
     }
 }
예제 #12
0
 public function setUp()
 {
     if (!CdbReader::haveExtension()) {
         $this->markTestSkipped('Native CDB support is not available');
     }
 }
예제 #13
0
 /**
  * Fetch all interwiki prefixes from interwiki cache
  *
  * @param $local null|string If not null, limits output to local/non-local interwikis
  * @return Array List of prefixes
  * @since 1.19
  */
 protected static function getAllPrefixesCached($local)
 {
     global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
     static $db, $site;
     wfDebug(__METHOD__ . "()\n");
     if (!$db) {
         $db = CdbReader::open($wgInterwikiCache);
     }
     /* Resolve site name */
     if ($wgInterwikiScopes >= 3 && !$site) {
         $site = $db->get('__sites:' . wfWikiID());
         if ($site == '') {
             $site = $wgInterwikiFallbackSite;
         }
     }
     // List of interwiki sources
     $sources = array();
     // Global Level
     if ($wgInterwikiScopes >= 2) {
         $sources[] = '__global';
     }
     // Site level
     if ($wgInterwikiScopes >= 3) {
         $sources[] = '_' . $site;
     }
     $sources[] = wfWikiID();
     $data = array();
     foreach ($sources as $source) {
         $list = $db->get("__list:{$source}");
         foreach (explode(' ', $list) as $iw_prefix) {
             $row = $db->get("{$source}:{$iw_prefix}");
             if (!$row) {
                 continue;
             }
             list($iw_local, $iw_url) = explode(' ', $row);
             if ($local !== null && $local != $iw_local) {
                 continue;
             }
             $data[$iw_prefix] = array('iw_prefix' => $iw_prefix, 'iw_url' => $iw_url, 'iw_local' => $iw_local);
         }
     }
     ksort($data);
     return array_values($data);
 }
예제 #14
0
 /**
  * Get entry from interwiki cache
  *
  * @note More logic is explained in DefaultSettings.
  *
  * @param $prefix String: database key
  * @return String: the entry
  */
 protected static function getInterwikiCacheEntry($prefix)
 {
     global $wgInterwikiCache, $wgInterwikiScopes, $wgInterwikiFallbackSite;
     static $db, $site;
     wfDebug(__METHOD__ . "( {$prefix} )\n");
     if (!$db) {
         $db = CdbReader::open($wgInterwikiCache);
     }
     /* Resolve site name */
     if ($wgInterwikiScopes >= 3 && !$site) {
         $site = $db->get('__sites:' . wfWikiID());
         if ($site == '') {
             $site = $wgInterwikiFallbackSite;
         }
     }
     $value = $db->get(wfMemcKey($prefix));
     // Site level
     if ($value == '' && $wgInterwikiScopes >= 3) {
         $value = $db->get("_{$site}:{$prefix}");
     }
     // Global Level
     if ($value == '' && $wgInterwikiScopes >= 2) {
         $value = $db->get("__global:{$prefix}");
     }
     if ($value == 'undef') {
         $value = '';
     }
     return $value;
 }
예제 #15
0
 /**
  * Open a writer and return a subclass instance.
  * The user must have write access to the directory, for temporary file creation.
  *
  * @param $fileName string
  *
  * @return CdbWriterDBA|CdbWriterPHP
  */
 public static function open($fileName)
 {
     return CdbReader::haveExtension() ? new CdbWriterDBA($fileName) : new CdbWriterPHP($fileName);
 }
 protected function getReader()
 {
     if ($this->reader) {
         return $this->reader;
     }
     $file = TranslateUtils::cacheFile($this->filename);
     if (!file_exists($file)) {
         // Create an empty index to allow rebuild
         $this->store(array());
         $this->index = $this->rebuild();
     }
     return $this->reader = CdbReader::open($file);
 }