24 $this->errors = $errors;
25 $this->warnings = $warnings;
28 public function hasIssues():
bool {
29 return $this->hasWarnings() || $this->hasErrors();
34 $issues->merge( $this->errors );
35 $issues->merge( $this->warnings );
39 public function hasWarnings():
bool {
40 return $this->warnings->hasIssues();
43 public function hasErrors():
bool {
44 return $this->errors->hasIssues();
48 return $this->warnings;
55 public function getDescriptiveWarnings( IContextSource $context ): array {
56 return $this->expandMessages( $context, $this->warnings );
59 public function getDescriptiveErrors( IContextSource $context ): array {
60 return $this->expandMessages( $context, $this->errors );
63 private function expandMessages( IContextSource $context,
ValidationIssues $issues ): array {
64 $expandMessage =
function (
ValidationIssue $issue ) use ( $context ):
string {
65 $params = $this->fixMessageParams( $context, $issue->messageParams() );
66 return $context->msg( $issue->messageKey() )->params( $params )->parse();
69 return array_map( $expandMessage, iterator_to_array( $issues ) );
72 private function fixMessageParams( IContextSource $context, array $params ): array {
74 $lang = $context->getLanguage();
76 foreach ( $params as $param ) {
77 if ( !is_array( $param ) ) {
80 [ $type, $value ] = $param;
81 if ( $type ===
'COUNT' ) {
82 $out[] = $lang->formatNum( $value );
83 } elseif ( $type ===
'PARAMS' ) {
84 $out[] = $lang->commaList( $value );
85 } elseif ( $type ===
'PLAIN-PARAMS' ) {
86 $value = array_map(
'wfEscapeWikiText', $value );
87 $out[] = $lang->commaList( $value );
88 } elseif ( $type ===
'PLAIN' ) {
89 $out[] = wfEscapeWikiText( $value );
90 } elseif ( $type ===
'MESSAGE' ) {
91 $messageKey = array_shift( $value );
92 $messageParams = $this->fixMessageParams( $context, $value );
93 $out[] = $context->msg( $messageKey )->params( $messageParams );
95 throw new InvalidArgumentException(
"Unknown type $type" );