Commit graph

84 commits

Author SHA1 Message Date
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
Thiemo Kreuz 9565d6e887 Resolve a TODO by covering it with a test case
It turns out this is indeed necessary. The test demonstrates why.

Change-Id: Id9c6a48f72ef8d3f0cc9a714d826418e69913b0a
2020-01-21 10:11:03 +00:00
Thiemo Kreuz 2da4305cd9 Simplify initialization in ReferenceStack::pushRef
Change-Id: I52b0f891e41a0d0b25ac0aade0d4f4fcc4dcd2f2
2020-01-21 08:22:24 +01:00
Adam Wight b3ea9f4ef8 Relax empty-string name validation
Allow a ref with `name=""` for backwards-compatibility.
Partially reverts I07738cce2641026dfaa92ba263ed6f9834be0944

Bug: T242437
Change-Id: Iaed2d1c41be377a4961aff39838b0965f6c00616
2020-01-20 12:40:09 +00:00
jenkins-bot 6d02c1569d Merge "Final clean-ups for a more consistent parameter order" 2020-01-09 12:44:55 +00:00
jenkins-bot 953030386a Merge "Replace all # single line comments with //" 2020-01-09 11:40:24 +00:00
jenkins-bot 9bbaeb6f24 Merge "Consistent empty lines between @param and @return PHPDoc tags" 2020-01-09 11:40:23 +00:00
jenkins-bot 89df0f1c62 Merge "Simplify a for-loop in ReferenceStack" 2020-01-09 11:40:02 +00:00
jenkins-bot 0be582dc12 Merge "Report conflicting extends="…" with an error message" 2020-01-09 11:37:27 +00:00
Thiemo Kreuz 013e1bfa90 Final clean-ups for a more consistent parameter order
* Always have an empty line between @param and @return to improve
readability as well as consistency within this codebase (before, both
styles have been used).

* Flip parameter order in validateRefInReferences() for consistency with
the rest of the code.

* In Cite::guardedRef() the Parser was now the 1st parameter. I changed
all related functions the same way to make the code less surprising.

* Same in CiteUnitTest. This is really just the @dataProvider. But I feel
it's still helpful to have the arguments in the same order everywhere, if
possible.

* Add a few strict type hints.

* It seems the preferred style for PHP7 return types is `… ) : string {`
with a space before the `:`. There is currently no PHPCS sniff for this.
However, I think this codebase should be consistent, one way or the other.

Change-Id: I91d232be727afd26ff20526ab4ef63aa5ba6bacf
2020-01-09 12:13:54 +01:00
Thiemo Kreuz 04c5773953 Replace all # single line comments with //
There is currently no strict CodeSniffer rule for this. I think we
need to have one sooner or later. Anyway, what I find important is to
have a consistent code style in one codebase.

I refused to do this change previously because I don't like to mess
with Git blame if it's not really necessary. However, at this point all
code was moved around anyway.

I ended removing a comment that appears misplaced now, and doesn't help
maiing the code more readable. I like not having a dot at the end if
it's not really a sentence.

Change-Id: Id1d4f43277c69080c512c1a5ceff4c948bfa05be
2020-01-09 12:13:34 +01:00
Thiemo Kreuz 446524f8a9 Consistent empty lines between @param and @return PHPDoc tags
In the end I don't care much if we agree on having this newline, or
not. What I care about more is that this codebase is consistent.

Personally I prefer having the newline. It creates a visible separation
between what "goes in" and what "goes out" (@throws and @return).

Change-Id: Ibc60af621132e415a5579397c01688fa21eb0be5
2020-01-09 12:00:35 +01:00
Thiemo Kreuz 04fbbbd3ca Report conflicting extends="…" with an error message
Bug: T242110
Change-Id: I04342b2c219981dfb9575ea58cfccf6c2ba1066c
2020-01-08 16:47:07 +00:00
Thiemo Kreuz d07110b790 Fix incomplete undo/redo stack implementation
The rollback feature was not able to properly restore a __placeholder__.
That's why a specific use case was behaving different. This already
worked just fine:

<ref extends="a">…</ref>
<references>
<ref name="a">…</ref>
</references>

But this didn't, even if it is the exact same from the users
perspective:

<ref extends="a">…</ref>
{{#tag:references|
<ref name="a">…</ref>
}}

Bug: T239810
Change-Id: I163a1bffb9450a9e7f776e32e66fb08d0452cdb9
2020-01-08 17:43:02 +01:00
Thiemo Kreuz 87642f4fb8 Simplify a for-loop in ReferenceStack
The main motivation is to remove the not needed variable $i. As well
as getting rid of the break.

Change-Id: Idd9f83c2166b1c0da7054a616cd8c3d5540ebc12
2020-01-08 16:55:49 +01:00
Thiemo Kreuz 6ddfd9983b Fix bad numbering when reusing sub-references
Note this leaves *another* bug behind. When a <ref> is properly reused
by name="…", and the content is fine (either missing or identical),
possibly conflicting extends="…" attributes are currently entirely
ignored. However, this is already much better than what happened before.

Bug: T242110
Change-Id: Id808ce31c8036cc290f68bb3e8c5a7b12f4f44cf
2020-01-07 16:34:05 +01:00
jenkins-bot 44f3f5bf44 Merge "build: Updating mediawiki/mediawiki-phan-config to 0.9.0" 2020-01-07 03:47:57 +00:00
Adam Wight 2aed80be24 Consolidate refCallStack-gnosticism
The rollbackRefs function no longer needs to "know" details about
how to turn a refCallStack item into a redo item.  This is better a
responsibility of the subroutine, where the items are unpacked.

Change-Id: I1e2ff77cb5e66d70e451ee09e641ff752c770ab4
2020-01-06 12:43:16 +00:00
libraryupgrader 2e0792a0dd build: Updating mediawiki/mediawiki-phan-config to 0.9.0
One of the most significant changes is when I noticed that the $group
can never be null. We set it to DEFAULT_GROUP before. That's an empty
string.

I'm not very happy with the two @phan-suppress-next-line. Is there a
better way to fix these lines?

Change-Id: I33c1681e2f3857cb6701da71f4ed8893caff4d1e
2019-12-27 19:45:17 +00:00
Adam Wight 2a3879eafa Harden logic assertions
These should be impossible conditions, we don't want to continue with
processing.

I hate this patch, it's a temporary workaround until someone rewrites
or replaces the rollback logic, for example with a two-pass parse.

Change-Id: I6a1327e397d4272fa412c3f290c2107d867d2854
2019-12-20 14:53:29 +01:00
Thiemo Kreuz 028424a682 More function call argument unpacking
I hope this patch is not to horrifying and can be reviewed. It's
possible to split this into a sequence of smaller patches. Please
tell me.

Change-Id: I4797fcd5612fcffb0df6c29ff575dd05f278bd4d
2019-12-19 12:58:02 +01:00
jenkins-bot 347ad9fb5f Merge "Change order of elements in the refs call stack" 2019-12-19 10:30:35 +00:00
Thiemo Kreuz 38fe3665e5 Change order of elements in the refs call stack
The main benefit is this nifty call: `$this->rollbackRef( ...$call )`

To make this possible, the minimal change I needed to do was to move
the two $argv and $text arguments to the end.

I also tried to order all other arguments as good as I could: Required
first, optional later. Group and name together. Name and extends
together.

All this is private implementation and should not affect anything.

Change-Id: I7af7636c465769aa53122eb40d964eabdd1289ba
2019-12-19 09:27:15 +01:00
Thiemo Kreuz 5c65525c95 Introduce ReferenceStack::appendText
I feel this is a little better than before. It looks like we never need
to *replace* a text that existed before.

This depends on I4a156aa which fixes one of the last remaining trimming
issues. Outside of <references>, a <ref> </ref> with no other content
but some whitespace was already forbidden. But not inside of <references>.
This is relevant for appendText(). It should not be called with null, but
was because of the inconsistent behavior.

