Jump to content

MediaWiki:Gadget-AuthorityControl.js

From Wikidata
Revision as of 09:21, 7 December 2014 by ValterVB (talk | contribs) (add NSZL)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* AuthorityControl.js
 * Provides a link to various Authority Control tools (VIAF, GND, etc.) for Wikidata statements that
 * feature certain properties.
 *
 * Original gadget coded by [[User:Ricordisamoa]]
 */
( function ( mw, $ ) {

if ( mw.config.get( 'wgNamespaceNumber' ) !== 0 || !mw.config.exists( 'wbEntityId' ) ) {
	// Only item pages feature appropriate statements.
	return;
}

var BASE_LANGUAGE = mw.config.get( 'wgUserLanguage' ).replace( /[^a-z].*/, '' );

var PROPERTIES = {
	212: mw.util.getUrl( 'Special:BookSources' ) + '/$1', // ISBN-13
	213: 'http://www.isni.org/$1', // ISNI
	214: '//viaf.org/viaf/$1/', // VIAF
	220: 'http://www-01.sil.org/iso639-3/documentation.asp?id=$1', // ISO 639-3
	225: '//species.wikimedia.org/wiki/$1', // taxon name
	227: 'http://d-nb.info/gnd/$1', // GND
	231: '//tools.wmflabs.org/magnustools/cas.php?cas=$1', // CAS
	233: 'http://chemapps.stolaf.edu/jmol/jmol.php?model=$1', // SMILES molecular spec
	234: 'http://chemapps.stolaf.edu/jmol/jmol.php?&model=InChI=$1', // InChl chem ID
	235: '//www.ncbi.nlm.nih.gov/sites/entrez?cmd=search&db=pccompound&term=%22$1%22[InChIKey]', // InChIKey
	236: '//www.worldcat.org/search?fq=x0:jrnl&q=n2:$1', // ISSN
	243: '//www.worldcat.org/oclc/$1?lang=' + BASE_LANGUAGE, // OCLC
	244: 'http://lccn.loc.gov/$1', // LCCN
	245: '//www.getty.edu/vow/ULANFullDisplay?find=&role=&nation=&subjectid=$1', // ULAN
	246: 'http://www.iupac.org/highlights/periodic-table-of-the-elements.html', // element symbol (table)
	247: 'http://nssdc.gsfc.nasa.gov/nmc/spacecraftDisplay.do?id=$1', // NSSDC ID
	267: 'http://www.whocc.no/atc_ddd_index/?code=$1', // ATC code
	268: 'http://catalogue.bnf.fr/ark:/12148/cb$1/PUBLIC', // BNF
	269: 'http://www.idref.fr/$1', // SUDOC
	270: 'http://opac.calis.edu.cn/aopac/ajsp/detail.jsp?actionfrom=1&actl=CAL++$1%23', // CALIS
	271: 'http://ci.nii.ac.jp/author/$1', // CiNii
	303: 'http://www.entente-ee.com/deutsch/sparten/tauben/Dateien/2012/ELRT%2011-06-2012.pdf', // EE breed number (list)
	345: 'http://www.imdb.com/Name?$1', // IMDb
	347: 'http://www.culture.gouv.fr/public/mistral/joconde_fr?ACTION=CHERCHER&FIELD_1=REF&VALUE_1=$1', // Joconde
	349: 'http://id.ndl.go.jp/auth/ndlna/$1', // NDL
	350: '//rkd.nl/' + ( $.inArray( BASE_LANGUAGE.substring( 0, 2 ), ['en', 'nl'] ) !== -1 ? BASE_LANGUAGE : 'en' ) + '/images/$1', // RKDimages
	351: 'http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=gene&cmd=retrieve&dopt=default&list_uids=$1', // Entrez Gene
	352: 'http://www.uniprot.org/uniprot/$1', // Uniprot
	353: 'http://www.genenames.org/data/hgnc_data.php?match=$1', // HGNC/HUGO gene symbol
	354: 'http://www.genenames.org/data/hgnc_data.php?hgnc_id=$1', // HGNC
	356: 'http://dx.doi.org/$1', // DOI
	359: 'http://monumentenregister.cultureelerfgoed.nl/php/main.php?cAction=search&cOffset=1&cLimit=25&oOrder=ASC&cSubmit=1&sCompMonNr=$1', // Rijksmonument
	373: '//commons.wikimedia.org/wiki/Category:$1', // Commons category
	374: 'http://www.insee.fr/fr/bases-de-donnees/esl/comparateur.asp?codgeo=com-$1', // INSEE commune code
	377: 'http://www.n2yo.com/satellite/?s=$1', // SCN
	380: 'http://www.culture.gouv.fr/public/mistral/merimee_fr?ACTION=CHERCHER&FIELD_1=REF&VALUE_1=$1', // Mérimée
	381: '//tools.wmflabs.org/heritage/api/api.php?action=search&format=html&srcountry=ch&srid=$1', // KGS identifier
	396: 'http://id.sbn.it/af/$1', // SBN
	402: '//www.openstreetmap.org/relation/$1', // OpenStreetmap
	409: 'http://nla.gov.au/anbd.aut-an$1', // NLA
	424: '//$1.wikipedia.org', // Wikimedia language code
	428: 'http://www.ipni.org/ipni/advPlantNameSearch.do?find_includePublicationAuthors=on&find_includePublicationAuthors=off&find_includeBasionymAuthors=on&find_includeBasionymAuthors=off&find_rankToReturn=all&output_format=normal&find_authorAbbrev=$1', // botanist author abbreviation
	434: '//musicbrainz.org/artist/$1', // MusicBrainz Artist ID
	435: '//musicbrainz.org/work/$1', // MusicBrainz Work ID
	436: '//musicbrainz.org/release-group/$1', // MusicBrainz Release Group ID
	454: 'http://' + ( $.inArray( BASE_LANGUAGE, ['de', 'en', 'fr'] ) !== -1 ? BASE_LANGUAGE : 'en' ) + '.structurae.de/structures/data/index.cfm?ID=$1', // Structurae ID
	455: 'http://www.emporis.com/' + ( $.inArray( BASE_LANGUAGE, ['de', 'en', 'fr'] ) !== -1 ? BASE_LANGUAGE : 'en' ) + '/wm/bu/?id=$1', // Emporis ID
	458: '//www.marinetraffic.com/ais/details/ships/$1', // IMO number
	464: 'http://www.legifrance.gouv.fr/UnTexteDeJorf.do?numjo=$1', // NOR (French law)
	476: 'http://eur-lex.europa.eu/LexUriServ/LexUriServ.do?uri=CELEX:$1:' + ( $.inArray( BASE_LANGUAGE, ['bg', 'es', 'cs', 'da', 'de', 'et', 'el', 'en', 'fr', 'ga', 'it', 'lv', 'lt', 'hu', 'mt', 'nl', 'pl', 'pt', 'ro', 'ro', 'sk', 'sl', 'fi', 'sv'] ) !== -1 ? BASE_LANGUAGE : 'en' ) + ':NOT', // CELEX (European law)
	477: 'http://www.historicplaces.ca/' + ( $.inArray( BASE_LANGUAGE, ['en', 'fr'] ) !== -1 ? BASE_LANGUAGE : 'en' ) + '/rep-reg/place-lieu.aspx?id=$1', // Historic Places (Canada)
	480: 'http://www.filmaffinity.com/' + ( $.inArray( BASE_LANGUAGE, ['en', 'es'] ) !== -1 ? BASE_LANGUAGE : 'en' ) + '/film$1.html', // Filmaffinity
	481: 'http://www.culture.gouv.fr/public/mistral/palissy_fr?ACTION=CHERCHER&FIELD_1=REF&VALUE_1=$1', // Palissy
	486: '//www.nlm.nih.gov/cgi/mesh/2013/MB_cgi?field=uid&term=$1', // Mesh
	492: '//omim.org/entry/$1', // OMIM
	493: 'http://www.icd9data.com/getICD9Code.ashx?icd9=$1', // ICD 9
	494: 'http://apps.who.int/classifications/icd10/browse/2010/en#/$1', // ICD 10
	496: 'http://orcid.org/$1', // ORCID
	497: 'http://db1.ihp.sinica.edu.tw/cbdbc/cbdbkm' + ( $.inArray( BASE_LANGUAGE.substring( 0, 2 ), ['zh'] ) !== -1 ? '' : 'eng' ) + '?~~AAA$1', // China Biographical Database
	498: 'http://www.currency-iso.org/dam/downloads/table_a1.xls', // ISO 4217 currency codes (list)
	502: 'http://www.nhc.noaa.gov/archive/$1', // HURDAT identifier
	508: 'http://thes.bncf.firenze.sbn.it/termine.php?id=$1', //BNFC
	535: 'http://www.findagrave.com/cgi-bin/fg.cgi?page=gr&GRid=$1', // Find a Grave
	536: 'http://www.atpworldtour.com/Tennis/Players/$1.aspx', // ATP id
	539: 'http://www.culture.gouv.fr/public/mistral/museo_fr?ACTION=CHERCHER&FIELD_98=REF&VALUE_98=$1', // Museofile
	549: 'http://genealogy.math.ndsu.nodak.edu/id.php?id=$1', // MGP
	557: 'http://www.diseasesdatabase.com/ddb$1.htm', // DiseasesDB
	563: 'http://www.progenetix.org/cgi-bin/subsets.cgi?project=progenetix&subsetType=ICDM&ICDMcodes_m=$1', // ICD-O
	586: 'http://www.ipni.org/ipni/idAuthorSearch.do?id=$1', // IPNI author
	587: 'http://www.marinetraffic.com/en/ais/details/ships/$1', // MMSI author
	590: '//geonames.usgs.gov/pls/gnispublic/f?p=gnispq:3:::NO::P3_FID:$1', // GNIS
	592: 'https://www.ebi.ac.uk/chembl/compound/inspect/$1', // ChEMBL
	593: '//www.ncbi.nlm.nih.gov/homologene?term=$1', // HomoloGene
	594: 'http://www.ensembl.org/Homo_sapiens/Gene/Summary?db=core;g=$1', // Ensembl ID
	597: 'http://www.wtatennis.com/players/player/$1', // WTA id
	599: 'http://www.itftennis.com/procircuit/players/player/profile.aspx?playerid=$1', // ITF id
	600: '//appdb.winehq.org/appview.php?iAppId=$1', // Wine AppDB-ID
	604: '//www.nlm.nih.gov/medlineplus/ency/article/$1.htm', // MedlinePlus
	625: '//tools.wmflabs.org/geohack/geohack.php?language=' + BASE_LANGUAGE + '&params=$1', // coordinates
	627: 'http://www.iucnredlist.org/details/$1/0', // IUCN
	628: 'http://www.codexalimentarius.net/gsfaonline/additives/results.html?searchBy=ins&ins=$1', // E Number
	630: 'http://www.v2asp.paris.fr/commun/v2asp/v2/nomenclature_voies/Voieactu/$1.nom.htm', // Paris streets
	633: 'http://www.patrimoine-culturel.gouv.qc.ca/rpcq/detail.do?methode=consulter&id=$1&type=bien', // Quebec protected places
	637: '//www.ncbi.nlm.nih.gov/protein/$1', // RefSeq Protein ID
	638: 'http://www.rcsb.org/pdb/explore/explore.do?structureId=$1', // PDB ID
	640: 'http://www.culture.gouv.fr/public/mistral/leonore_fr?ACTION=CHERCHER&FIELD_1=COTE&VALUE_1=$1', // Léonore
	646: 'http://www.freebase.com$1', // Freebase ID (note that property values are supposed to start with slashes)
	648: 'https://openlibrary.org/books/$1', // Open Library
	650: '//rkd.nl/' + ( $.inArray( BASE_LANGUAGE.substring( 0, 2 ), ['en', 'nl'] ) !== -1 ? BASE_LANGUAGE : 'en' ) + '/artists/$1', // RKDartists
	651: 'http://www.biografischportaal.nl/persoon/$1', // BPN
	652: 'http://fdasis.nlm.nih.gov/srs/srsdirect.jsp?regno=$1', // UNII
	653: '//www.ncbi.nlm.nih.gov/pubmedhealth/$1', // PubMed Health
	661: 'http://www.chemspider.com/Chemical-Structure.$1', // Chemspider
	662: 'https://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=$1', // PubChem ID
	665: 'http://www.kegg.jp/entry/$1', // KEGG ID
	668: '//www.ncbi.nlm.nih.gov/books/$1', // GeneReviews ID
	671: 'http://www.informatics.jax.org/marker/MGI:$1', // Mouse Gene Informatics ID
	673: 'http://emedicine.medscape.com/article/$1', // eMedicine
	675: 'http://books.google.com/books?id=$1', // Google Books identifier
	677: 'http://drusop.nature.cz/ost/chrobjekty/chrob_find/index.php?frame=1&h_kod=$1', // ÚSOP Code
	683: 'https://www.ebi.ac.uk/chebi/searchId.do?chebiId=CHEBI:$1', // ChEBI
	685: '//www.ncbi.nlm.nih.gov/taxonomy/$1', // NCBI Taxonomy ID
	686: 'http://amigo.geneontology.org/cgi-bin/amigo/term_details?term=GO:$1', // Gene Ontology ID
	687: 'http://biodiversitylibrary.org/page/$1', // BHL Page ID
	691: 'http://aut.nkp.cz/$1', // NK CR
	698: '//www.ncbi.nlm.nih.gov/pubmed/?term=$1', // PubMed ID
	699: 'http://disease-ontology.org/term/DOID%3A$1', // diseases ontology ID
	701: 'http://dodis.ch/$1', // DODIS
	709: 'http://hsewsf.sedsh.gov.uk/hslive/hsstart?P_HBNUM=$1', // Historic Scotland ID
	715: 'http://www.drugbank.ca/drugs/DB$1', // Drugbank ID
	716: 'http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=$1', // JPL Small-Body Database
	717: 'http://newton.dm.unipi.it/neodys/index.php?pc=2.1.0&o=$1', // MP
	718: 'http://canmore.rcahms.gov.uk/en/site/$1/details/', // Canmore ID
	721: 'http://www.mosclassific.ru/mClass/okato_view.php?text=$1', // OKATO
	723: 'http://www.dbnl.org/auteurs/auteur.php?id=$1', // DBNL ID
	724: 'https://archive.org/details/$1', // Internet Archive ID
	727: 'http://www.europeana.eu/portal/record/$1.html', // Europeana ID
	731: '//www.bgr.de/app/litholex/gesamt_ausgabe_neu.php?id=$1', // Litholex ID
	732: '//www.bgs.ac.uk/Lexicon/lexicon.cfm?pub=$1', // BGX Lexicon ID
	733: 'http://www.dinoloket.nl/$1', // Dinoloket ID
	745: 'http://www.ins-bremen.de/pbub/autor-werke.php?ID=$1&START=1&ORD=JAHR', // PBuB identifier
	757: 'http://whc.unesco.org/' + ( $.inArray( BASE_LANGUAGE, ['en', 'fr'] ) !== -1 ? BASE_LANGUAGE : 'en' ) + '/list/$1', // UNESCO World Heritage
	758: 'http://www.kulturminnesok.no/kulturminnesok/kulturminne/?LOK_ID=$1', // Kulturminne
	759: 'https://hermis.alberta.ca/ARHP/Details.aspx?DeptID=1&ObjectID=$1', // Alberta Historic Places ID
	761: 'http://www.viss.lansstyrelsen.se/Waters.aspx?waterEUID=SE$1', // VISS
	763: 'http://www.gov.pe.ca/hpo/app.php?nav=details&p=$1&lang=' + ( $.inArray( BASE_LANGUAGE.substring( 0, 2 ), ['fr'] ) !== -1 ? 'F' : 'E' ), // Prince Edward Island Historic Places ID
	764: 'http://classif.spb.ru/classificators/view/tma.php?st=A&kr=1&kod=$1', // OKTMO
	781: 'http://www.sikart.ch/KuenstlerInnen.aspx?id=$1&lng=' + ( $.inArray( BASE_LANGUAGE, ['de', 'fr', 'it'] ) !== -1 ? BASE_LANGUAGE : 'en' ), // Sikart
	791: 'http://dispatch.opac.d-nb.de/DB=1.2/CMD?ACT=SRCHA&IKT=8529&TRM=$1', // ISIL-ID
	804: '//geonames.usgs.gov/pls/gnispublic/f?p=gnispq:5:::NO::P5_ANTAR_ID:$1', // GNIS Antarctica ID
	809: 'http://protectedplanet.net/sites/$1', // WDPA ID
	815: 'http://www.itis.gov/servlet/SingleRpt/SingleRpt?search_topic=TSN&search_value=$1', // ITIS TSN
	818: 'http://arxiv.org/abs/$1', // arXiv
	819: 'http://adsabs.harvard.edu/abs/$1', // ADS bibcode
	821: 'http://www4.rncan.gc.ca/search-place-names/unique.php?id=$1', // CGNDB ID
	824: 'http://www.lpi.usra.edu/meteor/metbull.php?code=$1', // ADS bibcode
	827: 'http://www.bbc.co.uk/programmes/$1', // BBC Identifier
	829: '//oeis.org/$1', // On-Line Encyclopedia of Integer Sequences
	830: 'http://eol.org/pages/$1', // EOL
	838: 'http://www.biolib.cz/en/taxon/id$1', // BioLib
	839: 'http://imslp.org/wiki/$1', // IMSLP ID
	842: 'http://fossilworks.org/bridge.pl?a=taxonInfo&taxon_no=$1', // Fossilworks ID
	845: 'http://heritageapp.cyr.gov.sk.ca/public/index.cfm?action=propdetails&id=$1', // Saskatchewan ID
	846: 'http://data.gbif.org/species/$1', // GBIF-ID
	850: 'http://www.marinespecies.org/aphia.php?p=taxdetails&id=$1', // WoRMS-ID
	860: 'http://www.e-archiv.li/personDetail.aspx?persID=$1', // e-archiv.li
	861: 'http://www.premiershiprugby.com/matchcentre/fixtures/squads.php?player=$1&includeref=dynamic', // premiershiprugby.com
	863: 'https://inpho.cogs.indiana.edu/idea/$1.html', // Indiana Philosophy Ontology project
	864: '//dl.acm.org/author_page.cfm?id=$1', // Association for Computing Machinery Digital Library author identifier
	865: 'http://bmlo.de/$1', // Bayerisches Musiker-Lexikon Online
	866: 'http://www.perlentaucher.de/autor/$1.html', // Perlentaucher
	867: '//recrutement.pole-emploi.fr/fichesrome/ficherome?codeRome=$1&domaine=Candidat', // Rome occupation code
	882: 'http://quickfacts.census.gov/qfd/states/$1.html', //FIPS
	884: 'http://vwo.osm.rambler.ru/?page=findname&name=$1', // State Water Register Code (Russia)
	886: 'http://www.e-lir.ch/e-LIR___Lexicon.$1.450.0.html', // Lexicon istoric retic (LIR)
	888: 'http://www.jstor.org/stable/$1', // JSTOR
	889: 'http://www.ams.org/mathscinet-getitem?mr=$1', // ?Mathematical Reviews identifier
	892: '//tools.ietf.org/html/rfc$1', // Request for Comments number (IETF)
	893: 'http://ssrn.com/abstract=$1', // Social Science Research Network
	894: 'https://zbmath.org/?q=an:$1', // Zentralblatt MATH
	902: 'http://www.hls-dhs-dss.ch/textes/' + ( $.inArray( BASE_LANGUAGE, ['fr'] ) !== -1 ? 'f/F' : ( $.inArray( BASE_LANGUAGE, ['it'] ) !== -1 ? 'i/I' : 'd/D' )) + '$1.php', // HDS/HLS/DHS/DSS identifier
	905: 'http://port.' + ( $.inArray( BASE_LANGUAGE.substring( 0, 2 ), ['ro', 'cs', 'sk', 'hr', 'sr'] ) !== -1 ? ( $.inArray( BASE_LANGUAGE, ['cs'] ) !== -1 ? 'cz' : ( $.inArray( BASE_LANGUAGE, ['sr'] ) !== -1 ? 'rs' : BASE_LANGUAGE ) ) : 'hu' ) + '/pls/fi/films.film_page?i_film_id=$1', // PORT-network identifier
	906: '//libris.kb.se/auth/$1', // Libris library catalog
	907: 'http://allgame.com/game.php?id=$1', // AMG Game ID
	909: 'https://eapps.ednet.ns.ca/HPIPublic/PropertyDisplay.aspx?Fid=$1', // Nova Scotia Register of Historic Places ID
	918: 'http://www5.' + ( $.inArray( BASE_LANGUAGE.substring( 0, 2 ), ['fr'] ) !== -1 ? 'rhdcc.gc.ca/CNP/Francais/CNP/2011/Profil' : 'hrsdc.gc.ca/noc/english/noc/2011/Profile' ) + '.aspx?val=7&val1=$1', // NOC Occupation Code
	920: 'http://id.sgcb.mcu.es/lem/ver/Autoridades/$1/concept', // Spanish subject headings for public libraries
	933: 'http://www.heritagefoundation.ca/property-search/property-details-page.aspx?id=$1', // heritagefoundation.ca ID
	935: '//commons.wikimedia.org/wiki/$1', // Commons gallery
	938: 'http://www.fishbase.org/Summary/speciesSummary.php?id=$1', // Fishbase ID
	939: 'http://www.ksh.hu/apps/!cp.hnt2.telep?nn=$1', // Hungarian Central Statistical Office (KSH)
	946: 'http://tools.wmflabs.org/isin/?language=de&isin=$1', // ISIN
	947: 'http://aleph.rsl.ru/F?func=find-b&find_code=SYS&adjacent=Y&local_base=RSL11&request=$1', // Russian State Library identifier
	949: 'http://a20.libnet.ac.il/F?func=find-b&REQUEST=$1&find_code=SYS&local_base=NNL10', // NLI (Israel) identifier
	950: 'http://catalogo.bne.es/uhtbin/authoritybrowse.cgi?action=display&authority_id=$1', // BNE identifier
	951: 'http://viaf.org/processed/NSZL%7C$1', // NSZL identifier
	959: 'http://www.departments.bucknell.edu/biology/resources/msw3/browse.asp?s=y&id=$1', // MSW species identifier
	960: 'http://www.tropicos.org/Name/$1', //Tropicos taxon name identifier
	961: 'http://www.ipni.org/ipni/idPlantNameSearch.do?id=$1', // IPNI taxon name identifier
	962: 'http://www.mycobank.org/MycoTaxo.aspx?Link=T&Rec=$1', // MycoBank taxon name identifier
	966: '//musicbrainz.org/label/$1', // MusicBrainz Label ID
	982: '//musicbrainz.org/area/$1', // MusicBrainz Area ID
	998: 'http://www.dmoz.org/$1', // Open Directory Project (DMOZ)
	1003: 'http://alephnew.bibnat.ro:8991/F?func=find-b&request=$1&find_code=SYS&adjacent=Y&local_base=NLR10', // NLR (Romania) identifier
	1004: '//musicbrainz.org/place/$1', // MusicBrainz Place ID
	//1005: 'http://purl.pt/index/geral/aut/PT/$1.html', // PTBNP identifier
	1006: 'http://opc4.kb.nl/PPN?PPN=$1', // NTA name identifier
	1014: 'http://www.getty.edu/vow/AATFullDisplay?find=&logic=&note=&page=&subjectid=$1', // AAT
	1025: 'http://www.sudoc.fr/$1', // SUDOC catalog (editions only)
	1036: 'http://dewey.info/class/$1/about', // DDC
	1042: 'http://dispatch.opac.d-nb.de/DB=1.1/CMD?ACT=SRCHA&IKT=8506&TRM=$1', // ZDB identifier
	1043: 'http://www.onisep.fr/onisep-portail/portal/media-type/html/group/gp/page/interieur.espace.guide.metiers.detail/js_peid/InitGuideResultatDetail/js_peid/GuideResultatMetiersDetail?typeRecherche=metierParNom&ficheIdeo=$1', // IDEO Job ID
	1044: 'http://swb.bsz-bw.de/DB=2.1/PPNSET?PPN=$1&INDEXSET=1', // SWB editions (union catalog)
	1045: 'http://www.assemblee-nationale.fr/sycomore/fiche.asp?num_dept=$1', // Sycomore
	1047: 'http://www.catholic-hierarchy.org/bishop/b$1.html', // Catholic Hierarchy
	1048: 'http://aleweb.ncl.edu.tw/F/?func=accref&acc_sequence=$1', // NCL identifier
	1051: 'http://pshmanager.techlib.cz/psh_csv', // PSH
	1053: 'http://www.researcherid.com/rid/$1', // ResearcherID
	1054: 'http://iss.ndl.go.jp/books?op_id=1&any=$1', // NDL editions
	1055: '//www.ncbi.nlm.nih.gov/nlmcatalog/$1', // NLM
	1058: 'http://lamp.infosys.deakin.edu.au/era/?page=jnamedet12f&eraid=$1', // ERA ID
	1059: 'http://cvr.dk/Site/Forms/PublicService/DisplayCompany.aspx?cvrnr=$1', // CVR identifier
	1076: 'http://ictvdb.bio-mirror.cn/ICTVdB/$1htm', // ICTV ID
	1070: 'http://www.theplantlist.org/tpl1.1/record/$1', // PlantList
	1084: 'http://srv3.eulc.edu.eg/eulc_v5/libraries/Start.aspx?fn=ApplySearch&BibID=$1', // EUL control number
	1085: 'http://www.librarything.com/work/$1', // LibraryThing work identifier
	1133: 'http://lampspw.wallonie.be/dgo4/site_thema/index.php?details=$1&thema=bc_pat', // DGO4 classified properties ID
	1138: 'https://www.kulturarv.dk/kid/VisKunstner.do?kunstnerId=$1', // Kunstindeks Danmark
	1143: 'http://catalogo.bn.gov.ar/F/?func=find-b&request=$1&find_code=SYS', // BN (Argentine) editions
	1144: 'http://lccn.loc.gov/$1', // LCCN editions
	1146: 'http://www.iaaf.org/athletes/athlete=$1', // IAAF ID
	1153: '//www.scopus.com/authid/detail.url?authorId=$1', // Scopus bibliographic database
	1182: 'http://libris.kb.se/bib/$1', // LIBRIS editions
	1184: 'http://hdl.handle.net/$1', // Handle System ID
	1185: 'http://en.rodovid.org/wk/Person:$1', // Rodovid ID
	1186: 'http://www.europarl.europa.eu/meps/en/$1.html', // MEP database
	1187: 'http://authority.ddbc.edu.tw/person/search.php?aid=$1', //Dharma Drum Buddhist College person ID
	1212: 'http://cartelfr.louvre.fr/cartelfr/visite?srv=car_not_frame&idNotice=$1', //Atlas ID
	1213: 'http://opac.nlc.gov.cn/F/?func=accref&acc_sequence=$1', // NLC authorities
	1214: 'http://data.riksdagen.se/person/$1', //Riksdagen person-id
	1216: 'http://list.english-heritage.org.uk/resultsingle.aspx?uid=$1', //English Heritage list number
	1217: 'http://www.ibdb.com/venue.php?id=$1', // Internet Broardway Database Venue ID
	1218: 'http://www.ibdb.com/production.php?id=$1', // Internet Broadway Database Production ID
	1219: 'http://www.ibdb.com/show.php?id=$1', // Internet Broardway Database Show ID
	1220: 'http://www.ibdb.com/person.php?id=$1', // Internet Broadway Database Person ID
	1222: 'http://research.archives.gov/person/$1', // NARA person authority control
	1223: 'http://research.archives.gov/organization/$1', // NARA organization authority control
	1224: 'http://research.archives.gov/geographic-reference/$1', // NARA geographic authority control
	1225: 'http://research.archives.gov/topical-subject/$1', // NARA subject authority control
	1226: 'http://research.archives.gov/specific-records-type/$1', // NARA records type authority control
	1229: 'http://politici.openpolis.it/politico/$1', // Openpolis
	1231: 'research.archives.gov/description/$1', // NARA online catalog
	1232: 'http://multitree.linguistlist.org/codes/$1', // Linguist list code
	1233: 'http://www.isfdb.org/cgi-bin/ea.cgi?$1', //ISFDB author
	1234: 'http://www.isfdb.org/cgi-bin/pl.cgi?$1', //ISFDB publication
	1235: 'http://www.isfdb.org/cgi-bin/pe.cgi?$1', //ISFDB series
	1237: 'http://boxofficemojo.com/movies/?id=$1.htm', // Box Office Mojo film ID
	1238: 'http://svenskfotboll.se/allsvenskan/person/?playerid=$1', // Swedish Football Association playerid
	1239: 'http://www.isfdb.org/cgi-bin/publisher.cgi?$1', //ISFDB publisher
	1245: 'http://www.omegawiki.org/DefinedMeaning:$1', //OmegaWiki DefinedMeaning
	1248: 'http://kulturnav.org/$1', //KulturNav-id
	1252: 'http://austlang.aiatsis.gov.au/main.php?code=$1', // AIATSIS / AUSTLANG language code
	1256: 'http://www.iconclass.org/rkd/$1', // Iconclass ID
	1258: 'http://www.rottentomatoes.com/$1', // Rotten Tomatoes ID 
	1260: 'http://kulturarvsdata.se/$1', //kulturarvsdata
	1265: 'http://www.allocine.fr/film/fichefilm_gen_cfilm=$1.html?nopub=1', //AlloCiné
	1266: 'http://www.allocine.fr/personne/fichepersonne_gen_cpersonne=$1.html?nopub=1', //AlloCiné
	1267: 'http://www.allocine.fr/series/ficheserie_gen_cserie=$1.html?nopub=1', //AlloCiné
	1273: 'http://cantic.bnc.cat/registres/CUCId/$1', // CANTIC ID (aka BNC) 
	1280: 'http://www.cobiss.si/scripts/cobiss?command=DISPLAY&base=CONOR&rid=$1', // CONOR
	1282: '//wiki.openstreetmap.org/wiki/$1',
	1284: 'http://www.munzinger.de/search/go/document.jsp?id=$1', // Munzinger IBA ID (international)
	1285: 'http://www.munzinger.de/search/go/document.jsp?id=$1', // Munzinger Sport ID
	1286: 'http://www.munzinger.de/search/go/document.jsp?id=$1', // Munzinger Pop ID
	1287: 'http://www.munzinger.de/search/go/document.jsp?id=$1', // Munzinger KDG ID (composers)
	1288: 'http://www.munzinger.de/search/go/document.jsp?id=$1', // Munzinger KLG ID (german-speaking authors)
	1289: 'http://www.munzinger.de/search/go/document.jsp?id=$1', // Munzinger KLfG ID (non-german speaking authors)
	1291: 'http://repertoire.a-d-s.ch/edit/detail_a.php?id_autor=$1', //ADS ID
	1296: 'http://www.enciclopedia.cat/enciclop%C3%A8dies/gran-enciclop%C3%A8dia-catalana/EC-GEC-$1.xml', // Gran Enciclopèdia Catalana ID 
	1307: 'http://www.parlament.ch/E/Suche/Pages/biografie.aspx?biografie_id=$1', // parlament.ch
	1311: 'http://www.lostbridges.org/details.aspx?id=$1', // lostbridges.org ID
	1315: 'http://nla.gov.au/nla.party-$1', // NLA party ID (archival)
	1320: 'https://opencorporates.com/companies/$1', //OpenCorporates identifier
	1323: 'http://www.unifr.ch/ifaa/Public/EntryPage/TA98%20Tree/Entity%20TA98%20EN/$1%20Entity%20TA98%20EN.htm', // Terminologia Anatomica 98 (TA98)
	1330: '//musicbrainz.org/instrument/$1', // MusicBrainz Instrument ID
	1331: 'http://www.assembly.coe.int/nw/xml/AssemblyList/MP-Details-EN.asp?MemberID=$1', // PACE member ID
	1338: 'http://spatialreference.org/ref/epsg/$1/', // EPSG ID
	1362: 'http://tls.theaterwissenschaft.ch/wiki/$1', // Theaterlexikon der Schweiz
	1367: 'http://www.bbc.co.uk/arts/yourpaintings/artists/$1', // BBC Your paintings
	1380: 'http://www.uglybridges.com/$1', //uglybridges.com
	1381: 'http://www.bridgehunter.com/$1', //bridgehunter.com
	1391: 'http://www.indexfungorum.org/names/NamesRecord.asp?RecordID=$1',  //Index Fungorum ID
	1394: 'http://glottolog.org/resource/languoid/id/$1', //glottolog ID
	1395: 'http://www.cancer.gov/$1', //cancer.gov ID
	1396: 'http://www.hortensj-garden.org/index.php?tnc=1&tr=lsr&nid=$1', // Linguasphere code
	1402: 'http://purl.obolibrary.org/obo/FMA_$1', // Foundational Model of Anatomy ID
	1407: '//musicbrainz.org/series/$1', // MusicBrainz Series ID
	1409: 'http://www.cyclingarchives.com/coureurfiche.php?coureurid=$1', // Cycling Archives Cyclist ID
	1415: 'http://www.oxforddnb.com/index/$1/', // Oxford Dictionary of National Biography ID
	1417: 'http://global.britannica.com/EBchecked/topic/$1/', // Encyclopædia Britannica online ID
	1422: 'http://ta.sandrart.net/' + ( $.inArray( BASE_LANGUAGE.substring( 0, 2 ), ['en', 'de'] ) !== -1 ? BASE_LANGUAGE : 'en' ) + '/person/view/$1', // Sandrart.net ID
	1426: 'http://www.worldwildlife.org/ecoregions/$1', // ecoregion ID (WWF)
	1428: 'http://www.lostart.de/' + ( $.inArray( BASE_LANGUAGE.substring( 0, 2 ), ['de'] ) !== -1 ? 'DE' : 'EN' ) + '/Verlust/$1', // Lost Art-ID
	1430: 'http://openplaques.org/people/$1', // OpenPlaques ID
	1438: 'http://www.eleven.co.il/article/$1', // Jewish Encyclopedia ID
	1439: 'http://www.nb.no/filmografi/show?id=$1', //  Norsk filmografi ID
	1447: 'http://www.sports-reference.com/olympics/athletes/$1.html', // Sports Reference ID
	1459: 'http://www.britishlistedbuildings.co.uk/wa-$1', // Cadw Building ID
	1461: 'http://www.patient.co.uk/doctor/$1',
	1463: 'http://prdl.org/author_view.php?a_id=$1', //PRDL ID
	1466: 'http://wals.info/languoid/lect/wals_code_$1', //WALS language code	
	1467: 'http://wals.info/languoid/genus/$1',  //WALS genus code	
	1472: '//commons.wikimedia.org/wiki/Creator:$1', //Commons creator template
	1473: 'http://www.literaturabrasileira.ufsc.br/autores/?id=$1',
	1481: 'http://vici.org/vici/$1', //vici.org ID
	1483: 'http://kulturnoe-nasledie.ru/monuments.php?id=$1', // kulturnoe-nasledie.ru ID
	1529: 'http://patrimoine.region-bretagne.fr/main.xsp?execute=show_document&id=$1', //Glad ID
	1550: 'http://www.orpha.net/consor/cgi-bin/Disease_Search.php?&data_id=$1', //Orphanet
	1551: 'http://lampspw.wallonie.be/dgo4/site_thema/index.php?details=$1&thema=pat_exc', // Exceptionnal heritage of Wallonia ID
	1556: 'http://www.zbmath.org/authors/?q=ai:$1', // zbMATH 
	1562: 'http://www.allmovie.com/$1', //Allmovie
	1563: 'http://www-history.mcs.st-andrews.ac.uk/Biographies/$1.html', // MacTutor
	1564: 'http://www.victorianresearch.org/atcl/show_author.php?aid=$1', // At the Circulating Library
	1565: 'http://www.elem.mx/autor/datos/$1', // Enciclopedia de la Literatura en México
	1566: 'http://sws.geonames.org/$1', // Geonames
	1580: 'http://www.bib.ub.edu/fileadmin/autoritats/permanent/$1', //University of Barcelona
	1587: 'http://giskd2s.situla.org/rkd/Opis.asp?Esd=$1', //Slovene Cultural Heritage Register ID
	1612: '//commons.wikimedia.org/wiki/Institution:$1', //Commons Institution template
	1615: 'http://clara.nmwa.org/index.php?g=entity_detail&entity_id=$1', //CLARA
	1617: 'http://www.bbc.co.uk/things/$1', // BBC 'Things' ID
	1624: 'http://www.marinetraffic.com/en/ais/details/ports/$1',  // MarineTraffic Port ID
	1631: 'http://www.chinavitae.com/biography/$1' // China Vitae
	// Note: Watch out to keep the trailing comma at the end of every entry other than the last!
};

/*
*/
function getGeoHackParams( coord ) {
	// TODO: individual scale for every precession

	var globes = {
		'Q2': 'earth',
		'Q111': 'mars',
		'Q308': 'mercury',
		'Q313': 'venus',
		'Q405': 'moon',
		'Q15034': 'mimas'
	};

	/* BUG: .getGlobe() returns Q2 always */
	var globeQKey = coord.getGlobe().replace( 'http://www.wikidata.org/entity/', '' );
	var globe = globes[globeQKey];

	return coord.getLatitude() + '_N_' + coord.getLongitude() + '_E_globe:' + globe;
}

/**
 * Creates a link that is placed after a snak's input textarea.
 *
 * @param {number} numericPropertyId Refers to PROPERTIES.
 * @param {object} snakValue The original value that shall be used in the link.
 * @param {jQuery} $parent The node whose descendants shall be searched for the snak value
 *                 textarea.
 * @param {jQuery} $toolbarParent The node the "edit" toolbar corresponding to the value that shall
 *                 be linked is initialized on.
 */
function createLink( numericPropertyId, snakValue, $parent, $toolbarParent ) {
	// @todo this could be it's own function
	var linkValue;
	if ( snakValue.getType() === 'string' ) {
		switch ( Number( numericPropertyId ) ) {
		case 213: // ISNI
			linkValue = snakValue.getValue().replace( / /g, '' );
			break;
		case 502: // HURDAT
			linkValue = snakValue.getValue().substring( 4, 8 ); // year
			if ( Number( linkValue ) <= 2005 ) {
				linkValue += '/'; // Brings a list for that year
				// For direct link, would need to append <name of hurricane>.[s]htlm 
				// ex: http://www.nhc.noaa.gov/archive/2004/ALEX.shtml or 2001/ALLISON.html
			} else { // after 2005
				linkValue += '/' + snakValue.getValue().substring( 0, 4 ).toLowerCase() + '/';
			}
			break;
		case 628: // E Number
			linkValue = snakValue.getValue().substring( 1, 16 ); // Skip initial letter
			break;
		case 882: // FIPS
			linkValue = snakValue.getValue();
			linkValue = linkValue.substr( 0, 2 ) + '/' + linkValue;
			break;
		default:
			linkValue = snakValue.getValue();
		}
	}
	else if ( snakValue.getType() === 'globecoordinate' ) {
		linkValue = getGeoHackParams( snakValue.getValue() );
	}
	
	// FIXME: The second selector is a temporary fix and should be removed 30 days after the bug is fixed.
	var $displayElement = $parent.find( '.wb-snak-value .valueview, .wb-snak-value .valueview-valueview' );
	var displayText = $displayElement.text();

	var $btnEdit = $toolbarParent.find( '.wikibase-toolbar-button-edit' );
	var linkTemplate = PROPERTIES[numericPropertyId];

	var $link = $( '<a>' )
		.text( displayText )
		.attr( 'href', linkTemplate.replace( '$1', linkValue ) )
		// Show the 'external link' icon:
		.addClass( 'external' );

	$displayElement.hide().after( $link );

	// Using ".one" since, currently, link and textarea visibility are not toggled after leaving
	// edit mode anyhow:
	$btnEdit.one( 'click', function () {
		$link.hide();
		$displayElement.show();
	} );
}

/**
 * Creates a link for the snakview featuring a specific snak.
 * Since the order of the snaks within a SnakList does not necessarily have to be the same than the
 * displayed/grouped snakviews, all snakviews need to be looped over to find out the snakview that
 * features a specific snak.
 *
 * @param {wikibase.Snak} snakToLink
 * @param {jQuery} $parent The node whose descendants will be searched for snaklistviews
 * @param {jQuery} [$toolbarParent] The node the "edit" toolbar corresponding to the value that
 *                 shall be linked is initialized on.
 */
function linkSnakview( snakToLink, $parent, $toolbarParent ) {
	$toolbarParent = $toolbarParent || $parent;

	$parent.find( '.wb-snakview' ).each( function () {
		var snak = $.data( this, 'wikibaseSnakview' ).snak();

		if ( snak.equals( snakToLink ) ) {
			createLink( snak.getPropertyId().slice( 1 ), snak.getValue(), $( this ), $toolbarParent );
			return false;
		}
	} );
}

/**
 * Initializes the gadget.
 * This procedure needs to be perform as good as possible. jQuery selector usage should be limited
 * to a minimum.
 */
function initGadget() {
	$( ':wikibase-statementview' ).each( function () {
		var $statementview = $( this ),
			statementview = $.data( this, 'statementview' ),
			statement = statementview.value(),
			mainSnak = statement.getClaim().getMainSnak(),
			numericPropertyId = mainSnak.getPropertyId().slice( 1 ),
			qualifiers = statement.getClaim().getQualifiers(),
			references = statementview.getReferences(),
			// Do not look for referenceview DOM nodes before they are actually needed:
			$referenceviews = null;

		if ( PROPERTIES[numericPropertyId] ) {
			createLink(
				numericPropertyId,
				mainSnak.getValue(),
				statementview.$mainSnak || statementview.$claimview.data( 'claimview' ).$mainSnak,
				$statementview
			);
		}

		qualifiers.each( function ( i, snak ) {
			if ( PROPERTIES[snak.getPropertyId().slice( 1 )] ) {
				linkSnakview( snak, statementview.$qualifiers, $statementview );
			}
		} );

		for ( var i in references ) {
			references[i].getSnaks().each( function ( j, snak ) {
				if ( PROPERTIES[snak.getPropertyId().slice( 1 )] ) {
					if ( !$referenceviews ) {
						$referenceviews = $statementview.find( ':wikibase-referenceview' );
					}
					linkSnakview( snak, $referenceviews.eq( i ) );
				}
			} );
		}
	} );
}

if ( mw.loader.getState( 'wikibase.ui.entityViewInit' ) === 'ready' && $( '.wb-entity-spinner' ).length === 0 ) {
	console.log( 'Dependencies ready, intializing AC gadget directly.' );
	initGadget();
} else {
	console.log( 'Adding initGadget to mw.hook callback' );
	mw.hook( 'wikibase.domready' ).add( initGadget );
}

}( mediaWiki, jQuery ) );