Commit graph

40 commits

Author SHA1 Message Date
Petr Pchelko
f642215aed Convert ParserCache to PageRecord
ParserOptions not updated cause they depend on Title::getLanguage
implementation.

Tests converted to not require a DB anymore. Can't be proper unit
tests yet due to globals in ParserOptions and fake time hacks,
but exec time does go down from 70 seconds to 9 seconds.

Page content model is still emitted in the metrics since
it was considered useful. Should be removed when we get
something like a page type concept.

Change-Id: Ib16fd0b5b87ffc3cb4d21f4aa43d1203cb7206d2
2021-04-02 21:14:54 -06: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
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
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
Petr Pchelko
10de1d3472 Introduce MockAuthorityTrait for Authority test helpers
Change-Id: I152f2cbe8a7000eedc237fb46b4e4c6d2f9730d4
2021-01-21 20:19:12 -06:00
Petr Pchelko
3a2e8883b4 Rest: use Authority in all core handlers
Bug: T239753
Change-Id: Idf2229255f49514dd8b68bf63573c5b619b4f2f1
2021-01-21 18:22:33 -06:00
Petr Pchelko
816e02ae51 Convert RevisionRecord to Authority and PageIdentity
As we convert the RevisionRecord to using Authority,
we no longer need Title instances, so we can convert
that to PageIdentity.

Ideally, we'd part away from using Title at all, but:
1. For foreign wikis PageIdentity has stronger validation,
so calling PageIdentity getId() on Title will break things.
There's still a lot of code depending on lax Title guarantees,
so we keep it.
2. A lot of code still depends on Title, so we try to pass it
through even if we don't nesessarily need to, to save cost
on recreating it later on.

Bug: T271458
Depends-On: I287400b967b467ea18bebbb579e881a785a19158
Change-Id: I63d9807264d7e2295afef51fc9d982447f92fcbd
2021-01-21 13:37:01 -06:00
Thiemo Kreuz
2f66b3754f tests: Remove @param docs from test code that just repeat the signature
These are not only 100% identical to the actual code, but also:
* It's error-prone. Some are already wrong.
* These test…() functions are not meant to be called from
  anywhere. What is the target audience for this documentation?
* There is a @dataProvider. What such @param tags actually do is
  document the provider, but in an odd place. Just looking at
  the provider should give the same information.
* The MediaWiki CodeSniffer allows to skip @param when there is
  a @dataProvider, for the reasone listed.

Change-Id: I0f6f42f9a15776df944a0da48a50f9d5a2fb6349
2021-01-21 03:41:23 +00:00
Petr Pchelko
7854dd5fc9 Split title mocking methods out of HandlerTestTrait.
The functionality of creating title mocks is generally useful
and this will also allow to make HandlerTestTrait more narrow.

Bug: T264058
Change-Id: I76eca48dfcff65a6203fccde5366912a2d66c495
2021-01-13 12:46:10 -06:00
C. Scott Ananian
df1ddd6f9c LanguageLinksHandlerTest: use wgInterwikiCache instead of mutating database
Mutating the interwiki table invalidates the Title codec and in
general leads to a bunch of complications.  Easier to just use the
`wgInterwikiCache` mechanism, as a lot of other phpunit tests do.

Bug: T271287
Change-Id: Id1899a89ae6b55e7032befe73990d215370828d8
2021-01-06 17:07:47 -05:00
daniel
637f630fe9 Implement caching for old revision HTML endpoint
Bug: T269663
Change-Id: I2d17ec37d25f3a6e1c4836c05576bf0fabb7d429
2020-12-15 23:40:08 +01:00
daniel
fa8ddd48fc Implement /revision/{id} endpoint
Also implements and endpoint for revision source,
for parity with /page/{title}.

Bug: T267981
Change-Id: I88c714df6e428fbc02aa4ff7f4ecea7d8b458468
2020-12-14 16:54:43 +00:00
daniel
a4b51d2774 Implement /revision/{id}/html endpoint
This doesn't have caching yet.

Bug: T267981
Change-Id: I32a35bb7bc6c6832ce7c79fb942922abc1ddb0e0
2020-12-14 16:54:35 +00:00
daniel
00a3439dce Introduce RevisionOutputCache
Bug: T267981
Change-Id: Ib1dc641ed10d786918362b25bd655780d5844ba1
2020-12-14 16:50:28 +00:00
Petr Pchelko
1162411d7f Make /page/{title}/html emit etags in RESTBase format
RESTBase used to emit ETag in the `"<rev_id>/<render_id>" format.
For the benefit of the clients, preserve the formar.

Render ID is a UUIDv1 uniquely identifying the ParserOutput.
In future it would be used as a stashing key for stash deduplication.
At this time I decided to just attach the render ID as extension data
to our fake ParserOutput. Once we integrate Parsoid more into core,
we will likely move it into a ParserOutput property, or even
replace CacheTime::mCacheTime with a UUIDv1, but it's too early for that.

Bug: T268234
Change-Id: Ie604e9c98021d59eb1a17ca65f227e8f234a45be
2020-12-09 16:36:07 -06:00
Cindy Cicalese
808d841447 Moved page/{title}/bare to PageSourceHandler
Bug: T267981
Change-Id: Ie1a5ee9da5d8231bbf7ea2cbb419ab4bcec33c43
2020-12-09 22:02:11 +01:00
Daniel Kinzler
3bc61324b9 Re-Apply "Extract helper classes from PageHTMLHandler"
This reverts commit d51a697e13.

Reason for revert: Let's try this again...

Change-Id: Ie0218adff95576c972ff4c1d51cadd02f41eba3e
2020-12-07 16:59:29 +00:00
Subramanya Sastry
d51a697e13 Revert "Extract helper classes from PageHTMLHandler"
This reverts commit b98f7a6fc1.

Reason for revert: Breaks Parsoid CI but doesn't seem to run on core patches?

Change-Id: I1eaf1495dce6f6ba78093aacb9475a023a2aabfa
2020-12-02 23:32:27 +00:00
daniel
b98f7a6fc1 Extract helper classes from PageHTMLHandler
This extracts two helper classes from PageHTMLHandler:
* PageContentHelper for accessing page content. This replaces the
  LatestRevisionContentHandler mase class.
* ParsoidHtmlHelper for generating HTML from wikitext using parsoid.

The idea is to decouple the functionality from the REST handlers, so we
can easily mix and match functionality to create a handler for the
new per-revision HTML endpoint.

Bug: T267981
Bug: T267982
Change-Id: I3226833d12e51c959712d642b0195de1fe1ef979
2020-12-02 18:08:12 +00:00
Ppchelko
d2565533c4 Re-Re-apply "Use parsoid directly in /page/html handler
This reverts commit d4789dc29a.

Reason for revert: it's still good, resolving dependencies.

Change-Id: Ib5b75cf71b3d9ba2be21b1a369bf20db368c6968
2020-11-19 14:16:50 -07:00
Ppchelko
d4789dc29a Revert "Re-apply "Use parsoid directly in /page/html handler""
This reverts commit 38ca1b261e.

Reason for revert: Even though API appserver is ready, the REST API traffic is not routed to the correct MW cluster.

Change-Id: I00582e32c87e803c305930dd8de60c38b771b219
2020-11-17 17:05:19 +00:00
Ppchelko
38ca1b261e Re-apply "Use parsoid directly in /page/html handler"
This reverts commit 1157007658.

Reason for revert: can be reapplied after dependencies are resolved.

Change-Id: I1270853766fd5bf59ed191065b9e52b76e3d9fc9
2020-11-16 14:23:18 +00:00
Ppchelko
1157007658 Revert "Use parsoid directly in /page/html handler"
This reverts commit 4191c9fe31.

Reason for revert: This can not be released yet. It has slipped my mind that Parsoid extension is not enabled on the API MW cluster, thus releasing this will break the html endpoint. This code is good and can be re-reverted once https://gerrit.wikimedia.org/r/c/mediawiki/services/parsoid/+/635096 is resolved.

Change-Id: I808be187ae582995e6c1899044b2a7019bf02d32
2020-10-19 22:39:01 +00:00
Petr Pchelko
4191c9fe31 Use parsoid directly in /page/html handler
Bug: T265295
Change-Id: I6d9999b315def616e973daca0b7d544e502c7212
2020-10-16 15:21:39 -07:00
daniel
d2d2906ce7 REST /page/{title}: Fix title encoding.
Page titles used in URL paths, such as the Location header returned
after a page was created, must use the correct encoding for spaces and
pluses.

Bug: T258606
Change-Id: I75e91ac8f8da4eb183a9c8f1a682ea08c2225227
2020-07-23 23:17:17 +02:00
daniel
2f3e07a6c9 REST api: bump some endpoints to v1
The following endpoints move from v0 to v1:

  GET page/{title}/links/language
  GET page/{title}
  PUT page/{title}
  POST page
  GET page/{title}/bare
  GET page/{title}/html
  GET page/{title}/with_html
  GET page/{title}/links/media
  GET file/{title}

NOTE: after merging this, give SRE a heads up, e.g. by
putting a note on the train ticket when this is merged
(navigate from T254174 as appropriate). 

Bug: T255043
Change-Id: I3b8890da901e6312582d9a215c6a647173f16149
2020-06-11 20:16:47 +00:00
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00
daniel
504e9c446f CreationHandler: fix redirect URL
Add missing version prefix to Location header emitted after successful
creation.

Bug: T253143
Change-Id: I6262f61668cefacce12ed6f2a976340e10cf105b
2020-05-25 11:13:18 +02:00
jenkins-bot
412d9c8bbc Merge "Make REST tests more robust against content language" 2020-03-30 14:49:27 +00:00
daniel
905f6fc890 REST: page/ endpoints: don't use tokens with OAuth
CSRF tokens should only be required (and only be allowed) if
the current session isn't already inherently safe against
CSRF due to the way the authentication mechanism works.
This allows (and requires) tokens to be omitted for requests
that use an OAuth Authorization header.

Bug: T230843
Bug: T230842
Bug: T237852
Change-Id: Ib2922d556ff2470d4bf8c386c18986ca9f37d1b5
2020-03-27 12:20:22 +01:00
daniel
c8acf2655e Make REST tests more robust against content language
Change-Id: Id24536e96d89be768b96c2acd0edde6d371f438b
2020-03-27 09:23:36 +01:00
Bill Pirkle
c50523f1fc Display different errors for title vs file not found in MediaFileHandler
In Core REST API MediaFileHandler, display a different error for
title not found vs file not found. Files may be unfindable even if
the title exists due to permission errors, or if they are missing
from the file system.

Bug: T238374
Change-Id: If49273b979291e284043f6251ad8d989a10defe1
2020-03-26 11:58:12 -05:00
jenkins-bot
fde16090b6 Merge "REST endpoints: Add etag and last-modified headers" 2020-03-26 03:15:58 +00:00
jenkins-bot
6d791abd80 Merge "Define POST handler for /page/: create page" 2020-03-26 01:33:50 +00:00
daniel
22561b64a7 REST endpoints: Add etag and last-modified headers
Modified endpoints:
* /v1/page/{title}/history
* /v1/revision/{id}/bare
* /coredev/v0/page/{title}/links/language
* /coredev/v0/page/{title}/links/media
* /coredev/v0/file/{title}

Bug: T238374
Change-Id: I3ddf8fafc17eba3aec724a445d38af98bbc74dc1
2020-03-26 00:18:34 +01:00
daniel
65342f8353 Define POST handler for /page/: create page
NOTE: once this is merged, also merge Ie7b47e6868cc on the OAuth repo,
to fix unit tests after a breaking change to Router's constructor
signature.

Bug: T230842
Change-Id: I8f5b92918a58e44a4f2d8c78d234d9f64c2d06bf
2020-03-25 20:49:20 +01:00
daniel
f32abbaf0d LanguageLinksHandler: add phpunit integration test
Bug: T236172
Change-Id: Ib8b2af03bf9377dc8133e019237cef7feff919b3
2020-03-25 18:29:30 +01:00
daniel
81a47eaad3 page/update: return diffs on conflict
This adds diffs for use in an interactive merge when detecting an edit
conflict.

Bug: T230843
Change-Id: I6345361fce98524027ad778749d4fbf54169ccb6
2020-03-23 15:59:47 +00:00
daniel
58e5332991 page/update endpoint
Bug: T230843
Change-Id: I95289eddfc9ab2e0cef11b9363a5e239cdb2258e
2020-03-23 16:59:21 +01:00