Change-Id: I38c9929f2fa6e69482e45919e2f8dbf823cb1c8b
2019-12-19 08:52:48 +01:00
Thiemo Kreuz 51ff3cc819 Several code cleanups after getting rid of cloning
* Use the Html class to safely create HTML code.
* $this->referenceStack can not be null any more.
* $this->inReferencesGroup is not needed during output, only when
  parsing tags.
* Replace ReferencesStack::getGroupRefs() as well as deleteGroup()
  with a combined popGroup() that does both things.
* Extract the code responsible for the "responsive" behavior to a
  separate function.
* Some TestingAccessWrapper are not needed.

Change-Id: Ie1cf2533d7417ae2f6647664ff1145e37b814a39
2019-12-16 15:47:23 +01:00
Adam Wight ab07a3253c Remove Parser state from CiteErrorReporter
Finishes breaking the circular reference between Cite and Parser.

This patch also demonstrates how evil it is to allow the error reporter
to be called from anywhere, and have side-effects.  At least it's explicit
now.

Also fixes a bug where the inner error message would not be in the
interface language.

Bug: T240431
Change-Id: Ic3325cafb503e78295d72231ac6da5c121402def
2019-12-12 11:15:07 +01:00
Adam Wight a227395e3a Lazy instantiation of Cite
Only create a Cite object if we need one.  Never clearState, just
destroy and recreate later.

This makes it less likely that we leak state between parsers, and
saves memory and processing on pages without references.

It's also preparation to decouple Cite logic from state.

Change-Id: I3db517591f4131c23151c76c223af7419cc00ae9
2019-12-12 11:12:17 +01:00
Thiemo Kreuz 3f2aeb7e31 Rename two Cite… classes and clean up test setups
* All classes are in a Cite\ namespace now. No need to repeat the word
"Cite" all over the place.

* The "key formatter" is more an ID or anchor formatter. The strings it
returns are all used in id="…" attributes, as well as in href="#…" links
to jump to these IDs.

* This patch also removes quite a bunch of callbacks from tests that
don't need to be callbacks.

* I'm also replacing all json_encode().

* To make the test code more readable, I shorten a bunch of variable
names to e.g. $msg. The fact they are mocks is still relevant, and still
visible because these variable names are only used in very short scopes.

Change-Id: I2bd7c731efd815bcdc5d33bccb0c8e280d55bd06
2019-12-12 08:48:02 +01:00
jenkins-bot 69a8754e31 Merge "Rename "index" parameter to "key"" 2019-12-11 16:25:30 +00:00
jenkins-bot 97e144755d Merge "Rename "key" variable to "lookup"" 2019-12-11 16:25:29 +00:00
Thiemo Kreuz 83fc992159 Rename $type to $action in rollbackRef()
We call this an action when creating elements on the refCallStack.

Change-Id: I50e9df2f396060623e7e6b6deda086783709712b
2019-12-10 16:04:59 +01:00
jenkins-bot aa12b53e3e Merge "Comment about annoying thing" 2019-12-09 13:13:49 +00:00
Adam Wight 7e4ef22142 Rename "index" parameter to "key"
This is consistent, we check its value against $ref['key'].

Change-Id: Ie25edf4535893d3bb209920dfb3ebe089ee38cea
2019-12-09 13:26:22 +01:00
Adam Wight 4c045c897e Rename "key" variable to "lookup"
The concept "key" already exists in the structure handled by this
function, so to have a $key which means something else was distracting.

Change-Id: I91a76edbb42a1ab6514bc706b75ab89f78539fa5
2019-12-09 13:24:25 +01:00
jenkins-bot 740bd24178 Merge "Rename field to "key"" 2019-12-09 12:21:18 +00:00
Adam Wight 3e728799c2 Comment about annoying thing
Change-Id: I3c7f85bd822391d4e63314c0829ea1668d30a4ce
2019-12-09 12:56:58 +01:00
Adam Wight d6c0155e4c Rename field to "key"
This is consistent with the fact that it contains $ref['key'].

Change-Id: I134dba4a2405bb44b785e9cf191adc7bdd54c0d1
2019-12-09 12:52:26 +01:00