12use MediaWiki\Linker\LinkTarget;
13use MediaWiki\Logger\LoggerFactory;
14use MediaWiki\MediaWikiServices;
30 public function __construct( LinkTarget $title ) {
31 $this->title = $title;
39 global $wgTranslateMessageNamespaces;
40 $namespace = $this->title->getNamespace();
42 return in_array( $namespace, $wgTranslateMessageNamespaces );
50 if ( $this->key ===
null ) {
52 $this->key = $this->title->getDBkey();
53 $known = MessageIndex::singleton()->getGroupIds( $this ) !== [];
55 $pos = strrpos( $this->key,
'/' );
56 if ( $known || $pos ===
false ) {
60 $this->code = (string)( substr( $this->key, $pos + 1 ) );
61 $this->key = substr( $this->key, 0, $pos );
65 return [ $this->key, $this->code ];
97 $mwInstance = MediaWikiServices::getInstance();
98 if ( !$mwInstance->getLanguageNameUtils()->isKnownLanguageTag( $code ) ||
101 return $mwInstance->getContentLanguage();
104 return $mwInstance->getLanguageFactory()->getLanguage( $code );
112 global $wgTranslateDocumentationLanguageCode;
114 return $this->
getCode() === $wgTranslateDocumentationLanguageCode;
123 return $this->title->inNamespace( NS_TRANSLATIONS );
134 if ( $this->groupIds ===
null ) {
135 $this->groupIds = MessageIndex::singleton()->getGroupIds( $this );
138 return $this->groupIds;
149 if ( !isset( $ids[0] ) ) {
150 throw new MWException(
'called before isValid' );
153 return MessageGroups::getGroup( $ids[0] );
174 $logger = LoggerFactory::getInstance(
'Translate' );
176 '[MessageHandle] MessageIndex is out of date. Page {pagename} refers to ' .
177 'unknown group {messagegroup}',
179 'pagename' => $this->
getTitle()->getPrefixedText(),
180 'messagegroup' => $groups[0],
185 $job = MessageIndexRebuildJob::newJob();
186 MediaWikiServices::getInstance()->getJobQueueGroup()->push( $job );
199 return Title::newFromLinkTarget( $this->title );
209 return Title::makeTitle(
210 $this->title->getNamespace(),
211 $this->getKey() .
"/$code"
221 return Title::makeTitle(
222 $this->title->getNamespace(),
234 return strpos( $text, TRANSLATE_FUZZY ) !==
false;
242 $dbr = wfGetDB( DB_REPLICA );
244 $tables = [
'page',
'revtag' ];
247 'page_namespace' => $this->title->getNamespace(),
248 'page_title' => $this->title->getDBkey(),
249 'rt_type' => RevTagStore::FUZZY_TAG,
251 'page_latest=rt_revision'
254 $res = $dbr->selectField( $tables, $field, $conds, __METHOD__ );
256 return $res !==
false;
267 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
268 $contentLanguage = MediaWikiServices::getInstance()->getContentLanguage();
272 $groupKeys = $group->getKeys();
274 if ( in_array( $key, $groupKeys,
true ) ) {
278 $namespace = $this->title->getNamespace();
279 if ( $nsInfo->isCapitalized( $namespace ) ) {
280 $lowercaseKey = $contentLanguage->lcfirst( $key );
281 if ( in_array( $lowercaseKey, $groupKeys,
true ) ) {
282 return $lowercaseKey;
288 foreach ( $groupKeys as $haystackKey ) {
289 $normalizedHaystackKey = Title::makeTitleSafe( $namespace, $haystackKey )->getDBkey();
290 if ( $normalizedHaystackKey === $key ) {
Class for pointing to messages, like Title class is for titles.
isFuzzy()
Check if a title is marked as fuzzy.
isPageTranslation()
Determine whether the current handle is for page translation feature.
static hasFuzzyString( $text)
Check if a string contains the fuzzy string.
figureMessage()
Recommended to use getCode and getKey instead.
isDoc()
Determine whether the current handle is for message documentation.
getGroup()
Get the primary MessageGroup this message belongs to.
getTitleForLanguage( $code)
Get the original title.
isValid()
Checks if the handle corresponds to a known message.
getEffectiveLanguage()
Return the Language object for the assumed language of the content, which might be different from the...
getGroupIds()
Returns all message group ids this message belongs to.
getTitle()
Get the original title.
isMessageNamespace()
Check if this handle is in a message namespace.
getCode()
Returns the language code.
getTitleForBase()
Get the title for the page base.
getInternalKey()
This returns the key that can be used for showMessage parameter for Special:Translate for regular mes...
getKey()
Returns the identified or guessed message key.