Commit graph

187 commits

Author SHA1 Message Date
Umherirrender
aed646001c htmlform: Add missing documentation to class properties
Add doc-typehints to class properties found by the PropertyDocumentation
sniff to improve the documentation.

Once the sniff is enabled it avoids that new code is missing type
declarations. This is focused on documentation and does not change code.

Change-Id: I1f306a3925d6768209a06e70082598b2f70cd319
2024-09-14 11:49:05 +00:00
Alex
ac82eb2627 Deprecate the 'help' key in form descriptors in favor of 'help-raw'
This new key name should better signal to developers that this key
will be used as-is without escaping

Bug: T356971
Change-Id: I98849b2e45cc4555eca7674875b9bed89f128310
2024-08-09 13:47:45 +02:00
Bartosz Dziewoński
c045fa0291 Replace gettype() with get_debug_type() in exception messages
get_debug_type() does the same thing but better (spelling type names
in the same way as in type declarations, and including names of
object classes and resource types). It was added in PHP 8, but the
symfony/polyfill-php80 package provides it while we still support 7.4.

Also remove uses of get_class() and get_resource_type() where the new
method already provides the same information.

For reference:
https://www.php.net/manual/en/function.get-debug-type.php
https://www.php.net/manual/en/function.gettype.php

To keep this safe and simple to review, I'm only changing cases where
the type is immediately used in an exception message.

Change-Id: I325efcddcb58be63b1592b9c20ac0845393c15e2
2024-07-31 19:24:39 +02:00
Bartosz Dziewoński
c9f73efd5a Namespace MessageSpecifier under Wikimedia\Message\
In change I625a48a6ecd3fad5c2ed76b23343a0fef91e1b83 I am planning to
make Wikimedia\Message\MessageValue use it, and we try to pretend that
it is a library separate from MediaWiki, so it makes sense to move
MessageSpecifier to the same namespace under Wikimedia\.

Bug: T353458
Change-Id: I9ff4ff7beb098b60c92f564591937c7d789c6684
2024-07-28 14:21:32 +02:00
Daimona Eaytoy
e71d02d79f htmlform: Improve documentation of the validation-callback option
The code works with StatusValue, not just Status, so update the docblock
accordingly, especially considering the fact that more modern code
should prefer the former.

Also mention what the expected signature is by linking directly to the
callback property, so that developers don't have to scan the whole body
of `validate()` to figure it out.

Change-Id: I9d5f155d1d797e3fa8ab4a0f10cc19b21d933c8a
2024-06-28 19:58:30 +02:00
Umherirrender
c08b492d75 Use namespaced classes (3)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Ia35b2d3105880631dd26ec974068b000ac7f4b6b
2024-06-16 20:26:43 +02:00
Ebrahim Byagowi
a717db8e60 Add namespace and deprecation alias to FormatJson
This patch introduces a namespace declaration for the
MediaWiki\Json to FormatJson and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I5e1311e4eb7a878a7db319b725ae262f40671c32
2024-05-16 16:28:01 +03:30
Dreamy Jazz
294972227e Log duplicate translations of options-messages for HTMLFormField
Why:
* When using a HTMLFormField that has accepts the options-messages
  parameter, the message keys are the key and the value is either
  an array of options or the name of the value.
* However, when converting the message key to the translated text
  it is possible for two or more message keys to have the same
  translation (for example T19746 and T347314). This causes only
  one of the duplicate items to be displayed in the options list.
* As such, an logstash error should be raised when this happens
  so that, when debugging a missing option, the error can be found
  and lead to the issue being found quickly. For example, in
  T347314 it took several months for the issue to be found and
  solved.

What:
* In HTMLFormField::lookupOptionsKeys, add code to check if the
  translated text for the message key already exists in the array
  of translated text to option value. If it does, then create a
  logstash error and skip adding the item to the array (as it
  will override the already added item).
* Also do this in LogEventsList and UsersPager, where the code
  passes the options using the 'options' key and uses the
  HTMLSelectFieldand. This means that HTMLFormField
  ::lookupOptionsKeys will not be called and as such need the
  same code to handle the duplicate values.

Bug: T360326
Change-Id: Ifdeb917f7034967feed7a3b86aabec3c4d49bcc6
2024-04-01 22:04:48 +02:00
Umherirrender
723134eade Add explicit parentheses around mixed boolean operator
Mixing different binary boolean operators within an expression
without using parentheses to clarify precedence is not allowed (T358966)

Change-Id: I24ca752d5dac7c948fdbcabf721f6f0aef8a466f
2024-03-23 01:58:59 +01:00
jenkins-bot
0dffe07c6e Merge "htmlform: Fix double escaping in Label div" 2024-03-19 22:34:30 +00:00
Ammarpad
7d795d4fc7 htmlform: Fix double escaping in Label div
Bug: T360381
Follow-up: Iab3f3c81f4de034a3a04b54caf269de6fde4a7f2
Change-Id: I56ffc4b6c194e3115a7c9986d3639d5831288155
2024-03-19 21:22:41 +01:00
James D. Forrester
8e940c4f21 Standardise all our class alias deprecation comments for ease of grepping
Change-Id: I7f85d931d3b79da23e87b4e5692b2e14be8fcaa0
2024-03-19 20:11:29 +00:00
jenkins-bot
773da1b26c Merge "HTMLForm: Wrap Codex-based form fields in a Codex Field component" 2024-03-12 17:37:56 +00:00
jenkins-bot
d6188b5c37 Merge "HTMLFormField: Add getInputCodex() method for Codex output" 2024-03-12 17:37:49 +00:00
Roan Kattouw
c12ba1fc20 HTMLForm: Wrap Codex-based form fields in a Codex Field component
Besides expanding getCodex() to build the Field component and its
constituent parts, this required adding parameters to pass the
cdx-message--inline class to the error box generation code, and passing
the error status to getCodexHtml() so that field subclasses can add
status CSS classes to the components they generate.

Bug: T359021
Change-Id: Iab3f3c81f4de034a3a04b54caf269de6fde4a7f2
2024-03-11 21:29:29 -07:00
Bartosz Dziewoński
f1d7e68cd2 Rename dropdown-related methods to avoid random camel-case
It's a dropdown, not a drop down, therefore rename:
* Html::listDropDownOptions     → Html::listDropdownOptions
* Xml::listDropDownOptions      → Xml::listDropdownOptions
* Html::listDropDownOptionsOoui → Html::listDropdownOptionsOoui
* Xml::listDropDownOptionsOoui  → Xml::listDropdownOptionsOoui
* Xml::listDropDown             → Xml::listDropdown

In PHP, method names are case-insensitive, therefore we can do this
without a breaking change or deprecation.

This also matches the naming convention in OOUI.

Change-Id: Ifda13ba9dee316709c424636ec3b285de8d0e9b1
2024-03-09 02:31:33 +01:00
Roan Kattouw
1a666669ae HTMLFormField: Add getInputCodex() method for Codex output
Treat Codex the same as OOUI, which also has separate getOOUI() and
getInputOOUI() methods. With this, we can refactor the HTMLFormField
subclasses that already have Codex support to override getInputCodex()
instead of checking for $this->mParent instanceof CodexHTMLForm.

The getCodex() method is mostly a copy of getDiv() for now. The next
commit reworks this to use the correct field wrappers that correspond
to Codex's Field component.

Bug: T359013
Change-Id: Iccd6fec003b6ca119b13c01a43dda9e8b2aca3e2
2024-03-08 06:00:27 +00:00
James D. Forrester
eeb5a740b3 Namespace Message, move to appropriate directory
Bug: T353458
Change-Id: I088cbc53fbcdb974e5b05b45a62e91709dacc024
2024-02-14 15:10:36 -05:00
James D. Forrester
59c0aa2134 Namespace HTMLForm and friends
Bug: T353458
Change-Id: I09e66c3223018ec47e0549ee7f6a590b676f4eef
2024-02-14 08:18:33 -05:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
James D. Forrester
1ed893880c Html: Copy listDropDownOptions() and listDropDownOptionsOoui() from Xml and migrate users
Bug: T356544
Change-Id: Ibcc13c92a48b3fd2a33914418dfbefb0dd890c82
2024-02-03 18:27:23 +00:00
thiemowmde
195267f142 htmlform: Improve type safety related to HTMLFormFieldCloner
The main benefit is that IDEs, static analyzers and such are now
able to understand that this refers to code from the
HTMLFormFieldCloner class. This was completely hidden before.

Also fix a mistake in the documentation for getNearestField. This
was accidentally copying the getNearestFieldValue documentation,
which does return mixed.

Change-Id: Ie4204bc967013825d9d73d30f264b07ff0c9e846
2024-01-13 19:17:32 +01:00
Amir Sarabadani
5bd33d46ef Reorg: Move WebRequest to includes\Request
This has been approved as part of RFC T166010

Bug: T321882
Change-Id: I6bbdbbe6ea48cc1f50bc568bb8780fc7c5361a6f
2023-09-11 21:44:34 +01:00
Amir Sarabadani
f4e68e055f Reorg: Move Status to MediaWiki\Status\
This class is used heavily basically everywhere, moving it to Utils
wouldn't make much sense. Also with this change, we can move
StatusValue to MediaWiki\Status as well.

Bug: T321882
Depends-On: I5f89ecf27ce1471a74f31c6018806461781213c3
Change-Id: I04c1dcf5129df437589149f0f3e284974d7c98fa
2023-08-25 15:44:17 +02:00
jenkins-bot
27c9573312 Merge "htmlform: Allow validation-callback to return Status instances" 2023-07-10 20:47:18 +00:00
mainframe98
b6ded3b2c5 htmlform: Allow validation-callback to return Status instances
Convert this in HTMLFormField::validate to prevent callers from
receiving unexpected Status instances that will be identified as
an error result, even if the Status is good.

Bug: T338677
Change-Id: If2208cca92c5c496eef73f25363221bc490d9c88
2023-07-09 19:53:01 +02:00
thiemowmde
918aed5f77 htmlform: Use more compact PHP features in places
Some of these classes are really huge, up to 2000 lines and more. I
hope this makes the source code a little more readable.

Change-Id: I3d4b2a042a34c14e6ea0ea30ea31ca53448d8d59
2023-07-07 13:11:05 +02:00
thiemowmde
4ae624e6e6 Improve performance of HTMLFormField::shouldInfuseOOUI
While this is not really a bottleneck, I found this does quite a lot
of unnecessary things that are not used in this particular context.
All we want to know is if one or more help messages exist. We don't
need the actual, parsed help messages in this context.

Note this patch changes the code in a way that is not 100% the same as
before. Let's say there is only 1 message, and it's disabled. Since
the possibly expensive exists() check is delayed shouldInfuseOOUI()
might return true in rare edge-case situations where it returned
false before. I would like to argue this is worth it. We just trade
one performance optimization for another.

Change-Id: Ib4550e954853355f361249b13ec877478de9c789
2023-07-03 14:12:33 +02:00
Daimona Eaytoy
4d5cd3a84f Replace deprecated MWException
Bug: T328220
Change-Id: I66be7a6dd752d6b9c254beb65f4eb5ace3c89776
2023-06-09 17:21:12 +02:00
Marius Hoch
dc87b69568 Allow setting "notices" for OOUI form fields
We need this in Wikibase to nicely indicate why
a certain form field cannot be used.

Bug: T330193
Change-Id: Ic0a6f9561db41d4da218122477ce9318665929d5
2023-05-30 12:28:15 +02:00
Amir Sarabadani
7d8768e931 Reorg: Move HTML-related classes out of includes/ to Html/
Bug: T321882
Change-Id: I5dc1f7e9c303cd3f5b9dd7010d6bb470d8400a18
2023-02-16 20:40:01 +01:00
Brian Wolff
07cdef809c Deprecate creating HTMLFormFields without reference to parent form
Currently it is documented that mParent in HTMLFormField may be null.
This can happen if the form element is constructed manually via
new, instead of the normal way via HTMLForm methods.

As it stands, much of the code assumes that mParent is always set
despite the documentation. Lets mark creating form fields without
parent set as deprecated. The current situation seems like a
recipe for bugs, and after the deprecation period this would allow
us to simplify some of the HTMLFormField code.

Bug: T326456
Change-Id: Ica0740049f0a3e8ec764903c5b71825e4d628a3f
Depends-On: I15a39605e3eec8a5c265c4a331039fa906eda036
2023-01-08 18:20:16 -08:00
jenkins-bot
509f8dc360 Merge "Use str_starts_with/str_ends_with/str_contains" 2022-12-14 03:06:28 +00:00
Roan Kattouw
3c3386949c HTMLForm: Fix E_NOTICE when hide-if is used with setFormIdentifier
When a form identifier is set, HTMLForm::prepareForm() initializes
mFieldData as an empty array. When resolving hide-if conditions based on
other fields, HTMLFormField looks up that field's value in the parent
form's mFieldData and expects its key to be set, but it isn't because
mFieldData is deliberately empty. That causes an E_NOTICE for an
undefined index.

Resolve this by having HTMLFormField::getNearestFieldValue() fall back
to the field's default value when the field's actual value isn't found
in mFieldData.

Change-Id: I3a12f6aec1e8a6da3cd3a29195d37c12ebf08b16
2022-12-13 14:52:10 -08:00
Umherirrender
45e6a2b0f9 Use str_starts_with/str_ends_with/str_contains
Use the new function in conditions to avoid creating substrings or to
search the whole string

