Commit graph

155 commits

Author SHA1 Message Date
jenkins-bot f1fbefffb4 Merge "Add PreferencesGetIconHook" 2022-10-25 21:31:31 +00:00
Siddharth VP 7793a9475f Add support for ES6 gadgets, but with validation disabled
Gadgets can mark themselves as ES6-only by specifying the requiresES6
boolean attribute. Syntax validation is disabled for them (as the
validator doesn't support ES6 yet), and they are loaded together in a
separate request.

The minifier doesn't reject syntax errors, and thus these would
be passed through to web clients. Hence, communities using this feature
are encouraged to use ESLint or another linter to make sure only
valid ES <= 6 code is being used.

Because of the above, this feature is only made available for
non-default gadgets.

Bug: T75714
Change-Id: Ib98ac0700471554d5721d7ab858d4660e1e0e980
2022-10-20 22:03:18 +00:00
suecarmol 12eada5338 Add PreferencesGetIconHook
Added PreferencesGetIconHook to add an icon on the Special:Preferences section.

Bug: T317419
Depends-On: I6d5730d47e7595b1705787995fe5db2fe734d7f5
Change-Id: Ie2505622680573dfe9e50b48976c986cf2512097
2022-10-14 19:02:29 -05:00
libraryupgrader eb99f12bce build: Updating mediawiki/mediawiki-phan-config to 0.12.0
Change-Id: Ic857959b35f31be8a963e1889b6d79b54dbd3855
2022-10-09 12:06:20 +00:00
Gergő Tisza 1083062529
Purge in-process cache in MWGadgetsDefinitionRepo::handlePageUpdate
This is needed for registering gadgets for parser tests.

Change-Id: If7bf0cf63cc352566a58c20c4cf49e57c0085bb9
2022-09-01 21:41:04 -07:00
Siddharth VP 08cf009f36 Migrate usage of Database::selectFieldValues to SelectQueryBuilder
Bug: T312440
Change-Id: I4a54426667cd4c6070b0ff7953e6478dc25b96c8
2022-08-27 17:17:27 +05:30
Fomafix dda2f5a129 Remove default values for the constructor of SpecialPage
Change-Id: Ibdc2d3906f3020798cd885d6fba7e5149d1b5cdf
2022-08-08 15:44:05 +00:00
Reedy 67b8bf23d0 SpecialGadgets: Don't call explode() on null
Bug: T311557
Change-Id: I05455a309bee4a4f59dc5351484dfffc682a329a
2022-06-29 00:51:24 +00:00
Reedy 6e30b50063 MediaWikiGadgetsDefinitionRepo::loadGadgets(): Cast ttl to int
Bug: T311367
Change-Id: I4ca0d075bad91903f24906c34d1fbac915fde735
2022-06-28 19:56:01 +00:00
DannyS712 4cdb1486e3 Use new ResourceLoader namespace
Extensions using Phan need to be updated simultaneously with core due
to T308443.

Bug: T308718
Change-Id: I4cabf840fe5bfac65542a08675865b2ce3952ecc
2022-05-28 00:59:46 +00:00
Ammarpad c279d5cc36 Remove legacy handling for EditFilterMergedContent hook
Extension now requires MW 1.39

Change-Id: Ic63b6f66cec49fe72e5a291fe8d7685101324e4a
2022-04-18 05:19:30 +00:00
Fomafix b504a6f496 Use HookHandlers and implement hook interfaces
Bug: T271014
Change-Id: I50d42df04038d1214fd9835c3d3b0f602037ac62
2022-04-17 12:00:24 +00:00
jenkins-bot f77367d6a7 Merge "Rewrite and simplify MediaWikiGadgetsDefinitionRepo cache" 2022-04-06 22:51:28 +00:00
jenkins-bot 09c2ddeaf2 Merge "GadgetRepo: Fix missing purging on delete and simplify hook handling" 2022-04-06 17:33:35 +00:00
jenkins-bot 85b37dd0b1 Merge "GadgetRepo: Add or improve type hints in various methods" 2022-04-05 21:14:52 +00:00
Timo Tijhof db04e488b6 Rewrite and simplify MediaWikiGadgetsDefinitionRepo cache
* Remove most APCu logic, including the reverse checking of WANCache
  touch time to validate the APCu key
  The APCu expiry had a 7-15s blind TTL before this check took place.
  Keep the conservative part of this (blind TTL). This should be
  more than enough to debounce memcached traffic.

* Simplify WAN handling with plain key and delete (using the default
  holdoff tombstone, which should take care of edge cases like second
  DC warming up the WAN key shortly after a delete).

* Fix incorrect method doc about being by section. The returned
  list is not by section.

Change-Id: If14ff83a29367df58d1824615bcf0bcd2edc886f
2022-04-05 21:39:45 +01:00
Timo Tijhof ab753d805e GadgetRepo: Fix missing purging on delete and simplify hook handling
== Motivation ==

On a local dev wiki and in CI, where no gadgets are defined yet,
fetchStructuredList() is called on every load.php request and doing
uncached database look ups. This is because T39228 (stale cache
after Gadgets-definition was empty or created) was fixed by disabling
the cache until the page exists. This seems like a poor solution,
and commit I3092bcb162d032 recognises that the problem was not
understood at the time. I propose to instead cache it always and
purge it when the page is modified in any way.

Cold calling fetchStructuredList() accounted for ~170ms of ~400ms
when trying out debug v2 (T85805), thus making it significantly
slower and causing a chain of dozens of requests to pile up.

== Previously ==

* Legacy repo (MediaWikiGadgetsDefinitionRepo) only implemented
  handlePageUpdate.
* handlePageUpdate was called from onPageSaveComplete for both
  any page edit, and for creations in the experimental namespace.
* The experimental GadgetDefinitionNamespaceRepo is based on
  ContentHandler rather than global hooks. This system does not
  have a create-specific callback. It called update for edit/create,
  and delete for delete. The experimental repo relied on create being
  called from the global hook for the legacy repo, and update was
  then called twice.
* There was no global hook for onPageDeleteComplete, thus the
  legacy repo did not get purges.

== Changes ==

* Add onPageDeleteComplete hook to fix purges after deletion,
  with the legacy repo now implementing handlePageDeletion() and doing
  the same as handlePageUpdate().

* Fix handlePageUpdate() docs to reflect that it covers page create,
  since onPageSaveComplete() called it either way.

* Fix experimental repo to include its namespace purge in
  its handlePageUpdate() method.

* Get rid of now-redundant handlePageCreation().

* Get rid of handlePageDeletion() since its implementations would
  now be identical to handlePageUpdate().

  All these hooks and handle*() methods are just for a memc key
  holding gadget metadata. We don't need to microoptimise this
  on a per-page basis. Gadget edits are rare enough that purging them
  as a whole each time is fine. We do the same in MediaWiki core
  with ResourceLoaderGadgetsModule already.

Bug: T85805
Change-Id: Ib27fd34fbfe7a75c851602c8a93a2e3e1f2c38a0
2022-04-05 21:39:45 +01:00
Timo Tijhof f0c75c4a78 GadgetRepo: Add or improve type hints in various methods
Change-Id: Ia1a3e5a69ac02822d9062262e69e6c48325c15a0
2022-04-05 20:32:16 +01:00
gerritbot f9cd97a716 Fix usage of ApiBase::PARAM_* deprecated constants
The ones that are replaced with ParamValidator

Bug: T275455
Change-Id: I2cee8a2a6af9391baba188ebb9db10ceee4a5a52
2022-04-04 01:27:06 +02:00
jenkins-bot 24a5961f0d Merge "SpecialGadgets: Avoid setting internal fields of HTMLForm" 2022-03-31 12:46:00 +00:00
Reedy 85c05077e6 Drop global class aliases
Change-Id: I00c04f64e24454ba7b55d65803de64cbe90381eb
2022-03-29 20:39:19 +01:00
Func 3c23c202e5 SpecialGadgets: Avoid setting internal fields of HTMLForm
HTMLForm would handle title itself, don't need to set it manually here.

Depends-On: Iaec81a2fb49162f2fc764f143f88e887572a3a0b
Change-Id: I4a9788e853463e51570ba7c04a8bd40f1ed95cfa
2022-03-27 13:33:38 +08:00
jenkins-bot f9d09841cf Merge "Use RequestContext::getActionName instead of the uncached ActionFactory::getActionName" 2022-03-26 22:15:58 +00:00
Siddharth VP cb6f69103c Use RequestContext::getActionName instead of the uncached ActionFactory::getActionName
Also avoids injecting the ActionFactory service.

Change-Id: I9a26aff0d3885470d6cd376ab870023bb377ac77
2022-03-26 22:00:01 +00:00
Siddharth VP 0412a47e63 Add getSkins() in GadgetResourceLoaderModule
Overrides ResourceLoaderModule#getSkins() as introduced in core
with I08a1a59b4eab90d380ca8f874, so that skin-specific gadgets are
only registered client-side if applicable to the current skin.

Bug: T236603
Depends-On: I08a1a59b4eab90d380ca8f874bb6dbba2f399590
Change-Id: I111a67c3119a294afc093b7b64bf0927a56f5b1f
2022-03-25 00:17:02 +00:00
tacsipacsi 9f14584713 Replace span.errorbox with div.mw-message-box-error
The errorbox class will soon stop working. It and its successor
mw-message-box-error were designed to work with block elements, which
meant that its inline usage caused overlaps and partially unreadable
text above/below it. To fix this, and to be able to use the
Html::errorBox function, I switched to use block elements (<div>s).
Please note that *this causes visual changes* (see screenshots on
Phabricator), and while I tried to test it locally, I might have missed
edge cases, so do tell me if it breaks something.

Bug: T304602
Change-Id: If68b934723722f976668d08a910984f89538a4f2
2022-03-24 15:35:19 +01:00
Siddharth VP 235820d631 Add GadgetLoadConditions class
Avoids expensive re-computations such as that of Action::getActionName, for
each gadget. It is now computed just once in the GadgetLoadConditions
constructor and stored.

This structure makes it cleaner to add more conditions down the line (such as
namespaces and content models - see T204201) and could be reused for user gadgets
(T36958).

Change-Id: I8cbc4bba4d248d9f2ff3a2836450f69970370b1a
2022-03-20 22:16:07 +05:30
Alexander Vorwerk 1f40a76cc0 Bump MediaWikiGadgetsDefinitionRepo cache version
Bug: T303455
Change-Id: I32138cd8547f8c5773cbe603fdeb9826e04b0461
2022-03-09 20:32:12 +01:00
Alexander Vorwerk ba83b57d1d Bump the cache version of Gadget
Bug: T303391
Change-Id: I7f6f17de42d601e059b1b8f155a6db3dfb2c75a1
2022-03-09 14:57:57 +01:00
Reedy 2952dadb9f Add global class_alias for Gadget
Used for serialization purposes...

Change-Id: I3345ad668aa55596bc9ec18b56d9891f10bb0285
2022-03-06 01:50:36 +00:00
Reedy 01f6a6c34e Namespace extension
Bug: T278278
Change-Id: I49b57e68079c998419e235b1727eea8c121c234b
2022-03-05 17:03:35 +00:00
jenkins-bot f238e6d4e1 Merge "Avoid validating gadget definition content multiple times on save" 2022-01-26 18:24:44 +00:00
Siddharth VP bded600e36 Avoid validating gadget definition content multiple times on save
The validation appears to be occurring 4 times:
1. JsonContentHandler->preSaveTransform --> GadgetDefinitionContent->isValid
2. GadgetHooks::onEditFilterMergedContent --> GadgetDefinitionContent->validate
3. ContentHandler->validateSave --> GadgetDefinitionContent->isValid
4. RevisionStore->checkContent ---> GadgetDefinitionContent->isValid

Caching the validation result reduces it down to 2.

(Validation in GadgetHooks::onEditFilterMergedContent is to provide a more useful error message than what ContentHandler gives – which is just "Invalid content data".)

Change-Id: I026751b7e9b111b4f0bb9ab5fa0e9737a0385b07
2022-01-26 15:39:14 +05:30
jenkins-bot de2ed9219f Merge "Restrict ?withgadget query parameter to opt-in gadgets." 2022-01-24 00:46:10 +00:00
Ammarpad 5d3a547c8b Restrict ?withgadget query parameter to opt-in gadgets.
?withgadget query parameters allows for ad-hoc loading of gadgets
(after passing all other basic checks). This was recently added in
I5b30d4e.

In T29766#7611796 Gergo raised concerns about how this can be
potentially abused.

This patch aims to restrict the feature by giving gadgets latitude
to either use it or not depending on the nature of the gadget.

The patch does so by adding `supportsUrlLoad` option that gadgets
(maybe those deemed safe) can use it to opt-in to the parameter.
By default gadgets don't support it, so it can be enabled for each
on a case-by-case basis.

Bug: T29766
Change-Id: Ie64174085e650579d76cc862774a4fe1b3d08396
2022-01-24 00:31:19 +00:00
C. Scott Ananian 165a030a4c Passing a string to ParserOutput::addModules()/addModuleStyles() is deprecated
In addition, renamed several instance of $output to $parserOutput to
help readers (and code search!) differentiate between variables which
contain a ParserOutput and those which contain an OutputPage (esp.
since those two classes contain many similarly-named methods).

Bug: T296123
Change-Id: If34330acf97d2c4e357b693b086264a718738fb1
2022-01-20 13:12:33 -05:00
jenkins-bot 6fb18ae1fb Merge "Tighten some type hints" 2022-01-20 02:03:10 +00:00
Bartosz Dziewoński 4e27ab0e01 Tighten some type hints
* Gadget::isEnabled() only requires a UserIdentity, not the whole User
* Gadget::isAllowed() only requires an Authority, not the whole User

Both of those interfaces are implemented by the User class, so this is
compatible with all existing code, and it's easier to call from code
that only has access to a UserIdentity/Authority.

Change-Id: I8ea710c555f6fb7790ae575bb60aab1a05e288d8
2022-01-19 23:30:40 +00:00
jenkins-bot 1cd6771f3a Merge "Avoid raising exception while trying to change content model of gadget definition" 2022-01-18 21:18:22 +00:00
jenkins-bot d883cfefe4 Merge "Avoid adding hidden gadgets in default options" 2022-01-17 05:39:56 +00:00
Siddharth VP f1673c441a Avoid raising exception while trying to change content model of gadget definition
Currently, trying to change content model of a page in gadget definition namespace (via either the special page or the API) raises an exception. This uncaught exception has been replaced with a localisable error message.

Bug: T299303
Change-Id: Iad7d353d03cdfb52bf66aa2c9a12bc71a840577c
2022-01-16 22:43:37 +05:30
Siddharth VP 43efda4f96 Avoid adding hidden gadgets in default options
Hidden gadgets do not have associated user preferences. Adding them to $defaultOptions only causes them to be unnecessarily exported in mw.user.options.

Bug: T299071
Change-Id: Ic55e7f2a9daa405cddd0189de3d32f5825bc336a
2022-01-14 09:23:30 +05:30
Kunal Mehta 44d3602898 Link entries on Gadget definition pages
Links the following entries in gadget definitions to the associated page:
- scripts
- styles
- datas
- peers
- dependencies (only when they are also a gadget)
- category (links to MW message page)
- messages

unserialize(serialize()) hack is a bit ugly, but it works.

Co-Authored-By: Siddharth VP <siddharthvp@gmail.com>
Bug: T298844
Change-Id: I9154f600997fe693410e7560ed30732102b806aa
2022-01-12 19:33:04 +05:30
Gergő Tisza 6b74e170c0
Add edit link to gadget definition in Special:Gadgets
When using the Gadget definition: namespace, link to the definition
pages from Special:Gadgets. Also change the wording of the links
to edit the names of the gadgets, to disambiguate them.

Change-Id: I327a4cfa9846edec60e1aaafc674cd66f4e0beae
2021-12-31 20:42:37 -08:00
Siddharth VP 7ead5dab61 Allow specifying page actions in definitions
Allow specifying page actions ('view', 'edit', 'history', etc) in
gadget definitions. If specified, the gadget is run only on the given
page action(s).

This is especially useful for default gadgets like RefToolbar[1] and
TextReactions[2] that only need to be loaded while editing.

[1]: https://en.wikipedia.org/wiki/WP:RefToolbar
[2]: https://en.wikipedia.org/wiki/WP:Text_reactions

Bug: T204201
Bug: T63007
Change-Id: Idde71b3f1f6c36cd21539a2312be8f12217a9acc
2022-01-01 00:41:08 +05:30
Siddharth VP 1f7b9d90df Support JSON files in gadgets
The parsed content of JSON files in the gadget is made available from the
gadget's JS files via require(). That is, MediaWiki:Gadget-data.json (or
Gadget:data.json) is available as `require('./data.json')`. This is
supported for both MediaWikiGadgetsDefinitionRepo and
GadgetDefinitionNamespaceRepo. The JSON parsing is done server-side.

JSON can only be used in "package" gadgets - in which the JS files can
also be invoked via require().

Also added a test for GadgetResourceLoaderModule.

Bug: T198758
Depends-On: Ib4556d09c4d393269e32771aab00f59a5f630e1b
Depends-On: Id4589a597ccfc4266b3e63d10f75b146aa7a287a
Change-Id: I21acb46cdd244a39b5cc6963aa763f0113bd1e38
2021-12-27 17:33:21 +00:00
jenkins-bot 0010b1802b Merge "Add global 'withgadget' query parameter for ad-hoc loading of gadgets" 2021-12-15 07:47:25 +00:00
vladshapik b3524efe41 Avoid using User::getOption
Remove using of User:getOption since this method
will be hard-deprecated. Now it is soft-deprecated.

Bug: T296083
Change-Id: I140cbd5655ac4ae0ad7b6d30c5e6bae0008aba07
2021-11-26 12:27:39 +01:00
Bartosz Dziewoński ea786ce9dc Re-apply "Make each gadget a separate preference, instead of one huge multiselect"
Previously attempted in 82281d82d0,
reverted in 7c4ac597e2.

This gives each section and each gadget's entry an `id` attribute,
which can be used for linking, as requested in T126962. Existing user
options still match the new preferences.

It also probably makes future improvements easier. No one understands
multiselects with subsections.

Bug: T126962
Change-Id: Ie96fd94c994d05ab8507920fa560c7ed9c1f9b69
2021-11-05 23:15:45 +01:00
Siddharth VP 14af941e88 Add global 'withgadget' query parameter for ad-hoc loading of gadgets
When viewing pages, the 'withgadget=' query parameter can be used in
the URL to load a gadget that isn't enabled by the user's preferences.

The gadget is only loaded if all other conditions are still satisfied
(supported skin, supported targets, required user rights).

Bug: T29766
Change-Id: I5b30d4e0010561685eef661a515e2892045bb776
2021-10-16 03:14:34 +00:00