Commit graph

90 commits

Author SHA1 Message Date
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
jenkins-bot
5d8b59b3ea Merge "ResourceLoader: Add module property skipStructureTest" 2024-03-13 22:09:01 +00:00
Tim Starling
c45ca5c0e3 ResourceLoader: Add module property skipStructureTest
Allow extensions with very special modules that can't be called in a
testing environment to skip ResourcesTest::testRespond().

Needed by If1186797fd047d4f for ext.wikisource.OCR.

Change-Id: Id02915d9633c2d8209d2ff2e60f6748095ec10fe
2024-03-11 17:01:16 +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
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
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
Reedy
c1252c1589 doc: Improve description of type in extension.schema.v1.json
cf 60d9e6007dcb30a96d4f9bad98dc3a89634b5bb6

Change-Id: Id048b0abb3f581dff5bfac766684e800d40ea651
2023-09-26 12:14:09 +01:00
Reedy
5ac1a02b80 Update extension.schema.v1 per extension.schema.v2
Follows-Up: I3d01ab5467d1cf496d144781ef57a221b1476347

doc: Make extension.schema.v2.json a valid JSON schema.

The following validation errors have been fixed:
* The required validation keyword must be an array.
* Remove trailing commas
* Remove improper use of "".

Change-Id: I5f0dc8b2ab51c999f7ad3a827c66dbdc08113313
2023-09-20 18:35:16 +01:00
Martin Urbanec
85e78d22bd Add UserRegistrationLookup
Why:
Temporary accounts introduced as part of IP Masking are supposed
to expire 1 year after their registration. Accounts can have
multiple registration timestamps when in a wiki-farm setup,
depending on which wiki we consult.

To implement the account expiration logic, we need to know the global
(first) registration timestamp.

Similar to CentralIdLookup, a concept of a registration date
provider is introduced. Unlike IDs, users can have multiple
kinds of registration dates (Wikimedia recognizes local and global,
but third parties can have different needs). For that reason,
any number of registration providers can be registered at any
given time; caller determines which one is requested. The default
is `local`, which is the only provider that is guaranteed to exist.

What:
* Add UserRegistrationLookup
* Add UserRegistrationProviders config variable

Bug: T344694
Change-Id: If9fa12a392064dd504590a861a175e3604a34fab
2023-09-15 11:38:23 +02:00
Reedy
b3b415eb1c Expose PrivilegedGroups to extension schema
Bug: T208477
Change-Id: Ic7c1b02d6d6c077981599f00e443d157648a1fd8
2023-09-07 15:41:38 +01:00
Tim Starling
4f540e159a ResourceLoader: In extension schema, validate properties of file info objects
Change-Id: I3d1738265fa3aca5144bf22c47b2198a3ffd49d6
2023-05-10 15:27:35 +00:00
Tim Starling
a59c446154 ResourceLoader: Allow FileModule scripts to be generated with a callback
To implement source maps, we want FileModule::getScript() to return
an array with path information, but that would break subclasses of
FileModule which concatenate to the return value of parent::getScript().
So allow scripts to be generated by a callback, eliminating the need for
concatenation in subclasses.

* Factor out most of the loop body of expandPackageFiles() into
  expandFileInfo(). Add 'name' to the return value. Ensure 'filePath'
  is always a FilePath object since we need that to safely return it
  to ResourceLoader later. Document the return value.
* Make sure the base path is always set in FilePath objects returned by
  expandFileInfo().
* Factor out the loop body of the final stage of file info expansion
  into readFileInfo(). Retain filePath, do not unset it.
* Assert that $fileInfo['content'] is definitely set.
* Convert array_map() in getDefinitionSummary() to a loop.
* Migrate LanguageDataModule.

Bug: T47514
Change-Id: I97d61b5793159cea365740e0563f7b733e0f16de
2023-05-09 11:47:40 +10: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
James D. Forrester
6c7177349b ResourceLoader: Raise MW JavaScript startup requirement to ES6
The UA sniffs that overrode the feature tests are no longer needed.

* MSIE 10: Fine, rejected by feature checks.

* UC Mini "Speed Mode": Redundant, the version that this sniff
  matched is pre-ES6. Current versions of UC Mini don't appear to
  support enabling "Speed Mode" on random websites nor does it offer
  it for Wikipedia specifically.
  Details at https://phabricator.wikimedia.org/T178356#8740573.

