Commit graph

279 commits

Author SHA1 Message Date
Cole White
89a10817dc diff: migrate TextSlotDiffRenderer to use StatsFactory
Bug: T359241
Change-Id: I4f443b004b9ed77b9e6b8b1144d0cc2847a55d16
2024-06-28 19:29:31 +00:00
Timo Tijhof
b170672dc7 diff: Mark TextSlotDiffRenderer DI setters as @internal
For use by I4f443b004b9ed7 (T359241).

Change-Id: If6acfb4fbb041dc13c7b4ccfaae4abd6f5b9b550
2024-06-15 00:01:38 +01: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
James D. Forrester
a5a10aff9b ContentHandler: Hard-deprecate deprecated methods
Depends-On: If0049aabff2dedfcecf739dbbcf688d16d9cc864
Depends-On: I7f82748be5a7c16525bc57e33ebeb0bb974267b9
Change-Id: Ife87b189e73883cfc8a4ef115d431ec8ad37dea7
2024-05-01 07:41:18 +01:00
Tim Starling
917f0a5996 Replace all instances of "per default" with "by default"
According to the dictionary, "per" (or more conventionally "as per")
means "according to". Refer OED "per" sense II.3.a. For example:

"No value was passed, so return null, as per default".

In this sentence, we are not specifying the default, we are referring
to the default. This correct usage of "per default" was used nowhere
in MediaWiki core as far as I can see.

Instead we have "per default" being used to mean "by default", that is,
giving the value to use when no explicit value was specified.

In OED, the phrase "by default" is blessed with its own section just
for computing usage:

"P.1.e. Computing. As an option or setting adopted automatically by a
computer program whenever an alternative is not specified by the user
or programmer. Cf. sense I.7a."

There are highly similar pre-computing usages of the same phrase,
whereas the phrase "per default" is not mentioned.

As a matter of style, I think "per default" should not be used even
when it is strictly correct, since the common incorrect usage makes it
ambiguous and misleading.

Change-Id: Ibcccc65ead864d082677b472b34ff32ff41c60ae
2024-04-29 10:47:54 +10:00
Taavi Väänänen
f28348d9c0
Hard-deprecate ContentHandler::getContentText()
No remaining uses in WMF-deployed extensions. (Although there is a
similarly named but separate function in CiteThisPage.)

Bug: T268041
Change-Id: Iec68845c631758fe85d32a939b28b6d8b1243858
2024-04-21 22:15:09 +03:00
Umherirrender
e10441e555 IReadableDatabase::select cannot return false
Remove check for false from IDatabase::select as this is not possible
A DBQueryError is thrown (documented since efda8cd3 / I056b7148)

Use IResultWrapper::numRows to check for empty IResultWrapper

This ignores includes\libs\rdbms as QUERY_SILENCE_ERRORS is an internal
option to get false from this function

Change-Id: I4b2fc26ca0e68612f6beadc01e68097a74962c84
2024-04-18 22:48:25 +02:00
daniel
e7f21f6e64 HtmlOutputRendererHelper: fall back to page language
HtmlOutputRendererHelper should not crash hard if the ParserOutput has
no language set. ParserOutput may come from a variety of places, we
should be lenient about it not having a language.

However, we should try harder to actually set a language on ParserOutput
if we have one available. So this also updates
PageBundleParserOutputConverter to keep the ParserOutput's language in
sync wit the language header in the PageBundle.

Bug: T349868
Bug: T353689
Bug: T359426
Change-Id: I2edf20dc3b199e22cda2f32bc858c21ca7d8f4bd
2024-03-06 17:18:16 +00:00
jenkins-bot
5c87a85f23 Merge "content: lowercase model name before looking up message" 2024-03-01 09:44:49 +00:00
Siddharth VP
e038427fe0 content: lowercase model name before looking up message
In ContentHandler::getLocalizedName, lowercase the model name before
looking up the relevant i18n message. This change allows localisation of
names of content models which contain an uppercase character, which
isn't possible today as message keys with uppercase chars cause build to
fail.

Bug: T358341
Change-Id: I0f090f21ce2b0f6d92790ae9f2b755dabb2e7082
2024-02-23 22:55:18 +05:30
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Amir Sarabadani
ba1563a0ba Drop deprecated config ContentHandlerTextFallback
Soft-deprecated since 1.37 and hard-deprecated since at least
I9776d11d4e2d184 (1.39)

Not set in production.

Change-Id: I0b25e89d1652dfa697ab1176a1e2b6ca3163bdab
2024-01-26 12:45:18 +01:00
Amir Sarabadani
014bc61006 Remove more indirect calls to IDBAccessObject::READ_* constants
Found via (?<!IDBAccessObject)::READ_

