Commit graph

247 commits

Author SHA1 Message Date
Umherirrender
e662614f95 Use explicit nullable type on parameter arguments
Implicitly marking parameter $... as nullable is deprecated in php8.4,
the explicit nullable type must be used instead

Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a

Break one long line in SpecialPage.php

Bug: T376276
Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
2024-10-16 20:58:33 +02:00
James D. Forrester
a5387c7c20 Namespace all remaining classes in includes/parser
Bug: T353458
Change-Id: If02cc9b1ff78e26c1cf8c91ee4695845eb133829
2024-10-15 23:54:32 +01:00
James D. Forrester
53b67ae0a6 Add namespace to remaining parts of Wikimedia\ObjectCache
Bug: T353458
Change-Id: I3b736346550953e3b2977c14dc3eb10edc07cf97
2024-09-27 16:19:10 -04:00
Umherirrender
8e8a56c880 parser: Add missing documentation to class properties
Add doc-typehints to class properties found by the PropertyDocumentation
sniff to improve the documentation.

Once the sniff is enabled it avoids that new code is missing type
declarations. This is focused on documentation and does not change code.

Change-Id: I3afaba387663320187c49ff1cdb2ff3ae01681ad
2024-09-07 22:46:08 +02:00
Dreamy Jazz
ea295a2b5f Use stashed temp name in ParserOptions::newFromContext over anon
Why:
* The REVISIONUSER magic word displays the username of the user
  making the edit when the user is previewing an edit
* When temporary accounts are enabled, the user performing the
  edit should see a temporary account name and not an IP address
  to avoid confusion.
* This currently works as intended for all but the user's first
  edit because, until they have submitted their first edit, they
  have no temporary account. However, they should have a stashed
  name for a non-existing account.
* Setting the ParserOptions user as the stashed name in this
  edge case fixes the issue and should not cause unintended side
  effects.

What:
* Update ParserOptions::newFromContext to use the stashed temporary
  account name if all of the below are true:
** The current context user is an IP address
** Temporary account autocreation is enabled
** The user has a stashed name defined in their session
* In all other cases the user used in ParserOptions::newFromContext
  is unchanged.
* Add tests for ParserOptions::newFromContext to verify these
  changes and to avoid regressions.

Bug: T372723
Change-Id: Ie532aa997a59cbf5204a554bd087ba7451f7d47a
2024-09-06 13:44:33 +01:00
Novem Linguae
bf8e83fe44 ParserOptions: delete 3 hard deprecated methods
Git blame on wfDeprecated() is 4 years old.

Unique names, no sign of them in CodeSearch.

Bug: T362636
Change-Id: I90f11dc78be0938aea53a304b5824f034dd70107
2024-06-26 18:56:59 +00:00
C. Scott Ananian
8d031bcf87 Add ParserOptions::setCollapsibleSections()
This is a non-default option that will add a <div> wrapper around
section contents to allow client-side collapsing.  This is intended
for use by MobileFrontEnd, but could eventually be enabled for
desktop read views as well.

Since this parser option is in the "cache-varying options" set, any
caller who sets this option will fork the cache for that page, which
is reasonable as the parser options sets a ParserOutput property.
In the future our caching strategy will get smarter and we'll add
code which avoids the cache split and just transfers the appropriate
values from ParserOptions to ParserOutput flags after the cached
output is retrieved.

Bug: T359001
Change-Id: Ie93959a056ed15a728404eb293e4bb6eeaeb15c0
2024-04-29 12:11:09 -04:00
C. Scott Ananian
06f683b983 Mark ParserOptions suppressSectionEditLinks as safe to cache
This will split the cache for now, but pages are generally either
always rendered with suppressed edit links or always rendered without
suppressed edit links.  Previously, ParserCache would report the page
as "not safe to cache" and always bypass the cache when
suppressSectionEditLinks was set.  This isn't a problem since no one
uses this parser option yet in production, although the original
motivation was to replace the mutation of the $options array
done by the Translate extension in the ParserOutputPostCacheTransform
hook here:
  5eff51db88/src/PageTranslation/Hooks.php (197)

See 770d2bf040 for more information.

Change-Id: I88e33248c1e40a8aa694974b2a1f94e36d8c7ed6
2024-04-25 14:12:40 +00:00
Subramanya Sastry
e55cc517da Move Parser to Mediawiki\Parser namespace
Bug: T166010
Co-Authored-By: Daimona Eaytoy <daimona.wiki@gmail.com>
Co-Authored-By: James Forrester <jforrester@wikimedia.org>
Co-Authored-By: Subramanya Sastry <ssastry@wikimedia.org>
Change-Id: I79b4e732c45095eedbaa80afa5eb7479b387ed8a
2024-02-16 09:18:38 -05:00
jenkins-bot
42d23476b9 Merge "WikiPage: remove ::suppressTOC hack" 2024-02-10 02:02:09 +00:00
C. Scott Ananian
770d2bf040 [ParserOutput] Make 'enableSectionEditLinks' a ParserOption
This will allow the Translate extension to set this parser option
in the ArticleParserOptions hook, instead of mutating $options passed
to ParserOutput::getText() in the ParserOutputPostCacheTransform hook.

It ought to also help to handle the many places which call:

   ... = $parserOutput->getText( [
       'enableSectionEditLinks' => false,
   ] );

by allowing them to set the appropriate ParserOption instead
of passing arguments to ::getText().

Bug: T350626
Change-Id: I719c115194059060f7f888608417a194ac80cc92
2024-02-09 23:42:03 +00:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
C. Scott Ananian
0196c8a5d8 WikiPage: remove ::suppressTOC hack
Instead of overriding the ParserOptions for the page, just clear the
section data and set the NO_TOC flag in the resulting ParserOutput.

Bug: T307691
Bug: T350626
Change-Id: I6a24edcc5eb5bed50adcfb8648b953afa54ac0f6
2024-02-05 17:01:44 -05:00
Umherirrender
9b0591448e Use UserFactory::newAnonymous
Bug: T325686
Change-Id: Ia7ce7df94c233a4534625d250229806fb21d8017
2024-01-22 20:39:05 +00:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Amir Sarabadani
15a278189f Reorg: Move MWTimestamp to MediaWiki\Utils
Bug: T321882
Change-Id: I48c10343295c4eb3d9ef8037343b0070e928f040
2023-08-19 05:53:40 +02:00
thiemowmde
ef84619cd3 Consistently use LogicException for test-only methods
"BadMethodCallException" sounds like it would fit, but it does
have a very different meaning, described as "exception thrown if
a callback refers to an undefined method or if some arguments are
missing". This is not what's going on here. These are methods that
should only be called from unit tests.

This appears to be a common mistake, often copy-pasted.

Change-Id: Ib39e28f596a883481d5f526460a5c871c75f5313
2023-07-22 16:21:42 +00:00
Subramanya Sastry
c6fcbbaf44 Fix comment in ParserOptions::optionUsed to reflect current reality
Change-Id: I4792e8d3b0be2507c72a6ca88ce2ed0ebddd452e
2023-06-29 18:20:46 -05:00
Umherirrender
e04d3a28f6 Replace internal Hooks::runner
The Hooks class contains deprecated functions and the whole class is
going to get removed, so remove the convenience function and inline the
code.

Bug: T335536
Change-Id: I8ef3468a64a0199996f26ef293543fcacdf2797f
2023-05-11 06:17:38 +00:00
C. Scott Ananian
cfd9c516e1 Allow setting a ParserOption to generate Parsoid HTML
This is an initial quick-and-dirty implementation.  The
ParsoidParser class will eventually inherit from \Parser,
but this is an initial placeholder to unblock other Parsoid
read views work.

Currently Parsoid does not fully implement all the ParserOutput
metadata set by the legacy parser, but we're working on it.

This patch also addresses T300325 by ensuring the the Page HTML
APIs use ParserOutput::getRawText(), which will return the entire
Parsoid HTML document without post-processing.  This is what
the Parsoid team refers to as "edit mode" HTML. The
ParserOutput::getText() method returns only the <body> contents
of the HTML, and applies several transformations, including
inserting Table of Contents and style deduplication; this is
the "read views" flavor of the Parsoid HTML.

We need to be careful of the interaction of the `useParsoid` flag with
the ParserCacheMetadata.  Effectively `useParsoid` should *always* be
marked as "used" or else the ParserCache will assume its value doesn't
matter and will serve legacy content for parsoid requests and
vice-versa.  T330677 is a follow up to address this more thoroughly by
splitting the parser cache in ParserOutputAccess; the stop gap in this
patch is fragile and, because it doesn't fork the ParserCacheMetadata
cache, may corrupt the ParserCacheMetadata in the case when Parsoid
and the legacy parser consult different sets of options to render a
page.

Bug: T300191
Bug: T330677
Bug: T300325
Change-Id: Ica09a4284c00d7917f8b6249e946232b2fb38011
2023-03-26 21:46:05 -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
C. Scott Ananian
24d69ef952 Deprecate Parser::getFunctionLang()
This is identical to Parser::getTargetLanguage() in modern MediaWiki,
since 7df3473cfe in MW 1.19 (2012).

Bug: T318860
Depends-On: If5fa696e27e84a3aa1343551d7482c933da0a9b6
Depends-On: I87a7ceedce173f6de4bb6722ffe594273c7b0359
Change-Id: Ieed03003095656e69b8e64ed307c6bd67c45c1e7
2022-11-16 16:47:16 -05:00
daniel
118d4980b2 Track the reason for rendering.
Allow the causeAction that triggers page rendering to be looped through
to ParserCache, so we can count what causes writes to the cache.

Change-Id: I6ad8e105a3ce457e3ab4f85cd154f47a32085e0d
2022-11-09 09:38:57 +00:00
Umherirrender
1b342a8893 Various doc fixes about false and null on method arguments/return types
Doc-only changes

Change-Id: Ice974b3ba41708859dfe646e94b31c5ebbf26410
2022-11-03 18:55:47 +01:00
Amir Sarabadani
0fff5089ba Reorg: Move StubObject classes in includes to its own directory
Bug: T166010
Change-Id: Idcf0e9dc6e0841e4f132207bce0f96774dad898c
2022-10-25 16:04:48 -04: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
C. Scott Ananian
dd32fe1a34 Mark ParserOptions::{get,set}MaxTemplateDepth() @internal
This option is not used outside core, according to codesearch:

 https://codesearch.wmcloud.org/deployed/?q=etMaxTemplateDepth&i=nope&files=&excludeFiles=&repos=

ParserTests can set this in the site config; this doesn't need to be
a parser option.

Bug: T318826
Change-Id: I815d340a43870249db5e36084a5e5403bb71b6ca
2022-09-28 15:22:10 -04:00
C. Scott Ananian
b7b13c87f4 Mark ParserOptions::{get,set}ExternalLinkTarget() @internal
This option is not used outside core code, according to codesearch:

  https://codesearch.wmcloud.org/deployed/?q=etExternalLinkTarget&i=nope&files=&excludeFiles=&repos=

Users should set this in the site config, not as a parser option.

The installer will eventually invoke Parsoid directly (T317644) with
a custom site config.

Bug: T317647
Change-Id: I099c04045de256ef0fb4cb114ee3c2be350dfdc4
2022-09-28 15:17:33 -04:00
C. Scott Ananian
cc79898522 ParserOption/ParserOutput flag to suppress or hide the table of contents
There are two related issues here: first, when parsing non-wikitext
pages for side effects (categories, etc) we want to ensure that any
spurious `===` or `<h2>` on the page don't create nonsense "sections".
We introduce a ParserOption to suppress the ToC in this case; a
follow-up patch will set this parser option from the correct path in
CodeContentHandler and its subclasses. [T307691]

Second, modern skins can generate the ToC on-the-fly outside the
content area, and need to be able to regenerate the ToC from API
output when the page is edited.  A ParserOutput flag is added to
mirror the $enoughToc variable from the parser to indicate whether
or not the ToC should be generated and/or updated after edit.
(See I6cf76c870124c162dc1bcbc2f7e9ca0c5fdcd10e for parallel code
to echo this value in ApiParse.)

Bug: T294950
Bug: T307691
Change-Id: I35e199cca40c0e4359ac493e5806dcf4ae49321c
2022-07-21 15:29:11 -04:00
Kosta Harlan
a9ee442f7f ParserOptions: Add fallback to enableMagicLinks
Due to quirks of bootstrapping process in PHPUnit, enableMagicLinks can
end up as null instead of an array with keys expected by ParserOptions.
As a workaround, set a fallback for each expected key.

Change-Id: I1511503937f8ac4fcd2f2c8b98bfd7dba17385ec
2022-06-03 14:43:16 +00:00
Aryeh Gregor
7b791474a5 Use MainConfigNames instead of string literals, #4
Now largely automated:

VARS=$(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | \
  tr "\n" '|' | sed "s/|$/\n/;s/'//g")
sed -i -E "s/'($VARS)'/MainConfigNames::\1/g" \
  $(grep -ERIl "'($VARS)'" includes/)

Then git add -p with lots of error-prone manual checking. Then
semi-manually add all the necessary "use" lines:

vim $(grep -L 'use MediaWiki\\MainConfigNames;' \
  $(git diff --cached --name-only --diff-filter=M HEAD^))

I didn't bother fixing lines that were over 100 characters unless they
were over 120 and triggered phpcs.

Bug: T305805
Change-Id: I74e0ab511abecb276717ad4276a124760a268147
2022-04-26 19:03:37 +03:00
Derick Alangi
ccac0f2077
linker,parser: Remove deprecated Linker & Parser methods
Change-Id: I8207bf137c1c10534ed797901de2710dfc379ea7
2022-04-14 14:06:28 +01:00
Umherirrender
45a4868f55 parser: Adjust documentation about false for $wgExternalLinkTarget
The default for $wgExternalLinkTarget is false,
which can be set or returned on ParserOptions

Found by phan strict checks

Change-Id: Ibcf6c40eaf1ffb628fc1b92a0d0ecd79d9421100
2022-03-03 22:35:41 +01:00
daniel
026133bb05 remove access to config globals from includes/parser
Loops ServiceOptions through to CoreParserFunctions and CoreTagHooks to
avoid access to the main config from static methods.

Bug: T294739
Change-Id: Ia6c97f2d0952964c2ad6189f8053ad127589b37c
2022-02-01 07:48:57 -08:00
Reedy
2a2bb1e9bd Remove or replace usages of "sane"
Bug: T254646
Change-Id: I096b2cf738a1395a14f1d47bcbed0c2c686c2581
2021-11-22 13:35:17 +00:00
jenkins-bot
0d188e7cdd Merge "parser: Make ParserOptions::registerWatcher() public and ::optionUsed() private" 2021-11-16 18:36:26 +00: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
Timo Tijhof
066690c8f4 parser: Make ParserOptions::registerWatcher() public and ::optionUsed() private
Follows-up fe14fdefa7 (r79018), which introduced the registerWatcher()
method with the comment that it was for internal use by the Parser.

Howevever it lacked an `@internal` annotation, and it is de-facto used
in various places now, so perhaps we should just consider it public.

This can be changed of course, but that should probably be done through
its own explicit deprecation given it's been around so long and used
in various places.

The ::optionUsed() option is only used internally, introduced by the
same commit, and has no known caller or theoreretical need to be called
outside this class. Make this private going forward.

Change-Id: Iab006be742b7bdf55a0d79509e8b827e109e9ceb
2021-11-08 20:33:36 +00:00
Subramanya Sastry
f70b15558f Get rid of ParserOptions::setTidy()
Bug: T198214
Change-Id: I90ea6ce6831caa92e5d88d843132161a5fc66184
2021-10-07 15:13:59 -05:00
Amir Sarabadani
649bbdd6c5 Remove "auto-number headings" preference
Bug: T284921
Change-Id: Ic9ed88f419419cf4cc5cc32010539eea8b76314b
2021-10-03 00:47:08 +02:00
Petr Pchelko
a407ce4124 Remove hard-deprecated methods returning User from Parser
Change-Id: I4ff100136a777974f7206f599422589d51f02b88
2021-09-26 14:50:14 -07:00
Petr Pchelko
5afc62f258 Remove stub threshold feature
Bug: T284917
Change-Id: I5c9ea04a9deca136bb7210f07200d18f97fd6686
2021-09-13 09:26:38 -07:00
Arlo Breault
e6970ac8d3 Fix throws from parserTestsRunner.php
This lets test/parser/parserTests.php run.

Follow up to I9e820045443be1df2c89e1ed4b56f0d55662c486

Change-Id: I92f00a58ed1e0717a39ab5a6d258800326eebeed
2021-08-19 02:23:03 +00:00
vladshapik
1091f7753f Hard-deprecate Parser::mUser public access, Parser::getUser and ParserOptions::getUser
Bug: T285713
Depends-On: Ie75c9cd66d296ce7cf15432e2093817e18004443
Change-Id: I4297aea3489bb66c98c664da2332584c27793bfa
2021-08-17 15:42:05 +00:00
Petr Pchelko
79475042a5 ParserOptions: support setting a default for lazy options
If the default is not set for a lazy loaded option,
canonical parser output key ends up being 'lazy_option=default',
because when computing the keys we exclude defaults.

If on the other hand we register a default for a lazy option,
it does not get loaded, since in lazyLoadOption we believe
the default is already the loaded value.

Change-Id: I92b3e18fabef4eecac2ec2a4844f1be2716e5d89
Needed-By: I3bce04684070ad306685dabbc51267def25773cd
2021-08-10 10:22:05 -07:00
Petr Pchelko
39c6c5e34c Tests: reset ParserOptions static cache with MW services
ParserOptions store the result of ParserOptionsRegister
hook execution in a static cache. If we register a lazy
option, which depends on user options and use OptionsLookup,
tests break because a lookup from a destroyed service container
ends up being reused between tests.

The reset was added to resetLegacyGlobals because 1) it's
called at all the right times 2) this static cache is legacy,
when we have a factory service for ParserOptions, this will
not be needed anymore.

Change-Id: I9e820045443be1df2c89e1ed4b56f0d55662c486
2021-08-10 09:11:19 -07:00
DannyS712
29ec3ec7e3 Remove $wgUser fallback in ParserOptions
ParserOptions::__construct() and ::newCanonical()
no longer accept null and fallback to the global
$wgUser - instead, ::__construct() has a typehint
for a UserIdentity, and ::newCanonical() will throw
an exception.

Bug: T284977
Change-Id: I35865e160190582ab10abaa696c6fc6686cc8989
2021-06-24 02:55:20 +00:00
Petr Pchelko
61599cd74a Clean up hard-deprecated Parser methods returning Revision
Bug: T278376
Change-Id: Ia4b5ab71c1df20e07dbfa3465be022225e8b44c1
2021-04-26 13:59:53 -07:00