Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1427049
QueryMessageTranslationsActionApi.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
QueryMessageTranslationsActionApi.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\MessageLoading
;
use
ApiBase
;
use
ApiQuery
;
use
ApiQueryBase
;
use
ApiResult
;
use
MediaWiki\Extension\Translate\Utilities\Utilities
;
use
MediaWiki\Title\Title
;
use
Wikimedia\ParamValidator\ParamValidator
;
/**
* Api module for querying message translations.
* @author Niklas Laxström
* @license GPL-2.0-or-later
* @ingroup API TranslateAPI
*/
class
QueryMessageTranslationsActionApi
extends
ApiQueryBase
{
public
function
__construct
(
ApiQuery
$query
,
string
$moduleName
)
{
parent
::
__construct
(
$query
,
$moduleName
,
'mt'
);
}
public
function
getCacheMode
(
$params
)
{
return
'public'
;
}
public
function
execute
():
void
{
$params
=
$this
->
extractRequestParams
();
$title
=
Title
::
newFromText
(
$params
[
'title'
]
);
if
(
!
$title
)
{
$this
->
dieWithError
(
[
'apierror-invalidtitle'
,
wfEscapeWikiText
(
$params
[
'title'
]
)
]
);
}
$handle
=
new
MessageHandle
(
$title
);
if
(
!
$handle
->
isValid
()
)
{
$this
->
dieWithError
(
'apierror-translate-nomessagefortitle'
,
'nomessagefortitle'
);
}
$namespace
=
$title
->
getNamespace
();
$pageInfo
=
Utilities
::
getTranslations
(
$handle
);
$result
=
$this
->
getResult
();
$count
=
0
;
foreach
(
$pageInfo
as
$key
=>
$info
)
{
if
(
++
$count
<=
$params
[
'offset'
]
)
{
continue
;
}
$tTitle
=
Title
::
makeTitle
(
$namespace
,
$key
);
$tHandle
=
new
MessageHandle
(
$tTitle
);
$data
=
[
'title'
=>
$tTitle
->
getPrefixedText
(),
'language'
=>
$tHandle
->
getCode
(),
'lasttranslator'
=>
$info
[
1
],
];
$fuzzy
=
MessageHandle
::
hasFuzzyString
(
$info
[
0
]
)
||
$tHandle
->
isFuzzy
();
if
(
$fuzzy
)
{
$data
[
'fuzzy'
]
=
'fuzzy'
;
}
$translation
=
str_replace
(
TRANSLATE_FUZZY
,
''
,
$info
[
0
]
);
ApiResult
::
setContentValue
(
$data
,
'translation'
,
$translation
);
$fit
=
$result
->
addValue
(
[
'query'
,
$this
->
getModuleName
()
],
null
,
$data
);
if
(
!
$fit
)
{
$this
->
setContinueEnumParameter
(
'offset'
,
$count
);
break
;
}
}
$result
->
addIndexedTagName
(
[
'query'
,
$this
->
getModuleName
()
],
'message'
);
}
protected
function
getAllowedParams
():
array
{
return
[
'title'
=>
[
ParamValidator
::
PARAM_TYPE
=>
'string'
,
ParamValidator
::
PARAM_REQUIRED
=>
true
,
],
'offset'
=>
[
ParamValidator
::
PARAM_DEFAULT
=>
0
,
ParamValidator
::
PARAM_TYPE
=>
'integer'
,
ApiBase
::
PARAM_HELP_MSG
=>
'api-help-param-continue'
,
],
];
}
protected
function
getExamplesMessages
():
array
{
return
[
'action=query&meta=messagetranslations&mttitle=MediaWiki:January'
=>
'apihelp-query+messagetranslations-example-1'
,
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 14:07 (1 d, 13 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
fa/fa/82fb6c812b9862dff36420bceca2
Default Alt Text
QueryMessageTranslationsActionApi.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment