Пример #1
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);
 }
 public function contents()
 {
     $optional = $this->context->msg('translate-optional')->escaped();
     $this->doLinkBatch();
     $sourceLang = Language::factory($this->group->getSourceLanguage());
     $targetLang = Language::factory($this->collection->getLanguage());
     $titleMap = $this->collection->keys();
     $output = '';
     $this->collection->initMessages();
     // Just to be sure
     /**
      * @var TMessage $m
      */
     foreach ($this->collection as $key => $m) {
         $tools = array();
         /**
          * @var Title $title
          */
         $title = $titleMap[$key];
         $original = $m->definition();
         $translation = $m->translation();
         $hasTranslation = $translation !== null;
         if ($hasTranslation) {
             $message = $translation;
             $extraAttribs = self::getLanguageAttributes($targetLang);
         } else {
             $message = $original;
             $extraAttribs = self::getLanguageAttributes($sourceLang);
         }
         Hooks::run('TranslateFormatMessageBeforeTable', array(&$message, $m, $this->group, $targetLang, &$extraAttribs));
         // Using Html::element( a ) because Linker::link is memory hog.
         // It takes about 20 KiB per call, and that times 5000 is quite
         // a lot of memory.
         $niceTitle = htmlspecialchars($this->context->getLanguage()->truncate($title->getPrefixedText(), -35));
         $linkAttribs = array('href' => $title->getLocalUrl(array('action' => 'edit')));
         $linkAttribs += TranslationEditPage::jsEdit($title, $this->group->getId());
         $tools['edit'] = Html::element('a', $linkAttribs, $niceTitle);
         $anchor = 'msg_' . $key;
         $anchor = Xml::element('a', array('id' => $anchor, 'href' => "#{$anchor}"), "↓");
         $extra = '';
         if ($m->hasTag('optional')) {
             $extra = '<br />' . $optional;
         }
         $tqeData = $extraAttribs + array('data-title' => $title->getPrefixedText(), 'data-group' => $this->group->getId(), 'id' => 'tqe-anchor-' . substr(sha1($title->getPrefixedText()), 0, 12), 'class' => 'tqe-inlineeditable ' . ($hasTranslation ? 'translated' : 'untranslated'));
         $button = $this->getReviewButton($m);
         $status = $this->getReviewStatus($m);
         $leftColumn = $button . $anchor . $tools['edit'] . $extra . $status;
         if ($this->reviewMode) {
             $output .= Xml::tags('tr', array('class' => 'orig'), Xml::tags('td', array('rowspan' => '2'), $leftColumn) . Xml::tags('td', self::getLanguageAttributes($sourceLang), TranslateUtils::convertWhiteSpaceToHTML($original)));
             $output .= Xml::tags('tr', null, Xml::tags('td', $tqeData, TranslateUtils::convertWhiteSpaceToHTML($message)));
         } else {
             $output .= Xml::tags('tr', array('class' => 'def'), Xml::tags('td', null, $leftColumn) . Xml::tags('td', $tqeData, TranslateUtils::convertWhiteSpaceToHTML($message)));
         }
         $output .= "\n";
     }
     return $output;
 }
Пример #3
0
	public function contents() {
		$optional = wfMsgHtml( 'translate-optional' );

		$this->doLinkBatch();

		$sourceLang = Language::factory( $this->group->getSourceLanguage() );
		$targetLang = Language::factory( $this->collection->getLanguage() );
		$titleMap = $this->collection->keys();

		$output =  '';

		$this->collection->initMessages(); // Just to be sure
		foreach ( $this->collection as $key => $m ) {
			$tools = array();
			$title = $titleMap[$key];

			$original = $m->definition();

			if ( $m->translation() !== null ) {
				$message = $m->translation();
				$rclasses = self::getLanguageAttributes( $targetLang );
				$rclasses['class'] = 'translated';
			} else {
				$message = $original;
				$rclasses = self::getLanguageAttributes( $sourceLang );
				$rclasses['class'] = 'untranslated';
			}

			global $wgLang;
			$niceTitle = htmlspecialchars( $wgLang->truncate( $title->getPrefixedText(), -35 ) );

			$linker = class_exists( 'DummyLinker' ) ? new DummyLinker() : new Linker();
			$tools['edit'] = $linker->link(
				$title,
				$niceTitle,
				TranslationEditPage::jsEdit( $title, $this->group->getId() ),
				array( 'action' => 'edit' ) + $this->editLinkParams,
				'known'
			);

			$anchor = 'msg_' . $key;
			$anchor = Xml::element( 'a', array( 'id' => $anchor, 'href' => "#$anchor" ), "↓" );

			$extra = '';
			if ( $m->hasTag( 'optional' ) ) {
				$extra = '<br />' . $optional;
			}

			$leftColumn = $this->getReviewButton( $m ) . $anchor . $tools['edit'] . $extra . $this->getReviewStatus( $m );

			if ( $this->reviewMode && $original !== $message ) {
				$output .= Xml::tags( 'tr', array( 'class' => 'orig' ),
					Xml::tags( 'td', array( 'rowspan' => '2' ), $leftColumn ) .
					Xml::tags( 'td', self::getLanguageAttributes( $sourceLang ),
						TranslateUtils::convertWhiteSpaceToHTML( $original ) )
				);

				$output .= Xml::tags( 'tr', array( 'class' => 'new' ),
					Xml::tags( 'td', $rclasses, TranslateUtils::convertWhiteSpaceToHTML( $message ) )
				);
			} else {
				$output .= Xml::tags( 'tr', array( 'class' => 'def' ),
					Xml::tags( 'td', null, $leftColumn ) .
					Xml::tags( 'td', $rclasses, TranslateUtils::convertWhiteSpaceToHTML( $message ) )
				);
			}
			$output .= "\n";
		}

		return $output;
	}
 /**
  * Access point for this special page.
  */
 public function execute($parameters)
 {
     global $wgTranslateBlacklist, $wgContLang;
     $out = $this->getOutput();
     $out->addModuleStyles(array('ext.translate.special.translate.styles', 'jquery.uls.grid'));
     $out->addModules('ext.translate.special.translate');
     $this->setHeaders();
     $request = $this->getRequest();
     // @todo Move to api or so
     if ($parameters === 'editpage') {
         $editpage = TranslationEditPage::newFromRequest($request);
         if ($editpage) {
             $editpage->execute();
             return;
         }
     }
     if (!defined('ULS_VERSION')) {
         throw new ErrorPageError('translate-ulsdep-title', 'translate-ulsdep-body');
     }
     $this->setup($parameters);
     $isBeta = self::isBeta($request);
     if ($this->options['group'] === '' || $isBeta && !$this->group) {
         $this->groupInformation();
         return;
     }
     $errors = $this->getFormErrors();
     if ($isBeta && $this->options['taction'] !== 'export') {
         $out->addHTML(Html::openElement('div', array('class' => 'grid ext-translate-container')));
         $out->addHTML($this->tuxSettingsForm($errors));
         $out->addHTML($this->messageSelector());
     } else {
         $out->addModuleStyles('ext.translate.legacy');
         TranslateUtils::addSpecialHelpLink($out, 'Help:Extension:Translate/Translation_example');
         // Show errors nicely.
         $out->addHTML($this->settingsForm($errors));
     }
     if (count($errors)) {
         return;
     } else {
         $checks = array($this->options['group'], strtok($this->options['group'], '-'), '*');
         foreach ($checks as $check) {
             if (isset($wgTranslateBlacklist[$check][$this->options['language']])) {
                 $reason = $wgTranslateBlacklist[$check][$this->options['language']];
                 $out->addWikiMsg('translate-page-disabled', $reason);
                 if ($isBeta) {
                     // Close div.ext-translate-container
                     $out->addHTML(Html::closeElement('div'));
                 }
                 return;
             }
         }
     }
     $params = array($this->getContext(), $this->task, $this->group, $this->options);
     if (!Hooks::run('SpecialTranslate::executeTask', $params)) {
         return;
     }
     // Initialise and get output.
     if (!$this->task) {
         return;
     }
     $this->task->init($this->group, $this->options, $this->nondefaults, $this->getContext());
     $output = $this->task->execute();
     if ($this->task->plainOutput()) {
         $out->disable();
         header('Content-type: text/plain; charset=UTF-8');
         echo $output;
     } else {
         $description = $this->getGroupDescription($this->group);
         $taskid = $this->options['task'];
         if (in_array($taskid, array('untranslated', 'reviewall'), true)) {
             $hasOptional = count($this->group->getTags('optional'));
             if ($hasOptional) {
                 $linktext = $this->msg('translate-page-description-hasoptional-open')->escaped();
                 $params = array('task' => 'optional') + $this->nondefaults;
                 $link = Linker::link($this->getPageTitle(), $linktext, array(), $params);
                 $note = $this->msg('translate-page-description-hasoptional')->rawParams($link)->parseAsBlock();
                 if ($description) {
                     $description .= '<br />' . $note;
                 } else {
                     $description = $note;
                 }
             }
         }
         $groupId = $this->group->getId();
         // PHP is such an awesome language
         $priorityLangs = TranslateMetadata::get($groupId, 'prioritylangs');
         $priorityLangs = array_flip(array_filter(explode(',', $priorityLangs)));
         $priorityLangsCount = count($priorityLangs);
         if ($priorityLangsCount && !isset($priorityLangs[$this->options['language']])) {
             $priorityForce = TranslateMetadata::get($groupId, 'priorityforce');
             if ($priorityForce === 'on') {
                 // Hide table
                 $priorityMessageClass = 'errorbox';
                 $priorityMessageKey = 'tpt-discouraged-language-force';
             } else {
                 $priorityMessageClass = 'warningbox';
                 $priorityMessageKey = 'tpt-discouraged-language';
             }
             $priorityLanguageNames = array();
             $languageNames = TranslateUtils::getLanguageNames($this->getLanguage()->getCode());
             foreach (array_keys($priorityLangs) as $langCode) {
                 $priorityLanguageNames[] = $languageNames[$langCode];
             }
             $priorityReason = TranslateMetadata::get($groupId, 'priorityreason');
             if ($priorityReason !== '') {
                 $priorityReason = "\n\n" . $this->msg('tpt-discouraged-language-reason', Xml::element('span', array('lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir()), $priorityReason))->parse();
             }
             $description .= Html::RawElement('div', array('class' => $priorityMessageClass), $this->msg($priorityMessageKey, '', $languageNames[$this->options['language']], $this->getLanguage()->listToText($priorityLanguageNames))->parseAsBlock() . $priorityReason);
         }
         if ($description) {
             $description = Xml::fieldset($this->msg('translate-page-description-legend')->text(), $description, array('class' => 'mw-sp-translate-description'));
         }
         if ($isBeta) {
             $out->addHTML($output);
         } else {
             $out->addHTML($description . $output);
         }
         ApiTranslateUser::trackGroup($this->group, $this->getUser());
     }
     if ($isBeta) {
         $out->addHTML(Html::closeElement('div'));
     }
 }
 /**
  * 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);
 }
Пример #6
0
 /**
  * Access point for this special page.
  */
 public function execute($parameters)
 {
     global $wgOut, $wgTranslateBlacklist, $wgRequest;
     $wgOut->addModules('ext.translate.special.translate');
     $this->setHeaders();
     // @todo Move to api or so
     if ($parameters === 'editpage') {
         $editpage = TranslationEditPage::newFromRequest($wgRequest);
         if ($editpage) {
             $editpage->execute();
             return;
         }
     }
     $this->setup($parameters);
     $errors = array();
     if ($this->options['group'] === '') {
         TranslateUtils::addSpecialHelpLink($wgOut, 'Help:Extension:Translate/Translation_example');
         $this->groupInformation();
         return;
     }
     $codes = Language::getLanguageNames(false);
     if (!$this->options['language'] || !isset($codes[$this->options['language']])) {
         $errors['language'] = wfMsgExt('translate-page-no-such-language', array('parse'));
         $this->options['language'] = $this->defaults['language'];
     }
     if (!$this->task instanceof TranslateTask) {
         $errors['task'] = wfMsgExt('translate-page-no-such-task', array('parse'));
         $this->options['task'] = $this->defaults['task'];
     }
     if (!$this->group instanceof MessageGroup) {
         $errors['group'] = wfMsgExt('translate-page-no-such-group', array('parse'));
         $this->options['group'] = $this->defaults['group'];
     }
     TranslateUtils::addSpecialHelpLink($wgOut, 'Help:Extension:Translate/Translation_example');
     // Show errors nicely.
     $wgOut->addHTML($this->settingsForm($errors));
     if (count($errors)) {
         return;
     } else {
         $checks = array($this->options['group'], strtok($this->options['group'], '-'), '*');
         foreach ($checks as $check) {
             $reason = @$wgTranslateBlacklist[$check][$this->options['language']];
             if ($reason !== null) {
                 $wgOut->addWikiMsg('translate-page-disabled', $reason);
                 return;
             }
         }
     }
     // Proceed.
     $taskOptions = new TaskOptions($this->options['language'], $this->options['limit'], $this->options['offset'], array($this, 'cbAddPagingNumbers'));
     // Initialise and get output.
     $this->task->init($this->group, $taskOptions);
     $output = $this->task->execute();
     if ($this->task->plainOutput()) {
         $wgOut->disable();
         header('Content-type: text/plain; charset=UTF-8');
         echo $output;
     } else {
         $description = $this->getGroupDescription($this->group);
         $taskid = $this->options['task'];
         if (in_array($taskid, array('untranslated', 'reviewall'), true)) {
             $hasOptional = count($this->group->getTags('optional'));
             if ($hasOptional) {
                 $linker = class_exists('DummyLinker') ? new DummyLinker() : new Linker();
                 $linktext = wfMessage('translate-page-description-hasoptional-open')->escaped();
                 $params = array('task' => 'optional') + $this->nondefaults;
                 $link = $linker->link($this->getTitle(), $linktext, array(), $params);
                 $note = wfMessage('translate-page-description-hasoptional')->rawParams($link)->parseAsBlock();
                 if ($description) {
                     $description .= '<br>' . $note;
                 } else {
                     $description = $note;
                 }
             }
         }
         $status = $this->getWorkflowStatus();
         if ($status !== false) {
             $description = $status . $description;
         }
         if ($description) {
             $description = Xml::fieldset(wfMsg('translate-page-description-legend'), $description);
         }
         $links = $this->doStupidLinks();
         if ($this->paging['count'] === 0) {
             $wgOut->addHTML($description . $links);
         } else {
             $wgOut->addHTML($description . $links . $output . $links);
         }
     }
 }