Commit graph

852 commits

Author SHA1 Message Date
Brian Wolff
466fa62321 BackLinkCache::queryLinks: Make janky filter more robust
The conds part of the query, could potentially be a string instead
of an array. The individual keys can have values that are not strings
like numbers or null. This casts everything appropriately to be
more robust.

Additionally, this fixes a deprecation warning on php8.1 about
passing null to preg_match.

Bug: T313663
Change-Id: I5671c7882af57be29299e9032c6e8f056fe10e30
2022-09-12 08:36:51 +00:00
Platonides
42fbc845b7 FileCache: Allow ?uselang= to utilize cache if set to content language
Previously the mere presence of uselang made it disable the FileCache,
even though requesting the wiki content language is equivalent
to not providing it at all.

The requested language being the content one is already checked
in lines 124-138.

This used to work but was broken with the 2008 refactoring of
isFileCacheable() in e29274ca (r41274).

Change-Id: I01320d36a3b31b7a69025d845b61d9eb05e9fca3
2022-09-07 16:35:19 +00:00
Amir Sarabadani
84edec9825 LinksUpdate: Last pieces of templatelinks migration
I dropped the columns and these paths started to fatal. Nothing super
complicated.

Bug: T312865
Change-Id: Ic44edc5b4a2d8da924ba6176b619715e4780bddd
2022-07-25 20:23:30 +02:00
Alexander Vorwerk
8846700ef0 Stop merging LinkCache select fields with page_title and page_namespace
LinkCache::getSelectFields() includes page_title and page_namespace
since If77c2f9879d7bae71eb59944efd8b3798d16aa46, so we don't need
to add those two specifically.

Change-Id: I8fa9d563af3f9da90fb96369dab0ee5bde860081
2022-07-05 22:28:53 +00:00
Timo Tijhof
0ffe341629 language: Add missing @ingroup, subgroup "Languages" and ungroup files
== Ungroup file blocks

Remove `@ingroup` from `@file` blocks and keep only the class block.

This matches similar changes previously applied to API, Skins, Profile,
and ResourceLoader.

This helps make the API documentation easier to navigate.
E.g. Modules -> Language in the sidebar of
<https://doc.wikimedia.org/mediawiki-core/master/php/> as well as
<https://doc.wikimedia.org/mediawiki-core/master/php/group__Language.html>

These are currently cluttered with tons of duplicate entries for files
and classes both. We only need to group files that aren't also
documented as a class (e.g. message files, entry points, other scripts
or files that we mainly consider a data file). This has the helpful
side-effect that we don't encourage duplication of the class
description (or worse, place useful docs only in the file block), and
makes the class files consistently start with a mentally ignorable
block. Basically, unless there's something other than a class, don't
describe or group the file itself.

== Missing group

Various classes in this subtree were missing the `Language` group,
or were using different group from before T225756.

== Subgroup

For ease of navigation, move Converter subclasses to a group called
"Languages", which for documentation purposes is a subgroup of
"Language". The next commit does the same for Messages* files,
and Language subclasses (done separately for ease of review).

Change-Id: I301f471f86ba2dee924fece29a16dc3c20b5bebe
2022-06-28 17:12:46 -07:00
Timo Tijhof
051e127bdb language: Move l10n-related classes from /cache to /language
* Make the code easier to own and maintain by being part of a topical
  area of expertise rather than a generic catch-all bucket.
  This also helps Gerrit team dashboards, [[mw:Git/Reviewers]]
  subscription patterns, more meaningful component prefix for
  [[mw:Commit_message_guidelines]].

* Prep for possible CODEOWNERS adoption.

* Prep for T166010 to give us better PSR-4 namespaces that we won't
  have to break/migrate again shortly after for the above.

Bug: T225756
Change-Id: I62c701d574d2a79365b1c5350f92bef47770e3ce
2022-06-28 16:27:20 -07:00
Umherirrender
f3863ddd77 MessageCache: Replace deprecated WikiPage::factory
Bug: T297688
Change-Id: I8752c1175c1c8a6c3480a20b561aae2ddd2d712d
2022-06-24 19:22:19 +02:00
Matěj Suchánek
1c48194d4e Remove LinkCache::forUpdate and clean up the constructor
Passing null to the constructor as well as the LinkCache::forUpdate
method have been deprecated since 1.34. Since this is a service
class, it should only be instantiated directly by the service
container anyways.

Change-Id: Id15ccf2af6ef59e7052ea88548464e7481ca73d4
2022-06-16 20:17:54 +02:00
Tim Starling
a01aa705a9 MessageCache: Increase the MapCacheLRU size
Quick fix for linked bug. Regression testing will be in a separate
commit.

Bug: T310532
Change-Id: Ibc0997c87be194e0a8a92a726de07f4dc786cd47
2022-06-15 01:04:06 +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
jenkins-bot
40abc7d834 Merge "Use User::isRegistered for readability instead of ::getId falsy check" 2022-05-23 04:06:10 +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
jenkins-bot
67361d6f04 Merge "Revision: Log traces as 'exception.trace' instead of 'trace'" 2022-05-13 19:49:18 +00:00
jenkins-bot
0e08a27e03 Merge "Use injection for LinksMigration on LinkBatch, action, api, special page" 2022-05-11 05:48:30 +00:00
Umherirrender
d79fd02d4b Use injection for LinksMigration on LinkBatch, action, api, special page
Even the service does not long stay in that classes,
it should be injected to avoid global state

Bug: T304780
Change-Id: Ib488037f5a6966ab61042ed3cd889ddc50f1ba8e
2022-05-10 20:19:58 +00:00
Amir Sarabadani
30aa4679c0 Remove references to legacy page_restrictions field in page table
Bug: T218446
Change-Id: I4d45de0890b96e00d4b24fc96ceffbf336928bc2
2022-05-09 11:20:53 +02:00
Umherirrender
49ad716948 Use User::isRegistered for readability instead of ::getId falsy check
Change-Id: I42aab149559e3e899cde6c77af76c66936ed0ef0
2022-04-29 21:15:57 +02:00
Aryeh Gregor
7b791474a5 Use MainConfigNames instead of string literals, #4
Now largely automated:

VARS=$(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | \
  tr "\n" '|' | sed "s/|$/\n/;s/'//g")
sed -i -E "s/'($VARS)'/MainConfigNames::\1/g" \
  $(grep -ERIl "'($VARS)'" includes/)

Then git add -p with lots of error-prone manual checking. Then
semi-manually add all the necessary "use" lines:

vim $(grep -L 'use MediaWiki\\MainConfigNames;' \
  $(git diff --cached --name-only --diff-filter=M HEAD^))

I didn't bother fixing lines that were over 100 characters unless they
were over 120 and triggered phpcs.

Bug: T305805
Change-Id: I74e0ab511abecb276717ad4276a124760a268147
2022-04-26 19:03:37 +03:00
Timo Tijhof
8ffee67611 Revision: Log traces as 'exception.trace' instead of 'trace'
Various in RevisionStore did this already, but we forgot a few.

Bug: T233342
Change-Id: Ib678868b239bcd4ff4ae62b2ab47022b5a70e8be
2022-04-13 22:18:50 +00:00
Derick Alangi
d371cd942d
cache: Introduce member to expose service options for configs
There are some static methods in sub-classes of FileCacheBase
that use the service locator to get the main config object
which maybe I think we can just use DI in the methods to
pass this from the calling code.

That could be in a follow-up patch, for now, we can leave
things as they are here?

Change-Id: Ic75e1e5f867faee7fc71c34552f9f0a7a124d7ae
2022-04-13 20:17:30 +01:00
Amir Sarabadani
19e77d4fc9 Add more support for read new in links migration
- In Info action and its API counter part
 - In LinkBatch::constructSet
 - In Title::getLinksFrom

Bug: T304780
Change-Id: I449f041986acdd16feecac818e3579987b4b11be
2022-04-12 02:22:17 +02:00
Amir Sarabadani
6fd2843361 linker: Add LinksMigration service for read new
Bug: T304780
Change-Id: Ifdea1ef80c34831564fe12827c5c06ade6200df8
2022-04-07 16:54:38 +00:00
Umherirrender
7aa0884029 phan: Remove PhanTypePossiblyInvalidDimOffset suppression
Make phan stricter about array keys
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T304887
Depends-On: I3105a5fd4826f8667b5232834defc5ec93be32a1
Depends-On: Ie9610a6e83731468311edb3ed17f80fc509de385
Change-Id: I701f12ab94478c3b8e7fd82110ade74a8e6b04ef
2022-03-28 23:26:49 +02:00
Umherirrender
1f71eccf63 phan: Disable null_casts_as_any_type setting
Make phan stricter about null types by setting null_casts_as_any_type to
false (the default in mediawiki-phan-config)
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T242536
Bug: T301991
Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
2022-03-21 18:25:07 +00:00
Umherirrender
6dd8a2bb32 phan: Disable scalar_implicit_cast setting
Make phan stricter about scalar types by setting scalar_implicit_cast to
false (the default in mediawiki-phan-config)

Bug: T242536
Bug: T301991
Change-Id: Ia2fe30b17804186571722e728578121c8b75d455
2022-03-18 18:52:24 +00:00
Umherirrender
fe48e1223a cache: Fix various scalar and null types to match documentation
Adding float as type when INF is used as argument

Found by phan strict checks

Change-Id: I7e19cd0d9b09bf685e4e8387c900f303b669ad54
2022-03-14 17:36:04 +00:00
jenkins-bot
0200221a93 Merge "Fix various documentation related to null types (part II)" 2022-03-09 22:42:42 +00:00
jenkins-bot
96393c492e Merge "Add various fallback values for null return values" 2022-03-09 22:32:29 +00:00
jenkins-bot
8f618cf551 Merge "Avoid use of null, bool or Status in log messages" 2022-03-09 22:15:20 +00:00
Umherirrender
19925ef026 Add various fallback values for null return values
Found by phan strict checks

Change-Id: I83187b5fd25b015d2c75e22d4b5202803653d743
2022-03-09 20:15:36 +01:00
Umherirrender
d7248d63fb Fix various documentation related to null types (part II)
The functions returning null or the class property is set explict null.
Some function should not accept null or return null.

Found by phan strict checks

Change-Id: Ie50f23249282cdb18caa332f562a3945a58d86ff
2022-03-08 23:45:31 +00:00
Reedy
11cc2d6993 Consistently use @deprecated since rather @deprecated
Change-Id: I301786f35cd6eb9c63fb72e0b64cffa9efd7b86b
2022-03-06 02:55:54 +00:00
Umherirrender
58fdd4f8e3 Avoid use of null, bool or Status in log messages
Explicit convert to string

Found by phan strict checks

Change-Id: I843fe4c30b2f82ef3b98241e208b5d38002c0d07
2022-03-02 22:45:10 +00:00
Umherirrender
f9858b2863 MessageCache: Move LanguageConverterFactory call from wiring to constructor
This avoids mismatches between the language in the message cache and the
language converter used for content language.

Bug: T292239
Change-Id: I1f0ca70b184362a783d164658b3867e00a306591
2022-02-28 23:05:35 +00:00
Umherirrender
b126dbe3f2 Fix various documentation related to null types
The functions returning null or the class property is set explict null

Found by phan strict checks

Change-Id: I4a271093fb6526564d8083a08249c64cb21f2453
2022-02-26 10:31:24 +01:00
Reedy
86934b2fa8 Replace some more usages of Wikimedia\(suppress|restore)Warnings()
Change-Id: I2eb133a9e32116cd155f59086245bc4d15ecbfcc
2022-02-24 20:27:46 +00:00
jenkins-bot
6a85933fd7 Merge "Avoid references to DefaultSettings." 2022-02-22 23:47:25 +00:00
daniel
a5277ce87f Avoid references to DefaultSettings.
This replaces references to DefaultSettings with
references to config-schema.yaml where appropriate.

NOTE: this does not yet change Setup.php. DefaultSettings.php
remains intact and is still being used.

NOTE: this does not remove usages in the installer, see I5d8843a1062fbf
for that.

Bug: T300129
Change-Id: Ie6152cf510c3be61bc22167ca6d90dfc28910a45
2022-02-22 19:43:50 +01:00
Gergő Tisza
6a7bffaac2
LinkBatch::getPageIdentities(): Fix return type
LinkBatch::getPageIdentities() returns PageIdentityValues, which
are ProperPageIdentities. Indicate this in the return type
documentation to avoid phan complaints.

