Commit graph

292 commits

Author SHA1 Message Date
Aaron Schulz
eed58f2f61 rdbms: fix owner id and RELEASE_ALL_LOCKS query in session flushing methods
Use the LoadBalancer id in flushPrimarySessions(), not the LBFactory one,
and use assertOwnership() to check $owner, similar to other methods.

In DatabaseMysqlBase::doFlushSession(), change RELEASE_ALL_LOCKS() query
to use RELEASE_LOCK(), since only newer MariaDB versions (>=10.5.2) support
it. No errors were thrown in the method since they are suppressed, but the
syntax error would cause the transaction to be placed in an error state.

Add assertion to testTransactionCallbackChains() that would otherwise fail.

Randomize lock names in lock() tests to avoid contention.

Bug: T292239
Bug: T303887
Follow-Up: ee3c65d541
Follow-Up: 4cac31de4e
Change-Id: I414d737028338cfd5369eee24576df4aa26a2f6f
2022-03-17 02:55:43 +00:00
daniel
e239b02a5e Add convenience methods for asserting status.
This ensures that assertions work in a uniform way,
and provides meaningful messages in cause of failure.

Change-Id: Ic01715b9a55444d3df6b5d4097e78cb8ac082b3e
2022-03-16 22:44:25 +01:00
Alexander Vorwerk
d66fe8b7c7 Bump minimum required version for upgrade to 1.31
The policy allows this and since 1.39 is going to be the next LTS
release, I think it is fine to do this now.

Change-Id: If426e0ee349252ccc0ba9c4222c7d6865ab57fa2
2022-03-15 22:12:59 +01:00
Alexander Vorwerk
71a092e513 Add 1.38 snapshot to sqlite db tests
Change-Id: I72e703473679dbe982c8d851a6c357b17de415eb
2022-03-15 17:05:42 +01:00
jenkins-bot
98f06217ff Merge "Fix error message in test assertion" 2022-03-14 21:53:42 +00:00
Aaron Schulz
277d34818b tests: Split out DatabaseSqliteUpgradeTest class
The testUpgrades() method is slow and is easier to
parallelize via paratest if it lies in a separate class/file

Also make the test use a data provider

Bug: T50217
Change-Id: I5c8df6ae0ff34941f4cf7275680b309e79565925
2022-03-10 23:29:29 -08:00
Tim Starling
89cfcb3cfd rdbms: Followups to automatic connection recovery patch
Change-Id: I5d51224a49937a2ca4bb09a8304fef358a91db9c
2022-03-10 05:30:22 +00:00
Subramanya Sastry
8aae1a0b21 Fix error message in test assertion
Change-Id: Id7604d9af623ffdb77b16960e8b9ca893d368963
2022-03-09 16:29:25 -06:00
Aaron Schulz
4cac31de4e rdbms: make automatic connection recovery apply to more cases
Rename canRecoverFromDisconnect() in order to better describe
its function. Make it use the transaction ID and query walltime
as arguments and return an ERR_* class constant instead of a bool.
Avoid retries of slow queries that yield lost connection errors.

Add methods and class constants to track session state errors
caused by the loss of named locks or temp tables. Such errors can
be resolved by a "session flush" method.

Make assertQueryIsCurrentlyAllowed() better distinguish ROLLBACK
queries from ROLLBACK TO SAVEPOINT queries. For some scenarios,
only full tranasction ROLLBACK queries should be allowed.

Add flushSession() method to Database and flushPrimarySessions()
methods to LBFactory/LoadBalancer.

Also:
* Rename wasKnownStatementRollbackError() and make it take the
  error number as an argument, similar to wasConnectionError().
  Add mysql error codes for query timeouts since they only cause
  statement rollbacks.
* Rename wasConnectionError() and mark it as protected. This is an
  internal method with no outside callers.
* Rename wasQueryTimeout(), remove some HHVM-specific code, and
  simplify the arguments.
* Make executeQuery() use a for loop for the query retry logic
  to reduce code duplication.
* Move the error state setting logic in executeQueryAttempt() up
  in order to reduce code duplication.
* Move the beginIfImplied() call in executeQueryAttempt() up to the
  retry loop in executeQuery(). This narrows the executeQueryAttempt()
  concerns to sending a single query and updating tracking fields.
* Make closeConnection() and doHandleSessionLossPreconnect() in
  DatabaseSqlite more consistent with the base class by releasing named locks.
* Mark trxStatus() as @internal.

Bug: T281451
Bug: T293859
Change-Id: I200f90e413b8a725828745f81925b54985c72180
2022-03-09 15:49:38 +11:00
Timo Tijhof
fb7e47fd5a block: Use $wgUpdateRowsPerQuery for purgeExpiredBlocks()
Follows-up I052735edbfac.

Bug: T301742
Change-Id: Iec989945f4c592d7569e62199dd8190c535acae7
2022-03-04 22:40:53 +00:00
Ammarpad
e9e3c4a75f Fix broken SQLite test and simplify.
This is not testing anything since tables.sql was emptied
in I9f33132

It's probably also no longer necessary, since the schema
is now generated by Doctrine per platform, but I am not sure
about that, so I am just fixing the test and simplifying it.

Change-Id: Icb4d04e6057958771eb00a31b967a42cc948d6a1
2022-03-02 22:39:53 +01:00
jenkins-bot
24aa34d06c Merge "phpcs: Disable Generic.Files.LineLength for test files" 2022-02-21 15:51:29 +00:00
Timo Tijhof
8d406bbcd6 phpcs: Disable Generic.Files.LineLength for test files
There is a common and reasonable need for longer lines in tests.
The nudge for shorter lines doesn't seem valuable here. The natural
breaks will likely still fall in 80-100 given the enforced practice
for non-test code, e.g. whether through habit, or 80-100 column markers
in text editors, or the finite width of diff and code review
interfaces.

Change-Id: I879479e13551789a67624ce66f0946d2f185e6ee
2022-02-18 18:32:05 +00:00
Ammarpad
a078ad29d5 CommentParser: Treat known titles as always known for linking
Existence of global userpages (or similar nonlocal pages)  can only be
known if the relevant title hook is involved, but LinkBatch is caching
these pages as bad links immediately after querying the local database.

CommentParser is then relying on this information to treat them as
always bad; thus preempting any further checks that might be done by
LinkRenderer to properly account for their magical existence.

Now title always-known status will be checked, to preempt bad linking.

Bug: T293665
Change-Id: Ica8733fb4a890fd2d2fc37eb85657c3715805133
2022-02-18 10:20:51 +00:00
Sam Smith
f18338fadd TemplateParser: Only hash unique files
LightnCandy resolves recursively-defined partials twice, which leads to
the template file being hashed twice. While the cost of hashing the
partial the second time is minimised due to
FileContentsHasher::getFileContentsHash() caching the hash of a file in
APCu, it need not be paid.

Bug: T300210
Change-Id: Id3f62bf32c47f21181b1ec6d77a5ae9a703952b1
2022-02-09 14:12:24 +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
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Tim Starling
6ccfe5d5c9 Fix PHP 8.0 failure of WikiExporterFactoryTest
In PHP 7, "some unlikely string 2" was a valid value for the $text
parameter to XmlDumpWriter::__construct(), because non-strict comparison
was used, so "some unlikely string 2" was coerced to integer 0 which is
equal to WRITE_CONTENT. In PHP 8.0, non-strict comparison has changed such
that "some unlikely string 2" != 0.

Pass strict=true to in_array() so that the test fails on both versions.
Please review for potential production impact.

Fix the test so that it passes after this change.

Bug: T283275
Change-Id: I5a84fb70db9d02ea10f87299eb41f80ba8fc787c
2022-01-21 15:20:57 +11:00
Tim Starling
84f0876b83 Add regression test for LinksDeletionUpdate loss of page_id
Bug: T299244
Change-Id: Ica31000df693ff6a4ab2c54c88b6cbdc7e70d6d0
2022-01-17 12:10:57 +11:00
jenkins-bot
3cf9b2e64d Merge "DeletePage: add option to delete the associated talk page" 2022-01-16 03:00:37 +00:00
Alexander Vorwerk
40d6ad9ed9 Inject MainConfig into actions
Change-Id: I395d7870c5dc75ed83e7202c8ac709dfd04392c2
2022-01-12 22:30:31 +01:00
Daimona Eaytoy
f976775201 DeletePage: add option to delete the associated talk page
Currently this is implemented internally as a second method call. In the
future, it might be possible to optimize the implementation, e.g. to
reduce the amount of DB queries/jobs etc. without changing anything for
callers.

Since the implementation of e.g. the result getters is generic, a future
commit may add an option to delete subpages with relatively low effort.

The revision limit for big deletions is now using the total number of
revisions (base page + talk page). This is because both deletions would
happen in the same main transaction, and we presumably want to optimize
the deletion as a whole, not as two separated steps. This would become
even more important if the aforementioned improvements are ever
implemented. Note, the whole concept of "big deletion" might have been
superseded by batched deletions in the author's opinion, but as long as
such a limit exists, it should serve its purpose.

The current interpretation of the associated talk option is that the
request is validated, and an exception is raised if we cannot delete the
associated talk, as opposed to silently ignoring the parameter if the
talk cannot be deleted. The only exception to this is that it will not
fail hard if the talk page turns out not to exist by the time the
deletion is attempted, as that's hard to foresee due to race conditions.

Note that the summary for the talk deletion is prefixed with the
delete-talk-summary-prefix message. The main reason behind this is that
the delete UI can sometimes offer an auto-generated summary like "the
only contributor was XXX" or "the content was YYY", and since this may
not apply to the talk page as well, the log entry might look confusing.

Bug: T263209
Bug: T27471
Change-Id: Ife1f4e8258a69528dd1ce8fef8ae809761aa6f1d
2022-01-11 14:48:56 +01:00
jenkins-bot
87dc11393d Merge "UserSelectQueryBuilderTest: Test behavior of hidden()" 2021-12-22 07:05:53 +00:00
Amir Sarabadani
050fbbec8f rdbms: Remove IDatabase::numFields() method
Soft-deprecated since 1.37.

Unused https://codesearch.wmcloud.org/search/?q=numFields&i=nope&files=&excludeFiles=&repos=

Bug: T286694
Bug: T296960
Change-Id: I722602c8b11dcfc5cab70593876a4fb336e9684a
2021-12-21 23:10:49 +00:00
Martin Urbanec
8ce472ce91 UserSelectQueryBuilderTest: Test behavior of hidden()
Bug: T291966
Change-Id: If22d5db53e71bb7a49a71a8d00be42ccc3b158c3
2021-12-20 15:59:15 +01:00
Kosta Harlan
ac80347d99 SpecialPageAliasTest: Don't access MW services in dataProvider
Bug: T297292
Change-Id: I31ecb1f6ad26b6163e0435f5a9c5cbbcd5888c57
2021-12-08 15:54:13 +01:00
Kosta Harlan
c9da85abb5 UpdateHandlerTest: Don't access MW services in dataProvider
Bug: T297292
Change-Id: I22777f933e2351cc11735ff75861174c80d81bd4
2021-12-08 15:54:13 +01:00
Kosta Harlan
63dfd39c11 RestrictionStoreTest: Don't access services in data providers
Otherwise a deprecation warning is emitted with vendor/bin/phpunit

Bug: T297292
Change-Id: I75414b16c781f0272bf7d10150ba1302da06e65a
2021-12-08 15:54:13 +01:00
Kosta Harlan
ce10edfbc4 CreationHandlerTest: Don't access MW services in dataProvider
Bug: T297292
Change-Id: I2e7d4fa7e9fd0861ecb4eaf0687c9dc1cbe144f7
2021-12-08 15:25:20 +01:00
jenkins-bot
b085cd60cf Merge "Change return format of DeletePage again" 2021-12-06 22:20:15 +00:00
Umherirrender
3f08cd753a Replace deprecated Language::fetchLanguageNames
Change-Id: Iecd5481edb4dae6c7911157e24c32a51f4438ab2
2021-12-05 21:11:49 +01:00
Daimona Eaytoy
0e558da7b8 Change return format of DeletePage again
In retrospect, I rushed the previous patch: we really need a way to tell
which deletion an ID belong to (and whether it was scheduled). So make
both result getters return an array with known keys that can be used
programmatically. Right now the class can only delete a single page, and
thus there's a single constant and this change is effectively a noop.

The deletionWasScheduled() method, introduced in 1.37, was
hard-deprecated out of an abundance of caution. There are no known uses
on codesearch, so it can probably just be removed in the next release.

Also reorder constructor params to DeletePage -- BacklinkCacheFactory is
a service injected by the factory, hence it shouldn't be grouped
together with value objects injected by the caller.

Change-Id: I32679b7cacc638ec3e9dc5b8dfe9bcc794b22ecf
2021-11-29 15:09:42 +00:00
Majavah
7e3df796b0 Revert "Remove last User dependencies from File"
This reverts commit 73a25838b4.

Reason for revert: T296508

Bug: T296508
Change-Id: I8af37665eeb284b85157a72459d43261ec4829ed
2021-11-26 17:06:36 +00:00
Petr Pchelko
73a25838b4 Remove last User dependencies from File
Change-Id: I953fcc66b5cde1ef481178b08e16c50b8a118702
2021-11-26 05:42:00 +00:00
Reedy
6e29611642 Remove or replace usages of "sanity"
Still some more to go...

Bug: T254646
Change-Id: Ia117f01e443c35b4765f3275cab4f2707e1be96f
2021-11-21 16:42:31 +00:00
Thiemo Kreuz
ee0f97378b Replace new stdClass with more compact array syntax
It does the exact same. The resulting object is still an stdClass
instance.

Change-Id: Ief68609943ee30aa95732d24021c921dfbad166c
2021-11-02 09:43:03 +00:00
Daimona Eaytoy
965f6db3c1 Change return format of DeletePage entrypoints
Instead of putting logID/false in the status' value, add getters that
can be used to retrieve this information. Also, make it return an array
of log IDs, which is easier to expand later on to account for deletion
of related pages (e.g. associated talk page).

Note: this change will be backported to 1.37.

Bug: T288758
Change-Id: I7ef64242ae0cb7018a4b1e8eb004a5563925b9a4
2021-10-20 19:26:12 +00:00
Alexander Vorwerk
0a86c3655d phpunit: Fix parameter order on two assertSame() calls
The first parameter of assertSame() is the expected value, the second
one the actual value.

Change-Id: I5a411403443f18b30c93ab9552f625a70c75f75c
2021-10-12 20:22:34 +00:00
Amir Sarabadani
c3fff36540 Add 1.36 and 1.37 snapshots to sqlite db tests
To make sure upgrades from those versions work properly

Change-Id: I570cf965286bc5358a43c9601217b8781bb09b0e
2021-09-29 20:13:38 +02:00
jenkins-bot
3ab14c18ca Merge "Move Content::getParserOutput & AbstractContent::fillParserOutput to ContentHandler" 2021-09-29 13:10:00 +00:00
Roman Stolar
a68e641f9d Move Content::getParserOutput & AbstractContent::fillParserOutput to ContentHandler
Update/Create override classes of ContentHandler.
Soft-deprecate and remove method from Content and classes that override them.

Bug: T287158
Change-Id: Idfcfbfe1a196cd69a04ca357281d08bb3d097ce2
2021-09-29 13:10:51 +03:00
jenkins-bot
ff04006810 Merge "Bump minimum required version for upgrade to 1.29" 2021-09-29 07:43:48 +00:00
Tim Starling
f7f84dddb3 Introduce CommentFormatter
CommentParser:

* Move comment formatting backend from Linker to a CommentParser service.
  Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
  was used for.
* Rename the "autocomment" concept to "section link" in public
  interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
  static analysis and code review.

CommentFormatter:

* Add CommentFormatter and RowCommentFormatter services as a usable
  frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.

Linker:

* Remove Linker::makeCommentLink() without deprecation -- nothing calls
  it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
  commentBlock() and revComment().

Caller migration:

* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
  ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
  ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
  ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager

Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-09-28 11:13:03 -07:00
Amir Sarabadani
753a4ecdd3 Bump minimum required version for upgrade to 1.29
Since the branch cut has happened, we can bump and get rid of legacy
cruft. According to the policy we can go up to 1.31 but let's keep it
that way to avoid major distruptions.

Change-Id: I9d697445a3bb5047726c8b2a7f808edb8403cdda
2021-09-28 17:57:57 +02:00
jenkins-bot
62d9c60273 Merge "Detect and monitor against multiple Parser invocation during edit requests" 2021-09-23 22:01:43 +00:00
Cindy Cicalese
eed48e402b Detect and monitor against multiple Parser invocation during edit requests
Bug: T288707
Change-Id: I0cca8f9bcf1d6e964b8b06c0c4490e83f4fb1de5
2021-09-23 16:12:40 -05:00
Derick Alangi
2432cc2bb4 Use PageUpdater's fluent interface as in some parts of our codebase
Some methods in the PageUpdater's class implements the fluent interface
design pattern. Use the fluent interface where need be.

Change-Id: If76a4b8c5070c20ed40038a4ee78e2d677de5180
2021-09-23 00:31:33 +01:00
Martin Urbanec
408999928d
HTMLTitleTextField: Remove B&C code
Bug: T288181
Change-Id: Iec9225d0f0fe47dd972f6c302ca803e65b8232a7
2021-09-22 00:48:59 -07:00
Umherirrender
bcee220ad1 tests: Avoid non-namespaced aliases for Wikimedia\Rdbms namespace
Change-Id: I49cb151f64c578f41dc1236b2a8906694ca97b93
2021-09-18 20:24:08 +02:00
Alexander Vorwerk
ecbaedbad2 Reapply "GrantsInfo service to replace MWGrants"
This patch adds a service as a replacement for MWGrants. This is done
as it allows proper dependency injection of used services and
configuration settings.

This was previously committed as Iac52dba15f and reverted because it
introduced recursive service instantiation.

To avoid this recursive service instantiantion all UI related methods
get moved to a new GrantsLocalization service, instead of the GrantsInfo
service.

Bug: T253077
Change-Id: Ib900bc424fc272ec709d272dcaff71398fa856f8
2021-09-18 08:52:22 +00:00