Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5974307
MessageBundleContentHandler.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
MessageBundleContentHandler.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\MessageBundleTranslation
;
use
Content
;
use
InvalidArgumentException
;
use
MediaWiki\Content\Renderer\ContentParseParams
;
use
MediaWiki\Content\ValidationParams
;
use
MediaWiki\Parser\ParserOutput
;
use
StatusValue
;
use
TextContentHandler
;
use
const
CONTENT_FORMAT_JSON
;
/**
* @author Niklas Laxström
* @license GPL-2.0-or-later
* @since 2021.05
*/
class
MessageBundleContentHandler
extends
TextContentHandler
{
public
function
__construct
(
$modelId
=
MessageBundleContent
::
CONTENT_MODEL_ID
)
{
parent
::
__construct
(
$modelId
,
[
CONTENT_FORMAT_JSON
]
);
}
protected
function
getContentClass
():
string
{
return
MessageBundleContent
::
class
;
}
public
function
makeEmptyContent
():
Content
{
$class
=
$this
->
getContentClass
();
return
new
$class
(
'{}'
);
}
public
function
validateSave
(
Content
$content
,
ValidationParams
$validationParams
)
{
// This will give an informative error message when trying to change the content model
try
{
if
(
$content
instanceof
MessageBundleContent
)
{
$content
->
validate
();
}
return
StatusValue
::
newGood
();
}
catch
(
MalformedBundle
$e
)
{
// XXX: We have no context source nor is there Message::messageParam :(
return
StatusValue
::
newFatal
(
'translate-messagebundle-validation-error'
,
wfMessage
(
$e
)
);
}
}
/** @inheritDoc */
protected
function
fillParserOutput
(
Content
$content
,
ContentParseParams
$cpoParams
,
ParserOutput
&
$parserOutput
)
{
if
(
!
$content
instanceof
MessageBundleContent
)
{
throw
new
InvalidArgumentException
(
'Expected $content to be MessageBundleContent; got: '
.
get_class
(
$content
)
);
}
$label
=
$content
->
getMetadata
()->
getLabel
();
if
(
$label
!==
null
)
{
$parserOutput
->
setDisplayTitle
(
$label
);
}
if
(
$cpoParams
->
getGenerateHtml
()
&&
$content
->
isValid
()
)
{
/** @param $content JsonContent::class */
$parserOutput
->
setRawText
(
$content
->
rootValueTable
(
$content
->
getData
()->
getValue
()
)
);
$parserOutput
->
addModuleStyles
(
[
'mediawiki.content.json'
]
);
}
else
{
$parserOutput
->
setRawText
(
null
);
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 17:17 (1 d, 13 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
9a/30/0d8e584771666d7c081c87931dc7
Default Alt Text
MessageBundleContentHandler.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment