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
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
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
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
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
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
- Remove mockDeprecatedHooks in favor of real DeprecatedHooks
- Create mockExtensionRegistry with createNoOpMock to
prevent any non-mocked methods from being called
Change-Id: I8beb25f058fe76bcc436f7e9bc2d55bde7795b35
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
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
* 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
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
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
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
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
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
* 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
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
Completion search used for type-ahead should make use of http caches,
like ApiOpenSearch does.
Bug: T245675
Change-Id: Ia8366684203381b6c4dc55669a6877e53e9ffe40