Commit graph

774 commits

Author SHA1 Message Date
TChin
d4cb97952f Add logger to BacklinkCache serializing
While refactoring BacklinkCache, it was noticed that there is a __sleep method even though it doesn't seem to be used anywhere.

Git blame indicated that the last time BacklinkCache could've been potentially serialized was back in 2012 when Title used to save an instance of it. This is no longer the case.

However, there is a slight possibility that it's used in a hidden corner of some extension out there, so the plan is to add a logger, wait a week to see if __sleep is ever hit, and if not, we can just remove it so we don't have to worry about it when refactoring and writing tests.

Bug: T288278
Change-Id: Idb0f9985cb321cd53fea60d1fc94613c914e0de2
2021-08-20 12:58:26 -04:00
Timo Tijhof
6c4f7ad9db localisation: Remove conditional for plurals-mediawiki.xml file
Follows-up bbbcf089db.

This file always exists. If we want to support disabling this, we
could introduce a configuration option rather than encouraging users to
apply core hacks by modifying or removing this file.

Also move the file paths into an array for re-use.

Bug: T225756
Change-Id: I6c86b5b0bdc4b0242bc406599eb0a172f17f2d03
2021-08-05 01:44:41 +00:00
Jack Phoenix
b326dd4352 Remove capitalize-all-nouns CSS class support
Functionality has been moved to MonoBook.

Bug: T97892
Change-Id: I3d4d74a2caa77f975b415af5977253ddeff6af21
Depends-On: I598c4469c46d284562ea3aec79330f9a1f40d2ce
2021-07-30 16:59:36 +00:00
Tim Starling
62bdc0fb60 Suppress LinkCache warning about "non-proper" pages
Every special page link handled by LinkRenderer::makeKnownLink()
would generate a warning in LinkCache about the target being a
"non-proper" page. Duplicate LinkCache's sanity checks to avoid this.

Also improve LinkCache warning messages.

Change-Id: Ia2dc9136cc2edf5ee57e8f1ee54819f891b41a1c
2021-07-27 20:51:42 +10:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
James D. Forrester
719cf161f2 More master -> primary documentation and internal var renaming
Bug: T254646
Change-Id: I63cc8895033714bdfbf09aee933a8f0a43b387f3
2021-07-15 11:20:20 +01:00
DannyS712
04202c17bf MessageCache: stop reading from $wgUser
Use RequestContext::getMain()->getUser() instead.
Given that there is an explicit check if the user is safe
to load, this should be fine - if the RequestContext
doesn't already have a user, it'll create one via
User::newFromSession() and then the isSafeToLoad()
call will fail.

Bug: T243708
Change-Id: I217f169b2f5c5a0a337011e383b5171f7c7a2975
2021-07-14 04:55:07 +00:00
daniel
04c2eef862 Improve logging in LinkCache.
When reporting non-preoper LinkTargets or PageReferences, we need to
include the fragment part. Title::__toString does not, so use
TitleFormatter::getFullText instead.

For the purpose of T285951: this patch is not necessary to resolve the
bug, it just improves logging.

Bug: T285951
Change-Id: I1b4fccebae585edf07dccadfb4e8cb48e0b5d597
2021-07-01 19:21:19 +02:00
jenkins-bot
c93be24da9 Merge "Make LinkCache behavior more consistent" 2021-06-24 20:10:50 +00:00
daniel
9e49260fc9 Make LinkCache behavior more consistent
This patch does several things to LinkCache to make its behavior more
consistent and predictable:

* Methods that set a "good" link now clear the "bad link" flag, and vice
  versa.

* invalidateTitle() now also clears the local cache, not just the
  persistent cache.

* Attempts to set data for LinkTargets that are not proper local pages
  are ignored.

* All methods now accept LinkTarget|PageRecord as the key.
  The ones that previously accepted a string still allow that as well.

* addLinkObject() now consistently uses the local cache if possible,
  and consistently bypasses it if the forUpdate() flag is set.

This is all done in preparation for LinkCache being used inside PageStore.

Bug: T278940
Change-Id: I62107789fa185606a81be20ffa8f0be48297c08f
2021-06-24 18:25:55 +02:00
Tim Starling
9c3c0b704b Use array_fill_keys() instead of array_flip() if that reflects the developer's intention
array_fill_keys() was introduced in PHP 5.2.0 and works like
array_flip() except that it does only one thing (copying keys) instead
of two things (copying keys and values). That makes it faster and more
obvious.

When array_flip() calls were paired, I left them as is, because that
pattern is too cute. I couldn't kill something so cute.

Sometimes it was hard to figure out whether the values in array_flip()
result were used. That's the point of this change. If you use
array_fill_keys(), the intention is obvious.

Change-Id: If8d340a8bc816a15afec37e64f00106ae45e10ed
2021-06-15 00:11:10 +00:00
Petr Pchelko
bdecf516b9 Replace Title in Message/MessageCache
Change-Id: Ib0e36d767788edcdd8fa9ebc5de6bbde4cf50f12
2021-06-09 06:16:56 -07:00
Gergő Tisza
8925ba9c50 Add TransactionProfiler::silenceForScope()
Add a helper method for the common use case of temporarily silencing
transaction profiler warnings.

Change-Id: I40de4daf8756da693de969e5526b471b624b2cee
2021-05-16 18:19:53 +02:00
jenkins-bot
707e435a39 Merge "In MessageCache respect injected content language" 2021-05-15 02:55:53 +00:00
jenkins-bot
dba72b74c3 Merge "Optimise MessageCache::isMainCacheable() for the single-message case" 2021-05-15 02:52:30 +00:00
James D. Forrester
f2f9345e39 Replace uses of DB_MASTER with DB_PRIMARY in documentation and local variables
This is just a start.

Bug: T254646
Change-Id: I9213aad4660e27afe7ff9e5d2e730cbf03911068
2021-05-14 12:40:34 -07:00
Tim Starling
2ae37fa62e In MessageCache respect injected content language
Replace the many references to $wgLanguageCode with a cached copy of the
code of the content language passed to the constructor. The references
to $wgLanguageCode in this class were just meant to be a shortcut for
$wgContLang->getCode().

Change-Id: I60c61aaef0abe6df79ab39f123206d8aae044113
2021-05-14 09:32:38 +10:00
jenkins-bot
297d1bfb0e Merge "Remove unused default values from class properties" 2021-05-13 00:58:34 +00:00
Thiemo Kreuz
6805f39a30 Remove unused default values from class properties
In all these cases the property is unconditionally set in
the constructor. The extra initialisation is effectively
dead code and an extra source of errors and confusion.

Change-Id: Icae13390d5ca5c14e2754f3be4eb956dd7f54ac4
2021-05-12 13:44:28 +02:00
DannyS712
ba2e216399 GenderCache: remove checking for valid usernames
Violates proper DI by retrieving UserNameUtils from
MediaWikiServices instead of injecting, but can't inject
because that creates a circular dependency (UsernameUtils
indirectly relies on GenderCache via MediaWikiTitleCodec).

If callers can validate that they are only searching for the
genders of valid user names, that would be great but its
not required, at worst we just search for a few
extra database rows that don't exist.

Bug: T267054
Change-Id: I00813228e177a7a7d13969fae85cf725def8f879
2021-05-12 06:37:38 +00:00
Tim Starling
8a010024be Optimise MessageCache::isMainCacheable() for the single-message case
Loading all messages with getSubitemList() takes about 10ms per
language and loads an array with ~20k elements. When messages in many
languages are requested, this causes an OOM.

So, use getSubitemList() only when isMainCacheable() is called from
loadFromDB(). Remove the second parameter in that case, since it was
always the same.

In the getMsgFromNamespace() case, use getSubitem() to check the
specific message for existence. Have the caller specify the language, in
order to share a subitem cache entry with usual previous
getMessageForLang() call.

Bug: T247223
Change-Id: I6369f307b6bf74bd4aeb1d6e4c41d6e59e403703
2021-05-12 14:19:59 +10:00
daniel
0dec104bc0 Deferred updates: remove Title from method signatures.
This allows deferred update tasks to be constructed with a PageIdentity
rather than a Title instance.

Bug: T278459
Change-Id: Ifa2888fdef9ecc97f5bf09ae0b3fa7be48a0e9ef
2021-05-11 11:17:02 +02:00
daniel
316053ed88 LinkBatch: skip bad input
LinkBatch used to be lenient about receiving null or invalid titles.
This patch restores this lenient behavior.

Bug: T282180
Bug: T282070
Change-Id: I2c6378a3a0d508c77bcb290a6ed07f4d5f96d62c
2021-05-07 16:22:24 +02:00
Alexander Vorwerk
596344db7a Hard deprecate MessageCache::singleton()
deprecated since 1.34 and unused.

Bug: T249031
Change-Id: I6003c56f07469ffe796ccb415bb4d1e5ff8993a9
2021-05-03 14:11:21 +00:00
Alexander Vorwerk
41ae2236f0 Hard deprecate LinkCache::singleton()
deprecated since 1.28 and unused.

Bug: T249034
Change-Id: Ib21d994bf31e14f650a8684628d0b1542085c877
2021-05-03 12:32:11 +00:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
daniel
c829bfc8dd LinkBatch: replace Title with PageReference in method signatures
Bug: T278459
Change-Id: I7ed97f868f2a8a505ca4e529036d7efce6eea3ae
2021-04-26 19:54:24 +02:00
Petr Pchelko
ab9ecc0268 Drop hard-deprecated CacheHelper classes
Bug: T249230
Change-Id: I8fb43e862a19031520dda5a147e533becd7eb89e
2021-04-20 12:56:01 +00:00
daniel
90e1469012 HtmlCacheUpdater: replace Title in method signatures.
We still rely on Title internally, until the logic for mapping Titles to
URLs has been factored out.

Bug: T279796
Change-Id: I6abf30b8359fbe306c569ea290a64ed0d4105d71
2021-04-16 11:04:26 +00:00
daniel
185d535457 HTMLFileCache: replace Title in method signatures
Bug: T278459
Change-Id: I77fb37c1aec17d3e51056f85fdff59821f326cc3
2021-04-14 18:49:45 +02:00
Reedy
cce3fb49d0 Use more neutral or alternative language
Bug: T277987
Change-Id: Iafc4b3e3137936046487119b7e17635f4e560277
2021-03-20 19:47:18 +00:00
C. Scott Ananian
3f990d5b4c Inline Parser::firstCallInit() into ::__construct()
This has effectively been the case since 1.35; this just cleans up the
remaining code which assumed it still needed to explicitly call
Parser::firstCallInit() on a newly-constructed Parser.

Bug: T250444
Change-Id: I340947c721172f12ff413322b4283627c0b0b3a4
2021-03-16 19:41:56 +00:00
ZabeMath
15881aefe9 Avoid using User::isValidUserName()
User::isValidUserName is deprecated since 1.35 and should be replaced with the UserNameUtils service

Bug: T277398
Change-Id: Iaef995b992e2f38f651453092b23c928479e7d18
2021-03-14 18:04:12 +01:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
jenkins-bot
d749cbdf38 Merge "Use __CLASS__/::class to define callback for array_map/_filter/usort" 2021-02-05 03:14:42 +00:00
Petr Pchelko
c446e32682 Hard deprecate CacheHelper, ICacheHelper, CachedAction, SpecialCachedPage.
Bug: T249230
Depends-On: Ia2c6e93595905e6143cccede8478a6aac8dbf567
Change-Id: I749be35d784481671936c5ba037945f3b9ee2c4f
2021-01-25 13:34:31 -06:00
Umherirrender
e4d1a2c8bd Use __CLASS__/::class to define callback for array_map/_filter/usort
Change-Id: I3519dd5a1ce1ea688de602190cd74755c400c717
2021-01-22 16:39:29 +00:00
Ammarpad
beeccf8520 LinkBatch: Fix property documentations
* Remove incorrect null type from documentation of properties
that cannot be null.
* Add type doc for $caller and $data

