Commit graph

274 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
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
Umherirrender
ec7f8ca99a htmlform: Hard-deprecated HTMLForm::*Text functions
Bug: T325474
Change-Id: I89fc570f9238048b7eb58a6f4393e2b35000e133
2024-07-26 13:02:21 +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
Ebrahim Byagowi
14b4269d83 Add namespace and deprecation alias to Xml and XmlSelect
This patch introduces a new namespace declaration,
MediaWiki\Xml and adds Xml and XmlSelect to it
and establishes class aliases marked as deprecated
since version 1.43.

Bug: T353458
Change-Id: I45cccd540b6e15f267d3ab588a064fbeb719d921
2024-05-16 15:23:14 +03:30
Volker E.
48459c0c62 htmlform: Remove the reset button
Nowhere it has ever been activated for many years.
Nobody has been missing it.
Nobody wants it.

Bug: T361032
Depends-On: I2761d634b2c351d755c664778ee0a4796d67c37b
Depends-On: I419cba60e43e10a0a3003f911bd125573b3b7cd7
Change-Id: I067866abc9cc6acdcf05b6048416cfa6caad66d6
2024-04-15 18:46:58 +00:00
Bartosz Dziewoński
dd992c1a7d Remove $wgHTMLFormAllowTableFormat and its uses
Described as "Evil hack for mobile :(", this config variable had been
overridden in the MobileFrontend extension for some time, but this has
been removed last year in Icb1711a0cef828dda0d99b8a7c7963bc409816c9.

Since it was introduced, most HTMLForms using the 'table' format have
been reworked to use 'ooui' (or 'codex', these days), so the hack is
no longer needed.

We recently removed $wgUseMediaWikiUIEverywhere for similar reasons
in aa7eeeeef9 / be135c0fc0.

Change-Id: Id507c0dc5a1c1cfb9737073bae97b14badc30a54
2024-03-26 22:49:55 +01:00
jenkins-bot
054242ffe5 Merge "CodexHTMLForm: Add support for fieldset, description, and optional" 2024-03-26 19:30:34 +00:00
Anne Tomasevich
eb29d1424d CodexHTMLForm: Add support for fieldset, description, and optional
- Override HTMLForm::wrapFieldSetSection() to apply the right
  markup and classes for a fieldset and its legend
- Override HTMLForm::formatSection() to include the
  .cdx-field__control class
- Add a setter for section info to HTMLForm (that only
  works when the display format is 'codex')
- Add an optional flag message
- Override HTMLForm::getLegend() to include CSS classes
  and additional sub-elements of the legend, including an
  "optional" flag and a description.

Implementation notes:
- CodexHTMLForm::getLegend() returns HTML, while the parent
  method returns plain text. This was necessary to include
  the "optional" flag and description within the legend
  element, which is critical for users of assistive tech.
- setSections() was added to HTMLForm instead of CodexHTMLForm
  to support use cases like FormSpecialPage, which expect the
  form to be an HTMLForm

Bug: T359020
Bug: T359016
Change-Id: I7b637331e171c46b48de085a6fa92f8ceaf16a50
2024-03-26 14:56:36 -04:00
jenkins-bot
2e857b0d92 Merge "HTMLForm: Add per-option descriptions for Codex radio buttons" 2024-03-25 15:04:29 +00: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
Roan Kattouw
677bf52b42 HTMLForm: Add per-option descriptions for Codex radio buttons
Add the 'option-descriptions', option-descriptions-messages' and
'option-descriptions-messages-parse' settings to HTMLRadioField, which
allow setting descriptions for each option.

For simplicity, only support this for HTMLRadioField, and only for
Codex. See also T324268 for a previous stalled attempt to implement this
for OOUI, which ran into issues.

Bug: T359019
Change-Id: I38116bb2fa3086408d3e2b47e5fe020b30f9729a
2024-03-21 15:06:47 -07: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
Timo Tijhof
8fc75cbd20 htmlform: Fix HTMLForm::addButton phan-param to allow message params
Example at Ia0281346be:

```
$form->addButton( [
  'name' => 'renew',
  'value' => '1',
  'label-message' => [ 'wikimediaevents-special-wikimediadebug-submit-renew',
    Message::durationParam( self::DEFAULT_EXPIRY )
  ],
] );
```

Causes

> `PhanTypeMismatchArgument Argument 1 ($data) is array{…label-message:array{0:'wikimediaevents-special-wikimediadebug-submit-renew',1:int[]}} but \MediaWiki\HTMLForm\HTMLForm::addButton() takes array{…,label-message?:\MessageSpecifier|string|string[],…} defined at ../../includes/htmlform/HTMLForm.php:1244`

The inferred return value of Message::durationParam() and other such
Message class methods is `int[]`, not string.

Change-Id: Id0835193442e17e0f9979373c366c087ff4a7640
2024-03-14 17:16:38 -07: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
Bartosz Dziewoński
aa7eeeeef9 Remove uses of $wgUseMediaWikiUIEverywhere
Removing the config variable in a separate change:
Ib9966bc6a4a94f771cb99a5aa52fb6a1dc826ca5
(just in case something depends on its existence).

Bug: T182050
Change-Id: Ic3e038df16fc540ec7f6bcb9a54d73f8d596d305
2024-02-04 19:16:30 +00:00
Daimona Eaytoy
caef81d37a Replace deprecated MWException
Bug: T328220
Change-Id: Ic45438d9e6bbf127f1415add81ab902044765840
2024-01-16 21:04:33 +01:00
James D. Forrester
468e69bccc Namespace Sanitizer under \MediaWiki\Parser
Bug: T166010
Change-Id: Id13dcbf7a0372017495958dbc4f601f40c122508
2023-09-21 05:39:23 +00:00
James D. Forrester
94ece673b2 Namespace TitleValue under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: I4c901d5c32696d8334ec30cede7d9b6f3d8d645e
2023-09-18 18:24:39 +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
b888daea79 Merge "HTMLForm: Dispatch field formatting explicitly instead of guessing method names" 2023-07-11 11:47:02 +00:00
jenkins-bot
df8078f2d7 Merge "HTMLForm: Extract a formatField() helper method" 2023-07-11 11:46:55 +00:00
jenkins-bot
fb44c696a5 Merge "htmlform: Use more compact PHP features in places" 2023-07-10 18:39:58 +00:00
Bartosz Dziewoński
27a1d1151a HTMLForm: Dispatch field formatting explicitly instead of guessing method names
I've never liked how HTMLForm guesses the method names that return
each field's HTML based on the $displayFormat property, for example
`$displayFormat === 'div'` resulting in using `->getDiv()`. Recently
this mechanism resulted in CodexHTMLForm lying about its display
format to get the desired result. Instead, explicitly switch based
on the display format and call the appropriate method, and override
this in subclasses when using subclasses.

Change-Id: I91b802ac63622e3b592be589d89ea11117a616f8
2023-07-10 18:53:50 +02:00
Bartosz Dziewoński
daa623f886 HTMLForm: Extract a formatField() helper method
This is mostly so that I can add nice type hints. (But also, this is
one of the main things that this class does, I think it deserves its
own method instead of being sandwiched in that ugly loop.)

Change-Id: I621b839a8079cee1198c4250686e378ff7006c75
2023-07-10 18:35:25 +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
Jon Robson
51c6fe6167 Login page: Use Codex CSS components
Changes:
* Use Codex markup instead of mediawiki ui markup
* We limit what can be customized by the skin
* Current rules for touch area and snapping of
inputs is moved from Minerva into core so other skins
benefit from the styling
* A placeholder text is adding to the "real name" field.
* Introduce CodexHTMLForm

Bug: T182050
Change-Id: I834cc0e07fc1e705753df6866a5eeda2ac77fb8e
2023-07-06 17:20:17 -07:00
Func
13e7861123 HTMLForm: Allow conditional prefilling even without identifier
Special:Logs is prefilling fields manually by the `default` param
for compatibility with links without `wpFormIdentifier` set.
That disabled the validation built in HTMLForm, since we would
give up when the default value is invalid.

Prefilling fields and trying submit should be fine if the caller
is sure that the page only contains that GET form.

Bug: T338042
Change-Id: I047d2546d3dacc672304dab1e362c08992e68308
2023-06-14 03:41:28 +08: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
Tim Starling
317b460500 Fix even more PHPStorm inspections (#3)
* Inappropriate @inheritDoc usage. Arguably all @inheritDoc is
  inappropriate but these are the ones PHPStorm flags as misleading
  due to the method not being inherited.
* Doc comment type does not match actual argument/return type.
* I replaced "@return void|never" with "@return void" since never means
  never, it doesn't make sense for it to be conditional. If a method
  can return (even if that is unlikely) then @return contains the type
  that it returns. "@return never" means that there is no such type
  because the method never returns.
* Incomplete/partial/broken doc tags

Change-Id: Ide86bd6d2b44387f37d234c2b059d6fbc42ec962
2023-03-25 00:30:15 +00:00
Matěj Suchánek
c231736471 Fix some typos
Bug: T201491
Change-Id: I5c9408c262f09c936525f35abfacfa92a193b791
2023-03-21 15:58:09 +01:00
jenkins-bot
4c1ae11a41 Merge "htmlform: Skip array query parameter on HtmlForm::addHiddenField" 2023-03-10 23:59:57 +00:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05: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
Umherirrender
b1a287ca61 htmlform: Skip array query parameter on HtmlForm::addHiddenField
Also exclude them in TablePager::getHiddenFields

Bug: T321471
Change-Id: Iedcb9071e6543d08d14336a2e96711675b6f5811
2023-02-10 20:10:33 +00:00
jenkins-bot
d68e047a2d Merge "Refactor SpecialWhatLinksHere to use FormSpecialPage" 2023-02-01 22:58:05 +00:00
jenkins-bot
36f9c2e962 Merge "Avoid passing null to HTMLFormField methods" 2023-01-19 19:18:02 +00:00
Func
4727ed1a9c Refactor SpecialWhatLinksHere to use FormSpecialPage
Use cases of HTMLForm should not supply user inputs as the default
value, espacially values that can't pass validations.

Bug: T41126
Change-Id: Ia50b06e12fbe5d47165a73245e695ba75fa4faec
2023-01-11 13:10:11 +08: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
Func
c9dc5a0233 HTMLForm: Skip submission when got nothing from the user on GET forms
Don't throw errors when the user is only viewing these GET forms.

Change-Id: I6f6e68505152acd57ff4e9c4dd51bbd10b5e8c1d
2022-12-25 13:01:13 +00: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
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
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
Sam Wilson
c6dc9b93ca Avoid passing null to HTMLFormField methods
The methods HTMLFormField::getDiv, getRaw, getInline, etc. all
accept a single string parameter, but here are being passed null.
This raises a deprecation warning in PHP 8.1 in some situations,
(because of deeper usages of substr() etc.).

Bug: T289926
Change-Id: Id965f42b9cb4fc617d89c26d4459c66c3c478090
2022-10-14 12:46:34 +08:00
Daimona Eaytoy
350e9b88c1 Fixes for the phan upgrade, part 1
Mainly, document some parameters as non-empty-array so that phan knows
the list of arguments won't be empty when unpacking.

In EditPage, account for hooks potentially unsetting the copyright
notice.

Also rewrite some code in LogPager, so it's hopefully easier for phan to
understand what's going on.

Change-Id: Ic0638571554424098d0743db32dd46723a08e103
2022-10-08 13:08:47 +00:00
jenkins-bot
1e60c7337a Merge "Create an HTMLForm field for selecting a timezone" 2022-09-23 18:16:06 +00:00