Commit graph

1526 commits

Author SHA1 Message Date
Umherirrender
1934b45c65 parser: Fix version mention for class_alias
e55cc517da is REL1_42

Follow-Up: I79b4e732c45095eedbaa80afa5eb7479b387ed8a
Change-Id: Ib92b8f64f7443406742c5c6244866e701b010079
2024-07-05 16:16:44 +00:00
Arlo Breault
6b05fa3a21 Remove image and gallery image caption trimming
Post I5039c7ef9e07199c256fd568b4f94714e5831d17, gallery image captions
are no longer placed on new lines, so the presence of leading whitespace
shouldn't be significant.

This fixes an inconsistency in gallery image caption trimming, where
only the first and last option had start and end trimming, respectively.

It also matches Parsoid output, where no trimming takes places, as seen
in the updated tests.

Change-Id: I2a80198c43598dc8c7fa61cb4b0340a97d2ee895
2024-06-26 21:51:40 -04:00
Umherirrender
c08b492d75 Use namespaced classes (3)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Ia35b2d3105880631dd26ec974068b000ac7f4b6b
2024-06-16 20:26:43 +02:00
jenkins-bot
45c105ec46 Merge "Parser: Avoid extra escaping in replaceTableOfContentsMarker" 2024-06-12 19:51:18 +00:00
vahurzpu
fbba3bb2cf Parser: Avoid extra escaping in replaceTableOfContentsMarker
I60fdfc2c52 changed replaceTableOfContentsMarker from using
preg_replace, which supports backreferences in the replacement, and
thus expects literal backslashes and dollar signs to to be escaped,
to using preg_replace_callback, which does not expect any escaping.
This caused unwanted backslashes in headings. This patch removes the
escaping.

Bug: T365413
Change-Id: Idbdc3074c7ad007627c4c259a1aaf090a5d0c7f9
2024-06-12 06:10:58 -04:00
jenkins-bot
bbadf63fa8 Merge "Move Linker::makeExternalLink() to the LinkRenderer service" 2024-06-10 19:58:45 +00:00
C. Scott Ananian
b855c62f66 Move Linker::makeExternalLink() to the LinkRenderer service
Move Linker::makeExternalLink to the LinkRenderer service, as has been
done with the other static methods of Linker.

In order to allow phan's SecurityCheckPlugin to perform a more accurate
analysis of taintedness, tweak the API of Linker::makeExternalLink to
clearly indicate via the type system whether the link text has already
been escaped or not: a `string` argument will always be escaped, and
if the argument is already escaped it should be passed as an HtmlArmor
object.  In refactoring, `Message` arguments were also common, and accept
them as-is to avoid the caller having to think about whether to call
Message::text() or Message::escaped().

This allows us to provide a more precise taint type to the $text argument,
avoids an opaque boolean argument, and avoids spurious errors from
SecurityCheck.

We also require the caller to explicitly pass a Title context, instead
of implicitly relying on the global $wgTitle.  This works cleanly
everywhere except for CommentParser, which has a $selfLinkTarget which
generally works as the title context for the external link, but which
is nullable.  The original Linker::makeExternalLink() used $wgTitle as
a fallback, but $wgTitle can also be null in some circumstances.  The
title context only determines how $wgNoFollowNsExceptions is handled,
so existing code basically just ignored $wgNoFollowNsExceptions when
$wgTitle was null, which isn't terrible.  A future refactor could/should
clean up CommentParser to ensure that there is always a non-null title
context that can be used.

Change-Id: I9bcf4780f388ba639a9cc882dd9dd42eda5736ae
2024-06-10 18:47:32 +00:00
jenkins-bot
afef7619f3 Merge "Parser: Deprecate use of mOutput before initialization" 2024-06-06 16:07:42 +00:00
Paladox
580811c573 Parser: Deprecate use of mOutput before initialization
In some extensions they check that getOutput returns null
if it does they return early.  For example:

https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/5579

But with the type change in I247643b9bf0cabdc92a7e893d653edeaed9a1307
(MW 1.41.0), that attempt fails with the following:

```
Error: Typed property Parser::$mOutput must not be accessed before initialization
```

Fix this by allowing Parser::getOutput() to return null,
but emit a deprecation warning to notify users that the
Parser object has not been property initialized at this
point.

Change-Id: I0de2cf0381ceac36374a47fb11e260b1c522353b
2024-06-06 15:48:41 +00:00
Derk-Jan Hartman
2953f337fa Detect modern image formats when using wgAllowExternalImages
Add webp, avif, and svg

Bug: T365636
Change-Id: I11c45094c9f2228bc4a019ff2946a58bc91ba9a0
2024-05-24 21:55:42 +00:00
Fomafix
66aa439d00 Parser: Inject service LanguageNameUtils
Change-Id: Ia9884f991550c96e4d9bbca9bfb882144716cd24
2024-05-20 19:23:37 +00:00
Ebrahim Byagowi
97d1202784 Add namespace and deprecation alias to TextContent
This patch introduces a namespace declaration for the
MediaWiki\Content to TextContent and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: Ic251b1ddfcf6db9c85cb54cddf912aa827d2bc3a
2024-05-19 23:23:01 +03:30
jenkins-bot
bb1f7e4aa2 Merge "Deprecate Parser::replaceVariables with associative array instead of frame" 2024-05-18 15:21:39 +00:00
jenkins-bot
c5387f3802 Merge "[OutputPage] Hoist "null Title" checks up a level" 2024-05-18 15:19:50 +00:00
Ebrahim Byagowi
14b4269d83 Add namespace and deprecation alias to Xml and XmlSelect
This patch introduces a new namespace declaration,
MediaWiki\Xml and adds Xml and XmlSelect to it
and establishes class aliases marked as deprecated
since version 1.43.

Bug: T353458
Change-Id: I45cccd540b6e15f267d3ab588a064fbeb719d921
2024-05-16 15:23:14 +03:30
C. Scott Ananian
f61760614d [OutputPage] Hoist "null Title" checks up a level
Add strict types to private parsing-related methods
OutputPage::parseInternal() and OutputPage::addWikiTextTitleInternal()
and in the process hoist the "null Titles are not allowed" assertion
up a level to the callers.

Adjust some phan suppressions after this change.

Change-Id: If828d9ffa1edc292a1aca3eb6fe36daffa100bd4
2024-05-15 11:25:36 -04:00
Bartosz Dziewoński
12e40cadc0 Fix hashes (#) in "Parser function hooks"
To display the names as they're used in wikitext, we must look up the
right syntax, as not all of them are prefixed with "#".

This also displays them in content language (not sure if that's good,
but if we want them to look like they're supposed to be used in
wikitext, I guess it is?), in the preferred case, and in the right
order (order of hooks like 'lc' and 'lcfirst' was previously
reversed, because the trailing '}}' was considered when sorting).

Follow-up to 9308818ee9.

Change-Id: Ia7c505e196e7ae28badc6314b2d6c91f8be45689
2024-05-08 23:58:46 +02:00
Hakan Özdemir
6c5684d41f Add namespace and deprecation alias to DeprecationHelper
This patch introduces a namespace declaration for the
MediaWiki\Debug to DeprecationHelper and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I808c6aa7836445feaa7b401624d79d01f2c70322
2024-05-05 14:16:35 +02:00
C. Scott Ananian
295fada599 Deprecate Parser::replaceVariables with associative array instead of frame
Change-Id: I7de8ccfb20db0f9428b13017bcd93ed167d7436c
2024-05-02 12:06:09 -04:00
Isabelle Hurbain-Palatin
03c4ffe137 Replace TOC markers only once, if any
The legacy parser only allows for a single insertion of TOC (it drops
later __TOC__ magic words). On Parsoid, we can end up with multiple TOC
markers (which we want to keep around for round-trip reasons), so we
need to discard them in the HandleTOCMarkers phase.

Bug: T359882
Change-Id: I60fdfc2c52680ed53e48d1931fd7f5c937b437a2
2024-05-02 14:54:43 +02:00
Taavi Väänänen
ed7e787f32
Ignore/fix MediaWiki.Commenting.PropertyDocumentation.WrongStyle
Fix the real issues found by this sniff, and convert the remaining
false positive ignores to per-line ignores so that any more real issues
won't be added.

Change-Id: I18e75d59df327e2d93a3a487c115e92b9f268722
2024-04-22 18:26:14 +03:00
Taavi Väänänen
e2fd40cb77
Drop hard-deprecated Parser::getFreshParser
Bug: T325959
Change-Id: I6c4f33d7b1104756559043290a13ffccd3941d07
2024-04-21 22:06:10 +03:00
jenkins-bot
3202b6ac91 Merge "[ParserOutput] Remove deprecated ::getTOCHTML() and ::setTOCHTML() methods" 2024-04-17 20:25:53 +00:00
C. Scott Ananian
195ac55bfe [ParserOutput] Remove deprecated ::getTOCHTML() and ::setTOCHTML() methods
These were deprecated with warnings in 1.40.

Change-Id: I8027bc26c71ae94d3d5c7e5112545cd1b35749aa
2024-04-16 13:00:58 -04:00
C. Scott Ananian
a87b8754c9 [Parser] Add deprecated Parser::$mTemplatePath property
We are deprecating dynamic properties on the Parser object, but as a
first step we're making them *actual* properties, so that we can draw
a line in the sand against adding new dynamic properties.  In a follow
up we'll actually remove this property from the
LabeledSectionTransclusion extension.

An entry in RELEASE-NOTES-1.42 was already added in
Id3dbc99d92f2769d4e5c95293cf1a277b98ddd3b.

Bug: T362693
Bug: T343227
Bug: T362692
Followup-To: I701a27459704839f9f996a171b6982ed17cdd00b
Change-Id: I3a992f4d601135b6327d941a1852e861d1e82d78
2024-04-16 12:21:10 -04:00
C. Scott Ananian
26106a04dd [Parser] Add deprecated Parser:$proofreadRenderingPages property
We are deprecating dynamic properties on the Parser object, but as a first
step we're making them *actual* properties, so that we can draw a line in
the sand against adding new dynamic properties.  In a follow up we'll
actually remove this property from the ProofreadPage extension.

Also add an entry to RELEASE-NOTES-1.42, which
Ifcb9492cc5c814d702c6e61e8231abfd8ea0647c forgot to include.

Bug: T362664
Bug: T343227
Followup-To: Ifcb9492cc5c814d702c6e61e8231abfd8ea0647c
Change-Id: Id3dbc99d92f2769d4e5c95293cf1a277b98ddd3b
2024-04-16 10:13:54 -04:00
jenkins-bot
bd6b83c25f Merge "Parser::statelessFetchTemplate: remove dead code; add test cases" 2024-04-15 09:39:41 +00:00
C. Scott Ananian
deee755234 [Parser] Mark $mPPNodeCount and $mHighestExpansionDepth @internal
Code search:
 https://codesearch-beta.wmcloud.org/search/?q=-%3EmPPNodeCount%5Cb
 https://codesearch-beta.wmcloud.org/search/?q=-%3EmHighestExpansionDepth%5Cb

Bug: T236810
Bug: T236812
Change-Id: Ib49e215fc2895ac8423ead2ab60d4b5c94c7141e
2024-04-12 16:55:51 -04:00
C. Scott Ananian
add081f5f3 [Parser] Emit warnings for accesses to deprecated $mOptions property
Code search:
  https://codesearch-beta.wmcloud.org/search/?q=arser-%3EmOptions%5Cb

Patches to non-deployed code:
* https://github.com/ProfessionalWiki/SubPageList/pull/75
* PhpTagsFunctions: I1a72e88c5cc3d0587f085f5fa65d1f7ebb9fb602
* S5SlideShow: Ie2268432c9398af11fd02216a45df78e72609e15
* SemanticACL: I01243660d7241e094f60f5acb97726539c07c676
* VisualData: I1a972e159e6de3f94589a0c215d7f96c602b04bb
* https://github.com/Open-CSP/WikiSearch/pull/50
* https://github.com/SemanticMediaWiki/SemanticFormsSelect/pull/112
* https://github.com/SemanticMediaWiki/SemanticResultFormats/pull/828
* https://github.com/haleyjd/WikiActivity/pull/2
* https://github.com/thaider/Tweeki/pull/273

Bug: T236810
Bug: T236812
Change-Id: I8b98e851e6536f1a02bc41a6253c9ffe7c50ed36
2024-04-12 16:06:47 -04:00
C. Scott Ananian
4c047b6529 [Parser] Emit warnings for accesses to deprecated $mTitle property
Code search:
 https://codesearch-beta.wmcloud.org/search/?q=arser-%3EmTitle%5Cb

Patches to non-deployed code:
* I605b1eb8f6b8dd9a92e4652889b8641c929f7bbc
* https://github.com/Open-CSP/WikiSearch/pull/49

Bug: T236810
Bug: T236812
Change-Id: I0e859b2fd51ad3d0286df44087cd4c0354bf438d
2024-04-12 15:57:59 -04:00
C. Scott Ananian
d0622372ab [Parser] Emit warnings for accesses to deprecated $ot property
Code search:
 https://codesearch-beta.wmcloud.org/search/?q=-%3Eot%5Cb

Bug: T236810
Bug: T236812
Change-Id: Id706c38f5cf9fee51238483c9cf2f52f0ed052ad
2024-04-12 15:57:55 -04:00
C. Scott Ananian
9bc428fe84 Deprecate use of dynamic properties attached to Parser
Hack in declared public properties to work around T343229 (use in
Scribunto), T343230 (use in Cite), T343226 (use in TemplateStyles),
T203531 (use in Variables), T203532 (use in Arrays), T203563 (use
in Loops), T359887 (use in HashTables) and T357838 (use in parser
tests) for now, but we can draw a line in the sand and not allow
any further use of this pattern.

Bug: T343227
Depends-On: Ifcb9492cc5c814d702c6e61e8231abfd8ea0647c
Change-Id: I701a27459704839f9f996a171b6982ed17cdd00b
2024-04-12 15:24:44 -04:00
jenkins-bot
2472cd9247 Merge "Substitute category default sort key when filling links table, not at parse time" 2024-04-11 14:59:33 +00:00
C. Scott Ananian
4cc84cdafa Parser::statelessFetchTemplate: remove dead code; add test cases
Remove dead code left over from the removal of the
BeforeParserFetchTemplateAndtitle (sic) hook in
20c5632c4e.

While we're at it, add test cases for statelessFetchTemplate and
improve coverage.

Followup-To: Ifecd4108eb02ebccc0c7bc4ec432036da08ffe53
Followup-To: Idf1fd12cc61ca30867dc9f8aeb1701fe035fc5ff
Change-Id: I135f5234e7be015a2781d6cb8d23b3143b618c5a
2024-04-10 17:36:04 -04:00
C. Scott Ananian
3abab91259 Parser::statelessFetchTemplate: don't add interwiki redirects to dependencies
Bug: T362221
Change-Id: Ifecd4108eb02ebccc0c7bc4ec432036da08ffe53
2024-04-10 11:27:52 -04:00
C. Scott Ananian
63293370e5 Don't strip non-newline whitespace from left side of language links
This follows up on I5e87b33a956e296cdaf671fa99c9555944b73479 and makes
(invisible) language links consistent with how we handle (invisible)
category links.

Bug: T359886
Followup-To: I5e87b33a956e296cdaf671fa99c9555944b73479
Change-Id: I3e5567a91b47e0b04da928450644f3f475aaf51b
2024-03-29 18:46:16 -04:00
C. Scott Ananian
bf7120f80e Don't strip non-newline whitespace from left side of [[Category]] links
This follows up on a long series of tweaks to whitespace handling around
[[Category]] links (T2087, T87753, T174639) which aimed to simplify and
make intelligible the whitespace handling around category links without
allowing categories to break lists or paragraphs in which they are found.

Removing newlines but not other whitespace on the left-hand side of
category links should preserve the valuable features of T2087 et al
while still ensuring that the following all render equivalently:

  ABC [[Category:Foo]]DEF
  ABC[[Category:Foo]] DEF
  ABC [[Category:Foo]] DEF

Added parser test to document the new behavior; it's worth noting
that although there were plenty of tests documenting the expected
interaction of category links and newlines, there were previously
no tests covering the interaction of non-newline whitespace and
category links; the one test which needed to be altered added
non-semantic whitespace (ie, extra whitespace to the test output
which did not affect the way the HTML would display).

This patch brings the legacy parser into parity which Parsoid parsing
of category links.

Bug: T359886
Change-Id: I5e87b33a956e296cdaf671fa99c9555944b73479
2024-03-29 22:30:59 +00:00
C. Scott Ananian
c2df535b9c Substitute category default sort key when filling links table, not at parse time
This ensures uniform treatment of all places that call `addCategory`
without duplicating the `defaultsort` code; it also ensures that the
effect of the {{DEFAULTSORT}} parser function is independent of page
position.

Bug: T40435
Bug: T353530
Change-Id: I4480a6d59e766fa4eddc9ec9117c58b66771bb47
2024-03-29 18:30:02 -04:00
James D. Forrester
8e940c4f21 Standardise all our class alias deprecation comments for ease of grepping
Change-Id: I7f85d931d3b79da23e87b4e5692b2e14be8fcaa0
2024-03-19 20:11:29 +00:00
jenkins-bot
58e97df366 Merge "Drop comments in cleanUpTocLine" 2024-02-24 02:55:48 +00:00
jenkins-bot
80ac1a7ea2 Merge "Remove empty spans while traversing in cleanUpTocLine" 2024-02-24 01:30:27 +00:00
jenkins-bot
ccfefdf6bf Merge "Walk the dom instead of using a queryselector in cleanUpTocLine" 2024-02-24 01:27:01 +00:00
jenkins-bot
a3fa07e4d4 Merge "Move section heading formatting to post-cache transform (take 2)" 2024-02-23 05:15:21 +00:00
Arlo Breault
5ed94aba15 Drop comments in cleanUpTocLine
Needed-By: Ie6760dd25f937d4f6acbab1c0e1475b54878d4ed
Change-Id: I10f96435f892b188cffe64b92cdf2701a3e2058b
2024-02-22 19:06:15 -05:00
jenkins-bot
a62f5c7911 Merge "[ParserOutput] Rename $mText to $mRawText and ::setText() to ::setRawText()" 2024-02-21 17:11:00 +00:00
Arlo Breault
909043c539 Remove empty spans while traversing in cleanUpTocLine
Change-Id: I2d75bc6aa03c112c6e1dccd9a3b4f608cafde6cb
2024-02-20 19:09:00 -05:00
Arlo Breault
b05e4b98ce Walk the dom instead of using a queryselector in cleanUpTocLine
Change-Id: Ic59a4883f5b830c0c513e1836ad0de7c29a4b96d
2024-02-20 18:54:40 -05:00
Arlo Breault
89ddae6805 Remove metadata content while traversing all nodes in cleanUpTocLine
Change-Id: I900cff697b1d644140d0a8755ba601d8f94abb3e
2024-02-20 18:52:28 -05:00
C. Scott Ananian
72c4945a72 [ParserOutput] Rename $mText to $mRawText and ::setText() to ::setRawText()
ParserOutput::getText() is not a simple getter, but does
transformations on the "text" of the ParserOutput; the simple getter
is named ::getRawText().

To maintain consistency, rename ParserOutput::setText() to
::setRawText() and the property name ParserOutput::$mText to
::$mRawText so future readers are not confused.

The JSON property name as it appears in the serialized ParserCache
is left as 'Text' so that we don't have any forward- or backward-
rollback issues.

Change-Id: I3ef34814ab9473cc70d0a6806e8c5a4a02b73491
2024-02-20 17:13:28 +00:00
Bartosz Dziewoński
834ff25dc1 Move section heading formatting to post-cache transform (take 2)
[Previously attempted in de0646843a,
reverted in e72e1cd16368346b66853f68e2d13f9b416d5a11.]

Previously, Parser.php used Linker::makeHeadline() in order to
generate the `<h2><span class="mw-headline" id="...">...</span></h2>`
markup for section headings, and this was saved in the parser cache.
Now it generates heading tags with placeholder attributes like
`<h2 data-mw-...="..." ...>...</h2>`, and they are replaced in a
post-cache transform to generate the final heading markup, similarly
to how section edit links already worked.

The purpose of these changes is to allow changing the final markup
depending on skin options without splitting the parser cache (T13555).

Deployment and undeployment safety:
* The new post-cache transform has been already added in commit
  Ibce512b3c4a52f74b2d2124f0159e306f2689ea5 for forward-compatibility
  (so that if this patch is reverted, new parser cache entries
  will still be shown correctly).

Implementation notes:
* There are many ways to keep the temporary information other than
  `data-mw-...` attributes, but this way is the easiest to handle
  in a post-cache transform (everything is on the DOM node we want
  to modify), is compatible with other heading-enhancing code in
  DiscussionTools and MobileFrontend, and remains human-readable
  if the post-cache transform doesn't run.
* Sadly this code can't be reused to add section heading markup and
  section edit links to Parsoid (T269630), because it lacks some of
  the necessary metadata, and exposes the rest in ways that are
  trickier to handle in a post-cache transform (on other DOM nodes
  or outside the document).

Depends-On: If85f89c40834618f23dc0ace2e599efb3b6d5ed4
Bug: T13555
Change-Id: If04d72f427ec3c3730e757cbb3ade8840c09f7d3
2024-02-16 20:28:56 +00:00