Commit graph

158 commits

Author SHA1 Message Date
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
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
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
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
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
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
James D. Forrester
e159142920 Drop ExtensionProcessor::getExtraAutoloaderPaths(), deprecated in 1.39
Change-Id: Id42357123b1db4c6a42bca2d48e860e029e616ed
2023-12-08 17:32:35 -05: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
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
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
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
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
Bartosz Dziewoński
e3784468fc OutputPage: Support loading some mw.config vars late, at end of body
JS config vars listed in the 'LateJSConfigVarNames' extension attribute
or in the OutputPage::CORE_LATE_JS_CONFIG_VAR_NAMES constant will now
be added to the end of the HTML response, instead of early in the HTML
head where it blocks rendering/painting.

Bug: T41813
Change-Id: I86d461756398780dc24949013f35b7730a481052
2022-11-07 17:56:24 +00:00
C. Scott Ananian
4cb3957cf0 Remove $wgParserTestFiles, deprecated in MW 1.30
This global variable was replaced by auto-discovery of parser test
files in extensions and is no longer needed (or used).

Change-Id: Ib616e60f36db32ffd8bc69c71a096f23c0a27910
2022-10-13 09:22:22 -04:00
daniel
92e8f4e40a Collect autoloader info in ExtensionProcessor
This change cleans up when and how we register autoloader info for
extensions.

This bumps CACHE_VERSION to 8, to avoid issues in case this patch gets
reverted: the new code doesn't copy the map of class files into
$info['globals']['AutoloadClasses']. If old code was to read a new cache
entry, autoloading would fail.

BREAKING CHANGE: The following methods have been removed from
  ExtensionRegistry without deprecation and without replacement.
  They had been introduced in 1.35 for use in the testing framework,
  and were not in use by any known extension:
  - exportAutoloadClassesAndNamespaces
  - exportTestAutoloadClassesAndNamespaces

NOTE: breaks the hack that SocialProfile has in place for T243861.

Bug: T240535
Change-Id: I6e1ceac034c443d9475f1adc1babecddd6af6d05
2022-06-07 17:39:00 +02:00
Tim Starling
3e2653f83b ResourceLoader namespace (attempt 2)
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader itself.

Move the tests by analogy.

I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".

I did not address DependencyStore which continues to have a non-standard
location and namespace.

Revert of a241d83e0a.

Bug: T308718
Change-Id: Id08a220e1d6085e2b33f3f6c9d0e3935a4204659
2022-05-24 15:41:46 +00:00
Lucas Werkmeister (WMDE)
a241d83e0a Revert "ResourceLoader namespace"
This reverts commit e08ea8ccb9.

Reason for revert: Breaks Phan in extensions, and as far as I’m aware,
this change isn’t urgently needed for anything, so the simplest fix is
to revert it again for now. After PHP 7.4 it should be safer to try this
again (we hopefully won’t need the two “hack” classes by then).

Bug: T308443
Change-Id: Iff3318cbf97a67f821f78e60da62a583f63e389e
2022-05-16 14:43:33 +00:00
Tim Starling
e08ea8ccb9 ResourceLoader namespace
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader and
ResourceLoaderContext.

Move the tests by analogy.

I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".

I did not address DependencyStore which continues to have a non-standard
location and namespace.

Change-Id: I92998ae6a82e0b935c13e02a183e7c324fa410a3
2022-05-16 14:41:27 +10:00
Aryeh Gregor
7b791474a5 Use MainConfigNames instead of string literals, #4
Now largely automated:

VARS=$(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | \
  tr "\n" '|' | sed "s/|$/\n/;s/'//g")
sed -i -E "s/'($VARS)'/MainConfigNames::\1/g" \
  $(grep -ERIl "'($VARS)'" includes/)

Then git add -p with lots of error-prone manual checking. Then
semi-manually add all the necessary "use" lines:

vim $(grep -L 'use MediaWiki\\MainConfigNames;' \
  $(git diff --cached --name-only --diff-filter=M HEAD^))

I didn't bother fixing lines that were over 100 characters unless they
were over 120 and triggered phpcs.

Bug: T305805
Change-Id: I74e0ab511abecb276717ad4276a124760a268147
2022-04-26 19:03:37 +03:00
Tim Starling
e8dbf5f80c TempUser infrastructure and services
Add services and utilities for automatic creation of temporary user
accounts on page save, in order to avoid exposing the user's IP
address.

* Add $wgAutoCreateTempUser, for configuring the system
* Add TempUserConfig service, which interprets the config.
* Add TempUserCreator service, which creates users during page save as
  requested by EditPage. With proxy methods to TempUserConfig for
  convenience.
* Add table user_autocreate_serial. Table creation is necessary before
  the feature is enabled but is not necessary before deployment of this
  commit.

