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
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
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
And deprecated aliases for the the no namespaced classes.
ReplicatedBagOStuff that already is deprecated isn't moved.
Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
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
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
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
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
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
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
Introduce typed properties for $isSkin, $extName, $path, and
$error in MissingExtensionException, eliminating docblock
annotations for a cleaner and type-safe codebase.
Change-Id: I8e05245da1eb0952a8adf28b64ab72f5a0ecfdfb
* 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
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
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
* 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
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
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
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
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
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
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
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
"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
Motivation:
* Avoid code duplication.
* Hopefully make it easier to read.
* Also order stuff from cheap to expensive, if possible.
Change-Id: I575e3f2027ce60a0d0885be5b9bd3e07bc035eee
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
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
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
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
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
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
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