コード例 #1
0
 /**
  * Generates the html snippet for ajax edit. Echoes it to the output and
  * disabled all other output.
  */
 public function execute()
 {
     global $wgServer, $wgScriptPath;
     $context = RequestContext::getMain();
     $context->getOutput()->disable();
     $data = $this->getEditInfo();
     $helpers = new TranslationHelpers($this->getTitle(), '');
     $id = "tm-target-{$helpers->dialogID()}";
     $helpers->setTextareaId($id);
     if ($this->suggestions === 'checks') {
         echo $helpers->getBoxes($this->suggestions);
         return;
     }
     $handle = new MessageHandle($this->getTitle());
     $groupId = MessageIndex::getPrimaryGroupId($handle);
     $translation = '';
     if ($groupId) {
         $translation = $helpers->getTranslation();
     }
     $targetLang = Language::factory($helpers->getTargetLanguage());
     $textareaParams = array('name' => 'text', 'class' => 'mw-translate-edit-area', 'id' => $id, 'lang' => $targetLang->getCode(), 'dir' => $targetLang->getDir());
     if (!$groupId || !$context->getUser()->isAllowed('translate')) {
         $textareaParams['readonly'] = 'readonly';
     }
     $extraInputs = '';
     Hooks::run('TranslateGetExtraInputs', array(&$translation, &$extraInputs));
     $textarea = Html::element('textarea', $textareaParams, $translation);
     $hidden = array();
     $hidden[] = Html::hidden('title', $this->getTitle()->getPrefixedDbKey());
     if (isset($data['revisions'][0]['timestamp'])) {
         $hidden[] = Html::hidden('basetimestamp', $data['revisions'][0]['timestamp']);
     }
     $hidden[] = Html::hidden('starttimestamp', $data['starttimestamp']);
     if (isset($data['edittoken'])) {
         $hidden[] = Html::hidden('token', $data['edittoken']);
     }
     $hidden[] = Html::hidden('format', 'json');
     $hidden[] = Html::hidden('action', 'edit');
     $summary = Xml::inputLabel($context->msg('translate-js-summary')->text(), 'summary', 'summary', 40);
     $save = Xml::submitButton($context->msg('translate-js-save')->text(), array('class' => 'mw-translate-save'));
     $saveAndNext = Xml::submitButton($context->msg('translate-js-next')->text(), array('class' => 'mw-translate-next'));
     $skip = Html::element('input', array('class' => 'mw-translate-skip', 'type' => 'button', 'value' => $context->msg('translate-js-skip')->text()));
     if ($this->getTitle()->exists()) {
         $history = Html::element('input', array('class' => 'mw-translate-history', 'type' => 'button', 'value' => $context->msg('translate-js-history')->text()));
     } else {
         $history = '';
     }
     $support = $this->getSupportButton($this->getTitle());
     if ($context->getUser()->isAllowed('translate')) {
         $bottom = "{$summary}{$save}{$saveAndNext}{$skip}{$history}{$support}";
     } else {
         $text = $context->msg('translate-edit-nopermission')->escaped();
         $button = $this->getPermissionPageButton();
         $bottom = "{$text} {$button}{$skip}{$history}{$support}";
     }
     // Use the api to submit edits
     $formParams = array('action' => "{$wgServer}{$wgScriptPath}/api.php", 'method' => 'post');
     $form = Html::rawElement('form', $formParams, implode("\n", $hidden) . "\n" . $helpers->getBoxes($this->suggestions) . "\n" . Html::rawElement('div', array('class' => 'mw-translate-inputs'), "{$textarea}\n{$extraInputs}") . "\n" . Html::rawElement('div', array('class' => 'mw-translate-bottom'), $bottom));
     echo Html::rawElement('div', array('class' => 'mw-ajax-dialog'), $form);
 }
コード例 #2
0
 protected function formatTranslation(StashedTranslation $translation)
 {
     $title = $translation->getTitle();
     $handle = new MessageHandle($title);
     // Prepare for the worst
     $definition = '';
     $comparison = '';
     if ($handle->isValid()) {
         $groupId = MessageIndex::getPrimaryGroupId($handle);
         $group = MessageGroups::getGroup($groupId);
         $key = $handle->getKey();
         $definition = $group->getMessage($key, $group->getSourceLanguage());
         $comparison = $group->getMessage($key, $handle->getCode());
     }
     return array('title' => $title->getPrefixedText(), 'definition' => $definition, 'translation' => $translation->getValue(), 'comparison' => $comparison, 'metadata' => $translation->getMetadata());
 }
コード例 #3
0
 /**
  * Ajax-enabled message editing link.
  * @param $target Title: Title of the target message.
  * @param $text String: Link text for Linker::link()
  * @return link
  */
 public static function ajaxEditLink($target, $text)
 {
     $handle = new MessageHandle($target);
     $groupId = MessageIndex::getPrimaryGroupId($handle);
     $params = array();
     $params['action'] = 'edit';
     $params['loadgroup'] = $groupId;
     $jsEdit = TranslationEditPage::jsEdit($target, $groupId);
     $linker = class_exists('DummyLinker') ? new DummyLinker() : new Linker();
     return $linker->link($target, $text, $jsEdit, $params);
 }
コード例 #4
0
ファイル: MessageGroups.php プロジェクト: schwarer2006/wikia
 /**
  * Subpage language of any in the title is not used.
  */
 public function getMessageContent(MessageHandle $handle, $code)
 {
     $groupId = MessageIndex::getPrimaryGroupId($handle);
     $group = MessageGroups::getGroup($groupId);
     if ($group) {
         return $group->getMessage($handle->getKey(), $code);
     }
 }
コード例 #5
0
 /**
  * Subpage language code, if any in the title, is ignored.
  * @param MessageHandle $handle
  * @return null|string
  * @throws MWException
  */
 public function getMessageContent(MessageHandle $handle)
 {
     $groupId = MessageIndex::getPrimaryGroupId($handle);
     $group = MessageGroups::getGroup($groupId);
     if ($group) {
         return $group->getMessage($handle->getKey(), $group->getSourceLanguage());
     }
     throw new MWException('Could not find group for ' . $handle->getKey());
 }
コード例 #6
0
 /**
  * Ajax-enabled message editing link.
  * @param $target Title: Title of the target message.
  * @param $text String: Link text for Linker::link()
  * @return string HTML link
  */
 public static function ajaxEditLink($target, $text)
 {
     $handle = new MessageHandle($target);
     $groupId = MessageIndex::getPrimaryGroupId($handle);
     $params = array();
     $params['action'] = 'edit';
     $params['loadgroup'] = $groupId;
     $jsEdit = TranslationEditPage::jsEdit($target, $groupId, 'dialog');
     return Linker::link($target, $text, $jsEdit, $params);
 }
コード例 #7
0
 /**
  * Subpage language code, if any in the title, is ignored.
  * @param MessageHandle $handle
  * @return null|string
  */
 public function getMessageContent(MessageHandle $handle)
 {
     $groupId = MessageIndex::getPrimaryGroupId($handle);
     $group = MessageGroups::getGroup($groupId);
     $key = $handle->getKey();
     $source = $group->getMessage($key, $group->getSourceLanguage());
     if ($source !== null) {
         return $source;
     }
     // Try harder
     if (method_exists($group, 'getKeys')) {
         $keys = $group->getKeys();
     } else {
         $keys = array_keys($group->getDefinitions());
     }
     // Try to find the original key with correct case
     foreach ($keys as $realkey) {
         if ($key === strtolower($realkey)) {
             $key = $realkey;
             break;
         }
     }
     return $group->getMessage($key, $group->getSourceLanguage());
 }
 /**
  * @param string $key Message key
  * @param string $code Language code
  * @return null|string
  */
 public function getMessage($key, $code)
 {
     /* Just hand over the message content retrieval to the primary message
      * group directly. This used to iterate over the subgroups looking for
      * the primary group, but that might actually be under some other
      * aggregate message group.
      * @todo Implement getMessageContent to avoid hardcoding the namespace
      * here.
      */
     $title = Title::makeTitle($this->getNamespace(), $key);
     $handle = new MessageHandle($title);
     $groupId = MessageIndex::getPrimaryGroupId($handle);
     if ($groupId === $this->getId()) {
         // Message key owned by aggregate group.
         // Should not ever happen, but it does.
         error_log("AggregateMessageGroup {$groupId} cannot be primary owner of key {$key}");
         return null;
     }
     $group = MessageGroups::getGroup($groupId);
     if ($group) {
         return $group->getMessage($key, $code);
     } else {
         return null;
     }
 }