Commit graph

120 commits

Author SHA1 Message Date
Umherirrender 875b747d3c Replace isset() with null check
isset() should only be used to suppress errors, not for null check.
When the variable is always defined, there is no need to use isset.
Found by a new phan plugin (2efea9f989)
https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP#isset

Change-Id: I2eee98fdcb21192108183c431b10e0072b951f72
2024-10-27 14:36:26 +01:00
Umherirrender 411ee7efad Use namespaced classes
Changes to the use statements done automatically via script

Change-Id: I0768f296b528c81edd6bd9ac7d76515b15f3da6f
2024-10-19 23:25:16 +02:00
thiemowmde e4728d7d91 A few tiny code cleanups in the ReferenceStack class
Change-Id: I5feeba61da7e45dad1273cc9eb0b7674fa14e3f0
2024-05-16 14:39:03 +02:00
Adam Wight fa4a3c9405 Only increment sequence when we really mean it
I prefer this to having a mix of roll forward/roll back logic.

Change-Id: I9ac7c2ecf302c4d245a8fda7ed57f14cfb26757c
2024-01-10 13:40:41 +01:00
Adam Wight 9d64d837f1 Simplify "follow" block
There was no need to create a new variable here.

Change-Id: I034bc47c07be3ee716c9a1019addb93f0fb2910a
2024-01-10 13:14:06 +01:00
Adam Wight c36d1b90a5 Move extendsCount into parent ref item
Eliminates a complex shared structure in favor of more encapsulation.

Change-Id: I70efabf0ee263ac578472e16dc35047b0601b7ff
2024-01-10 11:55:16 +01:00
Adam Wight 12cd4b979e Test explicitly for parent ref existence
This test was obscured by testing for a field on the parent, but that
would exist if and only if the parent also existed.  Clarify the
guard condition and introduce a named local variable for the parent.

Change-Id: I03079f45cf5ba00d54642c89ac4232a944b2f353
2024-01-09 17:30:10 +01:00
Adam Wight 0e01e39061 Encapsulate ref: groupRefs returned as objects
This patch only affects the consumers of groupRefs.

Bug: T353451
Change-Id: I1eff735dbc26dda07aa8ac7af9ea4ddc0906f5a4
2024-01-09 10:22:04 +01:00
Adam Wight f148c65078 Encapsulate ref: pushRef returns an object
This patch affects a few methods which use the output of pushRef.

Bug: T353451
Change-Id: I10b3fe89406c11cdaede92f18a4b96586ecaf5a0
2024-01-09 10:18:57 +01:00
Adam Wight 262fbe24eb Encapsulate ref object: limited to ReferenceStack
This encapsulation gives us field name, type validation and code
documentation.

This patch only affects ReferenceStack and continues to return
approximately the same array outputs to callers.  Some additional
information is included and the placeholder column has a new name.

Bug: T353451
Change-Id: I405fe7ac241f6991fd4c526bfbb58fbc34f2e147
2024-01-09 09:59:16 +01:00
Adam Wight c23b824c34 Reorder conditions
The placeholder field will only be set if the ref exists, so we can
put these in a more logical order.

Change-Id: I2ddfb501fcc3aca936bb45c0d40e4f68c5d2b192
2024-01-09 09:57:03 +01:00
Adam Wight 1434dc5ca6 Switch to a 1-based "count"
The previous patch deprecated the last conditional depending on magic
meanings of 0 and -1, so now we're free to let "count" take on a more
natural meaning: the number of times a footnote mark appears in
article text.

Includes a small hack to avoid changing parser output, by
artificially decrementing the count by one during rendering.  The
hack can be removed and test output updated in a separate patch.

Bug: T353227
Change-Id: I6f76c50357b274ff97321533e52f435798048268
2024-01-08 11:45:36 +01:00
Adam Wight 6b0ebb3066 Reduce deeply nested variables
These can be hard to read so this patch introduces named, temporary
variables.

PHP reference assignment is helpful here, and has the nice property
of responding correctly to `isset` as if it were called on the
referenced variable.  However, we're prevented from using this trick
in more places in the code because of an unfortunate side-effect that
PHP will store `null` under the referenced array key.  In some cases
(the ones here), this is harmless because we always test using
`isset` and null behaves the same as an unset value.  In other cases
such as arrays that are iterated over, the spurious key and null
value would be more of a nuisance.

Bug: T353227
Change-Id: Ie43592a2f10677ba19842e92fa29eb4bf3be240c
2024-01-06 16:39:46 +01:00
Adam Wight a6cb979d88 Inline constant for "placeholder" key
Minor refactoring of an internal field, which can be treated like the
other columns.

Change-Id: I255578694c5ab9f2ad3cbe232217af3cea60669c
2024-01-05 11:22:30 +00:00
Adam Wight fd648aec98 Store group in ref items
Encapsulate all information about a ref inside of the internal
structure, rather than relying on the container to be organized by
group.

Bug: T353451
Change-Id: I4c91e8089638b7655bf120402a4a5fcbd1b35452
2024-01-05 11:22:12 +00:00
Adam Wight 76e6e870d4 Include more information in missing parent placeholder
This allows the subreferences to be collected together under a heading.

Bug: T353451
Change-Id: Ibf28f0baca14de8140c87b03ad4aa86d2f81a20d
2024-01-05 11:21:12 +00:00
Adam Wight 5a69c54900 Render list-defined parent without a backlink
In this case, there was never a ref with this name in the article so
no backlinks should be rendered.

