Hoo man has uploaded a new change for review.
https://gerrit.wikimedia.org/r/163063
Change subject: Conditionally load mw.capiunto.Infobox._render
......................................................................
Conditionally load mw.capiunto.Infobox._render
Bug: 69540
Change-Id: Ib73cffd929e894820d80ca9a539d448994dade4b
---
M Capiunto.hooks.php
M Capiunto.php
M includes/LuaLibrary.php
M includes/lua/Infobox.lua
R includes/lua/pure/InfoboxRender.lua
M tests/phpunit/includes/lua/InfoboxRenderTests.lua
6 files changed, 26 insertions(+), 8 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Capiunto
refs/changes/63/163063/1
diff --git a/Capiunto.hooks.php b/Capiunto.hooks.php
index 70bd562..a4bfff7 100644
--- a/Capiunto.hooks.php
+++ b/Capiunto.hooks.php
@@ -39,6 +39,7 @@
// @codeCoverageIgnoreEnd
}
+
/**
* External Lua library for Scribunto
*
@@ -52,7 +53,24 @@
}
$extraLibraries['mw.capiunto.Infobox'] = '\Capiunto\LuaLibrary';
- $extraLibraries['mw.capiunto.Infobox._render'] =
'\Capiunto\LuaLibrary';
+
+ return true;
+ }
+
+ /**
+ * External Lua library paths for Scribunto
+ *
+ * @param string $engine
+ * @param array $extraLibraryPaths
+ * @return bool
+ */
+ public static function registerScribuntoExternalLibraryPaths( $engine,
array &$extraLibraryPaths ) {
+ if ( $engine !== 'lua' ) {
+ return true;
+ }
+
+ // Path containing pure Lua libraries that don't need to
interact with PHP
+ $extraLibraryPaths[] = __DIR__ . '/includes/lua/pure';
return true;
}
diff --git a/Capiunto.php b/Capiunto.php
index 8180e00..ae2e8f2 100644
--- a/Capiunto.php
+++ b/Capiunto.php
@@ -27,8 +27,8 @@
$wgAutoloadClasses['Capiunto\Test\InfoboxModuleTest'] = __DIR__ .
'/tests/phpunit/includes/lua/InfoboxTest.php';
$wgHooks['UnitTestsList'][] =
'\Capiunto\CapiuntoHooks::registerUnitTests';
-# XXX: Rather use ScribuntoExternalLibraryPaths ?
$wgHooks['ScribuntoExternalLibraries'][] =
'\Capiunto\CapiuntoHooks::registerScribuntoLibraries';
+$wgHooks['ScribuntoExternalLibraryPaths'][] =
'\Capiunto\CapiuntoHooks::registerScribuntoExternalLibraryPaths';
$wgHooks['BeforePageDisplay'][] =
'\Capiunto\CapiuntoHooks::onBeforePageDisplay';
$commonModuleInfo = array(
diff --git a/includes/LuaLibrary.php b/includes/LuaLibrary.php
index 0ff7575..c47f170 100644
--- a/includes/LuaLibrary.php
+++ b/includes/LuaLibrary.php
@@ -18,7 +18,6 @@
*/
public function register() {
$this->getEngine()->registerInterface( __DIR__ .
'/lua/Infobox.lua', array(), array() );
- $this->getEngine()->registerInterface( __DIR__ .
'/lua/InfoboxRender.lua', array(), array() );
}
}
diff --git a/includes/lua/Infobox.lua b/includes/lua/Infobox.lua
index afb4454..fb1acbd 100644
--- a/includes/lua/Infobox.lua
+++ b/includes/lua/Infobox.lua
@@ -52,6 +52,11 @@
function methodtable.getHtml( t )
local html = mw.html.create( '' )
local args = t.args
+
+ if mw.capiunto.Infobox._render == nil then
+ -- Only load the InfoboxRender lib if it's really needed
+ require( 'InfoboxRender' )
+ end
local render = mw.capiunto.Infobox._render
html = render.renderWrapper( html, args )
diff --git a/includes/lua/InfoboxRender.lua
b/includes/lua/pure/InfoboxRender.lua
similarity index 98%
rename from includes/lua/InfoboxRender.lua
rename to includes/lua/pure/InfoboxRender.lua
index bd67e3a..802c87d 100644
--- a/includes/lua/InfoboxRender.lua
+++ b/includes/lua/pure/InfoboxRender.lua
@@ -285,14 +285,10 @@
end
end
-mw_interface = nil
-
-- Register this module in the "mw.capiunto" global
mw = mw or {}
mw.capiunto = mw.capiunto or {}
mw.capiunto.Infobox = mw.capiunto.Infobox or {}
mw.capiunto.Infobox._render = render
-
-package.loaded['mw.capiunto.Infobox._render'] = render
return render
diff --git a/tests/phpunit/includes/lua/InfoboxRenderTests.lua
b/tests/phpunit/includes/lua/InfoboxRenderTests.lua
index 4f647e1..8715c97 100644
--- a/tests/phpunit/includes/lua/InfoboxRenderTests.lua
+++ b/tests/phpunit/includes/lua/InfoboxRenderTests.lua
@@ -6,7 +6,7 @@
]]
local testframework = require 'Module:TestFramework'
-local render = mw.capiunto.Infobox._render
+local render = require( 'InfoboxRender' )
local function testExists()
return type( mw.capiunto.Infobox._render )
--
To view, visit https://gerrit.wikimedia.org/r/163063
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib73cffd929e894820d80ca9a539d448994dade4b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Capiunto
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits