30 private $languageNameUtils;
32 private $userOptionsLookup;
34 public const CONSTRUCTOR_OPTIONS = [
35 'TranslateSandboxLimit',
36 'TranslateSecondaryPermissionUrl'
39 public function __construct(
40 LanguageNameUtils $languageNameUtils,
42 UserOptionsLookup $userOptionsLookup,
43 ServiceOptions $options
45 $this->languageNameUtils = $languageNameUtils;
46 $this->stash = $stash;
47 $this->userOptionsLookup = $userOptionsLookup;
48 $this->options = $options;
49 parent::__construct(
'TranslationStash' );
52 public function doesWrites() {
56 protected function getGroupName() {
60 public function execute( $params ) {
61 $limit = $this->options->get(
'TranslateSandboxLimit' );
62 $secondaryPermissionUrl = $this->options->get(
'TranslateSecondaryPermissionUrl' );
65 $out = $this->getOutput();
69 if ( !$this->hasPermissionToUse() ) {
70 if ( $secondaryPermissionUrl && $this->getUser()->isRegistered() ) {
72 Title::newFromText( $secondaryPermissionUrl )->getLocalURL()
78 $out->redirect( Title::newMainPage()->getLocalURL() );
83 $out->addJsConfigVars(
'wgTranslateSandboxLimit', $limit );
84 $out->addModules(
'ext.translate.specialTranslationStash' );
85 $out->addModuleStyles(
'mediawiki.ui.button' );
90 private function hasPermissionToUse():
bool {
91 return TranslateSandbox::isSandboxed( $this->getUser() );
95 private function showPage():
void {
96 $out = $this->getOutput();
97 $user = $this->getUser();
99 $count = count( $this->stash->getTranslations( $user ) );
100 if ( $count === 0 ) {
101 $progress = $this->msg(
'translate-translationstash-initialtranslation' )->parse();
103 $progress = $this->msg(
'translate-translationstash-translations' )
104 ->numParams( $count )
111 <div
class=
"row translate-welcome-header">
113 {$this->msg(
'translate-translationstash-welcome', $user->getName() )->parse()}
116 {$this->msg(
'translate-translationstash-welcome-note' )->parse()}
119 <div
class=
"row translate-stash-control">
120 <div
class=
"six columns stash-stats">
123 <div
class=
"six columns ext-translate-language-selector">
124 {$this->tuxLanguageSelector()}
127 {$this->getMessageTable()}
128 <div
class=
"row limit-reached hide"></div>
134 private function getMessageTable():
string {
136 $targetLang = $this->getTargetLanguage();
138 return Html::element(
141 'class' =>
'row tux-messagelist',
142 'data-sourcelangcode' => $sourceLang->getCode(),
143 'data-sourcelangdir' => $sourceLang->getDir(),
144 'data-targetlangcode' => $targetLang->getCode(),
145 'data-targetlangdir' => $targetLang->getDir(),
150 private function tuxLanguageSelector():
string {
153 $language = $this->getTargetLanguage();
154 $targetLangName = $this->languageNameUtils->getLanguageName( $language->getCode() );
156 $label = Html::element(
'span', [], $this->msg(
'tux-languageselector' )->text() );
158 $languageIcon = Html::element(
160 [
'class' =>
'ext-translate-language-icon' ]
163 $targetLanguageName = Html::element(
166 'class' =>
'ext-translate-target-language',
167 'dir' => $language->getDir(),
168 'lang' => $language->getHtmlCode()
173 $expandIcon = Html::element(
175 [
'class' =>
'ext-translate-language-selector-expand' ]
178 $value = Html::rawElement(
181 'class' =>
'uls mw-ui-button',
183 'title' => $this->msg(
'tux-select-target-language' )->text()
185 $languageIcon . $targetLanguageName . $expandIcon
188 return Html::rawElement(
190 [
'class' =>
'columns ext-translate-language-selector' ],
198 return Language::factory(
'en' );
202 private function getTargetLanguage(): Language {
203 $ui = $this->getLanguage();
204 $source = $this->getSourceLanguage();
205 if ( !$ui->equals( $source ) ) {
209 $options = FormatJson::decode(
210 $this->userOptionsLookup->getOption( $this->getUser(),
'translate-sandbox' ),
213 $supported = TranslateUtils::getLanguageNames(
'en' );
215 if ( isset( $options[
'languages'] ) ) {
216 foreach ( $options[
'languages'] as $code ) {
217 if ( !isset( $supported[$code] ) ) {
221 if ( $code !== $source->getCode() ) {
222 return Language::factory( $code );
228 return Language::factory( $source->getCode() );
return[ 'Translate:ConfigHelper'=> static function():ConfigHelper { return new ConfigHelper();}, 'Translate:CsvTranslationImporter'=> static function(MediaWikiServices $services):CsvTranslationImporter { return new CsvTranslationImporter( $services->getWikiPageFactory());}, 'Translate:EntitySearch'=> static function(MediaWikiServices $services):EntitySearch { return new EntitySearch($services->getMainWANObjectCache(), $services->getCollationFactory() ->makeCollation( 'uca-default-u-kn'), MessageGroups::singleton(), $services->getNamespaceInfo(), $services->get( 'Translate:MessageIndex'), $services->getTitleParser(), $services->getTitleFormatter());}, 'Translate:ExternalMessageSourceStateImporter'=> static function(MediaWikiServices $services):ExternalMessageSourceStateImporter { return new ExternalMessageSourceStateImporter($services->getMainConfig(), $services->get( 'Translate:GroupSynchronizationCache'), $services->getJobQueueGroup(), LoggerFactory::getInstance( 'Translate.GroupSynchronization'), MessageIndex::singleton());}, 'Translate:GroupSynchronizationCache'=> static function(MediaWikiServices $services):GroupSynchronizationCache { return new GroupSynchronizationCache( $services->get( 'Translate:PersistentCache'));}, 'Translate:MessageBundleStore'=> static function(MediaWikiServices $services):MessageBundleStore { return new MessageBundleStore(new RevTagStore(), $services->getJobQueueGroup(), $services->getLanguageNameUtils(), $services->get( 'Translate:MessageIndex'));}, 'Translate:MessageGroupReview'=> static function(MediaWikiServices $services):MessageGroupReview { return new MessageGroupReview($services->getDBLoadBalancer(), $services->getHookContainer());}, 'Translate:MessageIndex'=> static function(MediaWikiServices $services):MessageIndex { $params=$services->getMainConfig() ->get( 'TranslateMessageIndex');if(is_string( $params)) { $params=(array) $params;} $class=array_shift( $params);return new $class( $params);}, 'Translate:ParsingPlaceholderFactory'=> static function():ParsingPlaceholderFactory { return new ParsingPlaceholderFactory();}, 'Translate:PersistentCache'=> static function(MediaWikiServices $services):PersistentCache { return new PersistentDatabaseCache($services->getDBLoadBalancer(), $services->getJsonCodec());}, 'Translate:ProgressStatsTableFactory'=> static function(MediaWikiServices $services):ProgressStatsTableFactory { return new ProgressStatsTableFactory($services->getLinkRenderer(), $services->get( 'Translate:ConfigHelper'));}, 'Translate:SubpageListBuilder'=> static function(MediaWikiServices $services):SubpageListBuilder { return new SubpageListBuilder($services->get( 'Translate:TranslatableBundleFactory'), $services->getLinkBatchFactory());}, 'Translate:TranslatableBundleFactory'=> static function(MediaWikiServices $services):TranslatableBundleFactory { return new TranslatableBundleFactory($services->get( 'Translate:TranslatablePageStore'), $services->get( 'Translate:MessageBundleStore'));}, 'Translate:TranslatableBundleMover'=> static function(MediaWikiServices $services):TranslatableBundleMover { return new TranslatableBundleMover($services->getMovePageFactory(), $services->getJobQueueGroup(), $services->getLinkBatchFactory(), $services->get( 'Translate:TranslatableBundleFactory'), $services->get( 'Translate:SubpageListBuilder'), $services->getMainConfig() ->get( 'TranslatePageMoveLimit'));}, 'Translate:TranslatablePageParser'=> static function(MediaWikiServices $services):TranslatablePageParser { return new TranslatablePageParser($services->get( 'Translate:ParsingPlaceholderFactory'));}, 'Translate:TranslatablePageStore'=> static function(MediaWikiServices $services):TranslatablePageStore { return new TranslatablePageStore($services->get( 'Translate:MessageIndex'), $services->getJobQueueGroup(), new RevTagStore(), $services->getDBLoadBalancer());}, 'Translate:TranslationStashReader'=> static function(MediaWikiServices $services):TranslationStashReader { $db=$services->getDBLoadBalancer() ->getConnectionRef(DB_REPLICA);return new TranslationStashStorage( $db);}, 'Translate:TranslationStatsDataProvider'=> static function(MediaWikiServices $services):TranslationStatsDataProvider { return new TranslationStatsDataProvider(new ServiceOptions(TranslationStatsDataProvider::CONSTRUCTOR_OPTIONS, $services->getMainConfig()), $services->getObjectFactory());}, 'Translate:TranslationUnitStoreFactory'=> static function(MediaWikiServices $services):TranslationUnitStoreFactory { return new TranslationUnitStoreFactory( $services->getDBLoadBalancer());}, 'Translate:TranslatorActivity'=> static function(MediaWikiServices $services):TranslatorActivity { $query=new TranslatorActivityQuery($services->getMainConfig(), $services->getDBLoadBalancer());return new TranslatorActivity($services->getMainObjectStash(), $query, $services->getJobQueueGroup());}, 'Translate:TtmServerFactory'=> static function(MediaWikiServices $services):TtmServerFactory { $config=$services->getMainConfig();$default=$config->get( 'TranslateTranslationDefaultService');if( $default===false) { $default=null;} return new TtmServerFactory( $config->get( 'TranslateTranslationServices'), $default);}]
@phpcs-require-sorted-array