Commit graph

175 commits

Author SHA1 Message Date
Timo Tijhof d12bf68c25 docs: Make PHP file headers more consistent
* A fixed license header for the file.

* Move class descriptions, doc tags, author/copyright to the
  class block. Remove MW-core specific "ingroup" tags such as
  "SpecialPage" which has no meaning in an extension and are not
  used by Doxygen.
  Ref https://gerrit.wikimedia.org/r/q/message:ingroup

Change-Id: I13d9b0ff7a3150180196c9fa58f8a321b14edd22
2023-10-30 18:10:58 -04:00
Siddharth VP a7309d2b1f Namespace special page classes
Change-Id: I005f6674c9cc80c5c9e26ae84acfbceebb43734e
2023-10-30 21:13:41 +05:30
Siddharth VP 72cbb64069 Add support for content models in definitions
Adds a contentModels option to gadget definitions to restrict gadgets to
run in pages of the given content models only.

Use-cases include gadgets for tabular data[1] (for Tabular
.JsonConfig model), for editing map data[2] (for Map.JsonConfig model),
and for showing links in code pages[3] (restricted to javascript, css,
json, and scribunto models), as well as common gadgets like ProveIt[4]
which can be restricted to wikitext model.

[1]: https://commons.wikimedia.org/wiki/MediaWiki:Gadget-TabularImportExport.js
[2]: https://fr.wikipedia.org/wiki/MediaWiki:Gadget-KartoEditor.js
[3]: https://en.wiktionary.org/wiki/MediaWiki:Gadget-CodeLinks.js
[4]: https://commons.wikimedia.org/wiki/Help:Gadget-ProveIt

Bug: T204201
Bug: T63007
Change-Id: I7dcfc21d674ead8d710e7f77d13bf18bcad15079
2023-09-21 22:27:22 +05:30
brandonxlf ec69cea0e3 Add support for namespaces in definitions
Adds a "namespaces" option to the gadget definition, which takes a
list of namespace IDs. Enabled gadgets will only load when the
viewed page is in one of the required namespaces.

Bug: T204201
Bug: T63007
Change-Id: I7f797e35352b242ad78704074e98c6569a1adf91
2023-09-20 14:50:33 -07:00
Timo Tijhof 5aaa843a28 tests: Enforce parity between Gadget::serializeDefinition and toArray
Follows-up 087ab65e24 (Ieae6706537). To avoid silent mistakes such
as during development of T63007 (I7f797e35352b242).

Bug: T303194
Change-Id: If675f8d02ed3fee768af3d2b4912249319ae9ef4
2023-09-20 14:41:33 -07:00
Dringsim e292854740 Hide gadgets on Special:Preferences when forcesafemode=true
See https://gerrit.wikimedia.org/r/c/mediawiki/core/+/940156/comments/bdd88839_f9bdd28a

Bug: T342347
Depends-On: I6f2d024c01cdb1d7305ff024996175eb2656d0a8
Change-Id: Ia72bb33a3fd559cd5a30a44f736b0d3040843323
2023-09-08 17:15:15 +00:00
jsn 929bfc6404 Preserve Gadget prefs when they can't be enabled
- Always define gadget enable/disable preferences
- Show a gadget's preference when it can be enabled

Bug: T341421
Change-Id: If32eecebccf2c9b557d7dde273b7faf7118a7ac3
2023-09-06 19:32:31 -05:00
gerritbot b9da596fe8 Replace some moved Title class uses, now MediaWiki\Title\Title
Bug: T321681
Change-Id: I9b9c59a564e81daf01bb99d48dc81c9357e94acc
2023-08-19 04:15:51 +00:00
Umherirrender 7f95440c4d Use HookHandlers for CodeEditor hook
This requires 1.41 for the interface (added in 4d6a470a)

Bug: T271014
Change-Id: Ic486f44bd9215ac7dad5bc70d7dca1e9aad470de
2023-08-16 05:30:40 +00:00
Umherirrender c800299653 i18n: Split apihelp for parameter list=gadgets/gadgetcategories prop=
Easier to translate
There is no visible change on Special:ApiHelp/query+gadgets

Also split for list=gadgetcategories&gcprop=
Visible on Special:ApiHelp/query+gadgetcategories

Bug: T285545
Change-Id: Ic40326cd747ffe2153cff7d10e0083bd5e51345e
2023-08-05 01:47:04 +02:00
Daimona Eaytoy 76522d5c66 Avoid loading gadgets if the storage backend is disabled in tests
This method is possibly the main cause of DB access in non-database
tests, because it's called from the UserGetDefaultOptions hook handler,
which is triggered by most tests using UserOptionsLookup in any way.

Trying to obtain a DB connection will throw an exception in I96ecf9ff,
so just skip the lookup altogether.

Bug: T155147
Change-Id: I2ac659a472655b2a95e64dcbd3f709e465839b33
2023-07-29 14:42:56 +02:00
Ed Sanders d09c3fac78 Use strict equality with in_array
Change-Id: I09ebdf0dae540195d5bfcebf32b1e6dd22ff11c5
2023-07-24 18:41:00 +01:00
Ed Sanders 9b6cfa97a0 SpecialGadgets: Remove incorrect comment and test for $requiredSkins being true
$requiredSkins is always an array

Change-Id: I91bade025a9581c33b99f986e9497299483b8b59
2023-07-24 13:36:59 +01:00
Siddharth VP 6d1ffbac15 Fix field name in schema.json
Change-Id: I7a89afe2876a1530cceb4884c8fdce348f8d6620
2023-07-08 21:13:26 +05:30
Ed Sanders f5466fca49 Use strict equality
Change-Id: Iccb15b405a6959238ba4f924ca4ec907e29a9ebf
2023-07-01 14:27:10 +01:00
Jon Robson 8af75aa6e5 Gadget maintains its own version of targets system
The ResourceLoader module associated with the gadget will have
mobile and desktop targets, but this allows gadgets to disable
themselves on the mobile site if necessary by not adding the gadget
to the page if it's been marked as such.

This also has the benefit of not showing the gadget on the preferences
page if it's not relevant.

Bug: T328610
Change-Id: I4f2b57d1d22f641ff7520358a46cd0e6b2103aa9
2023-06-29 16:20:29 -07:00
Siddharth VP 087ab65e24 Avoid caching serialized PHP object
Cache array representation of the Gadget object instead of the
php-serialized representation. Gadget::toArray() is an inverse of the
constructor which already constructs an object from an array of config
values.

Also, the static Gadget::newFromDefinitionContent method which accesses
the service container is replaced with the dependency-less
serializeDefinition() method.

Bug: T303194
Change-Id: Ieae6706537143d766777b2299c31726e2a1dfd29
2023-06-22 06:01:28 +00:00
Jon Robson 58463ce97c Gadgets should default to mobile and desktop targets
The targets system is being deprecated.

Bug: T127268
Bug: T340046
Change-Id: I69d11d52238ac852534cb9a4555208a0b0bb5fd7
2023-06-21 15:36:39 +00:00
Daimona Eaytoy 2912cd3477 Remove mention to deprecated MWException
The class is deprecated and RL will likely stop using it. And even then, this method shouldn't care. The exception is unchecked, so whatever its type is, it's just an implementation detail.

Bug: T328220
Change-Id: I3c87a376ce1d36f4a1d81a435bbc015199c75913
2023-06-07 15:58:45 +00:00
lens0021 c93bce31be
Add missing targets option
Bug: T303681
Change-Id: Id0d5f4e8fc1477e3322c0bc24b17b83ff9d0c6b3
2023-03-06 16:46:37 +09:00
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