MediaWiki REL1_31
SpecialMyLanguage.php
Go to the documentation of this file.
1<?php
36 public function __construct() {
37 parent::__construct( 'MyLanguage' );
38 }
39
47 public function getRedirect( $subpage ) {
48 $title = $this->findTitle( $subpage );
49 // Go to the main page if given invalid title.
50 if ( !$title ) {
51 $title = Title::newMainPage();
52 }
53 return $title;
54 }
55
65 public function findTitle( $subpage ) {
66 // base = title without language code suffix
67 // provided = the title as it was given
68 $base = $provided = null;
69 if ( $subpage !== null ) {
70 $provided = Title::newFromText( $subpage );
71 $base = $provided;
72 }
73
74 if ( $provided && strpos( $subpage, '/' ) !== false ) {
75 $pos = strrpos( $subpage, '/' );
76 $basepage = substr( $subpage, 0, $pos );
77 $code = substr( $subpage, $pos + 1 );
78 if ( strlen( $code ) && Language::isKnownLanguageTag( $code ) ) {
79 $base = Title::newFromText( $basepage );
80 }
81 }
82
83 if ( !$base ) {
84 // No subpage provided or base page does not exist
85 return null;
86 }
87
88 if ( $base->isRedirect() ) {
89 $page = new WikiPage( $base );
90 $base = $page->getRedirectTarget();
91 }
92
93 $uiCode = $this->getLanguage()->getCode();
94 $wikiLangCode = $this->getConfig()->get( 'LanguageCode' );
95
96 if ( $uiCode === $wikiLangCode ) {
97 // Short circuit when the current UI language is the
98 // wiki's default language to avoid unnecessary page lookups.
99 return $base;
100 }
101
102 // Check for a subpage in current UI language
103 $proposed = $base->getSubpage( $uiCode );
104 if ( $proposed && $proposed->exists() ) {
105 return $proposed;
106 }
107
108 if ( $provided !== $base && $provided->exists() ) {
109 // Explicit language code given and the page exists
110 return $provided;
111 }
112
113 // Check for fallback languages specified by the UI language
114 $possibilities = Language::getFallbacksFor( $uiCode );
115 foreach ( $possibilities as $lang ) {
116 if ( $lang !== $wikiLangCode ) {
117 $proposed = $base->getSubpage( $lang );
118 if ( $proposed && $proposed->exists() ) {
119 return $proposed;
120 }
121 }
122 }
123
124 // When all else has failed, return the base page
125 return $base;
126 }
127
136 return true;
137 }
138}
Superclass for any RedirectSpecialPage which redirects the user to a particular article (as opposed t...
Unlisted special page just to redirect the user to the translated version of a page,...
findTitle( $subpage)
Assuming the user's interface language is fi.
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.
personallyIdentifiableTarget()
Target can identify a specific user's language preference.
getConfig()
Shortcut to get main config object.
getLanguage()
Shortcut to get user's language.
Class representing a MediaWiki article and history.
Definition WikiPage.php:37
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition hooks.txt:865
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:964
if(!isset( $args[0])) $lang