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 ) {
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 
135  public function personallyIdentifiableTarget() {
136  return true;
137  }
138 }
Language\getFallbacksFor
static getFallbacksFor( $code)
Get the ordered list of fallback languages.
Definition: Language.php:4547
SpecialMyLanguage\getRedirect
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.
Definition: SpecialMyLanguage.php:47
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:273
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
Title\newMainPage
static newMainPage()
Create a new Title for the Main Page.
Definition: Title.php:586
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:37
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:752
$base
$base
Definition: generateLocalAutoload.php:11
php
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
Language\isKnownLanguageTag
static isKnownLanguageTag( $tag)
Returns true if a language code is an IETF tag known to MediaWiki.
Definition: Language.php:385
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:761
SpecialMyLanguage\findTitle
findTitle( $subpage)
Assuming the user's interface language is fi.
Definition: SpecialMyLanguage.php:65
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
SpecialMyLanguage\__construct
__construct()
Definition: SpecialMyLanguage.php:36
RedirectSpecialArticle
Superclass for any RedirectSpecialPage which redirects the user to a particular article (as opposed t...
Definition: RedirectSpecialPage.php:213
SpecialMyLanguage\personallyIdentifiableTarget
personallyIdentifiableTarget()
Target can identify a specific user's language preference.
Definition: SpecialMyLanguage.php:135
$code
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
as
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
Definition: distributors.txt:22
SpecialMyLanguage
Unlisted special page just to redirect the user to the translated version of a page,...
Definition: SpecialMyLanguage.php:35