/**
  * @param ApiPageSet $resultPageSet
  * TODO: Use the limit parameter
  */
 private function run($resultPageSet = null)
 {
     $config = $this->getConfig();
     if (!$config->get('ContentTranslationEnableSuggestions')) {
         $this->dieUsage('Suggestions not enabled for this wiki', 'suggestionsdisabled');
     }
     $params = $this->extractRequestParams();
     $result = $this->getResult();
     $user = $this->getUser();
     if ($params['from'] === $params['to']) {
         $this->dieUsage('Source and target languages cannot be the same. Use from, to API params.', 'invalidparam');
     }
     $translator = new Translator($user);
     $manager = new SuggestionListManager();
     $data = $manager->getRelevantSuggestions($translator, $params['from'], $params['to']);
     $lists = array();
     foreach ($data['lists'] as $list) {
         $lists[$list->getId()] = array('displayName' => $list->getDisplayNameMessage($this->getContext())->text(), 'name' => $list->getName(), 'type' => $list->getType());
     }
     $result->addValue(array('query', $this->getModuleName()), 'lists', $lists);
     $suggestions = array();
     foreach ($data['suggestions'] as $suggestion) {
         $suggestions[] = array('name' => $suggestion->getTitle()->getPrefixedText(), 'sourceLanguage' => $suggestion->getSourceLanguage(), 'targetLanguage' => $suggestion->getTargetLanguage(), 'listId' => $suggestion->getListId());
     }
     $result->addValue(array('query', $this->getModuleName()), 'suggestions', $suggestions);
 }
 /**
  * @param ApiPageSet $resultPageSet
  * TODO: Use the limit parameter
  */
 private function run($resultPageSet = null)
 {
     $config = $this->getConfig();
     if (!$config->get('ContentTranslationEnableSuggestions')) {
         $this->dieUsage('Suggestions not enabled for this wiki', 'suggestionsdisabled');
     }
     $params = $this->extractRequestParams();
     $result = $this->getResult();
     $user = $this->getUser();
     if ($params['from'] === $params['to']) {
         $this->dieUsage('Source and target languages cannot be the same. Use from, to API params.', 'invalidparam');
     }
     $translator = new Translator($user);
     $manager = new SuggestionListManager();
     $data = $manager->getRelevantSuggestions($translator, $params['from'], $params['to'], $params['limit'], $params['offset'], $params['seed']);
     $lists = array();
     $suggestions = $data['suggestions'];
     if (!count($suggestions)) {
         $result->addValue(array('query', $this->getModuleName()), 'lists', array());
         return;
     }
     // Find the titles to filter out from suggestions.
     $ongoingTranslations = $this->getOngoingTranslations($suggestions);
     $existingTitles = $this->getExistingTitles($suggestions);
     $suggestions = $this->filterSuggestions($suggestions, array_merge($existingTitles, $ongoingTranslations));
     // Remove the Suggestions that are no longer valid.
     $this->removeInvalidSuggestions($params['from'], $existingTitles);
     foreach ($data['lists'] as $list) {
         $lists[$list->getId()] = array('displayName' => $list->getDisplayNameMessage($this->getContext())->text(), 'name' => $list->getName(), 'type' => $list->getType(), 'suggestions' => array());
         foreach ($suggestions as $suggestion) {
             $lists[$suggestion->getListId()]['suggestions'][] = array('title' => $suggestion->getTitle()->getPrefixedText(), 'sourceLanguage' => $suggestion->getSourceLanguage(), 'targetLanguage' => $suggestion->getTargetLanguage(), 'listId' => $suggestion->getListId());
         }
     }
     if (count($suggestions)) {
         $this->setContinueEnumParameter('offset', $params['limit'] + $params['offset']);
     }
     $result->addValue(array('query', $this->getModuleName()), 'lists', $lists);
 }