jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/348080 )
Change subject: Add user script to include reports on item pages
......................................................................
Add user script to include reports on item pages
Bug: T97018
Change-Id: Icd078b1cf2f4279400080258e303c98dc4684701
---
A docs/user.js
1 file changed, 83 insertions(+), 0 deletions(-)
Approvals:
Jonas Kress (WMDE): Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/user.js b/docs/user.js
new file mode 100644
index 0000000..b8d01e5
--- /dev/null
+++ b/docs/user.js
@@ -0,0 +1,83 @@
+/* globals mw, $, OO */
+
+( function( mw, $, OO ) {
+ 'use strict';
+ var entityJson, entityId;
+
+ function buildWidget( $reports ) {
+ var widget = new OO.ui.PopupButtonWidget( {
+ icon: 'alert',
+ iconTitle: 'This statement violates some constraints.',
+ label: $reports.children().length.toString(),
+ framed: false,
+ popup: {
+ $content: $reports,
+ width: 400,
+ padded: true,
+ head: true,
+ label: $( '<h4>' ).text( 'Constraint report' )
+ }
+ } );
+ widget.$element.css( 'margin-left', '0.5em' );
+ widget.popup.$element.css( 'z-index', 2 ); // prevent collision
with rank selector and property grey field; TODO better way to do this?
+ return widget;
+ }
+
+ function buildReport( result ) {
+ var report;
+ if ( result.status === 'violation' ) {
+ report = 'Status: ' + result.status;
+ if ( result[ 'message-html' ] ) {
+ report += '<br>Message: ' + result[
'message-html' ];
+ }
+ report += '<br>Constraint: ' + result.constraint.type;
+ if ( result.constraint.detailMessage ) {
+ report += '<br>' +
result.constraint.detailMessage;
+ }
+ return new OO.ui.PanelLayout( {
+ expanded: false,
+ framed: true,
+ padded: true,
+ $content: $( '<div>' )
+ .addClass( 'wbqc-report' )
+ .html( report )
+ } ).$element;
+ } else {
+ return null;
+ }
+ }
+
+ function addReportsToStatement( entityData, $statement ) {
+ var claimId = $statement.parents( '.wikibase-statementview' )[
0 ].className.replace( /^.*wikibase-statement-([A-Z][0-9]*\$[0-9a-fA-F-]*).*$/,
'$1' ),
+ propertyId = $statement.parents(
'.wikibase-statementgroupview' )[ 0 ].id,
+ results, $reports,
+ i, $report;
+ if ( !( propertyId in entityData && claimId in entityData[
propertyId ] ) ) {
+ return;
+ }
+ results = entityData[ propertyId ][ claimId ];
+ $reports = $( '<div>' ).addClass( 'wbqc-reports' );
+
+ for( i = 0; i < results.length; i++ ) {
+ $report = buildReport( results[ i ] );
+ if ( $report !== null ) {
+ $reports.append( $report );
+ }
+ }
+
+ if ( $reports.children().length > 0 ) {
+ $statement.append( buildWidget( $reports ).$element );
+ }
+ }
+
+ entityJson = mw.config.get( 'wbEntity' );
+ if ( entityJson !== null ) {
+ entityId = JSON.parse( entityJson ).id;
+ mw.loader.using( [ 'oojs-ui-core', 'oojs-ui-widgets' ] ).done(
function () {
+ $.getJSON(
'../api.php?action=wbcheckconstraints&format=json&id=' + entityId, function(
data ) {
+ $( '.wikibase-statementgroupview
.wikibase-statementview-mainsnak-container .wikibase-snakview-value' )
+ .each( function () {
addReportsToStatement( data.wbcheckconstraints[ entityId ], $( this ) ); } );
+ } );
+ } );
+ }
+} )( mw, $, OO );
--
To view, visit https://gerrit.wikimedia.org/r/348080
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icd078b1cf2f4279400080258e303c98dc4684701
Gerrit-PatchSet: 14
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Lydia Pintscher <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits