Commit graph

25 commits

Author SHA1 Message Date
Umherirrender
e662614f95 Use explicit nullable type on parameter arguments
Implicitly marking parameter $... as nullable is deprecated in php8.4,
the explicit nullable type must be used instead

Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a

Break one long line in SpecialPage.php

Bug: T376276
Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
2024-10-16 20:58:33 +02:00
Umherirrender
f910edce6d Add @phan-mandatory-param for function name arguments
Providing the function name is often optional from the php code,
but it is needed for better logging, so make it mandatory and let phan
report issues about this.

Bug: T374546
Depends-On: Iaed5489a85a5a6e685829e151436afc94310fbd0
Depends-On: Ie2a1e5052e5b61bbb5b89905de942f47d3f1413d
Change-Id: I5227f2fa65850ac8c6f620900f22d1f4e7bfd470
2024-09-20 16:23:17 +00:00
thiemowmde
dca4931b42 Make use of the ??= and ?? operators where it makes sense
This touches various production classes and maintenance scripts.
The code should do the exact same as before. The main benefit is that
the syntax avoids any repetition.

Change-Id: I5c552125469f4d7fb5b0fe494d198951b05eb35f
2024-08-26 09:26:36 +02:00
James D. Forrester
f7ce0a0976 Move remaining four classes in includes/content into Content namespace
Bug: T353458
Change-Id: Ia0f3e22078550be410c4b87faf6aa4eabe6e270d
2024-08-10 10:40:53 +02:00
Ebrahim Byagowi
a717db8e60 Add namespace and deprecation alias to FormatJson
This patch introduces a namespace declaration for the
MediaWiki\Json to FormatJson and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I5e1311e4eb7a878a7db319b725ae262f40671c32
2024-05-16 16:28:01 +03:30
Timo Tijhof
07d31822c7 ResourceLoader: Edit real pages in testGetPreloadedTitleInfo
Remove a bunch of mocking complexity in favour of real pages.
This is in prep for making a better regression test in change
I591ee186083f for T360014.

Bug: T360014
Change-Id: I2f99a542a6d17a8503213f68c3df6a1c5ca50c77
2024-03-14 14:10:39 -07:00
Lucas Werkmeister
a294909a0e WikiModule: Fix pages merging
I don’t understand all this code, but if the page list comes out of
array_keys(), then it must be a numerically indexed list, not an
associative array; this means that we have to merge different versions
of it with array_merge(), not with the + operator: the + operator
doesn’t reassign numerical indexes, so

    [ 0 => 'A' ] + [ 0 => 'B', 1 => 'C' ] === [ 0 => 'A', 1 => 'C' ]

Bug: T360014
Change-Id: I832f8136c77a4ec45245b2ca21963d4cf545628a
2024-03-13 11:42:48 +01:00
Bartosz Dziewoński
b34c23047d WikiModule: Fix data structure when preloading title info
Follow-up to 6194cf19ce.

Bug: T359939
Change-Id: I72a2c21c68d7d6ad281c28b8e76abcfc9846032e
2024-03-12 15:51:07 +01:00
Timo Tijhof
6194cf19ce ResourceLoader: Add preload for foreign WikiModule title info
=== Objective ===

* Remove reliance on global state via WikiMap.
* Reduce reliance on MediaWikiServices::getInstance().

=== Details ===

Note that this does not increase or introduce use of cross-wiki
database connections. preloadTitleInfo() is not an optimistic
optimisation. We only pass modules to preloadTitleInfo() if the
caller will call WikiModule->getTitleInfo() shortly thereafter.

The Zend hack is no longer needed, as this existed to support PHP 5.5
as per <https://3v4l.org/EU6Ro>.

Remove needless complexity around levering array_intersect_key. This
made sense originally in I82e215745 (dbd11e04aa), when the arrays
had the same keys, but since Ibe7881577 (dbe592df6d) they don't.
Given they don't match, take the direct approach instead.

Bug: T359522
Change-Id: I7d407a1989d28ef329ab430841251c910fe78732
2024-03-11 19:07:13 +00:00
Timo Tijhof
3903c8cfec ResourceLoader: Migrate wfGetDB call to ICP and move to WikiModule
* Remove references to IDatabase from preloadModuleInfo() and with
  it the last reference to Rdbms in the ResourceLoader service
  (progressing T32956).

* Simplify WikiModule::preloadTitleInfo() so that it doesn't need
  an IDatabase object unless
  1) there are non-zero WikiModule objects in the batch, and
  2) there is a cache miss.

* Remove needless IDatabase parameters passed or mocked for this
  method. Note that WikiModule already had `@group Database` set
  since each WikiModule::getDB() is called and uses an unmocked
  database. The mocked database was only injected to satisfy the
  method signature.

Bug: T32956
Bug: T359522
Change-Id: I022f02d6e6bbae46c3258a7c07a1d6723506d8bc
2024-03-11 19:39:24 +01:00
James D. Forrester
21d8d9863b Drop old ResourceLoader class aliases, deprecated since 1.39
Depends-On: Iff15a2e13a3507ef1ab5cfa504ca1a1c8d2b2a60
Depends-On: Icf8331e35acf6fe51a8303ee639921b9e4f3e6bb
Depends-On: I5a5af003026db69b279ddde0b0dedbfcfe7d70fd
Change-Id: I5929a2f760c8d21c1cb2542a19220a91ac7240e4
2024-01-31 18:24:37 -05:00
Bartosz Dziewoński
e4c7272976 Change uses of getDBLoadBalancerFactory() to getConnectionProvider()
Update cases where one of the IConnectionProvider methods is called
immediately.

This doesn't really change anything, but I hope it helps promote
getConnectionProvider() as the common way to do this.

Follow-up to 8604c384f6.

Change-Id: Id0e7d02bab0c570343c2b1f03c70b44ee39db112
2024-01-22 22:27:45 +01:00
James D. Forrester
273cc042ae ResourceLoader: Drop targets system, deprecated in 1.41
Bug: T340802
Depends-On: Ie936afed7042d5a4713b027c30d7487565a35eaf
Change-Id: Icad30d62301be5d7390ebdf34e818519e3fe56c4
2024-01-12 16:42:38 -05:00
Amir Sarabadani
2e1cd74ad2 Migrate off wfGetDB() in more places to ICP
This function is uber-deprecated, meaning even its replacement is
deprecated, We have already migrated in static functions and more.

In this batch, all calls have been migrated that there is already a call
to MediaWikiServices::getInstance() making the migration easier. Of
course in most cases, they should eventually turn into proper service
injection but this at least makes it clear what services should be
injected.

Also removing "category" group since we are removing all groups except a
handful from mw (see T263127 for more information).

Bug: T330641
Change-Id: I90cd35ee45a37eb6e6bf7a531cc8f75effbd0328
2023-11-20 14:40:28 +01:00
James D. Forrester
94ece673b2 Namespace TitleValue under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: I4c901d5c32696d8334ec30cede7d9b6f3d8d645e
2023-09-18 18:24:39 +01:00
Taavi Väänänen
c5063e9c18
Database: support passing an IReadableDatabase to getCacheSetOptions
Change-Id: Ia93e52838c0ca68732969268f36a4ff5f193ff16
2023-06-09 10:46:03 +03:00
Bartosz Dziewoński
6ba47296d9 Fix Phan suppressions related to Title::castFrom*() and friends
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
2023-04-22 16:45:09 +02:00
Tim Starling
25d0d37adc ResourceLoader: tweak comments and error messages
Change-Id: Ifcaefedf65b090a87ec1417808277ae6451302dc
2023-04-03 18:21:30 +10: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
Amir Sarabadani
e8032eb8f7 ResourceLoader: Switch to use select query builder in WikiModule
Bug: T311866
Change-Id: I77d711a10b935680682eb2a91dab635460de3cf6
2023-02-28 17:23:58 +01:00
Matěj Suchánek
a592d47e91 Clean up redundant array manipulation
PHP does this implicitly.

Change-Id: I009a7c93d44fb5e8c430c971cfc637fa04a8e68d
2022-12-11 12:42:29 +01:00
DannyS712
847d248d92 WikiModule::getStyles() - simplify foreach loop
Only need to determine $remoteDir once rather than each
time through the loop, avoid determining $media unless
needed, should be a no-op in terms of functionality.

Change-Id: Ie5a0a5ffa71197c242400c0f4b72697da0d8f26e
2022-06-22 01:26:45 +00:00
Tim Starling
3e2653f83b ResourceLoader namespace (attempt 2)
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader itself.

Move the tests by analogy.

I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".

I did not address DependencyStore which continues to have a non-standard
location and namespace.

Revert of a241d83e0a.

Bug: T308718
Change-Id: Id08a220e1d6085e2b33f3f6c9d0e3935a4204659
2022-05-24 15:41:46 +00:00
Lucas Werkmeister (WMDE)
a241d83e0a Revert "ResourceLoader namespace"
This reverts commit e08ea8ccb9.

Reason for revert: Breaks Phan in extensions, and as far as I’m aware,
this change isn’t urgently needed for anything, so the simplest fix is
to revert it again for now. After PHP 7.4 it should be safer to try this
again (we hopefully won’t need the two “hack” classes by then).

Bug: T308443
Change-Id: Iff3318cbf97a67f821f78e60da62a583f63e389e
2022-05-16 14:43:33 +00:00
Tim Starling
e08ea8ccb9 ResourceLoader namespace
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader and
ResourceLoaderContext.

Move the tests by analogy.

I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".

I did not address DependencyStore which continues to have a non-standard
location and namespace.

Change-Id: I92998ae6a82e0b935c13e02a183e7c324fa410a3
2022-05-16 14:41:27 +10:00
Renamed from includes/resourceloader/ResourceLoaderWikiModule.php (Browse further)