Commit graph

563 commits

Author SHA1 Message Date
Sam Wilson b03dd1bba8 Load WikiEditor ref toolbar button on other content types
Allow other extensions to provide lists of page content
models for which they want to load the Cite toolbar button.
This will, for example, make it possible for ProofreadPage
to have the button on Page pages.

Bug: T348403
Change-Id: Id28cb0b6cb8a2b86a66b17232575afe513969c54
2023-12-13 21:45:19 +00:00
thiemowmde 04208b5fd1 Remove PHPDocs that just repeat what the code already says
We removed a bunch of now redundant docs already, see e.g. Ie0692fa.

Change-Id: I55c62d935bdec8bedaebc2666fca3eb17309b0c7
2023-12-13 12:44:41 +01:00
jenkins-bot c3aa27f2a1 Merge "Avoid a few isset() in favor of more recent syntax" 2023-12-12 23:58:45 +00:00
thiemowmde 9425bb3248 Move a bit of code out of Cite::guardedReferences
The main benefit is that the two lines that set and reset
$this->inReferencesGroup are now next to each other. More can be
done in later patches.

Bug: T353266
Change-Id: Ib3f40c40e0b1854f8e5a32af600f28931fffdb8c
2023-12-12 18:06:58 +00:00
jenkins-bot cdc2bd2b96 Merge "Skip URL encoding in id="…" attributes that aren't URLs" 2023-12-12 14:34:07 +00:00
thiemowmde 89bd26fcf5 Skip URL encoding in id="…" attributes that aren't URLs
I played around with a few options (see patchset 1) but ended
introducing new terminology:

* "Backlink" describes the ↑ button down in the list of <references>
  that jumps back up into the article. The code was already using
  "backlink" in some places.
* "Backlink target" is the id="…" attribute up there, visible as the
  typical [1] in the article.
* I use "jump" to describe the idea that clicking the [1] jumps down
  to the full reference.
* "Jump target" is the id="…" down there in the list of <references>.
* "Jump link" is the same id, but encoded to be used as the href="…"
  attribute when clicking the [1].

I hope this makes sense. Suggestions welcome.

Another benefit is that "normalization" is really only normalization
now, not any URL and/or HTML encoding.

Bug: T298278
Change-Id: I5a64ac43aef895110b61df65b27f683b131886fb
2023-12-12 13:56:37 +00:00
thiemowmde fee8606db6 Avoid a few isset() in favor of more recent syntax
As well as replacing a few `=== null` comparisons with the new ??=
operator.

Bug: T353227
Change-Id: I5b273f452d1e46d37fc28861b54c4e1f19a7a65a
2023-12-12 12:13:42 +00:00
jenkins-bot dda42b9aed Merge "Constants for internal enum" 2023-12-12 09:47:39 +00:00
Adam Wight 62497db444 Constants for internal enum
Change-Id: I6864bc7761abe653ab1f591c26e61a8ffb1ea3b6
2023-12-12 10:02:00 +01:00
jenkins-bot 039a8bbfb1 Merge "Rename internal variable" 2023-12-12 08:38:49 +00:00
jenkins-bot f7294f1b54 Merge "Parse error messages as late as possible" 2023-12-12 08:38:47 +00:00
Adam Wight c021c201c0 Rename internal variable
Updates the name to reflect the purpose and the new name for a cite
tag, now "ref".

Change-Id: I778641ad58048dd2c33b6487171c338555b0789b
2023-12-12 08:11:18 +01:00
thiemowmde 44ba7a89e2 Parse error messages as late as possible
This moves the actual parsing down to be done much later in the
process. This won't make any difference in production but makes it
easier to refactor the code further.

Note I tried to use a StatusValue object but couldn't because it
merges seemingly identical messages, while the plain array is fine
with containing duplicates. There is one parser test that covers
this. While we could change this it needs discussion and most
probably a PM decision.

Change-Id: I7390b688a33dace95753470a927bbe4de43ea03a
2023-12-11 18:28:35 +00:00
thiemowmde 6a18eac513 Fix regular expressions not being case-insensitive
The "parser marker" placeholders are case-sensitive, e.g. for a tag
that's written like <rEf> the placeholder will also say …-rEf-…. This
was really just a mistake.

The error is as old as this code is. Added in commit 75004e33 in
2009.

Note we shouldn't use /i at the end because the marker itself should
not be case-insensitive. Only the tag name.

Instead of adding more (slow) test cases I update two that are
exactly about this part of Cite (nested tags) anyway.

Bug: T64335
Change-Id: I44c7a42a0da682a1082952fd1af817bf7d45378c
2023-12-11 19:21:12 +01:00
Umherirrender c9773965ca Use namespaced classes
Done automatically via script

Change-Id: I40d64a194ad420c75dfa85711c53e35586895929
2023-12-10 23:18:51 +01:00
thiemowmde 202c0d3636 Drop unused …_suffix and …_key_with_num messages
The three messages cite_reference_link_key_with_num,
cite_reference_link_suffix, and cite_references_link_suffix are not
used for anything.

According to CodeSearch:
https://codesearch.wmcloud.org/search/?i=1&q=cite_references?_link_(key|suffix)

According to GlobalSearch:
https://global-search.toolforge.org/?q=.&regex=1&namespaces=8&title=Cite.references?.link.(key|suffix).*
For comparison:
https://global-search.toolforge.org/?q=.&regex=1&namespaces=8&title=Cite.references?.link.prefix.*

They are not meant to be localized, as noted in qqq.json. As many
messages in Cite the idea is that individual wikis can customize the
generated HTML (!) via such messages. These particular ones apparently
have been introduced just because it's technically possible, but never
been used for anything. They exist since the very first commit from
2005: https://phabricator.wikimedia.org/rECITb714bf09

Note how these messages aren't even visible anywhere, except in the
browser's address bar as part of a #… fragment.

This obviously doesn't solve T321217 but helps minimizing the
surface.

Bug: T321217
Change-Id: Icfa82155e3b02df39bb6e924bc472f6edc565d5f
2023-12-08 09:26:05 +01:00
thiemowmde 0bae6eb224 Fix confusing wording of "invalid parameter in <ref>" message
This error message really always meant nothing but "there is an
unknown parameter in your <ref> tag". It's unnecessarily confusing
only for historical reasons. See T299280#9384546 for a long
explanation.

