15use MediaWiki\Logger\LoggerFactory;
16use MediaWiki\Revision\RevisionRecord;
17use MediaWiki\Storage\EditResult;
18use MediaWiki\User\UserIdentity;
39 if ( $action !==
'edit' ) {
44 if ( !$handle->isValid() ) {
48 if ( $user->isAllowed(
'translate-manage' ) ) {
52 $group = $handle->getGroup();
53 $languages = $group->getTranslatableLanguages();
54 $langCode = $handle->getCode();
55 if ( $languages !==
null && $langCode && !isset( $languages[$langCode] ) ) {
56 $result = [
'translate-language-disabled' ];
60 $groupId = $group->getId();
63 strtok( $groupId,
'-' ),
67 $disabledLanguages = Services::getInstance()->getConfigHelper()->getDisabledTargetLanguages();
68 foreach ( $checks as $check ) {
69 if ( isset( $disabledLanguages[$check][$langCode] ) ) {
70 $reason = $disabledLanguages[$check][$langCode];
71 $result = [
'translate-page-disabled', $reason ];
93 UserIdentity $userIdentity,
96 RevisionRecord $revisionRecord,
97 EditResult $editResult
99 global $wgEnablePageTranslation;
101 $content = $wikiPage->getContent();
103 if ( !$content instanceof TextContent ) {
108 $text = $content->getText();
109 $title = $wikiPage->getTitle();
112 if ( !$handle->isValid() ) {
117 $revId = $revisionRecord->getId();
122 $group = $handle->getGroup();
124 if ( $handle->getCode() !== $group->getSourceLanguage() ) {
129 MessageGroupStats::clear( $handle );
135 DeferredUpdates::addCallableUpdate(
136 static function () use ( $handle ) {
141 $user = User::newFromIdentity( $userIdentity );
143 if ( $fuzzy ===
false ) {
144 Hooks::run(
'Translate:newTranslation', [ $handle, $revId, $text, $user ] );
147 TTMServer::onChange( $handle );
149 if ( $wgEnablePageTranslation && $handle->isPageTranslation() ) {
151 $minor = $flags & EDIT_MINOR;
153 $summary, $minor, $flags, $handle );
167 if ( $handle->
isDoc() ) {
172 if ( MessageHandle::hasFuzzyString( $text ) ) {
178 $validator = $group->getValidator();
187 $en = $group->getMessage( $key, $group->getSourceLanguage() );
190 $message->setTranslation( $text );
191 if ( $message->definition() ===
null ) {
194 LoggerFactory::getInstance(
'Translate' )->warning(
195 'Message definition is empty! Title: {title}, group: {group}, key: {key}',
197 'title' => $handle->
getTitle()->getPrefixedText(),
198 'group' => $group->getId(),
205 $validationResult = $validator->quickValidate( $message, $code );
206 return $validationResult->hasIssues();
216 $dbw = wfGetDB( DB_PRIMARY );
219 'rt_page' => $title->getArticleID(),
220 'rt_type' => RevTagStore::FUZZY_TAG,
221 'rt_revision' => $revision
225 if ( $fuzzy !==
false ) {
226 $index = array_keys( $conds );
227 $dbw->replace(
'revtag', [ $index ], $conds, __METHOD__ );
229 $dbw->delete(
'revtag', $conds, __METHOD__ );
232 return (
bool)$dbw->affectedRows();
249 if ( $user->isAllowed(
'bot' ) ) {
256 $name = $handle->
getKey() .
'/' . $group->getSourceLanguage();
257 $definitionTitle = Title::makeTitleSafe( $title->getNamespace(), $name );
258 if ( !$definitionTitle || !$definitionTitle->exists() ) {
262 $definitionRevision = $definitionTitle->getLatestRevID();
264 $dbw = wfGetDB( DB_PRIMARY );
267 'rt_page' => $title->getArticleID(),
268 'rt_type' => RevTagStore::TRANSVER_PROP,
269 'rt_revision' => $revision,
270 'rt_value' => $definitionRevision,
272 $index = [
'rt_type',
'rt_page',
'rt_revision' ];
273 $dbw->replace(
'revtag', [ $index ], $conds, __METHOD__ );
285 global $wgTranslateUsePreSaveTransform;
287 if ( !$wgTranslateUsePreSaveTransform ) {
289 if ( $handle->isMessageNamespace() && !$handle->isDoc() ) {
290 $popts->setPreSaveTransform(
false );
Message object where you can directly set the translation.
Hooks for page translation.
static onSectionSave(WikiPage $wikiPage, User $user, TextContent $content, $summary, $minor, $flags, MessageHandle $handle)
This is triggered after an edit to translation unit page.
static onChange(MessageHandle $handle)
Hook: TranslateEventTranslationReview and also on translation changes.
Class for pointing to messages, like Title class is for titles.
isDoc()
Determine whether the current handle is for message documentation.
getGroup()
Get the primary MessageGroup this message belongs to.
getTitle()
Get the original title.
getCode()
Returns the language code.
getKey()
Returns the identified or guessed message key.
Various editing enhancements to the edit page interface.
static updateTransverTag(MessageHandle $handle, $revision, $text, User $user)
Adds tag which identifies the revision of source message at that time.
static updateFuzzyTag(Title $title, $revision, $fuzzy)
static disallowLangTranslations(Title $title, User $user, $action, &$result)
Prevent translations to non-translatable languages for the group Hook: getUserPermissionsErrorsExpens...
static checkNeedsFuzzy(MessageHandle $handle, $text)
Returns true if message is fuzzy, OR fails checks OR fails validations (error OR warning).
static onSaveComplete(WikiPage $wikiPage, UserIdentity $userIdentity, string $summary, int $flags, RevisionRecord $revisionRecord, EditResult $editResult)
Runs message checks, adds tp:transver tags and updates statistics.
static disablePreSaveTransform(WikiPage $wikiPage, ParserOptions $popts)
Hook: ArticlePrepareTextForEdit.