LivingShadow has submitted this change and it was merged.

Change subject: Use localisation
......................................................................


Use localisation

Change-Id: I6190cf0f58f6b531dcbf0e8d0a55201cc789a843
---
M lib/Character.php
M lib/Collection.php
M lib/Component.php
M lib/Degree.php
M lib/Difficulty.php
M lib/Equipment.php
M lib/LWItem.php
M lib/Question.php
M lib/Taxon.php
M lib/Topic.php
M lib/resources/loadEditor.js
M lib/resources/loadFilter.js
12 files changed, 114 insertions(+), 81 deletions(-)



diff --git a/lib/Character.php b/lib/Character.php
index 5fa16f8..d5f9985 100644
--- a/lib/Character.php
+++ b/lib/Character.php
@@ -11,11 +11,11 @@
 class Character extends LWItem {
 
 
-    function loadFromPrefixedId($prefixedId) {
-        $this->fromPrefixedId($prefixedId, EntityIDs::pid('qCharacter'));
+    function loadFromId($prefixedId) {
+        $this->fromId($prefixedId, EntityIDs::pid('qCharacter'));
     }
-    function loadFromEntityId($entityId) {
-        $this->fromEntityId($entityId, EntityIDs::pid('qCharacter'));
+    function loadFromItemId($entityId) {
+        $this->fromItemId($entityId, EntityIDs::pid('qCharacter'));
     }
 
 
diff --git a/lib/Collection.php b/lib/Collection.php
index ca7db3a..9d4360a 100644
--- a/lib/Collection.php
+++ b/lib/Collection.php
@@ -10,11 +10,11 @@
 
 class Collection extends LWItem {
 
-    function loadFromPrefixedId($prefixedId) {
-        $this->fromPrefixedId($prefixedId, EntityIDs::pid('qCollection'));
+    function loadFromId($prefixedId) {
+        $this->fromId($prefixedId, EntityIDs::pid('qCollection'));
     }
-    function loadFromEntityId($entityId) {
-        $this->fromEntityId($entityId, EntityIDs::pid('qCollection'));
+    function loadFromItemId($entityId) {
+        $this->fromItemId($entityId, EntityIDs::pid('qCollection'));
     }
 
     function updatedData($clearCache = false) {
diff --git a/lib/Component.php b/lib/Component.php
index 63ec9c0..da6bf25 100644
--- a/lib/Component.php
+++ b/lib/Component.php
@@ -10,11 +10,11 @@
 
 class Component extends LWItem {
 
-    function loadFromPrefixedId($prefixedId) {
-        $this->fromPrefixedId($prefixedId, EntityIDs::pid('qComponent'));
+    function loadFromId($prefixedId) {
+        $this->fromId($prefixedId, EntityIDs::pid('qComponent'));
     }
-    function loadFromEntityId($entityId) {
-        $this->fromEntityId($entityId, EntityIDs::pid('qComponent'));
+    function loadFromItemId($entityId) {
+        $this->fromItemId($entityId, EntityIDs::pid('qComponent'));
     }
 
     function updatedData($clearCache = false) {
diff --git a/lib/Degree.php b/lib/Degree.php
index 514f461..65297f6 100644
--- a/lib/Degree.php
+++ b/lib/Degree.php
@@ -10,11 +10,11 @@
 
 class Degree extends LWItem {
 
-    function loadFromPrefixedId($prefixedId) {
-        $this->fromPrefixedId($prefixedId, EntityIDs::pid('qDegree'));
+    function loadFromId($prefixedId) {
+        $this->fromId($prefixedId, EntityIDs::pid('qDegree'));
     }
-    function loadFromEntityId($entityId) {
-        $this->fromEntityId($entityId, EntityIDs::pid('qDegree'));
+    function loadFromItemId($entityId) {
+        $this->fromItemId($entityId, EntityIDs::pid('qDegree'));
     }
 
     function updatedData($clearCache = false) {
diff --git a/lib/Difficulty.php b/lib/Difficulty.php
index 0cc824c..08f4952 100644
--- a/lib/Difficulty.php
+++ b/lib/Difficulty.php
@@ -10,11 +10,11 @@
 
 class Difficulty extends LWItem {
 
-    function loadFromPrefixedId($prefixedId) {
-        $this->fromPrefixedId($prefixedId, EntityIDs::pid('qDifficulty'));
+    function loadFromId($prefixedId) {
+        $this->fromId($prefixedId, EntityIDs::pid('qDifficulty'));
     }
-    function loadFromEntityId($entityId) {
-        $this->fromEntityId($entityId, EntityIDs::pid('qDifficulty'));
+    function loadFromItemId($entityId) {
+        $this->fromItemId($entityId, EntityIDs::pid('qDifficulty'));
     }
 
     function updatedData($clearCache = false) {
diff --git a/lib/Equipment.php b/lib/Equipment.php
index 155266b..033a9e7 100644
--- a/lib/Equipment.php
+++ b/lib/Equipment.php
@@ -10,11 +10,11 @@
 
 class Equipment extends LWItem {
 
-    function loadFromPrefixedId($prefixedId) {
-        $this->fromPrefixedId($prefixedId, EntityIDs::pid('qEquipment'));
+    function loadFromId($prefixedId) {
+        $this->fromId($prefixedId, EntityIDs::pid('qEquipment'));
     }
-    function loadFromEntityId($entityId) {
-        $this->fromEntityId($entityId, EntityIDs::pid('qEquipment'));
+    function loadFromItemId($entityId) {
+        $this->fromItemId($entityId, EntityIDs::pid('qEquipment'));
     }
 
     function updatedData($clearCache = false) {
diff --git a/lib/LWItem.php b/lib/LWItem.php
index a1479ba..aa199be 100644
--- a/lib/LWItem.php
+++ b/lib/LWItem.php
@@ -7,6 +7,7 @@
 
 
 require_once __DIR__ . '/../../Wikibase/repo/includes/store/StoreFactory.php';
+require_once __DIR__ . '/../../WikibaseDataModel/DataModel/Entity/ItemId.php';
 require_once 'Query.php';
 require_once 'EntityIDs.php';
 
@@ -19,9 +20,10 @@
 
 abstract class LWItem {
 
-    protected $entityContent;
-    protected $entityID;
-    protected $entity;
+    /// @type \Wikibase\EntityContent
+    protected $itemContent;
+    protected $itemId;
+    protected $item;
 
     protected $data = array(
         'revid' => -1
@@ -31,61 +33,68 @@
     function __construct($type, $options) {
         switch ($type) {
             case 'entityId' :
-                $this->loadFromEntityId($options['entityId']);
+                $this->loadFromItemId($options['entityId']);
                 break;
             case 'empty' :
                 break;
             case 'prefixedId' :
-                $this->loadFromPrefixedId($options['prefixedId']);
+                $this->loadFromId($options['prefixedId']);
                 break;
         }
     }
 
-    abstract protected function loadFromPrefixedId($prefixedId);
-    protected function fromPrefixedId($prefixedId, $pidInstanceType) {
-        $entityID = \Wikibase\EntityID::newFromPrefixedId($prefixedId);
-        $this->loadFromEntityId($entityID, $pidInstanceType);
+    abstract protected function loadFromId($id);
+    protected function fromId($id, $pidInstanceType) {
+        $itemID = new \Wikibase\DataModel\Entity\ItemId($id);
+        $this->loadFromItemId($itemID, $pidInstanceType);
     }
 
-    abstract protected function loadFromEntityId($entityID);
-    protected function fromEntityId($entityID, $pidInstanceType) {
+    abstract protected function loadFromItemId($itemId);
+    protected function fromItemId($itemId, $pidInstanceType) {
 
-        $this->entityID = $entityID;
+        $this->itemId = $itemId;
 
-        $this->entityContent = 
\Wikibase\EntityContentFactory::singleton()->getFromId( $this->entityID );
-        if ($this->entityContent === null) {
+        /*
+        if (!\Wikibase\EntityLookup::hasEntity($itemId)) {
             throw new Exception('Invalid ID.');
         }
-        $this->entity = $this->entityContent->getEntity();
+        */
 
-        if (!LWItem::instanceOfCheck($entityID, $pidInstanceType, 
EntityIDs::pid('pInstanceOf'))) {
+        if (!LWItem::instanceOfCheck($itemId, $pidInstanceType, 
EntityIDs::pid('pInstanceOf'))) {
             throw new Exception('Is not an instance.');
         }
+
+        $this->itemContent = 
\Wikibase\EntityContentFactory::singleton()->getFromId( $this->itemId );
+        if ($this->itemContent === null) {
+            throw new Exception('Invalid ID.');
+        }
+        $this->item = $this->itemContent->getEntity();
+
     }
 
 
     function getLabel($lang = 'en-gb') {
-        return $this->entity->getLabel($lang);
+        return $this->item->getLabel($lang);
     }
     function getPrefixedId() {
-        return $this->entity->getPrefixedId();
+        return $this->itemId->getPrefixedId();
     }
     function getEntity() {
-        return $this->entity;
+        return $this->item;
     }
     function getRevision() {
-        return $this->entityContent->getTitle()->getLatestRevID();
+        return $this->itemContent->getTitle()->getLatestRevID();
     }
     function updateContent($fromRev) {
-        $updatedContent = 
\Wikibase\EntityContentFactory::singleton()->getFromId( $this->entityID );
+        $updatedContent = 
\Wikibase\EntityContentFactory::singleton()->getFromId( $this->itemId );
 
         // Check if the item has been deleted
         if (!$updatedContent) { throw new ItemDeletedException(); }
 
         $newRev = $updatedContent->getTitle()->getLatestRevID();
         if ($fromRev != $newRev) {
-            $this->entityContent = $updatedContent;
-            $this->entity = $updatedContent->getEntity();
+            $this->itemContent = $updatedContent;
+            $this->item = $updatedContent->getEntity();
             return true;
         }
         return false;
@@ -99,13 +108,13 @@
 
         $strings = array();
 
-        $claims = $this->entity->getClaims();
+        $claims = $this->item->getClaims();
         foreach ($claims as $claim) {
 
             $snak = $claim->getMainSnak();
             $snakID = $snak->getPropertyId();
 
-            if ($snakID == strtolower($pidProperty)) {
+            if (strtolower($snakID) == strtolower($pidProperty)) {
                 $snakValue = $snak->getDataValue();
                 if ($snakValue instanceof \DataValues\StringValue) {
                     $strings[] = $snakValue->getValue();
@@ -126,17 +135,17 @@
 
         $values = array();
 
-        $claims = $this->entity->getClaims();
+        $claims = $this->item->getClaims();
         foreach ($claims as $claim) {
 
             $snak = $claim->getMainSnak();
             $snakID = $snak->getPropertyId();
 
-            if ($snakID == strtolower($pidProperty)) {
+            if (strtolower($snakID) == strtolower($pidProperty)) {
                 $snakValue = $snak->getDataValue();
-                if ($snakValue instanceof \Wikibase\EntityId) {
-                    if (LWItem::instanceOfCheck($snakValue, $pidInstanceType)) 
{
-                        $values[] = $snakValue->getPrefixedId();
+                if ($snakValue instanceof 
\Wikibase\DataModel\Entity\EntityIdValue) {
+                    if (LWItem::instanceOfCheck($snakValue->getEntityId(), 
$pidInstanceType)) {
+                        $values[] = $snakValue->getEntityId()->getPrefixedId();
                     }
                 }
             }
@@ -166,8 +175,8 @@
 
                 if ($snak instanceof \Wikibase\PropertyValueSnak) {
                     $snakValue = $snak->getDataValue();
-                    if ($snakValue instanceof \Wikibase\EntityId) {
-                        if ($snakValue == $eidInstance) {
+                    if ($snakValue instanceof 
\Wikibase\DataModel\Entity\EntityIdValue) {
+                        if ($snakValue->getEntityId() == $eidInstance) {
                             $isInstance = true;
                             break;
                         }
diff --git a/lib/Question.php b/lib/Question.php
index b08f421..f6c0629 100644
--- a/lib/Question.php
+++ b/lib/Question.php
@@ -11,16 +11,11 @@
 
 class Question extends LWItem {
 
-    protected $data = array(
-        'revid' => -1
-    );
-
-
-    function loadFromPrefixedId($prefixedId) {
-        $this->fromPrefixedId($prefixedId, EntityIDs::pid('qQuestion'));
+    function loadFromId($prefixedId) {
+        $this->fromId($prefixedId, EntityIDs::pid('qQuestion'));
     }
-    function loadFromEntityId($entityId) {
-        $this->fromEntityId($entityId, EntityIDs::pid('qQuestion'));
+    function loadFromItemId($entityId) {
+        $this->fromItemId($entityId, EntityIDs::pid('qQuestion'));
     }
 
     function updatedData($clearCache = false) {
diff --git a/lib/Taxon.php b/lib/Taxon.php
index a17e067..0a45cb8 100644
--- a/lib/Taxon.php
+++ b/lib/Taxon.php
@@ -10,11 +10,11 @@
 
 class Taxon extends LWItem {
 
-    function loadFromPrefixedId($prefixedId) {
-        $this->fromPrefixedId($prefixedId, EntityIDs::pid('qTaxon'));
+    function loadFromId($prefixedId) {
+        $this->fromId($prefixedId, EntityIDs::pid('qTaxon'));
     }
-    function loadFromEntityId($entityId) {
-        $this->fromEntityId($entityId, EntityIDs::pid('qTaxon'));
+    function loadFromItemId($entityId) {
+        $this->fromItemId($entityId, EntityIDs::pid('qTaxon'));
     }
 
     function keyName() {
diff --git a/lib/Topic.php b/lib/Topic.php
index e20f830..8fb2baa 100644
--- a/lib/Topic.php
+++ b/lib/Topic.php
@@ -10,11 +10,11 @@
 
 class Topic extends LWItem {
 
-    function loadFromPrefixedId($prefixedId) {
-        $this->fromPrefixedId($prefixedId, EntityIDs::pid('qTopic'));
+    function loadFromId($prefixedId) {
+        $this->fromId($prefixedId, EntityIDs::pid('qTopic'));
     }
-    function loadFromEntityId($entityId) {
-        $this->fromEntityId($entityId, EntityIDs::pid('qTopic'));
+    function loadFromItemId($entityId) {
+        $this->fromItemId($entityId, EntityIDs::pid('qTopic'));
     }
 
     function updatedData($clearCache = false) {
diff --git a/lib/resources/loadEditor.js b/lib/resources/loadEditor.js
index 14d7b8f..06b9c39 100644
--- a/lib/resources/loadEditor.js
+++ b/lib/resources/loadEditor.js
@@ -7,12 +7,22 @@
 console.log('Editor .js loaded');
 
 $().ready(function() {
-    console.log('Document is ready.');
 
-    var $dom = $('#editor');
-    $dom.empty();
+    i18n.init( {
 
-    LWE.UI.init($dom);
-    console.log('started.');
+        lng: mw.config.get( 'wgUserLanguage' ),
+        fallbackLng: 'en',
+        useCookie: false,
+        debug: true,
+        ns: 'translation',
+        resGetPath: 
'../../extensions/LifeWebCore/resources/script/locales/__lng__/__ns__.json'
+
+    }, function() {
+
+        var $dom = $('#editor');
+        $dom.empty();
+        LWE.UI.init($dom);
+
+    } );
 });
 
diff --git a/lib/resources/loadFilter.js b/lib/resources/loadFilter.js
index 4f99e5b..02294f9 100644
--- a/lib/resources/loadFilter.js
+++ b/lib/resources/loadFilter.js
@@ -6,9 +6,28 @@
 
 $().ready(function() {
 
-    var $dom = $('#filter');
-    $dom.empty();
+    i18n.init( {
 
-    new LWF.UI($dom);
+        lng: mw.config.get( 'wgUserLanguage' ),
+        fallbackLng: 'en',
+        useCookie: false,
+        debug: true,
+        ns: 'translation',
+        resGetPath: 
'../../extensions/LifeWebCore/resources/script/locales/__lng__/__ns__.json'
+
+    }, function() {
+
+        var $dom = $( '#filter' );
+        $dom.empty();
+
+        new LWF.UI( $dom, {
+            dKey: {
+                taxonPrefilters: [ 'selectedDegrees', 'selectedTaxa' ]
+            }
+        } );
+
+    } );
+
+
 });
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I6190cf0f58f6b531dcbf0e8d0a55201cc789a843
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/LifeWeb
Gerrit-Branch: master
Gerrit-Owner: LivingShadow <simon...@gmail.com>
Gerrit-Reviewer: Brian Wolff <bawolff...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: LivingShadow <simon...@gmail.com>

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

Reply via email to