/**
  * Find a translation with any status for the given language pair and title.
  */
 public function find($sourceTitle, $sourceLanguage, $targetLanguage)
 {
     $result = $this->getResult();
     $translation = ContentTranslation\Translation::find($sourceLanguage, $targetLanguage, $sourceTitle);
     if ($translation !== null) {
         $translator = $translation->translation['lastUpdatedTranslator'];
         $translation->translation['translatorName'] = ContentTranslation\GlobalUser::newFromId($translator)->getName();
         $result->addValue(array('query', 'contenttranslation'), 'translation', $translation->translation);
     }
     $this->getResult()->addValue(null, $this->getModuleName(), $result);
 }
 public function execute()
 {
     $result = $this->getResult();
     $params = $this->extractRequestParams();
     $source = $target = null;
     if (isset($params['source']) && Language::isValidBuiltInCode($params['source'])) {
         $source = $params['source'];
     }
     if (isset($params['target']) && Language::isValidBuiltInCode($params['target'])) {
         $target = $params['target'];
     }
     $interval = $params['interval'];
     $result->addValue(array('query'), 'contenttranslationlangtrend', ContentTranslation\Translation::getTrend($source, $target, $interval));
 }
 public function execute()
 {
     $params = $this->extractRequestParams();
     $user = $this->getUser();
     if ($user->isBlocked()) {
         $this->dieUsageMsg('blockedtext');
     }
     $translator = new ContentTranslation\Translator($user);
     $translation = ContentTranslation\Translation::find($params['from'], $params['to'], $params['sourcetitle']);
     $translation = $translation->translation;
     $translationId = $translation['id'];
     if ($translationId === null || $translator->getGlobalUserId() !== intval($translation['startedTranslator'])) {
         // Translation does not exist or belong to another translator
         $this->dieUsageMsg(array('invalidtitle', $params['sourcetitle']));
     }
     ContentTranslation\Translator::removeTranslation($translationId);
     ContentTranslation\Translation::delete($translationId);
     ContentTranslation\Draft::delete($translationId);
     $result = array('result' => 'success');
     $this->getResult()->addValue(null, $this->getModuleName(), $result);
 }
 public function execute()
 {
     $from = $to = null;
     $params = $this->extractRequestParams();
     $result = $this->getResult();
     $user = $this->getUser();
     if (isset($params['from'])) {
         $from = $params['from'];
     }
     if (isset($params['to'])) {
         $to = $params['to'];
     }
     $limit = $params['limit'];
     $offset = $params['offset'];
     if ($from !== null && !Language::isValidBuiltInCode($from)) {
         $this->dieUsage('Invalid language', 'invalidlanguage');
     }
     if ($to !== null && !Language::isValidBuiltInCode($to)) {
         $this->dieUsage('Invalid language', 'invalidlanguage');
     }
     $translations = ContentTranslation\Translation::getAllPublishedTranslations($from, $to, $limit, $offset);
     $resultSize = count($translations);
     $result->addValue(array('result'), 'translations', $translations);
 }
 public function execute()
 {
     $result = $this->getResult();
     $result->addValue(array('query', 'contenttranslationstats'), 'pages', ContentTranslation\Translation::getStats());
     $result->addValue(array('query', 'contenttranslationstats'), 'translators', ContentTranslation\Translator::getStats());
 }
 public function saveTranslationHistory($params)
 {
     global $wgContentTranslationDatabase, $wgContentTranslationTranslateInTarget;
     if ($wgContentTranslationDatabase === null) {
         // Central CX database not configured.
         return;
     }
     $user = $this->getUser();
     $translator = new ContentTranslation\Translator($user);
     if (!$wgContentTranslationTranslateInTarget) {
         $targetTitle = Title::newFromText($params['title']);
         if (!$targetTitle) {
             throw new InvalidArgumentException("Invalid target title given");
         }
         $targetURL = $targetTitle->getCanonicalUrl();
     } else {
         $targetTitle = ContentTranslation\SiteMapper::getTargetTitle($params['title'], $this->getUser()->getName());
         $targetURL = ContentTranslation\SiteMapper::getPageURL($params['to'], $targetTitle);
     }
     $translation = array('sourceTitle' => $params['sourcetitle'], 'targetTitle' => $params['title'], 'sourceLanguage' => $params['from'], 'targetLanguage' => $params['to'], 'sourceURL' => ContentTranslation\SiteMapper::getPageURL($params['from'], $params['sourcetitle']), 'status' => $params['status'], 'progress' => $params['progress'], 'startedTranslator' => $translator->getGlobalUserId(), 'lastUpdatedTranslator' => $translator->getGlobalUserId());
     // Save targetURL only when the status is published.
     if ($params['status'] === 'published') {
         $translation['targetURL'] = $targetURL;
     }
     $cxtranslation = new ContentTranslation\Translation($translation);
     $cxtranslation->save();
     $translationId = $cxtranslation->getTranslationId();
     $translator->addTranslation($translationId);
     if ($params['status'] === 'draft') {
         // Save the draft
         ContentTranslation\Draft::save($translationId, $params['html']);
     } else {
         // Delete the draft
         ContentTranslation\Draft::delete($translationId);
     }
 }