Commit graph

232 commits

Author SHA1 Message Date
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
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
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
4e3deb4d93 Merge "Remove unneeded initalize of local variables" 2022-09-22 23:41:08 +00: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
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
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
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
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
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
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
Reedy
107fafbf44 HTMLForm: Fix check typo
Change-Id: I101b45d1d64dfa22240c147f5763ec5e89d63206
2022-03-01 04:04:03 +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
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
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
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
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
Umherirrender
244ea7c0b5 Simplify else-branches after continue/break
When the if branch continues the loop,
than the next branch does not need to be an else branch

Change-Id: Ia158709b7fd2ea811f1049cf8f53ed12c89719e3
2021-08-17 22:51:43 +02: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
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
daniel
39a6e11310 HTMLForm: accept PageReference instead of Title.
Note that this changes the effective type of the protected mCancelTarget
field. This fields has no declared type, and does not seem to be used in
any subclass. The type of mTitle is not changed at this time, but
nothing seems to rely on that either.

Bug: T278459
Change-Id: I4bf0d46c74b53ffc9cb3e6e497c789ef6b3bab6a
2021-05-07 23:36:49 +02:00
Umherirrender
78cc6d77ff build: Swap deprecated @codingStandardsIgnore to phpcs:ignore
Bug: T278594
Change-Id: I09a6175917090593e6e0055203a890c32bea03a5
2021-04-04 21:18:22 +02:00
STran
ee93d068d2 Add HTMLTagMultiselectField
Implements HTMLTagMultiselectField, a form field that instantiates
TagMultiselectWidget, the PHP representation of the OOUI's js-based
widget of the same name with the implemented parameters:
* allowArbitrary
* allowedValues

Bug: T278317
Change-Id: I3a6a30506d493be4185f917c577b3837fffd8ae1
2021-03-26 08:15:38 -07:00
Thalia
420001adce HTMLForm: Fix documentation for tryAuthorizedSubmit
This can return any value returned by trySubmit.

Change-Id: Iaf6a69e44984585337c76f329ac491b2e69fe744
2021-01-22 21:41:22 +00:00
jenkins-bot
524a992458 Merge "Create HtmlFileField" 2021-01-21 23:52:27 +00:00
Ed Sanders
b28809cb16 Create HtmlFileField
Bug: T243476
Change-Id: I21d17de56f753c4f62c17c0baf988e1ca890bfda
2021-01-21 22:55:00 +00:00
Thalia
10e043b9c7 HTMLForm: Add documentation for sections and subsections
Change-Id: I6cc496476e980f0ee0dfd5d6c15e59ef9eb14aa0
2021-01-04 18:15:32 +00:00
James D. Forrester
abdc94a3da Swap out uses of User->isLoggedIn() with ->isRegistered()
Bug: T270450
Change-Id: I90ff94a553ebae9a4ef97c25c333f067f19c327d
2020-12-22 03:13:37 +00:00
Umherirrender
cf8c94b163 Do not assume string is message key in OOUIHtmlForm::getErrorsOrWarnings
single string is raw html,
not a message key as documented on HTMLForm::trySubmit

Also remove is_string, any truthy value would be implicit string casted
in HtmlForm::getErrorsOrWarnings

Reorder the if in HtmlForm to look similar to OOUI

Change-Id: I5b78b0df2cca695f8f5c6b08aa4d6c015d1fa1fe
2020-11-20 14:26:15 +00:00
Thiemo Kreuz
20b2c5000d Make use of array deconstruction directly in foreach, if possible
Deconstructing non-sparse, numerically indexed arrays directly in
foreach (a.k.a. using the list() syntax in foreach) is possible since
PHP 5.5.

The possibility to use string array keys as well as non-sequential
numeric keys in array deconstruction was added in PHP 7.1.

Change-Id: I56a48552a45f61cedc291b306cad8548fc70d485
2020-11-12 18:38:06 +00:00
Umherirrender
c85a43561e Improve class property documentation
Reformat existing documentation to match the format

Change-Id: I190b54b5e962f17bab6502dd1b3c02f11dc926d2
2020-10-30 10:38:58 +01:00
Thiemo Kreuz
1fc8d79ac6 Remove documentation that literally repeats the code
For example, documenting the method getUser() with "get the User
object" does not add any information that's not already there.
But I have to read the text first to understand that it doesn't
document anything that's not already obvious from the code.

Some of this is from a time when we had a PHPCS sniff that was
complaining when a line like `@param User $user` doesn't end
with some descriptive text. Some users started adding text like
`@param User $user The User` back then. Let's please remove
this.

Change-Id: I0ea8d051bc732466c73940de9259f87ffb86ce7a
2020-10-27 19:20:26 +00:00
Bartosz Dziewoński
d8c93b163a mediawiki.htmlform: Ensure collapsible forms are enabled
The code that enables collapsible elements in 'mediawiki.page.ready'
may not run on special pages.

Bug: T260642
Change-Id: I4c5250f5b2575ec6699b99bf979c02e5ac16722d
2020-10-13 22:37:15 +02:00
jdlrobson
741f0800ca Collapsible HTMLForms need to add JS module
Not working on Special:AbuseFilter for example
Skins can disable this module so special pages must
add it explicitly.

Bug: T260642
Change-Id: I51deedf9c60279b0917ab085fd7498edf55e93da
2020-09-15 17:01:46 +00:00
Thiemo Kreuz
d206da0e1e CSS 'class' names can be an array in Html::…element
Change-Id: I301d23066b19051b9e1cb9363639f6189a8b173c
2020-09-08 19:11:19 +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
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00