Commit graph

11 commits

Author SHA1 Message Date
jenkins-bot
65812ee715 Merge "parser: Make all LinkHolderArray properties private" 2023-04-08 22:28:31 +00:00
Tim Starling
5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +00:00
thiemowmde
4ebc778eb7 parser: Make all LinkHolderArray properties private
I could not find any use outside of core, or even outside of this
class.

The class is instantiated a single time in core:
https://codesearch.wmcloud.org/search/?q=new%5CW%2BLinkHolderArray&files=%5C.php%24
This instance is not used anywhere else:
https://codesearch.wmcloud.org/search/?q=mLinkHolders&files=%5C.php%24

I would argue this doesn't really qualify as a breaking change. This
was always meant to be private.

Change-Id: I4c614dae1fe1d61c9cf8b7a03c37eb93fae33873
2023-03-15 10:44:04 +01:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
thiemowmde
69c5757243 parser: Optimize regex patterns used in LinkHolderArray
Two micro-optimizations are done in this patch:

1. We know exactly how these placeholders are built in the makeHolder()
method. In »<!--IWLINK'" 1-->« it's guaranteed to be a single number
and in »<!--LINK'" 1:2-->« it's two numbers.

The most extreme synthetic micro benchmark I did cuts the runtime of
these regular expressions down to about 25%. It won't make much of a
difference in real-world scenarios but is still worth it, I believe.

It also makes the code more specific and less confusing (see below).

2. We don't need to use the full string »<!--LINK'" 1:2-->« as array
key when the only thing that matters is the part »1:2«. Note the same
is done just a few lines below in the replaceInterwiki() method.

This code does have outstanding test coverage via all the parser tests,
I believe. Any change here that doesn't make a test fail should be safe.

Note the unit tests have been written many years later via I2c12cc7,
using "dummy" strings and such instead of the expected numeric
namespace and link ids. Most of this is already fixed via previous
patches. The last mistake addressed in this patch is that
getPrefixedDBkey() is supposed to be a title. It can't contain one of
these placeholders.

Follow-Up: I2c12cc76a9bf01eb527db3ea038e4adc59446cac
Change-Id: Ie994059092df8861ddb97c098acd082698d45c53
2023-01-07 13:25:33 +00:00
thiemowmde
800fd1d4c4 Fix bogus nextLinkID in LinkHolderArrayIntegrationTest
Parser::nextLinkID cannot return a string. It returns a positive
integer number.

Note a very similar mistake was already fixed before via I7e71ffc.

Change-Id: Ifce71d0f4db31787bf0eb84e621cfdeb07c674ef
2022-12-09 11:45:09 +01:00
Derick Alangi
5e8cd2c838
Migrate from setMwGlobals() to overrideConfigValue(s)
Change-Id: I3f167d0e7d59a5aa091c3095a7d96c889d6e7e78
2022-08-02 10:14:10 +01:00
daniel
61a5531e4a Strict return types for PageIdentity
Bug: T208776
Change-Id: I7e71ffc209465b7cca385603d844cd40178485a9
2021-01-18 17:33:14 +01:00
Tim Starling
f7f6f0d700 Update LinkHolderArray tests for new HookContainer parameter
Change-Id: I63fc731ca1dbaef6f215279ee0b1788e735783df
2020-06-23 09:00:32 +10:00
Thiemo Kreuz
231bcef6af parser: Remove unused $query param from LinkHolderArray::makeHolder
We know it's never anything but an empty array:
https://codesearch.wmflabs.org/search/?q=makeHolder

Change-Id: Ibc230ec1a1a15a9a5dc61abe5b989a3391d671c1
2020-06-22 14:33:59 +00:00
ArtBaltai
757072d182 New unit and integraton tests for class LinkHolderArray
Bug: T243747
Change-Id: I2c12cc76a9bf01eb527db3ea038e4adc59446cac
2020-06-04 11:38:40 +00:00