Commit graph

105 commits

Author SHA1 Message Date
Brad Jorsch c69e2e5049 Update for API error i18n
See Iae0e2ce3.

Change-Id: I1642929fa48e5354217e0c6de19b4f80b38d94f0
2016-11-14 12:48:25 -05:00
Kunal Mehta edb1b51f8b Use EditFilterMergedContent hook
Bug: T147565
Change-Id: I37bc43392ffa950e230fbff6a902c061ca04b970
Depends-On: I1f0e463841298b8c59ed8bd898c8a4661c5e3aa4
2016-10-15 06:28:22 +00:00
Brad Jorsch db07787390 Cleanup backwards-compatibility code
https://www.mediawiki.org/wiki/Extension:Scribunto says that master
requires 1.25+, so let's remove checks for stuff that was added before
that.

* PPFrame::getTTL() was in 1.24.
* PPFrame::setTTL() was in 1.24.
* PPFrame::isVolatile() was in 1.24.
* Parser::fetchCurrentRevisionOfTitle() was in 1.24.
* ObjectCache::getLocalServerInstance() was added in 1.27, so restore the call to ObjectCache::newAccelerator() as BC.

This also removes BC with the php-luasandbox extension older than 1.6, which
was released before MediaWiki 1.22.

Bug: T148012
Change-Id: I36e37f3b65d0f167e1d28b00e0842d9721feee31
2016-10-13 11:07:44 -04:00
Aaron Schulz 3660ec17ba Clean up ObjectCache calls
Change-Id: I95b2d4d0f94a2e7f42372615ea9c612845502b30
2016-10-11 14:06:38 -07:00
jenkins-bot 32b91bb6f7 Merge "Use ParserOutput::addTrackingCategory()" 2016-09-14 19:47:05 +00:00
Kunal Mehta 44ccde4861 Use ParserOutput::addTrackingCategory()
Change-Id: I2989df0e689df69a0c9cf2ec6001a568fe4f635d
2016-09-14 12:34:21 -07:00
jenkins-bot cd32961367 Merge "Improve validation of ScribuntoContent" 2016-09-14 19:27:29 +00:00
Kunal Mehta 48748a6046 Improve validation of ScribuntoContent
Implement Content::prepareSave() to ensure that any content
directly passed to WikiPage::doEditContent() that doesn't run edit
filters will still be validated. We have to use prepareSave() instead of
Content::isValid() because validation depends upon the current Title.

Create a ScribuntoContent::validate() convenience function to hold the
logic for that and add a todo to use it in the EditFilterMerged hook.

Also, remove a parser test that depended upon being able to save invalid
modules directly, as what it is testing is no longer possible (unless it
pre-dates making valid syntax a requirement).

Bug: T145548
Change-Id: Ie57eff36100963f02899d669df7375577f7375e1
2016-09-14 11:50:07 -07:00
Kunal Mehta b21cecbac1 ApiScribuntoConsole: Don't use $wgUser
Change-Id: I41d9b0961e98d7836e8d5e8236ec2503f30713b1
2016-09-13 17:11:11 -07:00
Kunal Mehta 8a347d5680 Use context from EditPage/Article instead of global objects
Change-Id: Ieae2e92e248da32818f26649caaa7e70192f969b
2016-08-31 18:25:11 +00:00
jenkins-bot ef659a146a Merge "Add mw.hash to Scribunto" 2016-08-18 15:35:49 +00:00
Marius Hoch 0f4db74148 Add mw.hash to Scribunto
Provides a simple wrapper for PHP's hash() and
hash_algos() functions.

I will add docs to the Lua reference manual once
this is merged.

Bug: T142585
Change-Id: I6697463974a175e99f9b77428a1085247165ebc9
2016-08-18 04:39:04 +02:00
Brad Jorsch 31d53b4a40 ScribuntoContent: Use base class preSaveTransform()
Bug: T142805
Change-Id: I0228c8f9c09504001bb5e1d27b5482af1786c17e
2016-08-15 11:22:14 -04:00
Kunal Mehta 98436e2008 Have ScribuntoContentHandler extend CodeContentHandler
Change-Id: I8d99ba9db7f804e898a74a47d9e4e02cac45e945
2016-07-26 00:38:47 +00:00
Brad Jorsch aa4d72e3ff Fix uncontroversial phpcs errors
The following continue to be ignored:
* Generic.Arrays.DisallowLongArraySyntax.Found, because I'm not sure
  Scribunto is ready to abandon old version support in master.
* MediaWiki.ControlStructures.AssignmentInControlStructures.AssignmentInControlStructures,
  because it's overly strict for its purpose.

Squiz.Classes.ValidClassName.NotCamelCaps isn't ignored globally, we
just ignore it explicitly every place it's needed.

Change-Id: I307668da6ef7b3e23da19b1fd1e08914239b99b3
2016-05-18 16:31:28 -04:00
Brad Jorsch dd0c6e7668 Use ParserOutput::getRawText() where available
This is unlikely to be a cause of the cache corruption since this isn't
calling setText() on any wikitext ParserOutputs, but let's fix it just
in case.

Bug: T124356
Change-Id: Ic34c654af86385dede843009d89df6f442ddc915
2016-01-25 12:39:23 -05:00
Ori Livneh f3558e489d When logging perf stats, include wfWikiId() in metric key
...so that modules are easily locatable in multi-wiki environments (like
Wikimedia's).

Change-Id: I60b9eb6177294eedceaacd5398545a30ad896f11
2015-10-29 20:53:06 -07:00
Ori Livneh a5d97eaa90 Make the percentile threshold for slow function stats configurable
Introduce $wgScribuntoSlowFunctionThreshold, which is a float value between 0
and 1 (defaults to 0.9), specifying the percentile threshold for slow function
invocation reporting.

Change-Id: I3bd862347c21ba68d2f2f0729a834c4f7be3cd43
2015-10-30 00:16:03 +00:00
Ori Livneh 605b5ed742 Keep stats on slow function calls
Report timing data for the top 1% of Lua function invocations, measured by CPU
time. Use the PSquare class from RunningStat (Ibbd3925aa) to keep an online
estimate of the 99th percentile without storing observations.

Depends on Ibbd3925aa (and on a follow-up patch to bump the RunningStat version
in core's composer.json.)

Change-Id: I0d39920733fe719f87698f03408698ed032c9849
2015-10-28 21:34:50 -07:00
Ori Livneh 930421d242 Add ScribuntoEngineBase::getResourceUsage()
Introduce a method, ScribuntoEngineBase::getResourceUsage(), which may be
overridden by script engine implementations to provide CPU and memory usage
data.

Change-Id: I6a4ed03c1261f43a7ce7de6f274c32c450e66abb
2015-10-29 03:59:07 +00:00
jenkins-bot 3cd5e80036 Merge "Add mw-scribunto-console placeholder to view source page" 2015-09-01 16:46:02 +00:00
Derk-Jan Hartman 7e5d5759b4 Add mw-scribunto-console placeholder to view source page
Add a placeholder in the HTML to have a more reliable position in the
HTML structure of the View source page.

Depends On: Ia03265a907212ee7bac1b839dcdd4d2f24c79bbe

Bug: T110050
Change-Id: I10ff67b359f04c0decd38fae750cc264e6bce50a
2015-09-01 16:37:41 +00:00
Derk-Jan Hartman 87bc426b6b Don't override other content added to the edit page
Per the comment in EditPage.php:
extensions should take care to _append_ to the present value

Change-Id: Icaf3f250b5f65768e50b7983b5f018c38a13490a
2015-08-24 22:38:46 +02:00
Brad Jorsch b630ecdd3a Re-restrict the Scribunto content handler to NS_MODULE
I94ae07bc arbitrarily removed this restriction, which seems liable to
result in confusion where non-Module-namespace pages can be marked as
modules but can't be #invoked.

Change-Id: Ia80f49d14b1f5cded0d3f5bffb6b450fb26cd986
2015-07-24 10:17:45 -04:00
Jackmcbarn bd5e46b941 Check content model instead of title
Make Scribunto compatible with storing content model in the database, by
checking for it directly instead of guessing it based on the title.

Change-Id: I94ae07bc47273fbf65d64b2909e5895c1c3fd7e9
2015-07-19 22:16:21 -04:00
Jackmcbarn ca7a84b5b2 Fix some PHPCS issues
Change-Id: I5a44d07553d45bc01db070c99856b35a3d275bd1
2015-06-30 13:14:58 -04:00
Kunal Mehta ddfd65b790 Replace deprecated wfRunHooks by Hooks::run
Change-Id: Ie6f3280aa740304a0dadd6d00ca388c5ad6a648e
2015-06-21 15:34:10 +00:00
Ori Livneh d426627c9b lint: 'if(' => 'if ('
Change-Id: I056ff6bbc5f992bddfd7e3bd82803de107651b80
2015-06-20 21:38:56 -07:00
Mormegil a5ea880567 Allow Lua console on protected module pages
Lua debugging console is useful even if the module page is protected,
so we should display it on read-only edit pages.

However, the `EditPage::showReadOnlyForm::initial` hook does not allow
to insert HTML below the textarea, so we let the JS do it client-side.
(In fact, it might be a good idea to do the same in the base case
and never send the HTML from server, I guess.)

Bug: T93902
Change-Id: I953c4313fc67c6e708b5ef68db5380991a75b363
2015-03-28 23:28:27 +01:00
Brad Jorsch 3d51662881 Rewrite error handling to avoid OutputPage::addInlineScript
This is apparently unofficially deprecated, and we can do things a bit
more straightforwardly by using ParserOutput::addJsConfigVars() to
communicate the error messages to the JS.

This also takes the opportunity to move "ext.scribunto", which is mostly
about errors, to "ext.scribunto.errors".

Bug: T75618
Change-Id: I1577dab2dab1bd79cb127879de141fdbb8963aeb
2015-03-16 16:08:44 -04:00
Chad Horohoe beb8b63683 Remove obvious function-level profiling
Change-Id: I94654fc0f72d0953c618a9e0a9b73f4a387df8b7
2015-02-12 11:53:18 -08:00
Thiemo Mättig 93579c7363 Add more comments and type hints
Change-Id: I8c4b91d3a6695cc33c9c3d3fb427af5412323ff7
2014-12-19 19:25:53 +00:00
Mr. Stradivarius 98f25aa9a1 Improve error messages in mw.html
Add more information to error messages in mw.html. This includes the
error level, the function name, and the position of the argument in the
argument list. Where possible, use the functions in libraryUtil.lua to
do this.

Some functions in mw.html accept multiple types, so add a checkTypeMulti
function to libraryUtil.lua to make these kinds of functions easy to check.
And while we're at it, add test cases for libraryUtil.lua as well.

Change-Id: If9cf9a52bd4b1bb42cc7f9f1f1096828710cbc52
2014-12-08 17:01:31 +00:00
jenkins-bot 398713b1a7 Merge "Use Parser::SFH_OBJECT_ARGS class const" 2014-11-18 20:30:06 +00:00
umherirrender 30c38929d2 Use Parser::SFH_OBJECT_ARGS class const
Instead of the global const

Change-Id: Iaf557f0f56964c8b545a4cd1582a852c12183def
2014-11-18 20:56:33 +01:00
Thiemo Mättig 55fe0b69d0 Add missing visibility keywords everywhere
Change-Id: I270d1dd9b6545e15398c2f8b8e9ae533844cc998
2014-11-14 10:10:23 +01:00
Brad Jorsch 9443fda132 Add i18n for API module help and mark ApiScribuntoConsole as internal
MediaWiki core change I04b1a384 added support for i18n of API module
help. This takes advantage of that while still maintaining backwards
compatibility with earlier versions of MediaWiki.

Once support for MediaWiki before 1.25 is dropped, the methods marked
deprecated in this patch may be removed.

Change-Id: I67395aff48185f3e09da31b51a08aa2541fe6a17
2014-11-03 21:10:19 +00:00
Thiemo Mättig d7c173b521 Add missing PHPDoc comments and type hints
There are like a billion things missing in the inline documentation
of this extension. Wow. This is what I can do for now.

Change-Id: I019c24d13cf5cb22dde4d710b86ef8f976e1ec96
2014-10-09 23:23:05 +02:00
jenkins-bot 1fa52ef583 Merge "Allow for dynamically-loaded PHP libraries" 2014-10-03 14:01:46 +00:00
Brad Jorsch df38a296bf Allow for dynamically-loaded PHP libraries
Scribunto currently supports libraries with PHP callbacks that are
loaded on startup, and pure-Lua libraries that may be loaded from the
module with require().

This change allows for libraries with PHP callbacks to also be loaded
with require().

Change-Id: Ibdc1f4ef51b1c8644c3d4c98d57755b5c06447a5
2014-10-03 09:27:23 -04:00
Jackmcbarn 9b0060c89a Remove "Allow saving code with errors"
This was never really a good idea. If you really want to save incomplete
code, you can put it all in a block comment. Since some modules may still
have errors from before this change, the tracking category for them has
not been removed.

Change-Id: Icb3da00a86b9773287dcd0c9277ad61446ec07ce
2014-09-30 04:05:12 +00:00
Yuri Astrakhan 66ac157c12 Use single quotes for <pre> (easier to read)
Change-Id: Ib666f56471fc8ea7dac36367c962788d1a304100
2014-09-21 22:51:46 -04:00
Jackmcbarn c5959b56e7 Display the full error message in wikitext
Instead of just displaying "Script error" in wikitext, display the actual
error string. Currently, many users don't see meaningful error messages
generated by modules, and instead just assume that "Script error" means
the module itself has a bug.

Bug: 71038
Change-Id: Ie5358049975352e0fef92088a06b97ad94717000
2014-09-19 12:11:38 +00:00
Jackmcbarn ece8cc5e82 Only set indexOffset when the function name is indexed
If a function name contains an equals sign, it doesn't increase the index,
so indexOffset=1 makes Lua see arguments as starting with 0. This change
fixes that, so that indexOffset is only set to 1 if the function name has
an index.

Change-Id: Ifa2dfad4d2f7228c3fd5721ccfc4c235576b663d
2014-09-06 15:42:13 -04:00
addshore e29c8eda63 Use public instead of var in classes
Change-Id: I0c059515cbf0fa8ef3846526a989f1a322fcd8ae
2014-08-17 22:11:26 +01:00
Jackmcbarn 2295009729 Add 2 tests to unitTestsList
Change-Id: I839515927e66a046d7b3e7b00d7d24efad3eacb5
2014-08-09 21:34:12 -04:00
Jackmcbarn 40b8bd2caa Add comments and remove trailing whitespace
Clean up trailing whitespace from all of our code, and add comments
indicating that apparently unused variables are ScopedCallbacks.

Change-Id: I8e5997797cc7b1c64c5351ec112a18f30edc8fef
2014-07-07 14:46:59 -04:00
Brad Jorsch c44d576b78 Update GeSHi integration
Idf4ad439 deprecated SyntaxHighlight_GeSHi::buildHeadItem in favor of
ResourceLoader. We may as well follow along.

To avoid breaking things if people don't update their
SyntaxHighlight_GeSHi in sync with Scribunto, test for the RL class used
in GeSHi's ResourceLoader integration and continue using buildHeadItem
if it's not found.

Change-Id: Id93530dce7c8c5a70a98fca58844adf9b5c6a23f
2014-07-03 14:50:50 -04:00
Jackmcbarn ec42679913 Show ScribuntoExceptions in content language
Messages from ScribuntoException are cached and stored with the page, so
they need to be output in the content language.

Change-Id: Ic8bd5cef2c49118ccb258592ca515c0e71f210e3
2014-06-28 17:59:05 -04:00
Reedy 4d0665dbd8 Parameter type hints
Change-Id: I3d578ab6fb65917ef0fa65767089b01ca7c4e96d
2014-06-18 18:19:07 +01:00