Commit graph

152 commits

Author SHA1 Message Date
Thiemo Kreuz c4c6eaa8df Collapse duplicate code in Cite::referencesFormatEntry()
Bug: T237241
Change-Id: Id4d9b453244f9c1d1577497439e39d3d7b58b5ff
2019-11-19 09:44:09 +01:00
Thiemo Kreuz 97ba23aae9 Fix indention and add comments to referencesFormatEntry()
Bug: T237241
Change-Id: I8aaef716dcc0c1c7a5d6bac9e90f779dbf86c795
2019-11-19 09:44:09 +01:00
Thiemo Kreuz e1519911d8 Avoid intermediate array when rendering a <references> list
I suspect this might save a bit of memory. Also makes the code easier
to read.

Bug: T237241
Change-Id: Id877834800780b3b8fe697b020e06be7e71daa14
2019-11-19 09:44:09 +01:00
jenkins-bot d306b9480f Merge "Reduce duplicate code in Cite::stack()" 2019-11-19 08:12:37 +00:00
Thiemo Kreuz 508f7a0564 Remove dead code from Cite::referencesFormatEntry()
Note how this code was broken since 2018 (Iff480bc). In this execution
path, $val is a string. There is no $val['dir'].

Luckily, this was dead code since 2008 already. See
https://phabricator.wikimedia.org/rECIT448a99da5108c26ce88d3df7cf5df2b5b5b1d1d3
line 283 on the right.

Bug: T237241
Change-Id: I671f3379a124a2644a9b0eac38d46c59106980a7
2019-11-18 16:44:11 +01:00
Thiemo Kreuz 19eefa5d71 Reduce duplicate code in Cite::stack()
Bug: T237241
Change-Id: If808d9f7f0b0c7f9ea07a1bcb295e8ca9647e96c
2019-11-18 16:34:42 +01:00
Thiemo Kreuz 7920ec3150 Pass ParserOutput as parameter to Cite::checkRefsNoReferences
Change-Id: Ibc4455dfde9f60bb27eac0d71064796878994bc5
2019-11-12 16:33:52 +01:00
jenkins-bot 0782f24d31 Merge "Make most existing Cite tests pure unit tests" 2019-11-12 14:44:24 +00:00
Thiemo Kreuz f94b400474 Make most existing Cite tests pure unit tests
1. Most existing CiteTests can be unit tests. They run so much faster
this way.

2. I modified some test cases to cover all trim() in the code.

3. The strict type hint in CiteHooks is removed because the parameter
is not used. Having a hard type hint for what is effectively dead code
makes the code more brittle for changes done outside of this codebase.

Change-Id: I1bff1d6e02d9ef17d5e6b66aeec3ee42bba99cf4
2019-11-12 14:56:40 +01:00
Thiemo Kreuz d8fbbd0037 Remove dependency on PPFrame from Cite class
This fixes a series of issues:
* There is nothing about a "frame" in the Cite class any more.
* There is no addModules() call in the Cite class any more.

Change-Id: I20c814d46c26825c5c07eab0a5586de3a531eee7
2019-11-12 13:06:39 +01:00
jenkins-bot 47e642fa27 Merge "Use __CLASS__ instead of repeating the class name" 2019-11-12 11:21:00 +00:00
jenkins-bot 59dba7e184 Merge "Remove lazy registration of Parser related hooks" 2019-11-12 11:20:57 +00:00
Thiemo Kreuz c9310ff7b4 Use __CLASS__ instead of repeating the class name
Change-Id: I97e9d973accd1d3467ed1f04af37e021e55783b3
2019-11-12 10:55:35 +00:00
Thiemo Kreuz 7ce10d7539 Remove lazy registration of Parser related hooks
To be honest I don't get why this lazy registration was done in the
first place. None of the 4 other hooks should ever be called before
the ParserFirstCallInit hook got called.

Also, under which circumstances can the ParserFirstCallInit hook be
called more than once?

Both scenarios would be wrong, as far as I'm concerned. Either I'm
missing something, or this code can indeed be simplified. Maybe it was
something to make it more compatible with older MediaWiki versions?

The only reason I can think of is: in all situations that do not
involve a parser, having the 4 extra hooks registered is pointless.
Does this waste space and/or runtime in the $wgHooks registry?

Change-Id: I5ef1495f4ce7bce940fa5f8e700af3d2c4851a01
2019-11-12 11:47:55 +01:00
jenkins-bot 9de8876ecf Merge "Remove an unused private variable" 2019-11-12 10:45:41 +00:00
Adam Wight 9d706047f3 Rename refines -> extends
Bug: T171581
Change-Id: I42b2d8859f2958357024cbba089715c10712f370
2019-11-12 10:19:17 +00:00
Adam Wight 8963536278 Remove an unused private variable
Change-Id: If52cc90bacee96afce4528f98d7f07f869d2acde
2019-11-12 11:15:47 +01:00
jenkins-bot c75fe5dccd Merge "Move $this->mParser setters up one level" 2019-11-12 09:58:02 +00:00
jenkins-bot 5ae75353e4 Merge "Don't use $this->mParser in Cite::saveReferencesData()" 2019-11-12 09:48:52 +00:00
Thiemo Kreuz 818e869b0b More narrow method signatures involving Parser
Change-Id: I2da717b9a8d104644c59a62b49090605c95323d6
2019-11-12 10:24:58 +01:00
Thiemo Kreuz bd72636b95 Move $this->mParser setters up one level
Two motivations:

1. I want the two deeper nested functions guardedRef() and
guardedReferences() to have less side effects.

2. In guardedReferences() guardedRef() is called. Both set the
property. That's redundant. The new code avoids this.

Change-Id: I48146f8b6d91122a904be0a552ffe3b03bc0481f
2019-11-11 20:16:05 +01:00
Thiemo Kreuz 960b6ed17f Don't use $this->mParser in Cite::saveReferencesData()
Main motivation is to make the code easier to test, and easier to
extract to smaller services.

Does this make sense? I'm not sure any more. One can argue that
everything Cite does happens in the context of a specific Parser. Why
shouldn't the code have access to this Parser?

Change-Id: I9d0cb44d96ec70a56af57f86aeb1f264f52c8bc4
2019-11-11 20:12:05 +01:00
jenkins-bot 62ca80536e Merge "Block all combinations of refines="…" and follows="…"" 2019-11-11 12:37:34 +00:00
jenkins-bot 3cac8643a6 Merge "Move some glue code from Cite to the Cite…Hooks classes" 2019-11-11 12:37:31 +00:00
Thiemo Kreuz fe385ecc37 Block all combinations of refines="…" and follows="…"
Note it doesn't make a difference if this is behind the feature flag or
not. It should always be forbidden, and in fact is: Either the follows
attribute is unknown, or the combination is forbidden.

Bug: T236256
Change-Id: Iebbb2d1d5bab183ab0590b8a7a7f6e79d319b72c
2019-11-11 12:56:58 +01:00
Adam Wight b7a7457ffd Add page property when parsing book reference
Any time the book referencing attribute is used in a page,
permanently tag that page with the `ref-extends` property, so
that it can be watched and cleaned up if necessary.

Bug: T237531
Change-Id: Ice5d9d8f7a305702cdc7c2a55d4147c4f79b5881
2019-11-11 11:06:31 +01:00
Adam Wight 5ac57def59 refArg parses and returns the refines attribute
Incremental patch which extracts the refines attribute from the tag.
Doing this now to allow the calling function to have responsibility
for doing something with the attribute value.

Bug: T237531
Change-Id: I59bb409bedd8e6ed06268e705e02e8ffb45b1f0e
2019-11-08 12:30:12 +01:00
Thiemo Kreuz ae8360f84a Move some glue code from Cite to the Cite…Hooks classes
I was particularly suprised by the conditions that checked if
`$parser->extCite !== $this`. This can never happen. Maybe it was
possible in a very old version of this code, but it is not any more.

Change-Id: I049ff4109a747eb9dbf325c24cf20f65753827dd
2019-11-07 09:48:08 +01:00
Thiemo Kreuz 1a371ec6a5 Extract all hook handler functions to small glue classes
As of now, this patch does not touch the existing code. However, the
goal is to remove a lot of the related code from the Cite class. This
will be done in later patches. This here is a separate patch to make
reviewing the later patches much easier.

The existing parser tests should be proof enough this chain of patches
is not changing any behavior.

Change-Id: I27ae972f81071bb4036bd452560768fae409417b
2019-11-07 09:45:32 +01:00
Thiemo Kreuz f590379a64 Fix incomplete @param PHPDoc
Change-Id: I3b17178737cc42e8519a60a2ae2f7cca6ac6ccb3
2019-11-05 14:19:57 +00:00
WMDE-Fisch e3ef0e3a0d Consistently name the variable for the content
Renaming to $text since this is also already used in the array structure
to store the references and seems more intuitive than $str

Change-Id: I4dbe5d10ddc355b4587d195b50cf078ac01fac55
2019-11-05 10:04:49 +00:00
jenkins-bot 250f7e9973 Merge "Remove not needed and collapse overly complicated code" 2019-11-04 17:03:08 +00:00
Thiemo Kreuz a4b9302d88 Remove not needed and collapse overly complicated code
Change-Id: Iee4241245280b23ab2aaf452363e7db3e21f5554
2019-11-04 16:04:42 +01:00
Thiemo Kreuz 5397919857 Remove obsolete comments
Change-Id: I66246a4d4978e070d45def38ff5b6300f6057eb3
2019-11-04 16:03:33 +01:00
jenkins-bot 4ae083fe72 Merge "Extract handling of guardedRef inside reference tags" 2019-11-04 12:29:13 +00:00
jenkins-bot e006e9682c Merge "Elaborate comment on invalid keys" 2019-11-03 10:35:30 +00:00
WMDE-Fisch e2a98505d1 Fix PHPdoc for Cite::stack()
The text could be null if we're stacking a re-used reference there.
Also content is a more precise word for what was forwarded here.

Change-Id: Ic78fb4744314c40360a61c21e92462b6eb2ae1ab
2019-11-01 16:26:56 +01:00
WMDE-Fisch 2ddae75d95 Elaborate comment on invalid keys
Change-Id: If8e800d69d4ff01ff6c9471e5324c7184e74c136
2019-11-01 15:43:47 +01:00
WMDE-Fisch 85fe486e6a Extract handling of guardedRef inside reference tags
This is just simply moving the code to make the structure more clear.

Change-Id: I680047237458dcfe539525fbb826602d683facc9
2019-11-01 15:41:00 +01:00
jenkins-bot 87a2bf4bdb Merge "Move unrelated static code to ApiQueryReferences" 2019-10-25 13:01:12 +00:00
Thiemo Kreuz ed8dee9bfe Move unrelated static code to ApiQueryReferences
I tried to avoid unrelated refactorings. The only thing I ended doing
is turning a huge if-else around into a guard-clause.

Main motivation here is:
* Make the huge, almost 2000 line Cite class smaller.
* Turn public code into private implementation details.

Bug: T236260
Change-Id: Ifca28040ae60d021a31aaee65417c7584627a975
2019-10-25 10:26:37 +00:00
jenkins-bot 2012944930 Merge "Move misplaced ParserFirstCallInit hook handler to CiteHooks" 2019-10-25 09:02:17 +00:00
jenkins-bot d67684dfe0 Merge "Make use of PHP7's ?? feature instead of isset()" 2019-10-25 08:52:51 +00:00
Thiemo Kreuz 28dd373d24 Move misplaced ParserFirstCallInit hook handler to CiteHooks
All other hook handlers are in the dedicated CiteHooks class.

Main motivation here is to make the huge Cite class smaller,
especially by removing static code that does not rely on anything
else the class does.

Bug: T236260
Change-Id: If0b3f6c989e44283428cda4b2c4d8d5303385d22
2019-10-25 10:34:35 +02:00
jenkins-bot f62736c58c Merge "Simplify private listToText() implementation" 2019-10-25 08:32:49 +00:00
jenkins-bot 714996d72a Merge "Fix capitalization mismatch in class name" 2019-10-25 08:28:40 +00:00
Thiemo Kreuz ddafb6adee Make use of PHP7's ?? feature instead of isset()
Main motivation here is to make the code shorter and faster to read.

Bug: T236260
Change-Id: Ieddc0fe8a292f8f46e9f011a588946dcd063d53d
2019-10-25 10:19:08 +02:00
Thiemo Kreuz 7f99a1bfe1 Simplify private listToText() implementation
Motivation is to make the code shorter and faster to read, and also
perform better.

Bug: T236260
Change-Id: I9186370a628833c1563eb5fa4f2e062fb27d6ed7
2019-10-25 10:17:05 +02:00
Thiemo Kreuz 5acc1e5a2d Fix capitalization mismatch in class name
Change-Id: Id0f9331aecc8b26f4df78839cd43818c4221a5ff
2019-10-25 10:15:53 +02:00
Thiemo Kreuz b65e1bb238 Make use of ctype_digit() instead of a regex
Relevant edge-cases:
* ctype_digit() only works on strings. Anything else, including
integers, will make it return false.
* The empty string will return false.

Both is identical to what the code did before.

Motivation for this change is to streamline the code, and make it
smaller and faster to read.

Bug: T236260
Change-Id: I2d209347d16f2bde14b345c3f88ec64b081283cb
2019-10-25 10:12:39 +02:00