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 = '<div class="articleplaceholder-topimage">' .. 
renderedImage .. '</div>'
+    end
   end
-  return '<div class="articleplaceholder-topimage">' .. renderedImage .. 
'</div>'
+  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 0000000..e1970c1
--- /dev/null
+++ b/includes/Lua/Scribunto_LuaArticlePlaceholderLibrary.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace ArticlePlaceholder\Lua;
+
+use RuntimeException;
+use Scribunto_LuaLibraryBase;
+
+/**
+ * Registers and defines functions needed by the Lua modules
+ *
+ * @licence GNU GPL v2+
+ * @author Lucie-Aimée Kaffee
+ */
+class Scribunto_LuaArticlePlaceholderLibrary extends Scribunto_LuaLibraryBase {
+
+       /**
+        * @return string[]
+        */
+       public function getImageProperty() {
+               global $wgArticlePlaceholderImageProperty;
+               if (
+                       !is_string( $wgArticlePlaceholderImageProperty ) ||
+                       $wgArticlePlaceholderImageProperty === ''
+               ) {
+                       throw new RuntimeException( 'Bad value in 
$wgArticlePlaceholderImageProperty' );
+               }
+               return array( $wgArticlePlaceholderImageProperty );
+       }
+
+       /**
+        * @return array
+        */
+       public function register() {
+               // These functions will be exposed to the Lua module.
+               // They are member functions on a Lua table which is private to 
the module, thus
+               // these can't be called from user code, unless explicitly 
exposed in Lua.
+               $lib = array(
+                       'getImageProperty' => 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 @@
        <arg name="extensions" value="php,php5,inc"/>
        <arg name="encoding" value="utf8"/>
        <exclude-pattern>vendor</exclude-pattern>
+       <rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
+               
<exclude-pattern>Scribunto_LuaArticlePlaceholderLibrary</exclude-pattern>
+       </rule>
 </ruleset>

-- 
To view, visit https://gerrit.wikimedia.org/r/256439
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9ffb0ea1851a9a3c9a798ae83ce3ff7c3a616ad5
Gerrit-PatchSet: 20
Gerrit-Project: mediawiki/extensions/ArticlePlaceholder
Gerrit-Branch: master
Gerrit-Owner: Lucie Kaffee <lucie.kaf...@wikimedia.de>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com>
Gerrit-Reviewer: Lucie Kaffee <lucie.kaf...@wikimedia.de>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to