Lucas Werkmeister (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/373860 )

Change subject: Add snak hashes to entity HTML
......................................................................

Add snak hashes to entity HTML

The snakview tempate is updated to include a class for the snak hash,
similar to the classes for statement GUIDs and reference hashes. The PHP
SnakHtmlGenerator and the JS snakview both learn to populate and update
this class.

TODO: This requires changes in wikibase/data-model-javascript and
wikibase/serialization-javascript!

Bug: T171725
Change-Id: Ic74cb1461b6b794df56c1590c4d2bb99393a865d
---
M view/resources/jquery/wikibase/snakview/snakview.js
M view/resources/templates.php
M view/src/SnakHtmlGenerator.php
3 files changed, 32 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/60/373860/1

diff --git a/view/resources/jquery/wikibase/snakview/snakview.js 
b/view/resources/jquery/wikibase/snakview/snakview.js
index 4f379da..47dca52 100644
--- a/view/resources/jquery/wikibase/snakview/snakview.js
+++ b/view/resources/jquery/wikibase/snakview/snakview.js
@@ -71,7 +71,7 @@
                 */
                options: {
                        template: 'wikibase-snakview',
-                       templateParams: [ '', '', '' ],
+                       templateParams: [ '', '', '', new Array( 41 ).join( '0' 
) ],
                        templateShortCuts: {
                                $property: '.wikibase-snakview-property',
                                $snakValue: '.wikibase-snakview-value',
@@ -447,6 +447,10 @@
                                }
                        }
 
+                       if ( serialization.hash ) {
+                               value.hash = serialization.hash;
+                       }
+
                        return this._variation ? $.extend( 
this._variation.value(), value ) : value;
                },
 
@@ -609,12 +613,36 @@
                 * (Re-)renders the widget.
                 */
                draw: function () {
+                       this.updateHash();
                        this.drawProperty();
                        this.drawSnakTypeSelector();
                        this.drawVariation();
                },
 
                /**
+                * Updates the class list of the DOM element
+                * to contain the right wikibase-snakview-{hash} class if a 
hash is configured,
+                * and no other wikibase-snakview-{otherHash} classes.
+                */
+               updateHash: function () {
+                       var index,
+                               classList = this.element[ 0 ].classList,
+                               classes = Array.from( classList ),
+                               klass,
+                               hash;
+                       for ( index = 0; index < classes.length; index++ ) {
+                               klass = classes[ index ];
+                               if ( klass.match( 
/^wikibase-snakview-[0-9a-fA-F]{40}$/ ) ) {
+                                       classList.remove( klass );
+                               }
+                       }
+                       hash = this.snak() && this.snak().getHash();
+                       if ( hash ) {
+                               classList.add( 'wikibase-snakview-' + hash );
+                       }
+               },
+
+               /**
                 * (Re-)renders the Property DOM structure according to the 
current value. The `Property` DOM
                 * is not (re-)rendered if changing the `Property` is locked 
via the `locked` option and
                 * previously generated HTML is detected.
diff --git a/view/resources/templates.php b/view/resources/templates.php
index aec2466..d1cd90b 100644
--- a/view/resources/templates.php
+++ b/view/resources/templates.php
@@ -74,7 +74,7 @@
 
        $templates['wikibase-snakview'] =
 <<<HTML
-<div class="wikibase-snakview">
+<div class="wikibase-snakview wikibase-snakview-$4">
        <div class="wikibase-snakview-property-container">
                <div class="wikibase-snakview-property" dir="auto">$1</div>
        </div>
diff --git a/view/src/SnakHtmlGenerator.php b/view/src/SnakHtmlGenerator.php
index 8a4366e..8e57a49 100644
--- a/view/src/SnakHtmlGenerator.php
+++ b/view/src/SnakHtmlGenerator.php
@@ -86,7 +86,8 @@
                        // Display property link only once for snaks featuring 
the same property:
                        $propertyLink,
                        $snakViewCssClass,
-                       $formattedValue
+                       $formattedValue,
+                       $snak->getHash()
                );
 
                return $html;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic74cb1461b6b794df56c1590c4d2bb99393a865d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>

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

Reply via email to