Commit graph

118 commits

Author SHA1 Message Date
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
Amir Sarabadani
bbe704b5c1 Reorg: Move some of request related classes to MediaWiki/Request
Redoing I5ea70120d74 but without moving WebRequest that caused issues
with phan-taint-plugin.

Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequestUpload

Bug: T321882
Change-Id: I832b133aaf61ee9f6190b0227d2f3de99bd1717b
2022-10-28 10:15:31 +00: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
Tim Starling
43a93d9782 Use the null coalescing assignment operator
Available since PHP 7.4.

Automated search, manual replacement.

Change-Id: Ibb163141526e799bff08cfeb4037b52144bb39fa
2022-10-21 13:26:49 +11:00
jenkins-bot
aafa2e0b04 Merge "tests: Replace deprecated WikiPage::factory" 2022-09-09 16:25:08 +00:00
jenkins-bot
92e8310168 Merge "Add "1 year" to watchlist expiry" 2022-09-08 02:21:10 +00:00
Umherirrender
6555923b08 tests: Replace deprecated WikiPage::factory
Bug: T297688
Change-Id: Ic84d491c5603f3590e26cb56a305508b2b0ca109
2022-09-02 19:34:02 +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
DannyS712
f6291bb43a ActionTest: reduce duplication using data providers, simplify
Convert individual tests into cases for testGetActionName(),
add 'disabled' case to provider for testing action exists
and creation, and use separate data providers for testing
the action name and testing if actions exist/creating them.

Merge single use helper function getTitle() into caller.

Change-Id: I1ec5ca0aa35682e270dded2ee5612fe8ca60efe2
2022-06-20 14:18:01 +00: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
Tim Starling
1ae3b0ca86 Allow ContentHandler to "override" non-existent actions
Flow defines a lot of custom actions which are only implemented for its
own content type. This use case is not what we had in mind when
getActionOverrides() was introduced, but allowing it in ActionFactory
removes the need for Flow to write dummy ignored config to $wgActions.

Bug: T303237
Change-Id: I67c1ae95344b0004eb93023fae7e93de4e47888b
2022-03-08 14:17:22 +11:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Alexander Vorwerk
b6793e47de Make Block objects aware of which wiki they belong to
Bug: T274817
Depends-On: I1c46c712a3afefce56238108cb2e78382dd41956
Change-Id: I8ae8133f7e232cc75aae6b72fcd7feaeb313cba7
2022-01-17 21:49:20 +01:00
Legoktm
93f79a9122 Revert "Replace deprecated methods IContextSource::getWikiPage && IContextSource::canUseWikiPage"
This reverts commit ef458e8948.

Reason for revert: Causes page tabs to disappear on Special:WhatLinksHere.

Bug: T297744
Change-Id: I0ee282a9f7a5a9b2cfdc3261d800d9e27eaf977e
2021-12-14 12:43:15 -08:00
Roman Stolar
ef458e8948 Replace deprecated methods IContextSource::getWikiPage && IContextSource::canUseWikiPage
Bug: T275710
Change-Id: I74b8f76a525793bc029d9ee1f7297b46ac0a9174
2021-11-16 13:58:39 +02:00
Derick Alangi
2c10f768f0 actions: Update deprecated code in Actions::checkCanExecute()
Inspired by T290004, attempting to solve that ticket will be done
in the next patch on this one.

Bug: T290004
Change-Id: I431e3eba1bcfb446a4ab60aa3d2189762ea9f65f
2021-10-28 11:23:32 +01:00
Daimona Eaytoy
55b1c430ed Use expectException() in ActionTest
This way the intent is clearer, and it also properly covers the case
where the exception isn't thrown.

Change-Id: I7831382956d5bc204b695fecc47f7111519d53af
2021-10-28 03:05:43 +02: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
Tim Starling
f7f84dddb3 Introduce CommentFormatter
CommentParser:

* Move comment formatting backend from Linker to a CommentParser service.
  Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
  was used for.
* Rename the "autocomment" concept to "section link" in public
  interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
  static analysis and code review.

CommentFormatter:

* Add CommentFormatter and RowCommentFormatter services as a usable
  frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.

Linker:

* Remove Linker::makeCommentLink() without deprecation -- nothing calls
  it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
  commentBlock() and revComment().

Caller migration:

* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
  ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
  ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
  ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager

Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-09-28 11:13:03 -07: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
5b5763e230 SpecialPageAction: inject action name and SpecialPageFactory
Instead of trying to figure out the name based on the
context, which duplicates the handling in ActionFactory,
make use of ObjectFactory specs' `args` feature to inject
the name.

Also inject the SpecialPageFactory service.

Bug: T253078
Change-Id: Iec223583f93d45184152862d9eee735737453417
2021-07-31 03:43:56 +00:00
DannyS712
54faf584e5 Inject services into WatchAction and UnwatchAction
Bug: T253078
Change-Id: Ia2ea119bf54ecd8c169dbc3774571a3f371750b4
2021-07-29 02:08:05 +00:00
DannyS712
20293e4c99 Add an ActionFactory and start converting to DI
$wgActions used to map string action names to true,
false, a string, a callable, or an object. Now it can also
be an array (that isn't a callable) corresponding to an
ObjectFactory spec for DI.

This patch converts the revisiondelete and rollback actions to
use DI, with the rest to be converted later. The new structure
of $wgActions is fully backwards-compatible.

We don't yet deprecate Action::factory(), ::getActionName(),
and ::exists(), those will be deprecated in a follow-up.

Additionally, we no longer impose a rule that only some
actions can be overridden on a per-article basis via
Article::getActionOverrides().

Bug: T253078
Change-Id: I0fc3c53d671eced1758458f9a0148180b40c6c9b
2021-07-29 01:32:43 +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
Roman Stolar
67cc77312f Update DatabaseBlock construct option 'by' and 'byText' usage to use User Identity only
Bug: T283641
Change-Id: Ic6d4a6e10bda0115c87a85d8a9ddfd4098cd1373
2021-06-02 17:01:32 +03: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
Petr Pchelko
bf6d3c5cf3 Regression tests for ApiRollback and RollbackAction
Bug: T280655
Change-Id: I933b80bbe9bd33ffda68f9a5ab84424cb531abff
2021-04-26 07:58:44 -07: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
jenkins-bot
5015f64940 Merge "ActionTest: no need to save the block to the database" 2021-04-14 09:22:51 +00:00
DannyS712
39e62db589 Remove deprecated code in Action::factory
Action::factory() now requires a string and an article object,
dropping the deprecated support for null as the action name
and a non-article Page object.

Change-Id: I1e73a4638edb6f3aa14822b655d977da177d01bd
2021-03-22 20:42:09 +00:00
DannyS712
3e07bae20c ActionTest: no need to save the block to the database
Use mocks instead

Change-Id: I7d66931d52b22b68dd7c4ecbf509a0b32c33ab13
2021-03-21 19:26:09 +00:00
Petr Pchelko
07b63105ec WatchAction:doWatchOrUnwarch - use Authority
Change-Id: If3ed65093ea6db99fbd1314104e530163fb6a46b
2021-03-03 23:25:23 -07:00
DannyS712
fe54b72b3f Make ViewActionTest a pure unit test
Change-Id: I2845f8021116dfbc894294dc34ac3f1ac26bb9bc
2021-02-27 01:24:18 +00: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
Thiemo Kreuz
b655f382db Remove broken/outdated @param/@throws tags from @dataProviders
My personal best practice is to not document @params when there
is a @dataProvider. I mean, these test…() functions are not
meant to be called from anywhere. They do not really need
documentation. @param tags don't do much but duplicate what the
@dataProvider does. This is error-prone, as demonstrated by the
examples in this patch.

This patch also removes @throws tags from tests. A test…() can
never throw an exception. Otherwise the test would fail.

Most of these are found by the not yet released I10559d8.

Change-Id: I3782bca43f875687cd2be972144a7ab6b298454e
2021-01-21 03:42:42 +00:00