Commit graph

225 commits

Author SHA1 Message Date
James D. Forrester
eeb5a740b3 Namespace Message, move to appropriate directory
Bug: T353458
Change-Id: I088cbc53fbcdb974e5b05b45a62e91709dacc024
2024-02-14 15:10:36 -05: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
TheresNoTime
2466abb518 EditRecovery: Add user preference
Add a user preference to allow the user to enable or disable
EditRecovery.
Set the default as disabled.

Bug: T350653
Change-Id: Ibbb59eb84f1dd0b40f9576e048f2ac76044f9014
2024-01-23 13:28:31 +00:00
Daimona Eaytoy
2520f3d1c4 Replace more usages of deprecated MWException
Bug: T328220
Change-Id: Ie9b56bcf5e962e275d80570cad98d676da505894
2024-01-19 22:01:12 +00:00
jenkins-bot
7057d995bc Merge "Add support for conditional user defaults" 2024-01-09 04:42:53 +00:00
Martin Urbanec
6c8b696020 Add support for conditional user defaults
Why:
Sometimes, it is necessary to have different behavior
for newly registered and existing users. For example,
this happens in the Echo or GrowthExperiments extensions.
As of now, this behavior is implemented by inserting
user_properties rows in onLocalUserCreated.

Over time, this results in a singificant amount of rows
inserted, which contributes to the user_properties table bloat,
which is already overly large (cf. T54777). This patch makes it
possible to remove such rows by supporting conditional defaults
for user properties.

What:
Add support for conditional defaults of user properties. This can be
configured via `ConditionalUserOptions` config option.

Bug: T321527
Change-Id: I1549c3137e66801c85e03e46427e27da333d68e2
2024-01-09 02:33:17 +00:00
Dogu
137d046c12 Replace all the OOUI qualifiers with imports
List of affected classes:
- TablePager
- DefaultPreferencesFactory
- SignatureValidator
- SearchFormWidget
- SpecialUndelete

Change-Id: I63ba23108adb16ee4f8b0f965b05605c70ff7957
2024-01-07 21:17:57 +00:00
Martin Urbanec
29af4dd074 Move user options related classes into its own namespace
There are a couple of user options related classes already,
and the T321527 work on dynamic defaults is going to add
even more. Let's move them into a separate namespace
to make core a bit more organized.

Old name is kept as an alias for compatibility purposes.

Bug: T321527
Bug: T352284
Change-Id: I9822eb1553870b876d0b8a927e4e86c27d83bd52
2023-11-29 13:27:13 +01:00
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +00:00
James D. Forrester
3851805f64 Namespace remaining User-related classes under \MediaWiki\User
Bug: T166010
Change-Id: Ibda1e8be0f23c6262a32b607f8260cad36f188fc
2023-09-20 09:12:08 +01:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
James D. Forrester
a8a6cfd966 Namespace NamespaceInfo under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: Ibe103cd362535d3cb94cb8931e95fc74099d1497
2023-09-19 05:17:04 +00:00
James D. Forrester
459cbb0494 Namespace remaining 'specialpage' files under \MediaWiki\SpecialPage
SpecialPageFactory is already here, but none of the others were yet.

Bug: T166010
Change-Id: I9689bf0a1ab329625e23669b99f019b96295fffd
2023-09-18 18:23:13 +01:00
jenkins-bot
fbaea9b19c Merge "Add an option to allow users to always enable safemode" 2023-09-15 16:55:00 +00:00
James D. Forrester
0c0d8777a8 Namespace SpecialW* under \MediaWiki\Specials
This completes the namespacing of core special pages.

Change-Id: I195e7fc34a9413bfea0a33c941f2362cd4a7ff10
2023-09-15 09:01:31 +01:00
Dringsim
e944a2b764
Add an option to allow users to always enable safemode
Merge code from https://github.com/miraheze/MirahezeMagic/pull/399

Bug: T342347
Change-Id: I6f2d024c01cdb1d7305ff024996175eb2656d0a8
2023-09-08 11:58:04 +08:00
Amir Sarabadani
d8e542abf9 Reorg: Move three output related classes to includes/Output/
And namesapce them:
 - StreamFile
 - OutputHandler
 - OutputPage

Bug: T321882
Change-Id: Iedf8d88c595e580f2d8f0734c92aa5c45618ba33
2023-09-05 19:36:42 +01:00
Amir Sarabadani
f4e68e055f Reorg: Move Status to MediaWiki\Status\
This class is used heavily basically everywhere, moving it to Utils
wouldn't make much sense. Also with this change, we can move
StatusValue to MediaWiki\Status as well.

Bug: T321882
Depends-On: I5f89ecf27ce1471a74f31c6018806461781213c3
Change-Id: I04c1dcf5129df437589149f0f3e284974d7c98fa
2023-08-25 15:44:17 +02:00
Umherirrender
be67b9ba05 build: Remove unneeded newline from one line condition/foreach
Improve readability

Change-Id: I22ed08bbd8d821c4d4df620af4c5e97b043c305a
2023-08-22 21:49:58 +02:00
Umherirrender
1796dc225c preferences: Pass ParserFactory to DefaultPreferencesFactory
Bug: T343070
Change-Id: I10307ba3b76bc7b86617dbe2c4da6d745a73fdbe
2023-08-14 17:05:56 +00:00
Lucas Werkmeister
dedc1f3176 Use formatversion=2 for “account data from this project” link
This should make the output slightly more human-readable (mainly by
having actual booleans instead of empty strings).

Change-Id: Ia77064156b5e50ea9953dfdbca2cf6302c480421
2023-07-26 21:31:37 +02:00
Tim Starling
2b608a35ed Add an API-only user preference for diff type
* Add an API-only user preference for diff type
* Retain query parameter stickiness but fix it so that the diff-type
  from user preferences does not leak into the query string. So the
  no-JS control continues to work. If a no-JS user has the inline
  preference set, respect it on the initial load, but add an explicit
  diff-type=table to the query string of the table link so that the
  preference can be overridden.
* Get the diff type from the initial state of the no-JS button. Infuse
  the widget to access the active property using the OOUI public API.
* For a logged-in user, when the JS toggle is clicked, fetch the new
  diff body and update the user preference.
* For an anonymous user, when the JS toggle is clicked, update the
  prev/next links to include the correct diff-type query parameter.

Bug: T336713
Change-Id: Ie409d79ac8222dfa6ec8fd170b76be088be80b3a
2023-07-25 10:49:51 +10:00
Func
df8a2e83e0 DefaultPreferencesFactory: Make UserOptionsManager variable as protected for GlobalPreferences
Bug: T298003
Change-Id: I7cca1fcdc54ef92017184033f36d842830590f14
2023-07-12 20:41:46 +08:00
Func
ceca304e2a DefaultPreferencesFactory: Fetch array-type preferences in a general way
Use method in the class of respective fields to generate preferences keys, don't bother to handle every type of field.

Not only for the follow-up changes in the relation chain, but can also make use of any possible customized fields easier.

Bug: T224701
Change-Id: I5ea2f350c373673f5dba7720bbdcb76960d7c121
2023-07-10 15:52:58 +00:00
Daimona Eaytoy
7340a7fdf9 Replace usages of deprecated UserGroupMembership::getLink()
Bug: T183174
Change-Id: I34f40bd88404cfb7826dfd4d0ef3d662f6091c65
2023-05-20 21:21:19 +02:00
Daimona Eaytoy
43fb8de838 language: Annotate list() methods as preserving taintedness
The $list parameter to the various *list() methods is not escaped by
these methods, so any taintedness in the argument is preserved by the
method and kept in the return value. taint-check has troubles figuring
this out on its own due to T274780, so annotate the parameters.

Note: once this is merged, taint-check could start failing on some
repos. Any errors would have a decent chance of being true positives.

Bug: T253879
Change-Id: I6cf56aca9760370cbeae19879e6b170b1cbd273f
2023-05-20 11:39:55 +02:00
Umherirrender
c5864e92d9 preferences: Simplify handling of watch preferences for actions
The items in the list $watchTypes are checked with User::isAllowed,
no need to do that before adding to the list.
Except the watchcreations, where more userrights are checked.

Move delete action to the end of the list

Change-Id: Ic0db2708f845bed7d83d720c1ce4a00ee40b63b3
2023-05-01 14:43:18 +02:00
thiemowmde
d47215586c Make use of MainConfigNames references in a few more places
Change-Id: I29499c29e7f8c6ca7627b130b1fe648e79100582
2023-04-21 11:11:44 +02:00
jenkins-bot
562f3e3e5b Merge "preferences: Only show the "responsive mode" setting for relevant skins" 2023-03-27 16:50:01 +00:00
Tim Starling
580ec48e5b Fix more PHPStorm inspections (#2)
* Illegal string offset and invalid argument supplied to foreach, due to incorrect type information
* Array internal pointer reset is unnecessary
* $hookData unused since MW 1.35 due to incomplete revert
* array_push() with single element
* Unnecessary sprintf()
* for loop can be replaced with str_repeat()
* preg_replace() can be replaced with rtrim()
* array_values() call is redundant
* Unnecessary cast to string
* Unnecessary ternary. Often the result relies on short-circuit evaluation, but I find it more readable nonetheless.

Change-Id: I4c45bdb59b51b243fa96286bec8b58deb097d707
2023-03-25 00:19:58 +00:00
Func
c2ce7588aa preferences: Only show the "responsive mode" setting for relevant skins
Bug: T291656
Change-Id: I76376aa2680a2d9de853c3efb90aecae5c9661f1
2023-03-23 22:40:03 +00:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
Amir Sarabadani
7d8768e931 Reorg: Move HTML-related classes out of includes/ to Html/
Bug: T321882
Change-Id: I5dc1f7e9c303cd3f5b9dd7010d6bb470d8400a18
2023-02-16 20:40:01 +01:00
Func
040eb0f676 Move validation of timezone to HTMLTimezoneField
So that the validation can benefit all use cases.

Bug: T320296
Change-Id: Ie667fd53656d4553096691a69a68786571a49eb8
2023-01-19 22:43:59 +08:00
Tim Starling
7b3e7c017a Respond to some messages from Phan on PHP 8.1
* ForkController, OrderedStreamingForkController: indeed pcntl_fork()
  can't return false.
* RL\Image: Specify type instead of using suppression, since the issue
  name changes.
* VueComponentParser: Accept complaint about nullable nodeValue.
* Disable PHP 8.0 polyfill stubs when running on PHP 8.0+ to avoid
  duplicate interface errors.
* Add Socket stub and use it in LegacyHandler instead of multiple
  existing suppressions.
* MemcachedPeclBagOStuff: accept complaint recommending !$result over
  $result === false when the type is boolean.
* MemcachedPeclBagOStuff: fix probable bug, ignoring errors from
  Memcached::getMulti(). Phan noticed that $res=false was unreachable,
  but it should probably be reachable.
* DatabaseMysqli: accept complaint that $this->conn->errno is already
  known to be an int. It was probably a hack for some previous version
  of Phan.
* BcryptPassword, MWOldPassword, MWSaltedPassword: accept complaint that
  the !is_string() checks are unnecessary, after code review of PHP.
* Pbkdf2PasswordUsingHashExtension: note that contrary to Phan's
  suggestion, this check is necessary.
* DefaultPreferencesFactory: remove an existing hack for
  array_diff_key(), no longer necessary on 7.4 and causes an error on
  8.1. Use coalesce instead of cast for the remaining
  array_intersect_key() hack since it better shows that we are casting
  away null.
* FullSearchResultWidget: fix likely bug involving strict comparison
  between a float and an int.
* SpecialWatchlist: accept complaint that $selectedHours is
  unconditionally a float, being the return value of round(), and thus
  the cast is unnecessary.
* Add stub for AllowDynamicProperties, resolving an error in User.php.
* Xml: accept complaint that $encMonth is already known to be an int.

Six errors remain. These need suppressions or otherwise conflict with
PHP 7.4 support.

Bug: T322278
Change-Id: Ie375bbc8ccf22330b9a169e8da98f2bbe26ec8b9
2022-11-03 16:25:43 +11:00
Matthias Mullie
ea6c1ceebb Add preference to control Special:Search thumbnails
Bug: T320337
Change-Id: I828dcd3679a4869b3b58b05d7cdca6c9f8a45d3e
2022-10-17 13:48:12 +02:00
Bartosz Dziewoński
ac26b64d97 preferences: Show errors about invalid timezone instead of silently correcting
Bug: T320296
Change-Id: I8048780f180aa9a1d85244745b6c95c17ad94c63
2022-10-08 18:59:44 +00:00
jenkins-bot
bb2fc938e5 Merge "Fix logic for formatting negative timezone offsets" 2022-10-07 16:39:42 +00:00
Func
049d304dc2 preferences: Use 'timezone' type for the 'timecorrection' field
The GlobalPreferences extension are using types for the denylist and
classes for the allowlist, while every derivative class of HTMLFormField
defined in the core have a valid type registered.
So, we should use type instead of class here, which all the other fields
did.

Bug: T320238
Change-Id: I1cc59eaf6ed8ac1505eb79c6ecfc7f137c8e17a8
2022-10-07 12:42:59 +00:00
Daimona Eaytoy
b6431b5caf Fix logic for formatting negative timezone offsets
As described on the task, floor() returns the closest integer to the
left, and so it's not the right choice in this case for negative
offsets.

Put the logic in a static method of the UserTimeCorrection class so that
it can be reused elsewhere without making the previous mistake, and add
tests for it.

Also update a comment in UserTimeCorrection, as a follow-up to
I99a00dff7e3319ce45883191daee16bec1ed68ba.

Bug: T318455
Change-Id: I9acc8fa278d5a58a1d56c28c9e8b3f9093f8add9
2022-09-23 22:35:11 +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
f2bbe611e1 Merge "Update docs for HTMLFormField::validate() to permit all data types" 2022-09-23 00:13:28 +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
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
jenkins-bot
f312848695 Merge "Bury the reset preferences link" 2022-05-13 22:53:52 +00:00
Nicholas Ray
ad60752204 Add optional link to project talk page next to a skin's listing
Vector-2022 skin requires that a link to the desktop improvements page
is shown next to the "Preview" link in the skin preferences options.
This allows the ability for other skins to add a link as well.

Bug: T307113
Change-Id: I4e944504f013344661d0c6f05896a4fc1fe8f4b4
2022-05-13 09:57:30 -06: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