Converts errors in data-mw to objects

Change-Id: I14930937c1beca039484cffd19e486cd06cbc124
This commit is contained in:
Isabelle Hurbain-Palatin 2024-09-20 17:59:44 +02:00
parent bc8407e824
commit 3a9ba45a7d
2 changed files with 16 additions and 15 deletions

View file

@ -140,7 +140,7 @@ class References extends ExtensionTagHandler {
$refsData->inReferencesContent() &&
$groupName !== $refsData->referencesGroup
) {
$errs[] = [ 'key' => 'cite_error_references_group_mismatch',
$errs[] = (object)[ 'key' => 'cite_error_references_group_mismatch',
'params' => [ $refDmw->attrs->group ] ];
}
@ -179,7 +179,7 @@ class References extends ExtensionTagHandler {
if ( $hasRefName ) {
if ( $hasFollow ) {
// Presumably, "name" has higher precedence
$errs[] = [ 'key' => 'cite_error_ref_follow_conflicts' ];
$errs[] = (object)[ 'key' => 'cite_error_ref_follow_conflicts' ];
}
if ( isset( $group->indexByName[$refName] ) ) {
$ref = $group->indexByName[$refName];
@ -201,7 +201,7 @@ class References extends ExtensionTagHandler {
}
} else {
if ( $refsData->inReferencesContent() ) {
$errs[] = [
$errs[] = (object)[
'key' => 'cite_error_references_missing_key',
'params' => [ $refDmw->attrs->name ]
];
@ -220,11 +220,11 @@ class References extends ExtensionTagHandler {
// section and it's the $followName we care about, but the
// extension to the legacy parser doesn't have an
// equivalent key and just outputs something wacky.
$errs[] = [ 'key' => 'cite_error_references_missing_key',
$errs[] = (object)[ 'key' => 'cite_error_references_missing_key',
'params' => [ $refDmw->attrs->follow ] ];
}
} elseif ( $refsData->inReferencesContent() ) {
$errs[] = [ 'key' => 'cite_error_references_no_key' ];
$errs[] = (object)[ 'key' => 'cite_error_references_no_key' ];
}
}
@ -283,9 +283,9 @@ class References extends ExtensionTagHandler {
if ( isset( $refDmw->attrs->dir ) ) {
if ( $refDir !== 'rtl' && $refDir !== 'ltr' ) {
$errs[] = [ 'key' => 'cite_error_ref_invalid_dir', 'params' => [ $refDir ] ];
$errs[] = (object)[ 'key' => 'cite_error_ref_invalid_dir', 'params' => [ $refDir ] ];
} elseif ( $ref->dir !== '' && $ref->dir !== $refDir ) {
$errs[] = [ 'key' => 'cite_error_ref_conflicting_dir', 'params' => [ $ref->name ] ];
$errs[] = (object)[ 'key' => 'cite_error_ref_conflicting_dir', 'params' => [ $ref->name ] ];
}
}
@ -293,7 +293,7 @@ class References extends ExtensionTagHandler {
// supports numerals as a name without it being an actual error, but core Cite does not.
// Follow refs do not duplicate the error which can be correlated with the original ref.
if ( ctype_digit( $refName ) ) {
$errs[] = [ 'key' => 'cite_error_ref_numeric_key' ];
$errs[] = (object)[ 'key' => 'cite_error_ref_numeric_key' ];
}
// Check for missing content, added ?? '' to fix T259676 crasher
@ -307,13 +307,13 @@ class References extends ExtensionTagHandler {
// is an error. It's possible that no name is present (!hasRefName), which also
// gets the error "cite_error_references_no_key" above, so protect against that.
if ( $refsData->inReferencesContent() ) {
$errs[] = [ 'key' => 'cite_error_empty_references_define',
$errs[] = (object)[ 'key' => 'cite_error_empty_references_define',
'params' => [ $refDmw->attrs->name ?? '', $refDmw->attrs->group ?? '' ] ];
} elseif ( !$hasRefName ) {
if ( !empty( $cDp->selfClose ) ) {
$errs[] = [ 'key' => 'cite_error_ref_no_key' ];
$errs[] = (object)[ 'key' => 'cite_error_ref_no_key' ];
} else {
$errs[] = [ 'key' => 'cite_error_ref_no_input' ];
$errs[] = (object)[ 'key' => 'cite_error_ref_no_input' ];
}
}
@ -334,7 +334,7 @@ class References extends ExtensionTagHandler {
if ( $contentDiffers ) {
// TODO: Since this error is being placed on the ref, the
// key should arguably be "cite_error_ref_duplicate_key"
$errs[] = [
$errs[] = (object)[
'key' => 'cite_error_references_duplicate_key',
'params' => [ $refDmw->attrs->name ]
];
@ -482,14 +482,14 @@ class References extends ExtensionTagHandler {
$errs = [];
// Mark all refs that are part of a group that is autogenerated
if ( $autoGeneratedWithGroup ) {
$errs[] = [ 'key' => 'cite_error_group_refs_without_references',
$errs[] = (object)[ 'key' => 'cite_error_group_refs_without_references',
'params' => [ $group ] ];
}
// Mark all refs that are named without content
if ( ( $ref->name !== '' ) && $ref->contentId === null ) {
// TODO: Since this error is being placed on the ref,
// the key should arguably be "cite_error_ref_no_text"
$errs[] = [
$errs[] = (object)[
'key' => 'cite_error_references_no_text',
'params' => [ $ref->name ]
];

View file

@ -3,6 +3,7 @@ declare( strict_types = 1 );
namespace Cite\Parsoid;
use stdClass;
use Wikimedia\Parsoid\Core\Sanitizer;
use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI;
@ -14,7 +15,7 @@ class ReferencesData {
private int $index = 0;
/** @var array<string,RefGroup> indexed by group name */
private array $refGroups = [];
/** @var array<string,array[]> */
/** @var array<string,stdClass[]> */
public array $embeddedErrors = [];
/** @var string[] */
private array $inEmbeddedContent = [];