Bug: T300263
Change-Id: Ib14a352490fc42039106523118e8d021844e3dfb
2022-04-14 09:23:55 +10:00
jdlrobson
2a7aeb9770 Include skin name in deprecation message
The deprecation warning shows on all skins which makes it hard
to debug.

Follow up to d3eda44

Change-Id: I067715df10a0b92665623a798c6c95386822a06e
2021-12-21 16:06:40 -08:00
Isabelle Hurbain-Palatin
f336375846 Fix the json schema and the extension processor for Parsoid extension modules
Trying to declare a Parsoid extension showed a couple of issues related
to the JSON specification (there was a possible confusion between both
object declarations) and in trying to declare an extension as a single
string. This patch fixes both these issues.

Change-Id: I8c2f901e9a7e51704f10c8d8754cc8738079fde6
2021-12-17 09:50:25 +01:00
jenkins-bot
967a24d050 Merge "registration: Let namespaces specify if they're includable" 2021-11-16 00:11:13 +00:00
jdlrobson
7746dd3eb5 Deprecate use of template directory relative to core
Warning now issued since skins have been updated.

Additional change:
Previously deprecations in release notes were in the wrong
section (Relating to ResourceLoaderSkinModule) these are
moved alongside the newly added deprecation note alongside
other skin deprecations.

Bug: T262067
Depends-On: I52bee67732cc72ec6857b6fc10cfbdd89ef9b8db
Depends-On:  I338198878e78cb5c6f47c53fdf18d3944655e965
Change-Id: Ic60524fe3c054706dbea15cc04235e979952e9f5
2021-10-29 17:28:35 +00:00
Alexander Vorwerk
b88db33fe4 registration: Apply manifest v2 logic to hypothetical v3
If a new manifest version would be published, this could end in a
regression if the corresponding if statements are forgotten to be
updated. If there is no breaking change in some area, the code from
manifest_version 2 should still be used. Therefore it makes sense to set
these if statements for all versions greater than 2 as well, to prevent
that when a new version is released, the code of version 1 is used.

Change-Id: I0a9feda19cec5be07e6ad0f46fef8c3140f14eca
2021-09-05 08:55:26 +00:00
jdlrobson
d3eda44624 registration: Make it easier to set a skin's templateDirectory
When originally introduced, a skin's templateDirectory was relative
to core, rather than the skin itself. Most skins needed to set
something like "skins/Example/templates", hardcoding the default value
of $wgStyleDirectory.

skin.json will now assume that the value of templateDirectory is
relative to the skin itself. If that directory doesn't exist, we'll
fallback and assume it's using the previous behavior of being relative
to core. In practice this should not be a breaking change since no skin
is expected to have a directory like "skins/Example/templates" inside
the skin itself.

Finally, ExtensionProcessor will set a default templateDirectory if
one isn't already set, so in most cases this setting should be able
to just be removed entirely.

Bug: T262067
Change-Id: I434b8a4319f3c8b65bcaab3465224058f31e7ae8
2021-08-27 00:22:38 -07:00
Kunal Mehta
d1c292fe1b registration: Let namespaces specify if they're includable
Extensions can now define namespaces as non-includable, corresponding to
$wgNonincludableNamespaces.

By default, namespaces are includable and need to explicitly be
specified as `"includable": false` to be added to
$wgNonincludableNamespaces.

Bug: T277210
Change-Id: I85dc7bf01e5af81673c745a21ac83168321d0fef
2021-08-19 22:09:47 -07:00
Thiemo Kreuz
84ac5265b1 registration: Better error when config value is missing
I believe this is "cheap enough" to be worth it. Without this,
the error message(s) one runs into when a "config" element in
extension.json doesn't have a "value" are very confusing. I
run into this when a "value" line accidentally got lost in a
merge conflict.

Change-Id: Id71a882932f6979742055fa58dea35ea65a7c16f
2021-05-12 15:19:01 +00:00
Reedy
fb771021ea Use some more neutral language
Bug: T277987
Change-Id: Ieceb01f7a61693a0f03cc331213cb8f93163b8e9
2021-04-18 16:49:36 +01:00
Ammarpad
ba17c42a79 registry: Allow specifying immovable namespaces in extension.json
In most cases this will alleviate the need to use the
ImmovableNamespaces hook.

Bug: T277520
Change-Id: If1e1063a597ebdb39343a356cc381a6ceafaebcc
2021-03-17 06:10:35 +00:00
jenkins-bot
5ea464b234 Merge "Use static closures where safe to use" 2021-02-14 23:05:48 +00:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Kunal Mehta
9859edb60b registration: Stop double-caching config settings
This was added for the stalled ConfigRepository project and never used.
It's currently bloating the cache that's read on every request early
during initialization.

When we do revive that project, we should make sure that the implementation
doesn't double cache the settings.

