aboutsummaryrefslogtreecommitdiffstats
path: root/includes/content
Commit message (Collapse)AuthorAgeFilesLines
...
* Merge "parser: Move lang/dir and mw-content-ltr to ParserOutput::getText"jenkins-bot2023-11-061-2/+1
|\
| * parser: Move lang/dir and mw-content-ltr to ParserOutput::getTextTimo Tijhof2023-11-031-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | == Skin::wrapHTML == Skin::wrapHTML no longer has to perform any guessing of the ParserOutput language. Nor does it have to special wiki pages vs special pages in this regard. Yay, code removal. == ImagePage == On URLs like /wiki/File:Example.jpg, the main output handler is ImagePage::view. This calls the parent Article::view to handle most of its output. Article::view obtains the ParserOptions, and then fetches ParserOutput, and then adds `<div class=mw-parser-output>` and its metadata to OutputPage. Before this change, ImagePage::view was creating a wrapper based on "predicting" what language the ParserOutput will contain. It couldn't call the new OutputPage::getContentLanguage or some equivalent as Article::view wouldn't have populated that yet. This leaky abstraction is fixed by this change as now the `<div>` from ParserOutput no longer comes with a "please wrap it properly" contract that Article subclasses couldn't possibly implement correctly (it coudln't wrap it after the fact because Article::view writes to OutputPage directly). RECENT (T310445): A special case was recently added for file pages about translated SVGs. For those, we decide which language to use for the "fullMedia" thumb atop the page. This was recently changed as part of T310445 from a hardcoded $wgLanguageCode (site content lang) to new problematic Title::getPageViewLanguage, which tries to guestimate the page language of the rendered ParserOutput and then gets the preferred variant for the current user. The motivation for this was to support language variants but used Title::getPageViewLanguage as a kitchen sink to achieve that minor side-effect. The only part of this now-deprecated method that we actually need is LanguageConverter::getPreferredVariant(). Test plan: Covered by ImagePageTest. == Skin mainpage-title == RECENT (T331095, T298715): A special case was added to Skin::getTemplateData that powers the mainpage-title interface message feature. This is empty by default, but when created via MediaWiki:mainpage-title allows interface admins to replace the H1 with a custom and localised page heading. A few months ago, in Ifc9f0a7174, Title::getPageViewLanguage was applied here to support language variants. Replace with the same fix as for ImagePage. Revert back to Message::inContentLanguage() but refactor to inLanguage() via MediaWikiServices::getContentLanguage so that LanguageConverter::getPreferredVariant can be applied. == EditPage == This was doing similar "predicting" of the ParserOutput language to create an empty preview placeholder for use by preview.js. Now that ApiParse (via ParserOutput::getText) returns a usable element without any secret "you magically know the right class, lang, and dir" contract, this placeholder is no longer needed. Test Plan: * EditPage: Default preview 1. index.php?title=Main_Page&action=edit 2. Show preview 3. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr> * EditPage: JS preview 1. Preferences > Editing > Show preview without reload 2. index.php?title=Main_Page&action=edit 3. Show preview 4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr> 5. Type something and 'Show preview' again 6. Assert old element gone, new text is shown, and new element attributes are the same as the above. == McrUndoAction == Same as EditPage basically, but without the JS preview use case. == DifferenceEngine == Test: 1. Open /w/index.php?title=Main_Page&diff=0 (this shows the latest diff, can do manually by viewing /wiki/Main_Page, click "View history", click "Compare selected revisions") 2. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr> 3. Open /w/index.php?title=Main_Page&diff=0&action=render 4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr> == Special:ExpandTemplates == Test: 1. /wiki/Special:ExpandTemplates 2. Write "Hello". 3. "OK" 4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr> Bug: T341244 Depends-On: Icd9c079f5896ee83d86b9c2699636dc81d25a14c Depends-On: I4e7484b3b94f1cb6062e7cef9f20626b650bb4b1 Depends-On: I90b88f3b3a3bbeba4f48d118f92f54864997e105 Change-Id: Ib130a055e46764544af0f1a46d2bc2b3a7ee85b7
* | Use a reference when registering a ParserOptions watcherC. Scott Ananian2023-11-062-2/+2
| | | | | | | | | | | | | | | | This ensures that the watcher follows the ParserOutput even if it gets replaced when it is passed by reference to Content::fillParserOutput() and/or ContentHandler::fillParserOutput(). Change-Id: I69102f841437e30d93ca1da0b71bc08c3f18cb96
* | content: Stop encoding `&` in JavaScript redirect contentKunal Mehta2023-11-012-3/+14
|/ | | | | | | | | | | | | | | | There is no security benefit from encoding &, it's perfectly safe in JavaScript (it likely dates from XML/XHTML requirements). Newly created redirects will use a literal & in these URLs, while continuing to support use of \u0026 for existing pages. Note that this is about use of & for query parameter seperators, the & in a page title will continue to be encoded as %26 in the 'title' value and is unaffected by this change. Bug: T107289 Co-Authored-By: Ammar Abdulhamid <ammarpad@yahoo.com> Change-Id: I1db4483db6bc52a96487fefd2c3693b4825ccbb2
* Pass full content to Parsoid for redirect pagesSubramanya Sastry2023-10-171-1/+9
| | | | | | | | | | | * See inline comment in WikitextContentHandler that explains what is happening here. * Added a new WikitextContentHandlerIntegration test to verify this expectation (which fails without the change in this patch). Bug: T349087 Change-Id: I072ddf89562fe79bad47d741feb5788430e05bb6
* Drop AbstractContent::getRedirectChain and ::getUltimateRedirectTarget, ↵James D. Forrester2023-10-051-39/+0
| | | | | | deprecated in 1.38 Change-Id: I6564ff72c89ec47a680381edc298f0ffbf9bae60
* doc: Fix variable name in ContentHandlerForModelIDHookUmherirrender2023-09-301-2/+2
| | | | Change-Id: I62075b95d8b6108f1ad6cea26794ac39ac213c9a
* Move getRedirectTargetAndText out of WikitextContentdaniel2023-09-222-62/+64
| | | | | | | | WikitextContent should be a value object that does not need access to services. For this reason, getRedirectTargetAndText has to be moved to WikitextContentHandler. Change-Id: Ia6595caf7e913ef580709a4d076aa2cc9dbaacef
* Unit test for LinkRenderer::makeRedirectHeader() used by WikitextContentHandlerC. Scott Ananian2023-09-222-7/+30
| | | | Change-Id: I3577633670d0c2a771c690e3d6601300e1867222
* Move Article::getRedirectHeaderHtml() to LinkRenderer::makeRedirectHeader()C. Scott Ananian2023-09-221-1/+11
| | | | | | | | | | | The use of Article::getRedirectHeaderHtml() has been discouraged for a while, since WikitextContentHandler can (should) be used to insert the redirect header. Further, since I20db09619999919bfeda997d79561d21e3bf8718 the header should be added as an extension data property instead of directly concatenated to the HTML. Regardless, this functionality logically should live in LinkRenderer. Change-Id: I4d0de0e72473ae039dca420a2733bc746d8c2951
* Namespace Sanitizer under \MediaWiki\ParserJames D. Forrester2023-09-211-0/+1
| | | | | Bug: T166010 Change-Id: Id13dcbf7a0372017495958dbc4f601f40c122508
* Namespace User under \MediaWiki\UserJames D. Forrester2023-09-192-0/+2
| | | | | Bug: T166010 Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
* WikitextContentHandler/ParserOutput: move redirect header to post processingC. Scott Ananian2023-09-151-3/+2
| | | | | | | | | Insert the redirect handler as part of the post-processing done in ParserOutput::getText(). This ensures that it does not corrupt edit-mode Parsoid output. Depends-On: Ia6e390d849830993a6b97004f099773cfd4fa54b Change-Id: I20db09619999919bfeda997d79561d21e3bf8718
* actions: Let getActionOverrides() return ObjectFactory specsLucas Werkmeister2023-09-141-2/+3
| | | | | | | | | | | | | | | | | This matches how many of the core actions are defined nowadays, and lets ContentHandler subclasses in extensions define actions in the same way without Phan complaining. getActionOverrides() is consumed by ActionFactory::getAction, which already supports these as-is. We suport ObjectFactory in core and extensions through ActionFactory::CORE_ACTIONS and $wgActions (via ActionFactory::getActionSpec, which also includes `array`; it also ends with `null`, which I don’t think should be added to getActionOverrides() because I doubt `null` is meaningful there.) Bug: T253078 Change-Id: Ib1a6a6f6d92eaead61b4341aa6c9d3cf389c7304 Follows-Up: I4e38d80baf34d6ecdb9877bc6c8f6c4fa00cedb6
* Remove redundant empty() constructsDaimona Eaytoy2023-09-081-1/+1
| | | | | | | | | | | | | empty() only makes sense when the expression it checks is possibly undefined, otherwise it's equivalent to a truthiness check with the additional downside of suppressing errors when it's not wanted. Replace it with simple truthiness checks, using strict comparison when that seems to help with polymorphic variables. These were caught by a bespoke phan plugin. Change-Id: I52999e5286a0d9ad70b0da40b41b9f998ecb990e
* Introduce RevisionSelectQueryBuilderAmir Sarabadani2023-09-061-10/+5
| | | | | | | | | Deprecating RevisionStore::getQueryInfo() and cleaning up a lot of code Also removing a brittle test that wasn't really testing anything. Bug: T344971 Change-Id: Ifd690dc8f030f86e3567a717eaeb830cb6dc703b
* Merge "ContentHandler: Hard-deprecate getSlotDiffRendererInternal"jenkins-bot2023-08-311-1/+3
|\
| * ContentHandler: Hard-deprecate getSlotDiffRendererInternalJames D. Forrester2023-08-251-1/+3
| | | | | | | | | | | | | | | | Deprecated since 1.35, but still used by ProofreadPage until the listed dependency is merged. Depends-On: I1c180521b831d8e6896679c8bfed6cb64260d40d Change-Id: I39a1bf5b6e5d14b07be84a0a139a1abb5b289368
* | Reorg: Move Status to MediaWiki\Status\Amir Sarabadani2023-08-254-0/+4
|/ | | | | | | | | | This class is used heavily basically everywhere, moving it to Utils wouldn't make much sense. Also with this change, we can move StatusValue to MediaWiki\Status as well. Bug: T321882 Depends-On: I5f89ecf27ce1471a74f31c6018806461781213c3 Change-Id: I04c1dcf5129df437589149f0f3e284974d7c98fa
* Title::getContentModel: Stop using ContentHandler::getDefaultModelFor()James D. Forrester2023-08-241-2/+0
| | | | | | It's deprecated; use the SlotRoleHandler directly. Change-Id: I21ee9d220c349695a0351fd7f3f92393c7036dd1
* WikiTextStructure: Rename extractHeadingBeforeFirstHeading() to ↵Reedy2023-08-231-2/+2
| | | | | | | | extractTextBeforeFirstHeading() Reflects what the function is actually trying to do... Change-Id: Ic28a3121326be210ceb97af1d3e0287dbcc7e4cf
* AbstractContent: Hard-deprecate getNativeData(), deprecated since 1.33James D. Forrester2023-08-191-1/+3
| | | | Change-Id: Ia30eca0dad454843db351f32859201bcd2710b9a
* Drop ContentHandler::getForTitle(), deprecated since 1.35James D. Forrester2023-08-161-21/+0
| | | | Change-Id: Ica756616439a014aa85b43093aeb51ebc30f4f61
* content: Rename $output in ContentGetParserOutputHookUmherirrender2023-08-141-2/+2
| | | | | | This is a ParserOutput, $output is often used for OutputPage Change-Id: I98c62140db863243e0342b9747032dc425fccc83
* Merge "content,maintenance: Use class-string<ClassName> in doc blocks"jenkins-bot2023-07-317-9/+11
|\
| * content,maintenance: Use class-string<ClassName> in doc blocksthiemowmde2023-07-317-9/+11
| | | | | | | | | | | | | | | | Start using `class-string<ClassName>` as a type hint in a few places where the information is really helpful. A lot of tools are able to understand this already. Change-Id: Ide45cae8c7875e664fab1155c6c720e515d8d811
* | Merge "Add support for wikidiff2_multi_format_diff()"jenkins-bot2023-07-311-1/+2
|\ \
| * | Add support for wikidiff2_multi_format_diff()Tim Starling2023-07-191-1/+2
| |/ | | | | | | | | Bug: T341754 Change-Id: I17396985d0b26516a06df17e9bd1343054521e01
* | Don't show the inline toggle selector on Special:MobileDiffTim Starling2023-07-261-0/+3
| | | | | | | | | | | | | | | | | | Have Article opt in to inline toggle switch display, so that random callers of DifferenceEngine::showDiffPage() do not receive a non-functional format selector. Bug: T342158 Change-Id: Id4e38c2a20b5381e5f70b1244304da2895eaf8e7
* | Implement rate limiting in Authority.daniel2023-07-231-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rate limits will automatically be checked by definitelyCan(), authorizeRead() and authorizeWrite(). The authorize methods also increment the counter. UserAuthority tracks which limits have already been incremented during the current request, to avoid duplicate increments caused by code that still calls pingLimiter directly. DEPLOY: Risky! We SHOULD not hit rate limits more often, but we might. Rate limit metrics should be monitored closely, see <https://grafana.wikimedia.org/d/8oA6CWr4z/mw-rate-limiting-overview>. Bug: T310476 Depends-On: Iebd62b0487af9172edaeae41c9b31aaf2f20fd06 Change-Id: Ic349f03b7040343815b60b0a2c84a5780326c797
* | Use Html::encodeJsVar() and Html::encodeJsCall()Lucas Werkmeister2023-07-201-1/+1
|/ | | | | | | | The only remaining references to the Xml:: versions of those methods are in doc comments and in HISTORY. Bug: T341779 Change-Id: I004a925f80ae23eff2c078c95b8caa8ccf64ffd2
* Factor out TextDiffer hierarchy from TextSlotDiffRendererTim Starling2023-07-191-20/+32
| | | | | | | | | | | | | | | | | | | | | | | | | * Follow the TODO comment in TextSlotDiffRenderer ::getTextDiffInternal() by moving the code out to three parallel implementations, namely ExternalTextDiffer, PhpTextDiffer and Wikidiff2TextDiffer. * Add a container/factory class ManifoldTextDiffer to glue them together and collate available formats. * Move the inline legend to Wikidiff2TextDiffer. Not the toggle since the ability to toggle depends on the available format, not the current format. * Update the diff cache keys so that ManifoldTextDiffer can store the engine=>format map it used to generate the diff. * Drop support for the second parameter to TextSlotDiffRenderer ::setEngine(), since nothing used it anymore. * Provide a format batch API, since some engines are able to efficiently generate multiple formats. This might be used by DifferenceEngine in future. Needs risky change notification for the cache key change. Bug: T339184 Depends-On: I8a35b9b8ec1622c9a36d2496bdd24f51bc52c85f Change-Id: I5c506e39162855aff53dd420dd8145156739059c
* Inject page language into TextSlotDiffRendererTim Starling2023-07-061-5/+10
| | | | | | | | | Fix fixme by sending the language code to SlotDiffRenderer as an option. Note that this is the language used for word segmentation of the content, not the UI language. Change-Id: I2d0a6996b02d37a3f2d8fefa851244803025bb6c
* Move DiffEngine and helpers to includes/libs/Diff and put them in a namespaceTim Starling2023-06-201-0/+1
| | | | | | | I will address the dependencies on MW core in a followup. Bug: T339184 Change-Id: I892364b0c9f15c9de4cfc29c683670c172d71764
* Split createTextSlotDiffRenderer() out of getSlotDiffRendererWithOptionsTim Starling2023-06-191-0/+11
| | | | | | | | The idea is to make it easier for ContentHandler subclasses to reuse TextSlotDiffRenderer by composition. Bug: T339184 Change-Id: I963eb6500fe8b5ba92214d4744eb0aee74fc9331
* Replace deprecated MWExceptionDaimona Eaytoy2023-06-121-2/+1
| | | | | Bug: T328220 Change-Id: I0408575ee71e58d1c9e9ebedabab35bd3813f515
* Replace deprecated MWExceptionDaimona Eaytoy2023-06-091-4/+0
| | | | | Bug: T328220 Change-Id: I66be7a6dd752d6b9c254beb65f4eb5ace3c89776
* Replace some more usages of deprecated MWExceptionDaimona Eaytoy2023-06-092-45/+18
| | | | | Bug: T328220 Change-Id: I3c36835fbd90acc301731e2b33ae4815cd4b0cc5
* Replace more usages of deprecated MWExceptionDaimona Eaytoy2023-06-081-2/+1
| | | | | Bug: T328220 Change-Id: Ib619ead0f397188d828e6e5dfc80ed1fa7175c7d
* diff: Add legend and tooltips to inline diff displaySam Wilson2023-05-311-0/+2
| | | | | | | | | | | | | | | | | | | | Add a legend at the top of the inline diff display, showing the meanings of the colours of the inserted and deleted highlighting. Also add the same text as tooltips on the highlighted elements. The legend is added as part of a new area above the diff table that can be modified via a new TextSlotDiffRendererTablePrefix hook, so that extensions can add other buttons etc. there as required. This is a follow-up to the previous attempt, which added the legend in DifferenceEngine::showDiff() and was called from too many places. This patch moves it to be called in DifferenceEngine::showDiffPage(). Bug: T324759 Change-Id: I2a3c67bcfa47313dee597e602a62073e4e298cd2 Follow-up: I6de30bf79eb5ac262285951792782b870d075e00
* Replace internal Hooks::runnerUmherirrender2023-05-113-6/+13
| | | | | | | | | 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
* Fix documentation on FallbackContent[Handler]. New in 1.36 not 1.34Brian Wolff2023-05-092-2/+2
| | | | | | Follow-up to a67cad6d0fc5b6a Change-Id: I26da1bb17f1a1855080c24a60af9c0f1ccf36d10
* Merge "actions: Update outdated/incomplete ActionFactory::getActionSpec docs"jenkins-bot2023-04-261-4/+6
|\
| * actions: Update outdated/incomplete ActionFactory::getActionSpec docsthiemowmde2023-04-261-4/+6
| | | | | | | | | | | | To the best of my knowledge. Change-Id: I4e38d80baf34d6ecdb9877bc6c8f6c4fa00cedb6
* | Fix Phan suppressions related to Title::castFrom*() and friendsBartosz Dziewoński2023-04-222-12/+7
|/ | | | | | | | | | | | | | | | | | | | | There is no way to express that Title::castFromPageIdentity(), Title::castFromPageReference() and Title::castFromLinkTarget() can only return null when the parameter is null. We need to add Phan suppressions or explicit types almost everywhere that these methods are used with parameters that are known to not be null. Instead, introduce new methods Title::newFromPageIdentity() and Title::newFromPageReference() (Title::newFromLinkTarget() already exists), without the null-coalescing behavior, and use them when the parameter is not null. This lets static analysis tools, and humans, easily understand where nulls can't appear. Do the same with the corresponding TitleFactory methods. Change the obvious uses of castFrom*() to newFrom*() (if there is a Phan suppression, a type check, or a method call on the result). Change-Id: Ida4da75953cf3bca372a40dc88022443109ca0cb
* Merge "Allow setting a ParserOption to generate Parsoid HTML"jenkins-bot2023-03-271-6/+25
|\
| * Allow setting a ParserOption to generate Parsoid HTMLC. Scott Ananian2023-03-261-6/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | Just another 80 or so PHPStorm inspection fixes (#4)Tim Starling2023-03-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | * Unnecessary regex modifier. I agree with this inspection which flags /s modifiers on regexes that don't use a dot. * Property declared dynamically. * Unused local variable. But it's acceptable for an unused local variable to take the return value of a method under test, when it is being tested for its side-effects. And it's acceptable for an unused local variable to document unused list expansion elements, or the nature of array keys in a foreach. Change-Id: I067b5b45dd1138c00e7269b66d3d1385f202fe7f
* | Fix some PHPStorm inspections (#1)Tim Starling2023-03-251-1/+1
|/ | | | | | | | | | | | * Triple backslash in regex should really be quadruple backslash * Using the returned value of a void method * Immediately overwritten array keys * Duplicate array keys * Foreach variable reuse * sprintf() with too many params * Incorrect reference usage Change-Id: I3c649b543c9561a1614058c50f3847f663ff04df
* WikiTextStructure: Also extract figcaption elements as captionsErik Bernhardson2023-03-231-0/+1
| | | | | | | | | | | | | | The figcaption element looks to be many years old, but was not previously considered a caption by the search engine. Some integration tests have recently started failing as an element that previously contained the thumbcaption css element is now inside a figcaption class. Update the code that extracts captions from the text into a separate field to also extract the figcaption, as it has the same purpose as thumbcaption. Change-Id: I2a4a309e58602281d6cca65744036efb4a5ce5b5