Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7431247
DateFormatterConfig.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
DateFormatterConfig.php
View Options
<?php
namespace
MediaWiki\ResourceLoader
;
use
MediaWiki\Config\Config
;
use
MediaWiki\Language\Language
;
use
MediaWiki\Language\LanguageCode
;
use
MediaWiki\MainConfigNames
;
use
MediaWiki\MediaWikiServices
;
/**
* @internal
*/
class
DateFormatterConfig
extends
Module
{
/**
* Callback for mediawiki.DateFormatter/config.json
*
* @internal
* @param Context $context
* @param Config $config
* @return array
*/
public
static
function
getData
(
Context
$context
,
Config
$config
)
{
$lang
=
MediaWikiServices
::
getInstance
()->
getLanguageFactory
()
->
getLanguage
(
$context
->
getLanguage
()
);
return
self
::
getDataForLang
(
$lang
,
$config
);
}
/**
* Get configuration data for DateFormatter given parameters
*
* @internal
* @param Language $lang
* @param Config $config
* @return array
*/
public
static
function
getDataForLang
(
Language
$lang
,
Config
$config
)
{
$locales
=
[
$lang
->
getHtmlCode
()
];
$fallbacks
=
$lang
->
getFallbackLanguages
();
foreach
(
$fallbacks
as
$code
)
{
$locales
[]
=
LanguageCode
::
bcp47
(
$code
);
}
// Discover which fields are required
$formats
=
$lang
->
getJsDateFormats
();
$haveField
=
[];
foreach
(
$formats
as
$format
)
{
$pattern
=
$format
[
'pattern'
]
??
''
;
foreach
(
[
'mwMonth'
,
'mwMonthGen'
,
'mwMonthAbbrev'
]
as
$field
)
{
if
(
str_contains
(
$pattern
,
"{$field}"
)
)
{
$haveField
[
$field
]
=
true
;
}
}
}
// Include only the required month data
if
(
$haveField
)
{
$months
=
[
[]
];
for
(
$i
=
1
;
$i
<=
12
;
$i
++
)
{
$data
=
[
isset
(
$haveField
[
'mwMonth'
]
)
?
$lang
->
getMonthName
(
$i
)
:
''
,
isset
(
$haveField
[
'mwMonthGen'
]
)
?
$lang
->
getMonthNameGen
(
$i
)
:
''
,
isset
(
$haveField
[
'mwMonthAbbrev'
]
)
?
$lang
->
getMonthAbbreviation
(
$i
)
:
''
];
// Trim the end of the array
while
(
end
(
$data
)
===
''
)
{
unset
(
$data
[
array_key_last
(
$data
)
]
);
}
$months
[]
=
$data
;
}
}
else
{
$months
=
[];
}
return
[
'locales'
=>
$locales
,
'formats'
=>
$formats
,
'defaultStyle'
=>
$lang
->
getDefaultDateFormat
(),
'localZone'
=>
$config
->
get
(
MainConfigNames
::
Localtimezone
),
'localOffset'
=>
(
int
)
$config
->
get
(
MainConfigNames
::
LocalTZoffset
),
'months'
=>
$months
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 10:51 (8 h, 21 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
c9/07/b0e1aaa79d271aa36368030c02be
Default Alt Text
DateFormatterConfig.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment