Commit graph

378 commits

Author SHA1 Message Date
Máté Szabó
3f294751b2 ApiParse: Coerce image links to string
When ApiParse is used to parse a page containing numeric image links
like [[File:1]], those image links are returned in the "images" section
as numbers, not strings. This is due to a longstanding PHP feature where
numeric strings get converted into numbers when used as keys in an
associative array. So, coerce them back to strings.

While numeric image links seem rather useless, they still occur in the
wild, whether by design or by accident, and may break API consumers that
expect to deal with strings here.

Bug: T346265
Change-Id: I9bd3813afd1867d0ba9c7ef480ad5e6b062c1e94
2023-09-13 20:06:31 +02: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
Umherirrender
778d266c2e api: Use ParserFactory on module creation
Change "Parser" to "ParserFactory" in object specs
and get a instance when needed

Bug: T343070
Change-Id: I9b65c272726bb0035f4cdca4fbf417a0a11375cb
2023-08-29 20:19:32 +02:00
Bartosz Dziewoński
365a588238 Use real type hints for services etc. in api/ except ApiQuery*.php
Mostly used find-and-replace:

Find:
/\*[\*\s]+@var (I?[A-Z](\w+)(?:Interface)?)[\s\*]+/\s*(private|protected|public) (\$[a-z]\w+;\n)((?=\s*/\*[\*\s]+@var (I?[A-Z](\w+)(?:Interface)?))\n|)
Replace with:
\3 \1 \4

Followed by some manual review to make sure I'm not changing too much,
omitting some changes that looked too complicated and anything that
caused test failures, and some whitespace fixes.

Change-Id: I6ec7587607df4f1a4f448a096c3e44c4e5270b70
2023-08-29 01:04:26 +00:00
Bartosz Dziewoński
1b825c1505 TempUserCreator: Change getStashedNameOrPlaceholder() to just getStashedName()
I found myself needing to just get the stashes name without the
placeholder for T331397, and I thought that this seems like a weird
API. The caller should get the placeholder separately if desired,
which is easy to do in all of the current callers.

Follow-up to 65f04c763a.

Change-Id: Icf1d24f17b60a461ef682bc5da01be6ebc3a2d93
2023-07-18 02:30:08 +02:00
Umherirrender
1086958611 Replace array_keys in foreach to use $_ as value instead
When the value of the associated array is not used, there is no need to
use array_keys and create internal a copy of the array, just omit the
value with $_ to tell static analyzer that the var is unused.

Change-Id: I5c6d667e98c0167c0573c683f0d617bc1d4ca619
2023-07-10 02:53:52 +00:00
Umherirrender
e77a022350 api: Replace deprecated ApiPageSet::getRedirectTitles in action=parse
Bug: T339384
Change-Id: Iabcaf55723118660648472047e0fd1f7cee56a50
2023-06-27 19:42:35 +02:00
James D. Forrester
83d72bc108 API: Replace deprecated calls to wfExpandUrl with UrlUtils::expand
Bug: T319340
Change-Id: Ic987f9381ac17e9e46504abdb2d07a5a94ba3b4a
2023-06-22 16:49:01 -04:00
Subramanya Sastry
0e9656e6da Add return type to getIndicators() in ParserOutput & OutputPage
This is in preparation for changes on the Parsoid side to make
sure its signature is compatible with the ContentMetadataCollector
interface there.

Change-Id: Ife4ae81dbc304097da7dcba40b143f7030b959f3
2023-06-02 16:13:01 +05:30
Tim Starling
54ca544726 Add convenience method TempUserCreator::shouldAutoCreate()
Factor out common concept originating in EditPage but since duplicated.

Change-Id: I5f5b75a7da9a40a6cc3041d3d6192d2d747b9f57
2023-05-12 15:31:11 +10:00
Umherirrender
65f04c763a api: Use a temp placeholder for signature on preview/pst
For pst on parse/compare/editstash/(all)revisions/(all)deletedrevisions

Do not show the IP when IP masking is enabled,
instead show a previous aquired temp name or a placeholder on preview.
MediaWiki itself used this for the ajax preview on GUI's action=edit

Cannot acquire a new unsaved temp user as api parse does not persist
the global session (each request results in a new id)
and it would require a db write on a read request.

Bug: T331397
Change-Id: I74bb4d655f371bd99e3b618d1a0ac45d730c746c
2023-05-04 20:52:40 +02:00
C. Scott Ananian
07a7ac0c88 ApiParse: Add 'parsoid' option
Allow requesting parsoid-format output from the action=parse API.

Change-Id: Iba9197491fd85e95b981206b63e43b470aac957c
2023-03-26 21:48:16 -04: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
4bb2886562 Reorg: Migrate WikiMap to WikiMap/ out of includes
And WikiReference

Bug: T321882
Change-Id: I60cf4b9ef02b9d58118caa39172677ddfe03d787
2023-02-27 05:19:46 +01:00
Amir Sarabadani
5323501d53 Reorg: Move EditPage.php to MediaWiki\EditPage
Also moving TemplatesOnThisPageFormatter to the same namesapce as it's
only used by EditPage

Bug: T321882
Change-Id: Ibefc44eb64aedb430148b109090584c3e35794ab
2023-02-15 22:40:10 +01:00
Nardog
bafbb39843 Fix API help URLs
expandtemplates API has had its own documentation page since 2016.
[[API:Parsing wikitext]] is now only about the parse API.

https://www.mediawiki.org/w/index.php?diff=2222810

Change-Id: Ia882752485926b89fbcb57d247ca0b41f048ac20
2023-02-10 14:08:29 +00:00
C. Scott Ananian
c1b3917c45 Pass appropriate userLang to ParserOutput::getText()
The rules for how ParserOptions::getUserLang() are set are a little
baroque.  When the 'uselang' option is set on the request, for example,
RequestContext::getLanguage() can differ from the user language; we
also deliberately force the "user language" to the content language
during the post-edit path to avoid having the user language leak into
the links table.

The changes in this patch make the ParserOutput::getText() calls "more
correct" but really they are just removing some uses of the global
RequestContext::getMain() from the code path, since in all of these
cases the main request context (which is what we use by default) does
have the correct language set.

For consistency, this patch also adds `allowTOC=false` in many of the
places where we already had `enableSectionEditLinks=false`; for
example, user interface messages, wikitext content injected on special
pages, etc.

Change-Id: Ib0d8c5e538e472ad672c45e5b68907242afb1e14
2023-02-01 16:02:12 +00: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
Jon Robson
5100288f6f Parse API should not include #mw-content-subtitle element
The newly created #mw-content-subtitle element should not be
included in parse API responses. That element is meant to identify
the subtitle area only.

Bug: T324876
Bug: T316830
Change-Id: Id8436324e2ae2fd9f488b65b3b7bfc19611870d1
2022-12-13 02:05:26 +00:00
jenkins-bot
381c1f0822 Merge "Track reason for rendering in more detail." 2022-11-17 12:44:01 +00:00
daniel
0820a7701f Track reason for rendering in more detail.
When setting causeAgent for jobs, be specific.
When creating parserOptions, call setRenderReason.

This allows us to capture statistics on what actions cause jobs,
renders, and cache writes.

Change-Id: Iaef64beadce1489bebb6bb00855c3ba6013a29d8
2022-11-15 15:32:03 +00:00
Bartosz Dziewoński
26ed8aee9f ApiParse: Avoid deprecated ParserOptions::newCanonical(), resolve todo comment
Change-Id: I5bc1a1ab2dffc2c835b8d6749f1bec404e1fa082
2022-11-14 18:09:28 +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
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
jenkins-bot
debd884db4 Merge "Use ParserOutputFlags::SHOW_TOC in ApiParse" 2022-09-09 21:49:14 +00:00
Reedy
b4717c2f0d api: Swap wfMessage() for $this->msg()
Change-Id: I5c80a2a36f601a46802170dd4747a32ecc7dffb3
2022-08-13 15:21:29 +01:00
Derick Alangi
3d03c6a1ff api: Migrate IDatabase::select() to SelectQueryBuilder interface
Bug: T311866
Change-Id: I5d79fce9d48b0d366ee2a918d3133186a5b65eb7
2022-08-08 15:52:34 +01:00
C. Scott Ananian
71686dc6f7 Use ParserOutputFlags::SHOW_TOC in ApiParse
Note: we should wait a full parser cache expiration time
after I3b76010f1e2283add629b84bf3824f215f932903 is deployed
in order to ensure that the parser cache entries all contain
the SHOW_TOC flag where appropriate.

Bug: T310083
Bug: T314000
Depends-On: I3b76010f1e2283add629b84bf3824f215f932903
Change-Id: I10c3d06fb162103c06395bf9d1d27ac3c199d7b6
2022-07-28 11:21:32 -04:00
C. Scott Ananian
3d2099f708 ApiParse: remove deprecated 'hidetoc' property
This was briefly used in ApiParse output, but never in a released
MW version.  We've transitioned VisualEditor to showtoc instead
to better match the underlying ParserOutput flag name, and so
hidetoc can be removed.

Bug: T314000
Depends-On: I823f26652b9770ea577daee32bff05864a7498bb
Change-Id: Icb9a79d4f7f1c2d01a8ac99a2de7d0784901b195
2022-07-28 11:17:04 -04:00
C. Scott Ananian
572409e568 ApiParse: transition 'hidetoc' to 'showtoc'
This ParserOutput flag will be renamed, so let's rename the API
property as well before this escapes out into the wild.

Bug: T314000
Change-Id: I1644a74370b42b04d0db167879f7de2207ebfcf5
2022-07-27 22:48:08 +00:00
Bartosz Dziewoński
add6c49e01 Fix edit API adding empty section title when creating new pages
WikitextContent methods replaceSection() (used when adding a section
to an existing page) and addSectionHeader() (used when creating a new
page) behaved inconsistently - the former would omit the heading
syntax when the section title was empty, but the latter would not.
They both omit it now.

Some callers of addSectionHeader() handled this case, but others did
not, which caused T311489. (I am removing the checks now, since the
change makes them redundant.)

Bug: T311489
Change-Id: Icd59bcf2b75bf50865f19fac92bddabe0c183dcc
2022-07-05 21:06:06 +00:00
Umherirrender
a5abaeba10 Call IContextSource::getAuthority instead of IContextSource::getUser
Change to use Authority object where possible
to use the interface instead of implementation

Change-Id: Ia7e9ce2a2f05ef2ae1cf981bf96faf48b04cf58d
2022-06-29 22:22:44 +02:00
jenkins-bot
01beedea28 Merge "ApiParse: When querying TOC sections, also return whether it should be hidden" 2022-06-15 20:38:35 +00:00
Bartosz Dziewoński
a63c258036 ApiParse: When querying TOC sections, also return whether it should be hidden
The table of contents is supposed to be hidden when the page has less
than 4 headings, but it can be overridden by several magic words.
The API provided no way to find out if it should be shown or hidden
for skins that don't use the built-in table of contents.

Using getTOCHTML() to check this is weird, but the TOC code is
currently enduring a rewrite, and this is how it's done in OutputPage.

Bug: T294950
Bug: T310083
Change-Id: I6cf76c870124c162dc1bcbc2f7e9ca0c5fdcd10e
2022-06-09 11:28:35 -04: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
jenkins-bot
b62bbbb68b Merge "ApiParse: Enable "skin mode" when mobileformat=1 is set" 2022-04-01 14:30:22 +00:00
Ed Sanders
9c2b72ba57 ApiParse: Enable "skin mode" when mobileformat=1 is set
Bug: T219420
Change-Id: I36db2cffa0cbedc7e89427c80301366168ff7f2e
2022-04-01 14:09:22 +00: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
Func
845bf42aa9 ApiParse: Ignore 'contentformat' param when the query is based on page
The 'contentformat' param should only have effects when the parsing
is based on the 'text' param, as what the document described.

Bug: T206253
Change-Id: Ia12b8697e515c6ba89ea81f085292d1ef018bf58
2022-03-20 20:33:20 +08:00
Func
5339aa645b ApiParse: Fail gracefully when the requested format is not supported
Format like 'application/json' is not supported for content model
wikitext, don't fail as internal exception.

This fix the case when providing text/title parameter.

Bug: T206253
Change-Id: I20ef52aa961143b7c50283c0d06acea9f220619c
2022-03-19 19:29:28 +00:00
C. Scott Ananian
a3000c2972 Export ParserOutput strategy keys for jsConfigVars
This allows Parsoid to properly merge jsconfigvars via the external API
(ie, when Parsoid is run in 'standalone mode') when an extension uses
the new-in-1.38 ParserOutput::appendJsConfigVar() method.

Change-Id: I974d9ecfb4ca8b22361d25c4c70fc5e55c39d5ed
2022-03-09 17:42:00 -05:00
Ppchelko
643fc535c3 Reapply "Move limit report rendering to ParserOutput"
This reverts commit 2bcb3fe567.

Reason for revert: this is a good change,
just needed more work to not break CI

Change-Id: I23768bee242e3cf81b1493a740cf070e7ad1e224
2021-11-09 11:08:08 -08:00
Ppchelko
2bcb3fe567 Revert "Move limit report rendering to ParserOutput"
This reverts commit 89028e0b8e.

Reason for revert: Temporary until we deal with T295357

Change-Id: I556de18dbf900a9bc58d5ae22d1bf194682d0840
2021-11-09 15:57:18 +00:00
Petr Pchelko
89028e0b8e Move limit report rendering to ParserOutput
This does not move the actual limit report data into
ParserOptions yet, that should be done separately
given that it will require serialization changes.
Let's get this change settled first before messing
with serialization.

This unifies canonical and non-canonical ParserOptions,
so ParserCache can now be used with both. It is hard
to say how this will affect the ParserCache capacity,
so we should monitor it after releasing this.

Change-Id: I154c0a77a5b0287b5572614d56339fb57ac56c33
2021-11-08 12:45:41 -08:00
C. Scott Ananian
f3d7462e37 Set ParserOutput 'injectTOC' based on Skin options for page views
Clean up loose ends from the skin table of contents patch (I44045b3b9).

* Clarify $options -> $skinOptions (because there are so many different
  "options" classes!)
* Remove redundant default when Article::doOutputFromParserCache()
  calls ParserOutput::getText() -- the 'injectTOC' option defaults
  to true inside ParserOutput::getText() as well.

Bug: T287767
Followup-To: I44045b3b9e78e7ab793da3f37e3c0dbc91cd7d39
Change-Id: I04b8d8a4076df551347ec6d6599d597424a2dadf
2021-11-08 18:09:46 +00:00
jdlrobson
24949480eb Give skins more flexibility over table of contents render
* Do not store table of contents in parser output
* Instead inject table of contents via strpos where needed
  inside Article based on Skin "toc" option
* Use <mw:tocplace> as a TOC placeholder; for Parsoid compatibility
  this will be replaced with a <meta> tag in a followup patch.

Bug: T287767
Change-Id: I44045b3b9e78e7ab793da3f37e3c0dbc91cd7d39
2021-10-25 22:26:41 +00:00
Roman Stolar
fa5237eb48 Replace Content::getParserOutput call to ContentRenderer::getParserOutput
Bug: T287158
Change-Id: I8a13f45027e08e2d8ddefa140dd47a0c55094934
2021-10-20 12:11:24 +03:00