Addshore has submitted this change and it was merged.

Change subject: Include template to call lua module
......................................................................


Include template to call lua module

Add page title and sitelinks in php, the rest of the content in lua (for now 
using Capiunto)

Change-Id: I23fb2e882561dc1d5aed8adfbea8edb36721dc7b
---
A Lua/fancy-lua.xml
M Specials/SpecialFancyUnicorn.php
2 files changed, 193 insertions(+), 28 deletions(-)

Approvals:
  Addshore: Verified; Looks good to me, approved



diff --git a/Lua/fancy-lua.xml b/Lua/fancy-lua.xml
new file mode 100644
index 0000000..d8441c5
--- /dev/null
+++ b/Lua/fancy-lua.xml
@@ -0,0 +1,108 @@
+<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.10/"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.10/ 
http://www.mediawiki.org/xml/export-0.10.xsd"; version="0.10" xml:lang="en">
+  <siteinfo>
+    <sitename>hey-hey-wiki</sitename>
+    <dbname>my_wiki</dbname>
+    <base>http://localhost/core/index.php/Main_Page</base>
+    <generator>MediaWiki 1.26alpha</generator>
+    <case>first-letter</case>
+    <namespaces>
+      <namespace key="-2" case="first-letter">Media</namespace>
+      <namespace key="-1" case="first-letter">Special</namespace>
+      <namespace key="0" case="first-letter" />
+      <namespace key="1" case="first-letter">Talk</namespace>
+      <namespace key="2" case="first-letter">User</namespace>
+      <namespace key="3" case="first-letter">User talk</namespace>
+      <namespace key="4" case="first-letter">Hey-hey-wiki</namespace>
+      <namespace key="5" case="first-letter">Hey-hey-wiki talk</namespace>
+      <namespace key="6" case="first-letter">File</namespace>
+      <namespace key="7" case="first-letter">File talk</namespace>
+      <namespace key="8" case="first-letter">MediaWiki</namespace>
+      <namespace key="9" case="first-letter">MediaWiki talk</namespace>
+      <namespace key="10" case="first-letter">Template</namespace>
+      <namespace key="11" case="first-letter">Template talk</namespace>
+      <namespace key="12" case="first-letter">Help</namespace>
+      <namespace key="13" case="first-letter">Help talk</namespace>
+      <namespace key="14" case="first-letter">Category</namespace>
+      <namespace key="15" case="first-letter">Category talk</namespace>
+      <namespace key="120" case="first-letter">Item</namespace>
+      <namespace key="121" case="first-letter">Item talk</namespace>
+      <namespace key="122" case="first-letter">Property</namespace>
+      <namespace key="123" case="first-letter">Property talk</namespace>
+      <namespace key="828" case="first-letter">Module</namespace>
+      <namespace key="829" case="first-letter">Module talk</namespace>
+    </namespaces>
+  </siteinfo>
+  <page>
+    <title>Template:FancyUnicorn</title>
+    <ns>10</ns>
+    <id>17</id>
+    <revision>
+      <id>192</id>
+      <parentid>190</parentid>
+      <timestamp>2015-08-20T16:36:46Z</timestamp>
+      <contributor>
+        <ip>127.0.0.1</ip>
+      </contributor>
+      <model>wikitext</model>
+      <format>text/x-wiki</format>
+      <text xml:space="preserve" bytes="43">
+
+{{#invoke:FancyUnicorn|showData|{{{1}}}}}</text>
+      <sha1>aj7tq9d2ompl5v5c0c7iil61fw4wiyz</sha1>
+    </revision>
+  </page>
+  <page>
+    <title>Module:FancyUnicorn</title>
+    <ns>828</ns>
+    <id>18</id>
+    <revision>
+      <id>244</id>
+      <parentid>243</parentid>
+      <timestamp>2015-08-21T13:26:51Z</timestamp>
+      <contributor>
+        <ip>127.0.0.1</ip>
+      </contributor>
+      <model>Scribunto</model>
+      <format>text/plain</format>
+      <text xml:space="preserve" bytes="1141">local p = {}
+
+-- get the label of the local entity
+p.showData = function(frame)
+  local entityID = mw.text.trim( frame.args[1] or &quot;&quot; )
+  --if mw.wikibase.sitelink( entityID ) ~= &quot;&quot; then
+  --  return mw.wikibase.sitelink( entityID )
+  --end
+  local entity = mw.wikibase.getEntityObject( entityID )
+  --return entity:getLabel() .. &quot; \n &quot; .. mw.wikibase.description( 
entityID )
+  content = mw.wikibase.description( entityID )
+  title = entity:getLabel()
+  return content .. ' ' .. tostring( getFancyBox( getPropValuePairs( entity ), 
title ):getHtml() )
+end
+
+function getPropValuePairs( entity )
+  table = {}
+  for key,value in pairs( entity:getProperties() ) do
+    for k, v in pairs( entity:formatPropertyValues( value ) ) do
+      table[mw.wikibase.label(value)] = v
+    end
+  end
+  return table
+end
+
+function getFancyBox(table, title)
+       local capiunto = require 'capiunto'
+       fancybox = capiunto.create( {
+               title = tostring(title) ,
+               topStyle = 'background:#cfc;'
+       } )
+  --fancybox = tostring(fancybox:getHtml())
+  for key,value in pairs(table) do fancybox:addRow(key,value) end
+  --:addRow(&quot;lucie&quot;, &quot;testing&quot;)
+  return fancybox
+end
+
+return p</text>
+      <sha1>7wycjtn9b556v9pf4bssl1dumtbqr52</sha1>
+    </revision>
+  </page>
+</mediawiki>
diff --git a/Specials/SpecialFancyUnicorn.php b/Specials/SpecialFancyUnicorn.php
index a3c64b6..e9026ac 100644
--- a/Specials/SpecialFancyUnicorn.php
+++ b/Specials/SpecialFancyUnicorn.php
@@ -1,29 +1,33 @@
 <?php
+
 /**
  * The FancyUnicorn SpecialPage for the ArticlePlaceholder extension
  *
  * @ingroup Extensions
  * @author Lucie-Aimée Kaffee
  * @license GNU General Public Licence 2.0 or later
- * 
+ *
  */
+
 namespace ArticlePlaceholder\Specials;
 
 use Html;
 use Exception;
 use Wikibase\Client\WikibaseClient;
-use Wikibase\DataModel\Entity\EntityIdParser;
-use Wikibase\DataModel\Entity\EntityIdParsingException;
 use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\DataModel\Entity\EntityIdParser;
+use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookupFactory;
+use Wikibase\Lib\Store\SiteLinkLookup;
+use SiteStore;
 use SpecialPage;
 
 class SpecialFancyUnicorn extends SpecialPage {
 
        public static function newFromGlobalState() {
                $wikibaseClient = WikibaseClient::getDefaultInstance();
-
                return new self(
-                               $wikibaseClient->getEntityIdParser()
+                       $wikibaseClient->getEntityIdParser(), 
$wikibaseClient->getLanguageFallbackLabelDescriptionLookupFactory(), 
$wikibaseClient->getStore()->getSiteLinkLookup(), 
$wikibaseClient->getSiteStore()
                );
        }
 
@@ -33,10 +37,28 @@
        private $idParser;
 
        /**
+        * @var LanguageFallbackLabelDescriptionLookupFactory
+        */
+       private $lfldlf;
+
+       /**
+        * @var SitelinkLookup
+        */
+       private $sitelinkLookup;
+
+       /**
+        * @var SiteStore
+        */
+       private $siteStore;
+
+       /**
         * Initialize the special page.
         */
-       public function __construct( EntityIdParser $idParser ) {
+       public function __construct( EntityIdParser $idParser, 
LanguageFallbackLabelDescriptionLookupFactory $lfldlf, SiteLinkLookup 
$sitelinkLookup, SiteStore $siteStore ) {
                $this->idParser = $idParser;
+               $this->lfldlf = $lfldlf;
+               $this->sitelinkLookup = $sitelinkLookup;
+               $this->siteStore = $siteStore;
                parent::__construct( 'FancyUnicorn' );
        }
 
@@ -45,11 +67,10 @@
         *
         */
        public function execute( $sub ) {
-               $out = $this->getOutput();
-
-               $out->setPageTitle( $this->msg( 
'articleplaceholder-fancyunicorn' ) );
+               $this->getOutput()->setPageTitle( $this->msg( 
'articleplaceholder-fancyunicorn' ) );
                if ( $this->getItemIdParam( 'entityid', $sub ) != null ) {
-                       $out->addWikiText( 'Testing test test' );
+                       $entityId = $this->getItemIdParam( 'entityid', $sub );
+                       $this->showPlaceholder( $entityId );
                } else {
                        //create the html elements
                        $this->createForm();
@@ -58,29 +79,27 @@
 
        /**
         *
-        * @todo add wikibase group?
+        * @todo add to wikibase group?
         */
        protected function getGroupName() {
                return 'other';
        }
 
        /**
-        * first function to add a form to enter an entity id and a submit 
button
+        * Create html elements
         */
        protected function createForm() {
-               //add css style thing (in Wikibase OutputPage#addModuleStyles
-
                // Form header
                $this->getOutput()->addHTML(
-                               Html::openElement(
-                                       'form', array(
+                       Html::openElement(
+                               'form', array(
                                        'method' => 'get',
                                        'action' => 
$this->getPageTitle()->getFullUrl(),
                                        'name' => 'ap-fancyunicorn',
                                        'id' => 'ap-fancyunicorn-form1',
                                        'class' => 'ap-form'
-                                       )
                                )
+                       )
                );
 
                // Form elements
@@ -88,13 +107,13 @@
 
                // Form body
                $this->getOutput()->addHTML(
-                               Html::input(
-                                               'submit', $this->msg( 
'articleplaceholder-fancyunicorn-submit' )->text(), 'submit', array(
+                       Html::input(
+                               'submit', $this->msg( 
'articleplaceholder-fancyunicorn-submit' )->text(), 'submit', array(
                                        'id' => 'submit'
-                                       )
                                )
-                               . Html::closeElement( 'fieldset' )
-                               . Html::closeElement( 'form' )
+                       )
+                       . Html::closeElement( 'fieldset' )
+                       . Html::closeElement( 'form' )
                );
        }
 
@@ -106,19 +125,18 @@
         */
        protected function getFormElements() {
                return Html::rawElement(
-                                       'p', array(),
-                                       $this->msg( 
'articleplaceholder-fancyunicorn-intro' )->parse()
+                                               'p', array(), $this->msg( 
'articleplaceholder-fancyunicorn-intro' )->parse()
                                )
                                . Html::element( 'br' )
                                . Html::element(
-                                       'label', array(
+                                               'label', array(
                                        'for' => 'ap-fancyunicorn-entityid',
                                        'class' => 'ap-label'
-                                       ), $this->msg( 
'articleplaceholder-fancyunicorn-entityid' )->text()
+                                               ), $this->msg( 
'articleplaceholder-fancyunicorn-entityid' )->text()
                                )
                                . Html::element( 'br' )
                                . Html::input(
-                                       'entityid', 
$this->getRequest()->getVal( 'entityid' ), 'text', array(
+                                               'entityid', 
$this->getRequest()->getVal( 'entityid' ), 'text', array(
                                        'class' => 'ap-input',
                                        'id' => 'ap-fancyunicorn-entityid'
                                                )
@@ -148,7 +166,7 @@
                try {
                        $id = $this->idParser->parse( $rawId );
                        if ( !( $id instanceof ItemId ) ) {
-                                       throw new Exception();
+                               throw new Exception();
                        }
 
                        return $id;
@@ -158,4 +176,43 @@
                }
        }
 
+       /**
+        * Show placeholder and include template to call lua module
+        * @param ItemId $entityId
+        */
+       private function showPlaceholder( ItemId $entityId ) {
+               $this->getOutput()->addWikiText( "{{fancyUnicorn|" . 
$entityId->getSerialization() . "}}" );
+               $this->showTitle( $entityId );
+               $this->showLanguageLinks( $entityId );
+       }
+
+       /**
+        * Show label as page title
+        * @param EntityId $entityId
+        */
+       private function showTitle( ItemId $entityId ) {
+               $array[] = $entityId;
+               $label = $this->lfldlf->newLabelDescriptionLookup( 
$this->getLanguage(), $array )->getLabel( $entityId )->getText();
+               $this->getOutput()->setPageTitle( $label );
+       }
+
+       /**
+        * Set language links
+        * @param ItemId $entityId
+        * @todo set links to other projects in sidebar, too!
+        */
+       private function showLanguageLinks( ItemId $entityId ) {
+               $sitelinks = $this->sitelinkLookup->getSiteLinksForItem( 
$entityId );
+               $languagelinks = array();
+               foreach ( $sitelinks as $sl ) {
+                       $languageCode = $this->siteStore->getSite( 
($sl->getSiteId() ) )->getLanguageCode();
+
+                       if ( $languageCode != null ) {
+                               $languagelinks[$languageCode] = $languageCode . 
':' . $sl->getPageName();
+                       }
+               }
+
+               $this->getOutput()->setLanguageLinks( $languagelinks );
+       }
+
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I23fb2e882561dc1d5aed8adfbea8edb36721dc7b
Gerrit-PatchSet: 12
Gerrit-Project: mediawiki/extensions/ArticlePlaceholder
Gerrit-Branch: master
Gerrit-Owner: Lucie Kaffee <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to