Change-Id: Ibad6b1b447a4f62cceb34359231f88ebb967a90b
2022-12-12 19:54:24 +01:00
Amir Sarabadani
2d60ba0c63 Reorg: Move DummyLinker and Linker to linker/
This feels like a no-brainer unless I'm missing something obvious

Bug: T321882
Change-Id: Id49c3d0dd6ea4593211048850856b5b8e05a8fb3
2022-12-08 06:38:17 +01:00
Umherirrender
20c3cc6ef1 Remove unused variable from unpacking arrays
Change-Id: Iac27cb4aa936cb494b3e491ce22c88c7fad375a1
2022-11-22 23:21:08 +00:00
Umherirrender
ea5ea60b31 Various doc fixes about false on method arguments/return types
Doc-only changes

Change-Id: I5177f582ae7ee70c357e9389fed14819faf79463
2022-11-10 19:23:46 +00:00
Lucas Werkmeister
2b0b187bae HTMLFormField: Treat null as missing value
null is the “default default” in getDefault() (if the method has neither
been overridden nor $this->mDefault been set), so it can appear in the
field data. Don’t pass it to the validator (which may not expect a null
value) if the param is supposed to be required.

Bug: T319219
Change-Id: Ib6bb119b841ffcbb5e7fb30014355dc90ba9b46e
2022-11-08 13:23:56 +01:00
Zabe
f6b9381d7f Revert "Reorg: Move some of request related classes to MediaWiki/Request"
This reverts commit 2bdc0b2b72.

Reason for revert: T166010#8349431

Bug: T166010
Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
2022-10-27 13:14:16 +00:00
Amir Sarabadani
2bdc0b2b72 Reorg: Move some of request related classes to MediaWiki/Request
Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequest
 - WebRequestUpload

Bug: T166010
Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
2022-10-26 16:49:10 +02:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
jenkins-bot
f2bbe611e1 Merge "Update docs for HTMLFormField::validate() to permit all data types" 2022-09-23 00:13:28 +00:00
Sam Wilson
e9e0bd68c4 Update docs for HTMLFormField::validate() to permit all data types
Callbacks for validation-callback definitions are given the submitted
field value, which was documented as being string or array, but
actually can include int, null, etc.

This fixes the docblock, and also updates
DefaultPreferencesFactory::validateSignature() which was assuming
a string and not expecting null. (This didn't matter before PHP 8.1.)

Bug: T318307
Change-Id: Ia9096d610bf377334bbeab9021a8ade9be62edd5
2022-09-22 12:10:43 +08:00
Umherirrender
5c5498a202 Remove unused key variable from foreach loops
Change-Id: Id2d91e30a6f7cc4eb93427b50efc1c5c77f14b75
2022-09-21 21:18:43 +02:00
Umherirrender
b15e689d49 Remove unused local variables
Various variables are left from ealier refactor are now unused
and can be removed to make the code easier to read

Change-Id: Id51770af1f08e85c7e7a02234a2cd2ab5b47ee7a
2022-09-19 23:07:07 +02:00
Bartosz Dziewoński
8f7cd07af6 HTMLFormField: Fix Phan suppression about mClassWithButton
Change-Id: Ie20fa54de1fcc69913b3881d2efe9192be5b90cc
2022-06-17 21:47:59 +02:00
Tim Starling
d36ea62c20 Bury the reset preferences link
* Move the reset preferences link from the bottom of the preferences
  form to the "basic information" section.
* Change the link from "destructive" red to default styling, since the
  action requires confirmation so there is no reason to make the user be
  afraid of clicking it by accident.
* Add a checkbox to the /reset form, for triple confirmation.
* Add a cancel button to the /reset form, to take the user back to
  safety.
* Allow checkboxes to be "required" by fixing a detail in
  HTMLFormField::validate(). The UI is not pretty, but it works.

Bug: T226325
Change-Id: I116d5275ba1a5beaaa44b32b8eff5824e94b437a
2022-05-13 09:57:06 +10:00
stang
9c70df0cf6 Fix uses of (error|warning|success)box in core
Replace HTML class for boxes with "mw-message-box-" style.

Bug: T300358
Change-Id: Iddb0fd3ae859714fb03d3a6d4586f8525becaac6
2022-03-20 21:15:26 +00:00
Umherirrender
aa3de7651d htmlform: Allow string to return from HTMLFormField::getInputOOUI
It gets wrapped into a Widget in ::getOOUI

Found by phan strict checks (used by tagfilter and cloner)

Change-Id: Ie1fd15fc2a66fcb39fa2e2f63761d9683029e395
2022-03-09 20:05:15 +01:00