Commit graph

195 commits

Author SHA1 Message Date
wfan fed1972733 Migrate MediaWiki.scribunto.traces.* to statslib
Bug: T359275
Change-Id: Idd234bbb34747b4557dcded73eace69131a2566a
2024-05-04 22:40:52 -07:00
thiemowmde 4c4392b4f3 Use PHP's more recent ?? operator where it makes sense
… as well as avoid an overly complicated printf call where a string
cast does the same.

Change-Id: I66b51572d0f2f9e72b9ef7c32f9a62ebb698d739
2024-04-28 17:28:51 +00:00
thiemowmde fbbb56f1ef Stop using the Xml class in this codebase
Bug: T341775
Change-Id: I2ccecaccf1558d9c54d88e2d1f43ca59d7157d15
2024-04-26 13:20:06 +02:00
Dringsim 8307c6b328 Change use of AtEase to at operator
Change-Id: I0c92ba1ca00d43b3e7d636872372dd451f372a29
2024-04-23 01:57:14 +00:00
C. Scott Ananian dfdf5cb54a LanguageLibrary: Ensure language code is a string
Defense in depth: catch the error early when calling mw.language.new()
with a non-string `code` argument; but also check late when popping
the code off the argument array in case something altered the code
property after construction.

Bug: T361664
Change-Id: I04476d3e1c32c87e1df95cc9a0dddcaff475b756
2024-04-11 16:20:24 +00:00
C. Scott Ananian 5bde75bf38 TitleLibrary: Don't register external titles as dependencies
In TitleLibrary::getContentInternal(), an external (interwiki) title will
fail when we try to `Parser::fetchCurrentRevisionRecordOfTitle`, but by
that time we've already tried to add it to the dependency list for the
page via `ParserOutput::addTemplate()`, which causes issues further on.

Bug: T362222
Change-Id: I171e97f17b6de176f92ced47757d10c341c979fd
2024-04-10 11:32:44 -04:00
Timo Tijhof 796c3dddfd Replace 'hash' with CACHE_HASH to improve discovery
Bug: T139216
Change-Id: Icd75953ccdb71543f3100f659fa32e1a1e7d1e26
2024-03-29 15:38:08 -07:00
Umherirrender 52af61330f Add explicit parentheses around mixed boolean operator
Mixing different binary boolean operators within an expression
without using parentheses to clarify precedence is not allowed (T358966)

Change-Id: I6d3edc5f8dddcfc6bd6a7d2a8f2ad9467372908d
2024-03-23 00:59:35 +01:00
Fomafix 2a45dbb577 Inject services into ApiScribuntoConsole, CodeEditorHooks and Hooks
Also use private instead of public for internal function reportTiming.

Change-Id: I52c301d11244436ddc142ec84a7c6740a4ea4d32
2024-03-18 04:40:47 +00:00
Fomafix 70605bf630 Replace global configuration variables
Use overrideConfigValues instead of setMwGlobals in tests.

Change-Id: Icaf7d8d9bb3a4c1eb981ef83a12719c2619039fa
2024-03-18 04:40:44 +00:00
Umherirrender 09f2905ae6 build: Upgrade mediawiki/mediawiki-codesniffer to v43.0.0
Change-Id: Idf24dd1742439d80aaecc308eda386a1afbb0bdc
2024-03-10 23:46:30 +01:00
C. Scott Ananian d00b6aa0ea ParserOutput::setText() has been renamed to ::setRawText()
Depends-On: I3ef34814ab9473cc70d0a6806e8c5a4a02b73491
Change-Id: Iaf220266c8544ab2f1969af4c2b4ec16aca1e46d
2024-02-21 17:13:48 +00:00
vlakoff 6c340bff8d Synchronize mw.text.nowiki() with wfEscapeWikiText in core
Added escapes for "!" and ";" as well as additional escapes
at beginning and end of string.

Bug: T168763
Co-Authored-By: vlakoff <vlakoff@gmail.com>
Co-Authored-By: C. Scott Ananian <cananian@wikimedia.org>
Depends-On: I34f2fa8c329e6f6771453b2f94dc4afbec31dac8
Change-Id: I6c9dcfdbbb2c6eff9414e24d3f2693ebe576505a
2024-02-15 05:29:36 +00:00
Reedy d07d4039e6 mw.title: add pageLang property
Bug: T321239
Bug: T161976
Change-Id: I0f7c80a4bd2339c3cce34030b862e29d984aa714
2024-01-17 18:20:06 +00:00
C. Scott Ananian f5f4355633 Set some title properties to nil for interwiki links
In order to avoid misleading the caller, set some title properties to
nil for interwiki links. That value should still be falsey, but can
prevent making unwarranted assumptions about the destination of
interwiki links.

Split from I847ac4b7587b98be06b25fe14765e9efdc7b774d because this
could possibly have effects on existing modules.

Change-Id: I06efea9b264ba0f09bfb36e6bf1bb04f1cdd03e4
2024-01-16 20:49:42 +00:00
vlakoff e1bd4911bd Add a property "talkNsText" to mw.title objects
Bug: T180911
Change-Id: I847ac4b7587b98be06b25fe14765e9efdc7b774d
2024-01-16 20:36:22 +00:00
Umherirrender 68aebf853c Use namespaced classes
This requires 1.42 for some new names

Done automatically via script

Change-Id: I6f6899981eab571cabb57534d7d98ce546a30a75
2024-01-05 19:24:06 +01:00
Reedy 836baa7142 LuaBit: Minor cleanup
Bug: T353678
Change-Id: I19527eb162c20b5a6017dc3c4dd2b98bf5cad5d9
2023-12-18 23:46:16 +00:00
Reedy 54e9dd05be LuaBit: Save files with unix EOL
Change-Id: Ia757198e32e2beb060ccee9577012bf3c91d49e5
2023-12-18 23:46:09 +00:00
C. Scott Ananian 9694e8f543 mw.language: add :toBcp47Code() method
This allows conversion of MediaWiki-internal codes to standardized
codes suitable for inclusion in HTML.

Change-Id: I5d2102ca57cc6861b8ec144a90f9c17b630f38ce
2023-12-15 00:18:54 +00:00
DannyS712 e30641e439 Add redirects for modules
ScribuntoContent now supports content being redirects, if the underlying
ScribuntoEngine does so. For Lua, a redirect looks like:

    return require [[Module:Foo]]

which also happens to be perfectly valid Lua. There is intentionally no
`#REDIRECT`-style token (like in wikitext/JavaScript/CSS) because no one
will create a page with this content except for the purposes of a
redirect.

Bug: T120794
Co-Authored-By: DannyS712 <DannyS712.enwiki@gmail.com>
Co-Authored-By: C. Scott Ananian <cscott@cscott.net>
Co-Authored-By: Jackmcbarn <jackmcbarn@gmail.com>
Change-Id: I405e7953d00af8a34d5e8addc61a245732c71e8e
2023-12-13 17:34:30 -05:00
Timo Tijhof 8e0684da7a ScribuntoContentHandler: Add lang="en" to fallback <pre>
It currently inherents from the mw-parser-output div, which sets
it based on the documentation page (content language).

Change-Id: I79847cd8cfe75598c843e96a09d9aa61b00304a9
2023-12-12 12:31:10 -05:00
Bartosz Dziewoński ae8c68b051 ScribuntoContentHandler: Fix Phan suppressions
Title::castFromPageReference() and similar methods can return null
instead of Title when the parameter is null. Although that could not
happen in this code, there is no way to tell that to Phan, so
suppressions were required to avoid its warnings about possible nulls.

Instead, since MW 1.41, we can just use Title::newFromPageReference(),
which can't return null (and doesn't accept null as the parameter).
See also Ida4da75953cf3bca372a40dc88022443109ca0cb in MediaWiki core.

Change-Id: Ia3c415cdd68fe4b19869aa8eb8e816e707bb5ad6
2023-12-01 22:37:57 +00:00
Timo Tijhof 09f92105ed ScribuntoContentHandler: Remove redundant Title::getPageViewLanguage use
When OutputPage/Skin call ParserOutput->getText(), this already takes
care of the appropriate attributes. This redundancy is non-obvious
however, because in this code $parserOutput is re-purposed in an odd
way that makes it seem like it has to mark its own language, so as to
separate it from the appended portions for validation error and
syntax highlighted code.

However, at least the way the code has been in recent years, this
has always been a redundant wrapper since OutputPage/Skin already
set the same attributes on the resulting container. With T341244
closed, this is more obvious now that it is located in
ParserOutput::getText, but even before I worked on T341244, the Skin
will have already been doing the same thing as this code was doing,
setting the same redundant attributes.

Bug: T350806
Change-Id: Idb8471eec5d5ac39b7a347c70f3a618eba18a57b
2023-12-01 22:35:41 +00:00
Timo Tijhof 61874ca30e ScribuntoContentHandler: Refactor fillParserOutput()
The ParserOutput object used here starts life as the ParserOutput for
parsing the docpage (wrapped via an interface message). In order to
remove use of the Title::getPageViewLanguage method there, we need to
re-arrange some logic such that we parse the doc page first, and see
what language it was rendered in, instead of currently where
Title::getPageViewLanguage tries to "guess" what Parser and
LanguageConverter will do.

As prep for that stop reading/writing the HTML text of this
ParserOutput object in favour of being more like the Parser itself,
which accumulates metadata in ParserOutput and calls setText only
once at the end.

* Refactor highlight() to return standalone HTML instead.
* Refactor validation error to append to $html instead.

Other improvements while at it:

* Document how stuff works today.
* Clarify variable names.
* Separate concerns better by moving responsibility of `<pre>`
  fallback to highlight(), and limiting knowledge of
  ScribuntoEngineBase to the caller.

Bug: T350806
Change-Id: I9fe6d93727f29c284ea21db6edd6a2b1663e8e06
2023-12-01 22:25:51 +00:00
C. Scott Ananian d97ce9851c Ensure that Scribunto exceptions have a page context set
Some exception messages add tracking categories, which fail when there
is no title context.

Bug: T351045
Change-Id: I47d0160010c9da5a9a9974718a432fd5e79f8286
2023-11-27 14:08:12 +00:00
Umherirrender 8f6ead1f82 Replace empty() with falsy check
empty() should only be used to suppress errors
When the type of the variable is array,
a falsy check is the same (checks for null, false and empty array)
Found by a new phan plugin (T234237)

Change-Id: Id855be9dd25a27d9e46e3065dacbd268177b073d
2023-10-21 23:30:25 +02:00
Umherirrender 945a7871cd Replace empty() with isset()
The property is set to true or is unset,
isset is easier to understand in that case

Change-Id: Ib98e387ae1a2352556f57aee93da92bdf5453633
2023-10-21 20:38:47 +02:00
C. Scott Ananian 1eea8281c9 Assign UUIDs to Scribunto errors independent of page parse order
This replaces the use of ParserOutput::addJsConfigVars(), deprecated
since 1.38, and ensures that the IDs used for error messages are
independent of page parse order. (See T300979.)

This is an improved replacement for Ibd3fbcbc774491179b0d4fe29ba3b6a128220703
which was reverted (T346094).

Bug: T300307
Bug: T305161
Bug: T346094
Change-Id: I2c660972b289bbad730ceee1325d70d5ba75d27e
2023-10-13 15:23:22 +00:00
Umherirrender 29a9a8aec6 build: Change phan suppression to @phan-var for proc_get_status return
phan under php8.1 also detects PhanImpossibleTypeComparisonInLoop here,
but that cannot suppressed under php7.4,
so use @phan-var to set to the correct type, but keep the comment.
The suppression was added with 8328acb9 for a update of phan

According to the doc proc_get_status can only return array
(at least under php8.1)

Change-Id: Ieda5abc30126eed2e3a9f5fc283d36e64180f496
2023-10-06 19:37:10 +00:00
Umherirrender e126de6a78 Rethrow TimeoutException when using mw.language.formatDate function
timeout while converting timestamps should be a timeout for the whole
parse of that wikitext and not hidden by a invalid time.
Just let the exception bubble up to the caller
See ca71e69f for more information

Change-Id: I1f44e45dcc9b052717814990a3f5ce3a1bdf9d26
2023-10-02 21:03:02 +02:00
Umherirrender 80198cd635 Use ::class for class name resolution
Change-Id: I92a73fd6eccd3cf963ce1ff50ccf4f7aac6a0e1e
2023-09-21 22:46:00 +02:00
Jdlrobson 77286ebc87 Revert "Replace use of ParserOutput::addJsConfigVars(), deprecated since 1.38"
This reverts commit 9f8d16f9c9.

Reason for revert: Causes internal error on certain pages.

Bug: T346094
Change-Id: Ia9ccffbbbe2fe2413b54fb5e16f5cfc53527990e
2023-09-11 20:18:13 +00:00
C. Scott Ananian 9f8d16f9c9 Replace use of ParserOutput::addJsConfigVars(), deprecated since 1.38
Most uses can be replaced with ::setJsConfigVar(); the major semantic
change is that ::setJsConfigVar() is not expected to overwrite
previous values.  That *may* be an issue here, but if so it's not
a change from existing behavior, as the way ::addJsConfigVars() was
being called it would override previous values as well.

Bug: T300307
Bug: T305161
Change-Id: Ibd3fbcbc774491179b0d4fe29ba3b6a128220703
2023-09-11 16:55:54 +00:00
Daimona Eaytoy 7e54c088ac Avoid DB access in databaseless tests
- Force a content model on the title used by LuaEngineTestBase, so that
  calls to getPageLanguage() won't end up hitting the DB
- Don't actually use SiteStats from SiteLibrary in unit tests. There
  seem to be no test actually using this data.

Bug: T345372
Change-Id: I35884f04b582678982fb5f64d9199bab41cd8bce
2023-08-31 19:12:55 +00:00
Umherirrender a8280e5e5f Use namespaced Title
Bug: T321681
Change-Id: I65940dc6d276f86734ff724d6605facb68dd8e44
2023-08-19 20:18:41 +02:00
gerritbot b7a5e6fadd Replace some moved Title class uses, now MediaWiki\Title\Title
Bug: T321681
Change-Id: I27924141187aef8fe2f6500ec0c4b6360d268c28
2023-08-19 12:22:05 +00:00
Umherirrender a00ce79826 Use HookHandlers for CodeEditor hook
This requires 1.41 for the interface (added in 4d6a470a)

Bug: T271026
Change-Id: I393ba99b7265dac81c7fdaf3d21630386c7c53a9
2023-08-15 13:50:13 +02:00
Umherirrender 648985c981 Use HookHandlers for core hooks
The use of "HookHandlers" attribute in extension.json makes it possible
to inject services into hook handler classes in a future patch.

Bug: T271026
Change-Id: I1583f5075937c4ce71a0d8748700f7012280851c
2023-08-15 13:49:53 +02:00
Anne Haunime b3f55c05e9 Optimize mw.text.trim() with default charset
Using code by David Manura, published at lua-users.org/wiki/StringTrim

Note '\t\r\n\f ' is replaced with '%s', thus '\v' (vertical tab) is added to the characters trimmed by default.

Bug: T338561
Change-Id: I98e2677f1181b88f4cd97cffca3a53ce426ec5cd
2023-07-14 15:59:20 +00:00
Umherirrender 2ee5768ef5 Create HookRunner class and the hook handler interfaces
Bug: T271026
Change-Id: If525e0f950b3a098162b19373edb3b443f559bf2
2023-06-19 21:39:33 +00:00
Daimona Eaytoy 846495fe45 Replace deprecated MWException
Bug: T328220
Change-Id: I38be06abdabff29276f07c378f3ef434973fb8d6
2023-06-09 14:43:44 +02:00
gerritbot 881d0c2bbd Update moved class RawMessage
See T321882. Moved in I195cf4c67bd514

Bug: T321681
Change-Id: I9c5e19e62f5faf73e6825e29090f6e1ae84ae3fb
2023-05-19 10:31:10 +00:00
gerritbot 57e391d32a Update moved class Category
See T321882. Moved in I0b86acfdea

Bug: T321681
Change-Id: I98440222d04b3c15523a7e00d447933f85b360ed
2023-05-15 13:26:48 +00:00
gerritbot 7cf0fa1edb Update moved class EditPage
See T321882. Moved in Ibefc44eb64aed

Bug: T321681
Change-Id: I52f974372fe79145ddbb59fbbd4ec8dbf9c83e23
2023-05-07 00:32:11 +00:00
Umherirrender ebda052657 Replace deprecated Hooks::run
Bug: T335536
Change-Id: I3d7329c985d98b0f97003ef859113c87cf0c25c6
2023-05-06 23:06:24 +02:00
gerritbot 756926c479 Update moved class WikiMap
See T321882. Moved in I60cf4b9ef02b9d5

Bug: T321681
Change-Id: I4bd035a77ac80e9b408e63b35f3116e1901df7cb
2023-04-25 09:54:46 +00:00
Reedy 033c69cfab ScribuntoException: Use value property not dynamic property
Bug: T330524
Change-Id: I69a102497fffb939c849d2836302068ac9eff3d0
2023-02-25 00:57:56 +00:00
Umherirrender e2c3b41026 Use LanguageNameUtils::AUTONYMS/DEFINED instead of hard coded value
Easier to spot the documentation what happen with this option

Change-Id: Ic053e8daf14a74306b7ca3052503a59a19d16743
2022-12-29 13:43:27 +01:00
Umherirrender a20054fa34 Replace deprecated Language::isValidCode/isSupportedLanguage
Bug: T325974
Change-Id: I0245ea66abeebd9ae9b6d1edce9e8e93a479fdc0
2022-12-29 03:04:32 +01:00