Commit graph

7261 commits

Author SHA1 Message Date
jenkins-bot
d71db83e74 Merge "Don't process "all" option in Html::namespaceSelectorOptions" 2019-07-06 15:17:54 +00:00
jenkins-bot
c069752a95 Merge "rdbms: clean up $groups logic in LoadBalancer and expand comments" 2019-07-05 22:00:09 +00:00
jenkins-bot
11aa19e5f2 Merge "Bidi isolate user names in block error paramters" 2019-07-05 19:25:38 +00:00
Thalia
8cfa62d837 Bidi isolate user names in block error paramters
This fixes parameters returned by AbstractBlock::getBlockErrorParams,
but not those from ApiBlockInfoTrait.

Change-Id: I122017808766de1e9a9035f2f39a7b08607e56c1
2019-07-05 15:01:26 +01:00
jenkins-bot
77cc011b9c Merge "SlotRecord:compute sha1 if empty." 2019-07-05 06:56:31 +00:00
Aaron Schulz
ab09cf2fa5 rdbms: clean up $groups logic in LoadBalancer and expand comments
Split out private resolveGroups() method for normalizing query
groups. Move some server index validation to getConnectionIndex()
and make it stricter.

Make getConnectionIndex() group fallback logic aware of the generic
group. The main use case for custom default groups is heavy scripts
or jobs that run in the background. It is probably better to have
good DB server redundancy for the query group and rely on it rather
than possibly fallback onto all of the main servers used for normal
requests. The later behavior could spread slowness or outages.

Also make getAnyOpenConnection() more robust and readable by
splitting out a private pickAnyOpenConnection() method that
checks IDatabase::trxLevel().

In addition, remove redundant is_int() check from isOpen()
method as it will return false in that case even without it.

Remove bogus getConnection() parameter in testCopyTestData().

Change-Id: Ica619c5487c761c724791d151db7388e4b41b0aa
2019-07-04 22:26:55 +00:00
Timo Tijhof
a69880e05c resourceloader: Only output ResourceLoaderDynamicStyles when needed
In mediawiki.js, this marker has always been optional, falling back to
appending to <head>. When no stylesheets need to be after the marker
(e.g. no site styles on the wiki, and user is not logged-in), then
there is no need for the marker to exist.

In a previous refactor, I was going to do this and created an
"$append" variable in the function to do what this commit does,
but I forgot to actually use it for anything.

Test Plan:
* Local wiki, with no MediaWiki:Common/{Skinname}.css pages existing.
* When logged-out, before this change, there is a marker, now there is not.
* When creating "MediaWiki:Group-user.css" and logging in, there is still
  a marker, and it is still above the <link> for that user styles request
  in the <head>.

Bug: T219342
Change-Id: I2e9657f318088860916823efeb96ae4f1532974c
2019-07-04 19:14:39 +00:00
jenkins-bot
2b4c62b597 Merge "rdbms: make implement IResultWrapper directly instead of via inheritence" 2019-07-04 13:58:16 +00:00
Aaron Schulz
a830c14d0b rdbms: make implement IResultWrapper directly instead of via inheritence
Change-Id: If1b15c0c21d0ee336025fb99f47fc19ddf1d5435
2019-07-04 13:42:53 +00:00
Aaron Schulz
1b031cbf3f rdbms: make temp table tracking in Database more robust
Do not register table changes until query success

Change-Id: I8c0eeb510d15e2f4cc014f62b7a0f146e31b6613
2019-07-04 13:36:30 +00:00
daniel
440d9b84be SlotRecord:compute sha1 if empty.
The SHA1 should be computed automatically if empty, not just if it is
missing entirely. This is needed since rev_sha1 may contain an empty
string for old revisions.

Bug: T200653
Bug: T219816
Change-Id: Ia6870a828bc9661fb05085e36315a86483ec48c4
2019-07-04 08:57:17 +00:00
Matěj Suchánek
5fa9a2a191 Don't process "all" option in Html::namespaceSelectorOptions
The value of "all" can be completely arbitrary and in practice
it's usually an empty string. Avoid attempting to filter it out
and format anyhow.

Bug: T227202
Change-Id: I371466407bd038914faa4dc3b0cae9547cf427eb
2019-07-04 10:17:59 +02:00
jenkins-bot
5326140b30 Merge "LogFormatter::formatParameterValue: handle bad user names" 2019-07-03 18:49:45 +00:00
jenkins-bot
932daf05d2 Merge "Ensure canHaveTalkPage returns false when getTalkPage would fail." 2019-07-03 16:55:34 +00:00
daniel
20717fd031 LogFormatter::formatParameterValue: handle bad user names
This makes LogFormatter more robust against bad user names coming from
broken log records.

Bug: T224368
Change-Id: Ifce9e86bddba274182253cd25338766e8093d6ad
2019-07-03 18:49:58 +02:00
jenkins-bot
b7e7a97da6 Merge "Assert that LocalSettings file exists" 2019-07-03 12:35:00 +00:00
daniel
dbce648a15 Ensure canHaveTalkPage returns false when getTalkPage would fail.
This causes Title::getTalkPage and NamespaceInfo::getTitle() to throw
an MWException when called on a LinkTarget that is an interwiki link
or a relative section link. These methods were already throwing
MWException when called on a link to a Special page.

Bug: T224814
Change-Id: I525c186a5b8b8fc22bca195da48afead3bfbd402
2019-07-03 10:40:10 +02:00
jenkins-bot
7387f89ea0 Merge "tests: Use a fancy generator provider in ReleaseNotesTest" 2019-07-02 21:05:53 +00:00
Timo Tijhof
215c1f8ecc tests: Use a fancy generator provider in ReleaseNotesTest
Follows-up ffc23ee333.

Change-Id: I99bf0d7115f6d2a84eb499d104d9cd227331c20f
2019-07-02 19:49:43 +01:00
jenkins-bot
e7a4f38c7e Merge "Move trivial unit tests, round II" 2019-07-02 18:47:38 +00:00
Amir Sarabadani
095f5583cb Move trivial unit tests, round II
Change-Id: I18e5a1514d7372b34f7fb460adf506a1ac65001f
2019-07-02 19:52:29 +02:00
Kosta Harlan
822efb467d Assert that LocalSettings file exists
This time, use $IP to get correct path to LocalSettings so that tests can be run
from outside MediaWiki root.

Change-Id: I0dd3dd281cff67b0d8acdc09b97328c44eca2bb6
Follows-Up: Ia36d22217f94e019bb5945705243bd0daace72e0
Bug: T226977
2019-07-02 11:57:00 -04:00
Antoine Musso
ffc23ee333 test: refactor/speed up release note file test
The test ReleaseNotesTest:testReleaseNotesFilesExistAndAreNotMalformed
takes 4 seconds on my machine. That is due to assertLessThanOrEqual
being invoked for each lines of various files at the root of the
repository. HISTORY has more than 20000 lines and assert functions are
rather slow.

Refactor the test:
* extract the logic to verify the file length of various files to a
  standalone test and with a dataprovider.
* flip the boolean logic ensuring whether the file exists. When it does
  not, PHP emit a warning which breaks the test anyway.
* Check the line lenght and collect errors in an array, then for each
  file run a single assertion to ensure the array of errors is empty.
  That effectively get rid of assertLessThanOrEqual overhead.
* Use assertSame() to show the full faulty line. assertEqual() shorten
  the arrays content.

Running tests went from 4 seconds to 700 ms on my machine.

Bug: T227067
Change-Id: I9bbbc6647ba9732b462e331e4b6d4acffe35e7cd
2019-07-02 12:12:19 +02:00
jenkins-bot
9b460b64cd Merge "Unit tests: Support unit tests in extensions and skins" 2019-07-01 23:25:12 +00:00
jenkins-bot
97533fa173 Merge "Remove group validator from UnitTestCase" 2019-07-01 23:06:57 +00:00
Derick Alangi
49bbfc7f1f GlobalFunctions: Tighten version number type for wfDeprecated()
To avoid cases like: facddc4 and Ifaf6ab0d36bc02bd170, make sure the
value of the mediawiki version  must be a string (e.g. '1.33') or a
boolean (e.g. `false`).

For some reason, typos can slip through for this value to be a float.
Let's safe guard for future cases like this.

Change-Id: I52bdf94c957bda67548a937d51649e925195f926
2019-07-01 21:07:10 +00:00
daniel
3b3115e7f3 Title: ensure getBaseTitle and getRootTitle return valid Titles
Since getBaseText() and getRootText() may return text with trailing
whitespace, getBaseTitle and getRootTitle must use makeTitleSafe instead
of makeTitle.

Bug: T225585
Change-Id: Id92df552f05e6a9ed7c9259a8779fa94c3587a3e
2019-07-01 22:22:10 +02:00
Kosta Harlan
1139a9af6a Unit tests: Support unit tests in extensions and skins
For now only extensions with skin/extension.json which follow PSR-4 are
supported.

DefaultSettings is loaded in bootstrap to work around errors when unit tests are
run followed by integration tests (e.g. `vendor/bin/phpunit`)

Usage:

 - composer phpunit:unit will run all unit tests in core and any tests in
   `{extensions/skins}/tests/phpunit/unit` which also extend
   MediaWikiUnitTestCase, and which have an extension.json file
- Pass a specific directory to only run unit tests for a particular extension,
   e.g. `composer phpunit:unit -- extensions/GrowthExperiments`

Bug: T226911
Change-Id: I237a9f82e4d1b05cf2f08b3e4bb7ffcd8d47111c
2019-07-01 16:21:01 -04:00
RazeSoldier
b95a76ae9e Drop APIEditBeforeSave hook
Removed the source code and the test code.

Bug: T220656
Change-Id: I3674da6d9c33c08ec2f1774cb793b3a952480571
2019-07-02 02:58:47 +08:00
Kosta Harlan
5c2d3a5bf4 Remove group validator from UnitTestCase
Whether a unit test has `@group Database` is irrelevant, since it will simply
not work if it relies on database access.

Change-Id: Ibe01d4912160ae44ca86ef6f7c3946501a8c067e
2019-07-01 11:42:21 -04:00
Amir Sarabadani
6568edb9e2 Drop the check for existences of LocalSettings.php in MediaWikiIntegrationTestCase
This is not needed and we should let testers run integration tests without
the need to define LocalSettings.php

This reverts small part of Ie717b0ecf4fcfd089d46248f14853c80b7ef4a76

Bug: T226977
Change-Id: Ia36d22217f94e019bb5945705243bd0daace72e0
2019-07-01 17:15:35 +02:00
jenkins-bot
9e43263709 Merge "Defer cookie block checks to resolve a circular dependency" 2019-07-01 11:09:45 +00:00
Máté Szabó
344481f60d Move trivially compatible tests to the unit tests suite
This changeset resumes work on T89432 and related tickets
by porting an initial set of tests to the new unit test suite
separated out in I69b92db3e70093570e05cc0a64c7780a278b321a.
The tests were only ported if they worked immediately without
requiring any changes other than changing the test case class
to MediaWikiUnitTestCase and moving the test to the new suite.
If a test failed for any reason (even trivial misconfiguration),
it was NOT ported.

With this change, the unit tests suite now consits of a total
of 455 tests. As before, you can run these tests via the following
command:
$ composer phpunit:unit

Bug: T84948
Bug: T89432
Bug: T87781
Change-Id: Ibb8175981092d7f41864e641cc3c118af70a5c76
2019-06-30 15:23:53 +02:00
jenkins-bot
cbc42199a0 Merge "Re-apply: Factors out permissions check from User into PermissionManager service" 2019-06-28 23:44:38 +00:00
Aaron Schulz
baafb5adb4 Make ExternalStore wrap ExternalStoreFactory and create access class
* Inject settings and global instances as dependencies to the
  ExternalStoreMedium instances. This includes the local wiki
  domain, so that wfWikiId() calls are not scattered around.
* Create ExternalStoreAccess service for read/write logic.
* Deprecate the ExternalStore wrapper methods.
* Add some exception cases for bogus store URLs are used instead
  of just giving PHP warnings and failing later.
* Make moveToExternal.php require the type/protocol to decide
  which ExternalStoreMedium to use instead of assuming "DB".
* Convert logging calls to use LoggerInterface.

Change-Id: I40c3b5534fc8a31116c4c5eb64ee6e4903a6197a
2019-06-28 14:31:44 -07:00
Aaron Schulz
ca00e47f53 revision: rename various $wikiId fields/parameters to $dbDomain
These fields are passed to methods like LoadBalancer::getConnection() and are
already expected to be DB domains. Update various comments as well.

Fix a few minor IDEA warnings.

Change-Id: I7cf76700690aec449872a80d30b5ba540d2bf315
2019-06-28 21:30:25 +00:00
Vedmaka
dd6b94024c Re-apply: Factors out permissions check from User into PermissionManager service
Was reverted by I549810a4cd2e424cc4a438887d2f24614a24cc00 due to
T224607.

Original change by  Vedmaka Wakalaka was
Ia0d840b772ea5f20c9594ce151cc57adc270e48b.

Original commit message:

The following methods should are factored out of the User class into PermissionManager,
leaving only deprecated stubs:

- User::isAllowed -> PermissionManager::userHasRight
- User::getRights -> PermissionManager::getUserPermissions
- User::groupHasPermission -> PermissionManager::groupHasPermission
- User::getGroupPermissions -> PermissionManager::getGroupPermissions
 -User::getGroupsWithPermission -> PermissionManager::getGroupsWithPermission
- User::groupHasPermission -> PermissionManager::groupHasPermission
- User::isEveryoneAllowed -> PermissionManager::isEveryoneAllowed
- User::getAllRights -> PermissionManager::getAllPermissions

Depends-On: I7909e9bd6bbfbd708c0a00b861a9b22a38c6665d

Bug: T218558
Bug: T223294
Change-Id: I8899240378f636ea70f447616710516c0a3c5c31
2019-06-28 13:19:38 -07:00
Kosta Harlan
214750d8d2 Define unit and integration test suites
Following discussion in Ibb8175981092d7f41864e641cc3c118af70a5c76, this patch
proposes to further reduce the scope of what unit tests may access, by removing
the loading of DefaultSettings and GlobalFunctions.php. This also has the
implied effect of disabling the storage backend, as well as the global service
locator.

MediaWikiTestCase is renamed to MediaWikiIntegrationTestCase so it's scope and
purpose is more clear. Whether we still need to keep `@group Database`
annotation around is debatable, as it's unclear to me what the performance costs
are of implying database access for all tests which extend IntegrationTestCase.
As far as I can tell, `@group Database` is primarily used in CI to run faster
tests before slower ones, and with the new UnitTestCase the annotation seems
redundant.

To run all testsuites, use `composer phpunit`. Other composer scripts:

- `composer phpunit:unit` to run unit tests
- `composer phpunit:integration` to run integration tests
- `composer phpunit:coverage` to generate code coverage reports from unit
   tests (requires XDebug).

Note that you can pass arguments to composer scripts with `--`, e.g. `composer
phpunit:integration --exclude-group Dump`.

Other changes:

- Rename bootstrap.php to bootstrap.maintenance.php so it's clear it's part of
  the legacy PHPUnit-as-maintenance-class setup
- Create new bootstrap.php which loads the minimal configuration necessary for
  the tests, and do additional setup in the run() method of the unit/integration
	test case classes
- Move the unit-tests.xml file to phpunit.xml.dist in preparation for this being
  the default test configuration

For a follow-up patch:

- Find unit/integration tests for extensions/skins
- Migrate other test suites from suite.xml
- Support running all tests via vendor/bin/phpunit

Bug: T84948
Bug: T89432
Bug: T87781
Change-Id: Ie717b0ecf4fcfd089d46248f14853c80b7ef4a76
2019-06-28 12:18:18 -04:00
jenkins-bot
1e8a3eff9f Merge "Reset services after setting group permissions in tests" 2019-06-28 15:42:41 +00:00
daniel
efb0af6e9c Reset services after setting group permissions in tests
MediaWikiTestCase::setGroupPermissions must reset the service container
after modifying group permissions, so the changed permissions are sure
to take effect even once we start to manage them in a service instance.

Bug: T224607
Change-Id: I38b61612723c9a812ce562179c51eb6c3c416cac
2019-06-28 13:28:22 +02:00
Max Semenik
c873333333 Defer cookie block checks to resolve a circular dependency
User needs to load user preferences to get preferred language, which
calls User::load() which calls User::loadFromSession().

User::loadFromSession() tries to load blocks which might use messages
which need user language which calls User::load() because the previous
call to it haven't completed yet...

We have a protection against infinite recursion to prevent this from
completely crashing MW, however this patch fixes the main issue: loading
too much stuff when a User is initialized.

Bug: T180050
Change-Id: I63af6d2239b36124d5ed382b8d2aab82c8d54d69
2019-06-27 22:37:44 -07:00
jenkins-bot
8f8374204e Merge "Add support for xml dump schema 0.11" 2019-06-28 04:23:58 +00:00
jenkins-bot
9c23d8bbed Merge "Join slot and content tables when dumping XML" 2019-06-28 04:20:16 +00:00
Brad Jorsch
f8b48c99bf rdbms: Add callback for atomic section cancellation
The callback will be called immediately when the section is cancelled,
whether that occurs directly, or via cancelling of an outer section, or
via rollback of the entire transaction.

Change-Id: Id05296948b52b95544547bd38c4387496b6c83b9
2019-06-27 20:09:42 -07:00
Aaron Schulz
a9a13a1266 storage: rename various $wikiId fields/parameters to $dbDomain
These fields are passed to methods like LoadBalancer::getConnection() and are
already expected to be DB domains. Update various comments as well.

Fix a few minor IDEA warnings.

Change-Id: If480cc4d7d4a3c2d176ab346e6307e80cd2540c5
2019-06-28 00:57:04 +00:00
daniel
fdc3e9f952 Add support for xml dump schema 0.11
Bug: T174031
Change-Id: I2717019ea7efe36694bd2b2fba4dc2952a987cfc
2019-06-27 21:56:01 +00:00
daniel
dd14601afb Join slot and content tables when dumping XML
This introduces a way to construct a RevisionRecord based on a
known set of SlotRecords. To allow this to be used consistently
with the legacy revision schema, some tweaks had to be made
to getSlotsQueryInfo().

Bug: T220493
Change-Id: I5ea972bb07ca1cfb3a2ad8ef120aef77e460745c
2019-06-27 22:26:22 +02:00
Aaron Schulz
7911da9c6f rdbms: remove $opened field from Database for simplicity
This avoids having two similar fields that have to stay
in sync. Clean up the related error handling for connections.
If a connection handle is unusable, like when essential SET
queries fail, then destroy it.

Also:
* Avoid use of transactions in DatabasePostgres::determineCoreSchema.
* Make sure all subclasses log on connection failure.
* Add schema sanity checks to mysql/sqlite classes.
* Add IDatabase::QUERY_NO_RETRY flag to simplify reasoning about
  queries that already run on open() to begin with.
* Remove unused return value of Database::open.
* Remove deprecated Database::reportConnectionError method.

Change-Id: I97beba7ead1523085bda8784234d00c69ef1accc
2019-06-27 18:29:12 +01:00
James D. Forrester
5cbb90cf67 OutputPage::addScriptFile: Drop silencing invalid paths, deprecated in 1.24
Change-Id: Ia65c70366ab67324ef2a02f9b0e81a6fb7a081cb
2019-06-27 17:22:52 +00:00
David Causse
92c20832f1 Deprecate SearchResult::termMatches()
And start indicating that hooks relying on this data might become
unreliable as this data is only populated by SearchDatabase search
engines.

This information was only populated by SearchDatabase implementations
and due to bad initial design of SearchResult[Set] (now fixed) it forced
users of these classes to carry this information for the sole purpose of
highlighting.
Because SearchEngine can now own their SearchResult[Set] implementations
nothing that is engine specific should be exposed outside of these
specific implementations.
If there are some logic that still requires access to such list of terms
they should be made engine specific by guarding their code against
instanceof SqlSearchResult.

Change-Id: I38b82c5e4c35309ee447edc3ded60ca6a18b247a
Depends-On: I53fe37c65c7940f696c1e184125e01e592a976e4
2019-06-27 08:44:06 -07:00