User:PAC2/articlebox.js

mw.loader.using('mediawiki.util', function {

if (mw.config.get('wgNamespaceNumber') == 0) {

$("#p-navigation").append("Article box  ") ;

var articlebox = function ($) {

mw.util.addPortletLink( portletId = 'p-articlebox', href = 'https://tools.wmflabs.org/reasonator/?q=' + mw.config.get('wgWikibaseItemId') + '&lang=en', text = 'Reasonator', id = 'p-reasonator', tooltip = 'UI for Wikidata' );

mw.util.addPortletLink( portletId = 'p-articlebox', href = 'https://tools.wmflabs.org/pageviews/?project=en.wikipedia.org&platform=all-access&agent=user&range=latest-90&pages=' + mw.config.get('wgPageName'), text = 'Pageviews', id = 'p-pageviews', tooltip = 'Number of views') ;

mw.util.addPortletLink( portletID = 'p-articlebox', href = 'https://tools.wmflabs.org/xtools-articleinfo/index.php?project=en.wikipedia.org&article=' + mw.config.get( 'wgPageName' ), text = 'Articleinfo', id = 'p-xtools-article', tooltip = 'xtools' );

mw.util.addPortletLink( portledID = 'p-articlebox', href = 'http://www.google.com/search?num=20&safe=off&q=site%3Aen.wikipedia.org+\"' + mw.util.rawurlencode( mw.config.get( 'wgTitle' ) ) + '\"&btnG=Search', text = 'Search ' + mw.config.get( 'wgTitle' ) + ' in WikiPedia', id = 'p-googlewp', tooltip = 'Google search in Wikipédia' );

mw.util.addPortletLink( portledID = 'p-articlebox', href = 'http://www.google.com/search?&q=\"' + mw.util.rawurlencode( mw.config.get( 'wgTitle' ) ) + '\"', text = 'Search ' + mw.config.get( 'wgTitle' ) + ' on Google', id = 'p-google', tooltip = 'Google search' );

mw.util.addPortletLink( portletID = 'p-articlebox', href = 'https://scholar.google.com/scholar?hl=en&q=\"' + mw.util.rawurlencode( mw.config.get( 'wgTitle' ) ) + '\"&btnG=&lr=', text = 'Search ' + mw.config.get( 'wgTitle' ) + ' in Google Scholar', id = 'p-scholar', tooltip = 'Google Scholar Search' );

mw.util.addPortletLink( portletID = 'p-articlebox', href = 'https://commons.wikimedia.org/w/index.php?search=\"' + mw.util.rawurlencode( mw.config.get( 'wgTitle' ) ) + '\"', text = 'Search ' + mw.config.get( 'wgTitle' ) + ' in Commons', id = 'p-commons', tooltip = 'Google search in Wikimedia Commons' );

var prose = new XMLHttpRequest;

prose.open("GET", "https://xtools.wmcloud.org/api/page/prose/en.wikipedia.org/" + mw.config.get( 'wgPageName' ), false);

prose.send;

var prosecontent = JSON.parse(prose.responseText) ;

var articleinfo = new XMLHttpRequest; articleinfo.open("GET", "https://xtools.wmcloud.org/api/page/articleinfo/en.wikipedia.org/" + mw.config.get( 'wgPageName' ), false);

articleinfo.send;

var articleinfocontent = JSON.parse(articleinfo.responseText) ;

mw.util.addPortletLink( portletID = 'p-articlebox', href = "https://xtools.wmflabs.org/api/page/articleinfo/en.wikipedia.org/" + mw.config.get( 'wgPageName' ), text = articleinfocontent.revisions.toLocaleString('en-EN') + ' editions', id = 'p-revisions');

mw.util.addPortletLink( portletID = 'p-articlebox', href = "https://xtools.wmflabs.org/api/page/articleinfo/en.wikipedia.org/" + mw.config.get( 'wgPageName' ), text = articleinfocontent.editors.toLocaleString('fr-FR') + ' editors', id = 'p-editors' );

mw.util.addPortletLink( portletID = 'p-articlebox', href = "https://xtools.wmflabs.org/api/page/prose/en.wikipedia.org/" + mw.config.get( 'wgPageName' ), text = prosecontent.words.toLocaleString('fr-FR') + ' words', id = 'p-words' );

mw.util.addPortletLink( portletID = 'p-articlebox', href = "https://xtools.wmflabs.org/api/page/prose/en.wikipedia.org/" + mw.config.get( 'wgPageName' ), text = prosecontent.references.toLocaleString('fr-FR') + ' references', id = 'p-references' );

var whatlinkshere = new mw.Api;

whatlinkshere.get( { action: 'query', prop: 'linkshere', titles: mw.config.get( 'wgPageName' ), format: 'json', formatversion: 2, lhnamespace: 0, lhlimit: 500, } ).then( function( data ) { var nbLinks = data.query.pages[ 0 ].linkshere.length ; mw.util.addPortletLink( portletID = 'p-articlebox', href = "https://en.wikipedia.org/wiki/Special:WhatLinksHere/" + mw.config.get( 'wgPageName' ), text = nbLinks.toLocaleString('en-EN') + ' linked pages', id = 'p-nblinks' ); } );

}

$(document).ready(articlebox) ; }

});