2012-01-28 16:22:18 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Wikitext scripting infrastructure for MediaWiki: hooks.
|
|
|
|
* Copyright (C) 2009-2012 Victor Vasiliev <vasilvv@gmail.com>
|
|
|
|
* http://www.mediawiki.org/
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2012-04-06 05:04:30 +00:00
|
|
|
* Hooks for the Scribunto extension.
|
2012-01-28 16:22:18 +00:00
|
|
|
*/
|
2012-04-06 05:04:30 +00:00
|
|
|
class ScribuntoHooks {
|
2012-01-28 16:22:18 +00:00
|
|
|
/**
|
|
|
|
* Register parser hooks.
|
|
|
|
* @param $parser Parser
|
|
|
|
*/
|
|
|
|
public static function setupParserHook( &$parser ) {
|
2012-04-06 05:04:30 +00:00
|
|
|
$parser->setFunctionHook( 'invoke', 'ScribuntoHooks::callHook', SFH_OBJECT_ARGS );
|
|
|
|
$parser->setFunctionHook( 'script', 'ScribuntoHooks::transcludeHook', SFH_NO_HASH | SFH_OBJECT_ARGS );
|
2012-01-28 16:22:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-04 06:10:32 +00:00
|
|
|
* Called when the interpreter is to be reset.
|
2012-01-28 16:22:18 +00:00
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @param $parser Parser
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function clearState( &$parser ) {
|
2012-04-06 05:04:30 +00:00
|
|
|
Scribunto::resetParserEngine( $parser );
|
2012-01-28 16:22:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-04 06:10:32 +00:00
|
|
|
* Hook function for {{#invoke:module|func}}
|
2012-01-28 16:46:15 +00:00
|
|
|
*
|
|
|
|
* @param $parser Parser
|
|
|
|
* @param $frame PPFrame
|
|
|
|
* @param $args array
|
2012-01-28 16:22:18 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function callHook( &$parser, $frame, $args ) {
|
|
|
|
if( count( $args ) < 2 ) {
|
2012-04-06 05:04:30 +00:00
|
|
|
throw new ScribuntoException( 'scribunto-common-nofunction' );
|
2012-01-28 16:22:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$module = $parser->mStripState->unstripBoth( array_shift( $args ) );
|
|
|
|
$function = $frame->expand( array_shift( $args ) );
|
|
|
|
return self::doRunHook( $parser, $frame, $module, $function, $args );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-04 06:10:32 +00:00
|
|
|
* Hook function for {{script:module}}
|
2012-01-28 16:46:15 +00:00
|
|
|
*
|
|
|
|
* @param $parser Parser
|
|
|
|
* @param $frame PPFrame
|
|
|
|
* @param $args
|
2012-01-28 16:22:18 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function transcludeHook( &$parser, $frame, $args ) {
|
|
|
|
$module = $parser->mStripState->unstripBoth( array_shift( $args ) );
|
|
|
|
return self::doRunHook( $parser, $frame, $module, 'main', $args );
|
|
|
|
}
|
|
|
|
|
2012-01-28 16:46:15 +00:00
|
|
|
/**
|
|
|
|
* @param $parser Parser
|
|
|
|
* @param $frame PPFrame
|
2012-04-05 07:58:02 +00:00
|
|
|
* @param $moduleName
|
|
|
|
* @param $functionName
|
2012-01-28 16:46:15 +00:00
|
|
|
* @param $args
|
|
|
|
* @return string
|
2012-04-06 05:04:30 +00:00
|
|
|
* @throws ScribuntoException
|
2012-01-28 16:46:15 +00:00
|
|
|
*/
|
2012-04-05 07:58:02 +00:00
|
|
|
private static function doRunHook( $parser, $frame, $moduleName, $functionName, $args ) {
|
2012-01-28 16:22:18 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2012-04-05 07:58:02 +00:00
|
|
|
|
2012-01-28 16:22:18 +00:00
|
|
|
try {
|
2012-04-06 05:04:30 +00:00
|
|
|
$engine = Scribunto::getParserEngine( $parser );
|
2012-04-05 07:58:02 +00:00
|
|
|
$title = Title::makeTitleSafe( NS_MODULE, $moduleName );
|
|
|
|
if ( !$title ) {
|
2012-04-06 05:04:30 +00:00
|
|
|
throw new ScribuntoException( 'scribunto-common-nosuchmodule' );
|
2012-01-28 16:22:18 +00:00
|
|
|
}
|
2012-04-05 07:58:02 +00:00
|
|
|
$module = $engine->fetchModuleFromParser( $title );
|
Added more Lua environment features
Package library:
* Added a simulation of the Lua 5.1 package library.
* Removed mw.import(), replaced it with a package loader. Packages can be
retrieved from the wiki, using require('Module:Foo'), or from files
distributed with Scribunto, using require('foo'). The "Module:" prefix allows
for source compatibility with existing Lua code.
* Added a couple of libraries from LuaForge: luabit and stringtools.
* Made fetchModuleFromParser() return null on error instead of throwing an
exception, to more easily support the desired behaviour of the package loader,
which needs to return null on error.
* Renamed mw.setupEnvironment() to mw.setup() since it is setting up things
other than the environment now.
* In MWServer:handleRegisterLibrary(), remove the feature which interprets dots
in library names, since LuaSandbox doesn't support this.
Improved module isolation and related refactoring:
* Expose restricted versions of getfenv() and setfenv() to user Lua code.
Requires luasandbox r114952.
* Don't cache the export list returned by module execution for later function
calls. This breaks isolation of #invoke calls, since the local variables are
persistent.
* Removed ScribuntoFunctionBase and its children, since it doesn't really have
a purpose if it can't cache anything. Instead, invoke functions using a module
method called invoke().
* Removed Module::initialize(), replaced it with a validate() function. This is
a more elegant interface and works better with the new module caching scheme.
* Use a Status object for the return value of Engine::validate() instead of an
array. Use the formatting facilities of the Status class.
Other:
* Removed "too many returns" error, doesn't fit in with Lua conventions.
* Use the standalone engine by default, so that the extension will work without
configuration for more people.
* Added an accessor for $engine->interpreter
* Fix mw.clone() to correctly clone metatables
* If the standalone interpreter exits due to an error, there are some contexts
where the initial error will be caught and ignored, and the user will see the
error from checkValid() instead. In this case, rethrow the original error for
a more informative message.
* Load mw.lua into the initial standalone environment, to reduce code
duplication between mw.lua and MWServer.lua.
* Fixed a bug in Scribunto_LuaStandaloneInterpreter::handleCall() for functions
that return no results.
* Fixed a bug in encodeLuaVar() for strings with "\r". Added test case.
* In MWServer.lua, don't call error() for internal errors, instead just print
the error and exit. This avoids a protocol violation when an error is
encountered from within handleCall().
* Added lots of documentation. Lua doc comments are in LuaDoc format.
Change-Id: Ie2fd572c362bedf02f45d3fa5352a5280e034740
2012-04-18 03:46:18 +00:00
|
|
|
if ( !$module ) {
|
|
|
|
throw new ScribuntoException( 'scribunto-common-nosuchmodule' );
|
2012-04-05 07:58:02 +00:00
|
|
|
}
|
|
|
|
foreach( $args as &$arg ) {
|
|
|
|
$arg = $frame->expand( $arg );
|
2012-01-28 16:22:18 +00:00
|
|
|
}
|
Added more Lua environment features
Package library:
* Added a simulation of the Lua 5.1 package library.
* Removed mw.import(), replaced it with a package loader. Packages can be
retrieved from the wiki, using require('Module:Foo'), or from files
distributed with Scribunto, using require('foo'). The "Module:" prefix allows
for source compatibility with existing Lua code.
* Added a couple of libraries from LuaForge: luabit and stringtools.
* Made fetchModuleFromParser() return null on error instead of throwing an
exception, to more easily support the desired behaviour of the package loader,
which needs to return null on error.
* Renamed mw.setupEnvironment() to mw.setup() since it is setting up things
other than the environment now.
* In MWServer:handleRegisterLibrary(), remove the feature which interprets dots
in library names, since LuaSandbox doesn't support this.
Improved module isolation and related refactoring:
* Expose restricted versions of getfenv() and setfenv() to user Lua code.
Requires luasandbox r114952.
* Don't cache the export list returned by module execution for later function
calls. This breaks isolation of #invoke calls, since the local variables are
persistent.
* Removed ScribuntoFunctionBase and its children, since it doesn't really have
a purpose if it can't cache anything. Instead, invoke functions using a module
method called invoke().
* Removed Module::initialize(), replaced it with a validate() function. This is
a more elegant interface and works better with the new module caching scheme.
* Use a Status object for the return value of Engine::validate() instead of an
array. Use the formatting facilities of the Status class.
Other:
* Removed "too many returns" error, doesn't fit in with Lua conventions.
* Use the standalone engine by default, so that the extension will work without
configuration for more people.
* Added an accessor for $engine->interpreter
* Fix mw.clone() to correctly clone metatables
* If the standalone interpreter exits due to an error, there are some contexts
where the initial error will be caught and ignored, and the user will see the
error from checkValid() instead. In this case, rethrow the original error for
a more informative message.
* Load mw.lua into the initial standalone environment, to reduce code
duplication between mw.lua and MWServer.lua.
* Fixed a bug in Scribunto_LuaStandaloneInterpreter::handleCall() for functions
that return no results.
* Fixed a bug in encodeLuaVar() for strings with "\r". Added test case.
* In MWServer.lua, don't call error() for internal errors, instead just print
the error and exit. This avoids a protocol violation when an error is
encountered from within handleCall().
* Added lots of documentation. Lua doc comments are in LuaDoc format.
Change-Id: Ie2fd572c362bedf02f45d3fa5352a5280e034740
2012-04-18 03:46:18 +00:00
|
|
|
$result = $module->invoke( $functionName, $args, $frame );
|
2012-01-28 16:22:18 +00:00
|
|
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
2012-04-04 06:10:32 +00:00
|
|
|
return trim( strval( $result ) );
|
2012-04-06 05:04:30 +00:00
|
|
|
} catch( ScribuntoException $e ) {
|
2012-04-23 11:36:13 +00:00
|
|
|
$trace = $e->getScriptTraceHtml( array( 'msgOptions' => array( 'content' ) ) );
|
|
|
|
$html = Html::element( 'p', array(), $e->getMessage() );
|
|
|
|
if ( $trace !== false ) {
|
|
|
|
$html .= Html::element( 'p', array(), wfMsgForContent( 'scribunto-common-backtrace' ) ) . $trace;
|
|
|
|
}
|
|
|
|
$out = $parser->getOutput();
|
|
|
|
if ( !isset( $out->scribunto_errors ) ) {
|
|
|
|
$out->addOutputHook( 'ScribuntoError' );
|
|
|
|
$out->scribunto_errors = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$out->scribunto_errors[] = $html;
|
|
|
|
$id = 'mw-scribunto-error-' . ( count( $out->scribunto_errors ) - 1 );
|
|
|
|
$parserError = wfMsgForContent( 'scribunto-parser-error' );
|
2012-01-28 16:22:18 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2012-04-23 11:36:13 +00:00
|
|
|
|
|
|
|
// #iferror-compatible error element
|
|
|
|
return "<strong class=\"error\"><span class=\"scribunto-error\" id=\"$id\">" .
|
|
|
|
$parserError. "</span></strong>";
|
2012-01-28 16:22:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overrides the standard view for modules. Enables syntax highlighting when
|
|
|
|
* possible.
|
2012-01-28 16:46:15 +00:00
|
|
|
*
|
|
|
|
* @param $text string
|
|
|
|
* @param $title Title
|
|
|
|
* @param $output OutputPage
|
2012-01-28 16:22:18 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function handleScriptView( $text, $title, $output ) {
|
2012-04-06 05:04:30 +00:00
|
|
|
global $wgScribuntoUseGeSHi;
|
2012-01-28 16:22:18 +00:00
|
|
|
|
|
|
|
if( $title->getNamespace() == NS_MODULE ) {
|
2012-04-06 05:04:30 +00:00
|
|
|
$engine = Scribunto::newDefaultEngine();
|
2012-04-05 07:58:02 +00:00
|
|
|
$language = $engine->getGeSHiLanguage();
|
2012-01-28 16:22:18 +00:00
|
|
|
|
2012-04-06 05:04:30 +00:00
|
|
|
if( $wgScribuntoUseGeSHi && $language ) {
|
2012-01-28 16:22:18 +00:00
|
|
|
$geshi = SyntaxHighlight_GeSHi::prepare( $text, $language );
|
|
|
|
$geshi->set_language( $language );
|
|
|
|
if( $geshi instanceof GeSHi && !$geshi->error() ) {
|
|
|
|
$code = $geshi->parse_code();
|
|
|
|
if( $code ) {
|
|
|
|
$output->addHeadItem( "source-{$language}", SyntaxHighlight_GeSHi::buildHeadItem( $geshi ) );
|
|
|
|
$output->addHTML( "<div dir=\"ltr\">{$code}</div>" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No GeSHi, or GeSHi can't parse it, use plain <pre>
|
|
|
|
$output->addHTML( "<pre class=\"mw-code mw-script\" dir=\"ltr\">\n" );
|
|
|
|
$output->addHTML( htmlspecialchars( $text ) );
|
|
|
|
$output->addHTML( "\n</pre>\n" );
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-02-06 22:14:47 +00:00
|
|
|
|
2012-04-05 07:58:02 +00:00
|
|
|
public static function getCodeLanguage( $title, &$lang ) {
|
2012-04-06 05:04:30 +00:00
|
|
|
global $wgScribuntoUseCodeEditor;
|
|
|
|
if( $wgScribuntoUseCodeEditor && $title->getNamespace() == NS_MODULE ) {
|
|
|
|
$engine = Scribunto::newDefaultEngine();
|
2012-02-06 22:14:47 +00:00
|
|
|
if( $engine->getCodeEditorLanguage() ) {
|
|
|
|
$lang = $engine->getCodeEditorLanguage();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-01-28 16:22:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates that modules are not wikitext.
|
2012-01-28 16:46:15 +00:00
|
|
|
* @param $title Title
|
|
|
|
* @param $result
|
|
|
|
* @return bool
|
2012-01-28 16:22:18 +00:00
|
|
|
*/
|
|
|
|
public static function isWikitextPage( $title, &$result ) {
|
|
|
|
if( $title->getNamespace() == NS_MODULE ) {
|
|
|
|
$result = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds report of number of evaluations by the single wikitext page.
|
|
|
|
*
|
2012-01-28 16:46:15 +00:00
|
|
|
* @param $parser Parser
|
|
|
|
* @param $report
|
2012-01-28 16:22:18 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function reportLimits( $parser, &$report ) {
|
2012-04-13 10:38:12 +00:00
|
|
|
if ( Scribunto::isParserEnginePresent( $parser ) ) {
|
|
|
|
$engine = Scribunto::getParserEngine( $parser );
|
|
|
|
$report .= $engine->getLimitReport();
|
|
|
|
}
|
2012-01-28 16:22:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the module namespaces.
|
|
|
|
*/
|
|
|
|
public static function addCanonicalNamespaces( &$list ) {
|
|
|
|
$list[NS_MODULE] = 'Module';
|
|
|
|
$list[NS_MODULE_TALK] = 'Module_talk';
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function validateScript( $editor, $text, $section, &$error ) {
|
2012-04-23 11:36:13 +00:00
|
|
|
global $wgUser, $wgOut, $wgScribuntoUseCodeEditor;
|
2012-01-28 16:22:18 +00:00
|
|
|
$title = $editor->mTitle;
|
|
|
|
|
|
|
|
if( $title->getNamespace() == NS_MODULE ) {
|
2012-04-06 05:04:30 +00:00
|
|
|
$engine = Scribunto::newDefaultEngine();
|
2012-04-23 11:36:13 +00:00
|
|
|
$engine->setTitle( $title );
|
Added more Lua environment features
Package library:
* Added a simulation of the Lua 5.1 package library.
* Removed mw.import(), replaced it with a package loader. Packages can be
retrieved from the wiki, using require('Module:Foo'), or from files
distributed with Scribunto, using require('foo'). The "Module:" prefix allows
for source compatibility with existing Lua code.
* Added a couple of libraries from LuaForge: luabit and stringtools.
* Made fetchModuleFromParser() return null on error instead of throwing an
exception, to more easily support the desired behaviour of the package loader,
which needs to return null on error.
* Renamed mw.setupEnvironment() to mw.setup() since it is setting up things
other than the environment now.
* In MWServer:handleRegisterLibrary(), remove the feature which interprets dots
in library names, since LuaSandbox doesn't support this.
Improved module isolation and related refactoring:
* Expose restricted versions of getfenv() and setfenv() to user Lua code.
Requires luasandbox r114952.
* Don't cache the export list returned by module execution for later function
calls. This breaks isolation of #invoke calls, since the local variables are
persistent.
* Removed ScribuntoFunctionBase and its children, since it doesn't really have
a purpose if it can't cache anything. Instead, invoke functions using a module
method called invoke().
* Removed Module::initialize(), replaced it with a validate() function. This is
a more elegant interface and works better with the new module caching scheme.
* Use a Status object for the return value of Engine::validate() instead of an
array. Use the formatting facilities of the Status class.
Other:
* Removed "too many returns" error, doesn't fit in with Lua conventions.
* Use the standalone engine by default, so that the extension will work without
configuration for more people.
* Added an accessor for $engine->interpreter
* Fix mw.clone() to correctly clone metatables
* If the standalone interpreter exits due to an error, there are some contexts
where the initial error will be caught and ignored, and the user will see the
error from checkValid() instead. In this case, rethrow the original error for
a more informative message.
* Load mw.lua into the initial standalone environment, to reduce code
duplication between mw.lua and MWServer.lua.
* Fixed a bug in Scribunto_LuaStandaloneInterpreter::handleCall() for functions
that return no results.
* Fixed a bug in encodeLuaVar() for strings with "\r". Added test case.
* In MWServer.lua, don't call error() for internal errors, instead just print
the error and exit. This avoids a protocol violation when an error is
encountered from within handleCall().
* Added lots of documentation. Lua doc comments are in LuaDoc format.
Change-Id: Ie2fd572c362bedf02f45d3fa5352a5280e034740
2012-04-18 03:46:18 +00:00
|
|
|
$status = $engine->validate( $text, $title->getPrefixedDBkey() );
|
|
|
|
if( $status->isOK() ) {
|
2012-01-28 16:22:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Added more Lua environment features
Package library:
* Added a simulation of the Lua 5.1 package library.
* Removed mw.import(), replaced it with a package loader. Packages can be
retrieved from the wiki, using require('Module:Foo'), or from files
distributed with Scribunto, using require('foo'). The "Module:" prefix allows
for source compatibility with existing Lua code.
* Added a couple of libraries from LuaForge: luabit and stringtools.
* Made fetchModuleFromParser() return null on error instead of throwing an
exception, to more easily support the desired behaviour of the package loader,
which needs to return null on error.
* Renamed mw.setupEnvironment() to mw.setup() since it is setting up things
other than the environment now.
* In MWServer:handleRegisterLibrary(), remove the feature which interprets dots
in library names, since LuaSandbox doesn't support this.
Improved module isolation and related refactoring:
* Expose restricted versions of getfenv() and setfenv() to user Lua code.
Requires luasandbox r114952.
* Don't cache the export list returned by module execution for later function
calls. This breaks isolation of #invoke calls, since the local variables are
persistent.
* Removed ScribuntoFunctionBase and its children, since it doesn't really have
a purpose if it can't cache anything. Instead, invoke functions using a module
method called invoke().
* Removed Module::initialize(), replaced it with a validate() function. This is
a more elegant interface and works better with the new module caching scheme.
* Use a Status object for the return value of Engine::validate() instead of an
array. Use the formatting facilities of the Status class.
Other:
* Removed "too many returns" error, doesn't fit in with Lua conventions.
* Use the standalone engine by default, so that the extension will work without
configuration for more people.
* Added an accessor for $engine->interpreter
* Fix mw.clone() to correctly clone metatables
* If the standalone interpreter exits due to an error, there are some contexts
where the initial error will be caught and ignored, and the user will see the
error from checkValid() instead. In this case, rethrow the original error for
a more informative message.
* Load mw.lua into the initial standalone environment, to reduce code
duplication between mw.lua and MWServer.lua.
* Fixed a bug in Scribunto_LuaStandaloneInterpreter::handleCall() for functions
that return no results.
* Fixed a bug in encodeLuaVar() for strings with "\r". Added test case.
* In MWServer.lua, don't call error() for internal errors, instead just print
the error and exit. This avoids a protocol violation when an error is
encountered from within handleCall().
* Added lots of documentation. Lua doc comments are in LuaDoc format.
Change-Id: Ie2fd572c362bedf02f45d3fa5352a5280e034740
2012-04-18 03:46:18 +00:00
|
|
|
$errmsg = $status->getWikiText( 'scribunto-error-short', 'scribunto-error-long' );
|
2012-04-23 11:36:13 +00:00
|
|
|
$error = <<<WIKI
|
2012-01-28 16:22:18 +00:00
|
|
|
<div class="errorbox">
|
|
|
|
{$errmsg}
|
|
|
|
</div>
|
|
|
|
<br clear="all" />
|
2012-04-23 11:36:13 +00:00
|
|
|
WIKI;
|
|
|
|
if ( isset( $status->scribunto_error->params['module'] ) ) {
|
|
|
|
$module = $status->scribunto_error->params['module'];
|
|
|
|
$line = $status->scribunto_error->params['line'];
|
|
|
|
if ( $module === $title->getPrefixedDBkey() && preg_match( '/^\d+$/', $line ) ) {
|
|
|
|
$wgOut->addInlineScript( 'window.location.hash = ' . Xml::encodeJsVar( "#mw-ce-l$line" ) );
|
|
|
|
}
|
|
|
|
}
|
2012-01-28 16:22:18 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-01-28 16:46:15 +00:00
|
|
|
|
2012-01-28 16:22:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
Added tests and fixed bugs
* Added unit tests for the two Lua interpreter classes
* Fixed a bug in checkType()
* Have Scribunto_LuaSandboxInterpreter throw an exception on construct
when the extension doesn't exist, to match the standalone behaviour.
* In Scribunto_LuaSandboxInterpreter, removed debugging statements
accidentally left in.
* Convert LuaSandboxTimeoutError to the appropriate common error
message.
* Moved the option munging from the sandbox engine to the interpreter,
so that the interpreter can be unit tested separately.
* Use /bin/sh instead of bash for lua_ulimit.sh, since dash is smaller
and still supports ulimit.
* Use exec to run the lua binary, so that the vsize of the shell doesn't
add to the memory limit.
* Added a quit function to the standalone interpreter. Unused at present.
* Don't add a comma after the last element of a table in a Lua
expression.
* Make the SIGXCPU detection work: proc_open() runs the command via a
shell, which reports signals in the child via the exit status, so
proc_get_status() will never return a valid termsig element.
* In MWServer:call(), fixed a bug causing the return values to be
wrapped in an array.
* Fixed a misunderstanding of what select() does.
* In MWServer:getStatus(), fixed indexes so that vsize will be correct.
Removed RSS, since it wasn't used anyway and turns out to be measured
in multiples of the page size, and I couldn't be bothered trying to
fetch that from getconf. Return the PID and vsize as numbers rather
than strings.
* Added a simple table dump feature to MWServer:debug().
* Fixed brackets in MWServer:tostring().
* Added missing Linux 32-bit binary.
Change-Id: Ibf5f4656b1c0a9f81287d363184c3fe9d2abdafd
2012-04-16 04:41:08 +00:00
|
|
|
|
|
|
|
public static function unitTestsList( &$files ) {
|
2012-04-19 07:40:56 +00:00
|
|
|
$tests = array(
|
|
|
|
'engines/LuaStandalone/LuaStandaloneInterpreterTest.php',
|
|
|
|
'engines/LuaStandalone/LuaStandaloneEngineTest.php',
|
|
|
|
'engines/LuaSandbox/LuaSandboxInterpreterTest.php',
|
|
|
|
'engines/LuaSandbox/LuaSandboxEngineTest.php' );
|
|
|
|
foreach ( $tests as $test ) {
|
|
|
|
$files[] = dirname( __FILE__ ) .'/../tests/' . $test;
|
|
|
|
}
|
Added tests and fixed bugs
* Added unit tests for the two Lua interpreter classes
* Fixed a bug in checkType()
* Have Scribunto_LuaSandboxInterpreter throw an exception on construct
when the extension doesn't exist, to match the standalone behaviour.
* In Scribunto_LuaSandboxInterpreter, removed debugging statements
accidentally left in.
* Convert LuaSandboxTimeoutError to the appropriate common error
message.
* Moved the option munging from the sandbox engine to the interpreter,
so that the interpreter can be unit tested separately.
* Use /bin/sh instead of bash for lua_ulimit.sh, since dash is smaller
and still supports ulimit.
* Use exec to run the lua binary, so that the vsize of the shell doesn't
add to the memory limit.
* Added a quit function to the standalone interpreter. Unused at present.
* Don't add a comma after the last element of a table in a Lua
expression.
* Make the SIGXCPU detection work: proc_open() runs the command via a
shell, which reports signals in the child via the exit status, so
proc_get_status() will never return a valid termsig element.
* In MWServer:call(), fixed a bug causing the return values to be
wrapped in an array.
* Fixed a misunderstanding of what select() does.
* In MWServer:getStatus(), fixed indexes so that vsize will be correct.
Removed RSS, since it wasn't used anyway and turns out to be measured
in multiples of the page size, and I couldn't be bothered trying to
fetch that from getconf. Return the PID and vsize as numbers rather
than strings.
* Added a simple table dump feature to MWServer:debug().
* Fixed brackets in MWServer:tostring().
* Added missing Linux 32-bit binary.
Change-Id: Ibf5f4656b1c0a9f81287d363184c3fe9d2abdafd
2012-04-16 04:41:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-23 11:36:13 +00:00
|
|
|
public static function parserOutputHook( $outputPage, $parserOutput ) {
|
|
|
|
$outputPage->addModules( 'ext.scribunto' );
|
|
|
|
$outputPage->addInlineScript( 'mw.loader.using("ext.scribunto", function() {' .
|
|
|
|
Xml::encodeJsCall( 'mw.scribunto.setErrors', array( $parserOutput->scribunto_errors ) )
|
|
|
|
. '});' );
|
|
|
|
}
|
2012-01-28 16:22:18 +00:00
|
|
|
}
|