Commit graph

293 commits

Author SHA1 Message Date
Umherirrender db8f22c1d4 Use namespaced classes
Changes to the use statements done automatically via script

Change-Id: Iedad37d75aee4d2a6960ab20148f813c6cf7061a
2024-06-10 20:41:43 +02:00
Bartosz Dziewoński c6b1f32dff Update parser tests for new heading HTML
Bug: T13555
Depends-On: I1180169a8e83af834c2984ba16089e6277f2a8dd
Change-Id: I4d2be132e63aff7bf8953f0f371e806a834db10d
2024-05-16 16:35:58 +00:00
theknightwho a091b46d65 Use correct variable for error message in mw.loadJsonData
`mw.loadJsonData` in mw.lua throws an error if the input argument is
not a string. The error message should refer to the type of the input
argument `module`, not that of the variable `arg` (which is usually
undeclared, giving the type `nil`).

This also necessitates updating test `mw.loadJsonData, bad title (1)`
in CommonTests.lua, which checks for the error message if the input
is the number 0; the correct message should say "got number", not
"got nil".

Bug: T364987
Change-Id: I8362e91489a8ddc4c890e2799892f692c497c9b9
2024-05-15 14:05:32 +01: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
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
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
C. Scott Ananian f89e892a06 Fix parsoid parserTests
These errors weren't being flagged because of a bug in how
`parsoid-compatible` was handled in the parser test file options.
See Ifca13393c3bbec27c23cbdc311d4550fbccf21ca.

Change-Id: Ib65dd0adb472da53823c07af5991a140374501e4
2024-02-01 16:45:12 -05: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
Dringsim bab08d831e
Add test for mw.site.stylePath and mw.site.currentVersion
Change-Id: I3828928f65d6b1bbe4c2ab69bc680a753c64c04b
2023-12-29 23:23:21 +08: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
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
Daimona Eaytoy 83d0f76301 Update tests for PHPUnit 9.6
- Avoid defining abstract test classes (ending in "Test")

Bug: T342110
Change-Id: I729df8d3cd5071826b5e035813102148a0f47520
2023-11-22 15:18:47 +00: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 d734759316 tests: Declare class properties in LuaEngineTestHelper
Dynamic properties are deprecated under php8.2

Change-Id: I062f034295bf951d5761571e20d3e6d45df85ac3
2023-10-06 20:19:22 +02:00
Lucas Werkmeister b39d3589ba Remove Database group again where possible
Override the target language in the parser options, so that it isn’t
looked up from the database; this lets UriLibraryTest avoid database
access. And since the Database group is no longer strictly required,
remove the statement to that effect from the phpdoc again.

Bug: T345372
Change-Id: I79f35257b123eb939d9ab67b16aa56d34586bb67
2023-09-06 11:33:42 +02: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
Lucas Werkmeister ea0707c437 Add UriLibraryTest to Database group and add advice for others
All LuaEngineTestBase subclasses must be in the Database group, as far
as I can tell it can’t be avoided. (Several already are anyway.) We
can’t centrally do this in the base class anymore (needsDB() can no
longer be overridden), so just add it to the phpdoc here.

Bug: T345372
Change-Id: I47016ec84ed227f755f94a383bee8053975b4c81
2023-08-31 18:08:37 +02:00
Umherirrender a8280e5e5f Use namespaced Title
Bug: T321681
Change-Id: I65940dc6d276f86734ff724d6605facb68dd8e44
2023-08-19 20:18:41 +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
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
Umherirrender 16189b5866 tests: Make some PHPUnit data providers static
Initally used a new sniff with autofix (T333745)

Bug: T332865
Change-Id: Ia50628faba21eeb30a08f11823825dce9bb71db2
2023-05-20 19:35:54 +02:00
Brian Wolff 72366e5b68 Update tests for compat with kaa i18n changes
See be7291848428 & be7291848428

Change-Id: Icbf016311af029bfd02dd701ede881416b85ee31
2023-03-28 00:51:48 -07:00
Umherirrender f15b30cdb7 tests: Fix i18n part of test data to match new translation
https://translatewiki.net/w/i.php?title=MediaWiki:Duration-minutes/kaa&oldid=11412949

Follow-Up: Ibc5e8cee9e076c8952eb24839d5e97d4eca4ccf4
Change-Id: If352609c5ad7d9a52a94c737cac3f0f1a47de2e0
2023-02-13 20:39:57 +01:00
Umherirrender e76dff032d Replace deprecated Language::fetchLanguageName(s)
Bug: T325962
Change-Id: Iff57224d231480507f138f9ba51f385ed32bf5b1
2022-12-27 17:21:10 +01:00
Umherirrender a0732c2db8 tests: Replace assertEmpty with assertCount
Change-Id: I0002bb228701a3a5184ac7f1e38321bf10b23064
2022-11-25 10:26:34 +00:00
Kunal Mehta 1000d322e5 Add mw.loadJsonData()
mw.loadData() allows for optimizing the loading Lua tables by requiring
only one parse and lookup. However it's often easier for people to
write/maintain bulk data in JSON rather than Lua tables.

mw.loadJsonData() has roughly the same characteristics as mw.loadData()
and it can be used on JSON content model pages in any namespace.

As noted on the linked bug report, it's possible to already implement
this by writing a wrapper Lua module that loads and parses the JSON
content. But that requires a dummy module for each JSON page, which is
just annoying and inconvenient.

Test cases are copied from the mw.loadData() ones, with a few omissions
for syntax not supported in JSON (e.g. NaN, infinity, etc.).

Bug: T217500
Change-Id: I1b35ad27a37b94064707bb8c9b7108c7078ed4d1
2022-10-13 04:46:25 +00:00
Kunal Mehta 829c53ef05 Add strict.lua to replace "Module:No globals"
For the most part, it is a good idea to avoid global variables and use
`local` variables instead. Quoting from the ScopeTutorial[1], "The
general rule is to always use local variables, unless it's necessary for
every part of your program to be able to access the variable (which is
very rare)."

Wikimedia module authors have written "Module:No globals", which errors
on the use of any global variable. On the English Wikipedia, this is
used on 32% of pages (18 million). Wikidata[2] indicates that it's been
copied to 334 other wikis.

Lua itself distributes an extra named "strict.lua"[3], which is what
this is based off of. Similar to bit32.lua, this is a pure-Lua library
that can be imported/enabled with `require( "strict" )` at the top of a
module.

The two changes I made from Lua's strict is to exempt the `arg` key,
which is used internally by Scribunto, and remove `what()`, since we
don't enable access to `debug.getinfo()` for security reasons.

[1] https://lua-users.org/wiki/ScopeTutorial
[2] https://www.wikidata.org/wiki/Q16748603
[3] http://www.lua.org/extras/5.1/strict.lua

Bug: T209310
Change-Id: I46ee6f630ac6b26c68c31becd1f3b9d961bcab29
2022-10-13 04:39:21 +00:00
Reedy 69ed697681 Add more @covers
Bug: T320330
Change-Id: I3456453226faa3ba68be4deca764839ea0f54539
2022-10-08 20:59:33 +01:00
Reedy 408f4d0bc6 Namespace tests
Change-Id: I4977bf534400643f83ab3400c3dfd736c53f9705
2022-09-30 00:59:00 +00:00
Reedy 1eecdac6de Capitalise Engines folder
Change-Id: I6d730d67decc859fd130fee5ec92b1cfb8d9ef64
2022-09-30 00:58:27 +00:00
Reedy 073a365759 "Namespace LuaCommon" take 2
Revert "Revert "Namespace LuaCommon""

This reverts commit 18d122b60d.

Change-Id: I74fd43f7920c8772e9078f745ac6062d5461a7f1
2022-09-30 00:52:27 +00:00
Kunal Mehta 4ccebcdf4b Simplify creating JSON pages in the Module namespace
Pages ending with a ".json" suffix in the Module namespace will use the
built-in JSON content model by default. Previously editors had to use
Special:ChangeContentModel to get a JSON page, which requires the
"editcontentmodel" userright that is not granted to a wide set of users
by default.

Bug: T144475
Change-Id: I1546fcad823a55a8c5a93177df8715844de1e87c
2022-09-22 19:48:52 -07:00
Subramanya Sastry 23ac31e746 Add Parsoid-specific support for handling preprocessed nowikis
* This patch builds on core functionality provided in
  Ied0295feab06027a8df885b3215435e596f0353b.

* This removes any nowiki wrappers present in unstripped text
  (which there would be for preprocssed nowiki tags) which mimics
  the effect of procssing nowikis in core when generating HTML.

