Commit graph

4620 commits

Author SHA1 Message Date
Translation updater bot 9b11e93bbe Localisation updates from https://translatewiki.net.
Change-Id: I04ba74f6fae07793f3a3180b204f3fbe89b16949
2023-12-21 19:45:01 +01:00
Adam Wight 4ed93908a3 Ref sequence vs. key
Internal ref key is always an int, but another string `key` is
created in the formatters.  This patch makes the typing explicit.  We
can distinguish between these two different values in a later patch.

Bug: T353451
Change-Id: Id5e40517705961f4d54622e91264430d9f62008d
2023-12-21 10:03:18 +01:00
Translation updater bot daf9d7b71d Localisation updates from https://translatewiki.net.
Change-Id: I9eb5ff99f40b2db8956a4c95f17a20b8bb0e06bf
2023-12-20 14:04:30 +01:00
thiemowmde 6321074484 Remove redundant PHPDoc blocks that are identical to the code
Thanks to strict types and a recent MediaWiki CodeSniffer update a
lot of the PHPDoc comments in this codebase became redundant. Only
very few comments in this codebase contain additional information.
Such comments don't add any new information to what the code alone
already says. We started removing them in many other codebases
already.

In case someone wants to add more documentation to a method the
basic PHPDoc block can usually automatically be generated with a
button press in the IDE.

The only additional change in this patch is that I occasionally
add a missing `void` return type. This is necessary to be able to
remove the comment.

Change-Id: Id7d6d6a437175a9d017f564daf7ed16e76f09158
2023-12-19 17:10:23 +01:00
thiemowmde 3a128dce4b Use correct Sanitizer method for id/fragment escaping
Same as Idf50dad in the Cite extension.

Bug: T298278
Change-Id: Idde6c21e083f42642c3dd2fe64bbd3c4d2b63847
2023-12-19 15:38:36 +00:00
thiemowmde 8094a0ebf5 Move property initializations from constructor to property
This is doing the same as before, in pretty much the same execution
order. The only difference is the syntax.

In JavaScript it's relevant to not do array initializations to early.
Otherwise different instances share the same array. But this doesn't
happen in PHP.

Change-Id: I56363ccadf29f2b806f765ab8f54a3c1863fc10f
2023-12-19 14:57:12 +00:00
thiemowmde bb01b0d74b Merge two code paths about <references> sections
I'm not sure how much this helps. But this merges two code paths
that are both about "we are in the middle of a <references> section
right now.

Nothing changes, as proven by the tests.

Bug: T353266
Change-Id: I446e224b81d35c47736a437d78527c0cc8636f77
2023-12-19 15:04:08 +01:00
thiemowmde d73a76dce6 Rename appendText() to resolveFollow()
There is only 1 user left after Icf16965.

Bug: T353266
Change-Id: I4cafdcbe0a23dd7950613a385cb552e7a84e7f26
2023-12-19 14:49:52 +01:00
thiemowmde b181614ba1 Show warning when dir="…" don't match
This classifies as a "warning" because we still show everything,
just with an error message appended.

Disabling the Parsoid tests right away hopefully makes it easier to
do the same change in Parsoid.

Bug: T202593
Depends-On: If14acd1070617ca8c4d15be6b1759bd47ead4926
Change-Id: I294b59f989f553932b40d08308906dd72d92d2cd
2023-12-19 14:17:30 +01:00
Subramanya Sastry 58f008ae1e Sync up Cite repo tests with Parsoid + (en/dis)able some Parsoid tests
* This now aligns with Parsoid commit 0fab92ba453d424aedeadaaa9e1514c42bbd94d1
* Disabled the newly added tests because that Parsoid fixes for the
  tests haven't been released to vendor to let CI pass these tests.
* Re-enabled a previously disabled test.

Change-Id: I4ab87d2d486b7a1fef652c50c4f1e79ddfe83ce6
2023-12-18 16:35:01 -06:00
thiemowmde eeb8e28e52 Remove obsolete comment about Sanitizer::safeEncodeAttribute
By now I'm sure this really doesn't belong here. The code in the Cite
extension is doing this because it generates HTML by concatenating
plain strings. In such a context the necessary HTML entity encoding
(&quot; and such) must be done manually. Here in the Parsoid context
this is not needed.

This is split from I7249bd0. See the discussion over there.

