Commit graph

15 commits

Author SHA1 Message Date
Ebrahim Byagowi
697e19e461 Add MediaWiki\Registration namespace to registration classes
Bug: T353458
Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
2024-08-10 10:08:22 +00:00
Reedy
e94e265a93 tests: Add Tests to PHP namespacing
Change-Id: I849268172751d50292e93aa75abe8094873f56bc
2024-02-16 19:10:11 +00:00
daniel
4c90b274f7 Remove the $replace parameter from HookContainer::scopedRegister.
This parameter was unused outside core, and the functionality
was intended for testing. Removing it simplifies the code quite a bit.

Note that the $replace parameter remains functional in
MediaWikiIntegrationTestCase::setTemporaryHook.

Change-Id: Ib5b4f379fbb74d54c600040a4c90f8354f4c1c61
2023-06-14 11:00:54 +00:00
Lucas Werkmeister
5f2bfc44ce Simplify HookContainer (v2)
This reverts change I50c3d1c5df (commit b0317287bc), thus reinstating
change I7d690a1172 (commit d139eb07fe). The only change from the
original is in getHookMethodName(), additionally replacing '-' with '_'
(not just ':' and '\'). The original commit message follows:

This converts all hook handlers to the same internal representation.
This is done lazily, when the hook is run for the first time.

The logic for temporarily disabling handlers by calling scopedRegister()
with the $replace parameter set has been greatly simplified.

There are some minor changes to the class's interface and behavior,
none of which should be breaking changes:
* run() will emit deprecation warnings if and only if it was called
  with the deprecationVersion option set, for all kinds of handlers.
  The idea is that deprecated hooks should emit a warning either from
  run(), or from emitDeprecationWarnings(). The latter happens if the
  hook is listed in DeprecatedHooks.
* register() now also accepts hook handlers declared in the way that
  extensions register hooks.
* Attempts to call register() with an invalid hook definition now
  result in an invalidArgumentException.
* Attempts to call register() for a deprecated hook will consistently
  result in a deprecation warning.
* The internal getRegisteredHooks() method has been removed in favor
  of the identical getHookNames() method.
* The internal getLegacyHandlers method has been removed in favor
  of getHandlerDescriptions() and getHandlerCallbacks().
* The call order changed so that dynamically registered handlers
  are called last, instead of getting called before handler objects
  from extensions.

Bug: T338213
Change-Id: I6efb09e314ad2b124a33a757fdda2a07ae0d8f7c
2023-06-06 12:06:23 +02:00
Lucas Werkmeister
b0317287bc Revert "Simplify HookContainer"
This apparently caused some change in how hook handlers are called (it
now calls e.g.  AbuseFilterHookHandler::onAbuseFilter-generateUserVars()
instead of AbuseFilterHookHandler::onAbuseFilter_generateUserVars()),
causing both test failures and errors on Beta.

This reverts commit d139eb07fe.

Bug: T338213
Change-Id: I50c3d1c5dfd2d7eeac59992156a8a644cf0197e5
2023-06-06 11:12:18 +02:00
daniel
d139eb07fe Simplify HookContainer
This converts all hook handlers to the same internal representation.
This is done lazily, when the hook is run for the first time.

The logic for temporarily disabling handlers by calling scopedRegister()
with the $replace parameter set has been greatly simplified.

There are some minor changes to the class's interface and behavior,
none of which should be breaking changes:
* run() will emit deprecation warnings if and only if it was called
  with the deprecationVersion option set, for all kinds of handlers.
  The idea is that deprecated hooks should emit a warning either from
  run(), or from emitDeprecationWarnings(). The latter happens if the
  hook is listed in DeprecatedHooks.
* register() now also accepts hook handlers declared in the way that
  extensions register hooks.
* Attempts to call register() with an invalid hook definition now
  result in an invalidArgumentException.
* Attempts to call register() for a deprecated hook will consistently
  result in a deprecation warning.
* The internal getRegisteredHooks() method has been removed in favor
  of the identical getHookNames() method.
* The internal getLegacyHandlers method has been removed in favor
  of getHandlerDescriptions() and getHandlerCallbacks().
* The call order changed so that dynamically registered handlers
  are called last, instead of getting called before handler objects
  from extensions.

Change-Id: I7d690a1172af44a90b957b2274d68e51b7f09938
2023-06-04 15:36:38 +02:00
Amir Sarabadani
623d3dc419 rdbms: Move ReadOnlyMode and ConfiguredReadOnlyMode to rdbms library
The db/ directory does not have an owner and it's a mess in general.
These classes don't depend on anything in core except the rdbms library.
Let's simply move it there. In other words, Krinkle made me do it.

Since the class was moved in I6202e52ba73 merged less than a week ago,
no need to alias anything.

Bug: T321882
Change-Id: I24ceeb8bf765a50f441270136acd612359d50aa2
2023-05-04 23:41:21 +02:00
Amir Sarabadani
d59ffa4202 Reorg: Move ReadOnlyMode classes to db/
They are not suitable to go to rdbms library as they depend on mediawiki
pieces, the second best place is the db/ directory.

Bug: T321882
Change-Id: I6202e52ba7306d74261206c2ba7930c5f1a0a18e
2023-04-28 12:13:01 +02:00
Tim Starling
d36ea70309 Fix some PHPStorm inspections (#1)
* Triple backslash in regex should really be quadruple backslash
* Using the returned value of a void method
* Immediately overwritten array keys
* Duplicate array keys
* Foreach variable reuse
* sprintf() with too many params
* Incorrect reference usage

Change-Id: I3c649b543c9561a1614058c50f3847f663ff04df
2023-03-25 00:19:33 +00:00
daniel
db729e46f6 Treat $wgHooks as a regular setting
$wgHooks should be treated like a regular setting, which cannot be
manipulated after bootstrapping is complete. This will allow us to
greatly simplify the logic in HookContainer.

Replacing $wgHooks with a fake array after bootstrapping allows us to
detect any remaining live access to $wgHooks without breaking
functionality.

The plan is to have the fake array emit deprecation warnings in the 1.40
release, and make it throw exceptions in later releases.
See Iddcb760cf8961316d6527e81b9aa968657d8354c for the deprecation
warnings.

Bug: T331602
Change-Id: I0ebba9a29f81b0d86ad8fd84d478fb244f9e9c15
2023-03-09 10:20:44 +01:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Umherirrender
62002cdcf1 build: Update mediawiki/mediawiki-codesniffer to 35.0.0
Change-Id: Idb413be4b8cba8611afdc022af59810ce1a4531e
2021-01-31 13:34:38 +00:00
Tim Starling
9834d4c214 Prevent service injection to LoadExtensionSchemaUpdates hook
* Add noServices option to HookContainer::run()
* Use the option for LoadExtensionSchemaUpdates
* Document service injection including the caveats we know about

Bug: T258851
Change-Id: Ie57f2a3aeeea883f392e3c83ff228d1de68c6ebf
2020-09-18 08:01:52 +10:00
Nikki Nikkhoui
5a6f9968ce HookContainer Integration Test
Integration test for HookContainer.
Tests that hook handlers registered in extension.json
and through HookContainer::register() are executed.

Bug: T251444
Change-Id: I552ae606794d4482f7e8a4b0b67fd35b302e43f8
2020-05-11 13:45:39 -07:00