/**
  * @param ApiPageSet $resultPageSet
  * TODO: Use the limit parameter
  */
 private function run($resultPageSet = null)
 {
     $params = $this->extractRequestParams();
     $result = $this->getResult();
     $user = $this->getUser();
     if ($user->isAnon()) {
         $this->dieUsage('To view your translations, you must log in', 'notloggedin');
     }
     if ($params['sourcetitle'] && $params['from'] && $params['to']) {
         return $this->find($params['sourcetitle'], $params['from'], $params['to']);
     }
     if ($params['translationid']) {
         $translator = new ContentTranslation\Translator($user);
         $translation = $translator->getTranslation($params['translationid']);
         if ($translation !== null) {
             $result->addValue(array('query', 'contenttranslation'), 'translation', $translation->translation);
         } else {
             $this->dieUsage('Draft does not exist', $params['translationid']);
         }
     } else {
         $translator = new ContentTranslation\Translator($user);
         $translations = $translator->getAllTranslations();
         $result->addValue(array('query', 'contenttranslation'), 'translations', $translations);
     }
 }
 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);
 }
 /**
  * @param ApiPageSet $resultPageSet
  */
 private function run($resultPageSet = null)
 {
     $params = $this->extractRequestParams();
     $result = $this->getResult();
     $user = $this->getUser();
     if ($user->isAnon()) {
         $this->dieUsage('To view your translations, you must log in', 'notloggedin');
     }
     if ($params['sourcetitle'] && $params['from'] && $params['to']) {
         return $this->find($params['sourcetitle'], $params['from'], $params['to']);
     }
     if ($params['translationid']) {
         $translator = new ContentTranslation\Translator($user);
         $translation = $translator->getTranslation($params['translationid']);
         if ($translation !== null) {
             $result->addValue(array('query', 'contenttranslation'), 'translation', $translation->translation);
         } else {
             $this->dieUsage('Draft does not exist', $params['translationid']);
         }
         return;
     }
     // The main case, no filters
     $translator = new ContentTranslation\Translator($user);
     $translations = $translator->getAllTranslations($params['limit'], $params['offset'], $params['type']);
     // We will have extra continue in case the last batch is exactly the size of the limit
     $count = count($translations);
     if ($count === $params['limit']) {
         $offset = $translations[$count - 1]->translation['lastUpdateTimeStamp'];
         $this->setContinueEnumParameter('offset', $offset);
     }
     $result->addValue(array('query', 'contenttranslation'), 'translations', $translations);
     // Simple optimization
     if ($params['offset'] === null) {
         $result->addValue(array('query', 'contenttranslation'), 'languages', $translator->getLanguages($params['type']));
     }
 }
 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);
     }
 }