Commit graph

11 commits

Author SHA1 Message Date
Timo Tijhof 9c5b7cef9e Improve localisation on Special:Gadgets, minor code cleanups
For each item, either display human-readable and translated text,
or display a technical non-translatable identifier as `<code>`,
with optional localised text in the title attribute.

* Re-format "rights" as a sentence instead of a bullet list. It was
  the only one using a bullet list, which made it feel a bit long.

* Re-format "actions" as `<code>` since they are not localised.

* Re-format "contentModels" as `<code>`, and add the localised display
  name in a title attribute, same as we do with "rights" already.
  ContentHandler::getLocalizedName() is also used already on
  Special:ChangeContentModel.

* Fix "contentModels" to set `needLineBreakAfter = true`, otherwise
  if a gadget also sets "supportsUrlLoad", then that sentence is
  appended to the previous line.

Update phrasing and sorting to be consistent everywhere, and adopt
native PHP types where possible.

In most cases, I made things alphabetical, with the exception of
Special:Gadgets user interface output, and Gadget class methods,
which both follow the order of most recently added feature last
(rights, skins, actions, namespaces, contentmodels, categories).

Highlights:

* Fix namespace IDs type. These can be strings when they are parsed
  from the gadget definition text, not always integers.

* Add explicit default for 'category'. In theory not needed because
  MediaWikiGadgetsDefinitionRepo has a `$section = '';` default, and
  MediaWikiGadgetsJsonRepo uses GadgetDefinitionContentHandler where
  `category: ''` is part of both the initial page content, as well
  as merged via getDefaultMetadata.

  This default benefits simpler test cases, and static analysis,
  since the Gadget class constructor does not (yet) require it.
  Without this, getCategory() could TypeError due to returning null.

Bug: T63007
Change-Id: I3b2c72a6424d520431d03761d23a5a222518ce3d
2024-03-25 15:37:40 -07:00
Sophivorus e2cb01ddcd Add support for categories in definitions
Adds a "categories" option to the gadget definition, which takes a
list of category names. Enabled gadgets will only load when the
viewed page is in one of the required categories.

Bug: T204201
Bug: T63007
Change-Id: I0ced9507bdab6cacd0baf2a331859099f35b73e5
2024-03-16 22:31:03 +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
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
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 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
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 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 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