Commit graph

141 commits

Author SHA1 Message Date
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
Reedy
11cc2d6993 Consistently use @deprecated since rather @deprecated
Change-Id: I301786f35cd6eb9c63fb72e0b64cffa9efd7b86b
2022-03-06 02:55:54 +00:00
jenkins-bot
b0e7ad719b Merge "Revert "htmlform: Replace some uses of isHidden to isDisabled"" 2022-02-28 21:19:47 +00:00
Func
06f1306537 Revert "htmlform: Replace some uses of isHidden to isDisabled"
This reverts commit a745a87216.

Reason for revert: logspam on use cases out side the scope of HTMLForm

Bug: T302512
Change-Id: Idcf1c7db89b4456308d57915ffd0dcc41ee577ad
2022-02-28 15:05:45 +00:00
Umherirrender
b126dbe3f2 Fix various documentation related to null types
The functions returning null or the class property is set explict null

Found by phan strict checks

Change-Id: I4a271093fb6526564d8083a08249c64cb21f2453
2022-02-26 10:31:24 +01:00
Func
a745a87216 htmlform: Replace some uses of isHidden to isDisabled
After its logic is refactored, we have more faith to use isDisabled() in these cases, which matches the original semantics of isHidden().

Change-Id: I1aece7c691307ac8bb3770e6dc4b8e2877e4d65c
2022-02-20 15:17:49 +00:00
Func
0e36de19dc HTMLFormField: Adjust isSubmitAttempt and add more comments
This is a follow-up of change Ic414e7bb7933c8c5c58a277ac1c5c3aaf8c36119.
I noticed that HTMLForm would add a hidden field of edit token for forms
that require to be posted...
And I also noticed that there is a crazy use case (9ca8394943/includes/specials/SpecialTags.php (320))
that would break with the loose check (I'm also going to fix it by I5050311c37030a64daaa25d05e2223485ed86108).
So that change should be undone, but keep the POST check here to avoid
arbitrary token in a GET form.
Add more comments since there are some preconditions in another file and
avoid future regression.
(And I hope this is the last time I fix this test...)

Change-Id: Ib02cd6b4a45e3820c4378fe5b0c7fc61fe1251e7
2022-02-11 11:46:21 +00:00
Func
c6ca47570f HTMLFormField: Treat posted request as a submit attempt
This can help check fields default to true or have 'invert' enabled to
load correct data, because the 'false' values of checkboxes can never
be included in the request of normal use cases. Also better to other
use cases in HTMLCheckMatrix and HTMLMultiSelectField.

This partially reverted I5589ba7383587afdd9307c79e88849dacee02706.
I get trapped by the test case... The default value does need an invert
to check for hide-if and disable-if, like what
HTMLCheckField::getInputOOUI() do for display.

Depends-On: Icfa062eada75c50cd2c8bc5db2930602d80e9ae7
Change-Id: Ic414e7bb7933c8c5c58a277ac1c5c3aaf8c36119
2022-02-08 09:26:53 +00:00
Func
aa57f20aa2 HTMLFormField: Make the behavior of cond-state consistent between client and server
Old codes relied on some assumptions, so:
  * When a "key in form descriptor" is provided, the 'name' param can't be set otherwise the js wouldn't be able to find it.
  * When a "name for submission" (with 'wp' prefix or same as the 'name' param) is provided, it works on the client-side but something might be broken on the server-side.

Since the documented usage is to use "key in form descriptor" and most use case is fine, the use of "name for submission" is explicitly disallowed here.
Use cases simply with the 'wp' prefix would still keep working on both sides though.

Depends-On: I27fd8fa9643d611b37e3f47e77b698245814d539
Change-Id: I9a42417a6161f42181badd8cdbec81ba85dc62f6
2022-02-07 09:56:25 +00:00
jenkins-bot
2becc606d3 Merge "Try not to discard Excimer timeout exceptions" 2022-02-03 00:28:16 +00:00
Tim Starling
ca71e69fc6 Try not to discard Excimer timeout exceptions
Don't catch and discard exceptions from the RequestTimeout library,
except when the exception is properly handled and the code seems to be
trying to wrap things up.

In most cases the exception is rethrown. Ideally it should instead be
done by narrowing the catch, and this was feasible in a few cases. But
sometimes the exception being caught is an instance of the base class
(notably DateTime::__construct()). Often Exception is the root of the
hierarchy of exceptions being thrown and so is the obvious catch-all.

Notes on specific callers:

* In the case of ResourceLoader::respond(), exceptions were caught for API
  correctness, but processing continued. I added an outer try block for
  timeout handling so that termination would be more prompt.
* In LCStoreCDB the Exception being caught was Cdb\Exception not
  \Exception. I added an alias to avoid confusion.
* In ImageGallery I added a special exception class.
* In Message::__toString() the rationale for catching disappears
  in PHP 7.4.0+, so I added a PHP version check.
* In PoolCounterRedis, let the shutdown function do its thing, but
  rethrow the exception for logging.

Change-Id: I4c3770b9efc76a1ce42ed9f59329c36de04d657c
2022-02-02 16:27:44 +11:00
Func
0c707ca259 HTMLFormField: Bypass the inverting logic of HTMLCheckField for disable-if and hide-if
Values loaded from the default wouldn't be inverted, there is no need to copy the conditions to here, we can just simply bypass them.
Fortunately, nothing can be affected in a normal use case, since all value of fields would be set to server.

Thanks to the newly added tests, which helped me to realize this problem. 

Change-Id: I5589ba7383587afdd9307c79e88849dacee02706
2022-02-01 13:09:13 +00:00
Func
1dfed9b6d3 HTMLFormField: Simplify duplicated codes of checkStateRecurse()
Change-Id: I47b20cfc85741cbdea6599e89ae551b8f8f0c6f8
2022-01-31 16:18:08 +00:00
Func
53d4b41be3 HTMLFormField: Split out the validation of cond-state params
Follow-up changes will use cond-state params in other functions, split this out to make sure it's validated.

Change-Id: Icf358794b11a8f986fbd02c8f1b15ea9d1ef4d15
2022-01-28 21:47:52 +00:00
jenkins-bot
033f7b6fd2 Merge "HTMLForm: Pass field data instead of fields to filter" 2022-01-17 21:26:22 +00:00
jenkins-bot
55a9794f7a Merge "HTMLFormField: Handle invert state of value for HTMLCheckField" 2022-01-17 20:30:14 +00:00
Func
0b71f77d03 HTMLFormField: Handle invert state of value for HTMLCheckField
After I58f9df384df8ecc5ebae8cac68ec2251351bc984 applied, I found several bugs around...

Change-Id: I9ce42699f9746640b7e36e1c2210b2891fe742e4
2022-01-17 20:04:06 +00:00
Ammarpad
1e1f832dd0 HTMLFormField: Extract repeated logic to function
Change-Id: I8fe399e93815348058cc4dfa7c7f3c380450a41a
2022-01-17 13:46:34 +01:00
Func
0ae7dad148 HTMLForm: Pass field data instead of fields to filter
I believe there is a mistake, since DefaultPreferencesFactory::cleanSignature() uses it as field data, which is the only filter applied in the core.

Change-Id: Ic7aa509a3e5fd3a3c717259d83d5bf0a26d3556a
2022-01-15 06:05:58 +00:00
Func
9c9514a8d9 HTMLForm: Load data from default for fields that are supposed to be disabled
Data of disabled fields wouldn't be sent to the server, which needs to load data from default.

Bug: T298614
Bug: T298819
Change-Id: I58f9df384df8ecc5ebae8cac68ec2251351bc984
2022-01-13 11:54:01 +00:00
Func
2f3b8a4c9b Add cond-state classes in the server-side
There is only one use case of cond-state classes passed to the client-side, and it can be done more natively.

Change-Id: Ib6835bb334bd65c6176f0a5c3881b20265901af9
2022-01-07 22:14:23 +01:00
Bartosz Dziewoński
11c1cacf00 HTMLFormField: Avoid passing empty CSS class name to OOUI
It causes issues there (T298737).

Change-Id: I0dd8ed18d1df7f1b62e6ac460fa32d8c1770b7c5
2022-01-07 22:13:42 +01:00
Daimona Eaytoy
8fda40e95f HTMLFormField: fix merging of condState attributes
Array addition in PHP does not renumber keys, so it can't be used to get
the union of two lists.

Bug: T297975
Change-Id: Ic9932b23e32c704b14fc9fe234c35a48b59767c5
2021-12-20 21:34:29 +00:00
Func
361954801e Add support for conditional disable fields in HTMLForm
Provide a native method to disable fields in particular condition.

Bug: T272302
Change-Id: I8f46dedc2945cf3b7ef5419b0a54534ded8b6d5b
2021-12-11 01:39:42 +00:00
Bartosz Dziewoński
2990c003e3 htmlform: Remove HTMLFormField restrictions on 'name' and 'id'
The restrictions were introduced in r53480 (724411c7ca, 2009),
which makes it clear that this was just about HTML correctness,
and in HTML5 there are fewer requirements.

This code was last touched in commit fd6e9ef2d4 (2017), where it was
suggested in code review that it "can probably be removed":
https://gerrit.wikimedia.org/r/c/mediawiki/core/+/362326/comment/6e71af52_900abad4/

Bug: T126962
Change-Id: I54c1f28ec9112cd4a161a79e76c2224f91f134b9
2021-11-05 21:17:29 +00:00
Kunal Mehta
a85f569dd1 Revert "Use CsrfTokenSet as CSRF token source"
This reverts commit 0d75fdb4f7.

Bug: T287542
Change-Id: Iedd3461869f973f8d621a39e6ad4674cbb577551
2021-08-05 15:48:26 -07:00
Petr Pchelko
0d75fdb4f7 Use CsrfTokenSet as CSRF token source
Change-Id: I079d2c802d9b48d6abf7f37fa9ef7dafac631345
2021-07-12 14:19:15 -07:00
Bartosz Dziewoński
0feccb0cb1 Rename CSS class 'mw-htmlform-field-autoinfuse' to fit the convention
Rename to 'mw-htmlform-autoinfuse'. This avoids the 'mw-htmlform-field-'
prefix normally only used by HTMLFormField subclasses, and matches the
'mw-htmlform-autoinfuse-lazy' class used in related code.

Bug: T278036
Change-Id: I4a73ec6d5993a7e4f10ef8523eef594a70c9abcc
2021-06-19 15:57:43 +02:00
Thiemo Kreuz
2ba01c7ee7 Remove some more comments that literally repeat the code
… including PHPDoc tags like `@return <type> $variableName`.
A return value doesn't have a variable name. I can see that
some people do this intentionally, repeating the variable
name that was used in the final `return $var;` at the end
of a method. This can indeed be helpful. I leave a lot of
these untouched and removed them only when it's obviously
wrong, or does not provide any additional information in
addition to what the code already says.

Change-Id: Ia18cd9f25ef658b08ad25b97a744897e2a8deffc
2021-06-18 21:23:56 +00:00
Umherirrender
1121757ed7 Allow html form field option 'options-messages' to get parsed
The message keys by 'options-messages' are evaluated with
Message::plain(), but some situation needs Message::parse() to support
templates and HTML formatting in this values.

Bug: T58633
Change-Id: I8f52f21ae2641ddcad1aa85ce6bf14de1a09ab4b
2021-05-28 21:55:09 +02:00
Umherirrender
cf541752e0 Add comment to fall-through cases in switch
Fix new coming sniff
PSR2.ControlStructures.SwitchDeclaration.TerminatingComment

Bug: T182546
Change-Id: I3f8d43c730981d8faaa72910d7f3b58a14a8372f
2021-04-15 17:31:12 +00:00
Reedy
5bb8d031c0 HTMLFormField: Use non namespaced class name rather than static::class
Bug: T277414
Change-Id: I9ba76522932147df098abef48b2a076c2aa81aac
2021-03-19 18:19:20 +00:00
DannyS712
78b8a56114 Remove mentions of mw.htmlform.Checker
mw.htmlform.Checker was removed in 743edb1
and no longer exists

Change-Id: Id269f63fd3ca64a719745868d6df907548c15fad
2020-08-18 06:26:07 +00:00
Nikki Nikkhoui
6b0e9eafe1 HTML Classes stability annotations
Add stability annotations for HTML classes.

Bug: T247862
Change-Id: I4dad7b98213ceceb8c04b24e5d52e6fecadb3538
2020-07-13 14:54:28 +02:00
Bartosz Dziewoński
68cbfcf3ed Use errorbox/warningbox for all HTMLFormField errors
Continuing the work for 441e12f2d9,
which did this for the main HTMLForm errors (grouped at the top of
the form). This handles errors for individual fields.

This fixes the display of error/warning messages on Special:CreateAccount,
and should not break anything else too badly (it helps that most forms
are using OOUI these days).

Bug: T246894
Change-Id: If1ccdff10bebe0c2eeca4c15d82271c9de1af164
2020-03-19 21:29:15 +01:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
Daimona Eaytoy
598c4d7fcb build: Upgrade phan to 0.9.0
Scalar casts are still allowed (for now), because there's a huge amount
of false positives. Ditto for invalid array offsets.

Thoughts about the rest: luckily, many false positives with array offsets
have gone. Moreover, since *Internal issues are suppressed in the base
config, we can remove inline suppressions.

Unfortunately, there are a couple of new issues about array additions
with only false positives, because apparently they don't take
branches into account.

Change-Id: I5a3913c6e762f77bfdae55051a395fae95d1f841
2019-12-07 20:16:19 +00:00
Umherirrender
8752df6592 Use varargs for MessageLocalizer::msg and similar
Bug: T191666
Change-Id: I59f2ae1a96af392026fc106e57d23553003c16b8
2019-10-05 17:47:49 +00:00
Daimona Eaytoy
3439c00073 Suppress PhanUndeclaredProperty for custom properties and phan bugs
And remove the issue from the exclusions list.

Bug: T231636
Change-Id: Iee73ddb554e354abe52d13dcfc453f9a15bb8877
2019-09-14 13:22:54 +00:00
Daimona Eaytoy
7862475b0d Improve various PHP method doc blocks
Follows-up 5eac6d131c.

Change-Id: I92c9d482fd8693a16b3967e763a4eb40b963c562
2019-09-05 18:45:40 +00:00
Daimona Eaytoy
5eac6d131c Unsuppress more phan issues (part 3)
Bug: T231636
Depends-On: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd
Change-Id: I58e67c2b38389df874438deada4239510d21654f
2019-08-31 16:38:55 +00:00
Umherirrender
11c9075767 Adjust type hints in htmlform related classes
The return type of HTMLFormField::loadDataFromRequest to mixed
Some sub classes returning arrays or bools, not everytime strings

HTMLCheckField is working with arrays, so also allow array on getTableRow

Change-Id: I076feea76d8e296f27c8a9fb4cbd9368584ba187
2019-07-05 18:11:53 +00:00
Fomafix
110a5877e9 Use [...] instead of array(...) in PHP comments and documentation
Change-Id: I0c83783051bf35fe785bc01644eeb2946902b6b2
2019-06-17 21:15:09 +02:00
Umherirrender
cb897cbad4 Restore func_get_args in HTMLFormField
Mocking variadic arguments does not work in hhvm

Follow-Up: I066ec95a7beb7c0665146195a08e7cce1222c788
Change-Id: Ic3b689d003a4659abdc4c9344ffd83f24f448912
2019-04-14 15:01:20 +02:00
Aryeh Gregor
7b4489e019 Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints.  This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases).  As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User.  If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args().  Some of the changes are definitely safe, like
functions and test classes.

In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:

* Forwarding all arguments to another function. It's useful to keep
  func_get_args() here where we want to keep the list of expected
  arguments and their meanings in the function signature line for
  documentation purposes, but don't want to copy-paste a long line of
  argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
  arguments individually but want to use them as an array as well for
  some reason.

Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2019-04-12 20:17:01 +00:00
Ed Sanders
9b277fb5da OOUI forms: Remove infusable = false
False is already the default value for infusable.

Change-Id: Ie0e9b7467b7f3f13c45372b38b7b80ba78852e55
2019-03-25 19:00:18 +00:00
Thiemo Kreuz
fa7e5bd901 Avoid expensive array_shift where possible
array_shift manipulates the original array. This is surprisingly
expensive, because it iterates *all* elements in the array and
decrements numeric keys. The code touched in this patch does not need
this restructured new array, but only the individual elements.

Change-Id: Iee28377b2c9930f6de821e041381a1d7564f7633
2018-12-17 11:58:55 +01:00