public function execute()
 {
     $params = $this->extractRequestParams();
     // In MW 1.17 and above ApiBase::PARAM_REQUIRED can be used, this is for b/c with 1.16.
     foreach (array('from', 'to', 'words') as $requiredParam) {
         if (!isset($params[$requiredParam])) {
             $this->dieUsageMsg(array('missingparam', $requiredParam));
         }
     }
     $dbr = wfGetDB(DB_SLAVE);
     foreach (array_unique($params['words']) as $word) {
         $source = $dbr->selectRow('live_translate', array('word_id'), array('word_language' => $params['from'], 'word_translation' => $word));
         $toggledWord = false;
         if (!$source) {
             $toggledWord = LiveTranslateFunctions::getToggledCase($word);
             if ($toggledWord) {
                 $source = $dbr->selectRow('live_translate', array('word_id'), array('word_language' => $params['from'], 'word_translation' => $toggledWord));
             }
         }
         if ($source) {
             $destination = $dbr->selectRow('live_translate', array('word_translation'), array('word_language' => $params['to'], 'word_id' => $source->word_id, 'word_primary' => 1));
             if ($destination) {
                 if ($toggledWord) {
                     $translation = LiveTranslateFunctions::getToggledCase($destination->word_translation);
                     if ($translation) {
                         $destination->word_translation = $translation;
                     }
                 }
                 $this->getResult()->addValue('translations', $word, $destination->word_translation);
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Retrieve the specil words from the database.
  */
 public function execute()
 {
     // Get the requests parameters.
     $params = $this->extractRequestParams();
     if (!isset($params['language'])) {
         $this->dieUsageMsg(array('missingparam', 'language'));
     }
     $this->addTables('live_translate');
     $this->addFields(array('word_id', 'word_translation'));
     $this->addWhere(array('word_language' => $params['language']));
     if (!is_null($params['continue'])) {
         $dbr = wfGetDB(DB_SLAVE);
         $this->addWhere('word_id >= ' . $dbr->addQuotes($params['continue']));
     }
     $this->addOption('LIMIT', $params['limit'] + 1);
     $this->addOption('ORDER BY', 'word_id ASC');
     $words = $this->select(__METHOD__);
     $specialWords = array();
     $count = 0;
     while ($word = $words->fetchObject()) {
         if (++$count > $params['limit']) {
             // We've reached the one extra which shows that
             // there are additional pages to be had. Stop here...
             $this->setContinueEnumParameter('continue', $word->word_id);
             break;
         }
         $specialWords[] = $word->word_translation;
     }
     $toggeledSpecials = array();
     foreach ($specialWords as $word) {
         $toggledWord = LiveTranslateFunctions::getToggledCase($word);
         if ($toggledWord) {
             $toggeledSpecials[] = $toggledWord;
         }
     }
     foreach (array_unique(array_merge($specialWords, $toggeledSpecials)) as $word) {
         $this->getResult()->addValue('words', null, $word);
     }
 }
 /**
  * Handles edits to the dictionary page to save the translations into the db.
  *
  * @since 0.1
  *
  * @return true
  */
 public static function onArticleSaveComplete(&$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId, &$redirect = null)
 {
     $title = $article->getTitle();
     // FIXME: Hitting the db on every page save should be avoided
     if (in_array($title->getFullText(), LiveTranslateFunctions::getLocalMemoryNames())) {
         $requestData = array('action' => 'importtms', 'format' => 'json', 'source' => $title->getFullText(), 'type' => LiveTranslateFunctions::getMemoryType($title->getFullText()), 'local' => 1);
         $api = new ApiMain(new FauxRequest($requestData, true), true);
         $api->execute();
         $response = $api->getResultData();
     }
     return true;
 }
 /**
  * Cleans the language code.
  * 
  * @since 0.4
  * 
  * @param string language
  * 
  * @return string
  */
 protected function cleanLanguage($language)
 {
     $language = strtolower($language);
     $mappings = LiveTranslateFunctions::getInputLangMapping();
     if (array_key_exists($language, $mappings)) {
         $language = $mappings[$language];
     }
     return $language;
 }