Commit graph

359 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
Umherirrender
465777f188 Use const keyword for constant list of strings or ints
Also changed visiblity of some to private

Change-Id: I113b040321d27c84fe9b807c162736909e96fb20
2024-09-11 23:16:24 +02:00
thiemowmde
dca4931b42 Make use of the ??= and ?? operators where it makes sense
This touches various production classes and maintenance scripts.
The code should do the exact same as before. The main benefit is that
the syntax avoids any repetition.

Change-Id: I5c552125469f4d7fb5b0fe494d198951b05eb35f
2024-08-26 09:26:36 +02:00
Dreamy Jazz
33ac22c576 Allow ContributionsSpecialPage to accept usemodwiki IP addresses
Why:
* In 19238b429f, the
  ContributionsSpecialPage class was modified to not perform
  queries if the submitted form data was not determined to
  be valid.
* This was necessary to allow IPContributions in CheckUser to
  not run the query if the form was invalid.
* However, this broke looking up contributions from IPs that have
  the UseMod wiki format (i.e. "xxx" instead of the last octet of
  an IPv4 address) because the HTMLUserTextField class does not
  consider these as valid IP addresses.
* Fixing this is necessary to allow looking up contributions from
  these IPs in the contribution pagers.

What:
* Update HTMLUserTextField to have a 'usemodwiki-ipallowed' option
  that when specified as true will allow IP addresses in with the
  UseMod wiki format.
** This is done via the regex used by UserDef::processUser which
   determines if an IP is a UseMod wiki IP
** This option is only used if the 'ipallowed' option is also set
   to true.
* Update ContributionsSpecialPage::getTargetField to specify that
  the 'target' field should allow UseMod wiki IP addresses.
* Add tests for the changes to HTMLUserTextField and also a
  regression test via SpecialContributionsTest.

Bug: T370413
Change-Id: I2b1d981a21c7b85c22a371708776c7ca127dec4c
2024-08-19 16:31:47 +00:00
lwatson
f13ca84307 HTMLRadioField: clean up HTML
Ensure CodexHTMLForm reflects HTML changes made to Codex components,
Radio and Checkbox.

- Changed the top level element from `span` to `div` in HTMLRadioField.
- Update test in HTMLRadioFieldTest.

HTMLCheckboxField already has a top-level `div` so no changes are
needed.

Bug: T370689
Change-Id: I0b7e5369e23b1a95e431014d7b22f3f1064b3dba
2024-08-12 21:02:38 -04: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
Roan Kattouw
6347d8aa68 HTMLForm: Remove use of jquery.chosen in HTMLMultiSelectField
HTMLMultiSelectField used the jquery.chosen library, but only for the
legacy display format, and only if the 'dropdown' option was passed.
There is only one form that passes the 'dropdown' option
(SpecialActiveUsers), and that form uses the OOUI display format, so
this code is unused.

Also remove the htmlform-chosen-placeholder i18n message, which is now
unused as well.

Bug: T53443
Change-Id: Ie4f9fff322ae26fbdf9eae1b3634d1b04e746179
2024-06-13 17:28:37 +00:00
Ebrahim Byagowi
b5727d94b5 Import InvalidArgumentException at top of the source
It was asked in a patch review to apply fully import
InvalidArgumentException where possible. I was guessing some
of my other already merged patches have but turned out such
thing exists other places style so for the sake of consistency
I've turned rest of inline import of the specific exception at
top of the file.

There are instances of source files that aren't in any namespace but
have fully qualified import which this patch doesn't touch.

Change-Id: I4071fc698b65746d9594cf4d5f45bae82843d436
2024-05-19 23:57:44 +03:30
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
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
Roan Kattouw
5c6ffe4383 HTMLSelectNamespace: Add Codex output
The Codex implementation wraps HTMLSelectField.

Change-Id: I4241cb66d531e359534005b774a0951194a79edd
2024-05-05 11:35:18 +03:00
Taavi Väänänen
ed7e787f32
Ignore/fix MediaWiki.Commenting.PropertyDocumentation.WrongStyle
Fix the real issues found by this sniff, and convert the remaining
false positive ignores to per-line ignores so that any more real issues
won't be added.

Change-Id: I18e75d59df327e2d93a3a487c115e92b9f268722
2024-04-22 18:26:14 +03:00
lwatson
218b887049 CodexHTMLForm: Use a static method in getButtons()
Create a static method that returns the HTML for a Codex button.
CodexHTMLForm::getButtons() and HTMLButtonField::getInputCodex()
calls the static method and passes in a list of attributes,
flags, and the button label needed to build the Codex button.

This patch changes the way the Codex submit button is created. In a
previous patch, the submit button was an instance of HTMLSubmitField.

Bug: T361406
Change-Id: I046de61d4808f034335254e9a9c853f133d66a9b
2024-04-09 06:36:24 -04:00
Volker E.
b01148c65a CodexHTMLForm: Learn from OOUI HTMLForm layout styles
- Put select or fields side-by-side and apply form guidelines margin
- Put select and fields underneath with correct margins
- Indent connected components to Radio above visually

Change-Id: I7d262f533122cff5cf6e7be26af40090232c359e
2024-04-04 20:40:46 -07:00
Volker E.
3f99ca0a9c HTMLButtonField: Remove isBadIE()
Was only there for IE 6 & 7, which are gladly not supported in our
infrastructure and codebase for some years now.

Bug: T234582
Change-Id: I111ec7c45f04caf82a796b701baf206ebbc0540b
2024-03-29 22:58:54 +00:00
Daimona Eaytoy
6610a285b6 HTMLRadioField: Fix escaping of options with Codex
`$this->mOptionsLabelsNotFromMessage` is set when calling
`$this->getOptions()`, meaning the previous code wasn't actually seeing
its expected value. Compare with the `getInputOOUI` implementation,
where the ternary is inside the foreach loop.

So, do the same thing for Codex and choose the function to use inside
the loop. Also use the full method name in both cases instead of
indirect calls, as it makes the code easier to analyze statically (also,
the call itself is pretty simple).

Follow-up to I73b2e95cff.

Change-Id: Ie6b626fa4f9822f76bf202c5ed66ec16c17dc422
2024-03-29 04:59:42 +00:00
jenkins-bot
2f8d1c6701 Merge "HTMLForm: Make raw InfoFields work in Codex" 2024-03-28 02:31:50 +00:00
Roan Kattouw
ab33222b47 HTMLRadioField: Escape plain text description messages
Change-Id: I40c7f93ac5ba71a6a3c8a1caa15da6a6be7e331b
2024-03-25 17:39:37 -07:00
Roan Kattouw
f46fba34eb HTMLForm: Make raw InfoFields work in Codex
HTMLInfoField overrides getDiv(), getTableRow() and getOOUI() to output
the raw value if 'rawrow' is set. Override getCodex() too, so that
'rawrow' also works correctly in CodexHTMLForm.

This caused a bug where going to
Special:UserLogin?warning=mobile-frontend-watchlist-purpose would show a
message box that was incorrectly wrapped in a cdx-field div. That seems
to have been harmless, but it's incorrect behavior and could cause
styling bugs in the future.

Change-Id: I1fd4e2e53f9e03561fe300b6924e44cf222db3c9
2024-03-26 00:02:21 +00:00
jenkins-bot
2e857b0d92 Merge "HTMLForm: Add per-option descriptions for Codex radio buttons" 2024-03-25 15:04:29 +00:00
jenkins-bot
eea0901956 Merge "HTMLButtonField: remove hard-coded button flags in Codex" 2024-03-22 02:19:59 +00:00
lwatson
0e399e0957 HTMLButtonField: remove hard-coded button flags in Codex
Adds support for all Codex Buttons by removing the
hard-coded values in the flag class array ($flags).

This patch adds the `cdx-button` class to class
attributes. It maps each flag in `$this->mFlags`
array to the corresponding CSS class name and
appends each flag class to the flag class array.
This ensures that all flag classes defined in
$flags are included in the HTML output.

Flags include 'progressive', 'destructive', 'primary',
and 'quiet'.

Flag classes include:
- cdx-button--action-progressive
- cdx-button--action-destructive
- cdx-button--weight-primary
- cdx-button--weight-quiet

Bug: T359018
Change-Id: I4ceaa3ef484f654bd908479d27ce0d32ed099d86
2024-03-21 21:10:29 -04:00
Roan Kattouw
71c891f948 HTMLHiddenField: Support CodexHTMLForm
HTMLHiddenField does some black magic by outputting nothing and then
adding a hidden field to the form somewhere else. This black magic
wasn't updated for CodexHTMLForm, so it broke on forms that use Codex
(specifically, the login form, where CAPTCHAs are added using
HTMLHiddenField).

Bug: T360717
Change-Id: I2faec05d809b926b2ec2dedaceb7c74a445e06b2
2024-03-21 17:09:32 -07: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
jenkins-bot
4535b1049a Merge "HTMLFormField: Codex CSS-only version of HTMLRadioField" 2024-03-19 21:06:05 +00: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
lwatson
3df492fcca HTMLFormField: Codex CSS-only version of HTMLRadioField
Adds a CSS-only version of Codex Radio via HTMLRadioField.
Iterates through the list of options obtained from `getOptions()`
and generates the HTML markup for each radio input, radio icon,
and radio label. The three elements (input, icon, label)
combined make a single Codex Radio. The Radios are appended to
an empty `$html` string variable. The function returns the
concatenated HTML markup.

Bug: T359015
Change-Id: I73b2e95cff0bc50ba1bc70457d65e286592288ac
2024-03-19 16:07:08 -04:00
Roan Kattouw
40d2280079 HTMLForm: Use rows=10 instead of rows=25 for Codex multiselect fields
The Codex implementation of HTMLNamespacesMultiselectField and
HTMLTitlesMultiselectField falls back to a simple `<textarea>`, which is
also what the OOUI implementation does if JS is not available. However,
OOUI sets rows=10, which results in a much more reasonably sized
textarea then HTMLTextAreaField's default of rows=25.

Pass rows=10 to HTMLTextAreaField, but allow the field params to
override this.

Change-Id: I1e9a1ab6b4a71fb247bfe7861a49bb6cfeb61f54
2024-03-18 11:43:11 -07:00
Anne Tomasevich
891b716e6c HTMLFormField: Use Codex TextArea for multiselect fields
Add support for generating a Codex TextArea via
HTMLTextAreaField, then add Codex handlers to
HTMLNamespacesMultiselectField and HTMLTitlesMultiselectField,
which fall back to a TextArea.

Bug: T359015
Change-Id: I659241f56fae8aa60e25ad0c65b62e8465edad99
2024-03-14 17:06:41 -04:00
Anne Tomasevich
2762f3a89b HTMLFormField: Add Codex version of Select-related fields
This patch enables use of a Codex component for the following
HTMLFormFields:
- HTMLExpiryField
- HTMLSelectAndOtherField
- HTMLSelectField
- HTMLSelectOrOtherField

It also adds a new public static method to HTMLTextField that
takes in attributes and returns the HTML for a Codex text input.

Note that the Codex CSS-only Select does not yet support an
error state, so this has not been implemented here.

Bug: T359015
Change-Id: I6857813b9dbe09ae68d6cafdc87351d01626266a
2024-03-13 10:05:41 -07:00
Anne Tomasevich
8891c5029b HTMLFormField: Refactor Button, Check, and Text handling of Codex
- Refactor the HTMLButtonField, HTMLCheckField, and HTMLTextField
  classes to include getInputCodex() methods, rather than checking
  if CodexHTMLForm is being used.
- Add error classes if applicable.
- For HTMLCheckField, ensure that tooltips are propagated to the
  wrapper div instead of the label, so a tooltip will display no
  matter which part of the component you're hovering over
  (including the space between the input and label text).

Bug: T359013
Change-Id: I0ead69e2b6b33f48949a2dfe40140f2ef957bc06
2024-03-13 10:49:12 -04: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
Agent Isai
fded49bfd7 Add 'maxlength' and 'minlength' support to HTMLTextAreaField
Bug: T347541
Change-Id: If2d5868c23339ecc06fc76a66bc77b41cd10607d
2024-02-15 18:33:17 +00: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
102a4f8a35 build: Upgrade mediawiki/mediawiki-phan-config from 0.13.0 to 0.14.0 manually
* Switch out raw Exceptions, mostly for InvalidArgumentExceptions.
  * Fake exceptions triggered to give Monolog a backtrace are for
    some reason "traditionally" RuntimeExceptions, instead, so we
    continue to use that pattern in remaining locations.
* Just entirely give up on PostgresResultWrapper's resource vs. object mess.
* Drop now-unneeded false positive hits.

Change-Id: Id183ab60994cd9c6dc80401d4ce4de0ddf2b3da0
2024-02-10 02:22:41 +00:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
jenkins-bot
ee60406617 Merge "Remove uses of $wgUseMediaWikiUIEverywhere" 2024-02-05 13:59:51 +00: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
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
jenkins-bot
73dd6f532a Merge "Replace a few array_key_exists with the ??= syntax" 2024-01-16 21:26:28 +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
thiemowmde
9b0f6b568d Replace a few array_key_exists with the ??= syntax
Or just remove it. It's not needed when the structure is already an
array. PHP will happily initialize multi-dimentional arrays when
needed.

Change-Id: I93845e8d6f870d147bd55cfe3827bc94b375d0ba
2024-01-08 10:12:10 +01:00
jenkins-bot
5e3b940db2 Merge "htmlform: Correct validation for file input field" 2023-12-18 16:25:58 +00:00
Ammarpad
d2d7902f4e htmlform: Correct validation for file input field
Bug: T327007
Change-Id: Ibe8a4b2d77b530b9612285e422cbb3eca14d532e
2023-12-18 15:07:19 +01:00
Siddharth VP
ce6bd364b9 Allow setting page restrictions on BotPassword grants
Helps bot operators adhere to the principle of least privileges.

Grants can now be restricted to allow editing (and other write
operations) for upto 25 listed pages. The page IDs are persisted within
the bp_restrictions field of bot_passwords table, and in the session
metadata.

This restriction is checked only as part of expensive checks in
PermissionManager, since they are not applicable for UI actions.

Bug: T349957
Change-Id: I3d228eb97664d040a160c5b742d9176fdfae9a43
2023-12-05 14:51:06 +05:30
Siddharth VP
d72917ea2f Refactor HTMLRestrictionsField to allow more restrictions to be added
Earlier, loadDataFromRequest() returned MWRestrictions object only in
case of valid input, and the original string if invalid. Now, an
MWRestrictions object is returned in all cases, on which we now have a
validity field. This also de-duplicates the check to find the invalid IP
address(es).

Bug: T349957
Change-Id: Iadb762b572cf0e7d2b92dbc4912804a3ddb48e74
2023-11-23 16:01:50 +00:00
Gergő Tisza
de18cff244 htmlform: Support HTML tooltips in checkmatrix
Bug: T290790
Bug: T254222
Change-Id: I69e8217c408acca6bd7f19e7e274b255336dccd2
2023-11-06 23:24:51 +00:00
Siddharth VP
f697560fe0 Unmark HTMLRestrictionsField as stable to extend
This is a composite field meant for a specific purpose, rather than a
fundamental component.

No sub-classes were found in Code Search.

Bug: T349957
Change-Id: Idfb526a341b95322b698a5992b72f5ee8aabf497
2023-11-04 23:42:34 +05:30
Func
1ccb6f0cb1 HTMLSizeFilterField: Keep min/max selection for empty input
Using a flag depends on the *-mode query param, so won't care about
the default value of empty input being 0, empty string, or null anymore.

Bug: T347229
Change-Id: I389adfdf941a8cfd96a68b66120a209b5f38fbbe
2023-09-24 17:48:30 +08:00
James D. Forrester
468e69bccc Namespace Sanitizer under \MediaWiki\Parser
Bug: T166010
Change-Id: Id13dcbf7a0372017495958dbc4f601f40c122508
2023-09-21 05:39:23 +00:00