Commit graph

686 commits

Author SHA1 Message Date
jenkins-bot
1e60c7337a Merge "Create an HTMLForm field for selecting a timezone" 2022-09-23 18:16:06 +00:00
Daimona Eaytoy
ec09c19fba Create an HTMLForm field for selecting a timezone
This patch introduces HTMLTimezoneField, an HTMLForm field type that
allows the user to select a timezone, either from a geographic zone, by
manually entering an offset, or using the wiki/browser default. This
logic is extracted from DefaultPreferencesFactory so that it can be
reused elsewhere.

The widget itself is really just an HTMLSelectOrOtherField, it's just
the list of options and the JS logic that is special.

Bug: T309629
Change-Id: I99a00dff7e3319ce45883191daee16bec1ed68ba
2022-09-23 18:35:51 +02:00
jenkins-bot
f2bbe611e1 Merge "Update docs for HTMLFormField::validate() to permit all data types" 2022-09-23 00:13:28 +00:00
jenkins-bot
4e3deb4d93 Merge "Remove unneeded initalize of local variables" 2022-09-22 23:41:08 +00:00
jenkins-bot
61a9b38861 Merge "Simplify timezone-related code for user preferences" 2022-09-22 22:57:43 +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
eb159d8f5a Remove unneeded initalize of local variables
The variables are set conditional later, but all condition branches set
it or the variable is not used outside that scope

Change-Id: Ic9612915db507028ad4733a061d3ce9be3babfb6
2022-09-21 21:29:21 +02: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
Daimona Eaytoy
090599c048 Simplify timezone-related code for user preferences
This patch simplifies and fixes a few issues in code related to the
'timecorrection' user setting:
- Always re-apply UserTimeCorrection normalization to the preference
  value, although it should be already normalized
- Avoid duplicating code from UserTimeCorrection, both for the
  pipe-splitting and the offset computation/fallback
- Use better variable names
- Inject an ITextFormatter for generating the dropdown options, instead
  of a ContextSource (ew) or a Language, removing calls to wfMessage as
  well. Note that the ITextFormatter is not injected into the
  preferences factory because the eventual goal is to move the code to a
  new HTMLFormField class.
- In TimezoneFilter, remove a redundant check: the value comes from the
  form, and the option for using the system time is always "System|XXX",
  never just "System". This seems to have been introduced in
  I2cadac00e46dff2bc7d81ac2f294ea2ae4e72f47; the previous code was only
  comparing $data[0], and not $tz. Change the test accordingly and add a
  test case.
- Add missing star to docblocks in UserTimeCorrection, as well as a
  missing int cast.
- Fix typo and other style issues in UserTimeCorrectionTest
- Bonus: add missing docblock star in HTMLApiField

Bug: T309629
Change-Id: Iab35eb17259826429e4b6bc1ba7385ab57884e98
2022-09-12 12:23:48 +00:00
Gergő Tisza
8756b5c42f Allow returning StatusValue from HTMLForm submit callbacks
Callbacks are documented to return Status, but we use the two
interchangeably almost everywhere, so this eliminates an easy
mistake possibility.

(The more ideal solution would be to allow returning StatusValue
from trySubmit and associated methods, but that's way more effort.)

Change-Id: I6c54b4aceb0430530d22423f8e80ab20a88548b3
2022-08-22 20:43:20 +00:00
jenkins-bot
f6721b237a Merge "Make use of ?? and ?: operators where it makes sense" 2022-08-05 19:20:25 +00:00
jenkins-bot
89bc58d94e Merge "htmlform: Replace deprecated User::getOption" 2022-08-05 01:13:13 +00:00
Thiemo Kreuz
e23b070b45 Make use of ?? and ?: operators where it makes sense
Change-Id: I1d9d62d80b17d1a05222c6e82f631cb801c311a8
2022-08-04 21:43:12 +02:00
jenkins-bot
6e6e0093e2 Merge "HTMLUserTextField: Fix validation" 2022-07-20 15:53:59 +00:00
Reedy
32a4629b3d HtmlForm: Null coalescence in trim() calls
Bug: T312305
Bug: T311572
Bug: T311571
Bug: T311578
Change-Id: I89a135d271c981c011360098ca5e98dc5a47ae37
2022-07-16 02:49:14 +01:00
Bartosz Dziewoński
6f95c290c0 HTMLUserTextField: Fix validation
When 'exists' was false (the default), other validation was skipped.

Change the default 'iprangelimits' to allow any range, to avoid issues
with code that relied on the previous broken behavior.

Bug: T177329
Bug: T311948
Change-Id: I55cad7a5395da70105e20ce33e3a8e3834a4f4ad
2022-07-14 02:41:03 +02:00
Mark A. Hershberger
fc0197db59
Don't attempt to use mParent if it isn't set
Seen in

    MediaWiki\Skins\Vector\Tests\Integration\HTMLLegacySkinVersionFieldTest::testGetInput with data set #0 ('1', true)
    Error: Call to a member function getConfig() on null

when run with

    php tests/phpunit/phpunit.php '-c' 'tests/phpunit/suite.xml' '--testsuite' 'skins' \
        '--exclude-group' 'Broken,ParserFuzz,Stub,Database,Standalone'

Change-Id: I0f5d67c122adb922e3212e597a0ce27c7785009c
2022-07-09 22:24:13 -04:00
jenkins-bot
8b6652fb2d Merge "htmlform: Use ContextSource to get config" 2022-07-06 14:55:22 +00:00
Bartosz Dziewoński
8f7cd07af6 HTMLFormField: Fix Phan suppression about mClassWithButton
Change-Id: Ie20fa54de1fcc69913b3881d2efe9192be5b90cc
2022-06-17 21:47:59 +02:00
dreamyjazz
2f022f4843 HTMLInfoField: Ensure ID is included for the 'info' field.
Ensure that the ID is included in the generated label field for
the 'info' type (which is defined in HTMLInfoField.php).
This is needed for a OOUI conversion in the CheckUser extension,
as a JS script relies on an ID being present for a element that
only the 'info' type suits.

Change-Id: If4724e6699aa3ec076817a7c4727cbff184b94e7
2022-06-07 11:51:16 +00:00
jenkins-bot
7dbccf73f7 Merge "Apply ID and class more consistently in HTMLSelect(Or|And)OtherField" 2022-06-06 20:53:22 +00:00
Daimona Eaytoy
bc0db4dcc3 Apply ID and class more consistently in HTMLSelect(Or|And)OtherField
There were several inconsistencies in how ID vs cssclass vs own classes
were applied, both within the same widget + mode, between different
modes for the same widget, and different widgets. So uniform all of them
according to the plan detailed on phabricator. Include
HTMLSelectAndOtherField as well (that wasn't mentioned on phab) for
consistency. Also remove the select-or-other class from
HTMLAutoCompleteSelectField (which was only applied in HTML mode), since
the widget is not technically a SelectOrOther.

Adjust the logic in selectorother.js so that it works fine in HTML mode,
and disable it for OOUI mode since SelectWithInputWidget does that
already (and the field is autoinfused).

Also, in HTMLAutoCompleteSelectField, don't assign an array to
$this->mClass. This happens to be working right now, but it violates the
type definition of the property.

Luckily, according to codesearch this change seems to be
backwards-compatible because these fields are not commonly used, and
nobody seems to be passing cssclass to them.

Bug: T309883
Change-Id: If950f131d1c4bc1645de6021781045dccfc61966
2022-06-06 18:59:29 +02:00
Isabelle Hurbain-Palatin
a2e5997a4c Make "title" the first field in a form, when needed
In a default installation of Mediawiki, the article URLs use the URL GET
parameter "title" to construct the page title (index.php?title=Foo).
When a form is submitted, that parameter is added to the form as a
hidden field. Before this patch, it's added as last element of the form,
which makes the URL confusing. For example, when running a search on the
Lint errors, the URL becomes
index.php?pagename=Test&title=Special%3ALintErrors instead of starting
with title=Special:LintErrors as one would expect.
Note that this is not an issue on wikis that set their article path to
look like /wiki/Foo: in that case, the title of the page is not set as
a hidden field.

Change-Id: Id7c0617166754010cec987158e14ac54ddc94444
2022-05-31 09:46:08 +02:00
Umherirrender
3c05f3abcf htmlform: Use ContextSource to get config
Change-Id: I759e7d23822e6c435ec3d6010bf4e21ace0c9ce8
2022-05-30 11:29:40 +00:00
jenkins-bot
40abc7d834 Merge "Use User::isRegistered for readability instead of ::getId falsy check" 2022-05-23 04:06:10 +00:00
Gergő Tisza
dcd8680cfd HTMLTagMultiselectField: make allowArbitrary really optional
Change-Id: I1ac1d580d86e97b46be05b78af66a22c3a25e3ab
2022-05-22 17:00:27 +00:00
Bartosz Dziewoński
05c9df0066 HTMLForm: Require constructor $context parameter
Using the constructor without the $context parameter was deprecated
in MediaWiki 1.38 in 97056794fc.

Bug: T308407
Change-Id: Id92adde978e70ffd6fa5d4a048d5d45c7ede4bf3
2022-05-19 18:40:53 +00:00
Derick Alangi
7a33e1fbed htmlform: Remove mw1.30 B/C code for autocomplete attribute
Change-Id: I24afbacf21d24887508b8b4a0fa82f03ce4cc63d
2022-05-19 07:32:01 -04:00
Lucas Werkmeister
eb9b2b5d87 Support placeholder in OOUI HTMLComboboxField
In the HTMLTextField parent class, both getInputHTML() and
getInputOOUI() support adding a placeholder in the input, but for the
combobox field, this was lost in the OOUI method. (In the HTML method,
the parent call takes care of it.)

Bug: T307443
Change-Id: Ic5f86bcc22867619d184f08293c6bc03f3df082d
2022-05-16 13:10:14 +02:00
jenkins-bot
f312848695 Merge "Bury the reset preferences link" 2022-05-13 22:53:52 +00:00
Bartosz Dziewoński
fd5357d049 Support namespace dropdown 'in-user-lang' option in HTMLForm and OOUI widget
Change-Id: I3dbb2ec9d3989a1278151090ad81c7fabd3afbde
2022-05-13 20:29:44 +00: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
Umherirrender
49ad716948 Use User::isRegistered for readability instead of ::getId falsy check
Change-Id: I42aab149559e3e899cde6c77af76c66936ed0ef0
2022-04-29 21:15:57 +02:00
Umherirrender
6de7b6a87e htmlform: Replace deprecated User::getOption
Bug: T296083
Change-Id: I7f0e45ce7629d96d4ad38d32880b67da2d995de5
2022-04-29 21:00:40 +02:00
Aryeh Gregor
4a52bf553f Use MainConfigNames instead of string literals, #3
This edition brought to you by:

grep -ERIn $(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | tr
"\n" '|' | sed 's/|$/\n/') includes/

I only corrected a fraction of the results provided by that command. I'm
submitting the partial patch now so it doesn't bitrot.

Bug: T305805
Change-Id: If1918c0b3d88cdf90403921e4310740e206d6962
2022-04-26 14:31:26 +03:00
Umherirrender
a80bc9dd40 htmlform: List all arguments on HTMLForm::factory instead of varargs
Show the arguments and documentation better in IDEs

Change-Id: Ib2e9d8e82146479cf3f427a9aa7b0b4d2df77954
2022-04-02 18:40:30 +02:00
Umherirrender
7aa0884029 phan: Remove PhanTypePossiblyInvalidDimOffset suppression
Make phan stricter about array keys
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T304887
Depends-On: I3105a5fd4826f8667b5232834defc5ec93be32a1
Depends-On: Ie9610a6e83731468311edb3ed17f80fc509de385
Change-Id: I701f12ab94478c3b8e7fd82110ade74a8e6b04ef
2022-03-28 23:26:49 +02:00
Func
ef2e948d31 HTMLForm: Add title field if the action is overridden to script path
Some use cases like HistoryAction prefer the `index.php` form to keep
consistency, so they use setAction( wfScript() ) or something similar.
But the title is missing, so they hack it with manual addHiddenField()
or add a 'title' field in the descriptor. This is not good and prevents
us to warn the use of internal fields (title, wfEditToken).

Bug: T285464
Change-Id: Iaec81a2fb49162f2fc764f143f88e887572a3a0b
2022-03-27 11:51:59 +08:00
Tim Starling
97b8262d1f Use UserRigorOptions directly
Conventionally, public constants are accessed via their declaring
class, except for self:: which is an acceptable shortcut.

Change-Id: If05eab72140267e6ef54736710d751d7f24a7860
2022-03-25 10:06:34 +11:00
jenkins-bot
2f7da6037a Merge "Fix uses of (error|warning|success)box in core" 2022-03-21 20:16:57 +00:00
Umherirrender
1f71eccf63 phan: Disable null_casts_as_any_type setting
Make phan stricter about null types by setting null_casts_as_any_type to
false (the default in mediawiki-phan-config)
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T242536
Bug: T301991
Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
2022-03-21 18:25:07 +00: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
6dd8a2bb32 phan: Disable scalar_implicit_cast setting
Make phan stricter about scalar types by setting scalar_implicit_cast to
false (the default in mediawiki-phan-config)

Bug: T242536
Bug: T301991
Change-Id: Ia2fe30b17804186571722e728578121c8b75d455
2022-03-18 18:52:24 +00:00
Func
cd09bceb67 HTMLForm: Deprecate calling loadData() from outside
There is no reason to use loadData() only, and would unexpectedly skip
some necessary checks in prepareForm().
Some use cases are too old and didn't make use of the show() method
where should be available, which may be addressed in follow-up(s).

Bug: T256805
Change-Id: Ibbdc2c2c2b056342bb2c583a63546ac789b651d8
2022-03-17 04:49:53 +00:00
jenkins-bot
c29d5b3ab5 Merge "Add various null checks when null is not possible to use as argument" 2022-03-14 20:06:20 +00:00
Umherirrender
c259c37033 Add various null checks when null is not possible to use as argument
Also check for false if needed

Found by phan strict checks

Change-Id: I298204653dfb788515a87978dd8705b6e4f9c775
2022-03-14 17:17:17 +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
jenkins-bot
d1cfc0317d Merge "Add explicit casts between scalar types" 2022-03-08 17:32:26 +00:00
Umherirrender
6ea3d6ac2c Add explicit casts between scalar types
php internal functions like floor/round/ceil documented to return
float, most cases the result is used as int, added casts

Found by phan strict checks

Change-Id: I92daeb0f7be8a0566fd9258f66ed3aced9a7b792
2022-03-08 16:59:01 +00:00