Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7410287
MessageBundleMessageGroupFactory.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
MessageBundleMessageGroupFactory.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\MessageBundleTranslation
;
use
MainConfigDependency
;
use
MediaWiki\Config\ServiceOptions
;
use
MediaWiki\Extension\Translate\MessageGroupProcessing\CachedMessageGroupFactory
;
use
MediaWiki\Extension\Translate\MessageGroupProcessing\RevTagStore
;
use
MediaWiki\Extension\Translate\MessageProcessing\MessageGroupMetadata
;
use
MediaWiki\Title\Title
;
use
Wikimedia\Rdbms\IReadableDatabase
;
/**
* @since 2024.05
* @author Niklas Laxström
* @copyright GPL-2.0-or-later
*/
class
MessageBundleMessageGroupFactory
implements
CachedMessageGroupFactory
{
public
const
SERVICE_OPTIONS
=
[
'TranslateEnableMessageBundleIntegration'
];
private
MessageGroupMetadata
$messageGroupMetadata
;
private
bool
$enableIntegration
;
public
function
__construct
(
MessageGroupMetadata
$messageGroupMetadata
,
ServiceOptions
$options
)
{
$this
->
messageGroupMetadata
=
$messageGroupMetadata
;
$options
->
assertRequiredOptions
(
self
::
SERVICE_OPTIONS
);
$this
->
enableIntegration
=
$options
->
get
(
'TranslateEnableMessageBundleIntegration'
);
}
public
function
getCacheKey
():
string
{
return
'message-bundles'
;
}
public
function
getCacheVersion
():
int
{
return
1
;
}
public
function
getDependencies
():
array
{
return
[
new
MainConfigDependency
(
'TranslateEnableMessageBundleIntegration'
)
];
}
/** @inheritDoc */
public
function
getData
(
IReadableDatabase
$db
)
{
if
(
!
$this
->
enableIntegration
)
{
return
[];
}
$cacheData
=
[];
$res
=
$db
->
newSelectQueryBuilder
()
->
select
(
[
'page_id'
,
'page_namespace'
,
'page_title'
,
'rt_revision'
=>
'MAX(rt_revision)'
]
)
->
from
(
'page'
)
->
join
(
'revtag'
,
null
,
[
'page_id=rt_page'
,
'rt_type'
=>
RevTagStore
::
MB_VALID_TAG
]
)
->
groupBy
(
[
'page_id'
,
'page_namespace'
,
'page_title'
]
)
->
caller
(
__METHOD__
)
->
fetchResultSet
();
foreach
(
$res
as
$r
)
{
$title
=
Title
::
newFromRow
(
$r
);
$cacheData
[]
=
[
$title
->
getPrefixedText
(),
(
int
)
$r
->
page_id
,
(
int
)
$r
->
rt_revision
,
];
}
return
$cacheData
;
}
/** @inheritDoc */
public
function
createGroups
(
$data
):
array
{
$groups
=
[];
$groupIds
=
[];
// First get all the group ids
foreach
(
$data
as
$conf
)
{
$groupIds
[]
=
MessageBundleMessageGroup
::
getGroupId
(
$conf
[
0
]
);
}
// Preload all the metadata
$this
->
messageGroupMetadata
->
preloadGroups
(
$groupIds
,
__METHOD__
);
// Loop over all the group ids and create the MessageBundleMessageGroup
foreach
(
$groupIds
as
$index
=>
$groupId
)
{
$conf
=
$data
[
$index
];
$description
=
$this
->
messageGroupMetadata
->
getWithDefaultValue
(
$groupId
,
'description'
,
null
);
$label
=
$this
->
messageGroupMetadata
->
getWithDefaultValue
(
$groupId
,
'label'
,
null
);
$groups
[
$groupId
]
=
new
MessageBundleMessageGroup
(
$groupId
,
$conf
[
0
],
$conf
[
1
],
$conf
[
2
],
$description
,
$label
);
}
return
$groups
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 21, 22:54 (1 d, 23 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f2/c6/4a8cf0a38b98f71899757f7cfa5b
Default Alt Text
MessageBundleMessageGroupFactory.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment