Commit graph

141 commits

Author SHA1 Message Date
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
Kunal Mehta 0f2585244c Require CSRF token for action=scribunto-console
This is basically unexploitable, given that Scribunto sessions are
"extremely ephemeral", protected by a 31-bit non-cryptographically
random token and generally contain very little useful data.

But, requiring a CSRF token is a best practice and since this module
is internal and only used in one place, it's also unlikely to break
anything. Because it needs a token, the module is POST-only now too.

Bug: T212071
Change-Id: I7fb6b4f856ee6194eb37c26e14f178fea6c0a3f6
2022-10-05 14:38:50 +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
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
Tim Starling 6f437487b8 Fix incorrect param type, causing phan error
Change-Id: I3a87b0c58fd897ea83dbb44c51a01d206d1cd024
2022-08-22 17:26:57 +00:00
Alexander Vorwerk 738ca8d72d Bump scribunto-stats cache version
The addition of PSquare::__serialize() in wikimedia/running-stat is
having the same cache implication as the issue this was meant to fix.

The legacy PHP serialized form is not compatible with the stable
serialize form that we're switching to.

Bug: T313341
Change-Id: Iec4c1c958e10560abcbd4184a0ca4e1a0c19183a
2022-08-16 19:09:36 +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 dc97acc945 Update mediawiki/mediawiki-phan-config to 0.11.1
Bug: T295285
Change-Id: I65db513703b54b377dfbeacf2956c1ff13a27b99
2022-08-02 01:14:06 +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
Timo Tijhof e9988b8473 Hooks: Minor clean up, remove redundant PSquare check
PSquare is part of wikimedia/running-stat which is bundled with
MediaWiki core. There is no valid way to install a wiki without
the vendor libraries present.

The check was introduced in 2015 with I0d39920733fe7 when the class
was newly added to the package and deployment was happening
concurrently to the extension change.

Bug: T313341
Change-Id: I6717151c39b589f2e5b5e87da6896f62252cb5d8
2022-07-19 14:58:17 -05:00
Timo Tijhof e5362f639e Hooks: Bump scribunto-stats cache version
The Wikimedia\PSquare class has changed such that its serialization
is incompatible with its prior version. We should probably refactor
this to use an actually supported serialization format, possibly
by enhancing PSquare with some kind of getter method that provides
a plain array that its constructor can accept again instead of relying
on internal PHP serialisation format, but for now we can bump the
cache version.

The side-effect of this will be that the performance stats captured
by Scribunto for visualiation in Grafana, will briefly split its
sampling logic between two versions instead of being global across
all wikis until the train is fully deployed. This does not have any
effect on its business logic or runtime behaviour, and is presumably
by design as that's the only way to bump the cache version, which was
a pre-existing factor in its cache key.

Basically, this means that during the deployment days on weeks where
this is bumped, we will briefly capture fewer samples as there are then
two separate counters trying to reach 1000 before flushing a median
to Graphite. We can remedy that by backporting and deploying to both.

While at it, I'm changing the cache key to conform to our conventions
and make it an explicit, greppable, lowercase and descriptive name
(scribuntu-stats) instead of the implicit __METHOD__ which expanded
to "Scribunto\Hooks::reportTiming". I note that this means the split
brain sampling actually happened at least once before during the week
where the namespace was introduced as that will have implicily changed
the cache-key. Another reason not to use __METHOD__ in a cache key.

Bug: T313341
Change-Id: Ic9dad0f55cba18ec03272b87366a091a396beb74
2022-07-19 14:53:53 -05:00
Ferran Tufan 674e58b87a Replace usage of Linker with LinkRenderer service
Bug: T279335
Change-Id: I778e86cf3fad2cf333031aca95aeba65a88405ce
2022-07-11 20:24:35 +00:00
Thiemo Kreuz 8654dfc466 Use new ContentHandler::supportsPreloadContent() feature
Bug: T300644
Depends-On: Ia5c491cd856ca395fb431bcefd63026084b01a99
Change-Id: I301cbb6b2d547e622ee695fd20a910f8553788c5
2022-07-06 22:39:44 +00:00
Tim Starling a0a0c3ee7e In ScribuntoContentHandler use the new ParserFactory::getInstance()
To avoid an exception when the parser is re-entered.

Bug: T310948
Depends-On: I762b191e978c2d1bbc9f332c9cfa047888ce2e67
Change-Id: I5013ed2a2958c3ff422778f9146f663aff0f5939
2022-07-05 04:31:52 +00:00
Thiemo Kreuz 0860648680 Remove unused defaults from class properties
As well as:
* Remove redundant `=== null`. The `isset()` before does this already.
* Use convenient PHPUnit shortcuts.

Change-Id: Ibef571e53a48c443d7798fee8abbc2624fbad225
2022-05-21 18:45:52 +00:00
Sam Wilson 2f0775fe8a Increase mw.dumpObject() indent size
Increase from one space to two.

Bug: T307343
Change-Id: I14126475579bae310e5cbea0bdb992fb824b30ab
2022-05-21 13:51:14 +00:00
Reedy 8e73003fee Start namespacing extension
Change-Id: Ib632434861c2df03dfcddbd195f556c937812196
2022-05-12 01:33:11 +00:00
Reedy 09b60f174c Use namespaced SyntaxHighlight class
Also swap class_exists() for ExtensionRegistry->isLoaded() call

Change-Id: I3435e3775a28f4f056599ae26ba23f54d32cde18
2022-04-27 16:10:48 +00:00
Reedy 6f411e3921 Minor cleanup
Change-Id: Ic81ab852c43e98370097d01c3b6d6cddee7a5850
2022-04-16 22:09:10 +01:00
gerritbot 14589459a1 Fix usage of ApiBase::PARAM_* deprecated constants
The ones that are replaced with ParamValidator

Bug: T275455
Change-Id: I69cfbbe5b00a4e15a0d6492541292bcddd61069a
2022-04-04 02:30:20 +00:00
Umherirrender 9c3fe53170 Adjust argument for local interwiki in InterwikiLookup::getAllPrefixes
To match the type change in core

Depends-On: I63ed9772429c6f5bfe38a9fad190491812866f3f
Change-Id: I5394d82e7c78b12453f824664f53fe8e6a73aa0b
2022-04-04 02:30:19 +00:00
Reedy 5ca204aa0d Replace usages of Wikimedia\(suppress|restore)Warnings()
Change-Id: I6bf98327dafe3d2a7009cd0897f6418ca84690dd
2022-02-24 21:16:46 +00:00
Ammarpad b8d7d70084 Use Category::getMemberCount from core
Core now provides all-member count separately with type guarantee.

Depends-On: I8780a4f9bc6c4cb588d0da10b457130df104ced9
Change-Id: Iae795c7c46360727dd4a4d47e7b8bb4dc1c607ab
2022-02-06 16:35:03 +01:00
Thiemo Kreuz 6d7d686441 Remove comments that literally repeat the code
Change-Id: I6508745504af15a233ed4f6981c5114b72f1805a
2022-01-18 23:50:13 +00:00
C. Scott Ananian 6633e446d9 Passing a string to ParserOutput::addModules()/addModuleStyles() is deprecated
In addition, several variables which contained instances of ParserOutput
were renamed to $parserOutput to help future humans and code-searchers
to distinguish these from instances of OutputPage.

Bug: T296123
Change-Id: Ic532bca4348b17882716fcb2ca8656a04766c095
2022-01-12 11:31:31 -05:00
20after4 5e7cfe4b84 Revert "mw.title: Add pageLanguage property"
This reverts commit 602cef87e0.

Reason for revert: Production errors in 1.38.0-wmf.16

Bug: T298659
Change-Id: Ic6c0e31c8247f7d89824d20f28fb0aa56d6ed749
2022-01-06 22:13:30 +00:00
Alexander Vorwerk aae6e29547 Replace usages of deprecated wfWikiID()
The global function wfWikiID() is deprecated since 1.35 and it's usages
should be replaced with WikiMap::getCurrentWikiId().

Bug: T298059
Change-Id: Idb937a82b08679f6552699ecc4a7ea1da7006e09
2021-12-21 02:32:15 +01:00
Brad Jorsch 602cef87e0 mw.title: Add pageLanguage property
Bug: T161976
Change-Id: Ifc7a462efb11b28f20ebaad5d62cba8f1f1f8e91
2021-12-17 04:10:40 +00:00
Brian Wolff 405045c416 Return correct lua version on windows
For some reason this is hard coded 5.1.4. But if you look at the
included binaries, the windows ones are clearly 5.1.5.

Change-Id: If0e7e6ae47b058b3d425b586955cc87a14b21eb8
2021-11-15 19:33:30 -08:00
Roman Stolar d2c23dd3a3 Override ContentHandler::validateSave instead of Content::prepareSave.
Prepare override for ScribuntoContentHandler, remove usage in ScribuntoContent.

Bug: T287159
Depends-On: I7f23e6e97b1c7d27a6aaefdb88b19b2fc6e8b3a8
Change-Id: I4b9287372a95f4b6178dc321105081552d040ef8
2021-11-11 16:01:05 +00:00
Thiemo Kreuz 51592c654f Add missing & and (int) casts
Bug: T290189
Change-Id: I0bd0d06834f91fbc6a4067987e7e9e9e09b4e740
2021-10-27 17:27:33 +00:00
Roman Stolar 8c66ac25c9 Override ContentHandler::fillParserOutput instead of Content::fillParserOutput.
Prepare override for ScribuntoContentHandler, remove usage in ScribuntoContent.

Bug: T287158
Change-Id: I91f6a077f5cc0de25f83bea26d9f1772af0d3d68
2021-10-19 14:08:17 +00:00
C. Scott Ananian 1af638f8db Replace use of deprecated ParserOutput::addWarning()
Bug: T293515
Depends-On: I6a7c04c67ac586ab00d4edcbb3d09485a7794e23
Change-Id: Ib51c75e38b9bf490b4ded481ee92ede0949f272e
2021-10-16 01:17:20 +00:00
C. Scott Ananian c0963eced7 Replace use of deprecated ParserOutput::{get,set}Flag()
Depends-On: I39bc58d207836df6f328c54be9e3330719cebbeb
Change-Id: I906a5970088965c187bf653267ac4b369dac9b9b
2021-10-15 23:41:06 +00:00
C. Scott Ananian 0453ef6021 Replace use of deprecated ParserOutput::addTrackingCategory()
Depends-On: I697ce188a912e445a6a748121575548e79aabac6
Change-Id: Ie41ad70f1fb5de202355314a96a1243234fb267c
2021-10-13 21:46:57 -04:00
Petr Pchelko ae920ae5b8 Replace deprecated ParserOptions::getUser with ::getUserIdentity
Bug: T292589
Change-Id: I381863a62340292e8bbc7840256f591a31afb42e
2021-10-05 14:48:28 -07:00