We renamed many classes to be namespaced, but the `@covers` and
`@coversDefaultClass` annotations weren't updated properly.
PHPUnit didn't support short cover annotations with `use` statements,
these didn't trigger any errors yet, because they are class alias.
This patch is populated by a modified version of PhpunitAnnotationsSniff.
Change-Id: I6c602290a30099239b17d2dc0d67b1488b4eaeeb
There is no way to express that Title::castFromPageIdentity(),
Title::castFromPageReference() and Title::castFromLinkTarget()
can only return null when the parameter is null. We need to add
Phan suppressions or explicit types almost everywhere that these
methods are used with parameters that are known to not be null.
Instead, introduce new methods Title::newFromPageIdentity() and
Title::newFromPageReference() (Title::newFromLinkTarget() already
exists), without the null-coalescing behavior, and use them when
the parameter is not null. This lets static analysis tools, and
humans, easily understand where nulls can't appear.
Do the same with the corresponding TitleFactory methods.
Change the obvious uses of castFrom*() to newFrom*() (if there is
a Phan suppression, a type check, or a method call on the result).
Change-Id: Ida4da75953cf3bca372a40dc88022443109ca0cb
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
In getFulltext the namespace number is converted to text, for NS_USER
this trigger the gender cache. Use canonical namespace instead.
When Title::canExist is called to fill a LinkBatch (Like done for
Special:Log/block via BlockLogFormatter::getPreloadTitles),
the effect of the batch lookup is not the best, because GenderCache
filled with single database queries instead.
This is similar to the usage of makeName in Title::makeTitleSafe
Handle invalid namespace numbers in Title::makeName the same as in
Title::prefix
Change-Id: Ibbdc7e0762568bb29ae59764c3666f275d201c6c
To follow Message. This is approved as part of RFC T166010.
Also namespace it but doing it properly with PSR-4 would require
namespacing every class under language/ and that will take some time.
Bug: T321882
Change-Id: I195cf4c67bd51410556c2dd1e33cc9c1033d5d18
Method is documented as only taking strings. PHP8.1 gives
warning for nulls. We should not test invalid values unless
we are expecting an exception.
This fixes a failing test TitleTest::testMakeTitle_invalid on php8.1
Bug: T313663
Change-Id: I51fe4c54832914055a624d94ad1a1c2720b23ec9
If the on-wiki "mainpage" message is a bare local interwiki
(`localiw:`), MediaWiki will try to normalize it to the main page,
causing an infinite recursive loop. Once in this state, there's no way
to fix it short of editing the database (or applying this patch).
The easiest way out of this is to add a recursion guard to fall back to
the hardcoded "Main Page" default.
Bug: T297571
Change-Id: I91316ecbdbe7c4ad1b7594643aef29a8e1f8fb26
Feeding the return value of the DB query through timstamp conversion
made it so that false was turned into the current timestamp, causing
confusion and cache churn.
Bug: T298520
Change-Id: I6e10b21f6b0e40ce7e3403ffc9a41a307e945354
Follows-up I361fde0de7f4406bce6ed075ed397effa5be3359.
Per T253461, not mass-changing source code, but the use of the native
error silencing operator (@) is especially useful in tests because:
1. It requires any/all statements to be explicitly marked. The
suppressWarnings/restoreWarnings sections encourage developers to
be "lazy" and thus encapsulate more than needed if there are multiple
ones near each other, which would ignore potentially important
warnings in a test case, which is generally exactly the time when
it is really useful to get warnings etc.
2. It avoids leaking state, for example in LBFactoryTest the
assertFalse call would throw a PHPUnit assertion error (not meant
to be caught by the local catch), and thus won't reach
AtEase::restoreWarnings. This then causes later code to end up
in a mismatching state and creates a confusing error_reporting
state.
See .phpcs.xml, where the at operator is allowed for all test code.
Change-Id: I68d1725d685e0a7586468bc9de6dc29ceea31b8a
Expected value is the first parameter to assertSame() or assertEquals().
And turn to use assertCount() for some assertions aginst count of array.
Based on code search `assert(?:Same|Equals)\(.+,.+expected` and I look
through files roughly, so some assertions that don't contains 'expected'
are also fixed. In the meantime, some assertions that I am not clear
about are not touched.
Change-Id: I75798b60d29fd19b33f4fdf34ed3c788db420d01
In a3a2744d03 (then r28968), the illegal title character regex was
expanded to block XML/HTML character references. However even back then
the two parts of the regex that aimed to block character references with
hashes in them were unreachable, because the fragment split happened one
step before illegal characters were checked. Any character reference
with a # in it would be split across the dbkey and fragment, and the
regex is only run against the dbkey.
This was noted in the JavaScript port of mediawiki.Title's tests, but
still left in. Those commented out test cases have now been removed as
they're technically valid titles with fragments.
Bug: T297578
Change-Id: I079f91a87fd7587ed70e65916fdd5efa01735efe
Calling getPageById when the page ID is known was supposed to improve
query performance, but since it bypasses LinkCache, it ended up causing a
spike in database queries.
This optimization can be re-introduced once we also cache PageRecords by ID.
Bug: T296063
Change-Id: Ia4ee75b7b5a71d7d858f818d6467793bc642697b
This causes Title to no longer look up fields in the database
individually, but use LinkCache instead to load an entire row from the
page table at once.
This patch also causes Title to use in-process caching for some
getters that did not use caching before, such as isNewPage()
and getTouched(). These methods do not appear to be used on critical
code paths that involve database updates.
Note that getTouched() used to take an options $db parametr. This
appears to be unused, and has been deprecated in favor of a $flags
parameter, for consistency with other getters on the class.
DEPLOY: Risky! This re-implements the internal caching logic of Title
and slightly modifies caching semantics in some cases. This may have
unforeseen consequences.
Bug: T285389
Depends-On: I103b9e1d2bf594bfc1b0ea12b980dd20bb911c3a
Change-Id: I2df81df7186025e001520f24fd498623c7184772
LinkCache::addGoodLinkObj was hard deprecated.
Use addGoodLinkObjFromRow() instead. PHPUnit tests
must use LinkCacheTestTrait::addGoodLinkObject().
Bug: T284955
Change-Id: I0c22be2f00e6d6d4ba6dd1511c5385cad55e8ff7
NOTE: some test cases where removed as they're exactly doing the
same thing as the ones above.
Bug: T291268
Change-Id: I8fa8bafc892dbc84f2aab2549d453d6f39835d33
-> Fixed TODOs such as adding test cases for namespaces that are
not in `$wgNamespacesWithSubpages` in `testGetSubpageText()`.
-> Re-arranged provider methods to come before the test case as
already in the files for consistency.
Change-Id: Ice2b3a07ea2ddd20417cbe87da93065e1812619e
The behavior of getCascadeStrictionSources was changed by Ia73ea587586cb69eb5
to conform to the documented behavior: it would always return false as the
first element of the return value if there were no cascading restriction sources,
as specified in the documentation.
Hopwever, the previous behavior was to return an empty array in that
case, unless the $getPages parameter was false. That behavior seems more
senible, and there is existing code that relies on it.
This patch restores the previous behavior and updates the documentation
instead.
Bug: T218395
Needed-By: I31ca0a8987f9694bc3b312a48c2c111ceda6fa3e
Change-Id: I1f24703b80566220ac6fe8ee500e838ed7fd29af
The methods that have been covered in this patch are listed below:
~ Title::hasFragment()
~ Title::getFragment()
~ Title::setFragment()
~ Title::isMainPage()
~ Title::equals()
~ Title::getPrefixedURL()
~ Title::prefix()
~ Title::__toString()
~ Title::getFullText()
Bug: T241406
Change-Id: I51ffadb52e7eef822e9e619e5132513dc1501f9b
This makes the data stored by LinkCache compatible with PageStoreRecord,
so we can use LinkCache inside PageStore.
This causes PageStore to make use of local caching as well as WANObjectCache.
Note that getPageById() does not yet benefit from cache, but does
populate the cache.
Bug: T278940
Change-Id: Icc27a0d9299a3e4ce45521daef87ad06ec06f064
This allows checking restrictions without a dependency on Title, based
only on a PageIdentity.
Additional fixes along the way:
* Correctly return false instead of 'infinity' for
getRestrictionExpiry( 'create' ) on an existing page
* Correctly handle non-special pages that can't exist (like media pages)
in listApplicableRestrictionTypes() (return empty array instead of
'create')
* Improve readability of isProtected()
The expectation change in TitleTest::testIsProtected() is because the
test was formerly broken, since it set mRestrictions without setting
mRestrictionsLoaded. (Which illustrates how this approach to testing is
essentially broken.)
Co-authored-by: Vedmaka <god.vedmaka@gmail.com>
Bug: T218395
Change-Id: Ia73ea587586cb69eb53265b2f8f7a296a2573dd0
Changes from patch set Icb93c79f4843b59dae80d3eda1a880457a1a68f2
Also some swaps from assertEquals to assertSame/True/False/Null
Change-Id: Ife497ae6cb1888b77eb25e85b76df72adc65641a
Tests for the following methods don't need integration:
- legalChars()
- convertByteClassToUnicodeClass()
- newFromTitleValue()
- newFromLinkTarget()
- castFromLinkTarget()
Change-Id: I2ec6505088c74a90da9d0b8305ce94d81cc0562a
Results in passing a user where previously the fallback
to $wgUser was being used, mostly in tests.
Bug: T255507
Change-Id: Iabe24315b23c0ad1272353186425e71974528d23