Commit graph

192 commits

Author SHA1 Message Date
Umherirrender fb52519d7c Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: I813e0d8fb266474eab5ad59ba33f6cd089099212
2024-10-20 13:20:47 +02:00
Umherirrender ebcc8ac7c5 Use new namespace for OutputPageBeforeHTMLHook
Change-Id: I7cb4a8db2d8473757434eff9476af62e310f91ad
2024-06-10 22:00:02 +02:00
Fomafix 9485ab50c4 Use namespaced PHP classes
Change-Id: I9f3a45c2d1ce4b7d7c5bb4bbbe382d32d47ee342
2024-06-07 09:08:55 +00:00
jenkins-bot 0f21a4b375 Merge "Simplify normalization of "params" key" 2024-05-17 19:34:33 +00:00
thiemowmde db9c989e10 Simplify normalization of "params" key
The isset() check was odd and confusing. I think I added it in
Ie572809 to be able to run the normalizer independend from the
validator. But the "params" element is required anyway. It makes
much more sense to enforce it in the normalizer as well. Even if
this currently doesn't make a difference in real-world scenarios,
it makes the code easier to read.

Change-Id: If4eb2f3985c56146d74e760996ad983be12b921a
2024-04-08 13:56:05 +00:00
thiemowmde f09228b55a Pull dependency on global MediaWikiServices up one level
This pulls the dependency out of __construct() up into the static
newFromJSON() method.

I'm also replacing the "ContentLanguage" service, which is a Language
object, with the plain language code. Features from the Language
class are never needed.

Change-Id: Ic4892cd22d83ff557af37e36e62e2af14bc58a99
2024-04-08 13:27:18 +02:00
Umherirrender b4abfcc0d0 build: Upgrade mediawiki/mediawiki-codesniffer to v43.0.0
Change-Id: Ide8e6d9c8ba7294005b520696b8112f08e7b9928
2024-03-12 20:49:04 +01:00
James D. Forrester fb383cc0f2 Replace wfGetDB() with ICP getReplicaDatabase()
Bug: T330641
Change-Id: Ic6ea216ff3365f88288d6a44b723e6dca0b15d49
2024-02-14 11:08:04 -05:00
Umherirrender b43ae79b22 Drop RL targets definitions from module definition, no longer honoured
Bug: T328497
Change-Id: I4cfef72003a11af2763d52428d72da012e34c69c
2024-01-23 21:56:06 +01:00
Umherirrender b626bd18d3 Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statements done manually

Change-Id: I8e049e495a0d0f3a0e1ee02a8252354b12604bf9
2024-01-04 21:53:10 +01:00
thiemowmde 10a43a9ae3 Minor code cleanups in Hooks class
Change-Id: Ied3d5241df04b3fd070319070c0addfd3856e3bf
2023-11-16 13:59:24 +01:00
Umherirrender 46d9842652 Replace empty() with falsy check
empty() should only be used to suppress errors
When the type of the variable is array,
a falsy check is the same (checks for null, false and empty array)
Found by a new phan plugin (T234237)

Change-Id: I17e48498c9be9c542b48a9d77c5574fba9f38d4d
2023-10-21 21:58:58 +02:00
Sam Wilson ab3a80555b Inject MainConfig service to TemplateData hooks
Removes the global config variable.

Change-Id: I67c266a3f5189365de506230d1a7064a7427bff6
2023-09-25 10:40:05 +08:00
thiemowmde 8f81812242 Enable and enforce a few extra PHPCS sniffs
This is not really anything new. Most code already followed these
sniffs. This patch just fixes the remaining exceptions. Also:
* Remove PHPDoc blocks that don't add anything but just repeat the
  strict types.
* Remove @file comments in favor of class-level comments.
* Add strict types where possible, most notably some `void`.

Change-Id: Iff6872dff68170b0fc4e82ac2ba3cad385e8773e
2023-09-06 18:15:22 +02:00
jenkins-bot bde2188280 Merge "Show much more actionable context when paramOrder is incomplete" 2023-09-04 13:45:24 +00:00
thiemowmde 39602bdb8d Replace calls to deprecated ApiPageSet methods
Bug: T339384
Change-Id: Iafc14bb31fd37d38fe0cf53c81f0b774f939f6ef
2023-09-01 07:08:25 +00:00
jenkins-bot 4aaa893c4b Merge "Load GUI on action=edit if page has templatedata even outside NS_TEMPLATE" 2023-08-30 19:42:09 +00:00
thiemowmde 416c3d4f45 Make use of the ??= and ?: operators where it makes sense
This patch also removes small pieces of code from tests that are
never called, as it turns out.

Change-Id: I10ce18339135fefd9a99e0613dc6bfc457ddf4df
2023-08-23 09:24:50 +02:00
thiemowmde bb7b801b64 Show much more actionable context when paramOrder is incomplete
So far we show nothing but the index in the "paramOrder" array. This
is especially useless when a parameter is missing. The index just
points to the end of the array then.

Same when an unknown parameter appears. What the user needs is not
the index but the name of the unknown parameter.

I played around with a few formats. As suggested in this patch:
 Required property "paramOrder[ "foo" ]" not found.
 Invalid value for property "paramOrder[ "foo" ]".

A possible alternative is:
 Required property "paramOrder[0] ("foo")" not found.
 Invalid value for property "paramOrder[0] ("foo")".

Bug: T340377
Change-Id: I1dbef1b6e585d5b972a0c9a373a040aee6027cf3
2023-08-21 12:52:42 +02:00
Timo Tijhof 1f105ed5f6 Load GUI on action=edit if page has templatedata even outside NS_TEMPLATE
Bug: T189989
Bug: T300676
Change-Id: I372e29af7f14fba6ebc60bb6ea025b8e1015f2a7
2023-08-21 10:22:45 +00:00
gerritbot cfd2e5b664 Replace some moved Title class uses, now MediaWiki\Title\Title
Bug: T321681
Change-Id: I2a7aaadc47dd068ccea8fd8110054433973df52c
2023-08-19 18:11:41 +00:00
Umherirrender 8bd3dbc58c Use HookHandlers for core hooks
The use of "HookHandlers" attribute in extension.json makes it possible
to inject services into hook handler classes in a future patch.

Bug: T271031
Depends-On: Ic2d188d2c332ab8afeb5454fb5a956c8ba5670ae
Change-Id: Idf4cf94a0e4fae31a5c1f6c3dbf319c0d6913cd7
2023-08-15 13:03:15 +02:00
Ed Sanders 6107710ef1 Left align caption and put [Edit template data] inline
Bug: T339806
Change-Id: I69a46e64810edf458b8a8ee3e043f6dbc287c8aa
2023-08-05 15:13:22 +01:00
Thalia 855156c95f Hooks: Use UserIdentityUtils for temporary user check
Use instead of UserNameUtils, which has more dependencies.

Change-Id: If8c8687d360690368f9f07999a2baa7ee7a6ad61
2023-07-26 11:38:32 +01:00
thiemowmde b8f4df67f9 Replace inappropriate use of "word-separator" message
These aren't sentences but lists of aliases as well as suggested
values. They are rendered as <code>, visualized as light gray boxes.
We don't need them to respect some language-specific word separation
to be able to read them like a sentence.

https://translatewiki.net/wiki/MediaWiki:Word-separator/qqq
explains how the message should be used.

Bug: T340378
Change-Id: Ia082b5ccb211524262f0c535bb178ee7ec3c20eb
2023-06-25 16:57:50 +02:00
Thiemo Kreuz 647cd0bc65 Clean up base class reaching into the subclass
This does not change anything. It's only about the readabilility
of the code.

Change-Id: Ia908bd90ebc261f3bebc7854501a6f5d5e736384
2023-06-09 07:10:19 +00:00
gerritbot 2d16a7c72f Update moved class EditPage
See T321882. Moved in Ibefc44eb64aed

Bug: T321681
Change-Id: I9de606e32ac58ddbf68ee00587ee9b7f0f9f157d
2023-05-06 21:20:32 +00:00
jenkins-bot 82e5ba9172 Merge "Replace IDatabase with IReadableDatabase where possible" 2023-04-22 20:47:44 +00:00
jenkins-bot 849150c814 Merge "Add missing validation for empty parameter names" 2023-04-21 13:12:29 +00:00
Bartosz Dziewoński f2c89028bd Update TemplateDataEditor logging for IP masking
Bug: T332434
Change-Id: I9935e7d35b1cdb14c0958351cd84d9d6476d6363
2023-04-18 19:30:54 +00:00
thiemowmde b632162245 Add missing validation for empty parameter names
Note this will make the templatedata API temporarily fail for
templates that are affected by this, until their documentation is
fixed. I think we have two ways to proceed here:

1. Thanks to Ie572809 we can change the API module to not do the
validation again. This allows us to make the validation more strict,
but the API module will continue to deliver the same data as before
until the parser cache is invalidated.

2. We accept it and merge this patch as it is. The problem is
extremely rare and easy to fix.

Bug: T333826
Change-Id: I16c7cc2328c47dde196e2dc07edb2eace33a624f
2023-04-11 19:08:37 +00:00
jenkins-bot 0298a2d116 Merge "Split validation and normalization into separate services" 2023-04-11 04:51:02 +00:00
thiemowmde 584fdcddf6 Extract serialization methods into TemplateDataStatus class
This makes the large Hook class quite a bit smaller.

Change-Id: I55229116eb16ccd9be21d1f34de5e52826ece2bf
2023-03-09 11:46:49 +01:00
Thiemo Kreuz 7a32cba3ef Split validation and normalization into separate services
This makes it possible to use these steps independent from each
other. For example, a future patch can get rid of the re-validation
that's done over and over again when the API is called.

A significant change is that this gets rid of an expensive deep
clone. It was necessary before exactly because validation and
normalization was intertwined. Normalized properties would mess with
the later inheritance.

Strictly splitting validation and normalization (and executing them
in this order) solved this. The only downside of this is that
inherited properties are validated twice. But this is much less of a
problem, compared to the deep clone, I would like to argue.

This was always covered by tests. You can still see the tests fail
when you flip the execution order of inheritance and parameter
validation.

Bug: T301337
Change-Id: Ie5728094f9ed813f53b709d8b5283c4b99dc7d63
2023-03-06 13:05:51 +00:00
thiemowmde 962e2828e0 Replace IDatabase with IReadableDatabase where possible
This is a much more narrow interface and really all this code needs
to know.

Change-Id: I2f20fadb8a9630cdb1b7baf9da70e0287db85de2
2023-03-06 12:38:42 +01:00
Sam Smith 0f4d04e83f Use EventLogging::submit() to submit analytics events
EventLogging::logEvent() was marked as deprecated at the beginning of
2021 in I0cfd07295d4b51ca4805c79a28a9a4bd64ff7cc9.

Bug: T318263
Change-Id: I2d89784cc249e97954c9be05169f3060fd69945f
2023-01-30 18:20:16 +00:00
EpicPupper 1e0cecd494 Improve API examples
Bug: T271040
Change-Id: I5b9bbc932d887086d647ce89fb77d192a896d32d
2023-01-17 01:08:27 +00:00
Thiemo Kreuz 505a835c49 Extract named isValidCustomFormatString() method
Bug: T301337
Change-Id: I02e81c264e7ebeb60483d7eacf9fa7b27ad1e545
2022-12-15 12:15:35 +00:00
jenkins-bot e1b5970d3f Merge "Split parameter validation off as separate methods" 2022-12-13 21:09:37 +00:00
Ed Sanders 678d95251b Add an "Edit template data" button to the TemplateData output
This button, similar to an edit-section link, will launch the editor
and immediately open the TemplateDataGenerator UI.

Bug: T316759
Depends-On: Idb5e3c51a22361e0d9916d3c31444daeff310ed2
Change-Id: Ieb575c499c16d87c28972a55662ef0bd9cb72c06
2022-11-08 13:36:38 +00:00
libraryupgrader ca32a8ced1 build: Updating mediawiki/mediawiki-phan-config to 0.12.0
Change-Id: If6ebb246effabc99b7d72a336bacee65c54b5c67
2022-10-09 15:42:03 +00:00
Bartosz Dziewoński ba0e71fd33 Migrate usage of Database::select to SelectQueryBuilder
Bug: T312348
Change-Id: I59057174c102c29877608db2a6c26b7a50bd34cf
2022-08-12 23:54:22 +02:00
Thiemo Kreuz 8497d85a2d Fix CSS styling of the HTML rendering broken since 2016
Some time ago there was a little bit of custom CSS applied to the HTML
table rendering. This is broken since patch I74214ea from 2016. This
patch renamed all CSS classes but forgot to update the PHP code
accordingly.

I decided to not change the HTML rendering because these class names
might already be used in custom per-wiki or per-user CSS. Instead I
partly revert I74214ea.

Unfortunately, some of the styles are quite dramatic, don't look good
or just don't work. I decided to remove some. The argument is that
the HTML rendering looks the same for 6 years now. I don't see a good
reason to change it now.

In detail:
* Suggested values are not aliases and should not be rendered in
  gray.
* The message "no description" is rendered in gray and italics. But
  this was applied to the wrong DOM element and made everything else
  gray and italic as well.
* The color #777 is not readable, violating WCAG rules. While it's ok
  to dim aliases and such, it must be at least #555 or darker.
* The "nowrap" destroys the table the moment one of the parameters
  does have a longer name or alias. Let the browser handle this, as
  it did for 6 years now.
* Same for rendering aliases as individual, indented blocks. This
  makes the table unnecessarily big when there are many aliases, and
  just doesn't look right. Again, let's stick to what we had for
  6 years.

Change-Id: Idfa76eed6e2d68474c79d4674efce091cb031b66
2022-08-08 11:56:16 +02:00
Thiemo Kreuz c0755ea392 Split parameter validation off as separate methods
This only moves code around but doesn't change anything. The tests
should prove this. The only change is that validating if "inherits"
points to an existing parameter is now done a little earlier as part
of validateParameters().

Bug: T301337
Change-Id: I20865d8f93ea0f3cb1c0683804c7871056a700a8
2022-07-15 11:11:32 +02:00
WMDE-Fisch d1ffdc2b95 Remove $wgTemplateDataSuggestedValues feature flag
Feature is always enabled now.

Bug: T307188
Bug: T310684
Change-Id: Ic99c594ceec0020a6c9d20f0a4f10285b74ea9a8
2022-06-27 12:14:02 +02:00
Umherirrender 560819e270 Use WikiPageFactory to create WikiPage object
Bug: T297688
Change-Id: I5e6da574bd1377b492005adbc1aff3e97fe9c31b
2022-06-24 19:53:40 +02:00
Thiemo Kreuz e297e767f0 Streamline HTML rendering code for format messages
The idea is to make it a little easier to follow what's going on
here.

This also improves an error message when tests fail.

Change-Id: If35be8aefab5a1568d53a9ecdc4313a66f71317b
2022-05-16 18:04:27 +00:00
Thiemo Kreuz ff7470e316 Add placeholder to avoid wikitext editor jumping down
Bug: T279869
Change-Id: Ic8f9bf7c95b42422dc4b477f9c752f5e89b20dc7
2022-04-25 08:42:59 +00:00
Thiemo Kreuz 1c8b4ae729 No HTML needed to validate <templatedata> in wikitext
I tried to benchmark this and yes, it makes a difference, but probably
not a big one. This is an additional parse in addition to the one core
will later do when the page is actually saved. For this one here we
are just not interested in the HTML.

Bug: T305105
Change-Id: I71147af5161c934a822651e80e11f3bd26af56cd
2022-04-11 18:29:51 +02:00
gerritbot 42061b7174 Fix usage of ApiBase::PARAM_* deprecated constants
The ones that are replaced with ParamValidator

Bug: T275455
Change-Id: Ia08525d4162d8b460ca8f7fd97b75f564b6bbb7c
2022-04-04 01:29:48 +02:00