Commit graph

231 commits

Author SHA1 Message Date
Reedy
229b2c15e8 Fix a plethora of class and function call case mismatches
Bug: T231412
Change-Id: I597a25de3294a6673424f30475760280ef209a8a
2020-05-26 14:14:46 +01:00
jenkins-bot
9d1bd65aa2 Merge "REST Handler: add unit tests for base class" 2020-05-26 10:53:00 +00:00
daniel
ad6879e6b6 REST Handler: add unit tests for base class
This adds unit tests for the Handler base class.

This includes tests for public and protected methods.
Since the Handler base class is an extension point, the protected methods
are part of the stable public interface.

Change-Id: Ibe9fcbb139683dad03b92cd0618c3c0e8feb8b94
2020-05-26 10:33:36 +00:00
Reedy
07faedc8c6 Fix more libs PSR12.Properties.ConstantVisibility.NotFound
Change-Id: If3bac6b0ff6fbb89bfa2b9fa91809135a76c610b
2020-05-16 20:13:22 +00:00
DannyS712
cc8296b309 Add Unit tests for SpamChecker service
Brings coverage to 100% (up from 0%)

Bug: T251015
Change-Id: I264f9c6cd0d9926ee73b48f33d5083c12338b09d
2020-05-15 17:02:30 +00:00
jenkins-bot
7a0cfac4e6 Merge "Add HookRegistry" 2020-05-14 13:33:49 +00:00
DannyS712
29aa36c06e Add MergeHistoryFactory interface, implemented by PageCommandFactory
Bug: T249446
Change-Id: I94676e065a8aed5cad2fe2d5cf16ca586adce97d
2020-05-13 19:08:09 +00:00
Tim Starling
b3d762e148 Add HookRegistry
Add a HookRegistry interface and two concrete implementations,
representing HookContainer's view of its environment. This simplifies
creation of a HookContainer for testing.

Add MediaWikiTestCaseTrait::createHookContainer() which can be used
in most of the places that were previously creating mock hook
containers. It can also replace setTemporaryHook() in some cases.

Change-Id: I9ce15591dc40b3d717c203fa973141aa45a2500c
2020-05-13 11:51:02 +10:00
DannyS712
4a206f1f90 Add tests for RevisionList/RevisionItem classes
Fix RevisionItemBase::getId to actually return an int, as intended

Previously all four classes (RevisionItem, RevisionItemBase,
RevisionList, and RevisionListBase) had no coverage. Now:

+--------------------------------------------+-------+--------+
| Filename                                   | Old % | New %  |
+--------------------------------------------+-------+--------+
| includes/revisionlist/RevisionItem.php     | 0     |  46.77 |
| includes/revisionlist/RevisionItemBase.php | 0     |  70.27 |
| includes/revisionlist/RevisionList.php     | 0     | 100.00 |
| includes/revisionlist/RevisionListBase.php | 0     |  76.32 |
+--------------------------------------------+-------+--------+

Bug: T252076
Change-Id: I3da1ae350986ef6dc54a13ae9275b4c1d03f6e5b
2020-05-12 09:36:44 -07:00
jenkins-bot
d9da0268db Merge "Update setTemporaryHook() to use scopedRegister()" 2020-05-11 04:55:18 +00:00
Nikki Nikkhoui
8d378e977c Update setTemporaryHook() to use scopedRegister()
The new HookContainer.php introduces a scopedRegister() method for
temporarily setting hooks. Let's use that in MediaWikiUnitTestCase
and MediaWikiIntegrationTestCase instead of directly accessing
global $wgHooks to do so.

Also introduces setTemporaryHook() and removeTemporaryHook()
methods in MWIntegrationTestCase for easily adding/removing of
temporary hooks.

Bug: T250300
Change-Id: I8cefd41b66f882c53646b76de76c51f0d8730f72
2020-05-11 14:12:00 +10:00
jenkins-bot
8fc63e1bcd Merge "Fix SingleSpaceBeforeSingleLineComment" 2020-05-11 01:31:05 +00:00
Reedy
12a3883a7b Fix SingleSpaceBeforeSingleLineComment
Change-Id: I285af438ce484af40741489797f20455726ec110
2020-05-11 00:57:11 +00:00
Reedy
f96a15692b Function visibility in ParserFactoryTest.php
Change-Id: I043f0b92ac0694aa5c36267edd77869b707f4812
2020-05-10 23:44:08 +01:00
Reedy
ead6b1e53f Fix some PSR12.Properties.ConstantVisibility.NotFound in tests/phpunit/
Change-Id: I0f678049dc274f0cd29f543bb293c33da51d8529
2020-05-09 23:55:09 +00:00
jenkins-bot
06a884c9ee Merge "phpunit: Add error_reporting/AtEase check to MediaWikiUnitTestCase" 2020-05-09 02:49:10 +00:00
Timo Tijhof
355a6cd4c3 phpunit: Add error_reporting/AtEase check to MediaWikiUnitTestCase
This existed on MediaWikiIntegrationTestCase, but not on
MediaWikiUnitTestCase. As a result of that, I spent about four
days tracking down a dangling AtEase::suppressWarnings with
missing AtEase::restoreWarnings (as part of Ib6758d724c).

Move it to the common MediaWikiTestCaseTrait instead so that we
get it on unit/ as well.

Example:

> There was 1 failure:
>
> 1) Pbkdf2PasswordTest::testCryptThrows
> PHP error_reporting setting found dirty.
> Did you forget AtEase::restoreWarnings?

Change-Id: I7dc3fe90385c8066b89a5e06c55f5455edfbb4ca
2020-05-09 01:48:45 +00:00
jenkins-bot
b522caf749 Merge "Deprecate a few more tidy-related methods" 2020-05-08 22:32:38 +00:00
jenkins-bot
829255a71e Merge "FileBackend: Avoid undefined offset notices" 2020-05-08 15:46:19 +00:00
jenkins-bot
986065e89f Merge "Bring HookContainerTest to unit test standards" 2020-05-06 07:05:58 +00:00
Max Semenik
47f6b73231 FileBackend: Avoid undefined offset notices
While I'm at it, remove a pointless else.

Bug: T248925
Change-Id: I3107cff5aaf07779aa900e8325f30a6a44bface9
2020-05-05 20:55:33 +03:00
Peter Ovchyn
7df7b923da rest: Add 'thumbnail' and 'description' fields to the search response
By default, core adds those fields as null to each row.
provideThumbnail and provideDescription hooks are introduced.
Extension should subscribe on the hooks to provide a thumbnail and description respectively.

Bug: T250144
Change-Id: I42c6c8ff9d887a440174af2a21c7921573b06640
2020-05-05 19:35:52 +03:00
Timo Tijhof
161fab3a9c language: Avoid LCStoreStaticArray::decode() recursion for arrays
In looking at early flame graphs and XHGui profiles, I noticed
code paths like `decode -> decode@2 -> decode@3`, for example for
magic words arrays and special page names.

Rather than storing these as `[a, [a, [a, ..], [a, ..], [a, ..], .. ] ]`
store them instead as `[v, [ .. ]]`. This makes for smaller files,
but more important it further reduces runtime overhead.

Bug: T218207
Change-Id: I492e5d32106ba7fd1b22075cf026fee2e3d1944e
2020-05-04 17:46:04 +01:00
Timo Tijhof
08791d1c1d language: Add test coverage for LCStoreStaticArray
Bug: T218207
Change-Id: I2e4c95139153f206b5317a4efe1e9b324ecce225
2020-05-04 17:34:21 +01:00
C. Scott Ananian
aeb2f33cc7 Deprecate a few more tidy-related methods
Hard-deprecate ParserOptions::getTidy(), since it always returns true
and is rarely used.  Code search:
https://codesearch.wmflabs.org/search/?q=getTidy%5C%28&i=nope&files=&repos=

Soft deprecate most methods of MWTidy; folks should use MWTidy::tidy()
as the entry point here.  Code search:
https://codesearch.wmflabs.org/search/?q=MWTidy&i=nope&files=&repos=

Bug: T198214
Change-Id: I3584181070da7ed4888beaaf04e083114aca1eab
2020-05-01 21:08:54 +00:00
Nikki Nikkhoui
ea3e2e8f74 Bring HookContainerTest to unit test standards
- Remove mockDeprecatedHooks in favor of real DeprecatedHooks
- Create mockExtensionRegistry with createNoOpMock to
prevent any non-mocked methods from being called

Change-Id: I8beb25f058fe76bcc436f7e9bc2d55bde7795b35
2020-05-01 17:45:02 +00:00
jenkins-bot
eb4d00e460 Merge "Allow new style hook handlers to abort" 2020-05-01 01:22:37 +00:00
jenkins-bot
43562769eb Merge "Fix DeprecatedHooks and move emitDeprecatedHookWarnings to HookContainer" 2020-05-01 01:22:26 +00:00
Tim Starling
3d7365e844 Allow new style hook handlers to abort
Aborting was apparently lost by accident in PS28 of the HookContainer
commit.

In the test, to allow multiple different hooks to be registered, I
used a real ObjectFactory with a fake ServiceContainer, instead of a
fake ObjectFactory. I changed the parameter to
getMockExtensionRegistry() to take the full attribute value instead of
the hook name and a single handler.

Change-Id: I7b4c547737febe81a487fe154db150055ae31344
2020-05-01 08:02:31 +10:00
Tim Starling
6091dca5a6 Fix DeprecatedHooks and move emitDeprecatedHookWarnings to HookContainer
DeprecatedHooks was not listed as a core attribute and so was not
extracted from extension.json. I added some code to extract and merge it
in extractHooks(), and I also made the "component" default to the name
of the extension which deprecates the hook, instead of "MediaWiki".

I added the core deprecated hooks based on the current Hooks::run() calls.

I moved emitDeprecatedHookWarnings() to HookContainer, and to reduce the
performance overhead, arranged for it to be called only on page views.

Change-Id: Idc0cfba782b49398d9e7feaa164fe7692d491bf9
2020-05-01 08:02:25 +10:00
Timo Tijhof
2f35c3ae67 HtmlCacheUpdater: Add getUrls() method and support selective purging
* Move the Title::getCdnUrls() logic to the new HtmlCacheUpdater service.

* Introduce a runtime option to decide whether this is for a direct
  revision or a cascading LinksUpdate.

Bug: T250261
Change-Id: I514b9052761e0d949234996e97fdef255582df86
2020-04-30 18:16:07 +00:00
jenkins-bot
494a189f48 Merge "tests: Make static/non-static functions match" 2020-04-30 14:18:18 +00:00
jenkins-bot
dab27d410b Merge "search: Add 'SearchMappings' attribute to map canonical name to PHP class" 2020-04-30 10:05:31 +00:00
Reedy
eeb8cb1342 search: Add 'SearchMappings' attribute to map canonical name to PHP class
This allows indirection between the values in $wgSearchType and
$wgSearchTypeAlternatives where the underlying class name
doesn't match the actual class name that subclasses
SearchEngine.

Bug: T250977
Change-Id: Ib9634128f07d428276e80a6f2f492b850eef17e8
2020-04-30 04:29:17 +00:00
Max Semenik
09f2feafd6 tests: Make static/non-static functions match
PHP 8 is stricter about this.

Bug: T248925
Change-Id: I0e9c736d0e2a28ce4a1e096a8ec63321d8b41635
2020-04-29 10:59:53 +03:00
Tim Starling
977ee0730e Change HookContainer's namespace from HookRunner to HookContainer
It makes even less sense now that HookRunner has been modularized, with
API hooks being split out to ApiHookRunner. HookRunner is inherently
local and private and doesn't deserve to be a namespace.

Change-Id: I97ddc56e96c7bfeb1594f4a84619665aee9c401c
2020-04-29 10:58:24 +10:00
jenkins-bot
bba3028193 Merge "Convert MovePageFactory to interface, implement in PageHandlerFactory" 2020-04-28 22:51:34 +00:00
Kosta Harlan
7880815b4d Add MultiTitleFilter class
Add a new preference filter for use with HTMLTitlesMultiSelectField, to simplify
the process of saving article text as IDs in user preferences, and reading those
IDs back to text for presentation in the form.

Example usage in the Echo extension: I67f751eae5fdc5bccff7fe3047227d432c1cb8d5

Change-Id: Ia0ddf78646ec4c8ae0b84b6d5b46ef5e51c8e8c1
2020-04-28 14:06:51 +00:00
DannyS712
b14965e75e Convert MovePageFactory to interface, implement in PageHandlerFactory
Bug: T249446
Change-Id: I1335d976b992f44c8609c298f0ec19d81afa7b84
2020-04-27 23:26:28 +00:00
Tim Starling
aac9d32b98 HookContainer: add b/c for non-static handler with colons in the function name
A non-static call with colons in the function name worked with
call_user_func_array(), but now that we use $func(...$args) instead, it
fails with "Call to undefined method C::C::f()". So strip out the part
before the double-colon.

Bug: T240307
Change-Id: I52e6ad5d90ba188895448aeeb4268142d56ea265
2020-04-21 11:10:01 +10:00
jenkins-bot
10799c051c Merge "UserNameUtils: use ITextFormatter instead of MessageLocalizer" 2020-04-20 17:27:12 +00:00
C. Scott Ananian
7a2331706f Deprecate Parser::firstCallInit()
Originally we created a Parser object on every request, and so care
was taken to make Parser construction lightweight.  In particular,
all potentially costly initialization was moved into a separate
Parser::firstCallInit() method.  Starting with 1.32, parser construction
has instead been done lazily, via the ParserFactory registered with
MediaWikiServices.  The extra complexity associated with the old manual
lazy initialization of Parser is therefore no longer needed.

Deprecate Parser::firstCallInit() as part of a general plan to refactor
the Parser class to allow subclasses and alternate parser implementations.
Add some tests to assert that parsers are being created lazily, and are
not being created when they are not needed.

Bug: T250444
Change-Id: Iffd2b38a2f848dad88010d243250b37506b2c715
2020-04-17 12:49:34 -04:00
Tim Starling
e890ca9b16 HookContainer followups
* Set initial values for HookContainer array properties
* Fix scopedRegister() to only clear the registered handler when the
  ScopedCallback is consumed, instead of all registered handlers. Add
  test.
* Fix isRegistered() to return true when the relevant handler array is
  empty (not just missing)
* For performance, inline callHook() into run(), so that function name
  derivation can be moved outside the handler loop.

Change-Id: I631e15cba8c527e87b92c57e8421551184f08627
2020-04-17 15:48:38 +10:00
Nikki Nikkhoui
0adc5f3428 Hook Container
New classes and modificatons to existing classes to support the new Hooks system. All changes are documented in RFC https://phabricator.wikimedia.org/T240307.

- HookContainer.php: Class for doing much of what Hooks.php has historically done, but enabling new-style hooks to be processed and registered. Changes include new ways of defining hook handler functions as an object with defined dependencies in extension.json, removing runWithoutAbort() and addit it to an $options parameter to be passed to HookContainer::run(), being able to decipher whether a hook handler is legacy or non-legacy style and run them in the appropriate way, etc.
- DeprecatedHooks.php: For marking hooks deprecated and verifying if one is deprecated
- DeprecatedHooksTest.php: Unit tests for DeprecatedHooks.php
- Hooks.php: register() will now additionally register hooks with handlers in new HooksContainer.php. getHandlers() will be a legacy wrapper for calling the newer HookContainer::getHandlers()
- MediaWikiServices.php: Added getHookContainer() for retrieving HookContainer singleton
- ExtensionProcessor.php: modified extractHooks() to be able to extract new style handler objects being registered in extension.json
- ServiceWiring.php: Added HookContainer to list of services to return
- HookContainerTest.php: Unit tests for HookContainer.php
- ExtensionProcessorTest.php: Moved file out of /unit folder and now extends MediaWikiTestCase instead of MediaWikiUnitTestCase (as the tests are not truly unit tests). Modified existing tests for ExtensionProcessor::extractHooks() to include a test case for new style handler

Bug: T240307
Change-Id: I432861d8995cfd7180e77e115251d8055b7eceec
2020-04-17 15:48:38 +10:00
Timo Tijhof
3007dd624c objectcache: Add regression test for MapCacheLRU serialization
Follows-up fb5116028b (I77d42b43f4).

Bug: T218511
Change-Id: I157ef19899ac4e07ab456bc81e3c8c8d4989b9e6
2020-04-16 17:55:17 +01:00
Petr Pchelko
7f643f2ab6 UserNameUtils: use ITextFormatter instead of MessageLocalizer
Bug: T249045
Change-Id: Ica1e1e4788d4b9f9dfcf9f8c8b4136147d92b32e
2020-04-13 09:28:02 -07:00
C. Scott Ananian
75c5176b36 Typo fix: 'depencency' -> 'dependency'
Change-Id: I90712b2bdc819cad20c93a4ce3de8b9af9d7d14c
2020-04-09 14:02:53 -04:00
jenkins-bot
f98a9e576a Merge "SearchHandler: emit Cache-Control header." 2020-04-06 15:53:50 +00:00
daniel
7d8fe94ea2 SearchHandler: emit Cache-Control header.
Completion search used for type-ahead should make use of http caches,
like ApiOpenSearch does.

Bug: T245675
Change-Id: Ia8366684203381b6c4dc55669a6877e53e9ffe40
2020-04-06 13:37:49 +02:00
jenkins-bot
4df90065db Merge "Make use of DiffOp::norig/nclosing() and update tests" 2020-04-01 08:24:06 +00:00