Tpt has uploaded a new change for review. https://gerrit.wikimedia.org/r/296078
Change subject: Adds HTML classes based on rank to statement widgets ...................................................................... Adds HTML classes based on rank to statement widgets Allows to style statement widgets based on the rank e.g. highlight the prefered ranks Change-Id: I149114e4d65c55668b6dd684ae05f08c8f9e386e --- M view/resources/jquery/wikibase/jquery.wikibase.statementview.js M view/resources/templates.php M view/src/ClaimHtmlGenerator.php 3 files changed, 50 insertions(+), 12 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/78/296078/1 diff --git a/view/resources/jquery/wikibase/jquery.wikibase.statementview.js b/view/resources/jquery/wikibase/jquery.wikibase.statementview.js index 848c741..d793317 100644 --- a/view/resources/jquery/wikibase/jquery.wikibase.statementview.js +++ b/view/resources/jquery/wikibase/jquery.wikibase.statementview.js @@ -68,6 +68,13 @@ function() { // GUID return ( this.options.value && this.options.value.getClaim().getGuid() ) || 'new'; }, + function() { // Rank string + return this._getRankString( + this.options.value + ? this.options.value.getRank() + : wb.datamodel.Statement.RANK.NORMAL + ); + }, function() { // Rank selector return $( '<div/>' ); }, @@ -843,6 +850,28 @@ */ focus: function() { this._mainSnakSnakView.focus(); + }, + + /** + * Returns a `RANK`'s serialized string. + * + * @see wikibase.datamodel.Statement.RANK + * @ignore + * + * @param {number} rank + * @return {string|null} + */ + _getRankString: function( rank ) { + var rankString = null; + + $.each( wb.datamodel.Statement.RANK, function( rankId, i ) { + if ( rank === i ) { + rankString = rankId.toLowerCase(); + } + return rankString === null; + } ); + + return rankString; } } ); diff --git a/view/resources/templates.php b/view/resources/templates.php index e971bb4..48adf44 100644 --- a/view/resources/templates.php +++ b/view/resources/templates.php @@ -89,16 +89,16 @@ $templates['wikibase-statementview'] = <<<HTML -<div class="wikibase-statementview wikibase-statement-$1"> - <div class="wikibase-statementview-rankselector">$2</div> +<div class="wikibase-statementview wikibase-statement-$1 wikibase-statement-$2"> + <div class="wikibase-statementview-rankselector">$3</div> <div class="wikibase-statementview-mainsnak-container"> - <div class="wikibase-statementview-mainsnak" dir="auto"><!-- wikibase-snakview -->$3</div> - <div class="wikibase-statementview-qualifiers"><!-- wikibase-listview -->$4</div> + <div class="wikibase-statementview-mainsnak" dir="auto"><!-- wikibase-snakview -->$4</div> + <div class="wikibase-statementview-qualifiers"><!-- wikibase-listview -->$5</div> </div> - <!-- wikibase-toolbar -->$5 + <!-- wikibase-toolbar -->$6 <div class="wikibase-statementview-references-container"> - <div class="wikibase-statementview-references-heading">$6</div> - <div class="wikibase-statementview-references $8"><!-- wikibase-listview -->$7</div> + <div class="wikibase-statementview-references-heading">$7</div> + <div class="wikibase-statementview-references $9"><!-- wikibase-listview -->$8</div> </div> </div> HTML; diff --git a/view/src/ClaimHtmlGenerator.php b/view/src/ClaimHtmlGenerator.php index 9d4c670..12131a5 100644 --- a/view/src/ClaimHtmlGenerator.php +++ b/view/src/ClaimHtmlGenerator.php @@ -101,6 +101,7 @@ return $this->templateFactory->render( 'wikibase-statementview', $statement->getGuid(), + $this->getRankName( $statement->getRank() ), $rankHtml, $mainSnakHtml, $this->getHtmlForQualifiers( $statement->getQualifiers() ), @@ -232,11 +233,7 @@ */ private function getRankSelector( $rank ) { if ( !array_key_exists( $rank, $this->statementRankSelector ) ) { - $rankName = [ - Statement::RANK_DEPRECATED => 'deprecated', - Statement::RANK_NORMAL => 'normal', - Statement::RANK_PREFERRED => 'preferred' - ][ $rank ]; + $rankName = $this->getRankName( $rank ); // Messages: wikibase-statementview-rank-preferred, wikibase-statementview-rank-normal, // wikibase-statementview-rank-deprecated @@ -252,4 +249,16 @@ return $this->statementRankSelector[ $rank ]; } + /** + * @param int $rank + * + * @return string + */ + private function getRankName( $rank ) { + return [ + Statement::RANK_DEPRECATED => 'deprecated', + Statement::RANK_NORMAL => 'normal', + Statement::RANK_PREFERRED => 'preferred' + ][ $rank ]; + } } -- To view, visit https://gerrit.wikimedia.org/r/296078 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I149114e4d65c55668b6dd684ae05f08c8f9e386e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Tpt <thoma...@hotmail.fr> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits