11use MediaWiki\Linker\LinkTarget;
12use MediaWiki\Logger\LoggerFactory;
13use MediaWiki\MediaWikiServices;
29 public function __construct( LinkTarget $title ) {
30 $this->title = $title;
38 global $wgTranslateMessageNamespaces;
39 $namespace = $this->title->getNamespace();
41 return in_array( $namespace, $wgTranslateMessageNamespaces );
49 if ( $this->key ===
null ) {
51 $this->key = $this->title->getDBkey();
52 $known = MessageIndex::singleton()->getGroupIds( $this ) !== [];
54 $pos = strrpos( $this->key,
'/' );
55 if ( $known || $pos ===
false ) {
59 $this->code = (string)( substr( $this->key, $pos + 1 ) );
60 $this->key = substr( $this->key, 0, $pos );
64 return [ $this->key, $this->code ];
96 if ( $code ===
'' || $this->
isDoc() ) {
97 return MediaWikiServices::getInstance()->getContentLanguage();
100 return wfGetLangObj( $code );
108 global $wgTranslateDocumentationLanguageCode;
110 return $this->
getCode() === $wgTranslateDocumentationLanguageCode;
119 return $this->title->inNamespace( NS_TRANSLATIONS );
130 if ( $this->groupIds ===
null ) {
131 $this->groupIds = MessageIndex::singleton()->getGroupIds( $this );
134 return $this->groupIds;
145 if ( !isset( $ids[0] ) ) {
146 throw new MWException(
'called before isValid' );
149 return MessageGroups::getGroup( $ids[0] );
170 $logger = LoggerFactory::getInstance(
'Translate' );
172 '[MessageHandle] MessageIndex is out of date. Page {pagename} refers to ' .
173 'unknown group {messagegroup}',
175 'pagename' => $this->
getTitle()->getPrefixedText(),
176 'messagegroup' => $groups[0],
181 $job = MessageIndexRebuildJob::newJob();
182 MediaWikiServices::getInstance()->getJobQueueGroup()->push( $job );
195 return Title::newFromLinkTarget( $this->title );
205 return Title::makeTitle(
206 $this->title->getNamespace(),
207 $this->getKey() .
"/$code"
217 return Title::makeTitle(
218 $this->title->getNamespace(),
230 return strpos( $text, TRANSLATE_FUZZY ) !==
false;
238 $dbr = wfGetDB( DB_REPLICA );
240 $tables = [
'page',
'revtag' ];
243 'page_namespace' => $this->title->getNamespace(),
244 'page_title' => $this->title->getDBkey(),
245 'rt_type' => RevTagStore::FUZZY_TAG,
247 'page_latest=rt_revision'
250 $res = $dbr->selectField( $tables, $field, $conds, __METHOD__ );
252 return $res !==
false;
263 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
264 $contentLanguage = MediaWikiServices::getInstance()->getContentLanguage();
268 $groupKeys = $group->getKeys();
270 if ( in_array( $key, $groupKeys,
true ) ) {
274 $namespace = $this->title->getNamespace();
275 if ( $nsInfo->isCapitalized( $namespace ) ) {
276 $lowercaseKey = $contentLanguage->lcfirst( $key );
277 if ( in_array( $lowercaseKey, $groupKeys,
true ) ) {
278 return $lowercaseKey;
284 foreach ( $groupKeys as $haystackKey ) {
285 $normalizedHaystackKey = Title::makeTitleSafe( $namespace, $haystackKey )->getDBkey();
286 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.