Bug: T299280
Change-Id: Ic224d5828f7b7ac0928c44f526c61654ccf3425e
2023-12-07 10:54:46 +01:00
jenkins-bot e73c7d61ca Merge "Correctly encode non-breaking spaces in reference names" 2023-12-06 18:00:43 +00:00
thiemowmde f9bb125e4c Correctly encode non-breaking spaces in reference names
Note how this currently behaves. The user input is
<ref name="…&nbsp;…">
But what we get in the end is
<li id="…&#160;…">
This implies that the &nbsp; is decoded and re-encoded with a
slightly different entity encoding. (Note that &nbsp; and &#160;
and &#xa0; are all the same character.)

Also note how there is only an underscore in the href="…", but the
non-breaking space is gone. This is identical to what happens in
links and headlines. Try for example [[a&nbsp;_a]]. Multiple
underscores, non-breaking spaces, and normal spaces will be
normalized. We just do the same in the id="…" attributes.

Note this fixes only one of the issues listed in T298278.

Bug: T298278
Change-Id: Ia01f2fdd3b3e9ee6aaa9da60ca3386dcd5d6b1a0
2023-12-05 07:58:38 +01:00
thiemowmde 5f5e9ec9f0 Re-arrange code in preparation for T298278
This patch makes only sense together with I5a64ac4 where it is split
from. See I5a64ac4 for details.

The idea is that this patch just re-arranges the code without making
any changes to how the code behaves. This leaves a minimal change
behind that's much easier to revert, if needed.

Bug: T298278
Change-Id: Ie78313b7f3ac1ec7bce5ac7512e60a3bb011480a
2023-12-04 08:29:53 +01:00
thiemowmde 858fdcefd9 Split off separate key normalization function
This patch does two things:

1. The "normalization" function was never only doing normalization,
but also all the necessary HTML encoding. This is now more visible
and split into two separate functions.

2. To make this easier we change the order slightly. Because of this
the normalization step must now consider spaces. Before spaces have
been converted to underscores by escapeIdForLink.

The results are all the exact same as before.

This is split from I5a64ac4 to make that easier to review.

Bug: T298278
Change-Id: I9435a2ddaa21559e29587c58b7523103141467f7
2023-11-30 09:43:35 +01:00
gerritbot c26cc4fa44 Update UserOptionsLookup's FQN
User-options related classes are being moved to the MediaWiki\User\Options namespace in MediaWiki Core; reflect that change here.

Bug: T352284
Depends-On: I9822eb1553870b876d0b8a927e4e86c27d83bd52
Change-Id: I04337d15d32c1e8bdfdcfa272f1750ffecc8e47e
2023-11-29 12:38:22 +00:00
C. Scott Ananian d07d6affd9 Use DOMCompat::getAttribute() instead of Element::getAttribute()
This uses semantics consistent with the DOM spec (and any future
spec-compliant PHP DOM library, like Dodo or a native one bundled
with PHP).  It also helps avoid certain classes of errors caused
by conflating empty-string values and missing attributes.

A number of minor bugs have been fixed in the process, mostly
involving the string value "0" (and similar) which are falsey
and thus were sometimes treated the same as a missing attribute.

The API for MediaStructure was slightly tweaked to conform to
this "return null for missing attribute" convention.
No one outside Parsoid appears to use MediaStructure yet:

  https://codesearch.wmcloud.org/search/?q=MediaStructure

And Parsoid itself doesn't usethe MediaStructure::get* methods
which were tweaked here.

This patch squashes (and replaces):
 Ib272bd2a9a2da06efc4a4d962cd191107a70f84c
 Iae47c9f3c80f1642426ef985f1af6b44a9c807fb
 Ic3a43516e2a0c9bbd62f9519e5663b545fd975e7
 I7c45552a21ba49c76b1fc56f023d7937d9f41340
 Ic231a53dba9527c6b811cba990ae35f7fc7bf153
 I5209338d221ebf738a505d85fe1a019ea621fcc5
 Icb6b13c2b49edb3cd725999f09f8cb7e3a4c0f99
 I7eca3e616a66cac5b2a792435889cced2e2c9cd9

Change-Id: I11e7efb546c8cf1aac6b49c3361aacbd4eb5cef1
2023-11-22 14:04:11 -05:00
thiemowmde 67bbfe58ad Drop obsolete PHP 7.2 "arrayToObject" workaround
According to T228346 and T254519 this is a workaround for a PHP 7.2
bug. We require PHP 7.4 by now.

Not used anywhere outside of this codebase:
https://codesearch.wmcloud.org/search/?q=PHPU%5Cw*%3A%3AarrayToObject&files=%5C.php%24

Bug: T254519
Change-Id: I4150900e59c5bd865ce102417ac354a54552e623
2023-11-11 21:26:22 +00:00
Ed Sanders e7d3dec076 Document some generated messages
Change-Id: Id9c961f322c2f3730f29345da9ba61196243df5a
2023-11-08 12:07:50 +00:00
thiemowmde 4584c6d2b5 Add fast helper method DOMUtils::hasClass
While this is not really a bottleneck (usually the list of classes
is short) I was still curious. Why create an object, explode a
string into an array (even using a regex) and search the array if
we can do the same with a single regex?

This will be beneficial for other codebases, notably
DiscussionTools.

Change-Id: If9252a97562542e7a4bec29edcc6e8dee0fb8221
2023-11-03 21:27:01 +00:00
Umherirrender 2d6868cfe3 Use the expression assignment operator to simplify code
Suggested by phan, available since php7.4

Change-Id: If31fdd7174cf71d346e4080a70fa302bb3378745
2023-10-14 00:49:13 +02:00
Fomafix 21ceb98b74 Get context directly from $editpage
Change-Id: I9be4b9fb6016dea86f1cfa3893b69e2c92ac6c94
2023-10-10 07:27:29 +00:00
C. Scott Ananian dadeca74b5 Proper class type for DataMw
Slowly inch toward replacing the plethora of `stdClass` in the
Parsoid port with proper types.  The new classes could use additional
documentation of the various properties, but this is a start.

Bug: T226428
Change-Id: I87e73243203145b4067e70b0fa9e30da054fe1ed
2023-10-03 17:38:25 -04:00
gerritbot 198ae5b21c Replace some moved Title class uses, now MediaWiki\Title\Title
Bug: T321681
Change-Id: Idde5511e075fcec40cad12c7369abec3ee4d096c
2023-08-19 04:13:55 +00:00
Subramanya Sastry 4ed31f499e DOMPostProcess: Don't run extension dom processors on nested pipelines
* There is really no reason to run this once per nested pipeline
  since there is a lot of other processing that is skipped on
  nested pipelines.
* Eliminated the 'topLevel' arg to the wtPostProcess extension handler
  since that is no longer relevant.
* We may need to explicitly document this in the extension API spec.

Change-Id: Ib2508df736aeab9c649138249228647c00aaaef5
2023-07-28 14:40:59 +00:00
thiemowmde e750cc2ed2 Remove unused "HTML message" cite_references_no_link
I believe there is no reason to keep this. The only reason might be
a known wiki that uses this as a feature. But such a wiki doesn't
exist:
https://global-search.toolforge.org/?q=.&regex=1&namespaces=8&title=Cite.*no.*link

Bug: T321217
Change-Id: I128d4383da48f9bdda92f03b212ef3997b3a4802
2023-07-27 11:55:13 +02:00
jenkins-bot 1732720608 Merge "Remove (revert) expensive parsing of 1-character message" 2023-07-25 20:29:47 +00:00
thiemowmde 08814c8e38 Remove (revert) expensive parsing of 1-character message
This reverts a very tiny part of Ib3fdc89 from 2 weeks ago. The
reasons are explained in Ib3fdc89. Short version:
* The ->parse() calls have drastic performance implications.
* Allowing wikitext and HTML in this message also makes T321217
  worse.

The new message "cite_reference_backlink_symbol" is kept and still
used in the UI. Just not in these two messages any more. This is a
minor redundancy we want to get rid of at some point. But it's not
critical for the moment. This will be done as part of T321217.

Nothing will break on the wikis. Some wikis have customizations for
"cite_references_link_one" and "cite_references_link_many" in place.
This will continue to work as before Ib3fdc89.

Bug: T339973
Change-Id: I933771e3ad67cd530bcf5ee8469cef35ea1070d2
2023-07-21 14:05:31 +02:00
thiemowmde 25e7aa44dd No expensive transformations on prefix/suffix messages
This is a mistake that exists in this codebase for who knows how
long.

Cite mis-uses the messaging system a lot for internal things we still
want to customize somehow, but are not labels that will ever be shown
on the screen. The prefix/suffix messages in this patch are meant to be
part of the HTML in id="…" attributes. Prefix/suffix must be a static
plain text strings. Using e.g. {{GENDER}} or {{PLURAL}} in these
messages is not even possible because there is no $1 parameter to use.

Note how all other similar messages already use ->plain().

A few wikis override these messages, but stick to the plain-text
convention, as they should:
https://global-search.toolforge.org/?q=.&regex=1&namespaces=8&title=Cite.*reference.*fix
This will continue to work.

This has minor performance implications. Fetching these messages is
faster if we can skip transformations.

Bug: T321217
Change-Id: I7969c255fe4ce897e904897081da5f52678721aa
2023-07-20 16:22:46 +02:00
Subramanya Sastry 39e08e48fd Cite: Rename ext.cite.style to ext.cite.parsoid.styles
* Follows up the change in Cite repo

Change-Id: I043bea12cfcc80761c8c10e71a9c988d9f91637c
2023-07-19 14:32:56 -05:00
Subramanya Sastry 20889b2acb Cite: Add missing resource modules
* But, since Parsoid uses different class names, the JS code
  that inspects Cite content won't work!

  In this specific case, that code looks for .mw-cite-backlink
  which Parsoid doesn't add.

* Given the experience with media output changes in core, it might be
  prudent to switch over class names to what the Cite extension uses
  rather than try to update all the code that are probably referencing
  these classes.

Bug: T328695
Change-Id: Ie240898fa9de45f6d9d9821be39e9ec0af9f6bdf
2023-07-14 22:25:47 +00:00
Arlo Breault 128b758d13 Omit wrapperTag in references call to extTagToDOM
The contents of the domfragment gets migrated to an ol element and
then a query for sups in the ol makes up the nestedRefsHTML string.

Follows-Up: I44abd4f13254bc4512caad85244d523ac19140e7
Change-Id: Ie29d9b1ea7b34121587e77c8693dba79ed166ee1
2023-07-11 15:03:25 -04:00
Jon Harald Søby c66371b3d9 Move Cite-specific settings from WikiEditor
The WikiEditor extension has a button and some help text that
is only applicable if the Cite extension is enabled. Move
that (with some modifications) to the Cite extension instead.

Bug: T339973
Depends-On: I8256660f9c6886d6764b45735284e00308fc56e5
Change-Id: Ib3fdc897dd3330f69c5832003d4c3cb1e6dba2f3
2023-06-28 20:22:14 +02:00
Subramanya Sastry 5a77aa959b ParsoidExtensionAPI: Add method to process HTML embedded in attributes
* Parsoid core cannot know anything about how extensions represent
  information in their DOM. We were missing an extension API method
  and config that lets extensions specify this information along with
  handlers to process embedded content.

* This patch fills that above gap.

* There is a FIXME in ContentUtils::shiftDSR which will be addressed
  in followup patches with this new functionality.

Change-Id: If921ca471f25f21671a60c3f796fdf145267364d
2023-06-10 21:06:54 +05:30
Subramanya Sastry 1e61376d59 ParsoidExtensionAPI: Rename Extension API method
* This method isn't used anywhere else outside (per codesearch)
  so being bold and renaming without any public notification.

Change-Id: I0c4ec7c4b2afb1d0d3cd1a932e0384bd9626799e
2023-06-08 18:55:51 +05:30
jenkins-bot 5affadae9d Merge "Add strict types to all class properties" 2023-06-08 10:41:54 +00:00
Ed Sanders 58db72b0c5 Always use the strict equality flag when using in_array
Change-Id: I21283adfa1c10916bb0ee0b4e87d530bf19d94b9
2023-06-06 13:34:15 +01:00
thiemowmde 5c93bbfd00 Add strict types to all class properties
A good bunch of PHPDoc comments is obsolete when we use strict types.

Change-Id: Ie0692fae4d96c749e9048f7e7c6931ec97998093
2023-06-05 20:01:13 +02:00
thiemowmde 78658dbdb7 Replace misplaced substr_count
There is nothing to count here. All we want to know is if the number
is greater than zero.

Change-Id: I12a6d2413ab5b1c152817cd0f3ca3de165b3e2f7
2023-06-05 16:20:36 +02:00
Svantje Lilienthal 227b50d964 Adding extendsRef to reference model
* reads the new attribute extends from wikitext
* saves it into the reference model
* adds a message to the VE popup of an extension as a first demo
* tests will be added in a separate patch

Bug: T247922
Change-Id: If4d309c4678022642f39e21565950dc45e557d47
2023-05-30 11:56:47 +02:00
Arlo Breault c37977aad2 Assume strings for dataMw->body properties in ref handlers
The diffHandler already has this expectation.

Bug: T337036
Change-Id: I0c3a3532c655df6777407a1e0af2d9bac9495037
2023-05-19 13:28:41 -04:00
Tim Starling 5315297f38 Migrate CiteVisualEditorModule to a virtual file callback
Depends-On: I97d61b5793159cea365740e0563f7b733e0f16de
Bug: T47514
Change-Id: Iabfbb6751707813b7ec68f49b35441ab5dbb5622
2023-05-05 16:25:14 +10:00
Subramanya Sastry fc240841c4 ParsoidExtensionAPI: Simplify extTagToDOM
* leadingWS is always '' in all the uses so far and it originally
  came from Cite when we first extracted the extension API.

* It is unnecessarily confusing and serves no real purpose.

Change-Id: I5f2f0f123dc6938735c09b96a42c1923b0a49085
2023-03-28 15:44:06 -05:00
thiemowmde 6f302bf3f0 Replace string|false in CiteParserTagHooks with nullable ?string
This allows us to use strict types in one more place.

Change-Id: Id31a427b61a5eca720ec695fe219809a8e37d208
2023-02-27 15:32:04 +01:00
Subramanya Sastry a9260875ac SiteConfig: Transition away from hardcoded Cite info
* This builds on the core patch that adds this new method
  to core's SiteConfig class.

Bug: T268777
Depends-On: Ia489cd880de3df73d7cd47d1eb01971f2655effe
Change-Id: Ifd41e4275a9344474e48d013e1116b028c7775d7
2023-02-20 17:56:02 -05:00
Arlo Breault 8958246add Fix multiple ref nestings from the tag parser function
The algorithm in the grammar is fixed up and the restriction to one
level of nesting is lifted.  It was overlooked that parser functions can
be nested.  Some of the history of ref-in-ref can be found in 03bf14b0
and d634925.

Bug: T326521
Change-Id: I8e442d41f68133c1b4f16556fedaff6106e233fb
2023-01-25 01:17:09 +00:00
Isabelle Hurbain-Palatin 57fb5617a9 Fixes data-id for "follow" refs
"follow" refs are cloned, which can lead to issues with their
data-objects conflicting with the initial node: if
additional, possibly out-of-order processing is happening, we may end up
accessing/modifying the data bag. In particular, we considered adding a
call to the DOMNormalizer when serializing the reference bodies, and
this was triggering an exception when accessing the DOMDiff of the
cloned node. We are not considering this right now anymore, but cloning
the NodeData may avoid issues of this type in the future.

This patch also introduces a utility to do the clone+clone data bag in a
single method call.

Change-Id: Iccdae82dec81d488433981d764bea539609497eb
2022-11-25 17:41:33 +00:00
Subramanya Sastry ad919e3730 Parsoid CSS: Add (script-generated) language-specific counters
* These files were generated with the script in
  I3623e42d4cad7975813892a8f0f7765b74a638c5

* These styles mimic the behavior of Language::formatNumNoSeparators
  and Language::localizeSeparators used by a couple of methods.

  ReferencesFormatter:referencesFormatEntryNumericBacklinkLabel
  calls ReferenceMessageLocalizer::localizeDigits which calls
  that core Language method.

  FootnoteMarkFormatter::linkRef calls localizeDigits as well.

  - '.reference a*' CSS rules mimic linkRef localization
  - 'span[rel="mw:referencedBy" ]*' rule mimics localization
     of referencesFormatEntryNumericBacklinkLabel

* Overrode all hand-crafted language CSS files from previous
  patches. The content of some of those hand-crafted CSS files
  will end up in those wikipedia's Common.css -- specifically
  for es, fr, sv wikipedias.

  sv and es have non-canonical formatting strings that aren't
  handled by the script right now and so leaving them behind.

  I need to look at fr output more carefully, so leaving that
  behind as well. But the generated ones are more accurate when
  combined with the wiki-specific CSS files genreated by the other
  script that processes site messages.

* Some files could potentially be removed by looking at
  language fallback chains, but the redundancy is not a
  problem for now.

* Tweak the resource loader script to use "_" instead of "-"
  when looking for a resource file.

Bug: T156350
Change-Id: I000b4538bf2be681b85df5813efed083458a4281
2022-11-18 11:50:20 -06:00
C. Scott Ananian c24f5a18af Turn on phan warnings about the use of deprecated methods
MWParsoid\ParsoidServices depends on the deprecated
\MediaWiki\Parser\Parsoid\ParsoidServices in core; it is not needed
any more in MW 1.40 so it has been removed.

Change-Id: I2c4fd2e9ea2b5e2751074f1b9705e46436a32131
2022-11-04 12:36:24 -04:00
libraryupgrader a3babf81e3 build: Updating mediawiki/mediawiki-phan-config to 0.12.0
Change-Id: I70f1a3ef9e5a10edaf5a8dc9f3e272f99021b9c5
2022-10-09 19:48:09 +00:00
Isabelle Hurbain-Palatin 24b5204c28 Add 'outputHasCoreMwDomSpecMarkup' as option in extension registration
The ''outputHasCoreMwDomSpecMarkup' option in the extension registration
indicates whether the output of an extension complies to the MediaWiki
DOM Spec and should be processed as such.

The initial goal of this setting is to enable the DOMNormalizer pass for
Parsoid HTML generated in extensions, as needed by the implementation of
T309024.

We setup "Cite" as an example of configuration.

Bug: T309024
Change-Id: I26182c67ea17a4aa59414856d5f4614f2cd06c46
2022-09-29 13:25:53 +00:00
Thiemo Kreuz 8fef0dd2aa Improve two error messages
Makes it easier to find the source of the error in the wikitext.

Change-Id: I648a19881210184ab1abe9b948b5efbbbdabcdc9
2022-08-20 12:23:28 +02:00
Isabelle Hurbain-Palatin 51189f14ac Allow multivalues in rel attributes
The 'rel' attribute can be used for multiple values in the same way that
the 'typeof' attribute can. In this patch, we allow for that by
providing methods to handle these multivalues and by refactoring the
code that would only allow for single values.

Bug: T186241
Change-Id: I625b121ae77c06c519c3b578583d41dc220e3294
2022-07-19 18:46:50 +00:00
Arlo Breault 7537d185eb Improve comment around serializing autogenerated references
Follow up to Ia651b10449dc41c2cb439b33a361e8c8e482f502

Change-Id: I0a72e7fbf90a78d04144d66103cbe013e41c5163
2022-06-13 14:26:00 -04:00
Bartosz Dziewoński 40c40974d0 CiteVisualEditorModule: Disable URL loading to fix legacy debug mode
Bug: T309697
Change-Id: I3db2292ce3ec50c7c8950254fb52ba6ec92d8815
2022-06-02 20:51:16 +02:00
Thiemo Kreuz 11255770c5 Make message key parser accept more than just underscores
The best practice for message keys is to use dashes, not underscores.
This codebase is quite old and traditionally uses underscores. I
think we can make it flexible enough to work with both.

Required for Ie64f4ab.

Change-Id: I6f0584299a4f279ed929784927392eb0f72cbc80
2022-06-01 10:34:57 +02:00
jenkins-bot 20ec7ced59 Merge "Use new ResourceLoader namespace" 2022-05-24 23:22:32 +00:00
Tim Starling bb72bc65f5 Use new ResourceLoader namespace
Extensions using Phan need to be updated simultaneously with core due
to T308443.

Bug: T308718
Depends-On: Id08a220e1d6085e2b33f3f6c9d0e3935a4204659
Change-Id: Iebc5768a3125ce2b173e9b55fc3ea20616553824
2022-05-24 23:00:08 +00:00
Subramanya Sastry 74aa1ea647 Cite tests: Update html/parsoid sections with output in integrated mode
These changes are a result of adding Parsoid integrated testing support
in core.

* Some tests got new html/parsoid sections.
* Some tests got their html/parsoid output upgraded to remove bogus HTML.
* Since we are not treating the test runs to be in integrated mode,
  I removed some comments that only pertained to a test run in
  standalone mode.
* There are 8 tests that are failing in integrated mode as well and
  I've tagged 5 known ones with T307741. The other 3 failing ones are
  the responsive reference tests that have a threshold value set.
  Those failures will need investigation and require additional changes
  to the core parser test runner to pass through the config to Parsoid.

Change-Id: I370d57d45cf126f71b3666fb493a887faf6b8e0d
2022-05-11 17:40:46 +00:00
Isabelle Hurbain-Palatin 28d6a05c35 Hoisting references outside of links
When a reference is inserted in a link, Parsoid generates nested links,
which would break browser rendering. In some cases where the generated
HTML is reprocessed in later stages of Parsoid (as is the case in
T301293), it can lead to internal breakages.

In this patch, we propose to hoist references markers (and their <sup>
tag) included in links outside of that link, as next sibling to the link.
It avoids the vast majority of link nesting due to that situation, with
the following side effects:
* the <sup> tagging is now maintained around the marker tag,
* if a ref tag is in the middle of a link, it gets moved to the end of
the link (in the legacy parser, it stays where it is, but the end of the
link gets de-linked).

The selser test failures are consistent with the expected behaviour - wt2wt
does not round-trip correctly, leading to selser failures.

Bug: T301293
Change-Id: Ia39483c2112b1356e14a310fbb48baed946b5caa
2022-05-11 13:45:59 +00:00
Arlo Breault 6d9afe15dd Resolve linter test port-fixme
Implements mocking for the #tag parser function for ref tags.

The ref-in-ref linting cycles tests from 04aa4be can now be restored.

This shows that after I1b598bd359b900d1b89abf5d8105a5d131aea3d1, the
protection added in 04aa4be is no longer necessary, because we only lint
the content where it's defined.

Bug: T237463
Change-Id: I4059e32b9bea8cdc23d2112812c3f7e167e47399
2022-05-10 17:07:08 -04:00
Arlo Breault 18889348c9 Lint html stashed in data-mw of mw:Extension/references
Follow up to I1b598bd359b900d1b89abf5d8105a5d131aea3d1

This also lints the html stashed in data-mw of mw:Extension/ref, when
named references have redefinitions.

The fast fail for linting references with errors is removed since it's
no longer necessary after the work in T51538.

Bug: T214994
Change-Id: I2431b4782339a1ac41c49f7ca0ad3480c0b13bad
2022-05-02 23:37:42 +00:00
Arlo Breault 9fa2aeaba3 Only lint content defined by a specific ref
This change will fix the crasher from T301293, since all the necessary
information to locate the ref contents is contained in the first
encapsulation wrapper node, we therefore don't need to traverse into it
and potentially be tripped up by the node being closed early for having
content model violations.

By using the linkback id from the href, we're potentially linting the
content multiple times.

By using the id from the data-mw, we're only linting the content
specified by the specific ref (with the slight caveat that if two named
refs define exactly the same content, they share an id).

Note that if named refs have multiple definitions, and hence the content
ends up in data-mw, we aren't yet linting it, that's T214994.

However, by not using the linkback ids from the href, we'll need to
traverse the html that mw:Extension/References have stuffed in their
data-mw if we want to lint references defined in the references tags
themselves (see the commented out test).  This has the benefit though of
not running into the issue described in the References::lintHandler
(ie. not having the right tplInfo while traversing the content).

Bug: T301293
Bug: T214994
Change-Id: I1b598bd359b900d1b89abf5d8105a5d131aea3d1
2022-05-02 23:37:39 +00:00
Arlo Breault e3c4e96c71 Prioritize body->html over body->id when diffing refs
Just to keep things consistent since that's the precedence we use when
serializing.

Change-Id: I1456b6a21ae050d58d15620e501a14c29a64f9e3
2022-04-28 14:51:05 -04:00
Subramanya Sastry c3f34b7360 Cite: Document the Parsoid-only responsive refs threshold
* This functionality comes from 74acc71e

Change-Id: I5d985ff75670136a27d52850ea0e41da52fa3c96
2022-04-14 12:32:18 +05:30
C. Scott Ananian e7dd9b5549 Page properties should always be strings
Bug: T305158
Bug: T237531
Change-Id: Ibfd84b52057baa8e249d321ec9df612efd6a29a6
2022-03-31 14:26:40 -04:00
Subramanya Sastry 15a38973c7 html2wt: Use info level for unactionable Cite logspam caused by CX usage
Content Translation can lead to Cite references to nodes that aren't present
in the translated document. For now, I've suppressed these log entries in
Parsoid's logstash dashboard. But, there is no reason to continue emitting
these at error level given the large volume of CX pages and hence a large
volume of these non-actionable log entries.

Change-Id: I8df7e722203d7b866d987d626215bcd53b945d60
2022-03-02 20:07:35 +00:00
Subramanya Sastry 20e5117622 Minor tweak to function name in ParsoidExtensionAPI
Change-Id: Ic8fdfdc12b224460277d6a34247d20911526823a
2022-02-03 22:46:09 +00:00
jenkins-bot e0ccd777b0 Merge "Use correct Sanitizer method for id/fragment escaping" 2022-01-27 08:12:43 +00:00
C. Scott Ananian b2c1624ce0 Passing a string to ParserOutput::addModules()/addModuleStyles() is deprecated
Bug: T296123
Change-Id: Iedea960bd450474966eb60ff8dfbf31c127025b6
2022-01-11 15:23:25 -05:00
Thiemo Kreuz 7b30a165e4 Use correct Sanitizer method for id/fragment escaping
Note how only the HTML5 mode behavior changes, but nothing in
legacy mode.

Also note this does not 100% fix the issue. The esample with a
non-breaking space is still broken. But it's already much better
than before.

Bug: T298278
Change-Id: Idf50dad4219ff4c594a0cc15f63cb10fdac5ffb7
2022-01-03 16:23:45 +01:00
Timo Tijhof bee357337c ve-cite: Export citationTools as native object instead of JSON string message
* Remove the overhead of serializing and then re-parsing client-side,
  instead assign it directly as native object literal.

* Move code for array slicing to PHP.

Change-Id: Iedcc8d57d3bddd3fa32a78b4e7ecc25615d94277
2021-12-07 12:53:24 +00:00
Timo Tijhof fb2c7c37db Combine ext.cite.visualEditor.data into ext.cite.visualEditor
Rather than depending on a separate module with one line of generated
JS code, generate it as a prepended statement to the same module.

Should be a no-op.

Depends-On: I809951d34feb2dbd01b7ae0f4bd98dac7c3f6fe2
Change-Id: I5886bf9f82025048976b7750e8cb751681021fb4
2021-11-19 16:56:51 +00:00
Arlo Breault 2e4f69a492 Implement diffHandler for Cite extension
Bug: T214651
Change-Id: I64585cd89135887e095e3ab17d10c3c7d82af1c9
2021-11-16 20:33:24 +00:00
Tim Starling 0cc211d675 Make DataParsoid be a real class
Use @property to provide the types of undeclared variables to Phan and
PHPStorm, as in my NodeData patch. Declare $dp->tmp since it is
commonly used and does not affect the JSON serialized output since it is
always stripped.

I omitted the constructor, instead of following the suggestion in the
massageLoadedDataParsoid doc comment which proposed injesting a
JSON-like data structure in the constructor. I thought it would be more
efficient to have the initial property assignments inline in the calling
code. This means breaking up many object cast expressions into
individual assignments.

In IncludeOnly, the coalescing null operator was only handling the case
where $start->dataAttribs was unset, which seems unlikely. I made it so
that it checks whether $start->dataAttribs->tsr is unset.

I added strongly typed clone() methods, to preserve type information for
static analysis.

DataParsoid is the type of the data in both the DOM and in tokens. To
simplify the changes to the Token hierarchy, I removed the duplicate
definitions of the public properties $attribs and $dataAttribs.

Change-Id: I16172083e7e9bcb94601d1d6862d1d202a7e3660
2021-10-13 10:20:15 +11:00
C. Scott Ananian 30cfb7c05a Rename deprecated usage of ParserOutput::{get,set}Property()
Bug: T287216
Depends-On: Ie963eea5aa0f0e984ced7c4dfa0fd65d57313cfa
Change-Id: Id4581c6c45f9fc4690900a30d8172951bc461a1b
2021-10-08 10:12:05 -04:00
Umherirrender c0ace40aaa build: Updating mediawiki/mediawiki-phan-config to 0.11.0
Change-Id: Ifb2eec4e791fd0de0a50d8ef85e0947ab9a891e7
2021-09-21 12:13:36 -05:00
Subramanya Sastry f7bc278673 DOMUtils: Get rid of isElt, isText, isComment helpers
* Most of these are remnants from the Parsoid/JS codebase.
* This change follows the pattern we've been using everywhere
  since the port from JS->PHP.
* Also reduces instruction count by about 0.2%.

Change-Id: Ibf21104f6722c34299f03e303dc3401bf053a751
2021-09-20 22:39:38 +00:00
Tim Starling 8f3369b090 Avoid using regexes
Review regex usage, and use an alternative where possible, to improve
performance.

* Add PHPUtils::stripPrefix() and PHPUtils::stripSuffix(). Benchmark in
  doc comment.
* /foo/ -> str_contains()
* /^foo/ -> str_starts_with()
* /^f/ -> ($s[0] ?? '') === 'f'
* /foo$/ -> str_ends_with()
* /^(foo|bar)$/ -> in_array(), benchmark suggests 10x improvement
* preg_replace(/foo/) -> str_replace()
* preg_replace(/^[abc]/) -> strspn(), benchmark suggests 3x improvement.
  Curiously, it is faster without a limit for short input strings,
  although a limit presumably adds robustness.
* preg_replace(/[abc]+$/) -> rtrim()
* preg_match_all() -> substr_count()
* In DOMUtils::hasTypeOf(), use explode() instead of a regex. Validated
  by a benchmark.
* In DOMUtils::addTypeOf(), stop normalizing adjacent spaces. This
  allows us to use implode(explode()) without a filtering loop. The
  patch to Ext/Cite/References.php was to remove spaces added by this
  change. The parserTests.txt changes were a consequence of the
  References.php change.
* In LinkHandlerUtils::getHref() I allowed a single bare slash to be
  counted as a path-absolute URL since I think that was the intention of
  the original code.
* In LinkHandlerUtils::getLinkRoundTripData() I captured the portion of
  interest from the previoulinkHandlers regex instead of running a
  second regex.
* LinkHandlerUtils::linkHandler() had the regex
  /^mw:WikiLink|mw:MediaLink$/ which I think was a bug, missing
  parentheses. I fixed the bug.

The margins are pretty tight for a lot of these. Using polyfills for
str_contains() etc. might change the conclusion.

Also:

* In DOMUtils::matchTypeOf(), avoid calling hasAttribute().
  getAttribute() is documented as returning an empty string if the
  attribute does not exist.

Change-Id: I8d7bdf1bccc869b4dc17058a5822ef34968471e6
2021-09-13 23:01:45 +00:00
libraryupgrader c4872e1e8f build: Updating composer dependencies
* mediawiki/mediawiki-phan-config: 0.10.6 → 0.11.0
* php-parallel-lint/php-parallel-lint: 1.3.0 → 1.3.1

Change-Id: I89eb4438dacb2d0ab36f4986c0675eec5cb61731
2021-09-08 19:30:00 +00:00
Arlo Breault 66355c1ddc Migrate out valid follow contents after processing refs
Follow up to 47dd898

Also renames a variable to be consistent in the two places we get
contents for the ref.

Change-Id: I13e61b8911ff16549fbb0888b9c3313ed5e7701e
2021-08-27 15:00:54 -04:00
Arlo Breault 5c7c37e0c9 Reserialize processed refs if content differs
Follow up to 47dd898

Fixes the test case found in rt,
php bin/parse.php --domain ceb.wikipedia.org --pageName "Martin Van Buren" --offsetType ucs2 < /dev/null

The offsetType is necessary so that the ConvertOffsets pass runs.  The
crasher here is because the embedded html still contains the sealed ref
fragments because we've stored the unprocessed html.

Change-Id: Ic1e1c3e54433bf6d7574420c2eade1349261de0b
2021-08-27 15:00:37 -04:00
Subramanya Sastry 0d26fd19d5 Cite: Rename functions pushing/popping embedded content flags
Change-Id: Ie8736fcc139caba467209b7ba57daaa8f53bc18a
2021-08-26 11:43:52 -05:00
Arlo Breault 47dd8989a7 Don't process ref-in-ref as embedded, unless content differs
Restores linkbacks for ref-in-ref.

Follow up to 568034a where it's noted that it's fine to maintain
linkbacks for ref-in-ref, as long as the ref isn't a named ref that's
trying to redefine the contents for that name, in which case we embed
the contents.

A test case for this can be,

```
<ref name="hiho">off to work</ref>
{{#tag:ref|<i>we go <ref name="ohno">ohno</ref></i>|name="hiho"}}
{{#tag:ref|<i>we go <ref name="ohno2">ohno2</ref></i>|name="test"}}
```

The linkback to #cite_ref-ohno2_3-0 is present while continuing to
suppress the dangling linkback to #cite_ref-ohno_2-0, since that's in
embedded content.  On master, both linkbacks are unnecessarily
suppressed.

Bug: T289331
Change-Id: Ifcf7464e86a4408f5dd9e2fd6d3aa47a0670ca49
2021-08-26 16:41:02 +00:00
Arlo Breault d0e1637d22 Move content differ check up higher
This will be helpful in a subsequent patch where we make use of that
data while processing refs in refs.  Content differing implies that
we'll be embedding it for roundtripping, rather than putting in the dom.

Change-Id: I7bd1d4c503fc58f862960bec82ca514fc29d7eff
2021-08-26 16:38:58 +00:00
Arlo Breault 50dfe518cc Only call ReferencesData::add when adding
This moves determining if we already have a reference created for a
named ref outside of that function, which is helpful for making use of
the cached html for that ref earlier.

Change-Id: Ie416bd95b980f9f95111d7e420945f40e2ada747
2021-08-26 16:37:36 +00:00
C. Scott Ananian 187de4b769 The ::querySelectorAll() and ::getElementsBy* helpers don't always return array
The standard type for these returns is NodeList and HTMLCollection, which
are almost *but not quite* the same as an array.  In two places we got a
little complacent and assumed our non-standard DOMCompat workarounds would
always return arrays.  Tweaked the types of DOMCompat to report that they
return an `iterable`, which is a PHP7.1 "pseudo-type" that unifies
arrays and \Traversable types like HTMLCollection/NodeList.  This
allows phan to catch places where we slip up and assume an array type
return.

It does introduce a new wrinkle, though, since there is no simple way
to turn an iterable into an array.  We're using a simple
`iterable_to_array` helper function for this.

Change-Id: I35bdeb3afa30ef5182e71733a0a606aadcafb435
2021-07-31 03:50:07 +00:00
C. Scott Ananian a1d0fdd776 Allow Node::getAttribute() to return null
In PHP's DOM extension, one of the legacy bugs is that
DOMNode::getAttribute() can never return `null` (to indicate that the
attribute is missing), instead it returns an empty string in that
case.  This isn't (modern) spec-compliant behavior (it's a leftover
from ancient times) and we had to watch this carefully when porting
from JS.

In the time since the port, we've written new code and embedded this
assumption that DOMNode::getAttribute() will never return null into
the new code we've written.  Fix this.  Always use `getAttribute(...)
?? ''` (unless we're just doing an equality test against a non-empty
string, or the code is preceded by a `hasAttribute` test) so that our
code will work whether or not getAttribute returns null for a missing
attribute.

Change-Id: If33200e1053b2dd79abb5dfb3808c05ff3a0bbba
2021-07-30 20:34:47 +00:00
jenkins-bot e584c5cf3f Merge "Refactor newline logic for auto-generated <references> sections" 2021-07-30 14:17:49 +00:00
C. Scott Ananian fd3597cd39 Add class alias file to allow swapping in Dodo for DOMDocument
Change-Id: I56c10d2f4283e9e7b57bf722208fefab007cdf45
2021-07-23 12:20:06 -04:00
libraryupgrader 0af1a039b0 build: Updating mediawiki/mediawiki-codesniffer to 37.0.0
Change-Id: Ia399fafc5280aab1c0cfc129529a822e8d8f8382
2021-07-22 12:34:32 +00:00
DannyS712 55cc7c2828 Remove documentation that repeats the code
Mostly comments along the lines of "{classname} constructor"
in the doc block for the __construct method.

Change-Id: I67ffe070985dc75a5d817b1b5ac97b529d7ab4b8
2021-06-02 09:57:36 +00:00
Thiemo Kreuz 0cc1ddeccb More robust property initialization in ReferenceStack
I tried many things, but wasn't able to reproduce the error
described in T283755. What probably happens goes like this:
* Somehow $this->refs[$group] is initialized, but
  $this->groupRefSequence[$group] is not.
* There are not many places in the code where this can
  happen. There are a few suspicious lines in rollbackRef(),
  but they are all guarded. The only problematic place is in
  appendText().
* This problematic line is only called for <ref> in
  <references>.
* Somehow a <ref> is valid enough to make it to appendText(),
  but not valid enough to make it to pushRef().
* The next time another <ref> is added to the same group, it
  appears like the group already exists ($this->refs[$group]
  is set), but $this->groupRefSequence[$group] is missing.

I was unable to find a wikitext example that would behave like
this.

This patch just makes sure the initialization is done but
doesn't care why it was missing. The following code is fine
with an existing ref that contains nothing but text (which is
how appendText() leaves it behind).

Bug: T283755
Change-Id: I36ac56ef6ed98676a3e8f430a796826351a5f4e9
2021-05-31 14:10:07 +02:00
Aaron Piotrowski 81630c4267 Upgrade to mediawiki/mediawiki-codesniffer 36
Change-Id: I103a662d0af77cafa46cf6445e1580aabd005f31
2021-05-04 10:25:25 -05:00
libraryupgrader 3d79d3518b build: Updating composer dependencies
* mediawiki/mediawiki-codesniffer: 35.0.0 → 36.0.0
* php-parallel-lint/php-parallel-lint: 1.2.0 → 1.3.0

Change-Id: I409d4c564a02f537dbd1ceec1576410aefe0ea64
2021-05-04 01:29:20 +00:00
Arlo Breault be829c15b0 Check for multiples doesn't apply to follows
Follow up to 7bd9f87

Bug: T276388
Change-Id: I68ab87702b967e870c432564b54d86bcbf914174
2021-03-03 18:07:17 -05:00
Adam Wight 1a6fb7b0f9 Coerce type to please linter
Change-Id: I4a196cfc5b7191306446d187ca3fe4358afc24c5
2021-02-24 18:46:18 +00:00
Umherirrender e30f055226 Improve function and property documentation
Removed some wrong @param from test function,
the @dataProvider should be a enough here

Change-Id: Ib84ce497fef4d48df7547ebc38515fc377e7de01
2021-01-16 13:44:19 +01:00
Arlo Breault e047ff7afc Refactor sanitization in a normalizeKey function
This matches the legacy parser extension.

Change-Id: Iecec58e793e4a7c0ecd3a139773f225484f4be8f
2021-01-12 00:04:43 +00:00
sbailey c3bc1f00b0 Contract multiple underbars in a row in refnames to a single underbar
* Inlcudes test coverage for refnames with single and more than
   one underbar in a row which are maintained as separate keys but
   serialized without the multiple underbars

Bug: T267974
Change-Id: I9c21a6ff761f4b9a22b1185280b5676e2c160208
2021-01-11 23:14:11 +00:00
Subramanya Sastry 6ebe050750 Get rid of rtTestMode
Back in the early days of Parsoid, we introduced rtTestMode so
we can suppress lots of noisy (but harmless) diffs in rt-testing
so we can isolate the harmful diffs that absolutely needed fixing.
This mode was critical to running large scale round-trip testing on
a large test corpus and let us get a lot of confidence in Parsoid's
ability to handle VisualEditors edits.

But, now that Parsoid is established and selective serialization is
also fairly robust, it is time to get rid of this mode altogether.
This mode was adding clutter to the codebase and was potentially confusing
in some cases. We won't lose our ability to identify regressions in
rt-testing since all we care about is semantic diff changes relative
to a baseline. We just end up with a lower-fidelity baseline.

Change-Id: I22a1b3ecf4e0224000f1df6a98cf7ea9bcb4ee4e
2021-01-11 15:39:06 -06:00
sbailey 9679519b0a Fix for Parsoid Cite refname whitespace handling
* Refnames such as 'a b' and 'a_b' are now kept seperate like
   in Core Cite. Refnames with unicode whitespace characters
   such as "a\u2028b' are handled as distinct refnames from 'a b'
   and their ID's are sanitized appropriately to have underbars.

Bug: T267974
Change-Id: Ie06d1f2b8614dbdcf8572ed4647ec9093ef006d5
2021-01-08 17:22:44 +00:00
Arlo Breault e8d8481f60 More papering over in References.php
This is the same fix as in 5e5e360 for T259676

The root of the issue is described in T260082

Bug: T271357
Bug: T260082
Change-Id: I7ccf0b20f6b0be0f31101a2c4a88010675dc72ba
2021-01-06 18:53:55 -05:00
Taavi Väänänen 9293e2d5ca Update Cite to use the new HookContainer/HookRunner system
Bug: T270875
Change-Id: Ieb29603cde24a1c52829c12ae431eca09ba37bf9
2020-12-28 17:55:34 +02:00
sbailey 394015a38b Add ref/follow name to Cite error cite_error_references_missing_key
Bug: T51538
Change-Id: Id19a4e4c37169ca6eb7aecdce66b1662546ae31a
2020-12-21 18:08:21 -08:00
sbailey 511543e3f1 Add refname parameter to cite_error_empty_references_define error
Bug: T51538
Change-Id: I2850b7f181f44465437bc486bc544c5cd58aa5e3
2020-12-21 13:31:37 -08:00
sbailey b9b10a3fe0 Add group name to Cite error cite_error_references_group_mismatch
Bug: T51538
Change-Id: Ie6e04edcdf4b9760711ec53021d65970691a3813
2020-12-18 22:16:28 +00:00
sbailey 7bd9f87157 Add parameter $refName to Cite error cite_error_ref_duplicate_key
Bug T51538
Change-Id: If8399be12a5cad025b3a4db8e970c8de96c75ad6
2020-12-16 13:58:45 -08:00
sbailey 5fbf890f12 Add direction parameter to cite_error_ref_invalid_dir message
Bug: T51538
Change-Id: I5e964ad7341a46552d7b8eded0d844c0132816b1
2020-12-16 20:24:57 +00:00
sbailey cf4a49ba6e Add group name parameter to cite_error_group_refs_without_references
Bug: T51538
Change-Id: I8708ffa21c2ef68c124a5b055a6860cfb4ec12e1
2020-12-16 20:19:33 +00:00
Arlo Breault d95a783cc8 Stop referring to spec version numbers where unnecessary
Presumably the source should be up-to-date with the latest spec.

Change-Id: Iaea7f80e9d3bbd3520a7b499252162240deeba62
2020-12-16 13:55:27 -05:00
Ed Sanders 35b704dc2f Move ext.cite.ux-enhancements to extension.json
Change-Id: Ia6a0c34800b018e76b9e246898ddfb991f238d55
2020-12-14 10:38:32 +00:00
Ed Sanders 10c525b5b7 Unconditionally register the VisualEditor integration statically
This is how we handle this in othe repos; CI ensures that VisualEditor
is indeed loaded alongside the Cite extension whenever it's required,
and this significantly reduces the complexity of the code in the repo
and the processing time needed from Cite's hooks on every PHP init.

I'm leaving the "ux-enhancements" module for now, as you can't mix
static (late) module registration with dynamic (immediate) code.

Change-Id: I974654d00687b0dea6aed342d8fa9dcb6ef90768
2020-12-13 22:11:27 +00:00
Ed Sanders 10f7f716f0 ve-cite: Add dependency on ext.visualEditor.mwtransclusion
ReferencesListNode needs to be registered after
MWTransclusionNode so that it has a higher specificity
when matching.

Change-Id: I93610fac2ec9715a14b34efb76abc55d2d2c6900
2020-12-13 22:10:44 +00:00
Subramanya Sastry 07bcfd9add Purge Sanitizer proxying from ParsoidExtensionAPI
Sanitizer is heavily used by extensions and we decided to let
extensions directly access it.

So, stop proxying those methods from ParsoidExtensionAPI.

Change-Id: I5ff285bf33733878135e2091d53ae12f7340c8fc
2020-12-10 16:54:30 +00:00
sbailey e0322afd84 Parsoid Cite add class mw-ref-follow for refs with follow
* Addresses a FIXME (T263052) where Parsoid Cite injects
   style = "display: none;" in refs with follow instead of
   having css do that triggered by having a class "mw-ref-follow"
   as part of the refs html.

Bug: T263052
Depends-On: I351516b81566aba0adb4d298e39806dfb4fc7b03
Change-Id: I8bfc4ee3df162e2040e3c6f0c37fbf2a7c30d7f6
2020-12-10 16:54:25 +00:00
Arlo Breault 8d4543954f Cast references attributes to strings
Follow up to 01cf61a

Numeric array keys are returned as integers.

echo "<references 2/>" | php bin/parse.php

Bug: T269748
Change-Id: I892753c330f95d258e0310626f109386fd020177
2020-12-09 16:05:12 +00:00
Arlo Breault 3c15454851 Refine adding module(style)?s in extapi
Bug: T269022
Change-Id: Ic2c56c554934ced2aea04317d988098ca840076f
2020-11-30 17:15:27 -05:00
Arlo Breault 6525d69200 Reconcile some ref errors cases with $hasFollow
Change-Id: I5e3a27366f177af6c221d57da6e31f28cc91bb0c
2020-11-25 13:51:37 -05:00
sbailey de5d806335 Cite error tag name defined in references not used before
Bug: T51538
Change-Id: Id89b3cc186de42e5e5c05f15d7546db9d64ec864
2020-11-25 13:50:25 -05:00
sbailey 703dc8dc05 Adding cite error ref in reference with mismatched group
Bug: T51538
Change-Id: I5492dbaebb7bca79e83be09fdcfe810eaef8c053
2020-11-24 17:22:56 +00:00
Arlo Breault 680df4379c Use inReferencesContent flag to get rid of processRefsInReferences
It's sufficient to handle this case in processRefs.

Also moves $referencesGroup to the ReferencesData instance, rather than
passing it around as a variable (inconsistently).

Change-Id: I8637e3ce644642259e353d0df3d9c0dbc3102c7b
2020-11-24 17:22:01 +00:00
Arlo Breault b88f9ca881 Fix porting bug from 005176a
Bug: T249742
Change-Id: Iabe86266c06b2cbc3c51b16b73d360a7182878f1
2020-11-24 10:54:23 -05:00
sbailey 4c7108f553 Adding cite error ref in reference no content defined
Bug: T51538
Change-Id: I4cdcf1a36f472f582812dbb5e7050c0ead614639
2020-11-23 18:32:26 -05:00
sbailey 1f0221e327 Add reporting of cite error of a ref in reference without name specified
Bug: 51538
Change-Id: I193d5583b31be32741088fb25c348878f34b5016
2020-11-23 23:30:14 +00:00
Arlo Breault e3ca32c9ff Add method to check if in references content
More specific than just embedded content, needed for adding errors in
follow up patches.

Change-Id: I4bf659cd208c3322870e3ea0126bda4a2a7037d8
2020-11-23 18:53:03 +00:00
Arlo Breault b664b64fcb Use $extApi->pushError for invalid references parameters
Follow up to 01cf61a

Change-Id: Ic4483f151d12352cc9e6f6094e4df442eabca376
2020-11-16 22:19:54 +00:00
Arlo Breault 2f1bbc1804 Only look for data-mw.body.id in the top level dom
Follow up to 6c15f6e where the same approach was taken in dom diff'ing.

Clarifies where the "id" is expected to point and the limitations of the
approach vis-a-vis embedded content.

For example,

<ref>hi ho</ref>
[[File:Test.png|<references />]]

won't roundtrip, and never did, because the references section the "id"
would point to is in embedded content.

This was really only ever about the case where the <ref> itself was
found in embedded content, like an image caption, and we wanted to find
a top level references section, like,

[[File:Test.png|<ref>hi ho</ref>]]
<references />

The one case old approach was ostensibly doing something smarter was if
both the references section and the ref were in the same embedded
content, as in,

[[File:Test.png|<ref>hi ho</ref><references />]]

However, at least for file captions, those were always serialized in a
fragment of the top level doc and suffer from same dropping as the first
example here.  Maybe some other embedded content is handled differently,
in which case this is probably an acceptable regression.

Change-Id: Ia90eadcc5099a8c27f0bf3fda0ce2f0effca7bcc
2020-11-10 21:56:16 +00:00
sbailey 01cf61ad67 Adding check for illegal attributes in references tag
Bug: T51538
Change-Id: I7dbc577a61abb660d2bdb66ead0d7b71fd66cf47
2020-11-10 19:47:04 +00:00
Arlo Breault 4310b6a243 Mark up cite errors in embedded content
It's a feature of named refs that we only know at the time of inserting
the references list whether they have content or not, and are therefore
in err.  The strategy of 4438a72 was to keep pointers to all named ref
nodes so that if an error does occur, we can mark them up.

The problem with embedded content is that, at the time when we find out
about the errors, it's been serialized and stored, and so any pointers
we might have kept around are no longer live or relevant.  We need to go
back and process all that embedded content again to find where the refs
with errors are hiding.

This patch slightly optimizes that by keeping a map of all the errors
for refs in embedded content so that only one pass is necessary, rather
than for each references list.  Also note that, in the common case, this
pass won't run since we won't have any errors in embedded content.

Bug: T266356
Change-Id: I32e7bfa796cd4382c43b3b1d17b925dc97ce9f7f
2020-11-06 18:31:26 -05:00
Arlo Breault b2e2732674 Switch some uses of matchTypeOf to hasTypeOf in Cite
Change-Id: I99986c337944547ae398851676de13377f4114b1
2020-11-06 13:14:04 -05:00
Arlo Breault c675396445 Fix adding 'cite_error_group_refs_without_references' to unnamed refs
Follow up to 02fb17d, which was only iterating over named refs.

Bug: T51538
Change-Id: I1a1ce39029c2e9e6e29e768675bcde266ccf3247
2020-11-06 13:14:03 -05:00
Arlo Breault 049735ba0e Clean up signatures of ref group accessors
No need to hedge on null.

Change-Id: I2afb7619a113d784741bd7d29eccf4d8368fe56f
2020-11-06 17:45:18 +00:00
Arlo Breault 0254f138ab Suppress linkbacks for all refs in embedded content
Not just for refs in references content, since they'll be equally
inaccessible everywhere.

Change-Id: Id0a2361b41d9b8103e011ff4f809fa0809169bb3
2020-11-06 17:45:16 +00:00
sbailey 095b2c2388 Add "reference" class to <sup> in addition to the "mw-ref" class
* Added, required adjusting many tests and knownFailures info.

 * Change impacted parserTests.txt as well, updated.

Bug: T265930
Change-Id: I79d915ebd811bdb83344bf7295862588fe7d46ea
2020-11-05 00:17:54 +00:00
Arlo Breault 1dda4cdc8a Consolidate adding ref errors at references insertion
Change-Id: I01ce55989fb7b822320c63ddad19c2edf7e03bf9
2020-10-29 15:54:30 -04:00
sbailey 02fb17d102 Refs in group with no <references group="xxx" />
* Generating error message in data-mw in affected refs

 * Cite test validates correctness of adding error to afflicted
   refs

 * Autogenerated references aren't considered erroneous
   (the extension to the legacy parser also generates them)
   and are not suppressed when serializing because apparently
   that's the behaviour Parsoid clients want.  However, in
   this patch we're marking up autogenerated references
   *with group attributes* as errors (the legacy extension
   doesn't generate them at all) and are choosing to suppress
   them when serializing since we considered them an error
   while parsing and don't want them to persist in the content.

Bug: T51538
Change-Id: Ia651b10449dc41c2cb439b33a361e8c8e482f502
2020-10-28 22:28:13 +00:00
Arlo Breault b5b3475d28 Set a top level doc when serializing
First step in using a single document for the serializing direction as
well.

Bug: T265061
Change-Id: Ia845faed693bf4c6f74facc7576d01a9f5a875be
2020-10-28 18:48:17 +00:00
Arlo Breault 568034a00c Traverse with inEmbeddedContent for ref in ref
While, for the most part, content nested in refs will end up in the
references section and should be fine to maintain a linkback.  However,
if content differs from a previously named ref (ie. !== cachedHtml), it
ends up being serialized and nested in data-mw, so is also unsafe.

Bug: T266294
Bug: T266356
Change-Id: Ia92f42e06353c411b986d0665cbe6338052555fa
2020-10-23 17:52:51 -04:00
Arlo Breault 8e237b4e34 Make $inEmbeddedContent an explicit stack
Change-Id: I48ff2f7be352fdec72b2c5e0eeee843330ec3872
2020-10-23 11:42:45 -04:00
Arlo Breault b8d4bb1f37 Set inEmbeddedContent when running processRefsInReferences
In 47506af, serializing references content to be added to data-mw was
delayed until we were inserting the reference into the dom, to give us a
chance to mark up errors about not finding named ref content.  After
which, the content is cleaned out of references to make room for list
items that belong there.

In 6bd0594, we noted that we can't store linkback from embeded content
since the content is released after serializing and won't be available
when it comes time to mark it up with errors.

Similarly, the linkbacks added to other groups from the references
content won't be available after inserting that reference and so we
shouldn't be holding on to them either.  This means that we won't be
marking them up for the named error above but with the benefit that we
won't crash when trying to access these linkbacks from another group.

A test case is added which crashes trying to access a linkback from a
group that has already been inserted.

Note that the extension to the legacy parser considers referencing
another group from group content to be
"cite_error_references_group_mismatch".  If we choose to also do that,
we may be able to reverse this change.

Change-Id: Idf0e49fa07dc3614068793c72a30ce3de1e2392c
2020-10-23 11:42:25 -04:00
sbailey a8e299b21e Added cite error checks for numeric digit in name
* Note: the <ref name="1"> numeric is flagged as an error, but
   <ref follow="1"> is not flagged as well as it would be duplicitous.
   We are proposing that Numeric digits as a name be changed to
   a warning as Parsoid Cite handles them properly without error.

   Background: The core Cite extension started off not allowing numeric
   names because the data structure they used made it inconvenient,
   but Parsoid Cite has a separate index for named refs.
   The core Cite devs thought there was potential for a conflict in
   the ids if numeric names were allowed. The ids that core uses
   follow the pattern:
     for no name defined:  cite_ref-1             cite_ref-2
     for name="refname":   cite_ref-refname_3-0   cite_ref-refname_3-1
   so for name="1" at worst you might see ids like:
     cite_ref-1  or  cite_ref-1_2-0
   so that does not produce conflicting IDs and isn't a concern,
   and that is the pattern that Parsoid Cite uses.

 * Error case of numeric in name and follow and two tests that
   validate errors.

Bug: T51538
Change-Id: I95d725d0f77abadc1ddb2dd6939762b7d322e4f2
2020-10-15 23:57:16 +00:00
Thiemo Kreuz 27c5632ebd Compact trivial arrays in test providers
This is meant to make the code easier to read.

Change-Id: Ib684bf64acfbac9b458d110d9ccff2d071b993be
2020-10-08 11:07:35 +02:00
sbailey aadef667d4 Added cite error checks for invalid text direction
* Error case of dir= not ltr or rtl is caught and a cite tests
   validates the new check.

Bug: T51538
Change-Id: I8c7e088416f0a000e638771a3fe5e8e0c58bcc23
2020-10-07 13:22:46 -07:00