Commit graph

311 commits

Author SHA1 Message Date
DannyS712
c1db64b808 Make use of ??= in more places
New feature from PHP 7.4

Change-Id: Ifa7a9bc7b2ec415ad7ecb23f4c1776f51f58fd6b
2022-12-17 01:10:13 +00: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
Daimona Eaytoy
947ff7c0f5 build: Update mediawiki/mediawiki-phan-config to 0.12.0
This patch only adds and removes suppressions, which must be done in the
same patch as the version bump.

Bug: T298571
Change-Id: I4044d4d9ce82b3dae7ba0af85bf04f22cb1dd347
2022-10-08 15:45:42 +02:00
Bartosz Dziewoński
0fbe063a0c ApiEditPage: Create temporary account on edit attempt if enabled
Bug: T307056
Change-Id: I5a9ccf44f5cf563dfe9c40df22a6153e7d9425d7
2022-09-30 16:20:22 +02:00
Reedy
b4717c2f0d api: Swap wfMessage() for $this->msg()
Change-Id: I5c80a2a36f601a46802170dd4747a32ecc7dffb3
2022-08-13 15:21:29 +01:00
Reedy
f45fefec0e api: Replace numerous more deprecated constants
Change-Id: I498a315b8b4b56d5e2f939e797adbe0487cd7d07
2022-06-06 02:24:41 +01:00
Reedy
0b5084f868 api: Replace numerous deprecated constants
Change-Id: I34ffcb70efbfa257da8dab6e0790aa0d697caf5b
2022-06-06 00:18:50 +01:00
Taavi Väänänen
ac07cc0362 SECURITY: ApiEditPage: update title after redirects
Otherwise permission checks are directed to the old title which makes it
possibly to bypass protection via redirects.

Bug: T309028
Change-Id: I157df365439b09416639e6ea2beefc01b60e6264
2022-06-02 22:48:29 +02:00
Aryeh Gregor
666ca1bdf3 Use MainConfigNames instead of string literals, #2
This covers all occurrences of /onfig->.*get( '/ in includes/.
Undoubtedly there are still plenty more to go.

Change-Id: I33196c4153437778496f40436bcde399638ac361
2022-04-13 18:55:46 +03:00
jenkins-bot
3f11e9a34e Merge "api: Simplify param handling for undoafter on action=edit" 2022-03-30 18:07:47 +00:00
Umherirrender
1d08f5cbfb api: Simplify param handling for undoafter on action=edit
The param is set to min => 0, no extra check needed
Not given parameter are null, but null == 0 is true as well

Found by phan (T259172)

Bug: T259172
Change-Id: I2e4ab82b90370eb9e0f49ce37d680ef4aaddead9
2022-03-30 17:32:01 +00: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
Umherirrender
1f71eccf63 phan: Disable null_casts_as_any_type setting
Make phan stricter about null types by setting null_casts_as_any_type to
false (the default in mediawiki-phan-config)
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T242536
Bug: T301991
Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
2022-03-21 18:25:07 +00:00
jdlrobson
3869cc522b Edits via API should set cookie for anons
Bug: T295910
Change-Id: Ice45db0cb685439603c676f790a146e7e5bb50df
2021-12-17 18:09:36 +00:00
Derick Alangi
8fe9e0317f Introduce Redirect(Lookup&Store) services to handle redirects
The concept of a redirect chain didn't really work for a value of
max redirect > 1. In the ideal world, we just want to have a source
which points to target (source -> target) discarding the concept of
a redirect chain completely.

Having something like: source -> target -> target1 -> target2 doesn't
really work well with the current database design.

NOTE: Support for $wgMaxRedirect will be removed soon hence
deprecation without interfaces for replacement.

Bug: T290639
Change-Id: I469de6f85e405e8ddbe7abaa5b99b77cb9cf415d
2021-12-01 19:14:22 +01:00
Ammarpad
77165e665e ApiEditPage: Harden content model mismatch checks
Bug: T290607
Change-Id: Ibced84ae6ee1648a3b8bcf616c3c0561394a3fdc
2021-10-02 21:13:51 +01: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
773f6b6322 api: Replace deprecated User::getOption in ApiEditPage
Change-Id: Ic20c8c6402d80ca8b5a426b3d10fbe3efb0e89a4
2021-07-06 23:10:28 +02:00
Umherirrender
d146800ee8 api: Inject services into ApiWatchlistTrait
Bug: T259960
Change-Id: I73596f8c924ec4a02a7042608d19a35f82bb752a
2021-07-06 20:15:30 +00:00
Umherirrender
c9319f7b55 api: Replace deprecated WikiPage::factory in ApiEditPage
Change-Id: Ic62d9144f64c32a3d403984a0e04f590c9a67188
2021-07-02 14:35:14 +02:00
Umherirrender
576ccf392d api: Inject services into ApiEditPage
Bug: T259960
Change-Id: Idf6eee7fed14495a8ab6e05a768fcb28178a4c2f
2021-06-30 22:30:28 +02:00
Roman Stolar
6ebaa5caf6 Remove the fallback for create rights (covered in PM edit rights check).
Remove key to i18n message, no longer being used.

Bug: T272079
Change-Id: Id6566e5241b06ba377c2eca083221ee02556365f
2021-06-30 17:30:30 +03:00
Bartosz Dziewoński
2361889b78 Use the edited page's title for magic words in action=edit error messages
Allow specifying the title used for rendering error messages in
ApiErrorFormatter.

Then, specify one in ApiEditPage (and a few similar modules that deal
with single pages) once we've figured out which page is being edited.

Bug: T247661
Change-Id: Ic3d70efc23744ef6e90abc445f3babebf45c4697
2021-05-21 18:00:36 +02:00
Umherirrender
cf541752e0 Add comment to fall-through cases in switch
Fix new coming sniff
PSR2.ControlStructures.SwitchDeclaration.TerminatingComment

Bug: T182546
Change-Id: I3f8d43c730981d8faaa72910d7f3b58a14a8372f
2021-04-15 17:31:12 +00:00
DannyS712
3413868d0d Clean up some logic in ApiEditPage
Should be a no-op

Change-Id: I292aa153eb0bf4fdda099995073904c0c9c96d99
2021-04-12 05:36:10 +00:00
Petr Pchelko
ee7d3e9335 Convert ChangeTags public interface to Authority.
Bug: T275507
Change-Id: I3b7f99391ab299df2b046a2878010cf6afe7fed7
2021-02-24 14:09:16 -07:00
Thiemo Kreuz
ca56a3a1b8 Safe-guard switch possibly doing bad comparisons
Old PHP versions are fine doing a `switch` with anything, even
if the types don't match. This changed. More recent PHP versions
start to bring up notices and such when a `switch` accidentially
compares e.g. an object with an int.

Bug: T255177
Bug: T258790
Change-Id: Ib415bd2fb394b95b02737b6df50e4e1fbbc440d3
2021-02-10 19:42:25 +01:00
jenkins-bot
fab3c6ed57 Merge "ApiEditPage: Document that it is extended" 2020-10-06 18:50:01 +00:00
Ammar Abdulhamid
30b947ad5f Revert "Revert "ApiEditPage: Show existing watchlist expiry if status
is not being changed.""

This reverts commit 149e99f072.

It's not necessary to change the constructor now, the module is already
using service locator to fetch RevisionLookup and ContentHandlerFactory.

The WatchedItemStore can also be gotten from there, voiding the need for
altering the constructor now. As Daniel said in T259960#6380471 dependency
injection for API modules is good but not urgent.

Bug: T261030
Bug: T264200
Change-Id: I16aa942cc800cd66a2cd538680a02b10cb0b1bfe
2020-09-30 19:28:47 +00:00
DannyS712
bd7ecc3b06 ApiEditPage: Document that it is extended
To avoid future issues like T264200

Bug: T264200
Change-Id: I0eafbad96be5037fb7795559fe6a62e69d54f0c5
2020-09-30 16:47:11 +00:00
jenkins-bot
e3d4f1db9b Merge "Revert "ApiEditPage: Show existing watchlist expiry if status is not being changed."" 2020-09-30 16:12:48 +00:00
DannyS712
149e99f072 Revert "ApiEditPage: Show existing watchlist expiry if status is not being changed."
This reverts commit 07e547f47c.

Reason for revert: LiquidThreads extends the ApiEditPage class,
even though it shouldn't, and thus fails when the dependencies
are not injected.

Bug: T261030
Bug: T264200
Change-Id: Ib14f8a04bb6c723aa502a47ef9ccde6fe96a0ac7
2020-09-30 15:29:59 +00:00
jenkins-bot
1d49ad1e5b Merge "ApiEditPage: Don't swap undo and undoafter parameters" 2020-09-30 01:45:14 +00:00
Ammar Abdulhamid
07e547f47c ApiEditPage: Show existing watchlist expiry if status is not being changed.
Bug: T261030
Change-Id: I795db12aefeffb1cfbbe2ab00fbb19444df7d37b
2020-09-29 16:20:20 +01:00
Dov Alperin
a1cd498fdf ApiEditPage: Don't swap undo and undoafter parameters
This made it impossible to correctly undo changes if revision IDs are out of
order with respect to timestamps.

Removes block of code responsible for creating this bug, and updates tests to reflect the change

Bug: T190285
Change-Id: Id5837ed958023bdbf544ae0f79e2d5e05c94cc64
2020-09-21 19:08:20 +01:00
jenkins-bot
f78bf7963d Merge "Remove requirement for ApiWatchlistTrait to be in ApiBase." 2020-09-11 00:36:58 +00:00
Ammar Abdulhamid
cf004d524d Remove requirement for ApiWatchlistTrait to be in ApiBase.
This trait is not needed in ApiBase and its presence here is
proving to be problematic. See I795db12.

In this patch, the trait usage (more precisely the 'use statement')
has been removed from ApiBase and accordingly the signatures of
ApiWatchlistTrait::getWatchlistValue() and ::setWatch() have been
altered to now require User object.

With these changes, the abstract getUser() method in the trait is no
longer needed, so it has been removed also.

All core usages of the affected functions are fixed in this patch.

The trait is used in only one extension according to codesearch tool,
the extension will be fixed in  Ic22e163.

Bug: T262175
Bug: T248512
Follow-up: Ia18627b9824dca81f44f0571e8420d89b7626cf6
Change-Id: Idabcea71edfca9e7ed42000a258c99ff407873d4
2020-09-07 01:13:57 +01:00
Ammar Abdulhamid
7af5678847 API: Handle ContentHandler exception for content model mismatch
Ensure the content we are trying to save and the base content have
identical content models before proceeding to save so as to forestall
Exception that may be thrown by ContentHandler if it founds they're not.

There are two cases where the models are allowed to differ: Edit that
undoes content model change or edit that's meant to explicitly change
the model. The logic for these is handled separately and may succeed
or fail, but exception will not be thrown.

Bug: T255700
Change-Id: I8782732bb0fc3059693cd7035b7ebb43fd71d333
2020-09-04 03:41:58 +01:00
Ed Sanders
7683f7d839 Use strict (in)equality with namespaces constants when LHS is definitely an integer
Change-Id: I8fede00dfe1270d93c5d78d3c36e788cddfc8a99
2020-07-31 18:03:28 +01:00
jenkins-bot
28f0b2cfc8 Merge "EditPage: handle undoafter param properly" 2020-07-14 13:23:04 +00:00
MusikAnimal
6a898faed2 Add watchlist expiry support to applicable APIs
This introduces an ApiWatchlistTrait that refactors out common code
across APIs that allow you to watch pages. Some methods have been
migrated from ApiBase and changed completely, but codesearch suggests
they aren't being used outside the API modules in this patch.

Bug: T248512
Bug: T248514
Change-Id: Ia18627b9824dca81f44f0571e8420d89b7626cf6
2020-07-13 18:18:15 -04:00
Ostrzyciel
5bf2cf380b EditPage: handle undoafter param properly
This is to fix issues with reverts being marked incorrectly,
especially when using the undoafter param which, until this patch,
wasn't really supported.

Honestly, EditPage is such a mess that I'm not sure if this is good
or not, but I did a lot of manual testing and it seems to work fine.

WikiPage::doEditContent() now checks whether the provided original
revision really has the same content as the new revision. This was
previously the task of callers, but that doesn't make much sense to
me because:
* This task would fall on EditPage otherwise and it should be more
focused on the UI side of things, without too much worrying about
backend details.
* This would require adding another parameter to WikiPage::
doEditContent(), $undoAfterId. It would be only useful for multiple-
revision undos that are not top revisions. In all other cases it
would be the same as $originalRevId.
* An extra sanity check before applying the value to the PageUpdater
won't hurt. Who knows what crazy ideas extensions might have.

The test cases are almost identical to those written for
McrUndoAction, so I decided to group them in a single file.
This should cover most undo cases.

Bug: T256915
Change-Id: I78641b3de0a012af932ea38265b695362f1f8491
2020-07-08 21:46:04 +02:00
Reedy
12a3883a7b Fix SingleSpaceBeforeSingleLineComment
Change-Id: I285af438ce484af40741489797f20455726ec110
2020-05-11 00:57:11 +00:00
ArtBaltai
8426e984f9 Soft deprecate Page interface
Additionally, use Article::getPage() instead of relying on
Page interface proxy method in ApiEditPage, forgotten before

Bug: T239975
Change-Id: I01696a1b11b2ea5c3d94fcb9a42beea68eb7b804
2020-04-09 04:00:31 +00:00
Thiemo Kreuz
854d5bcd7f Replace isset() in if() conditions with ?? if possible
The basic idea is: The sequence `$var ?? 'default'` either uses the
value from the variable (or array element) if available, or falls back
to the default value. The resulting value is then used in the if()
condition.

if ( $var ?? true ) means the variable should default to true, if not
set.

This is mostly a style change.

In ApiEditPage the $params are impossible to not be set.

Change-Id: Id67b81744fa21fe22a2d2377259e426aab67c479
2020-03-23 09:28:07 +01:00
jenkins-bot
7932a7cb52 Merge "Remove usage of deprecated Revision from ApiEditPage" 2020-03-11 22:08:20 +00:00
daniel
3ebd55ed47 ApiEditPage: add baserevid parameter
This adds a baserevid parameter for detecting edit conflicts, as an
alternative to the less precise basetimestamp parameter. This is
introduced for parity with and use by the new REST api.

Bug: T230843
Bug: T34037
Change-Id: Id7565018f66860b5c2ba688777508db1b88700ae
2020-03-11 13:29:09 +01:00