Commit graph

70 commits

Author SHA1 Message Date
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Amir Sarabadani
f5abfb8d58 Bump codesniffer to 42.0.0
Most noisily, this enables MediaWiki.Arrays.OneSpaceInlineArray.

Change-Id: I8ab11399c67ce7e3ab1b6249b591452774393428
2023-09-27 15:06:32 -04: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
94ece673b2 Namespace TitleValue under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: I4c901d5c32696d8334ec30cede7d9b6f3d8d645e
2023-09-18 18:24:39 +01:00
Amir Sarabadani
5bd33d46ef Reorg: Move WebRequest to includes\Request
This has been approved as part of RFC T166010

Bug: T321882
Change-Id: I6bbdbbe6ea48cc1f50bc568bb8780fc7c5361a6f
2023-09-11 21:44:34 +01: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
Daimona Eaytoy
ff8561cea9 Mock PermissionManager in WatchActionTest to avoid DB access
This test ends up calling PermissionManager::getUserPermissions, which
calls UserGroupManager::getUserEffectiveGroups, which tries to access
the DB. Since WatchActionTest is not in the Database group, this will
fail after I96ecf9ffd5fbf18db3e15e8774f7dc2fe5b9fd2a.

The test doesn't care about permissions, but only about whether the user
is logged-in, and the check for that happens before PermissionManager is
used (in Action::checkCanExecute). Therefore, we can simply set a mock
PermissionManager to avoid DB queries.

Change-Id: Idcc68b0dea662792f0fd87a8f2052573ad64d003
2023-08-26 02:08:04 +02: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
Daimona Eaytoy
d3243571d0 Fix DB usage in non-database tests (part 2)
Mock the relevant services that need the DB instead, when possible. When
not possible, e.g. because DB access is needed for the test to make
sense, add the test to the Database group instead.

Change-Id: Iefbfe00bedc243906c6b860572568343268646cc
2023-08-06 22:57:28 +00:00
Umherirrender
a3dc761a0c tests: No hook clean up needed on tearDown in WatchActionTest
With the use of setTemporaryHook the clean up is handled in parent class

Bug: T335536
Change-Id: Idcb5c230c0173116bcca70516d77a8c91cbc4026
2023-04-27 22:05:19 +02:00
daniel
2016418bc5 Make $wgHooks trigger deprecation warnings.
This will allow us to treat $wgHooks as a normal config
variable in 1.41.

Note: should be backported to 1.40

Bug: T331602
Change-Id: Iddcb760cf8961316d6527e81b9aa968657d8354c
2023-03-29 07:29:37 +00:00
Tim Starling
5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +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
523ab7cff8 Reorg: Move RawMessage to under language/
To follow Message. This is approved as part of RFC T166010.

Also namespace it but doing it properly with PSR-4 would require
namespacing every class under language/ and that will take some time.

Bug: T321882
Change-Id: I195cf4c67bd51410556c2dd1e33cc9c1033d5d18
2022-12-16 11:30:19 +01:00
Zabe
f6b9381d7f Revert "Reorg: Move some of request related classes to MediaWiki/Request"
This reverts commit 2bdc0b2b72.

Reason for revert: T166010#8349431

Bug: T166010
Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
2022-10-27 13:14:16 +00:00
Amir Sarabadani
2bdc0b2b72 Reorg: Move some of request related classes to MediaWiki/Request
Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequest
 - WebRequestUpload

Bug: T166010
Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
2022-10-26 16:49:10 +02:00
jenkins-bot
92e8310168 Merge "Add "1 year" to watchlist expiry" 2022-09-08 02:21:10 +00:00
NovemLinguae
aad407bb3e Add "1 year" to watchlist expiry
When $wgWatchlistExpiry = true and a user adds a page to their
watchlist, they are currently presented with a combo box where they can
pick a duration of permanent, 1 week, 1 month, 3 months, and 6 months.

This patch adds 1 year to the combo box, and raises the maximum age to 1
year. `api.php?action=watch&expiry=1 year` will now also work.

Bug: T313255
Change-Id: Ia84d6f99584ae23feea3831499d5baee2dd1a024
2022-08-13 00:50:05 -04:00
C. Scott Ananian
35cb2e524b tests: don't assume wgLanguageCode is 'en'
Change-Id: Ic748489309a1c8ff0f916b3f55aacc93ca128ea3
2022-07-21 19:32:41 -04:00
Derick Alangi
a3a2ed268a tests: Use overrideConfig(Value|Values) where needed
This patch covers: tests/phpunit/includes/actions/ and
tests/phpunit/includes/api/.