Bug: T274445
Change-Id: I16f31ecf1bc60dba9f93525d5dcb94129d9d149a
2021-02-10 16:03:58 -08:00
Bartosz Dziewoński
77cf34fae7 Fix base path handling for MessagePosterModule registration
It was done in a funny way to allow extensions to provide paths that
are relative to a different base path than the core ones. This way
results in wrong paths on Windows. Use the ResourceLoaderFilePath
class instead, which I wrote for this exact purpose :D

With this approach, it should also be possible to handle remote paths
correctly, and remove the `'debugRaw' => false` hack in ServiceWiring,
but I don't entirely understand how that is handled in the extension
registration code.

Bug: T264965
Change-Id: Id501a10d87a60f8c71df49820e1fb866adc12411
2020-10-28 02:27:32 +00:00
Timo Tijhof
0c01d8cc52 resourceloader: Add skin-based 'mediawiki.skin.variables.less' import
Add the SkinLessImportPaths attribute for skin-specific LESS import
paths, which skins can use to override the mediawiki.skin.variables.less
file.

As a starting point, add the following 5 variables:

* device widths (3x)
  To help phase out 'mediawiki.ui/variables'. These are
  commonly used by MobileFrontend.

* @font-family-sans
  Recommended by Volker. Used by multiple skins.

* @border-radius-base
  Recommended by Volker as example of something that we currently
  hardcode in MediaWiki core for Vector and OOUI/WikimediaUI
  in 'mediawiki.widgets.datetime' but should instead be allowed
  to vary by skin and OOUI theme.

  Remove the hardcoded value for '@border-radius-base' in
  various places in favour of importing from mediawiki.skin.
  The default is a bare default of 0 (as border-radius is off
  by default in the browser).

  The value for Vector is restored there by I47da304667811.
  The value for MonoBook is improved by I000f319ab31b.

Bug: T112747
Change-Id: Icf86c930a3b5524254bb549624737d3b9dccb032
2020-09-15 10:05:53 +00:00
C. Scott Ananian
5fb6e52bee Fill in the 'name' field in ParsoidModules registration
This avoids the need for extension.json to state the name of the
extension in two different places (which could then disagree).

Parsoid needs the name of the extension which registers a given
module for error reporting.

Bug: T133320
Change-Id: I0abb7ab433e4ac9c94cf2f9720b174372a29dc10
2020-06-01 16:24:39 -04:00
jenkins-bot
ca6ec5a4ee Merge "Add 'ParsoidModules' as a top-level core attribute in extension.json" 2020-05-29 00:16:01 +00:00
Timo Tijhof
5d8f62bdd3 ExtensionRegistry: Remove exporting and caching of wgExtensionCredits
This data is the same as the 'credits' data that is already compiled,
cached and made available via ExtensionRegistry.

Similar to various other configuration variables previously, the
$wgExtensionCredits variable is now also required to only be used
for providing input to the system (e.g. from LocalSettings.php,
or from legacy extension PHP entry points). It is no longer
supported to use this variable to reliably read out a full view
of all extension credits (specifically those registered via
extension.json).

Doing so had the downside of adding processing cost to every
web request, as well as taking one the single largest portion
of the ExtensionRegistry APCu cache key, which in PHP7+ incurs
a linear cost for every string value, string key, of every
(sub)array in this huge structure; and does to on every request
just in case something reads from $wgExtensionCredits.

The new method to access this information reliably is owned
by SpecialVersion for now (could be moved elsewhere). This
also makes the merging logic more testable and incurs it on-demand
rather than upfront.

Details:

* Move 'type' internally from NOT_ATTRIBS to CREDIT_ATTRIBS.
  These two arrays behave identically for most purposes (they are
  both used to mean "don't export this as a global attribute").

  By placing it in CREDIT_ATTRIBS it becomes complete and makes
  it easy to refer to in docs. Previously, extractCredits()
  read the 'type' key outside the loop for CREDIT_ATTRIBS.

* Remove redundant code in ApiBase.php, that is now more obviously
  redundant. Looks like a left-over or merge conflict mistake
  from when ExtensionRegistry was first introduced.

Bug: T187154
Change-Id: I6d66c58fbe57c530f9a43cae504b0d6aa4ffcd0d
2020-05-28 18:46:41 +00:00
C. Scott Ananian
e71e025aba Add 'ParsoidModules' as a top-level core attribute in extension.json
See also I20f641a1ff032a6da3549b01dfaf8f4cf1eb5071, which uses this
attribute, and the earlier discussion in the (abandoned)
Ia251d631febf5be7fcad21cd8b73a68ec2785137.

Bug: T133320
Change-Id: I6c74938883376ec17f3790678b435585083a440f
2020-05-22 18:19:00 +00:00