function execute() { # List of language prefixes likely to be found in multi-language sites $this->langlist = array_map("trim", file($this->getOption('langlist', "/home/wikipedia/common/langlist"))); # List of all database names $this->dblist = array_map("trim", file($this->getOption('dblist', "/home/wikipedia/common/all.dblist"))); # Special-case databases $this->specials = array_flip(array_map("trim", file($this->getOption('specialdbs', "/home/wikipedia/common/special.dblist")))); if ($this->hasOption('o')) { $this->dbFile = CdbWriter::open($this->getOption('o')); } else { $this->dbFile = false; } $this->getRebuildInterwikiDump(); }
public function startWrite($code) { if (!file_exists($this->directory)) { if (!wfMkdirParents($this->directory, null, __METHOD__)) { throw new MWException("Unable to create the localisation store " . "directory \"{$this->directory}\""); } } // Close reader to stop permission errors on write if (!empty($this->readers[$code])) { $this->readers[$code]->close(); } try { $this->writer = CdbWriter::open($this->getFileName($code)); } catch (CdbException $e) { throw new MWException($e->getMessage()); } $this->currentLang = $code; }
<?php /** * txt2cdb: Converts the text file of ISO codes to a constant database. * * Usage: php txt2cdb.php */ $dir = dirname(__FILE__); $IP = "{$dir}/../.."; @(include "{$dir}/../../CorePath.php"); // Allow override require_once "{$IP}/maintenance/commandLine.inc"; $names = dirname(__FILE__) . '/names.cdb'; $codes = dirname(__FILE__) . '/codes.cdb'; $names = CdbWriter::open($names); $codes = CdbWriter::open($codes); $fr = fopen(dirname(__FILE__) . '/codes.txt', 'r'); while ($line = fgets($fr)) { // Format is code1 code2 "language name" $line = explode(' ', $line, 3); $iso1 = trim($line[0]); $iso3 = trim($line[1]); // Strip quotes $name = substr(trim($line[2]), 1, -1); if ($iso1 !== '-') { $codes->set($iso1, $iso1); if ($iso3 !== '-') { $codes->set($iso3, $iso1); } $names->set($iso1, $name); $names->set($iso3, $name);
/** * Updates cache to cache format 2. * @param $oldcache CdbReader */ protected function updateCacheFormat($oldcache) { // Read the data from the old format $conv = array('#keys' => $oldcache->get('<|keys#>'), '#created' => $oldcache->get('<|timestamp#>'), '#updated' => wfTimestamp(), '#filehash' => $oldcache->get('<|hash#>'), '#version' => '3'); $conv['#msgcount'] = count($conv['#keys']); $messages = array(); foreach (unserialize($conv['#keys']) as $key) { $messages[$key] = $oldcache->get($key); } ksort($messages); $conv['#msghash'] = md5(serialize($messages)); $oldcache->close(); // Store the data in new format $cache = CdbWriter::open($this->getCacheFileName()); foreach ($conv as $key => $value) { $cache->set($key, $value); } foreach ($messages as $key => $value) { $cache->set($key, $value); } $cache->close(); }
/** * Writes change array as a serialized file into a known place. * @param array $array Array of changes as returned by processGroup * indexed by message group id. * @todo does not belong to this class. */ public static function writeChanges($array) { // This method is almost identical with MessageIndex::store /* This will overwrite the previous cache file if any. Once the cache * file is processed with Special:ManageMessageGroups, it is * renamed so that it wont be processed again. */ $file = TranslateUtils::cacheFile(SpecialManageGroups::CHANGEFILE); $cache = CdbWriter::open($file); $keys = array_keys($array); $cache->set('#keys', serialize($keys)); foreach ($array as $key => $value) { $value = serialize($value); $cache->set($key, $value); } $cache->close(); }
private function populateCDB($thisSite, $local, $global) { $cdbFile = tempnam(wfTempDir(), 'MW-ClassicInterwikiLookupTest-') . '.cdb'; $cdb = CdbWriter::open($cdbFile); $hash = $this->populateHash($thisSite, $local, $global); foreach ($hash as $key => $value) { $cdb->set($key, $value); } $cdb->close(); return $cdbFile; }
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'); } }
<?php /** * Rebuild interwiki table using the file on meta and the language list * Wikimedia specific! * * @file * @todo document * @ingroup Maintenance * @ingroup Wikimedia */ /** */ $oldCwd = getcwd(); $optionsWithArgs = array("o"); require_once dirname(__FILE__) . '/commandLine.inc'; require dirname(__FILE__) . "/dumpInterwiki.inc"; chdir($oldCwd); # Output if (isset($options['o'])) { # To database specified with -o $dbFile = CdbWriter::open($options['o']); } getRebuildInterwikiDump();
/** * Populates the cache from current state of the source file. * @param bool|string $created Unix timestamp when the cache is created (for automatic updates). */ public function create($created = false) { $this->close(); // Close the reader instance just to be sure $messages = $this->group->load($this->code); if ($messages === array()) { if ($this->exists()) { // Delete stale cache files unlink($this->getCacheFileName()); } return; // Don't create empty caches } $hash = md5(file_get_contents($this->group->getSourceFilePath($this->code))); wfMkdirParents(dirname($this->getCacheFileName())); $cache = CdbWriter::open($this->getCacheFileName()); $keys = array_keys($messages); $cache->set('#keys', serialize($keys)); foreach ($messages as $key => $value) { $cache->set($key, $value); } $cache->set('#created', $created ? $created : wfTimestamp()); $cache->set('#updated', wfTimestamp()); $cache->set('#filehash', $hash); $cache->set('#msgcount', count($messages)); ksort($messages); $cache->set('#msghash', md5(serialize($messages))); $cache->set('#version', '3'); $cache->close(); }
protected function store(array $array) { $this->reader = null; $file = TranslateUtils::cacheFile($this->filename); $cache = CdbWriter::open($file); $keys = array_keys($array); $cache->set('#keys', $this->serialize($keys)); foreach ($array as $key => $value) { $value = $this->serialize($value); $cache->set($key, $value); } $cache->close(); $this->index = $array; }