Commit graph

99 commits

Author SHA1 Message Date
jenkins-bot
5a53d57449 Merge "LinkCache: soft deprecate addGoodLinkObj()" 2021-09-10 17:22:02 +00:00
jenkins-bot
7ece0e7afd Merge "Title: Make use of BacklinkCacheFactory service" 2021-09-10 14:31:23 +00:00
daniel
855988fd0e LinkCache: soft deprecate addGoodLinkObj()
addGoodLinkObj() has many optional arguments, but omitting them actually
means corrupting the cache.

Nearly all existing callers are in tests.
So LinkCacheTestTrait::addGoodLinkObject() was created only
for testing. It is better to have this method in the
trait, because building the row directly in each test
would make these tests brittle against schema changes.

The only usage in WMF production code was in WikiPage and has been
fixed.

Bug: T284955
Change-Id: I03a2bd9ed64fcc0281ee29a286c8db395a9e03d9
2021-09-10 16:00:02 +02:00
jenkins-bot
1efeefe017 Merge "PageStore: Use LinkCache" 2021-09-09 20:04:47 +00:00
Derick Alangi
db43511e6a Title: Make use of BacklinkCacheFactory service
Change-Id: I48161585de6f329ec4037156234e0b07b3b837e6
2021-09-09 14:04:02 +01:00
Derick Alangi
96bc83e8eb Add BacklinkCacheFactory Service
Bug: T279433
Change-Id: I2943935e2d8148fce4457f76eca0234be72a5a5a
2021-09-09 09:58:52 +01:00
daniel
3b6345ca16 PageStore: Use LinkCache
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
2021-09-01 08:24:34 +00:00
TChin
e1ef35e713 Test new methods in BacklinkCache
Bug: T288614
Change-Id: Ifdced6549b30e27803a37678915f3571332356fd
2021-08-30 15:41:02 +00:00
TChin
de50954fdb Test BacklinkCache
Bug: T288614
Change-Id: I5a45bb0e7b179a1b545ed422fc2b6e7efd664d10
2021-08-19 17:29:05 +00: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
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
jenkins-bot
dba72b74c3 Merge "Optimise MessageCache::isMainCacheable() for the single-message case" 2021-05-15 02:52:30 +00:00
DannyS712
29e8f74b5c GenderCacheTest: fix call to overrideMwServices()
MediaWikiIntegrationTestCase::overrideMwServices() is not static
and should not be called statically

Change-Id: I9d1f07b5bca8a39b82017e59978f2b28c399803e
2021-05-12 07:37:19 +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
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
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
jenkins-bot
123a0e25e7 Merge "LinkBatch: replace Title with PageReference in method signatures" 2021-04-27 23:12:29 +00:00
daniel
c829bfc8dd LinkBatch: replace Title with PageReference in method signatures
Bug: T278459
Change-Id: I7ed97f868f2a8a505ca4e529036d7efce6eea3ae
2021-04-26 19:54:24 +02:00
Thiemo Kreuz
40764d277c Replace PHPUnit ->returnValue() with ->willReturn() shortcut
It's the same and makes the test code much more readable, I
would like to argue.

Because of the was I split all the changes I made into smaller
patches this patch contains some other changes in the same
lines where I could not split them off. E.g. removal of
->any(), which is the default anyway and doesn't do anything.

Change-Id: Ib297b989d4aec33b31a4e33fe9d5032865b39be0
2021-04-22 10:37:45 +02:00
Daimona Eaytoy
535d7abf59 phpunit: Mass-replace setMethods with onlyMethods and adjust
Ended up using
  grep -Prl '\->setMethods\(' . | xargs sed -r -i 's/setMethods\(/onlyMethods\(/g'

special-casing setMethods( null ) -> onlyMethods( [] )

and then manual fix of failing test (from PS2 onwards).

Bug: T278010
Change-Id: I012dca7ae774bb430c1c44d50991ba0b633353f1
2021-04-16 20:15:00 +02:00
DannyS712
23e7aef711 LocalisationCacheTest: remove legacy setting of globals
No longer needed, now provided via ServiceOptions injection

Change-Id: Icaa8c730c607b9372ad2ae7ba575c8578b031aaf
2021-03-22 16:37:12 +00:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
DannyS712
6a93b0ca93 More misc test cleanup
* parent::setUp() should be first, and ::tearDown()
  should be last
* Move tests that directly extend PHPUnit\Framework\TestCase
  to /unit

Change-Id: I1172855c58f4f52a8f624e6d596ec43beb8c93ff
2020-12-24 00:52:06 +00:00
daniel
7ffacacc6b MCR import
Bug: T220525
Change-Id: I7d41a8af12e33aed802526eb39a0880292c4f534
2020-07-18 20:34:16 -04:00
addshore
959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
The name change happened some time ago, and I think its
about time to start using the name name!
(Done with a find and replace)

My personal motivation for doing this is that I have started
trying out vscode as an IDE for mediawiki development, and
right now it doesn't appear to handle php aliases very well
or at all.

Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
2020-06-30 17:02:22 +01:00
Umherirrender
63eaa9ae89 Use DefaultOptionsLookup for default option in GenderCache
Change-Id: I778d2c4cd8de2aee138566fe82d658d046edf3f4
2020-06-28 16:53:24 +02:00
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00
DannyS712
d349b03db9 Make MessageCacheTest::makePage private, return RevisionRecord
Replace WikiPage::doEditContent with PageUpdater

Bug: T249393
Bug: T250638
Change-Id: I69bfe2c8e47a75171584fd0a984a4f37f88a3d4b
2020-05-21 03:25:05 +00:00
Timo Tijhof
c036b6aa5b cache: Remove use of $wgContLanguageCode in MessageCacheTest
Has been an unconfigurable copy of $wgLanguageCode,
since 2006 (MW 1.8).

Bug: T247674
Change-Id: I35f03bfcbf416d8689ba7b42c2bc4b9b0f1376e3
2020-03-15 00:23:02 +00:00
Umherirrender
3161311c5a Use MediaWikiServices::getMessageCache
Change-Id: I07fcc9529991adc634c10e5ed8498ac138a1c2b7
2020-03-14 14:25:03 +01:00
mainframe98
297a89069a Add LinkBatchFactory to inject services into LinkBatch
All services required by LinkBatch are now injected by the
LinkBatchFactory. The constructor for LinkBatch has been
soft-deprecated, but the required services are still optional.

Bug: T239855
Depends-On: If49cbb730d4ac48586b891908cf24601efbc5d6a
Change-Id: I93d931ab60305ad49a6e419f8269c77791a3938d
2020-01-06 17:02:31 +01:00
daniel
e98094956a Don't fail hard on bad titles in the database.
This updates some code that has been constructing TitleValue directly
to use TitleValue::tryNew or TitleParser::makeTitleValueSafe.

Bug: T200055
Change-Id: If781fe62213413c8fb847fd9e90f079e2f9ffc9d
2019-11-25 22:15:38 +01:00
Max Semenik
48a323f702 tests: Add explicit return type void to setUp() and tearDown()
Bug: T192167
Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43
Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
2019-10-30 14:31:22 -07:00
Umherirrender
5bd311b1a2 Add public as visibility in tests folder
Add public, protected or private to function missing a visibility
Enable the tests folder for the phpcs sniff

Change-Id: Ibefce76ea9984c47e08c94889ea2eafca7565e2c
2019-10-10 21:55:37 +02:00
jenkins-bot
52b44696ba Merge "Split some Language methods to LanguageNameUtils" 2019-10-08 21:10:07 +00:00
James D. Forrester
ebac0247cf Services: Convert LocalisationCache's static to a const now HHVM is gone
Change-Id: If5c015debed7efc034613b976bc5292ac30036d7
2019-10-08 11:25:30 -07:00
Aryeh Gregor
6d80b6c082 Split some Language methods to LanguageNameUtils
These are static methods that have to do with processing language names
and codes. I didn't include fallback behavior, because that would mean a
circular dependency with LocalisationCache.

In the new class, I renamed AS_AUTONYMS to AUTONYMS, and added a class
constant DEFINED for 'mw' to match the existing SUPPORTED and ALL. I
also renamed fetchLanguageName(s) to getLanguageName(s).

There is 100% test coverage for the code in the new class.

This was previously committed as 2e52f48c2e and reverted because it
depended on e4468a1d6b, which had to be reverted for performance
issues. There should be no changes other than rebasing.

Bug: T201405
Change-Id: Ifa346c8a92bf1eb57dc5e79458b32b7b26f1ee8a
2019-10-07 15:20:52 -07:00
Aryeh Gregor
043d88f680 Make LocalisationCache a service
This removes Language::$dataCache without deprecation, because 1) I
don't know of a way to properly simulate it in the new paradigm, and 2)
I found no direct access to the member outside of the Language and
LanguageTest classes.

An earlier version of this patch (e4468a1d6b) had to be reverted
because of a massive slowdown on test runs. Based on some local testing,
this should fix the problem. Running all tests in languages is slowed
down by only around 20% instead of a factor of five, and memory usage is
actually reduced greatly (~350 MB -> ~200 MB). The slowdown is still not
great, but I assume it's par for the course for converting things to
services and is acceptable. If not, I can try to optimize further.

Bug: T231220
Bug: T231198
Bug: T231200
Bug: T201405
Change-Id: Ieadbd820379a006d8ad2d2e4a1e96241e172ec5a
2019-10-07 13:18:47 -07:00
Thiemo Kreuz
32a429e8c4 tests: Prefer assertSame() when comparing the integer 0
assertSame() is guaranteed to not do any type conversion. This can be
critical when acciden tially comparing, for example, 0 to 0.0.

Change-Id: Iffcc9bda69573623ba14af655dcd697d0fcce525
2019-09-19 15:35:23 +00:00
Aryeh Gregor
7fb4a95563 Remove unneeded overrideMwServices/resetServices
Change-Id: If6cbdec05b8f310ef3a0b4649aaa16d9fb80a047
2019-08-29 14:26:18 +03:00
Amir Sarabadani
308e6427ae Revert "Make LocalisationCache a service"
This reverts commits:
 - 76a940350d
 - b78b8804d0
 - 2e52f48c2e
 - e4468a1d6b

