MediaWiki  1.30.2
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  return null;
85  }
86 
87  if ( $base->isRedirect() ) {
88  $page = new WikiPage( $base );
89  $base = $page->getRedirectTarget();
90  }
91 
92  $uiCode = $this->getLanguage()->getCode();
93  $proposed = $base->getSubpage( $uiCode );
94  if ( $proposed && $proposed->exists() && $uiCode !== $base->getPageLanguage()->getCode() ) {
95  return $proposed;
96  } elseif ( $provided && $provided->exists() ) {
97  return $provided;
98  } else {
99  return $base;
100  }
101  }
102 
110  public function personallyIdentifiableTarget() {
111  return true;
112  }
113 }
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:268
Title\newMainPage
static newMainPage()
Create a new Title for the Main Page.
Definition: Title.php:581
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:37
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:751
$base
$base
Definition: generateLocalAutoload.php:10
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:35
Language\isKnownLanguageTag
static isKnownLanguageTag( $tag)
Returns true if a language code is an IETF tag known to MediaWiki.
Definition: Language.php:385
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:932
SpecialMyLanguage\findTitle
findTitle( $subpage)
Assuming the user's interface language is fi.
Definition: SpecialMyLanguage.php:65
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:110
$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:781
SpecialMyLanguage
Unlisted special page just to redirect the user to the translated version of a page,...
Definition: SpecialMyLanguage.php:35