Commit graph

214 commits

Author SHA1 Message Date
Timo Tijhof a8c3eb1282 Move "gadgets" message to "special-gadgets"
This makes way for "MediaWiki:Gadgets/<id>.json" to be used free of
any confusion or misinterpretation about the subpage being a
translation of "MediaWiki:Gadgets".

Change-Id: Icb68ce6c26a83d7201a97a5406f8752b3c5b0855
2024-02-09 19:10:54 +00:00
jenkins-bot c6b47d5bfd Merge "Follow-Up 27f913cc96: Drop complicated MobileContext injection, now unused" 2024-02-07 18:15:34 +00:00
Reedy 1b2a84aaff Gadget: Bump GADGET_CLASS_VERSION
Bug: T356322
Follows-Up: If6d742ea719e4c8db9d915e8297d915d2150ef50
Change-Id: Id5f60e054304e6a715f0f54d11fd2f467fe4c5c7
2024-01-31 19:37:07 +00:00
James D. Forrester 9d6b0e8206 Follow-Up 27f913cc96: Drop complicated MobileContext injection, now unused
Change-Id: I8b32abd4bcc0b588972c65956d08c4b29bf6b4aa
2024-01-26 12:48:18 -05:00
James D. Forrester 27f913cc96 Drop RL targets definitions from module class, and validation / error code
Bug: T328497
Change-Id: If6d742ea719e4c8db9d915e8297d915d2150ef50
2024-01-24 12:11:20 -05:00
Novem Linguae cc22098a48 Make Special:Gadgets [Edit description] link smaller
To match the style of section [edit] links in articles.

Bug: T344489
Change-Id: Ic3fd864a7b2889ba246418d4a781fd8db29f5ce9
2024-01-18 16:49:16 -08:00
Novem Linguae 5b656b1ee9 SpecialGadgets: refactor
Improve code grouping and comments.

Change-Id: I67fd8081fb5e47bd5a13c85b68433d9a90b67c05
2024-01-18 16:44:43 -08:00
jenkins-bot da62832dde Merge "SpecialGadgets: better variable names" 2024-01-18 23:21:01 +00:00
jenkins-bot 4ca73e1556 Merge "SpecialGadgets: convert Xml class to Html class" 2024-01-17 18:08:04 +00:00
Novem Linguae e62314d4ba SpecialGadgets: fix docblock type mistake
Change-Id: I1716c0c4b74ec34d6b8b69316fb397aa1de3b8bc
2024-01-17 08:02:14 -08:00
Novem Linguae 209c626d66 SpecialGadgets: better variable names
Change-Id: I515d4016a3cb4a9eeb2488a39afa2b5d48a2dc48
2024-01-17 07:59:17 -08:00
Novem Linguae eeb4740fbc SpecialGadgets: convert Xml class to Html class
Change-Id: I8a24789a11ad5f494dc0f9a87642b1b79b40fd3b
2024-01-17 07:50:21 -08:00
jenkins-bot 50d2405a43 Merge "Add validations for skins and rights" 2024-01-11 17:03:15 +00:00
Siddharth VP b944152d3a Add validations for skins and rights
Bug: T298334
Change-Id: If32b334f331845eab6c115f40f8dcf4534028c9c
2024-01-11 10:02:40 +05:30
Timo Tijhof 1448500c2a Avoid global RequestContext in GadgetRep::validationWarnings()
This already returns safe Message objects, which allow Special:Gadgets
to localise it accordingly.

Avoid formatting the list ahead of time with a hardcoded user language,
and instead use Message::listParam() so that the caller controls
the Language object. This makes it safe to use in jobs, CLI, tests,
load.php and elsewhere instead of previously where RequestContext would
cause an exception or use something the caller doesn't control.

Bug: T298334
Change-Id: I77dd3c7fef86b4c8c41837bfb276b019f30baeb0
2024-01-09 21:05:18 +00:00
jenkins-bot cc4efec689 Merge "Avoid persisting default gadget configs in definitions" 2024-01-09 17:27:16 +00:00
jenkins-bot 47c360c47a Merge "Expand pre-save validations for JSON definition pages" 2024-01-09 06:07:27 +00:00
Siddharth VP 41af49e9b5 Expand pre-save validations for JSON definition pages
* Validate that pages have .js, .css or .json suffixes.
* Validate that namespaces are integers, disallowing doubles.
* Validate that type is either general or styles.
* Validate that targets are either desktop or mobile.
* Fix validation of skins: stop allowing `true` as it isn't actually
allowed - it causes an exception in Gadget::isSkinSupported().

Bug: T298334
Change-Id: Ic59c20172f496d281acd59419f5c760ad29ce317
2024-01-08 20:04:12 +00:00
Umherirrender dc84f149bc SpecialGadgetUsage: Fix query for postgres (and improve for mariadb)
The column user_properties.up_value is a text based type in all rdbms.
postgres does not autoconvert strings to numbers, so SUM( up_value )
gives an error when running on postgres.
The use of SUM( up_value ) is also problematic on mariadb/sqlite, as
up_value can be set to any number via the Action API's options module.
This value goes into the sum and produce a wrong result. Using a
non-number value allows to remove the value from the sum and that also
produce a wrong result.

Change the query to exclude the rows which disables a gadget and just
count the "active" ones. Typically there are only rows to disable a
gadget, when the gadget is marked as default, but default gadget are
displayed with the message 'gadgetusage-default' and does not needs to
be counted. In case a gadget was default in the past, there could always
such rows, so be safe and exclude them. That means it is safe to only
count for "active" gadget option usage.
This also allows to remove the up_value condition on the join to
querycachetwo as only rows to enable a gadget are now selected and get
joined to find the active users.

For the join condition use an assoc array, as for database condition the
database class is quoting the value of that array, if that is a string.
In postgres the " is used to quote columns or tables, but not values,
that gives a query error on postgres about the condition.
fixed when using the array style and not "raw" sql.

Define the condition only once as it should be the same for both
queries. Use the new IDatabase::expr function to write that sql piece.

Change-Id: I8dfc3fd5adc4c4bdabceaab20c4b37ffd48e6bee
2024-01-08 18:59:45 +01:00
Umherirrender 1afd0a6e02 Use namespaced classes
This requires 1.42 for some new names

Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Iacbea33299995c537a7ef77b524614ad02c6a559
2024-01-06 17:45:07 +01:00
jenkins-bot 95e524ffe7 Merge "Fix parsing logic when comments or hidden characters are present" 2024-01-06 16:22:33 +00:00
Siddharth VP 18204a4b0d Fix parsing logic when comments or hidden characters are present
0c61a5a468 subtly affected the
gadget definition parsing, causing issues with definitions containing
HTML comments or certain kinds of whitespace characters. They would get
saved to the pages array with a trailing whitespace but
Gadget::getScripts() would only return pages strictly ending in `.js`.

Trimming the title before in MediaWikiGadgetsDefinitionRepo fixes the
issue.

Bug: T354385
Change-Id: Iacee432756006060217981a534434fd455285793
2024-01-06 11:09:29 +05:30
Timo Tijhof 3e871f2015 tests: Improve validateScriptFile coverage and tolerate valid ES6
Remove the test that expects ES6 to fail by default, instead assert
that invalid syntax fails (as it should). Also add various other
test cases, including a commented-out test for valid ES6 by default,
to be enabled after Ie309e761f8b20640f7c0 in MediaWiki core.

Change-Id: If45856c563518255189687e3b1f620973349fb27
2024-01-05 21:48:58 +00:00
jenkins-bot be19375262 Merge "Specify all source pages in a single array in JSON definitions" 2023-12-29 11:08:02 +00:00
Siddharth VP 05cc93b9be Avoid persisting default gadget configs in definitions
Bug: T331222
Change-Id: I022a66267fd01efdfdc86cf0b21d3a0aaf7e5950
2023-12-16 14:31:09 +05:30
Siddharth VP 0c61a5a468 Specify all source pages in a single array in JSON definitions
As this repo is not used anywhere in production, there is no backward
compatibility. Any scripts, styles, datas specified in existing
definition pages will get ignored.

Gadget::getJSON() no longer checks isPackaged() – that is now left
for callers - only relevant one is in GadgetRLModule. That was done
because validationWarnings() method needs the JSON page list even for
non-package gadgets.

Bug: T353174
Change-Id: Ic820bc4632981369c72f822fb8b9b7195930eaa6
2023-12-16 14:31:09 +05:30
Novem Linguae 868c3c10d5 Special:GadgetUsage "Gadget" column now wikilinks to Special:Gadgets
A little efficiency to make getting from Special:GadgetUsage
to the relevant gadget files easier.

Bug: T344255
Change-Id: I0e26d10992bc3f8073bcdc8dbac86726ee6f7c36
2023-12-15 05:29:06 -08:00
jenkins-bot a3a1ea918e Merge "Remove redundant data updates for GadgetDefinitionNamespaceRepo" 2023-12-14 02:23:23 +00:00
Siddharth VP 8695a4ee1a Remove redundant data updates for GadgetDefinitionNamespaceRepo
Remove DefinitionDeletionUpdate and DefinitionSecondaryDataUpdate –
both call $repo->handlePageUpdate() which is already being called from
onPageSaveComplete/onPageDeleteComplete hooks.