We are planning to deprecate and remove implementing IDBAccessObject
interface just to use the constants.

Bug: T354194
Change-Id: I89d442fa493b8e5332ce118e5bf13f13b8dd3477
2024-01-23 15:42:38 +01:00
Bartosz Dziewoński
e4c7272976 Change uses of getDBLoadBalancerFactory() to getConnectionProvider()
Update cases where one of the IConnectionProvider methods is called
immediately.

This doesn't really change anything, but I hope it helps promote
getConnectionProvider() as the common way to do this.

Follow-up to 8604c384f6.

Change-Id: Id0e7d02bab0c570343c2b1f03c70b44ee39db112
2024-01-22 22:27:45 +01:00
jenkins-bot
25f83a9ce6 Merge "Replace unspecific exceptions with InvalidArgumentException" 2024-01-21 01:22:26 +00:00
thiemowmde
0ea7599e3e Replace unspecific exceptions with InvalidArgumentException
A LogicException is very generic and doesn't mean much. An
InvalidArgumentException is also a LogicException, but more
specific: A method was called (for whatever reason – bad code,
bad user input – we don't know) with an invalid, unsupported
argument. This is exactly what's going on in these cases.

BadMethodCallException does have a confusing name and is often
misused because of this. It's documented as "thrown if a callback
refers to an undefined method or if some arguments are missing".
That's something else and not what's going on in these cases.

Change-Id: Id446227f578ba701e22acd5e530ffb795e76c147
2024-01-20 21:10:12 +01:00
Daimona Eaytoy
1d6776fdbc Replace deprecated MWException
Also remove some unchecked exception from doc comments.

Bug: T328220
Bug: T240672
Change-Id: I88b1e948ce5da77d9c4862a2b98793d6ba00cf8b
2024-01-19 21:58:42 +00:00
jenkins-bot
e8fe9b6a66 Merge "Replace deprecated MWException" 2024-01-16 20:33:13 +00:00
Daimona Eaytoy
caef81d37a Replace deprecated MWException
Bug: T328220
Change-Id: Ic45438d9e6bbf127f1415add81ab902044765840
2024-01-16 21:04:33 +01:00
Aaron Schulz
b509d76329 Stop unstubbing and passing $wgLang to onPageContentLanguage hook handlers
All handlers in WMF-hosted repos no longer make use of nor type-hint against
this field. For compatibility with such handlers, pass null and document the
value as being deprecated and of type mixed.

Bug: T299369
Change-Id: Ie192beb6018ed40e2bc1920b23802ea62d1b105c
2024-01-15 17:58:55 +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
b7fc1b2f43 Merge "Only cache expensive renderings" 2023-11-30 21:24:34 +00:00
daniel
e3fb964439 Only cache expensive renderings
Pages that are fast to render can be omitted from the parser cache
to preserve disk space and cache write operations.

The threshold is configurable per namespace, so the tradeoff can
be evaluated based on different access patterns. For example, pages
that are accessed rarely, like file description pages on commons,
may have a high threshold configured, while pages that are read
frequently, like wikipedia articles, may be configured to be always
cached, using a 0 threshold.

Filtering is based on a time profile recorded in the ParserOutput.
A generic mechanism for capturing the timing profile is implemented
in the ContentHandler base class. Subclasses may implement a more
rigorous capture mechanism.

Bug: T346765
Change-Id: I38a6f3ef064f98f3ad6a7c60856b0248a94fe9ac
2023-11-30 20:56:12 +00:00
jenkins-bot
800f1b19f4 Merge "Remove deprecated methods from Content interface" 2023-11-28 15:52:14 +00:00
James D. Forrester
67217d08df Namespace remaining files under includes/deferred
Bug: T166010
Change-Id: Ibd40734b96fd2900e3ce12239d09becfb4150059
2023-11-22 10:08:53 -05:00
daniel
eb881d9b59 Remove deprecated methods from Content interface
Several methods on the Content interface had been deprecated in 1.35 and
1.36 in favor of corresponding methods on the ContentHandler base class,
to allow implementations of these methods to use proper dependency
injection. This patch removes backwards compatibility support for
subclasses that were overriding these methods.

Change-Id: I8e474a1cc4dec760a7f6db25e4b313392f3723b1
2023-11-21 12:40:11 +01:00
Amir Sarabadani
2e1cd74ad2 Migrate off wfGetDB() in more places to ICP
This function is uber-deprecated, meaning even its replacement is
deprecated, We have already migrated in static functions and more.

In this batch, all calls have been migrated that there is already a call
to MediaWikiServices::getInstance() making the migration easier. Of
course in most cases, they should eventually turn into proper service
injection but this at least makes it clear what services should be
injected.

Also removing "category" group since we are removing all groups except a
handful from mw (see T263127 for more information).

Bug: T330641
Change-Id: I90cd35ee45a37eb6e6bf7a531cc8f75effbd0328
2023-11-20 14:40:28 +01:00
jenkins-bot
c53a75856d Merge "parser: Move lang/dir and mw-content-ltr to ParserOutput::getText" 2023-11-06 17:38:10 +00:00
C. Scott Ananian
5c9322ae06 Use a reference when registering a ParserOptions watcher
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
2023-11-06 14:44:25 +00:00
Timo Tijhof
d0a96db0f9 parser: Move lang/dir and mw-content-ltr to ParserOutput::getText
== 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
2023-11-03 19:24:47 -04:00
Lucas Werkmeister
53f8b8a459 actions: Let getActionOverrides() return ObjectFactory specs
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
2023-09-14 16:58:27 +00:00
Amir Sarabadani
049b34b41c Introduce RevisionSelectQueryBuilder
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
2023-09-06 12:30:38 +02:00
James D. Forrester
ea81292455 ContentHandler: Hard-deprecate getSlotDiffRendererInternal
Deprecated since 1.35, but still used by ProofreadPage until the
listed dependency is merged.

Depends-On: I1c180521b831d8e6896679c8bfed6cb64260d40d
Change-Id: I39a1bf5b6e5d14b07be84a0a139a1abb5b289368
2023-08-25 10:27:57 -04:00
James D. Forrester
2b48febed0 Title::getContentModel: Stop using ContentHandler::getDefaultModelFor()
It's deprecated; use the SlotRoleHandler directly.

Change-Id: I21ee9d220c349695a0351fd7f3f92393c7036dd1
2023-08-24 15:25:50 -04:00
James D. Forrester
ab59a8d1e3 Drop ContentHandler::getForTitle(), deprecated since 1.35
Change-Id: Ica756616439a014aa85b43093aeb51ebc30f4f61
2023-08-16 16:58:34 +08:00
jenkins-bot
eaf4a8f585 Merge "content,maintenance: Use class-string<ClassName> in doc blocks" 2023-07-31 22:40:35 +00:00
thiemowmde
f549005179 content,maintenance: Use class-string<ClassName> in doc blocks
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
2023-07-31 17:14:09 +00:00
jenkins-bot
1d5e4f3d0a Merge "Add support for wikidiff2_multi_format_diff()" 2023-07-31 11:54:12 +00:00
Tim Starling
8d69f99a1a Don't show the inline toggle selector on Special:MobileDiff
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
2023-07-26 05:16:55 +00:00
Tim Starling
2ed4e600b4 Add support for wikidiff2_multi_format_diff()
Bug: T341754
Change-Id: I17396985d0b26516a06df17e9bd1343054521e01
2023-07-19 12:38:18 +10:00
Tim Starling
2aa87cdf2c Factor out TextDiffer hierarchy from TextSlotDiffRenderer
* 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
2023-07-19 12:38:18 +10:00
Tim Starling
36b92d45db Inject page language into TextSlotDiffRenderer
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
2023-07-06 10:35:03 +10:00
Tim Starling
9a5aa115e4 Split createTextSlotDiffRenderer() out of getSlotDiffRendererWithOptions
The idea is to make it easier for ContentHandler subclasses to reuse
TextSlotDiffRenderer by composition.

Bug: T339184
Change-Id: I963eb6500fe8b5ba92214d4744eb0aee74fc9331
2023-06-19 13:00:38 +10:00
Daimona Eaytoy
8adf1bfb93 Replace some more usages of deprecated MWException
Bug: T328220
Change-Id: I3c36835fbd90acc301731e2b33ae4815cd4b0cc5
2023-06-09 02:07:08 +02:00
Sam Wilson
1eb586013c diff: Add legend and tooltips to inline diff display
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
2023-05-31 15:43:28 +10: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
jenkins-bot
a8ab8413c9 Merge "actions: Update outdated/incomplete ActionFactory::getActionSpec docs" 2023-04-26 01:43:43 +00:00
thiemowmde
ef0ecf4e16 actions: Update outdated/incomplete ActionFactory::getActionSpec docs
To the best of my knowledge.

Change-Id: I4e38d80baf34d6ecdb9877bc6c8f6c4fa00cedb6
2023-04-26 01:27:42 +00:00
Bartosz Dziewoński
6ba47296d9 Fix Phan suppressions related to Title::castFrom*() and friends
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
2023-04-22 16:45:09 +02: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