jenkins-bot has submitted this change and it was merged.
Change subject: Set the image Property id in configurations
..
Set the image Property id in configurations
Bug: T113957
Change-Id: I9ffb0ea1851a9a3c9a798ae83ce3ff7c3a616ad5
---
M ArticlePlaceholder.php
M includes/Hooks.php
M includes/Lua/EntityRenderer.lua
A includes/Lua/Scribunto_LuaArticlePlaceholderLibrary.php
M phpcs.xml
5 files changed, 86 insertions(+), 11 deletions(-)
Approvals:
Hoo man: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ArticlePlaceholder.php b/ArticlePlaceholder.php
index 84dfbd2..14d27cd 100644
--- a/ArticlePlaceholder.php
+++ b/ArticlePlaceholder.php
@@ -20,12 +20,18 @@
'descriptionmsg' => 'articleplaceholder-desc',
);
+$wgArticlePlaceholderImageProperty = 'P18';
+
$wgAutoloadClasses['ArticlePlaceholder\Specials\SpecialAboutTopic']
= __DIR__ . '/Specials/SpecialAboutTopic.php';
+$wgAutoloadClasses['ArticlePlaceholder\Lua\Scribunto_LuaArticlePlaceholderLibrary']
+ = __DIR__ . '/includes/Lua/Scribunto_LuaArticlePlaceholderLibrary.php';
$wgAutoloadClasses['ArticlePlaceholder\Hooks'] = __DIR__ .
'/includes/Hooks.php';
$wgAutoloadClasses['ArticlePlaceholder\SearchHookHandler']
= __DIR__ . '/includes/SearchHookHandler.php';
+$wgHooks['ScribuntoExternalLibraries'][]
+ = '\ArticlePlaceholder\Hooks::onScribuntoExternalLibraries';
$wgHooks['ScribuntoExternalLibraryPaths'][]
= '\ArticlePlaceholder\Hooks::registerScribuntoExternalLibraryPaths';
$wgHooks['SpecialSearchResultsAppend'][]
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 3874699..c8f40f2 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -11,6 +11,27 @@
class Hooks {
/**
+* External Lua libraries for Scribunto
+*
+* @param string $engine
+* @param array &$extraLibraryPaths
+*
+* @return bool
+*/
+ public static function onScribuntoExternalLibraries(
+ $engine,
+ array &$extraLibraries
+ ) {
+ if ( $engine === 'lua' ) {
+ $extraLibraries['EntityRenderer'] = array(
+ 'class' =>
'ArticlePlaceholder\Lua\Scribunto_LuaArticlePlaceholderLibrary',
+ 'deferLoad' => true,
+ );
+ }
+ return true;
+ }
+
+ /**
* External Lua library paths for Scribunto
*
* @param string $engine
@@ -22,13 +43,9 @@
$engine,
array &$extraLibraryPaths
) {
- if ( $engine !== 'lua' ) {
- return true;
+ if ( $engine === 'lua' ) {
+ $extraLibraryPaths[] = __DIR__ . '/Lua';
}
-
- // Path containing pure Lua libraries that don't need to
interact with PHP
- $extraLibraryPaths[] = __DIR__ . '/Lua';
-
return true;
}
diff --git a/includes/Lua/EntityRenderer.lua b/includes/Lua/EntityRenderer.lua
index 7ad8490..863dd6a 100644
--- a/includes/Lua/EntityRenderer.lua
+++ b/includes/Lua/EntityRenderer.lua
@@ -6,8 +6,9 @@
local entityrenderer = {}
local util = require( 'libraryUtil' )
+local php = mw_interface
-entityrenderer.imageProperty = 'P6'
+entityrenderer.imageProperty = php.getImageProperty()
local identifierProperties = require( 'Identifier' )
-- Get the datavalue for a given property.
@@ -200,11 +201,14 @@
-- @return String renderedImage
local topImageRenderer = function( entity, propertyId, orientationImage )
local renderedImage = ''
- local imageName = entity:formatPropertyValues( propertyId ).value
- if imageName ~= '' and imageName ~= nil then
-renderedImage = '[[File:' .. imageName .. '|thumb|' .. orientationImage ..
']]'
+ if propertyId ~= nil then
+local imageName = entity:formatPropertyValues( propertyId ).value
+if imageName ~= nil and imageName ~= '' then
+ renderedImage = '[[File:' .. imageName .. '|thumb|' .. orientationImage
.. ']]'
+ renderedImage = '' ..
renderedImage .. ''
+end
end
- return '' .. renderedImage ..
''
+ return renderedImage
end
-- Render the description.
diff --git a/includes/Lua/Scribunto_LuaArticlePlaceholderLibrary.php
b/includes/Lua/Scribunto_LuaArticlePlaceholderLibrary.php
new file mode 100644
index 000..e1970c1
--- /dev/null
+++ b/includes/Lua/Scribunto_LuaArticlePlaceholderLibrary.php
@@ -0,0 +1,45 @@
+ array( $this, 'getImageProperty'
),
+ );
+
+ return $this->getEngine()->registerInterface(
+ __DIR__ . '/EntityRenderer.lua', $lib, array()
+ );
+ }
+}
diff --git a/phpcs.xml b/phpcs.xml
index d81a292..409f3eb 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -5,4 +5,7 @@
vendor
+
+