52 parent::__construct(
'MyLanguage' );
53 $this->languageNameUtils = $languageNameUtils;
54 $this->redirectLookup = $redirectLookup;
68 $title = Title::newMainPage();
89 return $this->findTitleInternal( $subpage,
false );
107 return $this->findTitleInternal( $subpage,
true );
118 private function findTitleInternal( $subpage, $forTransclusion ) {
121 $base = $provided =
null;
122 if ( $subpage !==
null ) {
123 $provided = Title::newFromText( $subpage );
126 if ( $provided && str_contains( $subpage,
'/' ) ) {
127 $pos = strrpos( $subpage,
'/' );
128 $basepage = substr( $subpage, 0, $pos );
129 $code = substr( $subpage, $pos + 1 );
130 if ( strlen( $code ) && $this->languageNameUtils->isKnownLanguageTag( $code ) ) {
131 $base = Title::newFromText( $basepage );
136 if ( !$base || !$base->canExist() ) {
142 if ( $base->isRedirect() ) {
143 $target = $this->redirectLookup->getRedirectTarget( $base );
144 if ( $target !==
null ) {
145 $base = Title::newFromLinkTarget( $target );
147 $fragment = $base->getFragment();
152 $baseLang = $base->getPageLanguage();
155 if ( !$forTransclusion && $baseLang->equals( $uiLang ) ) {
162 $proposed = $base->getSubpage( $uiLang->getCode() );
163 if ( $proposed && $proposed->exists() ) {
164 if ( $fragment !==
'' ) {
165 $proposed->setFragment( $fragment );
171 if ( $provided !== $base && $provided->exists() ) {
177 $possibilities = $uiLang->getFallbackLanguages();
178 foreach ( $possibilities as $lang ) {
182 if ( !$forTransclusion && $lang === $baseLang->getCode() ) {
186 $proposed = $base->getSubpage( $lang );
187 if ( $proposed && $proposed->exists() ) {
188 if ( $fragment !==
'' ) {
189 $proposed->setFragment( $fragment );