Commit graph

182 commits

Author SHA1 Message Date
jenkins-bot
4df90065db Merge "Make use of DiffOp::norig/nclosing() and update tests" 2020-04-01 08:24:06 +00:00
jenkins-bot
751fcb315e Merge "resourceloader: Export ResourceModules as extension attribute" 2020-03-30 23:26:29 +00:00
jenkins-bot
c564ae6722 Merge "resourceloader: Export ResourceModuleSkinStyles as extension attribute" 2020-03-30 23:24:31 +00:00
Timo Tijhof
a999da181e resourceloader: Export ResourceModules as extension attribute
Instead of exporting this as a global variable, export it as an extension
attribute.

The $wgResourceModules configuration variable will continue to be supported
for its main purpose of adding modules. However it may no longer be used to
access the complete registry. In actuality, it was already incomplete because
modules defined via 'ResourceLoaderRegisterModules' hooks were already absent.

The full copy is now owned only by the ResourceLoader class and publicly
available via isModuleRegistered() and getModuleNames().

This opens the door to making it a lazy-loaded attribute, which would help
reduce the size of the "main" APCu cache key for ExtensionRegistry.
This is not possible with global variables as those must be exported
unconditionally from Setup.php.

Bug: T32956
Bug: T247265
Change-Id: I13cf05af458131ce8439eee770d7a62bd9404288
2020-03-30 23:11:05 +00:00
Timo Tijhof
69e9b31fc5 resourceloader: Export ResourceModuleSkinStyles as extension attribute
Instead of exporting this as a global variable, export it as an extension
attribute.

The $wgResourceModuleSkinStyles configuration variable will continue
to be supported for its main purpose of setting skin styles. However
it may no longer be used to read these settings. The canonical copy
of this is now restricted to the ResourceLoader class and not (yet)
made publicly available (I found no use cases for it).

This opens the door to making it lazy-loaded attribute, which would help
reduce the size of the "main" APCu cache key for ExtensionRegistry.

This is not possible with global variables as those must be exported
unconditionally from Setup.php.

Bug: T32956
Bug: T247265
Change-Id: I4ecf558d9c630c91959786d2573c34e619223cef
2020-03-30 16:08:00 -07:00
jenkins-bot
7fa2b595c5 Merge "phpunit: Change optional params before required params to also be required" 2020-03-30 21:29:45 +00:00
Max Semenik
84f15a0a79 phpunit: Change optional params before required params to also be required
Bug: T248078
Change-Id: I7e1d4229d84f5960fd496f281084dbec4739da4c
2020-03-29 15:45:17 +00:00
jenkins-bot
83fc4e8c11 Merge "SearchHandler: add support for completion search" 2020-03-27 15:55:48 +00:00
daniel
905f6fc890 REST: page/ endpoints: don't use tokens with OAuth
CSRF tokens should only be required (and only be allowed) if
the current session isn't already inherently safe against
CSRF due to the way the authentication mechanism works.
This allows (and requires) tokens to be omitted for requests
that use an OAuth Authorization header.

Bug: T230843
Bug: T230842
Bug: T237852
Change-Id: Ib2922d556ff2470d4bf8c386c18986ca9f37d1b5
2020-03-27 12:20:22 +01:00
daniel
76b703fe5c SearchHandler: add support for completion search
This defines a new REST route, /coredev/v0/search/title

Bug: T246387
Change-Id: Ib8d64f3028d3fa2ce239f922181064a3fc91a488
2020-03-26 20:38:30 +01:00
jenkins-bot
fde16090b6 Merge "REST endpoints: Add etag and last-modified headers" 2020-03-26 03:15:58 +00:00
daniel
22561b64a7 REST endpoints: Add etag and last-modified headers
Modified endpoints:
* /v1/page/{title}/history
* /v1/revision/{id}/bare
* /coredev/v0/page/{title}/links/language
* /coredev/v0/page/{title}/links/media
* /coredev/v0/file/{title}

Bug: T238374
Change-Id: I3ddf8fafc17eba3aec724a445d38af98bbc74dc1
2020-03-26 00:18:34 +01:00
daniel
65342f8353 Define POST handler for /page/: create page
NOTE: once this is merged, also merge Ie7b47e6868cc on the OAuth repo,
to fix unit tests after a breaking change to Router's constructor
signature.

Bug: T230842
Change-Id: I8f5b92918a58e44a4f2d8c78d234d9f64c2d06bf
2020-03-25 20:49:20 +01:00
Thiemo Kreuz
42a03b9752 Make use of DiffOp::norig/nclosing() and update tests
The names of these methods are a little strange, that's probably why
we missed them before.

I tried to update closely related test cases, make use of PHP7 type
hints, as well as yield where it feels it makes sense.

Change-Id: I1cf27138e1e47f713739b6fd53101b9ec7d38fe7
2020-03-25 15:17:17 +00:00
daniel
58e5332991 page/update endpoint
Bug: T230843
Change-Id: I95289eddfc9ab2e0cef11b9363a5e239cdb2258e
2020-03-23 16:59:21 +01:00
Bill Pirkle
6b772fee0b Add config variable $wgRestAPIAdditionalRouteFiles
New configuration variable $wgRestAPIAdditionalRouteFiles
allows specifying additional Core REST API route files to
include. The initial use is to include development routes
from new file coreDevelopmentRoutes.json only on testing
wikis, but not on production wikis.

Bug: T247997
Change-Id: Iff8a9b7f4cafb29162e9b10f3d32e2a85f6f58df
2020-03-23 10:22:58 -05:00
jenkins-bot
48a8867982 Merge "ExtensionRegistry: Avoid losing 'defines' when loading lazy-loaded attributes" 2020-03-19 17:20:05 +00:00
jenkins-bot
c3e7919225 Merge "Remove sample REST API handler" 2020-03-18 21:35:51 +00:00
Clara Andrew-Wani
adb087f618 Remove sample REST API handler
Bug: T237540
Change-Id: Ie0a6ecbf9af6e53ed65b92c3b4c7414ae6ae5441
2020-03-18 13:47:24 -04:00
Nikki Nikkhoui
478f7e032d ExtensionRegistry: Avoid losing 'defines' when loading lazy-loaded attributes
When fetching lazy-loaded attributes in ExtensionRegistry to cache, we are saving all the values
from extension.json a second time. In doing so, we are wrongfully omitting the values
previously being defined for the "defines" attribute
(the attribute that is responsible for setting namespace constants).
This patch will make sure that we keep the value set in the "defines" attribute
so that the constants are defined when we load from cache the second time.

Bug: T245629
Change-Id: I4f151f88ece56cf718749b9de11fc8e204ccf29d
2020-03-18 10:32:48 -07:00
jenkins-bot
476b3034b7 Merge "filebackend: Fix undefined wgProfiler in FileBackendGroupTest" 2020-03-18 16:44:07 +00:00
Thiemo Kreuz
7a4df9b019 Remove auto-generated and empty lines in comments
… and add the missing newline after the initial <?php.

Change-Id: I83bbbb1504e4b2bd97eec63c7626d34c655c3197
2020-03-17 09:55:24 +01:00
mainframe98
2619b261bb Support the creation of Skins with services injected
The old way of providing a callable to SkinFactory::register is
still supported. Those callables expected the skin name as their
first argument. Coincidentally, so does the constructor of Skin.
Some skins might not define any constructor parameters at all,
which is acceptable to PHP, as it will just discard the argument.

The registration using $wgValidSkinNames has not been changed,
and skins that want to define services to be injected will still
need to manually register their skin to the skin factory.

CodeSearch did not indicate any extensions or skins manually
constructing a SkinFactory in tests, but for posterity, the old
way of creating a SkinFactory for testing can be replaced with
  new SkinFactory( new ObjectFactory(
  	$this->createMock( ContainerInterface::class )
  ) );

Note that the constructor for SkinFactory for internal use only,
in accordance with the Stable interface policy.
You should use MediaWikiServices::getInstance()->getSkinFactory
instead.

Bug: T244466
Change-Id: I8ba9d869bddd9b6124e47697b789d752c0620b02
2020-03-16 23:25:42 +00:00
Timo Tijhof
4f6051e96d filebackend: Fix undefined wgProfiler in FileBackendGroupTest
This currently passed CI without it, because:

1. Profiler::instance() uses 'global' instead of Config::get(),
   which means there is no warning for it being undefined. (When you
   run a stament like 'global $foo' it implicitly auto-creates the
   variable and assign it the null value).

2. Profiler::instance() uses array_merge() which silently tolerates
   non-array values like null in the list of arguments.
   This is changing in I638d9a219df7.

Bug: T247777
Change-Id: Ic77d6023ef88ad928fe5bf9807e6e8dfb7bc4e9c
2020-03-16 18:07:56 +00:00
Reedy
fe94d1b39a tests: Use ::class rather than string class name
Change-Id: I50cf50e93917ba81fa846a7ea50ac2883e3167e5
2020-03-14 02:00:55 +00:00
Thiemo Kreuz
6b2c9deef5 Replace all new stdClass() with identical (object)[]
This should be the exact same. Its more a style change than anything.
So why do it then?
* I believe this is much less confusing than code mentioning a weird
"standard class". Barely anybody knows what this is, and what the
difference between "object" and "stdClass" is.
* The code is shorter.
* It's even faster. In my micro benchmark it's twice as fast.

Change-Id: I7ee0e8ae6d9264a89b6cd1dd861f0466ae620ccc
2020-03-04 21:18:30 +00:00
jenkins-bot
7206c1ecbf Merge "SearchHandler: implement limit parameter" 2020-03-04 17:07:34 +00:00
daniel
c647e16c92 SearchHandler: implement limit parameter
The integration tests in Search.js were copied from the api-testing repo, see
<https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/tools/api-testing/+/refs/heads/master/test/REST/Search.js>

Bug: T245676
Change-Id: Icb4e9b363586914f2c4bcf809bde003d90c017db
2020-03-04 11:13:55 +01:00
jenkins-bot
12a26c2e2f Merge "SiteConfiguration: Optimise getSetting() internals for getAll()" 2020-03-04 02:48:24 +00:00
jenkins-bot
c07fe5a8eb Merge "SiteConfiguration: Add unit test for tag/suffix conflict scenario" 2020-03-04 02:42:23 +00:00
Timo Tijhof
15f6e986eb SiteConfiguration: Optimise getSetting() internals for getAll()
* getSetting() was retreiving the overrides array from $this->settings
  by settingName. But, the getAll() caller already had this array
  locally available from its foreach loop as "$stuff" which was
  previously unused.

  The protected getSetting() was renamed to processSetting(),
  and now takes this array directly.

* Remove the code duplication in processSetting() for handling
  of 'tags' and handling of 'suffix'. Instead, treat the 'suffix'
  as an extra tag internally, which is exactly how it was behaving
  already. This happens in mergeParmas(), which now documents this
  feature and what it means practically.

  This means for WMF that it can remove the duplication between
  $wgConf->suffices and wikifamily dblist files. These are redundant
  given the suffix for those wikis is identical to the tag name.
  This will save about a dozen dblist file reads in production,
  once we utilize this decade-old feature.

* Rewrite the internal do-while in processSetting() in a more
  procedural fashion. The only reason it used do-while was to
  perform an "early return" from the given block in two places.
  One was rewritten with a simple if/else that devides before/after,
  and the other was rewritten by explicitly tracking the action it
  wanted to skip (which is: applying of 'default' value').

* Document this scary code, including the various anti-features
  I found along the way (such as 'default' overridding '+wiki').
  No changes in behaviour for now.

Bug: T169821
Bug: T246858
Bug: T246213
Change-Id: I723133e6814a5d15c3b0b9e785921505ec7b9a69
2020-03-04 02:12:16 +00:00
Timo Tijhof
44dd120f5a SiteConfiguration: Add unit test for tag/suffix conflict scenario
This is currently broken per T246858. Will be fixed in the next
commit.

Bug: T246858
Change-Id: Ifb5239e118f8707ccc397d55e4ae3eb8287906a3
2020-03-04 02:09:21 +00:00
jenkins-bot
7192c88dba Merge "SearchHandler: add unit test" 2020-03-04 00:26:52 +00:00
jenkins-bot
b5ba50cfc8 Merge "Make use of PHPUnit's assertCount feature where possible" 2020-03-02 20:02:52 +00:00
daniel
9884139d65 SearchHandler: add unit test
Change-Id: I963a2f31afddd37ada615f12d6d5725c20a18631
2020-03-02 20:52:46 +01:00
Timo Tijhof
f9d35b7eee Add unit tests for SiteConfiguration extraction with nested strings
The $lang and $site placeholder variables don't just work on
strings assigned to wg-globals, they also work on strings within
arrays.

Add a test for this because it turns out this part is the slowest
part of the entire extraction process despite the fact that of the
thousands of variables, only a handful use these placeholders,
and even fewer use them within an array.

Bug: T169821
Change-Id: I1706a95764aa7d0ebfa627fb353fa496ccda5eee
2020-03-02 10:36:00 -08:00
Thiemo Kreuz
e1dd371e11 Make use of PHPUnit's assertCount feature where possible
… and avoid assertEmpty() on arrays, in favor of a much more strict
assertSame( [] ).

Change-Id: I20266b0b1fc38a3a87666ba1b0793cb2b37d94a9
2020-03-02 15:58:41 +00:00
Thiemo Kreuz
c05bdcee8b Remove unreachable null checks after isset()
isset() does two things: It checks if a variable (or array element)
is declared, *and* it checks if it is null. If a variable is null,
isset() fails as if the variable was not set. All these additional
null checks are dead code.

Change-Id: I71e8cc26dac839c9d081bf00b4164b7b5147e586
2020-02-28 21:40:48 +00:00
Timo Tijhof
f575721a06 Update all use of $wgVersion to MW_VERSION
Follows-up I04628de4152dd5.

Bug: T212738
Change-Id: I718474ec0d9fd29ac2c05477f0f2493615d8aff5
2020-02-25 02:16:12 +00:00
Tim Starling
44d51cb04e Fix the namespace of SpecialPageFactory
Follows-up d4045035b0.

This class was added to the MediaWiki\Special namespace, contrary to the
plan in T166010 which reserves that namespace for core special pages.
Instead, use MediaWiki\SpecialPage, following the directory in which it
is located.

Also, fix two bugs which prevented the introduction of a namespaced
class alias.

Bug: T166010
Change-Id: I6e31340aaae32a89beb7e45b79d76a7fea9808d2
2020-02-21 13:46:19 +11:00
jenkins-bot
be493195a8 Merge "Use ObjectFactory to construct ContentHandlers" 2020-02-11 17:57:14 +00:00
jenkins-bot
9c2f06f68d Merge "shell: Skip FirejailCommandTest::testBuildFinalCommand() on Windows" 2020-02-11 16:49:56 +00:00
RazeSoldier
f58616acce shell: Skip FirejailCommandTest::testBuildFinalCommand() on Windows
firejail is a Linux sandboxing system, unavailable on Windows.

Bug: T228568
Change-Id: I115e0e72ec31ebd7fd61e90250c10b414eea2489
2020-02-11 16:31:31 +00:00
ArtBaltai
272e941b7f Use ObjectFactory to construct ContentHandlers
Changed
 - ContentHandlerFactory with legacy support
 - ContentHandlerFactoryTests
Added
 - MediaWikiIntegrationNoDbTestCase for test without preparing DB
New
 - tests

Bug: T243560
Change-Id: I693dda56af55bd03e48d62a2f1ade42f65a8fac9
2020-02-10 21:36:36 +03:00
ArtBaltai
30e54b3962 Introduce ContentHandlerFactory
Added:
- ContentHandlerFactory
Tests:
- PHPUnit
Changed
- Calls of changed and deprecated
- DI for some service/api
Deprecated:
- ContentHandler::* then similar to ContentHandlerFactory
- ContentHandler::getForTitle
- ContentHandler::$handlers

Bug: T235165
Change-Id: I59246938c7ad7b3e70e46c9e698708ef9bc672c6
2020-02-07 00:53:51 +03:00
Peter Ovchyn
50e3bd4fac parser: Inject a LanguageConverterFactory through DI containers:
1. into class Parser
2. into class LinkHoderArray
3. into class DefaultPreferencesFactory

Add more tests for DefaultPreferencesFactory:
1. testVariantsSupport verifies that converter with variants is used correctly.
2. Test testUserGroupMemberships verifies that membership is used correctly

Bug: T243320, T243321, T243317
Change-Id: I1e5c37e18332d0d32391c74c06e3d84862e48df8
2020-02-04 14:42:03 +02:00
Thiemo Kreuz
9c57ea2b7f Replace complicated assertions with assertIsString() and such
This patch tries to make assertions in tests more readable by using more
self-documenting assertions as provided by modern PHPUnit versions. Among
a few others, these two main changes are done:

* I found a lot of assertions with the expected value being the *second*
parameter. I did not changed all of them. Only some that can be replaced
with assertNull() and such.

* I try to replace all `assertTrue( is_…() )` with dedicated assertions.

Change-Id: I1fc72188fbd0edacf13886e7f9a9eacbd85f13c2
2020-01-28 19:17:58 +00:00
C. Scott Ananian
b79c1e22ad Hard-deprecate Sanitizer::escapeId()
Deprecated in MW 1.30; time to clean up any remaining uses.

Code search:
https://codesearch.wmflabs.org/deployed/?q=escapeId%5C%28&i=nope&files=&repos=

Depends-On: Ic03a5da2e1d6b8f5656555420dd573a1d698b9cc
Depends-On: I311f44a5035f73c0fb2289f727eb39b73007429b
Depends-On: I76c5b539bae5572c4ac65f28fec9c0c36381348c
Depends-On: Id4cbfc3b113b1b04f949d485187e89ffe0b487f5
Depends-On: I7d5ba4930688ed7f011a4babed5986b8e40910a0
Depends-On: I964f83ce88fb9c66a7c59037c6066f4567bcf4c9
Change-Id: I89504cfdf8e02831d54a26900bfdc63a33b4eade
2020-01-26 22:05:45 +00:00
Thiemo Kreuz
192025f569 registration: Rewrite odd !(bool) cast in VersionCheckerTest
I found this while looking for something completely different. The
actual problem here is: Before, the test would accept *any* falsy value
(null, false, even the string "0"). But what needs to be checked here is
that the list of errors is empty. This is what the `=== []` comparison
now does.

Change-Id: I16d3534ba324b0cd35a86682ffbb8cff9eedc015
2020-01-24 02:15:22 +00:00
jenkins-bot
d0fc5e00e6 Merge "Replace Linker::link usage with LinkRenderer in includes" 2020-01-21 08:35:50 +00:00