Change-Id: I8d51dca7fd4910acf744361279c441fe4c3a4307
2021-01-22 07:41:07 +01:00
DannyS712
324a46f9a7 Remove hard deprecated GenderCache::singleton
Bug: T249019
Change-Id: Id0d368dc8fda78465806215a46b06022bc658b85
2020-12-18 02:21:33 +00:00
Umherirrender
ca1f2b967b Improve docs in MessageCache class
Change-Id: I6c79531691be0f80bdcfe9141ff6cc31ee9b91f9
2020-11-30 17:59:06 +01:00
jenkins-bot
e6a6592ecf Merge "Fix some unit tests accessing MediaWikiServices" 2020-11-17 18:36:37 +00:00
jenkins-bot
1976283835 Merge "Update a lot of unspecific "array" types in PHPDocs" 2020-11-13 21:48:24 +00:00
Daimona Eaytoy
95e17ee645 Fix some unit tests accessing MediaWikiServices
These are mostly easy fixes. Tests were fixed when that didn't require
any change to the tested code, and moved to /integration otherwise.

MediaWikiUnitTestCase::setTemporaryHook was removed: the
caller should provide a HookContainer, at which point it would just
become a useless wrapper around HookContainer::register. (We don't
really need it to be temporary, if proper DI is used).
The method was only used in the tests touched by this commit.

Change-Id: I2aba02560c41b77eea9dd4bff0e4d1c4bb0da9a2
2020-11-12 19:13:47 +00:00
Lucas Werkmeister
799716d78f Remove unneeded isset() before unset()
unset() does not throw an error if the value to be unset does not exist
in the first place, so guarding it with an isset() check is unnecessary.
Remove a few ifs that didn’t do anything else.

Change-Id: Ie5493c8a4c4d25e12a029d0257374527cd12303d
2020-11-10 16:52:14 +01:00
Umherirrender
de1b56caf7 Replace deprecated wfGetCache
Change-Id: I082b95bf0dcf3625f3c71689e78643b55238b5f8
2020-11-02 13:31:33 +01:00
Umherirrender
c85a43561e Improve class property documentation
Reformat existing documentation to match the format

Change-Id: I190b54b5e962f17bab6502dd1b3c02f11dc926d2
2020-10-30 10:38:58 +01:00
Thiemo Kreuz
b0130ca649 Update a lot of unspecific "array" types in PHPDocs
This includes fixing some mistakes, as well as removing
redundant text that doesn't add new information, either because
it literally repeats what the code already says, or is actually
duplicated.

Change-Id: I3a8dd8ce57192deda8916cc444c87d7ab1a36515
2020-10-28 11:01:33 +01:00
Thiemo Kreuz
1fc8d79ac6 Remove documentation that literally repeats the code
For example, documenting the method getUser() with "get the User
object" does not add any information that's not already there.
But I have to read the text first to understand that it doesn't
document anything that's not already obvious from the code.

Some of this is from a time when we had a PHPCS sniff that was
complaining when a line like `@param User $user` doesn't end
with some descriptive text. Some users started adding text like
`@param User $user The User` back then. Let's please remove
this.

Change-Id: I0ea8d051bc732466c73940de9259f87ffb86ce7a
2020-10-27 19:20:26 +00:00
DannyS712
cc464b2028 Convert UserCache to a service
Bug: T253061
Change-Id: Id951177712648dc5ac684ae38097a0e9f3e12c7a
2020-10-20 20:13:38 +00:00
jenkins-bot
72a90d3d06 Merge "Document hook names in hook interfaces." 2020-10-02 16:15:21 +00:00