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

Change subject: Check constraint parameters on property pages
......................................................................

Check constraint parameters on property pages

This updates the gadget to use the new wbcheckconstraintparameters API
module to check constraint statements on a property page.

Change-Id: Ief70ee62f3d98d9712c927064a9ddb937bd84a33
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M modules/gadget.css
M modules/gadget.js
5 files changed, 73 insertions(+), 6 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints
 refs/changes/14/364214/1

diff --git a/extension.json b/extension.json
index 990fdf0..184f740 100644
--- a/extension.json
+++ b/extension.json
@@ -52,7 +52,9 @@
                "wikibase.quality.constraints.ui": {
                        "messages": [
                                "wbqc-potentialissues-short",
-                               "wbqc-potentialissues-long"
+                               "wbqc-potentialissues-long",
+                               "wbqc-badparameters-short",
+                               "wbqc-badparameters-long"
                        ]
                },
                "wikibase.quality.constraints.gadget": {
diff --git a/i18n/en.json b/i18n/en.json
index 14ddb2a..f3478ed 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -31,6 +31,8 @@
 
        "wbqc-potentialissues-short": "Potential issues",
        "wbqc-potentialissues-long": "This statement has some potential 
issues.",
+       "wbqc-badparameters-short": "Bad parameters",
+       "wbqc-badparameters-long": "This constraint statement has some invalid 
parameters.",
 
        "apihelp-wbcheckconstraints-description": "Performs constraint checks 
on any entity you want and returns the result.",
        "apihelp-wbcheckconstraints-summary": "Performs constraint checks on 
any entity you want and returns the result.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index bee17cb..13a0699 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -32,6 +32,8 @@
        "wbqc-constraintreport-no-parameter": "Text that is displayed when 
there was no value for a parameter given.\n{{Identical|None}}",
        "wbqc-potentialissues-short": "Headline of the constraint report popup 
shown on statements with constraint violations. Should be easy to understand 
for users, and convey that the reported violations are not always errors, but 
should be thought of as hints to the user that something might be 
wrong.\n\n{{Related|wbqc-constraintreport}}",
        "wbqc-potentialissues-long": "Title for the icon shown on statements 
with constraint violations, usually displayed by the browser when the user 
hovers over the icon with the mouse 
cursor.{{Related|wbqc-potentialissues-short}}",
+       "wbqc-badparameters-short": "Headline of the constraint parameter 
report popup shown on constraint statements with invalid constraint 
parameters.",
+       "wbqc-badparameters-long": "Title for the icon shown on constraint 
statements with invalid constraint parameters, usually displayed by the browser 
when the user hovers over the icon with the mouse 
cursor.{{Related|wbqc-badparameters-short}}",
        "apihelp-wbcheckconstraints-description": 
"{{doc-apihelp-description|wbcheckconstraints}}",
        "apihelp-wbcheckconstraints-summary": 
"{{doc-apihelp-summary|wbcheckconstraints}}",
        "apihelp-wbcheckconstraints-param-id": 
"{{doc-apihelp-param|wbcheckconstraints|id}}",
diff --git a/modules/gadget.css b/modules/gadget.css
index 73b9bc1..8e26c50 100644
--- a/modules/gadget.css
+++ b/modules/gadget.css
@@ -3,7 +3,8 @@
 .wbqc-reports-button {
        margin-left: 0.5em;
 }
-.wbqc-report {
+.wbqc-report,
+.wbqc-parameter-report {
        border-top: 1px solid #eaecf0; /* Base80 */
 }
 .wbqc-constraint-type-help {
diff --git a/modules/gadget.js b/modules/gadget.js
index 0c5d051..c08af01 100644
--- a/modules/gadget.js
+++ b/modules/gadget.js
@@ -3,10 +3,11 @@
 
        var entityId;
 
-       function buildWidget( reports ) {
+       function buildWidget( reports, messageKey, flags /* = '' */ ) {
                var widget = new OO.ui.PopupButtonWidget( {
                        icon: 'alert',
-                       iconTitle: mw.message( 'wbqc-potentialissues-long' 
).text(),
+                       iconTitle: mw.message( 'wbqc-' + messageKey + '-long' 
).text(),
+                       flags: flags || '',
                        framed: false,
                        classes: [ 'wbqc-reports-button' ],
                        popup: {
@@ -19,7 +20,7 @@
                                width: 400,
                                padded: true,
                                head: true,
-                               label: $( '<strong>' ).text( mw.message( 
'wbqc-potentialissues-short' ).text() )
+                               label: $( '<strong>' ).text( mw.message( 
'wbqc-' + messageKey + '-short' ).text() )
                        }
                } );
                widget.popup.$element.css( 'z-index', 2 ); // prevent collision 
with rank selector and property grey field
@@ -64,6 +65,19 @@
                }
        }
 
+       function buildParameterReport( problem ) {
+               var $report = $( '<div>' )
+                       .addClass( 'wbqc-parameter-report' );
+               $report.append(
+                       $( '<p>' ).html( problem[ 'message-html' ] )
+               );
+
+               return new OO.ui.PanelLayout( {
+                       expanded: false,
+                       $content: $report
+               } );
+       }
+
        function addReportsToStatement( entityData, $statement ) {
                var match = $statement.parents( '.wikibase-statementview' )[ 0 
].className.match(
                                /\bwikibase-statement-([^\s$]+\$[\dA-F-]+)\b/i
@@ -95,7 +109,42 @@
                        if ( $target.length === 0 ) {
                                $target = $statement;
                        }
-                       $target.append( buildWidget( reports ).$element );
+                       $target.append( buildWidget( reports, 'potentialissues' 
).$element );
+               }
+       }
+
+       function addParameterReports( parameterReports ) {
+               var constraintId,
+                       status,
+                       problems,
+                       reports,
+                       i,
+                       report,
+                       $statement,
+                       $target;
+
+               for ( constraintId in parameterReports ) {
+                       status = parameterReports[ constraintId ].status;
+                       if ( status === 'okay' ) {
+                               continue;
+                       }
+
+                       problems = parameterReports[ constraintId ].problems;
+                       reports = [];
+                       for ( i = 0; i < problems.length; i++ ) {
+                               report = buildParameterReport( problems[ i ] );
+                               if ( report !== null ) {
+                                       reports.push( report );
+                               }
+                       }
+
+                       $statement = $( '.wikibase-statement-' + 
constraintId.replace( /\$/g, '\\$' ) +
+                                                               ' 
.wikibase-statementview-mainsnak .wikibase-snakview-value' );
+                       $target = $statement.find( '.valueview-instaticmode' );
+                       if ( $target.length === 0 ) {
+                               $target = $statement;
+                       }
+                       $target.append( buildWidget( reports, 'badparameters', 
'warning' ).$element );
                }
        }
 
@@ -126,6 +175,17 @@
                                .each( function () { addReportsToStatement( 
data.wbcheckconstraints[ entityId ], $( this ) ); } );
                } );
 
+               if ( /^P/.test( entityId ) ) {
+                       api.get( {
+                               action: 'wbcheckconstraintparameters',
+                               format: 'json',
+                               uselang: lang,
+                               propertyid: entityId
+                       } ).then( function( data ) {
+                               addParameterReports( 
data.wbcheckconstraintparameters[ entityId ] );
+                       } );
+               }
+
                mw.hook( 'wikibase.statement.saved' ).add( function( entityId, 
statementId ) {
                        api.get( {
                                action: 'wbcheckconstraints',

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ief70ee62f3d98d9712c927064a9ddb937bd84a33
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
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