Anomie has uploaded a new change for review. https://gerrit.wikimedia.org/r/54872
Change subject: (bug 39655) Add Lua version info to Special:Version ...................................................................... (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 --- M Scribunto.php M common/Base.php M common/Hooks.php M engines/LuaSandbox/Engine.php M engines/LuaStandalone/LuaStandaloneEngine.php 5 files changed, 82 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto refs/changes/72/54872/1 diff --git a/Scribunto.php b/Scribunto.php index 0e6763f..b2f599d 100644 --- a/Scribunto.php +++ b/Scribunto.php @@ -45,6 +45,8 @@ $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'; diff --git a/common/Base.php b/common/Base.php index 03cf3a3..78a5bf4 100644 --- a/common/Base.php +++ b/common/Base.php @@ -54,6 +54,13 @@ abstract function runConsole( $params ); /** + * Get software information for Special:Version + * @param &$software array + * @return bool + */ + abstract public function getSoftwareInfo( &$software ); + + /** * Constructor. * * @param $options array Associative array of options: diff --git a/common/Hooks.php b/common/Hooks.php index 3e44585..f3ed105 100644 --- a/common/Hooks.php +++ b/common/Hooks.php @@ -25,6 +25,18 @@ */ 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 * @return bool diff --git a/engines/LuaSandbox/Engine.php b/engines/LuaSandbox/Engine.php index 1f957db..bb8ea1a 100644 --- a/engines/LuaSandbox/Engine.php +++ b/engines/LuaSandbox/Engine.php @@ -10,6 +10,24 @@ ); } + 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' ); diff --git a/engines/LuaStandalone/LuaStandaloneEngine.php b/engines/LuaStandalone/LuaStandaloneEngine.php index f656111..08fd2e5 100644 --- a/engines/LuaStandalone/LuaStandaloneEngine.php +++ b/engines/LuaStandalone/LuaStandaloneEngine.php @@ -59,6 +59,17 @@ 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 @@ 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 @@ $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" ); -- To view, visit https://gerrit.wikimedia.org/r/54872 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I912197efee0211066677c4d46e638fb546a410c6 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Scribunto Gerrit-Branch: master Gerrit-Owner: Anomie <bjor...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits