Commit graph

143 commits

Author SHA1 Message Date
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
Reedy 32677ff590 Various code cleanup
Change-Id: I59b7ac50b621df1da402752327841743141944e3
2021-10-09 01:34:45 +01:00
jenkins-bot 669b351241 Merge "Override ContentHandler::fillParserOutput instead of Content::fillParserOutput." 2021-10-08 14:32:36 +00:00
jenkins-bot 0a55c5f0f9 Merge "Revert "Make each gadget a separate preference, instead of one huge multiselect"" 2021-10-07 20:11:30 +00:00
Krinkle 7c4ac597e2 Revert "Make each gadget a separate preference, instead of one huge multiselect"
This reverts commit 82281d82d0.

Bug: T126962
Bug: T292777
Change-Id: I7c858b8c4bc12626ea1d53374ea4d75862f684ff
2021-10-07 19:52:18 +00:00
Roman Stolar cbad567396 Override ContentHandler::fillParserOutput instead of Content::fillParserOutput.
Prepare override for GadgetDefinitionContentHandler, remove usage in GadgetDefinitionContent.

Bug: T287158
Change-Id: Icc3fa02f7089eaccd2dad8ff28f3db8cbf8eac03
2021-10-07 13:09:05 +03:00
jenkins-bot 1d3af2d82b Merge "Add all gadgets to DefaultUserOptions" 2021-10-06 23:59:58 +00:00
Bartosz Dziewoński 82281d82d0 Make each gadget a separate preference, instead of one huge multiselect
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: Ifaca96e288c475017636c2408712d6a20aa77da9
2021-09-30 18:39:41 +02:00
Umherirrender d175e964db Add all gadgets to DefaultUserOptions
Without the default the preference is never deleted from the database,
even it was disabled by the user.

Bug: T291748
Change-Id: I1010e260fda118cbea83ad39e33055e403e37630
2021-09-29 08:19:16 +00:00
Jayprakash12345 1472a2733c Use getText() instead of getNativeData()
Bug: T283673
Bug: T155582
Change-Id: Iaf8a0ded40e3303d6fbcfac022b1461c4d2b1333
2021-08-04 02:43:36 +00:00
Roman Stolar ffa6b4de09 Override ContentHandler::getDeletionUpdates and ContentHandler::getSecondaryDataUpdates.
Use it instead of Content::getDeletionUpdates and Content::getSecondaryDataUpdates.

Bug: T285730
Bug: T285729
Change-Id: Ie4ea0917f120809be59e2b7afad51cd189d64dd1
2021-07-16 12:46:41 +02:00
jenkins-bot d18d79ac7f Merge "Handle EditFilterMergedContent hook properly to display error message" 2021-06-26 12:00:21 +00:00
Umherirrender e9f6ea3492 Reduce message parse in GadgetHooks::getPreferences (second time)
Multiselect can build by message keys only and allows to parse them.

This reverts fix for T32182, there is no way to handle the dir on each
item/checkbox at the moment

Reintroduce Iccd6202c443bd699aa3a911c8ba36a2b7bcdcfed (reverted by
I1cf3c7c61e9e90567587350639590691add1af34)

Bug: T58633
Bug: T278650
Depends-On: I8f52f21ae2641ddcad1aa85ce6bf14de1a09ab4b
Change-Id: If71008195f58faff9f302f7ea2bf9dbb1a527844
2021-05-28 20:52:58 +02:00