* Updated lua tests to verify the new expectation.

* A previously failing parser test added to test T272507 now passes
  and has been re-enabled.

Bug: T272507
Depends-On: Ied0295feab06027a8df885b3215435e596f0353b
Change-Id: I1613ac7bd60cf3ef4a3308b08ea3705b3cf2dee0
2022-09-08 23:17:46 +00:00
Subramanya Sastry 3aa6ad45db Temporarily disable the newly added test in f230419b
* This test fails with a core patch and will only pass in a
  subsequent patch in this repo.

Needed-By: Ied0295feab06027a8df885b3215435e596f0353b
Change-Id: Id6ea611549e98893f53094116a3851e9c42b8dc8
2022-09-01 21:24:25 +00:00
Arlo Breault 7778a6eef3 Revert "Disable Parsoid testing tempoarily"
This reverts commit 2c3a363cdc.

Depends-On: I7c419e1d508c337328db1d5132454fb805bfb1b5
Change-Id: I1770656d450ee0ba0ca115993812c06116eb5928
2022-09-01 21:08:20 +00:00
Subramanya Sastry 7170021941 Update failing language tests
* Ia3cc8f95833cd0e9ae985528f8e72396111c4504 in core changed
  localizations for kaa language

Followup-To: Ia3cc8f95833cd0e9ae985528f8e72396111c4504
Change-Id: Ie1b686b65f008c0cd5f4017102699e51f6960b39
2022-08-29 16:20:59 -05:00
Subramanya Sastry 2c3a363cdc Disable Parsoid testing tempoarily
* Running into a missing module error in CI but cannot reproduce
  locally.

* Let us unbreak CI for other dependent repos and investigate this
  in the followup patch that reverts this.

Bug: T316331
Change-Id: Ic5983e503203f132fff521e422f0c7143f91d779
2022-08-26 14:57:48 +00:00
Subramanya Sastry f230419baf Enable testing with Parsoid + add failing test for T272507
* Turned on wt2html and wt2wt Parsoid modes for all tests with
  aggressive normalization to eliminate the need to add html/parsoid
  sections.

  We expect these modes to pass.

* The failing wt2wt tests is because the input wikitext duplicates
  arguments and Parsoid's wt2html doesn't capture duplicate template
  args which cause the wt2wt output to be normalized.

  This explains the two failing wt2wt tests and the corresponding
  selser "failures".

* The failing wt2html safesubst test might be a real failure and
  something we will have to look into. Will file a phab task for this.

* Added a new test for T272507 that fails with Parsoid right now,
  but will pass in a subsequent patch.

Change-Id: I96fba68dda7524d2fe562eb60ced64e5e0518f65
2022-08-22 13:27:20 -05:00
Subramanya Sastry 8adcc1668f Update failing language tests
* Core changed these kaa localizations in
  Ie0ce427238412d3badb247d2e2fae9bc9f57fbeb

Followup-To: Ie0ce427238412d3badb247d2e2fae9bc9f57fbeb
Change-Id: I7fc0334bf78222f2d7c1b636a70b3c60f899363c
2022-08-12 17:57:21 +00:00
Lucas Werkmeister (WMDE) 18d122b60d Revert "Namespace LuaCommon"
This reverts commit 62e1fb0b5f.

Reason for revert: caused several errors:
* unnamespaced HooksTest collides with core’s class of the same name
* Scribunto_LuaError renamed without class alias despite being used in Wikibase

Bug: T314464
Change-Id: I8b151327236bf86945e59823fba155497e4b3fc6
2022-08-03 10:03:12 +00:00
Reedy 62e1fb0b5f Namespace LuaCommon
Change-Id: Ib6e912e71fb797942aca4b4f22eb0ff9e005a662
2022-08-03 06:03:57 +00:00
Reedy c479ad6f86 Namespace LuaStandalone engine
Change-Id: I7d3f77a56c8b74e0481197224006f19ff4c9d108
2022-08-03 06:03:48 +00:00
Reedy 1628cfa367 Namespace LuaSandbox engine
Change-Id: I485401c202057ae0fea7226ab21e68ce1c7d40c8
2022-07-30 22:51:42 +01:00
Reedy 0eaa8edfb0 Fix MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment
Change-Id: Ia2148daf26cb167cbe71a0ab419473a31d97a506
2022-07-30 18:56:55 +00:00