29 private const METADATA_KEYS_DB = [
34 public function __construct(
36 private readonly JobQueueGroup $jobQueue,
37 private readonly LanguageNameUtils $languageNameUtils,
43 public function move( Title $oldName, Title $newName ):
void {
47 $this->messageGroupMetadata->moveMetadata(
48 $oldBundle->getMessageGroupId(),
49 $newBundle->getMessageGroupId(),
50 self::METADATA_KEYS_DB
53 MessageBundle::clearSourcePageCache();
55 MessageGroups::singleton()->recache();
61 $this->messageIndex->rebuild();
64 public function handleNullRevisionInsert(
TranslatableBundle $bundle, RevisionRecord $revision ):
void {
66 throw new InvalidArgumentException(
67 'Expected $bundle to be of type MessageBundle, got ' . get_class( $bundle )
71 $this->revTagStore->replaceTag( $bundle->
getTitle(), RevTagStore::MB_VALID_TAG, $revision->getId() );
72 MessageBundle::clearSourcePageCache();
75 public function delete( Title $title ):
void {
76 $this->revTagStore->removeTags( $title, RevTagStore::MB_VALID_TAG );
79 $this->messageGroupMetadata->clearMetadata( $bundle->
getMessageGroupId(), self::METADATA_KEYS_DB );
81 MessageBundle::clearSourcePageCache();
83 MessageGroups::singleton()->recache();
84 $this->jobQueue->push( RebuildMessageIndexJob::newJob( __METHOD__ ) );
92 $sourceLanguageCode = $metadata->getSourceLanguageCode();
93 if ( $sourceLanguageCode ) {
94 if ( !$this->languageNameUtils->isKnownLanguageTag( $sourceLanguageCode ) ) {
96 'translate-messagebundle-error-invalid-sourcelanguage', [ $sourceLanguageCode ]
100 $revisionId = $this->revTagStore->getLatestRevisionWithTag( $pageTitle, RevTagStore::MB_VALID_TAG );
102 if ( $revisionId !==
null && $sourceLanguageCode !== $pageTitle->getPageLanguage()->getCode() ) {
103 throw new MalformedBundle(
'translate-messagebundle-sourcelanguage-changed' );
108 $priorityLanguageCodes = $metadata->getPriorityLanguages();
109 if ( $priorityLanguageCodes ) {
110 $invalidLanguageCodes = [];
111 foreach ( $priorityLanguageCodes as $languageCode ) {
112 if ( !is_string( $languageCode ) ) {
113 throw new MalformedBundle(
'translate-messagebundle-error-invalid-prioritylanguage-format' );
116 if ( !$this->languageNameUtils->isKnownLanguageTag( $languageCode ) ) {
117 $invalidLanguageCodes[] = $languageCode;
121 if ( $invalidLanguageCodes ) {
122 throw new MalformedBundle(
123 'translate-messagebundle-error-invalid-prioritylanguage',
124 [ Message::listParam( $invalidLanguageCodes ), count( $invalidLanguageCodes ) ]
130 public function save(
132 RevisionRecord $revisionRecord,
133 MessageBundleContent $content
136 $this->validate( $pageTitle, $content );
138 $previousRevisionId = $this->revTagStore->getLatestRevisionWithTag( $pageTitle, RevTagStore::MB_VALID_TAG );
139 if ( $previousRevisionId !==
null ) {
140 $this->revTagStore->removeTags( $pageTitle, RevTagStore::MB_VALID_TAG );
143 if ( $content->isValid() ) {
145 $this->revTagStore->replaceTag( $pageTitle, RevTagStore::MB_VALID_TAG, $revisionRecord->getId() );
146 MessageBundle::clearSourcePageCache();
149 $job = UpdateMessageBundleJob::newJob( $pageTitle, $revisionRecord->getId(), $previousRevisionId );
151 $this->jobQueue->push( $job );
153 $metadata = $content->getMetadata();
155 if ( $previousRevisionId ===
null ) {
157 $definedLanguageCode = $metadata->getSourceLanguageCode();
158 $pageLanguageCode = $pageTitle->getPageLanguage()->getCode();
159 if ( $definedLanguageCode !==
null && $definedLanguageCode !== $pageLanguageCode ) {
160 $context = RequestContext::getMain();
161 SpecialPageLanguage::changePageLanguage(
164 $definedLanguageCode,
165 $context->msg(
'translate-messagebundle-change-sourcelanguage' )->inContentLanguage()->text()
171 $messageBundle =
new MessageBundle( $pageTitle );
172 $groupId = $messageBundle->getMessageGroupId();
174 $priorityForce = $metadata->areOnlyPriorityLanguagesAllowed() ?
'on' :
false;
175 $priorityLanguages = $metadata->getPriorityLanguages();
176 $priorityLanguages = $priorityLanguages ? implode(
',', $priorityLanguages ) : false;
178 $this->messageGroupMetadata->set( $groupId,
'prioritylangs', $priorityLanguages );
179 $this->messageGroupMetadata->set( $groupId,
'priorityforce', $priorityForce );
181 $description = $metadata->getDescription();
182 $this->messageGroupMetadata->set( $groupId,
'description', $description ??
false );
184 $label = $metadata->getLabel();
185 $this->messageGroupMetadata->set( $groupId,
'label', $label ??
false );