jenkins-bot has submitted this change and it was merged.

Change subject: Implemented rank selector widget
......................................................................


Implemented rank selector widget

The rank selector displays the rank and allows changing the rank of each 
statement.

Change-Id: I7caadcd0189bc492c7f55766186231299fb833b1
---
M lib/WikibaseLib.hooks.php
M lib/resources/Resources.php
A lib/resources/jquery.wikibase/jquery.wikibase.statementview.RankSelector.js
M lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
A lib/resources/jquery.wikibase/themes/default/images/rankselector.png
A 
lib/resources/jquery.wikibase/themes/default/jquery.wikibase.statementview.RankSelector.css
M lib/resources/templates.php
M lib/resources/wikibase.css
A 
lib/tests/qunit/jquery.wikibase/jquery.wikibase.statementview.RankSelector.tests.js
M repo/Wikibase.i18n.php
M repo/includes/ClaimHtmlGenerator.php
M repo/includes/EntityView.php
12 files changed, 625 insertions(+), 17 deletions(-)

Approvals:
  Tobias Gritschacher: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/WikibaseLib.hooks.php b/lib/WikibaseLib.hooks.php
index ae5b10f..0111ded 100644
--- a/lib/WikibaseLib.hooks.php
+++ b/lib/WikibaseLib.hooks.php
@@ -11,11 +11,10 @@
  *
  * @since 0.1
  *
- * @file
- * @ingroup WikibaseLib
- *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
+ * @author Daniel Werner < [email protected] >
+ * @author H. Snater < [email protected] >
  */
 final class LibHooks {
 
@@ -171,7 +170,16 @@
                        ),
                );
 