* Google Web Light: Redundant, shutdown as of 2022.
  Any references or extensions that still reach the proxy, get
  redirected to our online URLs
  https://googleweblight.com/?lite_url=https://en.m.wikipedia.org/wiki/Banana
  https://phabricator.wikimedia.org/T152602
  https://en.wikipedia.org/wiki/Google_Web_Light

* MeeGo: Redundant, discontinued and presumed rejected.
  Either way, unsupported.

* Opera Mini: Fine, rejected by checks.
  Details at https://phabricator.wikimedia.org/T178356#8740573.

* Ovi Browser: Redundant, discontinued and presumed rejected.
  Either way, unsupported.

* Google Glass: Improve UX (since 2013, T58008).

* NetFront: Redundant. Old versions are presumed rejected.
  Current versions are Chromium-based and presumed fine.
  The exclusion was not UX based, but due to jQuery explicitly not
  supporting it in 2013. This is no longer the case, so we can let
  the feature test lead the way here.

* PlayStation: Redundant, same story as NetFront.
  The version that matched the sniff is presumed rejected.
  Current versions probably fine, but even not, don't match
  our sniff so are already enabled today.

Bug: T178356
Change-Id: Ib6263ce3ffd11af5e501de8857f3e48a248c6210
2023-03-30 14:26:05 +01:00
Matěj Suchánek
c231736471 Fix some typos
Bug: T201491
Change-Id: I5c9408c262f09c936525f35abfacfa92a193b791
2023-03-21 15:58:09 +01: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
Bartosz Dziewoński
c681ee5f2d extension schema: Remove broken option to use null in OOUIThemePaths
Despite being documented, this seems to have never worked correctly,
causing confusing exceptions.

Rather than try to fix it in this scary legacy code, just document the
alternative that actually is supported: specifying a file that doesn't
exist.

Change-Id: I00b5e144350add475a8379ead62868ed21fefb81
2022-12-30 21:04:31 +00:00
Umherirrender
b3d065198e docs: Improve docs around SpecialPage_initListHook
Change-Id: I45410a4c7cf2feb99b24c06e9002ebbbfc66586f
2022-12-11 20:39:10 +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
jenkins-bot
8568901c3a Merge "build: Run eslint for /docs/ and make pass" 2022-08-05 01:03:29 +00:00
Umherirrender
fefb27b037 build: Run eslint for /docs/ and make pass
The doc folder contains (committed) json files with schema definition
for json files
That should be linted as well to spot syntax errors easier

Change-Id: I20ff7abf6b98d2247ee52e2d2b43af88c062f779
2022-07-27 00:43:02 +02:00
Umherirrender
3f7f35b1ce Fix typo in extension.schema.json
Change-Id: Ic4a0e32dc9d7e57afa7a71962e91801f556490b4
2022-07-26 20:47:35 +02:00
Reedy
c5fe40ae9d registration: Add suggested dependencies to extension.json schema
For now, this is not used by MediaWiki core itself, but in the future
we may add prompts in the installer and notes in update.php, amongst
other places.

The naming is taken from the `suggests` field as used by Composer.

Bug: T182472
Change-Id: Icc8c189812b231313e6d8b3e907a866c710bae24
2022-07-10 00:47:20 +00:00
Timo Tijhof
85892edce5 resourceloader: Minor doc changes following PSR-4 namepace change
Follows Id08a220e1d60 (after I92998ae6a82e).

Change-Id: I33d20201bfee4595baa39c01eaf8b7de6034a8ed
2022-05-29 16:41:19 +00: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
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
mbsantos
d825e0d457 Allow ParsoidModules extension schema to register services
In order to allow extensions to wire services in Parsoid's ExtensionModule
implementation, the ParsoidModules schema should have the needed properties.
But rather than try to exhaustively list the properties allowed in an
object factory specification, rewrite the schema to be more permissive
about allowing unknown properties while still disambiguating the object
factory case from the "Parsoid extension configuration array" case.
In particular, the latter will never have a `class` or `factory`
property.

Change-Id: Id630912fde0d35628188988860832821142ca6ca
2022-01-20 16:03:21 -05: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
aadc33bfc5 Merge "registration: Allow ObjectFactory spec in extension.json schema" 2021-12-05 09:37:23 +00:00
Ostrzyciel
f1266d1783 registration: Allow ObjectFactory spec in extension.json schema
Since 272e941b7f it has been possible for a while now to construct
ContentHandlers using ObjectFactory specifications. However, this
was neither reflected in the JSON Schema of extension.json, nor in
the documentation on mediawiki.org.

See example of this being used in the wild: Ieca72e60d39376.
That patch is currently stuck on extension.json schema validation
test. The ObjectFactory spec itself is fine and works as intended.

Bug: T243560
Change-Id: I5986e19f1780709cf7b3ed2f55d5f46a0a1deeb7
2021-12-05 09:17:38 +00: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
DannyS712
df6c612941 ExtensionProcessor: Remove loaderScripts from extension.json schemas
The `loaderScripts` feature of ResourceLoaderFileModule was removed
without replacement a while ago. Use of it would no longer work
correctly and should result in a test failure.

The `position` property was also removed, but made no functional change
to behaviour. Update its documentation to clarify that it is no longer
used (it is simply no longer needed).

Bug: T289108
Change-Id: If3dbbbe95d60803be8df3c9a4d5ee9e01c825ebb
2021-08-20 04:11:53 +00:00
Tim Starling
076b93fba0 Add extension.json merge strategy "provide_default"
Add a merge strategy which sets the whole value only if the global
has not previously been set. This can be used to allow LocalSettings.php
to remove elements from an array created by extension.json.

Bug: T142663
Change-Id: Id250f9c349ee4eafbc759452ca6ea2a918baeb11
2021-05-04 16:02:55 +10: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
Roan Kattouw
b267f7aa90 resourceloader: Allow modules to mark themselves as ES6-only
Modules that set "es6": true in their module definition will error when
a non-ES6 client tries to load them.

To detect ES6 support, this looks for native Promise support,
RegExp.prototype.flags, and non-BMP characters in variable names. All
browsers that lack full ES6 support fail at least one of those checks.

To flag modules as requiring ES6, this adds a ! to the end of their
version string. This takes up much less space than adding another
register() parameter (which would have to be at the end). It's hacky,
but we expect this feature to be relatively temporary, until we require
ES6 for running any JS at all (probably in about a year).

For distinguishing different types of errors thrown from
sortDependencies(), use e.name. We can't subclass Error properly because
that requires ES6.

Bug: T272104
Change-Id: I45670c910ff12eb422ae54c9fcf372e45c7b2bf1
2021-03-04 14:53:36 -05:00
DannyS712
6a03737104 Update for object-factory v.3
Bug: T267074
Change-Id: Iff9b46c9e78e87d32c8f75d26b284ce01bccb63d
2020-11-17 06:20:23 +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
Kunal Mehta
46d4504660 registration: Sync v2 and v1 schemas
Unless it's an intentional deviation, everything in v2 should also be in v1.

This copies over:
* e71e025aba: Add 'ParsoidModules' ...
* 7abd828ea3: Extension schema updates for HookContainer
* 34bff221ba: Introduce 'MessagePosterModule' extension attribute
* e97f2943f2: QUnitTestModule should support packageFiles and templates
** d50c7f5b56: Fix schemas for 'packageFiles'
** ee1f4f8ea3: Fix schemas for 'templates'
* 3f0056a252: REST API initial commit

Change-Id: I1ae6fed0261ad29ea5cb39b3511b8cde392ab612
2020-07-20 16:31:45 -07:00
Reedy
583602e16d [registration] Remove type of string from Hooks in extension.schema.v1.json
Same as it will be or v2 when that patch merges

Change-Id: I64c3bbcda0f353fe9c14b0d5bea241e0304c0e2e
Follows-Up: I1a8657ff9fd14618c6709dbab62c3b4ee9f659a5
2020-05-26 01:28:49 +01:00
jenkins-bot
b7968e948d Merge "Sync descriptions from extension.schema.v2.json to v1.json" 2020-05-16 02:44:20 +00:00
Reedy
0b91ceedec Sync descriptions from extension.schema.v2.json to v1.json
Change-Id: I2acb39f4544e2608596f8e76e10ddc516309edec
2020-05-16 03:06:19 +01:00
Reedy
1b1a17bcef skins: Allow $wgValidSkinNames to take ObjectFactory spec
Bug: T252760
Change-Id: I189de448c3b2c56dfe6bf49170d7746943cf2417
2020-05-16 01:57:25 +00:00
Reedy
aed1e72c96 registration: Move SearchMappings to CORE_ATTRIBS from NOT_ATTRIBS
Also remove SearchMappings from extension.v1.json

Bug: T250977
Change-Id: I010ac37a869ad12c4dcbe65805a19ee0662a34e3
Follows-Up: Ib9634128f07d428276e80a6f2f492b850eef17e8
2020-05-01 18:23:12 +00:00