Change-Id: I60d8fb7b8a63b423606db935fa0d24cf859b2512
2022-07-12 22:24:50 +00:00
Umherirrender
047c184bfe tests: Use Title::makeTitle instead of Title::newFromText
Avoid parsing known titles in tests to improve performance

Change-Id: Ibfccfe696f0b8bfda0b99abae324e60bbecef7d8
2022-07-06 00:44:00 +02:00
Umherirrender
8b1a3d13eb tests: Use WikiPageFactory to create WikiPage object
Bug: T259948
Change-Id: I9afcf3b845306f81ee5ca156553256e6c38df3a0
2022-06-26 23:21:02 +02:00
Tim Starling
6c1f5462f7 TempUser UI tweaks
* In PermissionManager, if a user is anonymous but temporary user
  creation is possible, grant elevated permissions at RIGOR_QUICK rigor
  level. This is mostly to make skins show "edit" instead of "view
  source" to anonymous users in the recommended permissions
  configuration.
* Present temporary users as if they are not logged in in various places
  in the interface: create/move permissions errors, login, preferences,
  watchlist, BotPasswords, ChangeEmail, ResetTokens.
* Show a warning on login/logout about loss of access to the temp
  account.
* On login, don't show the temporary name as a suggestion for the login
  username.

Change-Id: Id0d5ffa46c3ca5c7b30d540cedbaa528b682aa85
2022-04-26 14:34:08 +10:00
daniel
e239b02a5e Add convenience methods for asserting status.
This ensures that assertions work in a uniform way,
and provides meaningful messages in cause of failure.

Change-Id: Ic01715b9a55444d3df6b5d4097e78cb8ac082b3e
2022-03-16 22:44:25 +01:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Cindy Cicalese
b0c0a934e4 Remove hard deprecated Watchlist methods in User, Title, and WatchAction
Bug: T292464
Change-Id: Ie9cb3036a69810344971c49c424a76c7fa1cba07
2021-10-04 15:14:24 -04: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
DannyS712
54faf584e5 Inject services into WatchAction and UnwatchAction
Bug: T253078
Change-Id: Ia2ea119bf54ecd8c169dbc3774571a3f371750b4
2021-07-29 02:08:05 +00:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
Petr Pchelko
0d75fdb4f7 Use CsrfTokenSet as CSRF token source
Change-Id: I079d2c802d9b48d6abf7f37fa9ef7dafac631345
2021-07-12 14:19:15 -07:00
vladshapik
860ac3bbc8 Hard deprecate WatchAction::getWatchToken
Bug: T265944
Change-Id: I1f7f0cdfa59d421b1f0f29fe9aba906dde4e5bf1
2021-06-23 17:20:22 +00:00
jenkins-bot
e76972fa54 Merge "Hard deprecate watchlist methods in WatchAction" 2021-05-05 17:24:55 +00:00
DannyS712
7fb6c856ad Introduce DummyServicesTrait for use in unit tests
Shared trait to create services in unit tests to reduce
the mocking needed, beginning with a mock WatchedItemStore.
While this doesn't have everything a full WatchedItemStore(Interface)
supports, it does properly handled the following methods
* getWatchedItem
* addWatch
* removeWatch
* isWatched
* isTempWatched
and properly differentiates between different users and titles,
something the existing mocks in WatchActionTest and
WatchlistManagerTest did not.

Change-Id: I487354542f5322478b9e2c0383cad86453bd5f3e
2021-05-03 19:04:06 +00:00
Cindy Cicalese
169b7fd3bd Hard deprecate watchlist methods in WatchAction
Bug: T280750
Depends-On: Ib8bf129a8f31ca054a74a9ec07a1ca0f7ac3e68c
Depends-On: Id3b048ac654d617d96e2602ad63e9380f2bfc726
Change-Id: Ib884f3313486ae96ade0389340bc037e70cbee56
2021-04-28 14:02:34 -04:00
Thiemo Kreuz
c1ee8250e9 Remove unnecessary ->equalTo() from tests
This is the default anyway when using ->with(). The test code
becomes so much more readable without this, I would like to
argue. Let it just say "with these values".

Because of the way I split my changes into multiple patches
there are a few other changes in this patch I could not split,
e.g. removing unnecessary ->any(). This is the default anyway
and doesn't make the test more specific.

Change-Id: I34990799fa9258ba8dc64c7e78ec43f7903b7681
2021-04-23 12:02:42 +02:00
jenkins-bot
c67dddf9c2 Merge "Use WatchlistManager instead of User in WatchAction" 2021-04-19 03:40:38 +00:00
Cindy Cicalese
6bf0a0d3ef Use WatchlistManager instead of User in WatchAction
Change-Id: I69b40bdc6168a9a0afeb7fed7494415788b1c8b8
2021-04-19 01:49:47 +00:00
Daimona Eaytoy
535d7abf59 phpunit: Mass-replace setMethods with onlyMethods and adjust
Ended up using
  grep -Prl '\->setMethods\(' . | xargs sed -r -i 's/setMethods\(/onlyMethods\(/g'

special-casing setMethods( null ) -> onlyMethods( [] )

and then manual fix of failing test (from PS2 onwards).

Bug: T278010
Change-Id: I012dca7ae774bb430c1c44d50991ba0b633353f1
2021-04-16 20:15:00 +02:00
Petr Pchelko
07b63105ec WatchAction:doWatchOrUnwarch - use Authority
Change-Id: If3ed65093ea6db99fbd1314104e530163fb6a46b
2021-03-03 23:25:23 -07:00
Petr Pchelko
4f0e8b038e Use context Authority in Actions for permission checks
Change-Id: I54ee99098a39bf28646d61689b8e6e5a5d7c3c68
2021-02-22 15:07:28 -07:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Cindy Cicalese
f992c7d8a3 Add type hints for return types to methods on UserIdentity
Bug: T273285
Change-Id: I0ffc4963e8362264d1f10455af0f6222c05be7d8
2021-02-02 20:58:51 +00:00
DannyS712
6a93b0ca93 More misc test cleanup
* parent::setUp() should be first, and ::tearDown()
  should be last
* Move tests that directly extend PHPUnit\Framework\TestCase
  to /unit

Change-Id: I1172855c58f4f52a8f624e6d596ec43beb8c93ff
2020-12-24 00:52:06 +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
Dayllan Maza
dd829e11c2 Fix invalid watchlist expiry options
Watchlist expiry options are stored in a translatable
message that can potentially be malformed or contain invalid
strings representing time periods.

This patch addresses the following:
 * Checks that the dropdown options are valid strings
   supported by strtotime()
 * If no valid options are found it falls back to english
 * If a wiki decides to have their own time periods, it
   picks the first one from the list and sets it as the
   default option in the dropdowns

Bug: T267611
Change-Id: I072a49f1ec4901c8421d2687e14af10c91802668
2020-11-16 17:21:03 -05:00
Umherirrender
5d41326891 Use ::class together with createMock in unit tests
This makes it easier for IDEs to find usage
This works even for non-existing classes

Change-Id: I4a6389a9bc0b3c212633841d69bd4f48a7ed6f56
2020-10-30 14:45:37 +01:00
hmonroy
45bb027122 Normalize WatchedItem expiry field
Normalize watchlist expiry field so that it is set to
ConvertibleTimestamp and the expiry value validation is
handled by the WatchedItem class.

Bug: T260868
Bug: T260009
Change-Id: I3ef31900cfbe7bce23c5ebe1db777a5137ea6167
2020-10-06 13:00:50 -07:00
Sam Wilson
3a5881fd64 Use localized success message after watching via action=watch
Use the localized array key rather than the canonical English
array value when retrieving the watchlist-expiry options, so
that the correct language is used in the success message
when watching a page via ?action=watch.

Also add tests for all eight possible messages displayed on this
screen.

Bug: T262547
Change-Id: Ia92266f13d226f6f83199593d5a0f9697ef8a870
2020-09-17 16:28:58 +08:00
Sam Wilson
3b71d54bc4 Check existing watchitem when saving action=watch
When watching via action=watch, there's no need to
save if nothing has changed. This is already how
EditPage does it (by calling WatchAction::doWatchOrUnwatch())
so this change emulates that and also calls
doWatchOrUnwatch() when saving the watch item.

The format that's used in the expiry dropdown (in action=edit
and action=watch) is also changed to ISO8601 so that it
includes a timezone specifier and removes any ambiguity about
what timezone it is in.

The minor change to $changingWatchStatus is just to keep it as
a boolean and not turn it into an int.

Bug: T260009
Change-Id: If94ea7394588646abdac9a5025b0c8903366b521
2020-09-09 14:39:07 +08:00
jenkins-bot
cbdefbef48 Merge "Update language in watchlist expiry" 2020-08-17 20:56:24 +00:00