Thiemo Mättig (WMDE) has submitted this change and it was merged. (
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.
Bug: T171725
Change-Id: Ic74cb1461b6b794df56c1590c4d2bb99393a865d
---
M composer.json
M view/resources/jquery/wikibase/snakview/snakview.js
M view/resources/templates.php
M view/src/SnakHtmlGenerator.php
4 files changed, 28 insertions(+), 5 deletions(-)
Approvals:
jenkins-bot: Verified
Thiemo Mättig (WMDE): Looks good to me, approved
diff --git a/composer.json b/composer.json
index 69d9c28..7b4c3c0 100644
--- a/composer.json
+++ b/composer.json
@@ -37,9 +37,9 @@
"wikibase/data-model-serialization": "^2.5.0",
"wikibase/internal-serialization": "^2.2.0",
"wikibase/data-model-services": "^3.7.0",
- "wikibase/data-model-javascript": "^3.0.1",
+ "wikibase/data-model-javascript": "^3.1.0",
"wikibase/javascript-api": "^2.2.2",
- "wikibase/serialization-javascript": "^2.0.8",
+ "wikibase/serialization-javascript": "^2.1.0",
"diff/diff": "^2.0.0",
"wikimedia/purtle": "^1.0.6"
},
diff --git a/view/resources/jquery/wikibase/snakview/snakview.js
b/view/resources/jquery/wikibase/snakview/snakview.js
index 4f379da..d361b26 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: [ '', '', '', '' ],
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,30 @@
* (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 hash;
+ this.element.removeClass( function ( index, className )
{
+ var matches = className.match(
/\bwikibase-snakview-[0-9a-fA-F]{40}\b/g );
+ return matches ? matches.join( ' ' ) : '';
+ } );
+ hash = this.snak() && this.snak().getHash();
+ if ( hash ) {
+ this.element.addClass( '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: merged
Gerrit-Change-Id: Ic74cb1461b6b794df56c1590c4d2bb99393a865d
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits