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 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);
     }
 }