/** * @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); }
private function removeInvalidSuggestions($sourceLanguage, array $existingTitles) { DeferredUpdates::addCallableUpdate(function () use($sourceLanguage, $existingTitles) { // Remove the already existing links from cx_suggestion table $manager = new SuggestionListManager(); $manager->removeTitles($sourceLanguage, $existingTitles); }); }
protected function createFeaturedSuggestions($pages) { $sourceLanguage = $this->getOption('source'); $targetLanguage = $this->getOption('target'); $manager = new SuggestionListManager(); $list = new SuggestionList(array('type' => SuggestionList::TYPE_FEATURED, 'name' => 'featured', 'public' => true)); $listId = $manager->insertList($list); $suggestion = array(); foreach ($pages as $page) { $suggestions[] = new Suggestion(array('listId' => $listId, 'title' => $page, 'sourceLanguage' => $sourceLanguage, 'targetLanguage' => $targetLanguage)); } $manager->addSuggestions($suggestions); }
protected function createFeaturedSuggestions($pages) { $featureListName = 'cx-suggestionlist-featured'; $sourceLanguage = $this->getOption('source'); $targetLanguage = $this->getOption('target'); $manager = new SuggestionListManager(); $list = $manager->getListByName($featureListName); if ($list === null) { $list = new SuggestionList(array('type' => SuggestionList::TYPE_FEATURED, 'name' => $featureListName, 'public' => true)); $listId = $manager->insertList($list); } else { $listId = $list->getId(); } $suggestion = array(); foreach ($pages as $page) { $suggestions[] = new Suggestion(array('listId' => $listId, 'title' => $page, 'sourceLanguage' => $sourceLanguage, 'targetLanguage' => $targetLanguage)); } $manager->addSuggestions($suggestions); }