MediaWiki  REL1_31
LanguageCode.php
Go to the documentation of this file.
1 <?php
29 class LanguageCode {
38  private static $deprecatedLanguageCodeMapping = [
39  // Note that als is actually a valid ISO 639 code (Tosk Albanian), but it
40  // was previously used in MediaWiki for Alsatian, which comes under gsw
41  'als' => 'gsw',
42  'bat-smg' => 'sgs',
43  'be-x-old' => 'be-tarask',
44  'fiu-vro' => 'vro',
45  'roa-rup' => 'rup',
46  'zh-classical' => 'lzh',
47  'zh-min-nan' => 'nan',
48  'zh-yue' => 'yue',
49  ];
50 
63  public static function getDeprecatedCodeMapping() {
65  }
66 
77  public static function replaceDeprecatedCodes( $code ) {
78  if ( isset( self::$deprecatedLanguageCodeMapping[$code] ) ) {
79  return self::$deprecatedLanguageCodeMapping[$code];
80  }
81  return $code;
82  }
83 
94  public static function bcp47( $code ) {
95  $codeSegment = explode( '-', $code );
96  $codeBCP = [];
97  foreach ( $codeSegment as $segNo => $seg ) {
98  // when previous segment is x, it is a private segment and should be lc
99  if ( $segNo > 0 && strtolower( $codeSegment[( $segNo - 1 )] ) == 'x' ) {
100  $codeBCP[$segNo] = strtolower( $seg );
101  // ISO 3166 country code
102  } elseif ( ( strlen( $seg ) == 2 ) && ( $segNo > 0 ) ) {
103  $codeBCP[$segNo] = strtoupper( $seg );
104  // ISO 15924 script code
105  } elseif ( ( strlen( $seg ) == 4 ) && ( $segNo > 0 ) ) {
106  $codeBCP[$segNo] = ucfirst( strtolower( $seg ) );
107  // Use lowercase for other cases
108  } else {
109  $codeBCP[$segNo] = strtolower( $seg );
110  }
111  }
112  $langCode = implode( '-', $codeBCP );
113  return $langCode;
114  }
115 }
LanguageCode\replaceDeprecatedCodes
static replaceDeprecatedCodes( $code)
Replace deprecated language codes that were used in previous versions of MediaWiki to up-to-date,...
Definition: LanguageCode.php:77
LanguageCode\getDeprecatedCodeMapping
static getDeprecatedCodeMapping()
Returns a mapping of deprecated language codes that were used in previous versions of MediaWiki to up...
Definition: LanguageCode.php:63
array
the array() calling protocol came about after MediaWiki 1.4rc1.
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
$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
LanguageCode\$deprecatedLanguageCodeMapping
static array $deprecatedLanguageCodeMapping
Mapping of deprecated language codes that were used in previous versions of MediaWiki to up-to-date,...
Definition: LanguageCode.php:38
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
LanguageCode\bcp47
static bcp47( $code)
Get the normalised IETF language tag See unit test for examples.
Definition: LanguageCode.php:94
LanguageCode
Methods for dealing with language codes.
Definition: LanguageCode.php:29