Commit graph

411 commits

Author SHA1 Message Date
daniel
13acba25a0 REST: gracefully handle all exceptions.
ResponseFactory::createFromException already had support for arbitrary
exceptions, but Router was so far only using it for HttpExceptions,
leaving other kinds of exceptions uncaught.

In addition to catching all exceptions and generating an appropriate
JSON response for them, this patch introduces the ErrorReporter
interface, with an MWErrorReporter implementation which calls
MWExceptionHandler::rollbackMasterChangesAndLog(). This is how uncaught
errors are handled for requests coming in via api.php, so it seems
appropriate to use the same approach for requests coming in via
rest.php.

Bug: T285984
Change-Id: I0605a7693821ef58fac80ab67f51a742556a37fd
2021-11-02 20:33:13 +01:00
Nikki Nikkhoui
0b3a4c0fa8 Do not cache private wiki completion results
Previously, when a user with correct permissions uses completion search on a
private wiki, the results are returned and cached. Since we are on a private wiki,
we don't want to cache results since the content is not accessible to all users.

Now, content that is not accessible to all users will not be cached.

This patch achieves this by setting the appropriate Cache-Control response headers
for the MW REST Search endpoint.

Bug: T292763
Change-Id: I693b4088df9c0520d5238c286312ec52ab273604
2021-10-12 13:12:05 +00:00
jenkins-bot
a720ab41da Merge "Add slow-parsoid log channel" 2021-09-16 14:05:36 +00:00
Translation updater bot
c8a890fc77 Localisation updates from https://translatewiki.net.
Change-Id: I819136a588d1fa32e582f68401de0c4d781593b8
2021-09-15 08:00:28 +02:00
Tim Starling
4f41e2addd Add slow-parsoid log channel
By analogy with slow-parse.log. Also, I fixed the log message so that it
has the full title in it.

Change-Id: Icaeb6f002c5c2a676467d4c760f99cb2676ad73b
2021-09-15 15:48:11 +10:00
DannyS712
46ef24f70a UserDef: use TitleParser instead of Title objects
Migrate away from the Title object, use
TitleParser::parseTitle() which returns a
TitleValue which is enough. Will be followed by
switching UserDefTest to a unit test, but in a separate
commit.

Change-Id: Ia756964861c4e0f3edea89f6beec2643243ca741
2021-09-14 03:25:36 +00:00
DannyS712
9308ee9cf8 UserDef: no need to return full User objects
Maintain the existing behavior for creating based on a user
id or name that does not correspond to an existing user:
* if creating a User object based on the id 0, User::loadFromId()
will load the defaults with the name being set to false, and
User::getName() will convert that false to the ip of the current
request. We probably don't want UserDef to be doing that, but
this behavior should be changed separately - at the moment
we are just matching the existing behavior (see the prior commit
which adds tests to confirm the behavior isn't changing)
* if creating a User object based on an id that cannot be found
in the database, User::loadFromDatabase() will load the same
defaults, *except* that it will set the user name to "Unknown user"
* if creating a User object based on a name, User::getId() will,
if the id isn't already known, return 0 if the name matches
UserNameUtils::isIP() or ExternalUserNames::isExternal(). However,
the User object is currently only created based on a name after
passing an ExternalUserNames check, and the creation with
RIGOR_VALID prevents it from being an ip. Thus, the existing
code will call User::load(), which will check the database or
fallback to 0 if the user does not exist.

When creating a User from an id that does not exist, User::getId()
will return that id, until after the object tries to fully load,
after which it'll return 0 for the id. Since we cannot replicate
this with UserIdentity (switching the id to 0 only after getName()
is called for the first time) we set the id to always be 0, which
is more accurate. This is the only change in behavior.

We will remove the use of the context ip in a follow-up that will
switch to using "Unknown user" instead.

Accordingly, we will use a UserIdentityLookup as well as
manual construction of UserIdentityValue objects to match this
behavior.

Bug: T288311
Change-Id: Ida80c5d04d721fafa8d66f656dbd346c6cf643eb
2021-09-14 03:25:31 +00:00
Umherirrender
44fd53fee3 Using @return never documentation on always-throw-function
This helps phan to detect unreachable code and also impossible types
after the functions.
It helps phan to avoid false positives for array keys
when the keys are checked before

Bug: T240141
Change-Id: I895f70e82b3053a46cd44135b15437e6f82a07b2
2021-09-07 17:29:03 +02:00
Tim Starling
2f6b427f40 In Rest\ResponseFactory, substitute invalid UTF-8
Most of the time this is due to garbage user input, and MediaWiki's
normal handling of user input strings is to normalize them, not to
throw.

There are some hypothetical cases where a developer might want to see an
exception, rather than passing garbage to the client and letting the
client fail, but normalization is a defensible policy and works within
the existing interfaces.

Bug: T289597
Change-Id: Ida5ee72c10d1c3499b5b17594c5675db7cd38335
2021-08-26 08:58:45 +10: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
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
jenkins-bot
7b2a1da28c Merge "Make EntryPoint::getTextFormatters() private" 2021-07-16 17:34:10 +00:00
James D. Forrester
719cf161f2 More master -> primary documentation and internal var renaming
Bug: T254646
Change-Id: I63cc8895033714bdfbf09aee933a8f0a43b387f3
2021-07-15 11:20:20 +01:00
Tim Starling
d3d8dc9965 Schema migration for revison_actor_temp table removal
Introduce a new schema migration stage in which rev_actor is used
directly and the revision_actor_temp table is no longer needed. This
becomes the new "new" stage whereas the previous situation is now
termed SCHEMA_COMPAT_TEMP.

Introduce migrateRevisionActorTemp which copies data from
revision_actor_temp to rev_actor. The code is similar to
migrateImageCommentTemp.php except that it doesn't delete from the old
table.

Partial revert of c29909e59f. That change removed direct
references to $wgActorTableSchemaMigrationStage and made queries
involving revision_actor_temp be unconditional. Such changes need to be
reverted to make the use of revision_actor_temp be conditional again.

In ActorMigrationTest, I compacted provideGetJoin() and
provideGetWhere(), removing most of the duplication between expected
values. I gave all the stages a short name, and mostly used the name in
providers.

Bug: T275246
Change-Id: I7498107dd6433ab7de5bf2e7b3fe2aa5e10e345d
2021-07-14 08:29:04 +10:00
Petr Pchelko
0d75fdb4f7 Use CsrfTokenSet as CSRF token source
Change-Id: I079d2c802d9b48d6abf7f37fa9ef7dafac631345
2021-07-12 14:19:15 -07:00
jenkins-bot
2977943fbc Merge "Fix some @stable for ... annotations to use @stable to ..." 2021-07-12 16:23:50 +00:00
DannyS712
4939ef070d Router::__construct() put one parameter per line
Makes it a bit easier to read and to add new parameters

Change-Id: Ic4b6cae382b0e33c2ca3947e9fc92e64fb792408
2021-07-10 03:50:10 +00:00
DannyS712
b0ab985420 Fix some @stable for ... annotations to use @stable to ...
Bug: T257789
Change-Id: I3ba94a9d6b739cd57cd57afe5d397963127160a8
2021-07-08 02:54:59 +00:00
Translation updater bot
b3ef852bae Localisation updates from https://translatewiki.net.
Change-Id: If0781fe776a2472f79e8a671322f53c1a01f2890
2021-06-29 08:01:24 +02:00
DannyS712
47d70dbfba Post Revision-removal cleanup
Updates for the removal of the Revision class itself
and the various methods/hooks/variables removed in the
process, including:

- Update some documentation removing most references
to the Revision class and updating the MCR migration
notes to reflect the past tense for Revision methods.

- Change some capitalization from "Revision" to "revision"
to make it clear comments are about revisions in general,
not the Revision class in particular.

- Minor code tweaks including removing unused variables that
were around for the old hooks that were removed, and
removing the use of DeprecatablePropertyArray where no
longer needed for anything.

- Fix incorrect documentation for PageUpdater::getStatus(),
the status value changed a while ago to have revision-record
in addition to revision, and recently to only have the
revision-record, but ironically PageUpdater was never updated.

- Removed Parser::$mRevisionObject, used to be a Revision object
and was deprecated in 1.35, missed earlier because it was no
longer being set to Revision objects, always null.

- Add RevisionRecord typehints in DummyLinker to match those
in the corresponding Linker methods

This should be a no-op in terms of functionality.

Bug: T247143
Change-Id: I03bbb94fc29085855448780b1a5ad9063911ecc4
2021-06-24 00:32:39 +00:00
jenkins-bot
bdf813798f Merge "Make REST CORS allowed headers respect site configuration." 2021-06-02 14:44:15 +00:00
DannyS712
311b3b44f4 Make EntryPoint::getTextFormatters() private
It has MediaWikiServices as a parameter, and should be reworked
at some point, so make sure no external callers get added (there
currently are none). Added to release notes as a breaking change
made without deprecation.

Change-Id: I025e5386f414e9c71e2af3fd2f63d25da3125a22
2021-06-02 13:36:16 +00:00
Translation updater bot
fe657edcbe Localisation updates from https://translatewiki.net.
Change-Id: I3d31b6643bf08ca1b8c2447e1a81954aa3164326
2021-06-02 14:34:25 +02:00
jenkins-bot
e20a0d7c29 Merge "FileRepo::findFile - support Authority" 2021-06-01 15:24:39 +00:00
Petr Pchelko
e2676906a8 Make REST CORS allowed headers respect site configuration.
Bug: T268791
Change-Id: I4f10e508730baf5ce276bb71dc354554eed3cfb0
2021-05-30 10:15:47 -07:00
Translation updater bot
14837c42e5 Localisation updates from https://translatewiki.net.
Change-Id: I71412d3cc4a77d8f76a4145e443105be61371de8
2021-05-28 08:57:38 +02:00
Petr Pchelko
fb6529e653 FileRepo::findFile - support Authority
Change-Id: Ib42b7f7d5aa88447b4fb363f52062b08a1af30c3
2021-05-26 19:01:12 -07:00
DannyS712
f057d2253c Replace deprecated uses of PermissionManager with GroupPermissionsLookup
In a few places where a PermissionManager is used
but only GroupPermissionsLookup is needed

Also update references to the class in PermissionManager
that referred to it as GroupPermissionLookup

Change-Id: I5d7a13900852a38768a106aeee1ce012c3a04ea2
2021-05-26 05:47:21 +00:00
DannyS712
19739de872 Remove some unneeded uses of full User objects
Change-Id: Ib86399445a77d3005f23ae87d87f3cf742b13b1f
2021-05-22 03:58:25 +00:00
Translation updater bot
a2729f3a56 Localisation updates from https://translatewiki.net.
Change-Id: I30af270fe6c71c4572d834a29bc396f378c12980
2021-05-20 09:08:53 +02:00
Thiemo Kreuz
6805f39a30 Remove unused default values from class properties
In all these cases the property is unconditionally set in
the constructor. The extra initialisation is effectively
dead code and an extra source of errors and confusion.

Change-Id: Icae13390d5ca5c14e2754f3be4eb956dd7f54ac4
2021-05-12 13:44:28 +02:00
daniel
7b832c1fa3 Remove SearchResultPageIdentity interface
SearchResultPageIdentity and SearchResultPageIdentityValue were
introduced as placeholders for PageIdentity and PageIdentityValues.
They can now become aliases.

Bug: T282091
Depends-On: I9b1ab02e0acf12ace107361ea2c443aa543c4880
Depends-On: Ie405ea9539cd18e15b0abb6db6df64ec0135825d
Change-Id: I6eb55c78a0a72be66814f8bc854ba663e7c6f62b
2021-05-10 16:05:45 +02:00
Petr Pchelko
4ca16e8d08 Eliminate use of Title object in REST infrastructure
Change-Id: I585f0f23cac5f6dc2a4879f69f7b83828fda3dd3
2021-05-05 18:54:58 -07:00
Umherirrender
886643796c docs: Fix @var comments to use doc comment syntax
@var needs /**-comments to work, not /*-comments

Change-Id: If54b3f24d4ca49036fa91aa4c72fab6d841fcc9e
2021-04-29 22:48:52 +00:00
Translation updater bot
817a3c203b Localisation updates from https://translatewiki.net.
Change-Id: Iaadb232b6a928b709d501930416ea55d707fb207
2021-04-12 08:36:09 +02:00
Reedy
573d9b058f Rest/Handler.php: Minor cleanup
Change-Id: I4b15250abc7ec3a1271a5fc549057cdcfaee0b8a
2021-04-02 02:51:00 +01:00
daniel
91dc627c85 UpdateHandler: fix response for null edits
The response from a null-edit should contain the current revision's
revision ID and timestamp, not the info from the edit's base revision.

Bug: T277601
Change-Id: I9d353cdc4cb9e3c1435c93ffe63ef4fef173ec4d
2021-03-26 16:53:43 +00:00
daniel
b38e0e8e32 REST edit: handle null edits correctly
For null-edits, the new revision is the same as the old revision.

Bug: T277601
Change-Id: I73f902f7ef890470ff6ee3e4500095adbb00938a
2021-03-19 14:10:25 +01:00
Petr Pchelko
ea185c872e Rename Authority::getPerformer() to ::getUser()
We started to call Authority argument $performer everywhere,
and $performer->getPerformer() doesn't look that good.

Change-Id: Id2cf3f27b18340314e4ed1ea9931ad9404b4df6f
2021-03-04 12:45:28 -07:00
Petr Pchelko
375e9f0a68 Rename Authority::getActor to Authority::getPerformer
Bug: T274947
Change-Id: I8f652816af00bf9fa413ba4b1fa7ac4c27290dc2
2021-02-22 14:53:21 +00:00
James D. Forrester
5a622b6a2e build: Upgrade eslint-config-wikimedia from 0.17.0 to 0.18.1
Change-Id: I5e3687be2b197134578126e1b890ee37dbc1bc1b
2021-02-18 08:39:09 -08:00
Translation updater bot
83e1902628 Localisation updates from https://translatewiki.net.
Change-Id: I673b6ee4523c19ca495089266dde8d6c7ae38418
2021-02-16 08:28:42 +01:00
Translation updater bot
d6a1b7c249 Localisation updates from https://translatewiki.net.
Change-Id: I7af155ff41613c05e2cbd500d95cfd7ba68b8b1c
2021-02-15 10:03:10 +01:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Translation updater bot
e145437cc7 Localisation updates from https://translatewiki.net.
Change-Id: Ia305a6f8f7a2674736295aee980875070f4580e6
2021-02-08 08:36:10 +01:00
Translation updater bot
1a05d69bba Localisation updates from https://translatewiki.net.
Change-Id: I1610adf0a98cd554f284b1e52b43d376ff831561
2021-02-05 08:46:02 +01:00
jenkins-bot
605730a1cd Merge "Allow REST API POST handlers to opt out of mandatory sqlite locking" 2021-02-03 21:38:41 +00:00
C. Scott Ananian
b75ac3953e Allow REST API POST handlers to opt out of mandatory sqlite locking
This is a follow up to T93097, which worked around a limitation of
SQLite 3.8+ which prevents it from upgrading a read transaction to a write
transaction.  Our heuristic is that HTTP POST requests are going to
eventually become DB writes, and so we take the SQLite lock early.

However, Parsoid POST requests don't have any side effects on the DB,
and taking the write lock causes deadlocks during VE saves: the POST
to action=visualeditoredit conflicts with the POST to the recursive
request to the Parsoid REST API.  We can't use a GET request for
these requests without hitting query-length limits.

This patch allows REST API calls to set the `X-MediaWiki-Read` header
to opt-out of the SQLite obligatory lock.  This avoids the deadlock,
while still allowing the API call to use a POST and avoid query length
limits.

Bug: T259685
Change-Id: If37dc890a24a45c3a914e310b5b5bf625965e9e6
2021-02-03 20:26:41 +00:00
Translation updater bot
9e2a22f2c8 Localisation updates from https://translatewiki.net.
Change-Id: I944fec7934a758c0188a90c417b73a0db449d389
2021-02-03 08:38:07 +01:00
Translation updater bot
acc423a848 Localisation updates from https://translatewiki.net.
Change-Id: Iace82d035923e24c40d17214c041409e10aacf60
2021-02-02 08:37:35 +01:00