Change-Id: I461f2964aa9b4178d41e6071763e016b207c77d5
2022-02-19 10:09:57 -08:00
jenkins-bot
be029c5fa4 Merge "MessageCache: Avoid Undefined offset in normalizeKey()" 2022-02-04 17:52:15 +00:00
Timo Tijhof
067b07f4fc MessageCache: Avoid Undefined offset in normalizeKey()
It is quite rare that a notice like this is best fixed so close to
the caller. More often than not, low-level code like this doesn't
have a reasonable way to handle it and it's a genuine issue but one
that a higher-level should prevent instead.

In this case though it seems fair to handle here because an empty
string is actually, according to most l10n-related classes, a valid
message key. It can't exist, but it is a valid key.

See also MessageCache::get() which does not consider it an error and
similarly returns false. That method never calls normalizeKey with
an empty string though. The error came from ApiQueryAllMessages.

I don't think it should be ApiQueryAllMessages's concern to normalize
this key or otherwise hardcode its non-existence over there.

Bug: T300792
Change-Id: I8a8eed66704862bb3a645ef5941a5264e65bde4c
2022-02-04 03:37:36 +00:00
Tim Starling
ca71e69fc6 Try not to discard Excimer timeout exceptions
Don't catch and discard exceptions from the RequestTimeout library,
except when the exception is properly handled and the code seems to be
trying to wrap things up.

In most cases the exception is rethrown. Ideally it should instead be
done by narrowing the catch, and this was feasible in a few cases. But
sometimes the exception being caught is an instance of the base class
(notably DateTime::__construct()). Often Exception is the root of the
hierarchy of exceptions being thrown and so is the obvious catch-all.

Notes on specific callers:

* In the case of ResourceLoader::respond(), exceptions were caught for API
  correctness, but processing continued. I added an outer try block for
  timeout handling so that termination would be more prompt.
* In LCStoreCDB the Exception being caught was Cdb\Exception not
  \Exception. I added an alias to avoid confusion.
* In ImageGallery I added a special exception class.
* In Message::__toString() the rationale for catching disappears
  in PHP 7.4.0+, so I added a PHP version check.
* In PoolCounterRedis, let the shutdown function do its thing, but
  rethrow the exception for logging.

Change-Id: I4c3770b9efc76a1ce42ed9f59329c36de04d657c
2022-02-02 16:27:44 +11:00
jenkins-bot
c0f7f43e75 Merge "Fix pollution of LinkBatch/LinkCache with interwiki link" 2022-01-31 19:03:19 +00:00
Tim Starling
16979ecf29 Fix pollution of LinkBatch/LinkCache with interwiki link
* In LinkBatch::addObj(), reject interwiki links with a warning.
  Otherwise the link is added to the batch by ns/title and later
  reconstructed as if it were a local link without an interwiki
  prefix.
* In CommentParser, treat interwiki links as always good, don't defer
  the existence check.
* In LinkBatch, inject a LoggerInstance instead of calling LoggerFactory
  in four places.
* Add a regression test, and some general tests for known links.

Bug: T300311
Change-Id: I0e5825eb48a6ba2932aea69a4d0fff3439c50ff5
2022-01-28 10:52:38 +11:00
Aaron Schulz
c433c15087 Convert various callers to LoadBalancer::getConnectionRef()
Bug: T193565
Change-Id: I2e2ef6a1d841c632d1f3e53ca3f82a720af15d47
2022-01-27 01:02:44 +00:00
Umherirrender
95852cb22b Explicit cast TS_UNIX to int for arithmetic operations and int args
When the called function has a doc of int, it should be cast to be
explicit here.
Also cast for arithmetic operations to be explicit about the number

Change-Id: I905b78dfb66e66443e0e3203488bab5b548db543
2022-01-11 20:13:13 +01:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
Siddharth VP
b77dd0640c Fix typos in comments (M)
Change-Id: I5ab88a01ba3e5ea2aae853bb6f06492fbc84ceb5
2022-01-09 23:00:20 +05:30
Siddharth VP
b4b2a62040 Fix typos in comments (L)
Change-Id: I3deb34aec51504e09b20a367a93ebe863335be26
2022-01-09 22:54:04 +05:30