MediaWiki REL1_33
SpecialMyLanguage.php
Go to the documentation of this file.
1<?php
27
38 public function __construct() {
39 parent::__construct( 'MyLanguage' );
40 }
41
49 public function getRedirect( $subpage ) {
50 $title = $this->findTitle( $subpage );
51 // Go to the main page if given invalid title.
52 if ( !$title ) {
53 $title = Title::newMainPage();
54 }
55 return $title;
56 }
57
67 public function findTitle( $subpage ) {
68 // base = title without language code suffix
69 // provided = the title as it was given
70 $base = $provided = null;
71 if ( $subpage !== null ) {
72 $provided = Title::newFromText( $subpage );
73 $base = $provided;
74 }
75
76 if ( $provided && strpos( $subpage, '/' ) !== false ) {
77 $pos = strrpos( $subpage, '/' );
78 $basepage = substr( $subpage, 0, $pos );
79 $code = substr( $subpage, $pos + 1 );
80 if ( strlen( $code ) && Language::isKnownLanguageTag( $code ) ) {
81 $base = Title::newFromText( $basepage );
82 }
83 }
84
85 if ( !$base ) {
86 // No subpage provided or base page does not exist
87 return null;
88 }
89
90 if ( $base->isRedirect() ) {
91 $page = new WikiPage( $base );
92 $base = $page->getRedirectTarget();
93 }
94
95 $uiLang = $this->getLanguage();
96 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
97
98 if ( $uiLang->equals( $contLang ) ) {
99 // Short circuit when the current UI language is the
100 // wiki's default language to avoid unnecessary page lookups.
101 return $base;
102 }
103
104 // Check for a subpage in current UI language
105 $proposed = $base->getSubpage( $uiLang->getCode() );
106 if ( $proposed && $proposed->exists() ) {
107 return $proposed;
108 }
109
110 if ( $provided !== $base && $provided->exists() ) {
111 // Explicit language code given and the page exists
112 return $provided;
113 }
114
115 // Check for fallback languages specified by the UI language
116 $possibilities = $uiLang->getFallbackLanguages();
117 foreach ( $possibilities as $lang ) {
118 if ( $lang !== $contLang->getCode() ) {
119 $proposed = $base->getSubpage( $lang );
120 if ( $proposed && $proposed->exists() ) {
121 return $proposed;
122 }
123 }
124 }
125
126 // When all else has failed, return the base page
127 return $base;
128 }
129
138 return true;
139 }
140}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
MediaWikiServices is the service locator for the application scope of MediaWiki.
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.
getLanguage()
Shortcut to get user's language.
Class representing a MediaWiki article and history.
Definition WikiPage.php:45
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:955
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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:856
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
if(!isset( $args[0])) $lang