Change-Id: I5589e5c2147bfc9f205a0ff80d8bdd247ab49c63
2023-12-18 21:02:36 +01:00
Translation updater bot e64d944194 Localisation updates from https://translatewiki.net.
Change-Id: Ice9b812492a0bce8ef003413a66501d9db1c75e2
2023-12-18 18:16:28 +01:00
jenkins-bot 9b87bc717d Merge "Various cleanups to PHPUnit test mock setup" 2023-12-18 12:36:11 +00:00
jenkins-bot d79ae15bd0 Merge "Add basic class-level documentation to more classes" 2023-12-18 12:35:58 +00:00
jenkins-bot a10437ad1d Merge "Avoid the term "book referencing" in a few places" 2023-12-18 11:58:33 +00:00
jenkins-bot 4cc26a8fa7 Merge "Separate ReferenceStack::appendText() from setText()" 2023-12-18 11:58:29 +00:00
jenkins-bot 3bf67a3648 Merge "Track warnings separately in ReferenceStack" 2023-12-18 11:58:26 +00:00
jenkins-bot f112648cb2 Merge "Revert "Revert "Temporarily disable a Parsoid test to let us change code in Parsoid""" 2023-12-15 21:14:43 +00:00
Subramanya Sastry 8ac343718b Revert "Revert "Temporarily disable a Parsoid test to let us change code in Parsoid""
This reverts commit b163add15b.

Reason for revert: This was my mistake. I forgot that reverting this
would break Parsoid CI once the Parsoid Cite patch merged. So, I have to
wait till the Parsoid Cite change is released to vendor before I sync
the test change here.

Change-Id: Icaecee1e56907980681aae01be377b6906bd93a6
2023-12-15 20:36:43 +00:00
jenkins-bot 708436c998 Merge "Revert "Temporarily disable a Parsoid test to let us change code in Parsoid"" 2023-12-15 19:24:05 +00:00
jenkins-bot d5fe9559e7 Merge "Temporarily disable a Parsoid test to let us change code in Parsoid" 2023-12-15 19:10:57 +00:00
Subramanya Sastry 0754bc9ffd Fix encoding of non-breaking spaces if found in ref names
* This partly replicates the fixes in I9435a2d and Ia01f2fd. More
  to be done in later patches.
* Updated html/parsoid test output (which matches the change in the
  html/php section).

Depends-On: I401656265253a429691cc76adc5db5b129cff2cc
Change-Id: I7249bd03a7942ff7725a20178a051300b777e3a8
2023-12-15 16:38:24 +00:00
thiemowmde 54ac87e5ce Separate ReferenceStack::appendText() from setText()
This moves one more error situation into the stack class, together
with other error situations that are already there.

Bug: T353266
Change-Id: Icf169650f67f64e6d29d175c3b47cf558b8de3d4
2023-12-15 16:41:05 +01:00
thiemowmde 742a9ffbf5 Track warnings separately in ReferenceStack
Check out how this gets rid of so many "to do" as well as
"deprecated" comments.

Next qustion: The elements in the stack become more and more
complicated. It's probably worth converting them from arrays into
first-class objects. But this is for another patch.

Bug: T353266
Change-Id: If14acd1070617ca8c4d15be6b1759bd47ead4926
2023-12-15 16:41:04 +01:00
thiemowmde 13138d4ed0 Avoid the term "book referencing" in a few places
We are discussing this for a long time and finally renamed the tag
on Phabricator: https://phabricator.wikimedia.org/tag/cite-extends

This patch updates only places where it can't have any negative
consequences.

This is also a direct follow-up to Ic73f1b7 where this class was
created.

Bug: T353269
Change-Id: I644fe41d3386b9bf02b83366654301633efd535f
2023-12-15 15:49:04 +01:00
xiplus f7a181ed42 Give a different error from too_many_keys when 'follow' attribute conflicts
Add message "cite_error_ref_follow_conflicts" for tags with
conflicting parameters.

Bug: T299280
Change-Id: Ie64f4ab4831966f66f812ea67cc244718f818afb
2023-12-15 15:23:53 +01:00
thiemowmde e7dea09216 Add basic class-level documentation to more classes
Bug: T353227
Change-Id: I3953543a111121cc49f6ea89988351b80b03e828
2023-12-15 14:27:58 +01:00
thiemowmde 9304e24551 Various cleanups to PHPUnit test mock setup
For example, use convenient upstream methods, and generally make the
test setup a bit more readable.

Bug: T353227
Change-Id: Ifab71041fcc3f804315793ca7b783f84829c7a0f
2023-12-15 11:45:35 +00:00
thiemowmde 4377f0923d More simple and consistent @covers and @license tags
Same arguments as in Iafa2412. The one reason to use more detailled
per-method @covers annotations is to avoid "accidental coverage"
where code is marked as being covered by tests that don't assert
anything that would be meaningful for this code. This is especially a
problem with older, bigger classes with lots of side effects.

But all the new classes we introduced over the years are small, with
predictable, local effects.

That's also why we keep the more detailled @covers annotations for
the original Cite class.