-               $testModules['qunit']['jquery.wikibase.snaklistview.tests'] = 
$moduleBase +  array(
+               $testModules['qunit']['jquery.wikibase.statementview.tests'] = 
$moduleBase + array(
+                               'scripts' => array(
+                                       
'tests/qunit/jquery.wikibase/jquery.wikibase.statementview.RankSelector.tests.js',
+                               ),
+                               'dependencies' => array(
+                                       'jquery.wikibase.statementview',
+                               ),
+                       );
+
+               $testModules['qunit']['jquery.wikibase.snaklistview.tests'] = 
$moduleBase + array(
                        'scripts' => array(
                                
'tests/qunit/jquery.wikibase/jquery.wikibase.snaklistview.tests.js',
                        ),
diff --git a/lib/resources/Resources.php b/lib/resources/Resources.php
index 11b2c3b..d46a3bb 100644
--- a/lib/resources/Resources.php
+++ b/lib/resources/Resources.php
@@ -8,11 +8,9 @@
  *
  * @since 0.2
  *
- * @file
- * @ingroup WikibaseLib
- *
  * @licence GNU GPL v2+
  * @author Daniel Werner
+ * @author H. Snater < [email protected] >
  *
  * @codeCoverageIgnoreStart
  */
@@ -551,6 +549,7 @@
                                'wikibase.AbstractedRepoApi',
                                'wikibase.store', // required for getting 
datatype from entityselector selected property
                                'mediawiki.legacy.shared',
+                               'jquery.ui.position',
                                'jquery.ui.TemplatedWidget',
                                // valueviews for representing DataValues in 
snakview:
                                'jquery.valueview.experts.stringvalue',
@@ -605,17 +604,26 @@
                'jquery.wikibase.statementview' => $moduleTemplate + array(
                        'scripts' => array(
                                
'jquery.wikibase/jquery.wikibase.statementview.js',
+                               
'jquery.wikibase/jquery.wikibase.statementview.RankSelector.js',
+                       ),
+                       'styles' => array(
+                               
'jquery.wikibase/themes/default/jquery.wikibase.statementview.RankSelector.css',
                        ),
                        'dependencies' => array(
+                               'jquery.ui.position',
+                               'jquery.ui.toggler',
                                'jquery.wikibase.claimview',
                                'jquery.wikibase.listview',
                                'jquery.wikibase.referenceview',
                                'jquery.wikibase.toolbarcontroller',
                                'wikibase.AbstractedRepoApi',
+                               'wikibase.datamodel',
                                'wikibase.utilities',
-                               'jquery.ui.toggler',
                        ),
                        'messages' => array(
+                               
'wikibase-statementview-rankselector-rank-preferred',
+                               
'wikibase-statementview-rankselector-rank-normal',
+                               
'wikibase-statementview-rankselector-rank-deprecated',
                                
'wikibase-statementview-referencesheading-pendingcountersubject',
                                
'wikibase-statementview-referencesheading-pendingcountertooltip',
                                'wikibase-addreference'
diff --git 
a/lib/resources/jquery.wikibase/jquery.wikibase.statementview.RankSelector.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.statementview.RankSelector.js
new file mode 100644
index 0000000..70dd846
--- /dev/null
+++ 
b/lib/resources/jquery.wikibase/jquery.wikibase.statementview.RankSelector.js
@@ -0,0 +1,292 @@
+/**
+ * @licence GNU GPL v2+
+ * @author H. Snater < [email protected] >
+ */
+( function( mw, wb, $ ) {
+       'use strict';
+
+       var PARENT = $.Widget;
+
+       /**
+        * Selector for choosing a statement rank.
+        * @since 0.5
+        *
+        * @option [rank] {boolean} The rank that shall be selected.
+        *         Default: wikibase.Statement.RANK.NORMAL
+        *
+        * @option [isRTL] {boolean} Defines whether the widget is displayed in 
right-to-left context.
+        *         If not specified, the context is detected by checking 
whether the 'rtl' css class is
+        *         set on the HTML body element.
+        *         Default: undefined
+        *
+        * @event afterchange Triggered after the snak type got changed
+        *        (1) {jQuery.Event}
+        */
+       $.wikibase.statementview.RankSelector = wb.utilities.inherit( PARENT, {
+               widgetName: 'wikibase-rankselector',
+               widgetBaseClass: 'wb-rankselector',
+
+               /**
+                * @type {Object}
+                */
+               options: {
+                       rank: wb.Statement.RANK.NORMAL,
+                       isRtl: undefined
+               },
+
+               /**
+                * The node of the menu to select the rank from.
+                * @type {jQuery}
+                */
+               $menu: null,
+
+               /**
+                * Icon node.
+                * @type {jQuery}
+                */
+               $icon: null,
+
+               /**
+                * @see jQuery.Widget._create
+                */
+               _create: function() {
+                       var self = this;
+
+                       this.$menu = this._buildMenu().appendTo( 'body' 
).hide();
+
+                       this.element
+                       .addClass( this.widgetBaseClass )
+                       .on( 'mouseover.' + this.widgetName, function( event ) {
+                               if( !self.isDisabled() ) {
+                                       self.element.addClass( 'ui-state-hover' 
);
+                               }
+                       } )
+                       .on( 'mouseout.' + this.widgetName, function( event ) {
+                               if( !self.isDisabled() ) {
+                                       self.element.removeClass( 
'ui-state-hover' );
+                               }
+                       } )
+                       .on( 'click.' + this.widgetName, function( event ) {
+                               if( self.isDisabled() || self.$menu.is( 
':visible' ) ) {
+                                       self.$menu.hide();
+                                       return;
+                               }
+
+                               self.$menu.show();
+                               self.repositionMenu();
+
+                               self.element.addClass( 'ui-state-active' );
+
+                               // Close the menu when clicking, regardless of 
whether the click is performed on the
+                               // menu itself or outside of it:
+                               var degrade = function( event ) {
+                                       if ( event.target !== self.element.get( 
0 ) ) {
+                                               self.$menu.hide();
+                                               self.element.removeClass( 
'ui-state-active' );
+                                       }
+                                       self._unbindGlobalEventListeners();
+                               };
+
+                               $( document ).on( 'mouseup.' + self.widgetName, 
degrade  );
+                               $( window ).on( 'resize.' + self.widgetName, 
degrade );
+                       } );
+
+                       this.$icon = mw.template( 'wb-rankselector', '' 
).appendTo( this.element );
+
+                       self.$menu.on( 'click.' + this.widgetName, function( 
event ) {
+                               var $li = $( event.target ).closest( 'li' ),
+                                       rank = $li.data( self.widgetName + 
'-menuitem-rank' );
+
+                               if( rank !== undefined ) {
+                                       self.rank( rank );
+                               }
+                       } );
+
+                       this._setRank( this.options.rank );
+               },
+
+               /**
+                * @see jQuery.Widget.destroy
+                */
+               destroy: function() {
+                       this.$menu.data( 'menu' ).destroy();
+                       this.$menu.remove();
+                       this.$icon.remove();
+
+                       this.element.removeClass( 'ui-state-default 
ui-state-hover ' + this.widgetBaseClass );
+
+                       this._unbindGlobalEventListeners();
+
+                       PARENT.prototype.destroy.call( this );
+               },
+
+               /**
+                * @see jQuery.Widget._setOption
+                * @triggers afterchange
+                */
+               _setOption: function( key, value ) {
+                       PARENT.prototype._setOption.apply( this, arguments );
+                       if( key === 'rank' ) {
+                               this._setRank( value );
+                               this._trigger( 'afterchange' );
+                       }
+               },
+
+               /**
+                * Removes all global event listeners generated by the rank 
selector.
+                */
+               _unbindGlobalEventListeners: function() {
+                       $( document ).add( $( window ) ).off( '.' + 
this.widgetName );
+               },
+
+               /**
+                * Generates the menu the rank may be chosen from.
+                *
+                * @return {jQuery}
+                */
+               _buildMenu: function() {
+                       var self = this,
+                               $menu = $( '<ul/>' ).addClass( 
this.widgetBaseClass + '-menu' );
+
+                       $.each( wikibase.Statement.RANK, function( rankId, i ) {
+                               rankId = rankId.toLowerCase();
+
+                               $menu.append(
+                                       $( '<li/>' )
+                                       .addClass( self.widgetBaseClass + 
'-menuitem-' + rankId )
+                                       .data( self.widgetName + 
'-menuitem-rank', i )
+                                       .append(
+                                               $( '<a/>' )
+                                               .text( mw.msg( 
'wikibase-statementview-rankselector-rank-' + rankId ) )
+                                               .on( 'click.' + 
self.widgetName, function( event ) {
+                                                       event.preventDefault();
+                                               } )
+                                       )
+                               );
+                       } );
+
+                       return $menu.menu();
+               },
+
+               /**
+                * Returns a rank's serialized string.
+                * @see wikibase.Statement.RANK
+                *
+                * @param {number} rank
+                * @return {*}
+                */
+               _getRankString: function( rank ) {
+                       var rankString = null;
+
+                       $.each( wikibase.Statement.RANK, function( rankId, i ) {
+                               if( rank === i ) {
+                                       rankString = rankId.toLowerCase();
+                                       return false;
+                               }
+                       } );
+
+                       return rankString;
+               },
+
+               /**
+                * Sets the rank if a rank is specified or gets the current 
rank if parameter is omitted.
+                * @since 0.5
+                *
+                * @param {number} [rank]
+                * @return {number|undefined}
+                *
+                * @triggers afterchange
+                */
+               rank: function( rank ) {
+                       if( rank === undefined ) {
+                               var $activeItem = this.$menu.children( 
'.ui-state-active' );
+                               return ( $activeItem.length )
+                                       ? $activeItem.data( this.widgetName + 
'-menuitem-rank' )
+                                       : null;
+                       }
+
+                       this._setRank( rank );
+
+                       this._trigger( 'afterchange' );
+               },
+
+               /**
+                * Sets the rank activating the menu item representing the 
specified rank.
+                *
+                * @param {number} rank
+                */
+               _setRank: function( rank ) {
+                       if( rank === this.rank() ) {
+                               return;
+                       }
+
+                       this.$menu.children().removeClass( 'ui-state-active' );
+                       this.$menu
+                               .children( '.' + this.widgetBaseClass + 
'-menuitem-' + this._getRankString( rank ) )
+                               .addClass( 'ui-state-active' );
+
+                       this._updateIcon();
+               },
+
+               /**
+                * Updates the rank icon to reflect the rank currently set.
+                */
+               _updateIcon: function() {
+                       var self = this;
+
+                       $.each( wikibase.Statement.RANK, function( rankId, i ) {
+                               self.$icon.removeClass( 'wb-rankselector-' + 
rankId.toLowerCase() );
+                       } );
+
+                       this.$icon.addClass( 'wb-rankselector-' + 
this._getRankString( this.rank() ) );
+               },
+
+               /**
+                * Positions the menu.
+                * @since 0.5
+                */
+               repositionMenu: function() {
+                       var isRtl = ( this.options.isRTL )
+                               ? this.options.isRTL
+                               : $( 'body' ).hasClass( 'rtl' );
+
+                       this.$menu.position( {
+                               of: this.$icon,
+                               my: ( isRtl ? 'right' : 'left' ) + ' top',
+                               at: ( isRtl ? 'right' : 'left' ) + ' bottom',
+                               offset: '0 1',
+                               collision: 'none'
+                       } );
+               },
+
+               /**
+                * @see jQuery.Widget.disable
+                * @since 0.5
+                */
+               disable: function() {
+                       this.$menu.hide();
+                       this.element.removeClass( 'ui-state-active 
ui-state-hover' );
+                       this.element.addClass( 'ui-state-disabled' );
+                       return PARENT.prototype.disable.call( this );
+               },
+
+               /**
+                * @see jQuery.Widget.enable
+                * @since 0.5
+                */
+               enable: function() {
+                       this.element.removeClass( 'ui-state-disabled' );
+                       return PARENT.prototype.enable.call( this );
+               },
+
+               /**
+                * Returns whether the widget is currently disabled.
+                * @return 0.5
+                */
+               isDisabled: function() {
+                       return this.element.hasClass( 'ui-state-disabled' );
+               }
+
+       } );
+
+}( mediaWiki, wikibase, jQuery ) );
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
index 9475350..ce48538 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.statementview.js
@@ -27,6 +27,7 @@
                template: 'wb-statement',
                templateParams: [
                        'wb-last', // class: wb-first|wb-last
+                       '', // Rank selector
                        function() { // class='wb-claim-$2'
                                return ( this._claim && this._claim.getGuid() ) 
|| 'new';
                        },
@@ -37,6 +38,7 @@
                        '' // List of references
                ],
                templateShortCuts: {
+                       '$rankSelector': '.wb-statement-rank',
                        '$mainSnak': '.wb-claim-mainsnak',
                        '$qualifiers': '.wb-statement-qualifiers',
                        '$refsHeading': '.wb-statement-references-heading',
@@ -62,6 +64,8 @@
                var self = this,
                        statement = this.value(),
                        refs = statement ? statement.getReferences() : [];
+
+               this._createRankSelector( statement ? statement.getRank() : 
null );
 
                function indexOf( element, array ) {
                        var index = $.inArray( element, array );
@@ -159,11 +163,79 @@
        },
 
        /**
+        * Creates the rank selector to select the statement rank.
+        * @since 0.5
+        *
+        * @param {number} rank
+        */
+       _createRankSelector: function( rank ) {
+               if( !mw.config.get( 'wbExperimentalFeatures' ) ) {
+                       this.$rankSelector.css( 'display', 'none' );
+               }
+
+               this._rankSelector = new $.wikibase.statementview.RankSelector( 
{
+                       rank: rank
+               }, this.$rankSelector );
+
+               var self = this,
+                       changeEvent = 'afterchange.' + this.widgetName;
+
+               this.$rankSelector.on( changeEvent, function( event ) {
+                       if( self.value() ) {
+                               self._trigger( 'change' );
+                       }
+               } );
+
+               this.element
+               .on( this.widgetEventPrefix + 'afterstartediting.' + 
this.widgetName, function( event ) {
+                       self.$rankSelector.addClass( 'ui-state-default' );
+                       if( !self._claim ) {
+                               self._rankSelector.rank( 
wb.Statement.RANK.NORMAL );
+                       }
+                       self._rankSelector.enable();
+               } )
+               .on(
+                       this.widgetEventPrefix + 'stopediting.' + 
this.widgetName,
+                       function( event, dropValue ) {
+                               self._rankSelector.disable();
+                       }
+               )
+               .on( this.widgetEventPrefix + 'toggleerror.' + this.widgetName, 
function( event, error ) {
+                       if( !error ) {
+                               self._rankSelector.enable();
+                       }
+               } )
+               .on(
+                       this.widgetEventPrefix + 'afterstopediting.' + 
this.widgetName,
+                       function( event, dropValue ) {
+                               self.$rankSelector.removeClass( 
'ui-state-default' );
+                               if( dropValue && self._claim ) {
+                                       self._rankSelector.rank( 
self._claim.getRank() );
+                               }
+                               self._rankSelector.disable();
+                       }
+               );
+       },
+
+       /**
+        * @see jQuery.wikibase.claimview.isInitialValue
+        */
+       isInitialValue: function() {
+               if( !PARENT.prototype.isInitialValue.call( this ) ) {
+                       return false;
+               }
+               if( this._claim && this._rankSelector ) {
+                       return this._claim.getRank() === 
this._rankSelector.rank();
+               }
+               return true;
+       },
+
+       /**
         * Instantiates a statement with the statementview's current value.
         * @see jQuery.wikibase.claimview._instantiateClaim
         *
         * @param {string} guid
-        * @return {wb.Statement}
+        * @return {wikibase.Statement}
         */
        _instantiateClaim: function( guid ) {
                var qualifiers = null;
@@ -184,7 +256,7 @@
                        this.$mainSnak.data( 'snakview' ).snak(),
                        qualifiers,
                        this.getReferences(),
-                       null, // TODO: Rank
+                       this._rankSelector.rank(),
                        guid
                );
        },
@@ -285,9 +357,12 @@
        },
 
        /**
-        * @see $.widget.destroy
+        * @see jQuery.Widget.destroy
         */
        destroy: function() {
+               this._rankSelector.destroy();
+               this.$rankSelector.off( '.' + this.widgetName );
+
                this.element.removeClass( 'wb-claimview' );
                PARENT.prototype.destroy.call( this );
        },
diff --git 
a/lib/resources/jquery.wikibase/themes/default/images/rankselector.png 
b/lib/resources/jquery.wikibase/themes/default/images/rankselector.png
new file mode 100644
index 0000000..498acd3
--- /dev/null
+++ b/lib/resources/jquery.wikibase/themes/default/images/rankselector.png
Binary files differ
diff --git 
a/lib/resources/jquery.wikibase/themes/default/jquery.wikibase.statementview.RankSelector.css
 
b/lib/resources/jquery.wikibase/themes/default/jquery.wikibase.statementview.RankSelector.css
new file mode 100644
index 0000000..89a7db7
--- /dev/null
+++ 
b/lib/resources/jquery.wikibase/themes/default/jquery.wikibase.statementview.RankSelector.css
@@ -0,0 +1,68 @@
+.wb-rankselector {
+       border: none;
+       background: none transparent;
+       cursor: pointer;
+}
+
+.wb-rankselector.ui-state-disabled {
+       cursor: default;
+}
+
+.wb-rankselector .ui-icon {
+       /* @embed */ background-image: url(images/rankselector.png);
+       width: 6px;
+       height: 20px;
+}
+
+.wb-rankselector .ui-icon.wb-rankselector-preferred {
+       background-position: 0px;
+}
+
+.wb-rankselector .ui-icon.wb-rankselector-normal {
+       background-position: -7px;
+}
+
+.wb-rankselector .ui-icon.wb-rankselector-deprecated {
+       background-position: -14px;
+}
+
+.wb-rankselector.ui-state-disabled .ui-icon.wb-rankselector-preferred {
+       background-position: -21px;
+}
+
+.wb-rankselector.ui-state-disabled .ui-icon.wb-rankselector-normal {
+       background-position: -28px;
+}
+
+.wb-rankselector.ui-state-disabled .ui-icon.wb-rankselector-deprecated {
+       background-position: -35px;
+}
+
+.wb-rankselector.ui-state-default .ui-icon.wb-rankselector-preferred {
+       background-position: -42px;
+}
+
+.wb-rankselector.ui-state-default .ui-icon.wb-rankselector-normal {
+       background-position: -49px;
+}
+
+.wb-rankselector.ui-state-default .ui-icon.wb-rankselector-deprecated {
+       background-position: -56px;
+}
+
+.wb-rankselector.ui-state-hover .ui-icon.wb-rankselector-preferred {
+       background-position: -63px;
+}
+
+.wb-rankselector.ui-state-hover .ui-icon.wb-rankselector-normal {
+       background-position: -70px;
+}
+
+.wb-rankselector.ui-state-hover .ui-icon.wb-rankselector-deprecated {
+       background-position: -77px;
+}
+
+.wb-rankselector-menu {
+       position: absolute;
+       z-index: 2; /* Monobook #content has 2 */
+}
\ No newline at end of file
diff --git a/lib/resources/templates.php b/lib/resources/templates.php
index 20e8419..ea72a8f 100644
--- a/lib/resources/templates.php
+++ b/lib/resources/templates.php
@@ -103,20 +103,26 @@
        $templates['wb-statement'] =
 <<<HTML
 <div class="wb-statement wb-statementview $1">
-       <div class="wb-claim wb-claim-$2">
+       <div class="wb-statement-rank wb-rankselector 
ui-state-disabled">$2</div>
+       <div class="wb-claim wb-claim-$3">
                <div class="wb-claim-mainsnak" dir="auto">
-                       $3 <!-- wb-snak (Main Snak) -->
+                       $4 <!-- wb-snak (Main Snak) -->
                </div>
-               <div class="wb-claim-qualifiers 
wb-statement-qualifiers">$4</div>
+               <div class="wb-claim-qualifiers 
wb-statement-qualifiers">$5</div>
        </div>
-       $5 <!-- wikibase-toolbar -->
-       <div class="wb-statement-references-heading">$6</div>
+       $6 <!-- wikibase-toolbar -->
+       <div class="wb-statement-references-heading">$7</div>
        <div class="wb-statement-references">
-               $7 <!-- [0,*] wb-referenceview -->
+               $8 <!-- [0,*] wb-referenceview -->
        </div>
 </div>
 HTML;
 
+       $templates['wb-rankselector'] =
+<<<HTML
+<span class="ui-icon ui-icon-rankselector $1"></span>
+HTML;
+
        $templates['wb-referenceview'] =
 <<<HTML
 <div>
diff --git a/lib/resources/wikibase.css b/lib/resources/wikibase.css
index 1ffefd1..4fd93ca 100644
--- a/lib/resources/wikibase.css
+++ b/lib/resources/wikibase.css
@@ -735,6 +735,13 @@
        padding-bottom: 1em;
 }
 
+.wb-statement .wb-statement-rank {
+       position: absolute;
+       margin-left: 15.2em;
+       margin-top: 1em;
+       z-index: 1;
+}
+
 .wb-statement > .wikibase-toolbar {
        display: block;
 }
diff --git 
a/lib/tests/qunit/jquery.wikibase/jquery.wikibase.statementview.RankSelector.tests.js
 
b/lib/tests/qunit/jquery.wikibase/jquery.wikibase.statementview.RankSelector.tests.js
new file mode 100644
index 0000000..9982e20
--- /dev/null
+++ 
b/lib/tests/qunit/jquery.wikibase/jquery.wikibase.statementview.RankSelector.tests.js
@@ -0,0 +1,123 @@
+/**
+ * @licence GNU GPL v2+
+ * @author H. Snater < [email protected] >
+ */
+( function( $, mw, wb ) {
+       'use strict';
+
+       /**
+        * Initializes a rank selector suitable for testing.
+        *
+        * @return {jQuery.wikibase.statementview.RankSelector}
+        */
+       function createTestRankSelector( options ) {
+               var $node = $( '<span/>' )
+                       .addClass( 'test_rankselector' )
+                       .appendTo( 'body' );
+
+               var rankSelector = new $.wikibase.statementview.RankSelector( ( 
options || {} ), $node );
+               $node.data( 'test_rankselector', rankSelector );
+
+               return rankSelector;
+       }
+
+       QUnit.module( 'jquery.wikibase.statementview.RankSelector', 
window.QUnit.newWbEnvironment( {
+               teardown: function() {
+                       $( '.test_rankselector' ).each( function( i, node ) {
+                               var $node = $( node );
+                               $node.data( 'test_rankselector' ).destroy();
+                               $node.remove();
+                       } );
+               }
+       } ) );
+
+       QUnit.test( 'Instantiation', function( assert ) {
+               var rankSelector = createTestRankSelector( { rank: 
wb.Statement.RANK.DEPRECATED } );
+
+               assert.equal(
+                       wb.Statement.RANK.DEPRECATED,
+                       rankSelector.rank(),
+                       'Instantiated rank selector with "deprecated" rank'
+               );
+       } );
+
+       QUnit.test( 'Set and get rank via rank()', function( assert ) {
+               var rankSelector = createTestRankSelector();
+
+               rankSelector.rank( wb.Statement.RANK.DEPRECATED );
+
+               assert.equal(
+                       wb.Statement.RANK.DEPRECATED,
+                       rankSelector.rank(),
+                       'Set "deprecated" rank.'
+               );
+
+               rankSelector.rank( wb.Statement.RANK.PREFERRED );
+
+               assert.equal(
+                       wb.Statement.RANK.PREFERRED,
+                       rankSelector.rank(),
+                       'Set "preferred" rank.'
+               );
+
+               rankSelector.rank( wb.Statement.RANK.NORMAL );
+
+               assert.equal(
+                       wb.Statement.RANK.NORMAL,
+                       rankSelector.rank(),
+                       'Set "normal" rank.'
+               );
+       } );
+
+       QUnit.test( 'Set and get rank via option()', function( assert ) {
+               var rankSelector = createTestRankSelector();
+
+               rankSelector.option( 'rank', wb.Statement.RANK.DEPRECATED );
+
+               assert.equal(
+                       wb.Statement.RANK.DEPRECATED,
+                       rankSelector.option( 'rank' ),
+                       'Set "deprecated" rank.'
+               );
+
+               rankSelector.option( 'rank', wb.Statement.RANK.PREFERRED );
+
+               assert.equal(
+                       wb.Statement.RANK.PREFERRED,
+                       rankSelector.option( 'rank' ),
+                       'Set "preferred" rank.'
+               );
+
+               rankSelector.option( 'rank', wb.Statement.RANK.NORMAL );
+
+               assert.equal(
+                       wb.Statement.RANK.NORMAL,
+                       rankSelector.option( 'rank' ),
+                       'Set "normal" rank.'
+               );
+       } );
+
+       QUnit.test( 'disable(), enable(), isDisable()', function( assert ) {
+               var rankSelector = createTestRankSelector();
+
+               assert.ok(
+                       !rankSelector.isDisabled(),
+                       'Rank selector is enabled after instantiating.'
+               );
+
+               rankSelector.disable();
+
+               assert.ok(
+                       rankSelector.isDisabled(),
+                       'Disabled rank selector.'
+               );
+
+               rankSelector.enable();
+
+               assert.ok(
+                       !rankSelector.isDisabled(),
+                       'Enabled rank selector.'
+               );
+       } );
+
+} )( jQuery, mediaWiki, wikibase );
diff --git a/repo/Wikibase.i18n.php b/repo/Wikibase.i18n.php
index 77af682..48d8de4 100644
--- a/repo/Wikibase.i18n.php
+++ b/repo/Wikibase.i18n.php
@@ -73,6 +73,9 @@
        'wikibase-property-footer' => '', # do not translate or duplicate this 
message to other languages
        'wikibase-claimview-snak-tooltip' => 'Enter a value corresponding to 
the property named "$1". If the property has no designated value or the actual 
value is not known, you may choose an alternative to specifying a custom value 
by clicking the icon next to the value input box.',
        'wikibase-claimview-snak-new-tooltip' => 'After specifying a property 
you can enter a corresponding value. If the property has no designated value or 
the actual value is not known, you may choose an alternative to specifying a 
custom value by clicking the icon next to the value input box.',
+       'wikibase-statementview-rankselector-rank-preferred' => 'Preferred 
rank',
+       'wikibase-statementview-rankselector-rank-normal' => 'Normal rank',
+       'wikibase-statementview-rankselector-rank-deprecated' => 'Deprecated 
rank',
        'wikibase-statementview-referencesheading-pendingcountersubject' => 
'{{PLURAL:$1|source|sources}}',
        'wikibase-statementview-referencesheading-pendingcountertooltip' => 
'{{PLURAL:$1|One source|$1 sources}} not saved yet',
        'wikibase-snakview-property-input-placeholder' => 'property',
@@ -625,6 +628,9 @@
 Parameters:
 * $1 - the property name the user is about to edit a value of or add another 
value to',
        'wikibase-claimview-snak-new-tooltip' => 'Tooltip message displayed 
when hovering/clicking the help icon next to the save, cancel and remove links 
of a claim (see [[d:Wikidata:Glossary]]) when about to add a completely new 
claim which includes specifying the property.',
+       'wikibase-statementview-rankselector-rank-preferred' => 'Label of the 
[[d:Wikidata:Glossary#Rank-preferred|Preferred Rank]] item within the menu that 
allows adjusting a [[d:Wikidata:Glossary#Statement|Statement\'s]] 
[[d:Wikidata:Glossary#Rank|Rank]].',
+       'wikibase-statementview-rankselector-rank-normal' => 'Label of the 
[[d:Wikidata:Glossary#Rank-normal|Normal Rank]] item within the menu that 
allows adjusting a [[d:Wikidata:Glossary#Statement|Statement\'s]] 
[[d:Wikidata:Glossary#Rank|Rank]].',
+       'wikibase-statementview-rankselector-rank-deprecated' => 'Label of the 
[[d:Wikidata:Glossary#Rank-deprecated|Deprecated Rank]] item within the menu 
that allows adjusting a [[d:Wikidata:Glossary#Statement|Statement\'s]] 
[[d:Wikidata:Glossary#Rank|Rank]].',
        'wikibase-statementview-referencesheading-pendingcountersubject' => 
"Used in the heading for the references associated with a statement (see 
[[d:Wikidata:Glossary]]). The heading is giving information about how many 
references exist for that statement. This is just the label for the counter's 
subject: the number of references is not part of this message, and the word 
order is defined via {{msg-mw|wikibase-ui-pendingquantitycounter-nonpending}}.
 
 Parameters:
diff --git a/repo/includes/ClaimHtmlGenerator.php 
b/repo/includes/ClaimHtmlGenerator.php
index e6653ad..8f7d47a 100644
--- a/repo/includes/ClaimHtmlGenerator.php
+++ b/repo/includes/ClaimHtmlGenerator.php
@@ -5,6 +5,7 @@
 use DataValues\DataValue;
 use Wikibase\Lib\FormattingException;
 use Wikibase\Lib\PropertyNotFoundException;
+use Wikibase\Lib\Serializers\ClaimSerializer;
 use Wikibase\Lib\SnakFormatter;
 
 /**
@@ -81,10 +82,22 @@
 
                $mainSnakHtml = $this->getMainSnakHtml( $snakValueHtml );
 
+               $rankHtml = '';
+
+               if( is_a( $claim, 'Wikibase\Statement' ) ) {
+                       $claimSerializer = new ClaimSerializer();
+                       $serializedRank = $claimSerializer->serializeRank( 
$claim->getRank() );
+
+                       $rankHtml = wfTemplate( 'wb-rankselector',
+                               'wb-rankselector-' . $serializedRank
+                       );
+               }
+
                // @todo: Use 'wb-claim' or 'wb-statement' template accordingly
                // @todo: get rid of usage of global wfTemplate function
                $claimHtml = wfTemplate( 'wb-statement',
                        '', // additional classes
+                       $rankHtml,
                        $claim->getGuid(),
                        $mainSnakHtml,
                        '', // TODO: Qualifiers
diff --git a/repo/includes/EntityView.php b/repo/includes/EntityView.php
index d4214f9..dc2dc8e 100644
--- a/repo/includes/EntityView.php
+++ b/repo/includes/EntityView.php
@@ -281,6 +281,8 @@
                // make css available for JavaScript-less browsers
                $pout->addModuleStyles( array(
                        'wikibase.common',
+                       'jquery.ui.core',
+                       'jquery.wikibase.statementview',
                        'jquery.wikibase.toolbar',
                ) );
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7caadcd0189bc492c7f55766186231299fb833b1
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to