Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1429783
ValidationResult.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
ValidationResult.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\Validation
;
use
InvalidArgumentException
;
use
MediaWiki\Context\IContextSource
;
/**
* Container for validation issues returned by MessageValidator.
*
* @author Abijeet Patro
* @author Niklas Laxström
* @license GPL-2.0-or-later
* @since 2020.06 (originally 2019.06)
*/
class
ValidationResult
{
/** @var ValidationIssues */
protected
$errors
;
/** @var ValidationIssues */
protected
$warnings
;
public
function
__construct
(
ValidationIssues
$errors
,
ValidationIssues
$warnings
)
{
$this
->
errors
=
$errors
;
$this
->
warnings
=
$warnings
;
}
public
function
hasIssues
():
bool
{
return
$this
->
hasWarnings
()
||
$this
->
hasErrors
();
}
public
function
getIssues
():
ValidationIssues
{
$issues
=
new
ValidationIssues
();
$issues
->
merge
(
$this
->
errors
);
$issues
->
merge
(
$this
->
warnings
);
return
$issues
;
}
public
function
hasWarnings
():
bool
{
return
$this
->
warnings
->
hasIssues
();
}
public
function
hasErrors
():
bool
{
return
$this
->
errors
->
hasIssues
();
}
public
function
getWarnings
():
ValidationIssues
{
return
$this
->
warnings
;
}
public
function
getErrors
():
ValidationIssues
{
return
$this
->
errors
;
}
public
function
getDescriptiveWarnings
(
IContextSource
$context
):
array
{
return
$this
->
expandMessages
(
$context
,
$this
->
warnings
);
}
public
function
getDescriptiveErrors
(
IContextSource
$context
):
array
{
return
$this
->
expandMessages
(
$context
,
$this
->
errors
);
}
private
function
expandMessages
(
IContextSource
$context
,
ValidationIssues
$issues
):
array
{
$expandMessage
=
function
(
ValidationIssue
$issue
)
use
(
$context
):
string
{
$params
=
$this
->
fixMessageParams
(
$context
,
$issue
->
messageParams
()
);
return
$context
->
msg
(
$issue
->
messageKey
()
)->
params
(
$params
)->
parse
();
};
return
array_map
(
$expandMessage
,
iterator_to_array
(
$issues
)
);
}
private
function
fixMessageParams
(
IContextSource
$context
,
array
$params
):
array
{
$out
=
[];
$lang
=
$context
->
getLanguage
();
foreach
(
$params
as
$param
)
{
if
(
!
is_array
(
$param
)
)
{
$out
[]
=
$param
;
}
else
{
[
$type
,
$value
]
=
$param
;
if
(
$type
===
'COUNT'
)
{
$out
[]
=
$lang
->
formatNum
(
$value
);
}
elseif
(
$type
===
'PARAMS'
)
{
$out
[]
=
$lang
->
commaList
(
$value
);
}
elseif
(
$type
===
'PLAIN-PARAMS'
)
{
$value
=
array_map
(
'wfEscapeWikiText'
,
$value
);
$out
[]
=
$lang
->
commaList
(
$value
);
}
elseif
(
$type
===
'PLAIN'
)
{
$out
[]
=
wfEscapeWikiText
(
$value
);
}
elseif
(
$type
===
'MESSAGE'
)
{
$messageKey
=
array_shift
(
$value
);
$messageParams
=
$this
->
fixMessageParams
(
$context
,
$value
);
$out
[]
=
$context
->
msg
(
$messageKey
)->
params
(
$messageParams
);
}
else
{
throw
new
InvalidArgumentException
(
"Unknown type $type"
);
}
}
}
return
$out
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 18:00 (9 h, 7 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
96/14/177fd8a960339b3692f6eab8331c
Default Alt Text
ValidationResult.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment