Movatterモバイル変換


[0]ホーム

URL:


MediaWiki master
SpecialMyLanguage.php
Go to the documentation of this file.
1<?php
7namespaceMediaWiki\Specials;
8
9use MediaWiki\Languages\LanguageNameUtils;
10useMediaWiki\Page\RedirectLookup;
11useMediaWiki\SpecialPage\RedirectSpecialArticle;
12useMediaWiki\Title\Title;
13
25classSpecialMyLanguageextendsRedirectSpecialArticle {
26
27private LanguageNameUtils $languageNameUtils;
28privateRedirectLookup $redirectLookup;
29
30publicfunction__construct(
31 LanguageNameUtils $languageNameUtils,
32RedirectLookup $redirectLookup
33 ) {
34 parent::__construct('MyLanguage' );
35 $this->languageNameUtils = $languageNameUtils;
36 $this->redirectLookup = $redirectLookup;
37 }
38
46publicfunctiongetRedirect( $subpage ) {
47 $title = $this->findTitle( $subpage );
48// Go to the main page if given invalid title.
49if ( !$title ) {
50 $title = Title::newMainPage();
51 }
52return $title;
53 }
54
70publicfunctionfindTitle( $subpage ) {
71return $this->findTitleInternal( $subpage,false );
72 }
73
88publicfunctionfindTitleForTransclusion( $subpage ) {
89return $this->findTitleInternal( $subpage,true );
90 }
91
100privatefunction findTitleInternal( $subpage, $forTransclusion ) {
101// base = title without the language code suffix
102// provided = the title as it was given
103 $base = $provided =null;
104if ( $subpage !==null ) {
105 $provided = Title::newFromText( $subpage );
106 $base = $provided;
107
108if ( $provided && str_contains( $subpage,'/' ) ) {
109 $pos = strrpos( $subpage,'/' );
110 $basepage = substr( $subpage, 0, $pos );
111 $code = substr( $subpage, $pos + 1 );
112if ( $code !=='' && $this->languageNameUtils->isKnownLanguageTag( $code ) ) {
113 $base = Title::newFromText( $basepage );
114 }
115 }
116 }
117
118if ( !$base || !$base->canExist() ) {
119// No subpage provided or base page does not exist
120returnnull;
121 }
122
123 $fragment ='';
124if ( $base->isRedirect() ) {
125 $target = $this->redirectLookup->getRedirectTarget( $base );
126if ( $target !==null ) {
127 $base = Title::newFromLinkTarget( $target );
128// Preserve the fragment from the redirect target
129 $fragment = $base->getFragment();
130 }
131 }
132
133 $uiLang = $this->getLanguage();
134 $baseLang = $base->getPageLanguage();
135
136// T309329: Always use subpages for transclusion
137if ( !$forTransclusion && $baseLang->equals( $uiLang ) ) {
138// Short circuit when the current UI language is the
139// page's content language to avoid unnecessary page lookups.
140return $base;
141 }
142
143// Check for a subpage in the current UI language
144 $proposed = $base->getSubpage( $uiLang->getCode() );
145if ( $proposed && $proposed->exists() ) {
146if ( $fragment !=='' ) {
147 $proposed->setFragment( $fragment );
148 }
149return $proposed;
150 }
151
152// Explicit language code given and the page exists
153if ( $provided !== $base && $provided->exists() ) {
154// Not based on the redirect target, don't need the fragment
155return $provided;
156 }
157
158// Check for fallback languages specified by the UI language
159 $possibilities = $uiLang->getFallbackLanguages();
160foreach ( $possibilities as $lang ) {
161// $base already include fragments
162// T309329: Always use subpages for transclusion
163// T333187: Do not ignore base language page if matched
164if ( !$forTransclusion && $lang === $baseLang->getCode() ) {
165return $base;
166 }
167// Look for subpages if is for transclusion or didn't match base page language
168 $proposed = $base->getSubpage( $lang );
169if ( $proposed && $proposed->exists() ) {
170if ( $fragment !=='' ) {
171 $proposed->setFragment( $fragment );
172 }
173return $proposed;
174 }
175 }
176
177// When all else has failed, return the base page
178return $base;
179 }
180
189returntrue;
190 }
191}
192
197class_alias( SpecialMyLanguage::class,'SpecialMyLanguage' );
MediaWiki\SpecialPage\RedirectSpecialArticle
Helper for any RedirectSpecialPage which redirects the user to a particular article (as opposed to us...
DefinitionRedirectSpecialArticle.php:80
MediaWiki\SpecialPage\SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
DefinitionSpecialPage.php:914
MediaWiki\Specials\SpecialMyLanguage
Redirect to the appropriate translated version of a page if it exists.
DefinitionSpecialMyLanguage.php:25
MediaWiki\Specials\SpecialMyLanguage\findTitleForTransclusion
findTitleForTransclusion( $subpage)
Find a title for transclusion.
DefinitionSpecialMyLanguage.php:88
MediaWiki\Specials\SpecialMyLanguage\personallyIdentifiableTarget
personallyIdentifiableTarget()
Target can identify a specific user's language preference.
DefinitionSpecialMyLanguage.php:188
MediaWiki\Specials\SpecialMyLanguage\__construct
__construct(LanguageNameUtils $languageNameUtils, RedirectLookup $redirectLookup)
DefinitionSpecialMyLanguage.php:30
MediaWiki\Specials\SpecialMyLanguage\findTitle
findTitle( $subpage)
Find a title.
DefinitionSpecialMyLanguage.php:70
MediaWiki\Specials\SpecialMyLanguage\getRedirect
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.
DefinitionSpecialMyLanguage.php:46
MediaWiki\Title\Title
Represents a title within MediaWiki.
DefinitionTitle.php:69
MediaWiki\Page\RedirectLookup
Service for resolving a wiki page redirect.
DefinitionRedirectLookup.php:20
MediaWiki\Specials

[8]ページ先頭

©2009-2025 Movatter.jp