TODO:
* test case with empty parent backlink and LDR parent

Bug: T353451
Change-Id: I8a7abd05a48ce83da3beb92b15e894d53252bd33
2024-01-05 12:07:22 +01:00
jenkins-bot ab20cb3cdf Merge "Rename appendText() to resolveFollow()" 2024-01-04 15:29:44 +00: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
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
jenkins-bot 9ec01ef894 Merge "Introduce named constant for "__placeholder__" string" 2023-12-14 14:20:14 +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 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
jenkins-bot bf53249893 Merge "Move a bit of code out of Cite::guardedReferences" 2023-12-14 02:10:06 +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
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
Adam Wight 62497db444 Constants for internal enum
Change-Id: I6864bc7761abe653ab1f591c26e61a8ffb1ea3b6
2023-12-12 10:02:00 +01: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
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
libraryupgrader a3babf81e3 build: Updating mediawiki/mediawiki-phan-config to 0.12.0
Change-Id: I70f1a3ef9e5a10edaf5a8dc9f3e272f99021b9c5
2022-10-09 19:48:09 +00:00
libraryupgrader 0af1a039b0 build: Updating mediawiki/mediawiki-codesniffer to 37.0.0
Change-Id: Ia399fafc5280aab1c0cfc129529a822e8d8f8382
2021-07-22 12:34:32 +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
Thiemo Kreuz 7fbd5de7f5 Merge two code paths related to follow
This patch also adds a test case that was missing before. If a
follow="…" is followed by another, normal <ref>, the internal key
(a.k.a. $this->refSequence) is not incremented. This was the case
before, just not covered by any test.

Change-Id: I102d1e67a6918017acc7e4a4663b08c828d101a6
2020-05-12 10:52:08 +02:00
Thiemo Kreuz 53b043f28f Remove not needed code without changing anything
This removes a few tiny pieces of code, and a large chunk related to
incomplete follow="…" attributes (see T240858). It turns out we don't
need to insert elements at the top of the ReferenceStack::$refs
array, because this array is reordered anyway in
ReferencesFormatter::formatRefsList()!

Incomplete follow refs don't have a number, and are ordered to the top
because of this, as before. This doesn't change with this patch.

Change-Id: I43036420be22feb8f0f287d9ccee2afd317df2a9
2020-03-31 18:15:14 +02:00
libraryupgrader 81e6643baf build: Updating composer dependencies
* mediawiki/mediawiki-phan-config: 0.9.0 → 0.9.1
* mediawiki/minus-x: 0.3.2 → 1.0.0

Change-Id: Ica218e63fd747980b7acc39ac7403f19239fa861
2020-02-19 01:25:06 +00:00
Thiemo Kreuz 400ce89f30 Don't talk about follow being "broken" but "incomplete"
Bug: T240858
Change-Id: Iab6563fdf19d6e85795911e4140476fceabf7334
2020-02-05 16:38:49 +00:00
Adam Wight eb799af3df Revert "Remove broken "follow" special case from ReferenceStack"
This reverts commit d01cba60fb.

Bug: T240858
Change-Id: I5b528a285ed6a658ceb333b58f0f4a81a64c7f15
2020-02-05 11:42:26 +01:00
jenkins-bot ef65edf6e9 Merge "Update documentation of ReferenceStack::$refs data structure" 2020-02-03 15:11:12 +00:00
jenkins-bot 74fab9755f Merge "Remove one unnecessary LogicException from ReferenceStack" 2020-02-03 14:50:40 +00:00
Adam Wight d01cba60fb Remove broken "follow" special case from ReferenceStack
This is unreachable now that broken follow refs fail validation.

Bug: T240858
Change-Id: I22adaee9c4eaeb94bee953ae15c642e044b6a54b
2020-02-03 12:27:59 +01:00
Thiemo Kreuz 563225d5f9 Update documentation of ReferenceStack::$refs data structure
Change-Id: Ie6e43b147c8eb7cfb67fecfa045b63f9011fcece
2020-02-03 12:25:03 +01:00
Thiemo Kreuz f6fb6024e3 Fix two warnings about possibly unset text variables
Change-Id: I4f79ea559697a671321f4bd276061a6956c9346b
2020-01-30 14:21:41 +01:00
Thiemo Kreuz 0fda08b25a Remove one unnecessary LogicException from ReferenceStack
This exception was introduced very late in the patch I38c9929. It
already caused trouble. This here is essentially a revert. It restores
the previous behavior where this edge-case was silently ignored. The
worst thing that can happen is that appendText() creates an incomplete
entry in the $this->refs array, which will be rendered at the end. The
user can see it then.

As of now we are not aware of a code path where this would even be
possible. Still this does make the code *more* robust by not making it
explode, but give the user something they can work with.

Bug: T243221
Change-Id: I2e2d29bbd557090981903fcc2ece8796fafa4aa4
2020-01-28 16:15:55 +01:00
Thiemo Kreuz 2ddc6f133b Fix incomplete rollback producing bad footnote numbers
Bug: T48140
Change-Id: I53ce5d8488d4c24d6f23f6f0e70806d7db4064e1
2020-01-24 13:02:53 +01:00
Thiemo Kreuz 6cb84a1829 Remove TODOs and FIXMEs that we are not going to fix
Change-Id: I588d9e8f74247adcb26ecdc14b49cf8056291a2e
2020-01-23 07:27:27 +00:00
jenkins-bot 7057c48e27 Merge "Simplify initialization in ReferenceStack::pushRef" 2020-01-21 10:59:23 +00:00