Commit graph

124 commits

Author SHA1 Message Date
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
Umherirrender 6132dbae64 Remove PHP 5.3 $this closure workaround
Change-Id: Ib1f2808a9e0d9c93b2b598fd07e0f2a61c122f2a
2021-05-15 01:57:51 +02:00
jenkins-bot 0c5539d437 Merge "Do not use SpecialPage::getConfig in constructor on Special:GadgetUsage" 2021-05-04 20:50:02 +00:00
libraryupgrader c3c98c1146 build: Updating composer dependencies
* mediawiki/mediawiki-codesniffer: 35.0.0 → 36.0.0
* php-parallel-lint/php-parallel-lint: 1.2.0 → 1.3.0

Change-Id: I5e0b9e78f0436355cc21dc356fb78e96e59cb536
2021-05-04 18:43:54 +00:00
Umherirrender b0cc049a4f Do not use SpecialPage::getConfig in constructor on Special:GadgetUsage
The context source is not set at this point and the global request is
used and logged:
SpecialPage::getContext called and $mContext is null. Using
RequestContext::getMain(); for sanity

Change-Id: I50f96f8e6517ec7221c4b82872208787af63e12b
2021-04-30 16:28:20 +00:00
Func fb7ac5619b Handle EditFilterMergedContent hook properly to display error message
On mediawiki version 1.36 and before, just returning false in this hook can't display error message by default.
Set $status->value manually still to provide backward compatibility.

Bug: T280312
Change-Id: Ic80fd227668794c21299a3f7879f61a20a2f55bd
2021-04-24 01:52:58 +00:00
Jforrester b50309db2c Revert "Reduce message parse in GadgetHooks::getPreferences"
This reverts commit 662c63882c.

Reason for revert: plain() is too plain for our needs, sadly.

Change-Id: I1cf3c7c61e9e90567587350639590691add1af34
2021-04-21 21:55:32 +00:00
Umherirrender 662c63882c Reduce message parse in GadgetHooks::getPreferences
Multiselect can build by message keys only

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

Bug: T58633
Bug: T278650
Depends-On: Ie983757081dc39f3685ba5b01b02bd124880e1af
Change-Id: Iccd6202c443bd699aa3a911c8ba36a2b7bcdcfed
2021-04-20 18:49:19 +00:00
Umherirrender ab552f3e2d Use ::class for class name
Change-Id: I31900653180fa9667ac119fefaf1ea1c33aa2c83
2021-04-08 20:34:17 +02:00
James D. Forrester c5dddba954 Drop MW <= 1.34 compatibility
As a Wikimedia-deployed extension, we don't keep B/C for older MW branches,
instead people should use the release branches.

Change-Id: I8b8e554a8a8663c19ce3ea52f047c8d40537b042
2021-03-24 14:22:11 -07:00
sahil 5ceabd7219 Fixed typo "paramaters"
Changed from paramaters to parameters in extensions / Gadgets

Bug: T201491
Change-Id: Ib5e85d64796d70cf58a068116e211e3c1c73470d
2021-03-10 22:24:24 +05:30
Petr Pchelko 7f124b8874 Don't pass empty permissions to Authority::isAllowed
Bug: T271459
Change-Id: Iebf2dca34eea751391d9740443c195287399aa5c
2021-01-19 15:15:45 -06:00
Umherirrender 4de4305c6c Add missing @var and improve documentation
Change-Id: Ib258665c3fe76eeadd32f949fe01d88e6f2fd70d
2020-12-18 00:21:49 +01:00
libraryupgrader 5fc41bb340 build: Updating mediawiki/mediawiki-codesniffer to 32.0.0
The following sniffs are failing and were disabled:
* MediaWiki.Commenting.FunctionComment.ObjectTypeHintParam
* MediaWiki.Commenting.PropertyDocumentation.MissingDocumentationPrivate
* MediaWiki.Commenting.PropertyDocumentation.MissingVar
* MediaWiki.Usage.ExtendClassUsage.FunctionConfigUsage

Additional changes:
* Dropped .inc files from .phpcs.xml (T200956).
* Added the `wikimedia/mediawiki` profile in .eslintrc.json (T262222).

Change-Id: I73a5f722738dff75c623cf631bfa7e3dcf8d6f82
2020-10-29 13:34:25 +00:00
zoranzoki21 a66f0f7baa Fix MediaWiki.Commenting.FunctionComment.MissingDocumentationPrivate
In ApiQueryGadgetCategories.php for function getList() I've added inline comment for ignoring this rule, because is unclear why it throws this error.

Change-Id: I74c4a6c75f48b8f7a237396666db3b37993c300d
2020-10-12 15:26:23 +00:00
zoranzoki21 bc5b58d736 Fix MediaWiki.Commenting.FunctionComment.MissingDocumentationProtected
Change-Id: I26209fd4fd44917733e2b34e34dea31ec0d95341
2020-10-12 11:10:15 +02:00
Ammar Abdulhamid 146545919d Remove usage of Skin::getSkinNames()
Bug: T257993
Change-Id: Icc945ce1e3287a3b25152702818e5b2a90232677
2020-08-26 07:54:17 +01:00
DannyS712 f5ecc23c17 Update hooks to use PageSaveComplete hook in MW 1.35+
Bug: T250566
Change-Id: Ieccc1cae8c4b53a582391066a1a6336eae6c9277
2020-06-25 22:50:05 +00:00
Reedy 3ce0a0fb38 Fix PSR12.Properties.ConstantVisibility.NotFound
Bug: T253169
Change-Id: I17a7f0195dd0a419ae8afe46521dd8f061ba53c6
2020-05-20 00:13:16 +00:00
DannyS712 3f00fbb5aa Remove use of Revision::newFromTitle
Bug: T249183
Change-Id: Ibfcb8d7e56f559f3fb5179bac4dfeade8da22533
2020-04-08 12:44:29 +00:00