Commit graph

35 commits

Author SHA1 Message Date
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
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 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
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
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
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
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
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
Umherirrender bf4bdddb41 Replace deprecated Language::getFallbacksFor
Bug: T325979
Change-Id: Ia9658d0ce5bcd0c322cca0ffcec6aee82fb20a62
2022-12-29 02:01:09 +00:00
Umherirrender 3b84d90eb7 Replace deprecated Language::factory
Bug: T325986
Change-Id: I27a8742eb4897104d9bdaef298ec97c471baf641
2022-12-29 01:42:41 +00:00
Umherirrender 6e313296c5 Replace use of deprecated Parser::$mOptions
Bug: T275160
Change-Id: Id17fc7c2db20975fb6fbb2b9bf63a45135f7f354
2022-12-28 00:56:41 +00:00
Umherirrender e76dff032d Replace deprecated Language::fetchLanguageName(s)
Bug: T325962
Change-Id: Iff57224d231480507f138f9ba51f385ed32bf5b1
2022-12-27 17:21:10 +01:00
Bartosz Dziewoński 46bb5b0ac4 Avoid try…catch where if…else will do when using LanguageFactory
Needed for I869af06896b9757af18488b916211c5a41a8c563, where I am
trying to change LanguageFactory in MediaWiki core not to use
MWException.

Language::isSupportedLanguage() does not actually throw,
so this sigh can be one of relief.

Change-Id: I3079d8e18d88a4a26c2f2b09dccd4beea06678ee
2022-11-18 19:56:45 +00:00
Kunal Mehta 66e9257feb Partially revert 912324993f, restore old line ending behavior
As explained in T322883, the switch to
TextContent::normalizeLineEndings() means that rtrim() is run over the
input, which is a breaking and unintentional change.

This partially reverts commit 912324993f.

Bug: T322883
Change-Id: I2ad47d46e05112f413af453d61eb3f13434b2774
2022-11-11 21:04:19 -08:00
Jackmcbarn f032e847bf Include the bad timestamp string in the error when unable to parse it
Change-Id: I0a79c25baf829f755aa5d251a78e032a12168364
2022-10-17 03:13:05 +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
Kunal Mehta 9d94f11309 Hide mw.hash.setupInterface from users
Part of the standard library boilerplate that got missed.

Bug: T276138
Change-Id: I6d55d55405b57b18f3f413a108848f34620c15a6
2022-10-08 22:01:00 +00:00
Brian Wolff 047200c11e Make sure that lua stack trace is valid UTF-8.
This fixes a warning on php8.1 related to preg_match_all returning
null when given invalid UTF-8.

I made a separate patch to change the null into an exception Ic0c9083b

In a sense, this is a follow-up to ec103b6966.

Bug: T319218
Change-Id: Ia17fc2fa428ec35bdbd242f1127fcdff501fb741
2022-10-06 04:08:24 +00:00
Reedy 5f007a0c76 LuaError: Use ?: in more traditional way
Change-Id: I68011e1420ae95127ef284d5044f9f125cc656c3
2022-10-03 19:01:56 +01:00
Reedy 13e82702ab Add global alias for Scribunto_LuaEngine
Change-Id: I8a53a0583f25b397fec25ba77c8a061426c8a641
2022-09-30 02:07:29 +00:00
Thiemo Kreuz 912324993f Apply some minor PHP code modernizations
* Make use of the ?? syntax.
* Use an upstream function.
* Fix an incomplete type hint.

Change-Id: I7b1916418f4b1e65cc8396cfd646224f55c137a4
2022-09-29 21:45:09 -04:00
Reedy 1eecdac6de Capitalise Engines folder
Change-Id: I6d730d67decc859fd130fee5ec92b1cfb8d9ef64
2022-09-30 00:58:27 +00:00