Bug: T231200
Bug: T231198
Change-Id: I1a7e46a979ae5c9c8130dd3927f6663a216ba753
2019-08-26 18:28:26 +02:00
Aryeh Gregor
2e52f48c2e Split some Language methods to LanguageNameUtils
These are static methods that have to do with processing language names
and codes. I didn't include fallback behavior, because that would mean a
circular dependency with LocalisationCache.

In the new class, I renamed AS_AUTONYMS to AUTONYMS, and added a class
constant DEFINED for 'mw' to match the existing SUPPORTED and ALL. I
also renamed fetchLanguageName(s) to getLanguageName(s).

There is 100% test coverage for the code in the new class.

Change-Id: I245ae94bfc1f62b6af75ea57525139adf2539fe6
2019-08-23 12:52:35 +03:00
Aryeh Gregor
e4468a1d6b Make LocalisationCache a service
This removes Language::$dataCache without deprecation, because 1) I
don't know of a way to properly simulate it in the new paradigm, and 2)
I found no direct access to the member outside of the Language and
LanguageTest classes.

Change-Id: Iaa86c48e7434f081a53f5bae8723c37c5a34f503
2019-08-22 14:25:18 +03:00
Aryeh Gregor
752e7dd707 Convert MessageCache to service
Depends-On: Ia70e6c75f6e8a533f20cd44ebb05e013678e9951
Depends-On: I546eda0377f3a50843144b1450d3fbe8e4e02a8a
Change-Id: I305539a8598535a73e5cd280b2becdafa740ef97
2019-08-18 12:11:36 +03:00
Roan Kattouw
bcb6b9d0eb MessageCache: Fix isMainCacheable() logic for non-content languages
The way isMainCacheable() was used, it always returned false in
non-content languages, because it would try to find strings like
'hidetoc/fr' in the array of message keys (which contains strings like
'hidetoc').

The consequence of this was that MessageCache would check the database
for a MediaWiki:hidetoc/fr page even if it already knew that that page
didn't exist. This is a substantial performance hit when requesting lots
of messages, like when building version hashes for ResourceLoader's
startup module.

Follows-up 4fc5ba8bf8.

Bug: T228555
Change-Id: I20433175ca919acc1c995f4a9cd50ca53afcdd02
2019-07-20 03:41:14 +00:00
Thiemo Kreuz
8a4e15db7f Add missing newline between <?php and namespace/use section
The rest of the codebase is using this code formatting standard.

Change-Id: I4d2ba61757a7e28d40096d9dc5915005c340d4f2
2019-06-03 13:36:48 +00:00
Brad Jorsch
0301c8e03a Default $wgActorTableSchemaMigrationStage to READ_NEW
Probably good to start testing this in CI sometime soon.

The unit tests being changed here are:
* Hacky importing of a revision in MessageCacheTest, changed to use an
  interwiki username.
* WikiPageDbTestBase will get null rather than 0 for ar_user.
* DumpTestCase was using a custom IP $wgUser when creating its test
  revisions, which was winding up referring to an actor_id that had been
  deleted from the database. Fixed by having it use a registered user
  instead.

Also this has MediaWikiTestCase reset the $wgUser User object when the
actor table is truncated, as various tests were otherwise failing because
it was caching a later-deleted actor ID for User:127.0.0.1.

Bug: T188327
Change-Id: Ic483d0fda931810ac639b9de1cc5e5a4ef8161cc
Depends-On: I1bd0288cc132627d75b4001219522ec5e952eda7
2019-04-09 13:50:41 -04:00
daniel
3620931e69 Fix MessagecacheTest::testLoadFromDB_fetchLatestRevision
This re-enables the "flaky" testLoadFromDB_fetchLatestRevision which
was disabled because it failed on random patches for no apparent
reason, as documented in T219042.

The reason was an invalid timestamp in the test data, which caused
the timestamp to default to "now", which was "sometimes" newer than
the timestamp of the revision immediately created before.

Bug: T219042
Bug: T218918
Change-Id: I38f4816b2dc735a7698626c7e3fe4a93ec95a9d1
2019-03-25 11:37:30 +00:00
Max Semenik
6222d8931f Disable flapping MessageCacheTest::testLoadFromDB_fetchLatestRevision()
Bug: T219042
Bug: T218918
Change-Id: I93ed4d088691bfc50aeef1f9c07af5a6dc50de4b
2019-03-23 18:52:13 -07:00
daniel
f8dc579261 Only load latest revision in MessageCache::loadFromDB
In Id044b8dcd7c, we lost a condition that ensured that the cache would
be populated with the latest revision. Now it was being populated with
all revisions, with a random one winning.

Bug: T218918
Change-Id: I1a47356ea35f0abf35bb1a3489d0d3442a3400a5
2019-03-22 15:44:14 +01:00