The chain that made this redundant:

1. Ibe2e26d123, change hooks from hardcoded to GadgetRepo singleton.
2. Ieccc1cae8c, migrate from create-only onPageContentInsertComplete
   hook to create-and-edit onPageSaveComplete hook.
3. Ib27fd34fbf, further consolidate handling of create and edit
   events with handlePageUpdate, and remove any hook-level
   conditionals. At this point, the DateUpdate classes became redundant.

Bug: T31272
Change-Id: I20c2759b219c80571237a73e8422f3128047eb87
2023-12-14 02:03:44 +00:00
Siddharth VP 34a1a297c2 Make repo configuration independent of ObjectFactory specs
Replace $wgGadgetsRepoClass with $wgGadgetsRepo.

Change-Id: I3dc1e29d1c3c65a18c206e7aa50e5bf31a55cc21
2023-12-12 13:15:31 +00:00
Siddharth VP ce486be160 Further expand test coverage
* Separate out tests for MediaWikiGadgetsDefinitionRepo and
Hooks::onGetPreferences. Removed hack in fetchStructuredList() for
overriding page content for tests.
* Add tests for ES6 gadgets. For this, ResourceLoaderModuleTest is
converted back to an integration test.
* Removed createGadgetDefinitionPage() test helper method. Now using
MediaWikiIntegrationTestCase::editPage().
* Fixed GDNamespaceRepoTest failure when GDNamespaceRepo is the active
repo, by clearing WAN process cache.

Change-Id: I26b84576a91f6cb0ebae64c5fc1408666d767911
2023-12-09 09:29:15 +05:30
Siddharth VP d12f0f366a Expand test coverage
* Add tests for onBeforePageDisplay hook. A simple gadget repo
  implementation, StaticGadgetRepo, is introduced for this.
* Add integrations tests for various gadget load conditions.
* Add test for onUserGetDefaultOptions hook.
* Add tests for GadgetDefinitionNamespaceRepo.
* Convert ResourceLoaderModuleTest to a unit test.

Change-Id: I275380c2bfcaa44770b3946a0a468eaaabef70c0
2023-12-06 09:18:09 +05:30
Siddharth VP 9d11216d4b Inject services into Hooks
Change-Id: I042d6f33f9ecd2573f25e737bb0ee9a43869eeac
2023-12-06 09:18:09 +05:30
jenkins-bot 9ad0cf1a5a Merge "Make GadgetRepo a service" 2023-12-06 00:48:51 +00:00
Siddharth VP 22752225a1 Make GadgetRepo a service
Turn GadgetRepo into a service, deprecate GadgetRepo::singleton()

Change-Id: I0ab14ca936eec1eead91d4eb0970f898628c8388
2023-12-05 17:38:41 -06:00
Siddharth VP bf1d6b3e93 Remove gadgets-edit right, use core editsite{css,js,json} rights instead
With GadgetDefinitionNamespaceRepo, there should be separate rights for
editing gadget json as opposed to editing gadget css/js, so that admins
can be granted the former, while the latter remains restricted to
int-admins.

Reusing the MW core rights for site CSS/JS/JSON seems to make the most
sense here. Protection is now applied via GetUserPermissionsErrors hook
rather than as namespace protection.

For editing any non-CSS/JS/JSON pages in the namespace, editsitejs right
is required.

Bug: T298834
Change-Id: I6ffd5e9467774f1e79ccdce8b6b4739f07be2da8
2023-12-05 20:37:59 +05:30
Siddharth VP adda8a6649 Show gadget definition validation warnings in Special:Gadgets
Bug: T298334
Change-Id: Id241125b9b8abfb971dfa600ab0df9c6047f2b32
2023-11-30 21:59:04 +00:00
thiemowmde c4680366ac Various PHP code cleanups
… e.g. using modern syntax, or avoiding unnecessarily complex
language features. For example, we don't need to call count() when
all we care about is the boolean "is empty/not empty" information.

Change-Id: I13ae802f64627a79b29d1e57ad71486cb2fb977f
2023-11-22 09:53:48 +01:00
thiemowmde ba496f7f4a Remove meaningless trim() from MediaWikiGadgetsDefinitionRepo
This can't do anything for two reasons:
* There are no spaces in the string after the str_replace. There is
  nothing to trim.
* The regular expression above guarantees the string starts and ends
  with alphanumeric characters. There can't be anything to trim, not
  even underscores.

Change-Id: Iea40aafaa2457cdee9d05f105978627d38d9d5b8
2023-11-20 13:44:08 +01:00
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