Bug: T353227
Bug: T353269
Change-Id: I69850f4d740d8ad5a7c2368b9068dc91e47cc797
2023-12-15 12:12:16 +01:00
thiemowmde d0d5fbbee6 Add temporary ErrorReporter::firstError helper function
I hope this makes other refactorings a little easier.

Bug: T353266
Change-Id: Ib574d4d54ba2c8bc1310822539336ad71c4309ef
2023-12-14 17:16:49 +01:00
thiemowmde 01dcfbac47 Move Validator tests to a separate class
I wanted to make this a unit test but it turns out the
Sanitizer::safeEncodeAttribute() calls currently make this
impossible.

Bug: T353269
Change-Id: I5266e7b8b67db1c812dc9e4675d0c079ab1f9a40
2023-12-14 15:51:26 +00:00
jenkins-bot 6fc8ee7fec Merge "Get rid of "guarded <references>" terminology" 2023-12-14 14:25:57 +00:00
jenkins-bot 9ec01ef894 Merge "Introduce named constant for "__placeholder__" string" 2023-12-14 14:20:14 +00:00
jenkins-bot 78b40a8c6b Merge "Extract validation to a separate class" 2023-12-14 14:18:40 +00:00
thiemowmde cb71e87b0e Introduce named constant for "__placeholder__" string
This is a concept that's only relevant when a sub-reference (formerly
known as BookReferencing) appears before the parent reference it
belongs to. Let the name reflect this.

Bug: T353227
Change-Id: Iabf259e72942ea70cb1cc1e0ca5a5d8cf15d7225
2023-12-14 09:45:06 +01:00
thiemowmde c794962df7 Use short fn() syntax in tests where it makes sense
We can use this syntax now. It was introduced in PHP 7.4.

Bug: T353269
Change-Id: I5404b33b654efb01171fa2b4ad3925170ffd0e56
2023-12-14 08:05:01 +00:00
jenkins-bot 5b4e869014 Merge "tests: Widen @covers annotations" 2023-12-14 07:57:46 +00:00
thiemowmde 12c7ad7504 Get rid of "guarded <references>" terminology
This patch only moves existing code around without changing any
behavior. What I basically did was merging the old "guardedReferences"
method into "references", and then splitting the resulting code in
other ways. Now we see a few other concepts emerging. But the idea
something would be "guarded" (how?) is gone.

The most critical detail in this patch are the new method names, and
how the code is split. The names should tell a story, and the methods
should do exactly what the name says. Suggestions?

Bug: T353266
Change-Id: I8b7921ce24487e9657e4193ea6a2e3e7d7b0b1c3
2023-12-14 08:44:40 +01:00
thiemowmde a6a0f66130 Extract validation to a separate class
This removes almost 200 lines from the main class.

This patch intentionally doesn't make any changes to the code but
only moves it around. Further improvements are for later patches.

Bug: T353269
Change-Id: Ic73f1b7458b3f7b7b89806a88a1111161e3cf094
2023-12-14 07:43:29 +00:00
Translation updater bot 428494cd82 Localisation updates from https://translatewiki.net.
Change-Id: I876220af9cc824740b1ab30132cbb5b9f2af4632
2023-12-14 08:27:12 +01:00
jenkins-bot bf53249893 Merge "Move a bit of code out of Cite::guardedReferences" 2023-12-14 02:10:06 +00:00
jenkins-bot 61850c091a Merge "Remove PHPDocs that just repeat what the code already says" 2023-12-14 02:04:15 +00:00
Timo Tijhof 2ff327df53 tests: Widen @covers annotations
> We lose useful coverage and spend valuable time keeping these tags
> accurate through refactors (or worse, forget to do so).
>
> I am not disabling the "only track coverage of specified subject"
> benefits, nor am I claiming coverage in in classes outside the
> subject under test.
>
> Tracking tiny per-method details wastes time in keeping tags
> in sync during refactors, and time to realize (and fix) when people
> inevitably don't keep them in sync, and time lost in finding
> uncovered code to write tests for only to realize it was already
> covered but "not yet claimed".

https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:%2522Widen%2522

Change-Id: Iafa241210b81ba1cbfee74e3920fb044c86d09fc
2023-12-14 01:54:48 +00:00
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
Translation updater bot 7ef1d0d009 Localisation updates from https://translatewiki.net.
Change-Id: I1e7405edbd415fc2392fa73f4aa4917a48410c9d
2023-12-13 08:40:31 +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 689bafdd7f Use upstream assertStatusError and such in tests
The main benefit is that these methods give good debug output in
case they fail.

Bug: T353266
Change-Id: I0423737240c35c18078863a7eb1d8e4779363973
2023-12-12 19:16:50 +01: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 739e05e151 Merge "build: Update linter libs" 2023-12-12 14:45:22 +00:00