Dominic.sauer has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/207764

Change subject: WIP add js script for showing icons on claims
......................................................................

WIP add js script for showing icons on claims

Change-Id: I2677db9642e29d9e003fab11dba3ac38fca8a120
---
M WikidataQuality.php
M WikidataQualityHooks.php
A modules/ext.WikidataQuality.Script.js
3 files changed, 80 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataQuality 
refs/changes/64/207764/1

diff --git a/WikidataQuality.php b/WikidataQuality.php
old mode 100644
new mode 100755
index bec172e..8f58f85
--- a/WikidataQuality.php
+++ b/WikidataQuality.php
@@ -34,12 +34,25 @@
        // Register hooks for Unit Tests
        $GLOBALS['wgHooks']['UnitTestsList'][] = 
'WikidataQualityHooks::onUnitTestsList';
 
+    $GLOBALS['wgHooks']['BeforePageDisplay'][] = 
'WikidataQualityHooks::onBeforePageDisplay';
+
        // Define modules
        $GLOBALS['wgResourceModules']['SpecialCheckResultPage'] = array (
                'styles' => '/modules/SpecialCheckResultPage.css',
                'localBasePath' => __DIR__,
                'remoteExtPath' => 'WikidataQuality'
        );
+
+    $remoteExtPathParts = explode(
+        DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR, __DIR__, 2
+    );
+
+    $GLOBALS['wgResourceModules']['ext.WikidataQuality.Script'] = array(
+        'scripts'       => array( 'modules/ext.WikidataQuality.Script.js' ),
+        'dependencies'  => array( 'jquery.wikibase.entityselector' ),
+        'localBasePath' => __DIR__,
+        'remoteExtPath' => $remoteExtPathParts[1]
+    );
 });
 
 // Define database table names
diff --git a/WikidataQualityHooks.php b/WikidataQualityHooks.php
old mode 100644
new mode 100755
index 98ed20d..fb60ffd
--- a/WikidataQualityHooks.php
+++ b/WikidataQualityHooks.php
@@ -1,5 +1,7 @@
 <?php
 
+use Wikibase\Repo\WikibaseRepo;
+
 final class WikidataQualityHooks {
 
        /**
@@ -19,4 +21,22 @@
                        glob( __DIR__ . '/tests/phpunit/*Test.php' ) );
                return true;
        }
+
+    /**
+     * @param OutputPage $out
+     * @param Skin $skin
+     * @return bool
+     */
+    public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin 
) {
+
+        $entityNamespaceLookup = 
WikibaseRepo::getDefaultInstance()->getEntityNamespaceLookup();
+        $itemNamespace = $entityNamespaceLookup->getEntityNamespace( 
CONTENT_MODEL_WIKIBASE_ITEM );
+
+        if ( $out->getTitle()->getNamespace() !== $itemNamespace ) {
+            return true;
+        }
+
+        $out->addModules( 'ext.WikidataQuality.Script' );
+        return true;
+    }
 }
\ No newline at end of file
diff --git a/modules/ext.WikidataQuality.Script.js 
b/modules/ext.WikidataQuality.Script.js
new file mode 100755
index 0000000..aef0162
--- /dev/null
+++ b/modules/ext.WikidataQuality.Script.js
@@ -0,0 +1,47 @@
+/**
+ * override usual entityselector and replace _request and _create
+ * if a property is requested and we are on an Entity page.
+ *
+ * @see ui.suggester._request
+ */
+
+( function( $, util, mw ) {
+    'use strict';
+
+    if ( !mw.config.exists( 'wbEntityId' ) ) {
+        return;
+    }
+
+    $('.wikibase-snakview-value').append('<span class="wb-indicator"></span>');
+
+
+    var claim_guids = [];
+    $( ':wikibase-statementview' ).each( function() {
+        var claim_guid = $(this).data( 'statementview' 
).value().getClaim().getGuid();
+        /*var span_indicator = $(this).find( '.wb-indicator' ).first();
+        span_indicator.html( claim_guid );*/
+        claim_guids.push( claim_guid );
+    });
+
+
+    var request_data = {
+        action: 'query',
+        entity_id: mw.config.get( 'wbEntityId' )
+    };
+
+    /*mw.loader.using( 'mediawiki.api', function () {
+        ( new mw.Api() ).get( request_data ).done( function ( data ) {*/
+        var data = {"Q1001$155cb058-46db-9a96-a962-6b78fc3e33b9": "text to 
show"};
+            for ( var key in data ) {
+                if ( key in claim_guids ){
+                    var needed_class = "wikibase-statement-" + key;
+                    $( "." + needed_class ).find( '.wb-indicator' ).html( 
"violation" );
+                }
+
+            }
+       /* } );
+    } );*/
+
+
+
+}( jQuery, util, mediaWiki ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2677db9642e29d9e003fab11dba3ac38fca8a120
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikidataQuality
Gerrit-Branch: master
Gerrit-Owner: Dominic.sauer <dominic.sa...@yahoo.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to