Commit graph

641 commits

Author SHA1 Message Date
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
Reedy
11cc2d6993 Consistently use @deprecated since rather @deprecated
Change-Id: I301786f35cd6eb9c63fb72e0b64cffa9efd7b86b
2022-03-06 02:55:54 +00:00
Reedy
107fafbf44 HTMLForm: Fix check typo
Change-Id: I101b45d1d64dfa22240c147f5763ec5e89d63206
2022-03-01 04:04:03 +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
jenkins-bot
c6e9511266 Merge "Add dropdown menu to "Tag filter" fields" 2022-02-19 00:49:39 +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
3722dc30d6 HTMLMultiSelectField: Add forced-on options to the output of filter
Forced-on options (selected as default but disabled) should always in
the loaded data, like what HTMLCheckMatrix do.

Change-Id: I342928eca01ae8a9f34ee7156a515524c3a0d9dd
2022-02-09 07:32:12 +00:00
jenkins-bot
c928eb4d46 Merge "HTMLFormField: Treat posted request as a submit attempt" 2022-02-08 23:49:04 +00:00
jenkins-bot
5b471b266e Merge "HTMLFormField: Make the behavior of cond-state consistent between client and server" 2022-02-08 23:41:40 +00:00
jenkins-bot
2a1c1a1be6 Merge "HTMLFormFieldCloner: Provide methods to access the chain of cloners" 2022-02-08 23:41:23 +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
Bartosz Dziewoński
28dd577667 Add dropdown menu to "Tag filter" fields
* Re-use the methods that generate the dropdown for the input in fancy
  recent changes / watchlist filters interface.

* Use ComboBoxInputWidget for the OOUI version, and `<datalist>` for
  the plain HTML version, to add a dropdown menu while still using a
  text field, in case the dropdown is missing items (it's cached) or
  for easy copy-paste.

Bug: T27909
Change-Id: Iad60fb8d9a14e2c67fe9ba365e2ec0768bf5c2da
2022-02-07 23:22:40 +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
Bartosz Dziewoński
97056794fc HTMLForm: Hard-deprecate constructor without $context parameter
It was supposed to become required in 1.19, according to a code
comment (typo'ed in ead9055a).

There seem to be very few uses without the parameter out there (based
on a brief look at https://codesearch.wmcloud.org/), and most of them
are in tests, so they should be easy to find and correct.

Change-Id: I161cc342d1af813c281a6d9e30fdd85bc7b07578
2022-02-03 10:31:13 -05:00
Func
b67c796285 HTMLFormFieldCloner: Provide methods to access the chain of cloners
Needed by follow-up changes, make sure cond-state logic works.

Change-Id: If852a9d13fc7a0d4d67f5c54633d7b8b171b7245
2022-02-03 17:25:15 +08: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
bf6a654379 HTMLFormFieldCloner: Cache form fields for further use
Follow-up changes will use fields more frequently, cache them would be better.

Change-Id: I99dd488a684937b01713663e63d5c3ca68772ef0
2022-01-31 16:19:44 +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
jenkins-bot
d5f143d618 Merge "Add cond-state classes in the server-side" 2022-01-11 22:58:44 +00:00
jenkins-bot
582142cc0e Merge "HTMLFormField: Avoid passing empty CSS class name to OOUI" 2022-01-11 22:58:39 +00:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05: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
Gergő Tisza
499af9ccbe
Rename HTMLForm::[get|set|add]*Text() methods
Rename HTMLForm::[get|set|add][Pre|Post|Header|Footer]Text() to
HTMLForm::[get|set|add][Pre|Post|Header|Footer]Html() and
deprecate the old methods. Their arguments are rendered as raw
HTML so the old name was misleading.

Some of these are marked as stable to override and theoretically
the renaming could cause problems if callers are updated to the
new name while the overriding class is still using the old name,
but the only case known to codesearch is OOUIHTMLForm which is
also updated here.

Bug: T290771
Change-Id: I2c269eb6ab2b320fa2eef4ee8a226e96ad05fbe2
2022-01-02 21:51:48 -08:00
Siddharth VP
061ee25f7e Fix typos in comments (E-H)
Change-Id: I0748e0d5962fa909fdd6b7fcae4ab259bde4cdf1
2021-12-30 18:14:43 +05:30
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
jenkins-bot
9fc104a053 Merge "Allow placeholder to be set for multiselect fields in dropdown mode" 2021-12-16 20:54:58 +00:00
jenkins-bot
5a46f9c44d Merge "Add support for conditional disable fields in HTMLForm" 2021-12-13 22:50:53 +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
Func
81351f6eba Allow placeholder to be set for multiselect fields in dropdown mode
Change-Id: I5d9c15c776e7da6ca1832f5981e6423bc501bab6
2021-12-09 03:03:04 +00:00
Alexander Vorwerk
3aa5b6643b Use LanguageNameUtils constants instead of strings
Change-Id: I8521d00675008da0d7c8c768ab75352212653c66
2021-12-05 22:13:34 +01:00
Reedy
2a2bb1e9bd Remove or replace usages of "sane"
Bug: T254646
Change-Id: I096b2cf738a1395a14f1d47bcbed0c2c686c2581
2021-11-22 13:35:17 +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
C. Scott Ananian
df3cc40fac Rename ParserOutput::{allow,prevent}Clickjacking() -> ::{get,set}PreventClickjacking()
This name is consist with the rest of the setter and getter methods
in ParserOutput.  Renamed the methods in OutputPage, ImageHistoryList,
ImageHistoryPseudoPager, and ContribsPager as well for consistency;
it also makes chasing down lingering references in codesearch easier.

Soft-deprecated the old name for 1.38.  Hard-deprecation will follow,
but there are a number of users in production that should be chased
down first.

Code search:

https://codesearch.https://codesearch.wmcloud.org/deployed/?q=(allow%7Cprevent)Clickjacking&i=nope&files=&excludeFiles=&repos=

Bug: T287216
Change-Id: I9822c60c180d204bd30cb4447a1120155d456da4
2021-10-01 14:13:47 -04:00