(bug 39655) Add Lua version info to Special:Version

Use the SoftwareInfo hook to add the versions of LuaSandbox and Lua to
Special:Version.

Bug: 39655
Change-Id: I912197efee0211066677c4d46e638fb546a410c6
This commit is contained in:
Brad Jorsch 2013-03-20 12:30:26 -04:00 committed by Gerrit Code Review
parent 47e826d082
commit 5989d28678
5 changed files with 82 additions and 0 deletions

View file

@ -45,6 +45,8 @@ $wgAutoloadClasses['ApiScribuntoConsole'] = $dir.'common/ApiScribuntoConsole.php
$wgAutoloadClasses['ScribuntoContentHandler'] = $dir.'common/ScribuntoContentHandler.php';
$wgAutoloadClasses['ScribuntoContent'] = $dir.'common/ScribuntoContent.php';
$wgHooks['SoftwareInfo'][] = 'ScribuntoHooks::getSoftwareInfo';
$wgHooks['ParserFirstCallInit'][] = 'ScribuntoHooks::setupParserHook';
$wgHooks['ParserLimitReport'][] = 'ScribuntoHooks::reportLimits';
$wgHooks['ParserClearState'][] = 'ScribuntoHooks::clearState';

View file

@ -53,6 +53,13 @@ abstract class ScribuntoEngineBase {
*/
abstract function runConsole( $params );
/**
* Get software information for Special:Version
* @param &$software array
* @return bool
*/
abstract public function getSoftwareInfo( &$software );
/**
* Constructor.
*

View file

@ -24,6 +24,18 @@
* Hooks for the Scribunto extension.
*/
class ScribuntoHooks {
/**
* Get software information for Special:Version
* @param &$software array
* @return bool
*/
public static function getSoftwareInfo( &$software ) {
$engine = Scribunto::newDefaultEngine();
$engine->setTitle( Title::makeTitle( NS_SPECIAL, 'Version' ) );
$engine->getSoftwareInfo( $software );
return true;
}
/**
* Register parser hooks.
* @param $parser Parser

View file

@ -10,6 +10,24 @@ class Scribunto_LuaSandboxEngine extends Scribunto_LuaEngine {
);
}
public function getSoftwareInfo( &$software ) {
if ( is_callable( 'LuaSandbox::getVersionInfo' ) ) {
$versions = LuaSandbox::getVersionInfo();
} else {
$sandbox = new LuaSandbox;
list( $luaver ) = $sandbox->loadString( 'return _VERSION' )->call();
$versions = array(
'LuaSandbox' => phpversion( "LuaSandbox" ),
'Lua' => $luaver,
);
}
$software['[https://www.mediawiki.org/wiki/Extension:Scribunto#LuaSandbox LuaSandbox]'] = $versions['LuaSandbox'];
$software['[http://www.lua.org/ Lua]'] = str_replace( 'Lua ', '', $versions['Lua'] );
if ( isset( $versions['LuaJIT'] ) ) {
$software['[http://luajit.org/ LuaJIT]'] = str_replace( 'LuaJIT ', '', $versions['LuaJIT'] );
}
}
public function getLimitReport() {
$this->load();
$lang = Language::factory( 'en' );

View file

@ -59,6 +59,17 @@ class Scribunto_LuaStandaloneEngine extends Scribunto_LuaEngine {
function newInterpreter() {
return new Scribunto_LuaStandaloneInterpreter( $this, $this->options );
}
public function getSoftwareInfo( &$software ) {
$ver = Scribunto_LuaStandaloneInterpreter::getLuaVersion( $this->options );
if ( $ver !== null ) {
if ( substr( $ver, 0, 6 ) === 'LuaJIT' ) {
$software['[http://luajit.org/ LuaJIT]'] = str_replace( 'LuaJIT ', '', $ver );
} else {
$software['[http://www.lua.org/ Lua]'] = str_replace( 'Lua ', '', $ver );
}
}
}
}
class Scribunto_LuaStandaloneInterpreter extends Scribunto_LuaInterpreter {
@ -68,9 +79,11 @@ class Scribunto_LuaStandaloneInterpreter extends Scribunto_LuaInterpreter {
if ( $options['errorFile'] === null ) {
$options['errorFile'] = wfGetNull();
}
if ( $options['luaPath'] === null ) {
$path = false;
// Note, if you alter these, also alter getLuaVersion() below
if ( PHP_OS == 'Linux' ) {
if ( PHP_INT_SIZE == 4 ) {
$path = 'lua5_1_5_linux_32_generic/lua';
@ -143,6 +156,36 @@ class Scribunto_LuaStandaloneInterpreter extends Scribunto_LuaInterpreter {
$this->terminate();
}
public static function getLuaVersion( $options ) {
if ( $options['luaPath'] === null ) {
// We know which versions are distributed, no need to run them.
if ( PHP_OS == 'Linux' ) {
return 'Lua 5.1.5';
} elseif ( PHP_OS == 'Windows' || PHP_OS == 'WINNT' || PHP_OS == 'Win32' ) {
return 'Lua 5.1.4';
} elseif ( PHP_OS == 'Darwin' ) {
return 'Lua 5.1.5';
} else {
return null;
}
}
// Ask the interpreter what version it is, using the "-v" option.
// The output is expected to be one line, something like these:
// Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
// LuaJIT 2.0.0 -- Copyright (C) 2005-2012 Mike Pall. http://luajit.org/
$cmd = wfEscapeShellArg( $options['luaPath'] ) . ' -v';
$handle = popen( $cmd, 'r' );
if ( $handle ) {
$ret = fgets( $handle, 80 );
pclose( $handle );
if( $ret && preg_match( '/^Lua(?:JIT)? \S+/', $ret, $m ) ) {
return $m[0];
}
}
return null;
}
public function terminate() {
if ( $this->proc ) {
wfDebug( __METHOD__.": terminating\n" );