Commit graph

327 commits

Author SHA1 Message Date
thiemowmde
b1c9ec74fa Remove meaningless @var documentation from constants
A constant is not a variable. The type is hard-coded via the value
and can never change. While the extra @var probably doesn't hurt much,
it's redundant and error-prone and can't provide any additional
information.

Change-Id: Iee1f36a1905d9b9c6b26d0684b7848571f0c1733
2024-10-09 09:33:12 +02:00
Adam Wight
188d2cbbb0 Remove unchecked exception annotations
Callers should not catch an unchecked exception, so it doesn't belong
in a function signature.  Unchecked exceptions indicate a coding error,
which by definition the code will not be able to handle correctly.

If any of these exceptions were supposed to be in response to an edge
case, user input, or initial conditions, then they should be changed
to a runtime error.  If the exception class cannot be changed, then
the annotation should include a comment explaining its purpose and
prognosis.

Bug: T240672
Change-Id: I2e640b9737cb68090a8e1cb70067d1b74037d647
2024-09-17 22:20:58 +02:00
Ebrahim Byagowi
697e19e461 Add MediaWiki\Registration namespace to registration classes
Bug: T353458
Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
2024-08-10 10:08:22 +00:00
Arlo Breault
44580945ed Add OutputPipelineStages from extensions
Adds an experimental configuration to allow extensions to define
OutputPipelineStages to include in the DefaultOutputPipeline.

There are a lot of open questions about this api, like ordering of
execution, but adding it @experimental will help surface the
requirements.

Bug: T370541
Needed-By: I6dc92af0611c680b6e55605a7c9ff8a3fc1dfa26
Change-Id: I64baea40a1687c7a06fbcda9efe9f9a159b0ae8d
2024-07-25 11:44:17 -04:00
Ebrahim Byagowi
fab78547ad Add namespace to the root classes of ObjectCache
And deprecated aliases for the the no namespaced classes.

ReplicatedBagOStuff that already is deprecated isn't moved.

Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
2024-07-10 00:14:54 +03:30
daniel
b0e80a97bd REST: Add support for RestModules to extension.json
So far, extensions can only define REST entry points by listing them
directly in extension.json. This is inconvenient and makes it impossible
to define proper modules.

Bug: T365754
Change-Id: Id35bdd55e00457ddbeaee72d0e9399bd43a0d07a
2024-06-25 17:00:01 +00:00
jenkins-bot
2c24cdd0a5 Merge "Optimize globals processing in ExtensionRegistry for performance" 2024-06-19 00:28:15 +00:00
jenkins-bot
5362717e47 Merge "ExtensionRegistry: Avoid array_key_exists on $GLOBALS in PHP 8.1+" 2024-06-19 00:28:05 +00:00
thiemowmde
22b123ca58 Optimize globals processing in ExtensionRegistry for performance
We discussed this in the previous patch Ic6b8841 but wanted to keep
it focussed on one change at a time.

This code path can be quite hot the more extensions are registered.
This slightly re-arranges the existing code to avoid various kinds of
duplicate calls. No behavior changes.

I tried hard to not compromise readability for performance. In fact
I think this is even better readable.

Bug: T366547
Change-Id: I3c1263e0c0ed78bac1044d0287830cb1a32b7e44
2024-06-13 15:30:34 +02:00
Tim Starling
cdc5178150 user: Introduce UserOptionsStore
Refactoring:

* Break out the database access part of UserOptionsManager to a separate
  class hierarchy implementing interface UserOptionsStore. It's
  basically a key/key/string-value store, very simple. The complex
  parts of user options storage remain in UserOptionsManager.
* Bundle the UserOptionsManager caches into a per-user cache object. I
  was adding a couple more and it was getting tedious.

Start integrating GlobalPreferences with UserOptionsManager:

* Have an array of stores. There's always a local store, and extensions
  can add stores via an attribute.
* Add $global parameter to UserOptionsManager::setOption(), allowing
  this method to update or override global options.
* Rename loadOptionsFromDb to loadOptionsFromStore.
* Move the local override feature from GlobalPreferences to core.

Bug: T323076
Change-Id: Ib3623b723557c819bc0ffdf21a4ffcb070eb298b
2024-06-12 01:27:57 +00:00
Umherirrender
f369b84194 ExtensionRegistry: Avoid array_key_exists on $GLOBALS in PHP 8.1+
Passing $GLOBALS as function argument to array_key_exists creates a read
only copy on each call

Bug: T366547
Follow-Up: I9b46e7bc25365d01dbc86a9b2288559cb9e2cb8d
Change-Id: Ic6b884141a1998e30ba1ccb054ee922d9f026404
2024-06-11 17:42:20 +00:00
jenkins-bot
c9d1cf87e2 Merge "extension registration: Fix handling of null default values" 2024-05-22 12:30:51 +00:00
Derick Alangi
7475063bfd objectcache: Complete refactor of ObjectCache.php
This patch completes the rest of the ObjectCache refactor and
migrates methods to the appropriate class while deprecating them
in `ObjectCache.php`.

It also moves the `_LocalClusterCache` internal service logic
into ObjectCacheFactory and calls that instead making sure that
wiring code stays wiring code and let the class do the heavy lifting.

`::makeLocalServerCache()` is retained as a static method in the
ObjectCacheFactory class because it's called early in Setup.php
before the services container is available (so it needs to be stand-
alone).

To add, we also converts all global variables that were used in the
`ObjectCache.php` class into the config schema approach and retrieves
them using ServiceOptions injected in service wiring.

NOTE: MediaWikiIntegrationTestCase::setMainCache() was slightly
rewritten to take care of service reset which throws away the cache
object preserved by setInstanceForTesting() after service reset.
Instead, we preserve the object via MainConfigNames::ObjectCaches
setting with a factory closure which returns the correct cache object.

As a nice side effect of the above, the setInstanceForTesting() method
was removed entirely.

As a follow-up to this patch, I would like to remove the internal
_LocalClusterCache service in a stand-alone patch.

Bug: T363770
Change-Id: Ia2b689243980dbac37ee3bcfcbdf0683f9e1779b
2024-05-21 14:03:08 +00:00
Erik Bernhardson
1325deae9e extension registration: Fix handling of null default values
The current implementation of ExtensionRegistration violates the
documented behavior for extension registration, as described in
[[mw:Manual:Extension.json/Schema]]. According to the documentation,
when at least one of the global value and the default value is not an
array, the merge strategy is ignored and the global value will simply
override the default. However, an optimization incorrectly replaces a
configured empty array with the default null value.

The issue was fixed by applying the optimization after checking the
violated condition. Tests have been expanded for similar cases and
now additionally provide array diffs on failure.

WMF production configurations were evaluated with and without the
patch, and differences were analyzed on a per-wiki basis. This patch
results in two changes:

1. $wgCirrusSearchWriteClusters changes from null to []. This is the
 desired behaviour.

2. $wgLiqudThreadsAllowUserControlNamespaces changes from null to [].
 null means "no limits" and an empty array means "nothing allowed".
 This matches the intended configuration and will be corrected
 by this patch.

Bug: T365190
Change-Id: Ia3eaf6a607840e3e3134bded37e45050b7f247bf
2024-05-16 15:44:01 -07:00
Doğu Abaris
895aad4b80 Use typed properties in MissingExtensionException
Introduce typed properties for $isSkin, $extName, $path, and
$error in MissingExtensionException, eliminating docblock
annotations for a cleaner and type-safe codebase.

Change-Id: I8e05245da1eb0952a8adf28b64ab72f5a0ecfdfb
2024-04-01 16:34:56 +00:00
Derick Alangi
e0c34987eb
objectcache: Restore default keyspace for LocalServerCache service
* Fix main makeLocalServerCache() call in ObjectCacheFactory::newFromId
  to include a default keyspace, since wgCachePrefix is false by default
  (including at WMF).
* Idem for ExtensionRegistry.
* Dependency inject the domain ID so that service wiring does the
  correct thing when doing cross-wiki operations.

This is a followup on: I3179a387486377c6a575d173f39f82870c49c321.

Bug: T358346
Bug: T361177
Change-Id: Ibbb250465529810b8593f90bbb8330af0a2c3dbd
2024-03-28 19:47:44 +01:00
Derick Alangi
d372626b97
objectcache: Introduce ObjectCacheFactory MW service
ObjectCache is already doing a lot of factory pattern logic like
creating instances of the various BagOStuff, this should really be
the responsibility of the factory servicet.

This patch introduces a proper factory (ObjectCacheFactory) to handle
the responsibility of creating various instances of BagOStuff. Since
`newFromParams()` is a static function that gets passed in configuration
of $wgObjectCaches, that can stay that way (to keep supporting how we do
this in prod today).

Technical Breaking Change: `ObjectCache::makeLocalServerCache()` now has
a parameter and requires it but there are no callers of this method outside
MW core hence it is safe to change (and this patch update all callers) to
work correctly. Cache prefix is gotten from global state because sometimes
at this stage, the services container is not available.

Bug: T358346
Change-Id: I3179a387486377c6a575d173f39f82870c49c321
2024-03-19 12:38:39 +03:00
Abijeet
8ddc4ee2ef Add TranslationAliasesDirs to specify special page aliases in JSON
The TranslationAliasesDirs configuration allows defining translatable
aliases in JSON files. The value should be a name or names of folders
that contains files that have localized aliases. Each language should
have a separate file.

Currently, it supports defining special page aliases but in the
future can be extended to support magic words and namespace aliases.

The patch adds a script: ConvertExtensionsMessagesToTranslationAlias
that can be used to convert existing ExtensionMessagesFiles to the new
format.

Bug: T89947
Change-Id: Ief16a48a8dc8742854f67301791aa2a0b0531116
2024-03-06 18:13:28 +05:30
James D. Forrester
102a4f8a35 build: Upgrade mediawiki/mediawiki-phan-config from 0.13.0 to 0.14.0 manually
* Switch out raw Exceptions, mostly for InvalidArgumentExceptions.
  * Fake exceptions triggered to give Monolog a backtrace are for
    some reason "traditionally" RuntimeExceptions, instead, so we
    continue to use that pattern in remaining locations.
* Just entirely give up on PostgresResultWrapper's resource vs. object mess.
* Drop now-unneeded false positive hits.

Change-Id: Id183ab60994cd9c6dc80401d4ce4de0ddf2b3da0
2024-02-10 02:22:41 +00:00
Cindy Cicalese
c22300ec98 Deprecate array_merge_recursive merge strategy for extension/skins
The array_merge_recursive merge strategy is not intuitive and not
recommended. It does not appear to be used in any of the extensions
or skins that codesearch is aware of. To prevent confusion and
accidental use of array_merge_recursive when the behavior of
array_replace_recursive is likely desired, the array_merge_recursive
merge strategy is deprecated by this patch.

Bug: T292602
Change-Id: Ia0b861c308e6c7b4d40994af4c535ffdfa2b9ff5
2024-02-07 12:37:47 -05:00
Daimona Eaytoy
2520f3d1c4 Replace more usages of deprecated MWException
Bug: T328220
Change-Id: Ie9b56bcf5e962e275d80570cad98d676da505894
2024-01-19 22:01:12 +00:00
Gergő Tisza
183372c995 authz: Group grants by riskiness
Bug: T290790
Change-Id: Ib7a195c167f82e686c4ede45388957f9988bf75d
2024-01-16 23:55:48 +01:00
James D. Forrester
273cc042ae ResourceLoader: Drop targets system, deprecated in 1.41
Bug: T340802
Depends-On: Ie936afed7042d5a4713b027c30d7487565a35eaf
Change-Id: Icad30d62301be5d7390ebdf34e818519e3fe56c4
2024-01-12 16:42:38 -05:00
jenkins-bot
7057d995bc Merge "Add support for conditional user defaults" 2024-01-09 04:42:53 +00:00
Martin Urbanec
6c8b696020 Add support for conditional user defaults
Why:
Sometimes, it is necessary to have different behavior
for newly registered and existing users. For example,
this happens in the Echo or GrowthExperiments extensions.
As of now, this behavior is implemented by inserting
user_properties rows in onLocalUserCreated.

Over time, this results in a singificant amount of rows
inserted, which contributes to the user_properties table bloat,
which is already overly large (cf. T54777). This patch makes it
possible to remove such rows by supporting conditional defaults
for user properties.

What:
Add support for conditional defaults of user properties. This can be
configured via `ConditionalUserOptions` config option.

Bug: T321527
Change-Id: I1549c3137e66801c85e03e46427e27da333d68e2
2024-01-09 02:33:17 +00:00
Dogu
e6907ffdf6 Replace DuplicateKeyException qualifier with import
This patch simplifies the usage of the DuplicateKeyException by
adding a use statement for the Seld\JsonLint\DuplicateKeyException
class, and updating the catch block to use the shortened name.

Change-Id: I111ee9280f1770669822c218a43fa4dc0c431ce1
2024-01-05 02:10:05 +00:00
James D. Forrester
e159142920 Drop ExtensionProcessor::getExtraAutoloaderPaths(), deprecated in 1.39
Change-Id: Id42357123b1db4c6a42bca2d48e860e029e616ed
2023-12-08 17:32:35 -05:00
Daimona Eaytoy
48a1c0bb2f Autofix spacing around commas
This was done automatically using the
`Universal.WhiteSpace.CommaSpacing` sniff, which will be included in the
next release of the MW PHPCS config.

Some of these have been adjusted manually where the autofix broke
vertical alignment.

Change-Id: I54a4668d8a2759b9d7de47742c943a535a04e211
2023-10-25 01:08:44 +02:00
Amir Sarabadani
8bae683660 rdbms: Introduce concept of virtual domains and mapping to ext cluster
This would simplify any caller that's trying to use extension1 cluster

Bug: T330590
Change-Id: Icccde8e10070686870601cae74b21ca9bed71ece
2023-10-05 13:31:15 +02:00
mainframe98
d9cbaf33da Ensure that ExtensionProcessor exports UserRegistrationProviders
Bug: T344694
Follows-Up: If9fa12a392064dd504590a861a175e3604a34fab
Change-Id: I2f84ade7a5df68922a2266009592dd2d79ec42ec
2023-09-16 01:15:20 +02:00
Daimona Eaytoy
b65482ac1b phpunit: Prevent access to ExtensionRegistry in unit tests
Unit tests should not access the ExtensionRegistry singleton. This is
similar to how MediaWikiServices is disabled, but needs to be done
separately because ExtensionRegistry is not a service.

Make ExtensionRegistryTest use a mocked SettingsBuilder to avoid
triggering the exception when SettingsBuilder tries to access the global
instance of ExtensionRegistry.

Inject data from ExtensionRegistry into Parsoid's SiteConfig to keep
SiteConfigTest a working unit test.

Change-Id: I0a04c82250582fed7a66c1e10868d9b4f3823a28
2023-09-12 00:04:31 +00:00
jenkins-bot
f415979f2c Merge "Make all limits function as user rights." 2023-09-11 12:34:48 +00:00
daniel
9143649f48 Make all limits function as user rights.
In order to check all existing rate limits through Authority, the limit
keys must function as user rights. However, we do not want them to be
"normal" permissions, since they cannot sensibly be revoked, and they
should not clutter the user interface.

To solve this, we introduce the concept of "implicit rights", which are
always granted, but limitable.

Change-Id: I0ea6f29130da1d68d022d47d9221fe878bc9beae
2023-09-11 12:03:57 +00:00
Reedy
b3b415eb1c Expose PrivilegedGroups to extension schema
Bug: T208477
Change-Id: Ic7c1b02d6d6c077981599f00e443d157648a1fd8
2023-09-07 15:41:38 +01:00
Reedy
9c8ac53c08 ExtensionProcessor: Minor doc cleanup
Change-Id: I058d5f2a02471c4e5a0f3453cf9df236938ee3fe
2023-09-04 20:25:21 +01:00
James D. Forrester
f28d147474 ExtensionRegistry: Stop supporting no manifest_version, deprecated in 1.26
Change-Id: I1f8af82d9ba4a6cc2c225093a2d12f5d43ab78e9
2023-08-23 17:31:01 -04:00
Daimona Eaytoy
31fcbb83c1 Replace usages of wfParseUrl
wfParseUrl falls back to the global service locator as of I706ef8a5.
This will soon be disallowed in unit tests (see I5117eab9), and all the
classes updated in this patch are covered by a unit test that would then
fail.

SiteConfig already has a UrlUtils object available, so just use that.

In the other classes, there is no need to inject a UrlUtils service and
we can instead adopt parse_url, because these didn't depend on our
site-configurable or custom parsing logic. For precedent see also
change I6492f5142861513e4a7, I1e76d2f5aef, and lots of other examples
in Codesearch for parse_url().

The warnings about parse_url() in UrlUtils.php have been obsolete
since about PHP 5.4, when it started to support protocol-relative
URLs, non-slash protocols like "mailto", and deal with spaces/newlines
correctly (https://3v4l.org/YWUkl).

This patch was partly copied from PS 20 of I5117eab9.

Co-Authored-by: Timo Tijhof <krinkle@fastmail.com>
Change-Id: I98ea4670e842d11598664f058d8c90a900477be4
2023-08-11 00:00:25 +00:00
thiemowmde
ef84619cd3 Consistently use LogicException for test-only methods
"BadMethodCallException" sounds like it would fit, but it does
have a very different meaning, described as "exception thrown if
a callback refers to an undefined method or if some arguments are
missing". This is not what's going on here. These are methods that
should only be called from unit tests.

This appears to be a common mistake, often copy-pasted.

Change-Id: Ib39e28f596a883481d5f526460a5c871c75f5313
2023-07-22 16:21:42 +00:00
thiemowmde
9b03cde58e Merge sequences of if that end doing the same thing anyway
Motivation:
* Avoid code duplication.
* Hopefully make it easier to read.
* Also order stuff from cheap to expensive, if possible.

Change-Id: I575e3f2027ce60a0d0885be5b9bd3e07bc035eee
2023-06-16 16:09:42 +02:00
jenkins-bot
6f9ac8889b Merge "Replace substr with cleaner string methods" 2023-06-06 14:15:27 +00:00
Kevin Israel
a6024006ba registration: Fix error when processing pre-1.35 ValidSkinNames entry
Pre-1.35 skins set a string value within ValidSkinNames that "will be
prefixed with 'Skin' to create the class name of the skin to load."
Setting the "args" offset in this case results in a TypeError.

Avoid the error by restoring one of the isset() checks removed in
3b7ca220b3. Tested using "Schulenburg" skin.

Change-Id: I293830c0a25ea229887eac73cdd2d3648c2c0915
2023-05-20 17:21:31 -04:00
Matěj Suchánek
676fcf4379 Replace substr with cleaner string methods
Use str_starts_with, str_ends_with or string offset where appropriate.

This fixes a bug in MimeAnalyzer where the "UTF-16LE" header could not
be identified because of wrong constant. This is the exact type of bug
that the new functions can avoid.

Change-Id: I9f30881e7e895f011db29cf5dcbe43bc4f341062
2023-05-20 15:40:21 +02:00
Jon Robson
3b7ca220b3 ExtensionProcessor: Drop support for skin template directories relative to core
Bug: T262067
Change-Id: I447c66295dea44810267f2238849ff37c35812c7
2023-05-11 16:15:18 -07:00
Gergő Tisza
5099f79718 Add ForeignResourceDirs extension/skin attribute
Add an extension/skin attribute and a command line option for
manageForeignResources.php, for management of an extension's or
skin's foreign resources. This is less clumsy and more
introspectable than each extension/skin creating its own copy
of manageForeignResources.php.

Bug: T330508
Change-Id: I5df95ea4799d0efce60b58a35cb916c8e0f555b0
2023-04-25 09:27:35 -04:00
Timo Tijhof
5278d22423 registration: Improve docs and add ingroup tags
Follows-up I4ed0d333d57626d05.

* Clean up the file header, similar to other commits under
  <https://gerrit.wikimedia.org/r/q/message:ingroup+owner:Krinkle>.

* Describe the class on the first "brief" line as to-the-point as
  possible.

* Group the classes in the registration/ component together and link
  the architecture document, akin to ResourceLoader.

Change-Id: I67e6dc9ce7cfb98dfd30007584bb9e97ff817370
2023-03-24 19:11:36 -07:00
Brian Wolff
67d13660a4 registration: Add a friendly error message for missing extension
Based on Project:Support_desk, this seems to be a very common error.
Many more novice users seem to get confused by the technical message
involving "stat failed". Given that this might be the first user's
first experience with MW, I think its prudent to make it friendly
as possible.

This error message does not do i18n. I didn't do i18n to avoid
dependencies on MW stuff as it is very early in the setup process,
exceptions aren't usually i18n'd, and its entirely possible that
this error happens before a language is even set.

This does not respect $wgShowExceptionDetails. I think that can
be justified because this error happens during setup and not during
normal operation and there would be no user controlled values in
the backtrace just paths.

Bug: T321363
Change-Id: I4ed0d333d57626d05c361d08f1bf4a919115d550
2023-03-15 08:00:22 -07:00
jenkins-bot
6494f7b6dd Merge "Remove unused arguments to private functions" 2023-02-08 22:42:46 +00:00
Umherirrender
ed169d991e Remove unused arguments to private functions
Found by phan dead detection

Change-Id: I93379b7b9a733206d0e53add04fcdb9478c58755
2023-02-08 19:00:47 +00:00
Roan Kattouw
f326fc7f0d skins: Allow skins to specify their Codex theme
Add a "SkinCodexThemes" key to skin.json, that works just like
"SkinOOUIThemes". Based on the value the skin sets,
ResourceLoader\CodexModule loads the correct Codex theme for the skin.
The default theme is wikimedia-ui, meant for skins with a 16px base font
size. Skins with a 14px base font size (like Vector) should override
this to use wikimedia-ui-legacy.

Bug: T324367
Change-Id: I7435413928f2b8c5d43c34d9e2e7df470d710c93
2023-02-06 10:27:43 -08:00
Jon Robson
01aec63c21 ResourceLoader: Default File modules to mobile and desktop targets
If not specified, going forward all modules which do not define
targets should be assumed to be mobile AND desktop. I think this is
a fair expectation given that most new features should be built with
mobile in mind. This also avoids the issue where features are
unexpectedly not shipped to mobile.

The work in T324723 has ensured that all modules that need to remain
desktop only have been marked as such. After the audit, we can be
reasonably confident that enabling the remaining modules is okay,
given these modules run in isolated parts of the UI (not on every page
view).

I'm assuming CI is catching all offenders here. If not, any impacted
modules would require a trivial update to explicitly define modules
as mobile only. This would allow us to see clearly which modules
are depending on the target system and strategize around updating
them.

Once this patch is merged we can focus on fixing the modules we've
identified as mobile or desktop targeted and finally dismantling the
targets system altogether.

Bug: T127268
Change-Id: Ia062ff2d8b8732b0d3498c1a614bbf6a3e3a7ddb
2023-01-31 19:24:53 +00:00