[MediaWiki-commits] [Gerrit] Set the image Property id in configurations - change (mediawiki...ArticlePlaceholder)

2016-01-04 Thread jenkins-bot (Code Review)
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
+   
+   

[MediaWiki-commits] [Gerrit] Set the image Property id in configurations - change (mediawiki...ArticlePlaceholder)

2015-12-02 Thread Lucie Kaffee (Code Review)
Lucie Kaffee has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/256439

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 Specials/SpecialAboutTopic.php
M includes/Hooks.php
A includes/Lua/Scribunto_LuaArticlePlaceholderLibrary.php
4 files changed, 80 insertions(+), 11 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ArticlePlaceholder 
refs/changes/39/256439/1

diff --git a/ArticlePlaceholder.php b/ArticlePlaceholder.php
index 3d156ad..e2ea0e1 100644
--- a/ArticlePlaceholder.php
+++ b/ArticlePlaceholder.php
@@ -22,11 +22,15 @@
 
 $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['ScribuntoExternalLibraryPaths'][]
+$wgHooks['ScribuntoExternalLibraries'][]
+   = '\ArticlePlaceholder\Hooks::onScribuntoExternalLibraries';
+$wgHooks['ScribuntoExternalLibraryPath'][]
= '\ArticlePlaceholder\Hooks::registerScribuntoExternalLibraryPaths';
 $wgHooks['SpecialSearchResultsAppend'][]
= '\ArticlePlaceholder\SearchHookHandler::onSpecialSearchResultsAppend';
diff --git a/Specials/SpecialAboutTopic.php b/Specials/SpecialAboutTopic.php
index b0c5169..dc342b6 100644
--- a/Specials/SpecialAboutTopic.php
+++ b/Specials/SpecialAboutTopic.php
@@ -325,9 +325,6 @@
 
if ( isset( $sitelinksTitles[0][1] ) ) {
$sitelinkTitle = $sitelinkTitles[0][1];
-   }
-
-   if ( $sitelinkTitle !== null ) {
return $this->titleFactory->newFromText( $sitelinkTitle 
)->getLinkURL();
}
 
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 3874699..55ffc3d 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -18,17 +18,31 @@
 *
 * @return bool
 */
+   public static function onScribuntoExternalLibraries(
+   $engine,
+   array &$extraLibraries
+   ) {
+   if ( $engine == 'lua' ) {
+   $extraLibraries['EntityRenderer'] = 
'ArticlePlaceholder\Lua\Scribunto_LuaArticlePlaceholderLibrary';
+   }
+   return true;
+   }
+
+   /**
+* External Lua library paths for Scribunto
+*
+* @param string $engine
+* @param array &$extraLibraryPaths
+*
+* @return bool
+*/
public static function registerScribuntoExternalLibraryPaths(
$engine,
-   array &$extraLibraryPaths
+   array &$extraLibraryPath
) {
-   if ( $engine !== 'lua' ) {
-   return true;
+   if ( $engine == 'lua' ) {
+   $extraLibraryPath[] = __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/Scribunto_LuaArticlePlaceholderLibrary.php 
b/includes/Lua/Scribunto_LuaArticlePlaceholderLibrary.php
new file mode 100644
index 000..d24b505
--- /dev/null
+++ b/includes/Lua/Scribunto_LuaArticlePlaceholderLibrary.php
@@ -0,0 +1,54 @@
+ array( $this, 'getImageProperty' 
),
+   );
+
+   return $this->getEngine()->registerInterface(
+   __DIR__ . '/EntityRenderer.lua', $lib, array()
+   );
+   }
+}
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9ffb0ea1851a9a3c9a798ae83ce3ff7c3a616ad5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ArticlePlaceholder
Gerrit-Branch: master
Gerrit-Owner: Lucie Kaffee 

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