Commit graph

1506 commits

Author SHA1 Message Date
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
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
C. Scott Ananian
f7ba84855a Parser::getExternalLinkAttribs: Don't set rel attribute to null
Paser::getExternalLinkRel() is defined to return `null` if there's
no attribute to add, but then ParserOptions::getExternalLinkTarget()
may try to append to it and external users might try to actually pass
the $attribs to (eg) Xml::element() and become unhappy if the value
is `null`.

Bug: T357668
Followup-To: Ifec733a923f193b72eaba9a1e604ad4e56c0aef2
Change-Id: I907c22ef070616d81b9a50b0e807a7b8f78b59b5
2024-02-15 17:32:28 -05:00
C. Scott Ananian
e72e1cd163 Revert "Move section heading formatting to post-cache transform"
This reverts commit de0646843a.

Reason for revert: caused T357723.

Change-Id: I4690c03a34e8796090563e19a214d8ede63fe5d1
2024-02-15 20:58:32 +00:00
Bartosz Dziewoński
de0646843a Move section heading formatting to post-cache transform
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).

Bug: T13555
Change-Id: I4eae18d9d16f54391daba0de82ad05e50f07f9eb
2024-02-15 13:09:08 -05:00
jenkins-bot
cb6d6e8bae Merge "Parser: Convert wikitext entities to HTML entities in TOC" 2024-02-12 19:52:55 +00:00
James D. Forrester
102a4f8a35 build: Upgrade mediawiki/mediawiki-phan-config from 0.13.0 to 0.14.0 manually
* Switch out raw Exceptions, mostly for InvalidArgumentExceptions.
  * Fake exceptions triggered to give Monolog a backtrace are for
    some reason "traditionally" RuntimeExceptions, instead, so we
    continue to use that pattern in remaining locations.
* Just entirely give up on PostgresResultWrapper's resource vs. object mess.
* Drop now-unneeded false positive hits.

Change-Id: Id183ab60994cd9c6dc80401d4ce4de0ddf2b3da0
2024-02-10 02:22:41 +00:00
Bartosz Dziewoński
fb1be73a07 Parser: Convert wikitext entities to HTML entities in TOC
Bug: T355386
Bug: T324763
Change-Id: Ic0a805f29c928d0c2edf266ea045b0d29bb45a28
2024-02-09 02:00:38 +00:00
jenkins-bot
e831aa9c8b Merge "Namespace includes/context" 2024-02-08 18:04:34 +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
242c6d2cf9 Introduce ParserOutput:setFromParserOptions() and use for preview flag
Bug: T341010
Co-Authored-by: cananian <cananian@wikimedia.org>
Co-Authored-by: ihurbain <ihurbainpalatin@wikimedia.org>
Change-Id: I03125fdaa7dd71ba57d593e85ecb98be6806f3f6
2024-02-07 21:22:06 -05:00
Daimona Eaytoy
7acfa6a0a5 Replace more instances of unchecked MWException
Most (all?) of the remaining usages are caught somewhere and will be
migrated later.

Bug: T328220
Change-Id: I5c36693a5361dd75b4f1e7a0bab5ad48626ed75c
2024-01-23 16:20:53 +00:00
Arlo Breault
4318039a23 Remove redundant internal tag
Change-Id: I09b282324ae8d6307ae963bede4848dbdfb2a150
2024-01-17 17:55:52 -05:00
Arlo Breault
4b987168d0 Remove unnecessary null check from Parser::braceSubstitution
Parser::braceSubstitution is only called from PPFrame_Hash::expand with
the result of PPNode_Hash_Tree::splitRawTemplate which always sets
'parts' to a PPNode_Hash_Array

Parser::argSubstitution is similarly called without the unnecessary null
check..

The comment was introduced in e002df9 and, although true, even then
the ternary may have been made redundant by a previous refactor.

Change-Id: Ia1c5b8570c65c8e174c723dbd292e11c3a72f54d
2024-01-17 17:42:10 -05:00
Bartosz Dziewoński
c2c4645fa2 Parser: Normalize dot segments in URL paths
Bug: T352827
Change-Id: Id90a26b656067481039fa77080417f34347f9c22
2024-01-04 01:46:33 +01:00
Fomafix
45c450aacb Parser: Remove hard-deprecated getCustomDefaultSort and setDefaultSort
getCustomDefaultSort and setDefaultSort are unused:
* https://codesearch.wmcloud.org/search/?q=getCustomDefaultSort
* https://codesearch.wmcloud.org/search/?q=setDefaultSort
and are hard-deprecated since dc3d489156 included in MediaWiki 1.38.

Change-Id: Ib9a9622d50a5807f55be91885e473b90f98c2cb9
2023-12-29 11:19:28 +00:00
James D. Forrester
9bfb75ff90 Namespace ParserOutput
Most used non-namespaced class!

Bug: T353458
Change-Id: I4c2cbb0a808b3881a4d6ca489eee5d8c8ebf26cf
2023-12-14 14:57:34 -05:00
jenkins-bot
c57120300a Merge "ParserOutput: Allow passing LinkTarget to title-related methods" 2023-12-11 18:02:25 +00:00
Isabelle Hurbain-Palatin
a3f51c732d Refactor DefaultOutputTransform into a pipeline of transforms
Bug: T348253
Change-Id: I53551ec6d6471569709c71c1155729e550f64de8
2023-12-08 18:06:19 -05:00
C. Scott Ananian
4b83285954 ParserOutput: Allow passing LinkTarget to title-related methods
Broadened the argument type to allow passing LinkTarget to:
* ParserOutput::addCategory()
* ParserOutput::addLanguageLink()
* ParserOutput::addLink()
* ParserOutput::addImage()
* ParserOutput::addTemplate()

This allows for a tighter interface with Parsoid's
ContentMetadataCollector class and avoids errors caused by passing the
wrong form of string title ("text" with spaces versus "dbkey" with
underscores).

There are a few performance problems remaining after this patch, which
only apply to use by Parsoid (not the legacy parser):

1. ::addLink() does inefficient db requests to fetch the page id for
each link if the optional $id parameter is not passed.  These lookups
should be deferred and a LinkBatch used.  (The legacy parser always
passes $id.)

2. ::addTemplate() similarly requires $page_id (and $rev_id) to be
passed, so is not currently usable by Parsoid.

3. ::addLanguageLink() uses Title::getFullText() which is not present
in LinkTarget and is currently implemented as a full Title lookup.
This is not an issue for the legacy parser, because it already has a
Title object so the lookup is a no-op, but could be improved for
Parsoid's use.

Bug: T296023
Change-Id: If21ec8563c8a619bdde7c0cb6534bb9009480a21
2023-12-08 17:50:29 -05:00
jenkins-bot
b7fc1b2f43 Merge "Only cache expensive renderings" 2023-11-30 21:24:34 +00:00