mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-27 16:30:12 +00:00
Converts errors in data-mw to objects
Change-Id: I14930937c1beca039484cffd19e486cd06cbc124
This commit is contained in:
parent
bc8407e824
commit
3a9ba45a7d
|
@ -140,7 +140,7 @@ class References extends ExtensionTagHandler {
|
||||||
$refsData->inReferencesContent() &&
|
$refsData->inReferencesContent() &&
|
||||||
$groupName !== $refsData->referencesGroup
|
$groupName !== $refsData->referencesGroup
|
||||||
) {
|
) {
|
||||||
$errs[] = [ 'key' => 'cite_error_references_group_mismatch',
|
$errs[] = (object)[ 'key' => 'cite_error_references_group_mismatch',
|
||||||
'params' => [ $refDmw->attrs->group ] ];
|
'params' => [ $refDmw->attrs->group ] ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ class References extends ExtensionTagHandler {
|
||||||
if ( $hasRefName ) {
|
if ( $hasRefName ) {
|
||||||
if ( $hasFollow ) {
|
if ( $hasFollow ) {
|
||||||
// Presumably, "name" has higher precedence
|
// 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] ) ) {
|
if ( isset( $group->indexByName[$refName] ) ) {
|
||||||
$ref = $group->indexByName[$refName];
|
$ref = $group->indexByName[$refName];
|
||||||
|
@ -201,7 +201,7 @@ class References extends ExtensionTagHandler {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ( $refsData->inReferencesContent() ) {
|
if ( $refsData->inReferencesContent() ) {
|
||||||
$errs[] = [
|
$errs[] = (object)[
|
||||||
'key' => 'cite_error_references_missing_key',
|
'key' => 'cite_error_references_missing_key',
|
||||||
'params' => [ $refDmw->attrs->name ]
|
'params' => [ $refDmw->attrs->name ]
|
||||||
];
|
];
|
||||||
|
@ -220,11 +220,11 @@ class References extends ExtensionTagHandler {
|
||||||
// section and it's the $followName we care about, but the
|
// section and it's the $followName we care about, but the
|
||||||
// extension to the legacy parser doesn't have an
|
// extension to the legacy parser doesn't have an
|
||||||
// equivalent key and just outputs something wacky.
|
// 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 ] ];
|
'params' => [ $refDmw->attrs->follow ] ];
|
||||||
}
|
}
|
||||||
} elseif ( $refsData->inReferencesContent() ) {
|
} 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 ( isset( $refDmw->attrs->dir ) ) {
|
||||||
if ( $refDir !== 'rtl' && $refDir !== 'ltr' ) {
|
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 ) {
|
} 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.
|
// 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.
|
// Follow refs do not duplicate the error which can be correlated with the original ref.
|
||||||
if ( ctype_digit( $refName ) ) {
|
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
|
// 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
|
// 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.
|
// gets the error "cite_error_references_no_key" above, so protect against that.
|
||||||
if ( $refsData->inReferencesContent() ) {
|
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 ?? '' ] ];
|
'params' => [ $refDmw->attrs->name ?? '', $refDmw->attrs->group ?? '' ] ];
|
||||||
} elseif ( !$hasRefName ) {
|
} elseif ( !$hasRefName ) {
|
||||||
if ( !empty( $cDp->selfClose ) ) {
|
if ( !empty( $cDp->selfClose ) ) {
|
||||||
$errs[] = [ 'key' => 'cite_error_ref_no_key' ];
|
$errs[] = (object)[ 'key' => 'cite_error_ref_no_key' ];
|
||||||
} else {
|
} 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 ) {
|
if ( $contentDiffers ) {
|
||||||
// TODO: Since this error is being placed on the ref, the
|
// TODO: Since this error is being placed on the ref, the
|
||||||
// key should arguably be "cite_error_ref_duplicate_key"
|
// key should arguably be "cite_error_ref_duplicate_key"
|
||||||
$errs[] = [
|
$errs[] = (object)[
|
||||||
'key' => 'cite_error_references_duplicate_key',
|
'key' => 'cite_error_references_duplicate_key',
|
||||||
'params' => [ $refDmw->attrs->name ]
|
'params' => [ $refDmw->attrs->name ]
|
||||||
];
|
];
|
||||||
|
@ -482,14 +482,14 @@ class References extends ExtensionTagHandler {
|
||||||
$errs = [];
|
$errs = [];
|
||||||
// Mark all refs that are part of a group that is autogenerated
|
// Mark all refs that are part of a group that is autogenerated
|
||||||
if ( $autoGeneratedWithGroup ) {
|
if ( $autoGeneratedWithGroup ) {
|
||||||
$errs[] = [ 'key' => 'cite_error_group_refs_without_references',
|
$errs[] = (object)[ 'key' => 'cite_error_group_refs_without_references',
|
||||||
'params' => [ $group ] ];
|
'params' => [ $group ] ];
|
||||||
}
|
}
|
||||||
// Mark all refs that are named without content
|
// Mark all refs that are named without content
|
||||||
if ( ( $ref->name !== '' ) && $ref->contentId === null ) {
|
if ( ( $ref->name !== '' ) && $ref->contentId === null ) {
|
||||||
// TODO: Since this error is being placed on the ref,
|
// TODO: Since this error is being placed on the ref,
|
||||||
// the key should arguably be "cite_error_ref_no_text"
|
// the key should arguably be "cite_error_ref_no_text"
|
||||||
$errs[] = [
|
$errs[] = (object)[
|
||||||
'key' => 'cite_error_references_no_text',
|
'key' => 'cite_error_references_no_text',
|
||||||
'params' => [ $ref->name ]
|
'params' => [ $ref->name ]
|
||||||
];
|
];
|
||||||
|
|
|
@ -3,6 +3,7 @@ declare( strict_types = 1 );
|
||||||
|
|
||||||
namespace Cite\Parsoid;
|
namespace Cite\Parsoid;
|
||||||
|
|
||||||
|
use stdClass;
|
||||||
use Wikimedia\Parsoid\Core\Sanitizer;
|
use Wikimedia\Parsoid\Core\Sanitizer;
|
||||||
use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI;
|
use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI;
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ class ReferencesData {
|
||||||
private int $index = 0;
|
private int $index = 0;
|
||||||
/** @var array<string,RefGroup> indexed by group name */
|
/** @var array<string,RefGroup> indexed by group name */
|
||||||
private array $refGroups = [];
|
private array $refGroups = [];
|
||||||
/** @var array<string,array[]> */
|
/** @var array<string,stdClass[]> */
|
||||||
public array $embeddedErrors = [];
|
public array $embeddedErrors = [];
|
||||||
/** @var string[] */
|
/** @var string[] */
|
||||||
private array $inEmbeddedContent = [];
|
private array $inEmbeddedContent = [];
|
||||||
|
|
Loading…
Reference in a new issue