33 private $languageNameUtils;
35 private $messageIndex;
36 private const METADATA_KEYS_DB = [
41 public function __construct(
43 JobQueueGroup $jobQueue,
44 LanguageNameUtils $languageNameUtils,
47 $this->revTagStore = $revTagStore;
48 $this->jobQueue = $jobQueue;
49 $this->languageNameUtils = $languageNameUtils;
50 $this->messageIndex = $messageIndex;
53 public function move( Title $oldName, Title $newName ):
void {
57 TranslateMetadata::moveMetadata(
58 $oldBundle->getMessageGroupId(),
59 $newBundle->getMessageGroupId(),
60 self::METADATA_KEYS_DB
63 MessageBundle::clearSourcePageCache();
66 MessageGroups::singleton()->recache();
69 $this->messageIndex->rebuild();
72 public function handleNullRevisionInsert(
TranslatableBundle $bundle, RevisionRecord $revision ):
void {
74 throw new InvalidArgumentException(
75 'Expected $bundle to be of type MessageBundle, got ' . get_class( $bundle )
79 $this->revTagStore->replaceTag( $bundle->
getTitle(), RevTagStore::MB_VALID_TAG, $revision->getId() );
80 MessageBundle::clearSourcePageCache();
83 public function delete( Title $title ):
void {
84 $this->revTagStore->removeTags( $title, RevTagStore::MB_VALID_TAG );
87 TranslateMetadata::clearMetadata( $bundle->
getMessageGroupId(), self::METADATA_KEYS_DB );
89 MessageBundle::clearSourcePageCache();
91 MessageGroups::singleton()->recache();
92 $this->messageIndex->rebuild();
98 $metadata = $content->getMetadata();
99 $sourceLanguageCode = $metadata->getSourceLanguageCode();
100 if ( $sourceLanguageCode ) {
101 if ( !$this->languageNameUtils->isKnownLanguageTag( $sourceLanguageCode ) ) {
103 'translate-messagebundle-error-invalid-sourcelanguage', [ $sourceLanguageCode ]
107 $revisionId = $this->revTagStore->getLatestRevisionWithTag( $pageTitle, RevTagStore::MB_VALID_TAG );
109 if ( $revisionId !==
null && $sourceLanguageCode !== $pageTitle->getPageLanguage()->getCode() ) {
110 throw new MalformedBundle(
'translate-messagebundle-sourcelanguage-changed' );
115 $priorityLanguageCodes = $metadata->getPriorityLanguages();
116 if ( $priorityLanguageCodes ) {
117 $invalidLanguageCodes = [];
118 foreach ( $priorityLanguageCodes as $languageCode ) {
119 if ( !is_string( $languageCode ) ) {
120 throw new MalformedBundle(
'translate-messagebundle-error-invalid-prioritylanguage-format' );
123 if ( !$this->languageNameUtils->isKnownLanguageTag( $languageCode ) ) {
124 $invalidLanguageCodes[] = $languageCode;
128 if ( $invalidLanguageCodes ) {
130 'translate-messagebundle-error-invalid-prioritylanguage',
131 [ Message::listParam( $invalidLanguageCodes ), count( $invalidLanguageCodes ) ]
137 public function save(
139 RevisionRecord $revisionRecord,
143 $this->validate( $pageTitle, $content );
145 $previousRevisionId = $this->revTagStore->getLatestRevisionWithTag( $pageTitle, RevTagStore::MB_VALID_TAG );
146 if ( $previousRevisionId !==
null ) {
147 $this->revTagStore->removeTags( $pageTitle, RevTagStore::MB_VALID_TAG );
150 if ( $content->isValid() ) {
152 $this->revTagStore->replaceTag( $pageTitle, RevTagStore::MB_VALID_TAG, $revisionRecord->getId() );
153 MessageBundle::clearSourcePageCache();
156 $job = UpdateMessageBundleJob::newJob( $pageTitle, $revisionRecord->getId(), $previousRevisionId );
158 $this->jobQueue->push( $job );
161 $definedLanguageCode = $content->getMetadata()->getSourceLanguageCode();
162 $pageLanguageCode = $pageTitle->getPageLanguage()->getCode();
163 if ( $previousRevisionId ===
null ) {
164 if ( $definedLanguageCode !== $pageLanguageCode ) {
165 $context = RequestContext::getMain();
166 SpecialPageLanguage::changePageLanguage(
169 $definedLanguageCode,
170 wfMessage(
'translate-messagebundle-change-sourcelanguage' )->inContentLanguage()
177 $groupId = $messageBundle->getMessageGroupId();
179 $metadata = $content->getMetadata();
180 $priorityForce = $metadata->areOnlyPriorityLanguagesAllowed() ?
'on' :
false;
181 $priorityLanguages = $metadata->getPriorityLanguages();
182 $priorityLanguages = $priorityLanguages ? implode(
',', $priorityLanguages ) :
false;
184 TranslateMetadata::set( $groupId,
'prioritylangs', $priorityLanguages );
185 TranslateMetadata::set( $groupId,
'priorityforce', $priorityForce );
187 $description = $metadata->getDescription();
188 TranslateMetadata::set( $groupId,
'description', $description ??
false );