User:Joshbaumgartner/wd air useful.js

From Wikidata
Jump to navigation Jump to search

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/*
USAGE : Add the line
importScript("User:Magnus Manske/wikidata useful.js");// [[User:Magnus Manske/wikidata useful.js]]
to your [[Special:Mypage/common.js]] page
*/
 
/************************************************************************************************************************
The section below contains the "Wikidata Usefuls" link definitions. Add new ones or edit existing ones as you see fit.
*************************************************************************************************************************/
 
var wd_useful_thisis_langs = {} ;
wd_useful_thisis_langs['en'] = [
	[
		{
			pre : '<b>AIRCRAFT:</b> ' ,
			options : [
				[ 'Family' , 'P31:Q15056993' ] ,
				[ 'Model' , 'P31:Q15056995' ] ,
				[ 'License', 'P31:Q17447455' ] ,
				[ 'Sans', 'P31:Q17447449'] ,
				[ 'Proto' , 'P31:Q15126161' ] ,
				[ 'Conv' , 'P31:Q17910379' ] ,
				[ 'Proposed' , 'P31:Q15061018' ] ,
				[ 'Individial' , 'P31:Q11436' ] ,
				[ 'Fleet', 'P31:Q17372500' ] ,
				[ 'Uses AC', 'P121:Q11436' ] ,
				[ 'Part of GAF', 'P361:Q24175393' ] 
			]
		} ,
 
		{
			pre : '<b>Record:</b> ' ,
			options : [
				[ 'ALG', 'P31:Q17372500' , 'P17:Q262' ] ,
				[ 'ANG', 'P31:Q17372500' , 'P17:Q916' ] ,
				[ 'ARG', 'P31:Q17372500' , 'P17:Q414' ] ,
				[ 'ARM', 'P31:Q17372500' , 'P17:Q399' ] ,
				[ 'AUS', 'P31:Q17372500' , 'P17:Q408' ] ,
				[ 'OST', 'P31:Q17372500' , 'P17:Q40' ] ,
				[ 'AZE', 'P31:Q17372500' , 'P17:Q227' ] ,
				[ 'BNG', 'P31:Q17372500' , 'P17:Q398' ] ,
				[ 'BLR', 'P31:Q17372500' , 'P17:Q184' ] ,
				[ 'BLG', 'P31:Q17372500' , 'P17:Q31' ] ,
				[ 'BLZ', 'P31:Q17372500' , 'P17:Q242' ] ,
				[ 'BHU', 'P31:Q17372500' , 'P17:Q917' ] ,
				[ 'BOL', 'P31:Q17372500' , 'P17:Q750' ] ,
				[ 'BOS', 'P31:Q17372500' , 'P17:Q225' ] ,
				[ 'BOT', 'P31:Q17372500' , 'P17:Q963' ] ,
				[ 'BRA', 'P31:Q17372500' , 'P17:Q155' ] ,
				[ 'BRU', 'P31:Q17372500' , 'P17:Q921' ] ,
				[ 'BUL', 'P31:Q17372500' , 'P17:Q219' ] ,
				[ 'BRD', 'P31:Q17372500' , 'P17:Q967' ] ,
				[ 'BFO', 'P31:Q17372500' , 'P17:Q965' ] ,
				[ 'CMB', 'P31:Q17372500' , 'P17:Q424' ] ,
				[ 'MYA', 'P31:Q17372500' , 'P17:Q836' ] ,
			]
		} ,
 
		{
			pre : '<b>Class:</b> ' ,
			options : [
				[ 'Air' , 'P279:Q11436' ] ,
				[ 'Mil' , 'P279:Q216916' ] ,
				[ 'Attack' , 'P279:Q208187' , 'P366:Q331435' ] ,
				[ 'CAS' , 'P279:Q208187' , 'P366:Q1050818' ] ,
				[ 'Torpedo' , 'P279:Q753224' , 'P366:Q2527950' ] ,
				[ 'Bomber' , 'P279:Q170877' ] ,
				[ 'HvBomb' , 'P279:Q3534114' , 'P366:Q841418' ] ,
				[ 'MdBomb' , 'P279:Q10796151' ] ,
				[ 'LtBomb' , 'P279:Q15125597' , 'P366:Q331435' ] ,
				[ 'DBomb' , 'P279:Q678321' , 'P366:Q1050818' ] ,
				[ 'Fighter' , 'P279:Q127771' , 'P366:Q2164772' ] ,
				[ 'Intercept' , 'P279:Q320018' , 'P366:Q15104954' ] ,
				[ 'Recon' , 'P279:Q3041792' , 'P366:Q3306321' ] ,
				[ 'Marpat' , 'P279:Q658414' , 'P366:Q6765889' ] ,
				[ 'Liaison' , 'P279:Q1368478' ] ,
				[ 'Training' , 'P279:Q41426' , 'P366:Q383695' ] ,
				[ 'Racing' , 'P279:Q3605965' , 'P366:q1875777'] ,
				[ 'Trans' , 'P279:Q15126142' ] ,
				[ 'Airliner' , 'P279:Q210932' , 'P366:Q9640723' ] ,
				[ 'Airlift' , 'P279:Q1445518' , 'P366:Q256905' ] ,
				[ 'VIP' , 'P279:Q15126142' , 'P366:Q15449497' ] ,
				[ 'Biz' , 'P279:Q15126142' , 'P366:Q15449252' ] ,
				[ 'Utility' , 'P279:Q1130697' ] ,
				[ 'Helo' , 'P279:Q34486' ] ,
				[ 'AtHelo' , 'P279:Q753058' ] ,
				[ 'UtHelo' , 'P279:Q2735392' ] ,
				[ 'Exp' , 'P279:Q1384417' ] ,
			]
		} ,
 
		{
			pre : '<b>Use:</b> ' ,
			options : [
				[ 'MIL' , 'P366:q627716' ] ,
				[ 'AirWar' , 'P366:Q471145' ] ,
				[ 'AirSup' , 'P366:Q898788' ] ,
				[ 'CAP' , 'P366:Q2164772' ] ,
				[ 'Icept' , 'P366:Q15104954' ] ,
				[ 'TacBom' , 'P366:Q1422289' ] ,
				[ 'StrBom' , 'P366:Q841418' ] ,
				[ 'EW' , 'P366:Q272826' ] ,
				[ 'Recon' , 'P366:Q3306321' ] ,
				[ 'ACoop' , 'P366:Q15517541' ] ,
				[ 'MarPat' , 'P366:Q6765889' ] ,
				[ 'Airlift' , 'P366:Q256905' ] ,
				[ 'COM' , 'P366:Q9640723' ] ,
				[ 'GEN' , 'P366:Q1571929' ] ,
				[ 'BUS' , 'P366:Q15449252' ] ,
				[ 'Trng' , 'P366:Q383695' ] ,
			]
		} ,
 
		{
			pre : '<b>Wings:</b> ' ,
			options : [
				[ 'Mono' , 'P279:Q627537' ] ,
				[ 'Biplane' , 'P279:Q223818' ] ,
				[ 'Sesqui' , 'P279:Q15104989' ] ,
				[ 'Triplane' , 'P279:Q118240' ] ,
			]
		} ,
 
		{
			pre : '<b>Landing:</b> ' ,
			options : [
				[ 'Land' , 'P279:Q15062149' ] ,
				[ 'STOL' , 'P279:Q832489' ] ,
				[ 'Carrier' , 'P279:Q1261534' ] ,
				[ 'Sea' , 'P279:Q115940' ] ,
				[ 'FlyBt' , 'P279:Q1153376' ] ,
				[ 'Float' , 'P279:Q3119075' ] ,
			]
		} ,
 
		{
			pre : '<b>Arm:</b> ' ,
			options : [
				[ 'MG' , 'P520:Q12800' ] ,
				[ 'Bomb' , 'P520:Q1454201' ] ,
				[ 'Torp' , 'P520:Q165363' ] ,
				]
		} ,
 
		{
			pre : '<b>Crew:</b> ' ,
			options : [
				[ 'Pilot' , 'P1029:Q1146304' ] ,
				[ 'CoPlt' , 'P1029:Q15222877' ] ,
				[ 'FltEng' , 'P1029:Q432425' ] ,
				[ 'Gunner' , 'P1029:Q4305259' ] ,
				[ 'DrGnr' , 'P1029:Q495597' ] ,
				[ 'NsGnr' , 'P1029:Q7061750' ] ,
				[ 'TlGnr' , 'P1029:Q1842468' ] ,
				[ 'WtGnr' , 'P1029:Q15222885' ] ,
				[ 'Observ' , 'P1029:Q4698345' ] ,
				[ 'Navig' , 'P1029:Q254651' ] ,
				[ 'FltIns' , 'P1029:Q379318' ] ,
				[ 'FltAtd' , 'P1029:Q101539' ] ,
				]
		} ,
 
		{
			pre : '<b>ENGINE:</b> ' ,
			options : [
				[ 'Family' , 'P31:Q15057020' , 'P366:Q743004' ] ,
				[ 'Model' , 'P31:Q15057021' , 'P366:Q743004' ] ,
				]
		} ,
 
		{
			pre : '<b>Config:</b> ' ,
			options : [
				[ 'TF' , 'P279:Q654051' ] ,
				[ 'TJ' , 'P279:Q723916' ] ,
				[ 'TP' , 'P279:Q309027' ] ,
				[ 'TS' , 'P279:Q943162' ] ,
				[ 'F2' , 'P1002:Q3063504' ] ,
				[ 'F4' , 'P1002:Q3269254' ] ,
				[ 'F6' , 'P1002:Q3295589' ] ,
				[ 'F8' , 'P1002:Q3295336' ] ,
				[ 'I4' , 'P1002:Q1784109' ] ,
				[ 'I6' , 'P1002:Q1148385' ] ,
				[ 'I8' , 'P1002:Q2479238' ] ,
				[ 'V6' , 'P1002:Q10856569' ] ,
				[ 'V8' , 'P1002:Q341174' ] ,
				[ 'V12' , 'P1002:Q245272' ] ,
				[ 'Radial' , 'P1002:Q214098' ] ,
				[ 'R5' , 'P1002:Q15135162' ] ,
				[ 'R7' , 'P1002:Q15135178' ] ,
				[ 'R9' , 'P1002:Q15135215' ] ,
				[ 'R11' , 'P1002:Q15135228' ] ,
				[ 'R14' , 'P1002:Q15135255' ] ,
				[ 'R18' , 'P1002:Q15135275' ] ,
				[ 'Rotary' , 'P1002:Q1043622' ] ,
				[ 'Ro7' , 'P1002:Q15135289' ] ,
				[ 'Ro9' , 'P1002:Q15135304' ] ,
				[ 'W12' , 'P1002:Q2537655' ] ,
				[ 'H' , 'P1002:Q1431451' ] ,
				[ 'PJet' , 'P279:Q671090' ] ,
				[ 'Rocket' , 'P279:Q335225' ] ,
			]
		} ,
 
		{
			pre : '<b>Coolant:</b> ' ,
			options : [
				[ 'Air' , 'P588:Q7391292' ] ,
				[ 'Liquid' , 'P588:Q11435' ] ,
				[ 'Water' , 'P588:Q283' ] ,
				]
		} ,
 
		{
			pre : '<b>WEAPON:</b> ' ,
			options : [
				[ 'Family' , 'P31:Q15142889' ] ,
				[ 'Model' , 'P31:Q15142894' ] ,
				]
		} ,
 
		{
			pre : '<b>Type:</b> ' ,
			options : [
				[ 'MG' , 'P279:Q12800' ] ,
				[ 'Bomb' , 'P279:Q1454201' ] ,
				[ 'Torp' , 'P279:Q165363' ] ,
				]
		} ,
 
		{
			pre : '<b>FLIGHT:</b> ' ,
			options : [
				[ 'Dpt' , 'P559:q15733670' ] ,
				[ 'Dvt' , 'P559:Q392406' ] ,
				[ 'Dst' , 'P559:q15733672' ] ,
				]
		} ,
 
		{
			pre : '<b>COMPANY:</b> ' ,
			options : [
				[ 'AeroMfr' , 'P31:Q936518' ] ,
				[ 'Airline' , 'P31:Q46970' ] ,
				[ 'Publish' , 'P31:Q2085381' ] ,
				]
		} ,
 
		{
			pre : '<b>UNIT:</b> ' ,
			options : [
				[ 'Mil' , 'P31:Q772547' ] ,
				[ 'GS' , 'P31:Q495430'] ,
				[ 'Army' , 'P31:Q37726' ] ,
				[ 'Navy' , 'P31:Q4508' ] ,
				[ 'AF' , 'P31:Q61883' ] ,
				[ 'Mar' , 'P31:Q1898583'] ,
				[ 'SF' , 'P31:Q234497' ] ,
				[ 'AD' , 'P31:Q17597793' ] ,
				[ 'CG' , 'P31:Q1353040' ] ,
				[ 'BG' , 'P31:Q138775' ] ,
				[ 'Gend' , 'P31:Q204310' ] ,
				[ 'ArmAir' , 'p31:Q1593564'] ,
				[ 'NavAir' , 'p31:Q1898464'] ,
				[ 'AirSqn' , 'P31:Q679165' ] ,
				[ 'GndSqn' , 'P31:Q252280' ] ,
				[ 'NavSqn' , 'P31:Q955920' ] ,
				]
		} ,
 
		{
			pre : '<b>Branch:</b> ' ,
			options : [
				[ 'USAF' , 'P241:Q11223' , 'P17:Q30' ] ,
				[ 'USN' , 'P241:Q11220' , 'P17:Q30' ] ,
				[ 'USMC' , 'P241:Q11218' , 'P17:Q30' ] ,
				[ 'USAr' , 'P241:Q9212' , 'P17:Q30' ] ,
				[ 'RAF' , 'P241:q165862' , 'P17:Q145' ] ,
				[ 'FAA' , 'P241:Q1427735' , 'P17:Q145' ] ,
				[ 'RFC' , 'P241:Q943118' , 'P17:Q145' ] ,
				[ 'PLAAF' , 'P241:Q607832' , 'P17:Q148' ] ,
				[ 'RAAF' , 'P241:Q823635' , 'P17:q408' ] ,
				[ 'AFAA' , 'P241:Q3076989' , 'P17:Q408' ] ,
				[ 'AFC' , 'P241:Q4824175' , 'P17:Q408' ] ,
				[ 'RCAF' , 'P241:Q25456' , 'P17:Q16' ] ,
				[ 'IAF' , 'P241:Q330658' , 'P17:Q668' ] ,
				[ 'RNZAF' , 'P241:Q542164' , 'P17:Q664' ] ,
				[ 'SAAF' , 'P241:Q1519024' , 'P17:q258' ] ,
				]
		} ,
 
		{
			pre : '<b>PERSON:</b> ' ,
			options : [
				[ 'F' , 'P31:q215627' , 'p21:Q6581072' ] ,
				[ 'M' , 'P31:Q215627' , 'p21:Q6581097' ] ,
				[ 'LH' , 'P552:Q789447' ] ,
				[ 'RH' , 'P552:Q3039938' ] ,
				[ 'SH' , 'P552:Q871529' ] ,
				[ 'AMB' , 'P552:Q457332' ] ,
				[ 'Aviatior' , 'P106:Q2095549' ] ,
				[ 'BB' , 'P106:Q10871364' ] ,
				[ 'P' , 'P106:Q10871364' , 'P413:Q1048902' ] ,
				[ 'SP' , 'P106:Q10871364' , 'P413:Q772148' ] ,
				[ 'RP' , 'P106:Q10871364' , 'P413:Q1198553' ] ,
				[ 'C' , 'P106:Q10871364' , 'P413:Q1050571' ] ,
				[ '1B' , 'P106:Q10871364' , 'P413:Q1326154' ] ,
				[ '2B' , 'P106:Q10871364' , 'P413:Q1368195' ] ,
				[ '3B' , 'P106:Q10871364' , 'P413:Q1368170' ] ,
				[ 'SS' , 'P106:Q10871364' , 'P413:Q1143358' ] ,
				[ 'OF' , 'P106:Q10871364' , 'P413:Q1142885' ] ,
				[ 'LF' , 'P106:Q10871364' , 'P413:Q1149868' ] ,
				[ 'CF' , 'P106:Q10871364' , 'P413:Q5059480' ] ,
				[ 'RF' , 'P106:Q10871364' , 'P413:Q1149560' ] ,
				[ 'DH' , 'P106:Q10871364' , 'P413:Q727270' ] ,
				[ 'MGR' , 'P413:Q1186921' ] ,
				[ 'MLB' , 'P793:q15089689' , 'P793:q15056768' ] ,
				[ 'Pol' , 'P106:Q82955' ] ,
				[ 'Bus' , 'P106:Q43845' ] ,
				[ 'Author' , 'P106:Q482980' ] ,
				]
		} ,
 
		{
			pre : '<b>Awards:</b> ' ,
			options : [
				[ 'MVP' , 'P166:Q1514249' ] ,
				[ 'CYA' , 'P166:Q634857' ] ,
				[ 'AS' , 'P166:Q15074074' ] ,
				[ 'GG' , 'P166:Q120649' ] ,
				[ 'SS' , 'P166:Q1366948' ] ,
				[ 'HAA' , 'P166:Q1518478' ] ,
				[ 'RCA' , 'P166:Q3405246' ] ,
				[ 'ASMVP' , 'P166:Q1051079' ] ,
				[ 'WSMVP' , 'P166:Q1372040' ] ,
				[ 'TSNPIT' , 'P166:q7766029' ] ,
				[ 'TSNPLR' , 'P166:Q952797' ] ,
				[ 'Relief' , 'P166:Q843859' ] ,
				[ 'MMM' , 'P166:Q15141448' ] ,
				]
		} ,
 
		{
			pre : '<b>PLACE:</b> ' ,
			options : [
				[ 'City' , 'P31:Q515' ] ,
				[ 'Town' , 'P31:Q3957' ] ,
				[ 'Vllg' , 'P31:Q532' ] ,
				]
		} ,
 
		{
			pre : '<b>AIRPT:</b> ' ,
			options : [
				[ 'Aerodrome' , 'P31:Q62447' , 'P912:Q184590' , 'P912:Q918324' , 'P912:Q849706' , 'P912:Q1061299' , 'P912:Q247739' , 'P912:Q573970' , 'P912:Q192375' ] ,
				[ 'Airport' , 'P31:Q1248784' , 'P912:Q184590' , 'P912:Q918324' , 'P912:Q849706' , 'P912:Q1061299' , 'P912:Q247739' , 'P912:Q573970' , 'P912:Q192375' ] ,
				[ 'Airfield' , 'P31:Q4273135' , 'P912:Q184590' , 'P912:Q918324' , 'P912:Q573970' , 'P912:Q192375' ] ,
				[ 'Airbase' , 'P31:Q695850' , 'P912:Q184590' , 'P912:Q918324' , 'P912:Q849706' , 'P912:Q247739' , 'P912:Q573970' , 'P912:Q192375' ] ,
				[ 'Seaplane' , 'P31:Q15044480' , 'P912:Q184590' , 'P912:Q918324' , 'P912:Q849706' , 'P912:Q247739' , 'P912:Q573970' , 'P912:Q192375' ] ,
				[ 'Heliport' , 'P31:Q502074' , 'P912:Q184590' , 'P912:Q918324' , 'P912:Q849706' , 'P912:Q247739' , 'P912:Q573970' , 'P912:Q192375' ] ,
				]
		} ,
 
		{
			pre : '<b>Bulgaria:</b> ' ,
			options : [
				[ 'Oblast' , 'P17:Q219' , 'P31:Q209824' ] ,
				[ 'Obshtina' , 'P17:Q219' , 'P31:Q1906268' ] ,
				[ 'City' , 'P17:Q219' , 'P31:Q515' ] ,
				[ 'Town' , 'P17:Q219' , 'P31:Q3957' ] ,
				[ 'Vllg' , 'P17:Q219' , 'P31:Q532' ] ,
				]
		} ,
 
]
] ;
 
 
/************************************************************************************************************************
The section below contains the "Wikidata Usefuls" country list. Add new ones or edit existing ones as you see fit.
*************************************************************************************************************************/
 
var wd_useful_countries = {
	"Afghanistan" : "Q889",
	"Albania" : "Q222",
	"Algeria" : "Q262",
	"Andorra" : "Q228",
	"Angola" : "Q916",
	"Antigua and Barbuda" : "Q781",
	"Argentina" : "Q414",
	"Armenia" : "Q399",
	"Australia" : "Q408",
	"Austria" : "Q40",
	"Azerbaijan" : "Q227",
	"Bahamas" : "Q778",
	"Bahrain" : "Q398",
	"Bangladesh" : "Q902",
	"Barbados" : "Q244",
	"Belarus" : "Q184",
	"Belgium" : "Q31",
	"Belize" : "Q242",
	"Benin" : "Q962",
	"Bhutan" : "Q917",
	"Bolivia" : "Q750",
	"Bosnia and Herzegovina" : "Q225",
	"Botswana" : "Q963",
	"Brazil" : "Q155",
	"Brunei" : "Q921",
	"Bulgaria" : "Q219",
	"Burkina Faso" : "Q965",
	"Burundi" : "Q967",
	"Cambodia" : "Q424",
	"Cameroon" : "Q1009",
	"Canada" : "Q16",
	"Cape Verde" : "Q1011",
	"Central African Republic" : "Q929",
	"Chad" : "Q657",
	"Chile" : "Q298",
	"China" : "Q148",
	"Colombia" : "Q739",
	"Comoros" : "Q970",
	"Costa Rica" : "Q800",
	"Côte d'Ivoire" : "Q1008",
	"Croatia" : "Q224",
	"Cuba" : "Q241",
	"Cyprus" : "Q229",
	"Czech Republic" : "Q213",
	"Democratic Republic of the Congo" : "Q974",
	"Denmark" : "Q35",
	"Djibouti" : "Q977",
	"Dominica" : "Q784",
	"Dominican Republic" : "Q786",
	"East Timor" : "Q574",
	"Ecuador" : "Q736",
	"Egypt" : "Q79",
	"El Salvador" : "Q792",
	"Equatorial Guinea" : "Q983",
	"Eritrea" : "Q986",
	"Estonia" : "Q191",
	"Ethiopia" : "Q115",
	"Fed. St. of Micronesia" : "Q702",
	"Fiji" : "Q712",
	"Finland" : "Q33",
	"France" : "Q142",
	"Gabon" : "Q1000",
	"Gambia" : "Q1005",
	"Georgia" : "Q230",
	"Germany" : "Q183",
	"Germany (Empire)" : "Q43287",
	"Germany (Nazi)" : "Q7318",
	"Germany (Weimar)" : "Q41304",
	"Ghana" : "Q117",
	"Greece" : "Q41",
	"Grenada" : "Q769",
	"Guatemala" : "Q774",
	"Guinea" : "Q1006",
	"Guinea-Bissau" : "Q1007",
	"Guyana" : "Q734",
	"Haiti" : "Q790",
	"Honduras" : "Q783",
	"Hungary" : "Q28",
	"Iceland" : "Q189",
	"India" : "Q668",
	"Indonesia" : "Q252",
	"Iran" : "Q794",
	"Iraq" : "Q796",
	"Ireland" : "Q27",
	"Israel" : "Q801",
	"Italy" : "Q38",
	"Jamaica" : "Q766",
	"Japan" : "Q17",
	"Jordan" : "Q810",
	"Kazakhstan" : "Q232",
	"Kenya" : "Q114",
	"Kiribati" : "Q710",
	"Kuwait" : "Q817",
	"Kyrgyzstan" : "Q813",
	"Laos" : "Q819",
	"Latvia" : "Q211",
	"Lebanon" : "Q822",
	"Lesotho" : "Q1013",
	"Liberia" : "Q1014",
	"Libya" : "Q1016",
	"Liechtenstein" : "Q347",
	"Lithuania" : "Q37",
	"Luxembourg" : "Q32",
	"Macedonia" : "Q221",
	"Madagascar" : "Q1019",
	"Malawi" : "Q1020",
	"Malaysia" : "Q833",
	"Maldives" : "Q826",
	"Mali" : "Q912",
	"Malta" : "Q233",
	"Marshall Islands" : "Q709",
	"Mauritania" : "Q1025",
	"Mauritius" : "Q1027",
	"Mexico" : "Q96",
	"Moldova" : "Q217",
	"Mongolia" : "Q711",
	"Montenegro" : "Q236",
	"Monaco" : "Q235",
	"Morocco" : "Q1028",
	"Mozambique" : "Q1029",
	"Myanmar" : "Q836",
	"Namibia" : "Q1030",
	"Nauru" : "Q697",
	"Nepal" : "Q837",
	"Netherlands" : "Q55",
	"New Zealand" : "Q664",
	"Nicaragua" : "Q811",
	"Niger" : "Q1032",
	"Nigeria" : "Q1033",
	"North Korea" : "Q423",
	"Norway" : "Q20",
	"Oman" : "Q842",
	"Pakistan" : "Q843",
	"Palau" : "Q695",
	"Panama" : "Q804",
	"Papua New Guinea" : "Q691",
	"Paraguay" : "Q733",
	"Peru" : "Q419",
	"Philippines" : "Q928",
	"Poland" : "Q36",
	"Portugal" : "Q45",
	"Qatar" : "Q846",
	"Republic of the Congo" : "Q971",
	"Romania" : "Q218",
	"Russia" : "Q159",
	"Rwanda" : "Q1037",
	"Saint Kitts and Nevis" : "Q763",
	"Saint Lucia" : "Q760",
	"Saint Vincent and the Grenadines" : "Q757",
	"Samoa" : "Q683",
	"San Marino" : "Q238",
	"São Tomé and Príncipe" : "Q1039",
	"Saudi Arabia" : "Q851",
	"Senegal" : "Q1041",
	"Serbia" : "Q403",
	"Seychelles" : "Q1042",
	"Sierra Leone" : "Q1044",
	"Singapore" : "Q334",
	"Slovakia" : "Q214",
	"Slovenia" : "Q215",
	"Solomon Islands" : "Q685",
	"Somalia" : "Q1045",
	"South Africa" : "Q258",
	"South Korea" : "Q884",
	"South Sudan" : "Q958",
	"Spain" : "Q29",
	"Sri Lanka" : "Q854",
	"Sudan" : "Q1049",
	"Suriname" : "Q730",
	"Swaziland" : "Q1050",
	"Sweden" : "Q34",
	"Switzerland" : "Q39",
	"Syria" : "Q858",
	"Tajikistan" : "Q863",
	"Tanzania" : "Q924",
	"Thailand" : "Q869",
	"Togo" : "Q945",
	"Tonga" : "Q678",
	"Trinidad and Tobago" : "Q754",
	"Tunisia" : "Q948",
	"Turkey" : "Q43",
	"Turkmenistan" : "Q874",
	"Tuvalu" : "Q672",
	"Uganda" : "Q1036",
	"Ukraine" : "Q212",
	"United Arab Emirates" : "Q878",
	"United Kingdom" : "Q145",
	"United States" : "Q30",
	"Uruguay" : "Q77",
	"Uzbekistan" : "Q265",
	"Vanuatu" : "Q686",
	"Vatican City" : "Q237",
	"Venezuela" : "Q717",
	"Vietnam" : "Q881",
	"Yemen" : "Q805",
	"Zambia" : "Q953",
	"Zimbabwe" : "Q954"
} ;
 
/************************************************************************************************************************
DO NOT EDIT BELOW THIS LINE UNLESS YOU REALLY KNOW WHAT YOU ARE DOING!
*************************************************************************************************************************/
 
 
/************************************************************************************************************************
DO NOT EDIT BELOW THIS LINE UNLESS YOU REALLY KNOW WHAT YOU ARE DOING!
*************************************************************************************************************************/



var wd_useful_thisis ;
var wgUserLanguage = mw.config.get('wgUserLanguage');
if ( undefined === wd_useful_thisis_langs[wgUserLanguage] ) wd_useful_thisis = wd_useful_thisis_langs['en'] ; // Fallback
else wd_useful_thisis = wd_useful_thisis_langs[wgUserLanguage] ;


function ucFirst(string) {
	return string.substring(0, 1).toUpperCase() + string.substring(1);
}


var wd_useful = {

	q_prefix : 'Q' ,
	p_prefix : 'P' ,
	id_cnt : 0 ,
	api : '/w/api.php' ,
	link2data : [] ,
	bad_images : [ 'Blue morpho butterfly 300x271.jpg' ] , // Replace all underscores with spaces!!!
	
	countries : {} ,
	
	addPropsFromLink : function ( o ) {
		var self = this ;
		var lid = $(o).attr('lid') ;
//		console.log ( self.link2data[lid] ) ;
		var is_running = self.queue.length > 0 ;
		$.each ( self.link2data[lid]||[] , function ( k , v ) {
			var pq = v.split ( ':' ) ;
			if ( pq.length != 2 ) {
				console.log ( "PROBLEM : " + v ) ;
				return ;
			}
			self.queue.push ( { mode:'set' , prop:pq[0] , target_entity:pq[1] } ) ;
		} ) ;
		if ( !is_running ) {
			self.processed = 0 ;
			self.processNextQueueItem () ;
		}
		return false ;


	} ,

	init : function () {
		var self = this ;
		var q = mw.config.get('wgPageName').toUpperCase() ;
		self.q = q ;
		self.queue = [] ;
		if ( typeof wd_useful_thisis_add != 'undefined' ) {
			wd_useful_thisis[0].push ( { pre:'' , options:wd_useful_thisis_add } ) ;
		}	
		self.setTitleTool();
		var h = "<div id='wd_useful_dialog'>" ;
		h += "<div>" ;
		
		var lid = 0 ;
		var maxw = 480 ;
		$.each ( wd_useful_thisis , function ( k1 , v1 ) {
			h += "<div style='margin-bottom:5px'>" ;
			$.each ( v1 , function ( k2 , v2 ) {
				var indent = k2 == 0 ? 10 : 15 ;
				h += "<div style='max-width:"+maxw+"px;text-indent:-10px;margin-left:"+indent+"px;margin-bottom:3px'>" ;
				if ( v2.pre !== undefined ) h += v2.pre ;
				$.each ( v2.options , function ( k3 , v3 ) {
					var title = v3.shift() ;
					self.link2data[lid] = v3 ;
					var h2 = "<a href='#' lid='" + lid + "' onclick='wd_useful.addPropsFromLink(this);return false;'>" + title + "</a>" ;
					if ( k3+1 < v2.options.length ) h2 += '/' ;
					h += "<nobr>" + h2 + '</nobr>' ;
					h += '<wbr/>' ;
					lid++ ;
				} ) ;
				if ( v2.post !== undefined ) h += v2.post ;
				h += "</div>" ;
			} ) ;
			h += "</div>" ;
		} ) ;

		h += "<hr/>" ;
//		h += "|<a href='#' onclick='$(\"#country\").val(\"Q\");return false'></a>" ;
		h += "<a href='#' onclick='$(\"#country\").val(\"Q142\");return false'>France</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q148\");return false'>China</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q183\");return false'>Germany</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q17\");return false'>Japan</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q159\");return false'>Russia</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q145\");return false'>UK</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q30\");return false'>USA</a>" ;
		h += "<br/><a href='#' onclick='$(\"#country\").val(\"Q889\");return false'>Afghanistan</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q222\");return false'>Albania</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q262\");return false'>Algeria</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q228\");return false'>Andorra</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q916\");return false'>Angola</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q781\");return false'>Antigua</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q414\");return false'>Argentina</a>" ;
		h += "<br/><a href='#' onclick='$(\"#country\").val(\"Q399\");return false'>Armenia</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q408\");return false'>Australia</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q40\");return false'>Austria</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q28513\");return false'>Austria-Hungary</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q227\");return false'>Azerbaijan</a>" ;
		h += "<br/><a href='#' onclick='$(\"#country\").val(\"Q778\");return false'>Bahamas</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q398\");return false'>Bahrain</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q902\");return false'>Bangladesh</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q244\");return false'>Barbados</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q184\");return false'>Belarus</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q31\");return false'>Belgium</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q242\");return false'>Belize</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q962\");return false'>Benin</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q917\");return false'>Bhutan</a>" ;
		h += "<br/><a href='#' onclick='$(\"#country\").val(\"Q750\");return false'>Bolivia</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q225\");return false'>Bosnia</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q963\");return false'>Botswana</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q155\");return false'>Brazil</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q921\");return false'>Brunei</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q219\");return false'>Bulgaria</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q965\");return false'>Burkina Faso</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q967\");return false'>Burundi</a>" ;
		h += "<br/><a href='#' onclick='$(\"#country\").val(\"Q424\");return false'>Cambodia</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q1009\");return false'>Cameroon</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q16\");return false'>Canada</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q1011\");return false'>Cape Verde</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q929\");return false'>CAR</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q657\");return false'>Chad</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q298\");return false'>Chile</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q148\");return false'>China</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q739\");return false'>Colombia</a>" ;
		h += "<br/><a href='#' onclick='$(\"#country\").val(\"Q970\");return false'>Comoros</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q800\");return false'>Costa Rica</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q1008\");return false'>Cote d'Ivoire</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q224\");return false'>Croatia</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q241\");return false'>Cuba</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q229\");return false'>Cyprus</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q213\");return false'>Czech Rep</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q33946\");return false'>Czechoslovakia</a>" ;
		h += "<br/><a href='#' onclick='$(\"#country\").val(\"Q974\");return false'>DRC</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q35\");return false'>Denmark</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q977\");return false'>Djibouti</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q784\");return false'>Dominica</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q786\");return false'>Dominican Rep</a>" ;
		h += "<br/><a href='#' onclick='$(\"#country\").val(\"Q574\");return false'>E.Timor</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q736\");return false'>Ecuador</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q79\");return false'>Egypt</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q792\");return false'>El Salvador</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q983\");return false'>Eq Guinea</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q986\");return false'>Eritrea</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q191\");return false'>Estonia</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q115\");return false'>Ethiopia</a>" ;
		h += "<br/><a href='#' onclick='$(\"#country\").val(\"Q712\");return false'>Fiji</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q33\");return false'>Finland</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q142\");return false'>France</a>" ;
		h += "<br/><a href='#' onclick='$(\"#country\").val(\"Q38\");return false'>Italy</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q55\");return false'>Netherlands</a>" ;
		h += "|<a href='#' onclick='$(\"#country\").val(\"Q29\");return false'>Spain</a>" ;
		h += "<br/><select id='country'></select>" ;
		h += "<br/>" ;
		h += "<a href='#' onclick='wd_useful.useCountry(17);return false'>Country</a> | " ;
		h += "<a href='#' onclick='wd_useful.useCountry(27);return false'>C. of citizenship | </a>" ;
		h += "<a href='#' onclick='wd_useful.useCountry(137);return false'>Operator</a>" ;
		h += "</div>" ;
		
		h += "</div>" ;
		$('#mw-content-text').append ( h ) ;
		
		var main = $('#wb-item-'+self.q.toUpperCase()) ;
		$('#wd_useful_dialog').dialog ( {
			modal : false ,
			title : 'Wikidata Usefuls' ,
			width : 'auto' ,
			position : { my: "left top", at: "right top", of: $('div.wb-ui-descriptionedittool') } , // main
			open: function( event, ui ) {
				$('#wd_useful_dialog a').css ( { color:'#0b0080' } ) ;
				main.focus() ;
			}
		} ) ;
		$('#wd_useful_dialog a').blur();
		self.loadCountries () ;
		self.tryDesc() ;
		self.autoName() ;
		self.tryAutoAdd() ;
		self.autoRenameStatements () ;
		self.showQ() ;
	} ,
	
	showImages : function () {
		var self = this ;
		self.image_container_id = 'wd_wp_images' ;
		self.thumbsize = 128 ;
		var h = "<div id='" + self.image_container_id + "'></div>" ;
		$($('div.wb-claims').get(0)).prepend ( h ) ;
		
		self.images = {} ;
		
		var cnt = 0 ;
		var finish = function () {
			cnt-- ;
			if ( cnt > 0 ) return ; // Not done
			var found_any = false ;
			$.each ( self.images , function() { found_any = true } ) ;
			if ( found_any ) {
				$('#'+self.image_container_id).append ( '<i>All&nbsp;images&nbsp;loaded.</i>' ) ;
			} else {
				$('#'+self.image_container_id).append ( '<i>No images found.</i>' ) ;
			}
		} ;
		
		$.each ( (self.sitelinks||{}) , function ( wiki , v0 ) {
//		$.each ( ({enwiki:{title:"Peter_David"}}) , function ( wiki , v0 ) { // TESTING
			var lang = wiki.replace(/wiki$/,'') ;
			var title = v0.title ;
			cnt++ ;
			$.getJSON ( '//'+lang+'.wikipedia.org/w/api.php?callback=?' , {
				action:'query' ,
				generator:'images' ,
				titles:title ,
				gimlimit:500 ,
				prop:'imageinfo' ,
				iiprop:'url|size' ,
				iiurlwidth:self.thumbsize ,
				iiurlheight:self.thumbsize ,
				format:'json'
			} , function ( data ) {
				if ( data.query === undefined ) return finish() ;
				$.each ( (data.query.pages||{}) , function ( pid , page ) {
					if ( page.imagerepository != 'shared' ) return ; // Commons only
					if ( null != page.title.match ( /\.svg/i ) ) return ;
					if ( null != page.title.replace(/_/g,' ').match ( /\bstub\b/i ) ) return ;
					self.addImage ( page.title , page.imageinfo[0] ) ;
				} ) ;
				finish() ;
			} ) ;
		} ) ;
	} ,
	
	addImage : function ( file , imageinfo ) {
		var self = this ;
		var title = file.replace(/^[^:]+:/i,'').replace(/_/g,' ') ;
		if ( undefined !== self.images[title] ) return ; // Had that
		if ( -1 != $.inArray ( title , self.bad_images ) ) return ; // Don't want that
		if ( (imageinfo.width||999)<150 && (imageinfo.height||999)<150 ) return ; // Too small
		self.images[title] = imageinfo ;
		var left = Math.floor ( (self.thumbsize-imageinfo.thumbwidth)/2 ) ;
		var top = Math.floor ( (self.thumbsize-imageinfo.thumbheight)/2 ) ;
		var h = "<div style='margin:2px;display:inline-block;text-align:center' nowrap>" ;
		h += "<a href='" + imageinfo.descriptionurl + "' target='_blank'>" ;
		h += "<img alt='Loading...' border=0 style='padding-top:"+top+"px;padding-left:"+left+"px;padding;right:"+left+"px;padding-bottom:"+top+"px' src='" + imageinfo.thumburl + "' title='" + title.replace(/['"]/g,'') + "' /></a><br/>" ;
		h += "<a href='#' onclick='wd_useful.asImage(\"" + escape(title) + "\",\"image\");return false'>Image</a>/" ;
		h += "<a href='#' onclick='wd_useful.asImage(\"" + escape(title) + "\",\"logo\");return false'>logo</a>/" ;
		h += "<a href='#' onclick='wd_useful.asImage(\"" + escape(title) + "\",\"map\");return false'>map</a>/" ;
		h += "<a href='#' onclick='wd_useful.asImage(\"" + escape(title) + "\",\"signature\");return false' title='Signature'>sig</a>/" ;
		h += "<a href='#' onclick='wd_useful.asImage(\"" + escape(title) + "\",\"coa\");return false' title='Coat of Arms'>CoA</a>" ;
		h += "</div>" ;
		$('#'+self.image_container_id).append ( h ) ;
	} ,
	
	asImage : function ( title , type ) {
		var self = this ;
		title = unescape ( title ) ;
//		console.log ( title + " as " + type ) ;
		var p ;
		if ( type == 'image' ) p = 18 ;
		else if ( type == 'map' ) p = 242 ;
		else if ( type == 'logo' ) p = 154 ;
		else if ( type == 'signature' ) p = 109 ;
		else if ( type == 'coa' ) p = 94 ;
		else {
			console.log ( "asImage : unknown type " + type ) ;
			return ;
		}
		var o = { mode:'set_string' , s:title , entity:self.q , prop:self.p_prefix+p } ;
		console.log ( o ) ;
		self.queue.push ( o ) ;
		self.processNextQueueItem () ;
	} ,
	
	autoRenameStatements : function () {
		var self = this ;
		entity = self.q_prefix + self.q.replace ( /\D/g , '' ) ;
		$.getJSON ( self.api , {
			action : 'wbgetentities' ,
			format : 'json' ,
			ids : entity ,
			props : 'info|claims|sitelinks'
		} , function ( data ) {
			if ( undefined === data.entities[entity] ) return ;
			self.sitelinks = data.entities[entity].sitelinks ;
			if ( undefined === data.entities[entity].claims ) return ;
			$.each ( data.entities[entity].claims , function ( p , v ) {
				if ( p=='P28'|p=='P11'||p=='P12'||p=='P28'||p=='P83'||p=='P34' ) { // replacing deprecated properties with "located in administrative unit"
					self.replaceClaimProperty ( { old_prop : p , new_prop : 'P131' , claim : v } ) ;
				}
			} ) ;
			self.processNextQueueItem () ;
		} ) ;
	} ,
	
	replaceClaimProperty : function ( data ) {
		var self = this ;
		$.each ( data.claim , function ( k , v ) {
			var nid = v.mainsnak.datavalue.value['numeric-id'] ;
//			console.log ( data.old_prop + " => " + data.new_prop + " : " + nid ) ;
			self.queue.push ( { mode:'set' , prop:data.new_prop , target_entity:self.q_prefix+nid } ) ;
			self.queue.push ( { mode:'remove' , prop:data.old_prop , target_entity:self.q_prefix+nid } ) ;
		} ) ;
	} ,
	
	showQ : function () {
		$('div.valueview a').each ( function ( k , v ) {
			var url = $(v).attr('href') || '' ;
			var m = url.match ( /\/[qQ](\d+)$/ ) ;
			if ( m != null ) {
				var h = " <span style='color:#999999'><i>q" + m[1] + "</i></span>" ;
				$(v).after ( h ) ;
			}
		} ) ;
	} ,
	
	duplicateStatementsFromItemList : function () {
		var self = this ;
		var lang = 'en' ;
		var name = prompt("Enter a Wikidata page with item list : ", "");//'Wikidata:Tropical cyclones task force/standard/Atlantic' ;
		if ( name == null ) return ;
		self.dupCount = 0 ;
		self.processed = 0 ;
		self.claims = {} ;
		//http://wikidata.org/w/api.php?action=query&prop=links&titles=Wikidata:Tropical%20cyclones%20task%20force/standard/Atlantic&plnamespace=0&pllimit=500&format=jsonfm

		$.getJSON ( self.api , {
				action : 'wbgetentities' ,
				ids : self.q ,
				languages : lang ,
				format : 'json'
			} , function ( d0 ) {
			
				$.each ( d0.entities||[] , function ( k , v ) {
					self.claims = v.claims ;
				} ) ;
			
				$.getJSON ( '//www.wikidata.org/w/api.php?callback=?' , {
					action : 'query' ,
					prop : 'links' ,
					titles : name ,
					plnamespace : 0 ,
					pllimit : 500 ,
					format : 'json'
				} , function ( data ) {
					$.each ( data.query.pages , function ( k1 , v1 ) {
						$.each ( v1.links , function ( k , v ) {
							self.duplicateStatementsToEntity ( v.title ) ;
						} ) ;
					} ) ;
			} ) ;
		} ) ;

	} ,
	
	duplicateStatements : function () {
		var self = this ;
		var lang = 'en' ;
		var cat = prompt("Enter a en.wp category : ", "");//'Compositions_by_Pyotr_Ilyich_Tchaikovsky' ;
		if ( cat == null ) return ;
		self.dupCount = 0 ;
		self.processed = 0 ;
		self.claims = {} ;
		
		$.getJSON ( self.api , {
				action : 'wbgetentities' ,
				ids : self.q ,
				languages : lang ,
				format : 'json'
			} , function ( d0 ) {
			
				$.each ( d0.entities||[] , function ( k , v ) {
					self.claims = v.claims ;
				} ) ;
			
				$.getJSON ( '//'+lang+'.wikipedia.org/w/api.php?callback=?' , {
					action : 'query' ,
					list : 'categorymembers' ,
					cmtitle : 'Category:' + cat ,
					cmnamespace : 0 ,
					cmlimit : 500 ,
					format : 'json'
				} , function ( data ) {
					$.each ( data.query.categorymembers , function ( k , v ) {
						var t = v.title ;
						if ( t.match ( /^List[_ ]/ ) ) return ; // No lists!
						self.dupCount++ ;
						$.getJSON ( self.api , {
							action : 'wbgetentities' ,
							sites : lang+'wiki' ,
							titles : t ,
							languages : lang ,
							format : 'json'
						} , function ( d2 ) {
							$.each ( d2.entities||[] , function ( k2 , v2 ) {
//								self.dupCount++ ;
								self.duplicateStatementsToEntity ( k2 , v2 ) ;
							} ) ;
							self.dupCount-- ;
							if ( self.dupCount == 0 ) self.processNextQueueItem() ;
						} ) ;
//						if ( k > 5 ) return false ; // TESTING
					} ) ;
			} ) ;
		} ) ;
	} ,
	
	duplicateStatementsToEntity : function ( q , target ) {
		var self = this ;
		if ( q == self.q || q.replace(/\D/g,'')=='1' ) {
			return ;
		}
		
		$.each ( self.claims , function ( p , v ) {
			var nid = v[0].mainsnak.datavalue.value['numeric-id'] ;
			if ( nid === undefined ) return ;
			var o = { mode:'set' , prop:p , target_entity:self.q_prefix+nid , entity:q } ;
			self.queue.push ( o ) ;
		} ) ;

	} ,
	
	tryAutoAdd : function () {
		var self = this ;
		$('.wb-property-container-value .wb-value').each ( function ( k , v ) {
			var t = $(v).text() ;
			if ( t == 'Wikipedia disambiguation page' ) self.isDisambiguation() ;
		} ) ;
	} ,
	
	tryDesc : function () {
		var self = this ;
		var lang ;
		var title ;
		$.each ( ['en','de','nl','fr','it','es','ru','pl','ja','pt','zh','el','sv','nl'] , function ( k , l ) {
			var t = $('.wb-sitelinks-link-'+l+'wiki a').text() ;
			if ( t == '' ) return ;
			lang = l ;
			title = t ;
			return false ;
		} ) ;
		if ( lang === undefined ) return ;
		$.getJSON ( '//'+lang+'.wikipedia.org/w/api.php?callback=?' , {
			action : 'query' ,
			prop : 'extracts' ,
//			exsentences : 5 ,
			exchars : 300 ,
			titles : title ,
			format : 'json'
		} , function ( data ) {
			$.each ( data.query.pages , function ( k , v ) {
				//$($('table.wb-sitelinks').get(2)).after ( v.extract ) ;
				$($('#wd_useful_dialog > div').get(0)).append ( "<div style='max-width:335px;margin-top:5px;border-top:1px solid black'>"+v.extract+"</div>" ) ;
				self.wdUsefulprocessExtract(v.extract) ;
			} ) ;
		} ) ;
	} ,
	
	useCountry : function ( v ) {
		var self = this ;
		var cq = $('#country').val().replace(/\D/g,'') ;
		var prop = v;
//		self.running = true ;
		self.queue.push ( { mode:'set' , prop:self.p_prefix+prop , target_entity:self.q_prefix+cq } ) ;
//		self.queue.push ( [ self.p_prefix+prop , self.q_prefix+cq ] ) ;
		self.processed = 0 ;
		self.processNextQueueItem () ;
	} ,
	
	loadCountries : function () {
		var self = this ;
		self.countries = wd_useful_countries ;
		//JSON.parse ( "{\"Angola\":\"Q916\",\"Botswana\":\"Q963\",\"Burkina Faso\":\"Q965\",\"Burundi\":\"Q967\",\"Comoros\":\"Q970\",\"Romania\":\"Q218\",\"Republic of the Congo\":\"Q971\",\"Democratic Republic of the Congo\":\"Q974\",\"Djibouti\":\"Q977\",\"Equatorial Guinea\":\"Q983\",\"Gabon\":\"Q1000\",\"Gambia\":\"Q1005\",\"Guinea\":\"Q1006\",\"Guinea-Bissau\":\"Q1007\",\"Côte d'Ivoire\":\"Q1008\",\"Cameroon\":\"Q1009\",\"Lesotho\":\"Q1013\",\"Liberia\":\"Q1014\",\"Madagascar\":\"Q1019\",\"Malawi\":\"Q1020\",\"Mauritania\":\"Q1025\",\"Mauritius\":\"Q1027\",\"Morocco\":\"Q1028\",\"Mozambique\":\"Q1029\",\"Namibia\":\"Q1030\",\"Niger\":\"Q1032\",\"Nigeria\":\"Q1033\",\"Uganda\":\"Q1036\",\"Rwanda\":\"Q1037\",\"Sao Tomé and Príncipe\":\"Q1039\",\"Scotland\":\"Q22\",\"Seychelles\":\"Q1042\",\"Sierra Leone\":\"Q1044\",\"Somalia\":\"Q1045\",\"Sudan\":\"Q1049\",\"Swaziland\":\"Q1050\",\"Soviet Union\":\"Q15180\",\"Mexico\":\"Q96\",\"Netherlands\":\"Q55\",\"Russian Empire\":\"Q34266\",\"Egypt\":\"Q79\",\"Canada\":\"Q16\",\"Timor-Leste\":\"Q574\",\"Chad\":\"Q657\",\"New Zealand\":\"Q664\",\"India\":\"Q668\",\"Tonga\":\"Q678\",\"Kiribati\":\"Q710\",\"Mongolia\":\"Q711\",\"Fiji\":\"Q712\",\"Suriname\":\"Q730\",\"Paraguay\":\"Q733\",\"Guyana\":\"Q734\",\"Ecuador\":\"Q736\",\"Colombia\":\"Q739\",\"Bolivia\":\"Q750\",\"Saint Vincent and the Grenadines\":\"Q757\",\"Saint Lucia\":\"Q760\",\"Saint Kitts and Nevis\":\"Q763\",\"Jamaica\":\"Q766\",\"Grenada\":\"Q769\",\"Honduras\":\"Q783\",\"Dominica\":\"Q784\",\"Dominican Republic\":\"Q786\",\"Iran\":\"Q794\",\"Iraq\":\"Q796\",\"Israel\":\"Q801\",\"Panama\":\"Q804\",\"Yemen\":\"Q805\",\"Jordan\":\"Q810\",\"Nicaragua\":\"Q811\",\"Kyrgyzstan\":\"Q813\",\"Kuwait\":\"Q817\",\"Laos\":\"Q819\",\"Lebanon\":\"Q822\",\"Myanmar\":\"Q836\",\"Nepal\":\"Q837\",\"Pakistan\":\"Q843\",\"Vietnam\":\"Q881\",\"South Korea\":\"Q884\",\"Afghanistan\":\"Q889\",\"Mali\":\"Q912\",\"Bhutan\":\"Q917\",\"Brunei\":\"Q921\",\"Tanzania\":\"Q924\",\"Philippines\":\"Q928\",\"Central African Republic\":\"Q929\",\"Togo\":\"Q945\",\"Tunisia\":\"Q948\",\"Turkey\":\"Q43\",\"Zambia\":\"Q953\",\"Zimbabwe\":\"Q954\",\"Benin\":\"Q962\",\"Japan\":\"Q17\",\"Norway\":\"Q20\",\"Republic of Ireland\":\"Q27\",\"Hungary\":\"Q28\",\"Spain\":\"Q29\",\"United States of America\":\"Q30\",\"Belgium\":\"Q31\",\"Luxembourg\":\"Q32\",\"Finland\":\"Q33\",\"Sweden\":\"Q34\",\"Denmark\":\"Q35\",\"Poland\":\"Q36\",\"Lithuania\":\"Q37\",\"Italy\":\"Q38\",\"Switzerland\":\"Q39\",\"Austria\":\"Q40\",\"Greece\":\"Q41\",\"Uruguay\":\"Q77\",\"Kenya\":\"Q114\",\"Ghana\":\"Q117\",\"France\":\"Q142\",\"United Kingdom\":\"Q145\",\"China\":\"Q148\",\"Brazil\":\"Q155\",\"Russia\":\"Q159\",\"Germany\":\"Q183\",\"Belarus\":\"Q184\",\"Iceland\":\"Q189\",\"Estonia\":\"Q191\",\"Latvia\":\"Q211\",\"Ukraine\":\"Q212\",\"Czech Republic\":\"Q213\",\"Slovakia\":\"Q214\",\"Moldova\":\"Q217\",\"Bulgaria\":\"Q219\",\"Croatia\":\"Q224\",\"Bosnia and Herzegovina\":\"Q225\",\"Cyprus\":\"Q229\",\"Georgia\":\"Q230\",\"Indonesia\":\"Q252\",\"South Africa\":\"Q258\",\"Uzbekistan\":\"Q265\",\"Chile\":\"Q298\",\"Singapore\":\"Q334\",\"Liechtenstein\":\"Q347\",\"Armenia\":\"Q399\",\"Serbia\":\"Q403\",\"Australia\":\"Q408\",\"Argentina\":\"Q414\",\"Cambodia\":\"Q424\",\"Federated States of Micronesia\":\"Q702\"}" ) ;
		self.showCountries() ;
		
		return ;
		$.getJSON ( self.api , {
			action : 'query' ,
			list : 'backlinks' ,
			bltitle : 'Q3624078' ,
			bllimit : 500 ,
			blnamespace : 0 ,
			format : 'json'
		} , function ( data ) {
			var qs = [] ;
			$.each ( data.query.backlinks , function ( k , v ) {
				qs.push ( v.title ) ;
			} ) ;
			var chunk = 50 ;
			self.loading_country_chunks = 0 ;
			for (i=0,j=qs.length; i<j; i+=chunk) {
				self.loading_country_chunks++ ;
				var tmp = qs.slice(i,i+chunk);
				self.addCountries ( tmp ) ;
			}
		} ) ;
	} ,

	showCountries : function () {
		var self = this ;
		var h = '' ;
		var keys = [] ;
		$.each ( self.countries , function ( name , k ) { keys.push ( name ) } ) ;
		keys = keys.sort() ;
		$.each ( keys , function ( dummy , name ) {
			h += "<option value='" + self.countries[name] + "'>" + name + "</option>" ;
		} ) ;
		$('#country').html ( h ) ;
	} ,
	
	addCountries : function ( qs ) {
		var self = this ;
		$.getJSON ( self.api , {
			action : 'wbgetentities' ,
			ids : qs.join('|').toUpperCase() ,
			languages : 'en' ,
			format : 'json'
		} , function ( data ) {
			$.each ( data.entities , function ( k , v ) {
				var name = v.labels.en.value ;
				self.countries[name] = k ;
			} ) ;
			self.loading_country_chunks-- ;
			if ( self.loading_country_chunks > 0 ) return ;
			self.showCountries() ;
		} ) ;
	} ,

	isDisambiguation : function () {
		var self = this ;
//		self.queue.push ( { mode:'set' , prop:'P107' , target_entity:'Q11651459' } ) ;
		self.processed = 0 ;
		self.processNextQueueItem () ;
		return false ;
	} ,
	
	autoName : function () {
		var self = this ;
		
		var key = 'h1 input.wb-ui-propertyedittool-editablevalueinterface' ;
		var t = $($(key).get(0)) ;
		if ( t.val() != '' || t.tagName == 'span' ) return ; // Already has a title
		
		$.each ( ['en','de','fr','it','nl','sv','es'] , function ( k , v ) {
			var title = $($('td.wb-sitelinks-link-'+v + ' a').get(0)).text() ;
			if ( title == '' ) return ;
			title = title.replace ( /\s\(.+$/ , '' ) ;
			$($(key).get(0)).val(title).css({'background-color':'red'}) ;
			$($(key).get(0)).focus();
			
			return false ;
		} ) ;
	} ,
	
	processNextQueueItem : function () {
		var self = this ;
		if ( self.queue.length == 0 ) {
//			self.running = false ;
			if ( self.processed == 0 ) {
//				alert ( "No changes" ) ;
				return ;
			}
			// DONE
//			console.log ( "DONE" ) ;
//			location.reload();
			return ;
		}
		var q = self.queue.shift () ;
		if ( undefined === q.entity ) q.entity = self.q ;
		if ( q.mode == 'set' ) {
			var val = '{"entity-type":"item","numeric-id":' + q.target_entity.replace(/\D/g,'') + '}' ;
			self.tryCreateClaim ( q.entity , q.prop , val ) ;
		} else if ( q.mode == 'set_string' ) {
			var val = JSON.stringify ( q.s ) ;
			self.tryCreateClaim ( q.entity , q.prop , val ) ;
		} else if ( q.mode == 'remove' ) {
			var val = '{"entity-type":"item","numeric-id":' + q.target_entity.replace(/\D/g,'') + '}' ;
			self.tryRemoveClaim ( q.entity , q.prop , val ) ;
		} else {
			console.log ( q ) ;
		}
	} ,

	tryRemoveClaim : function ( entity , property , value ) {
		var self = this ;
		entity = self.q_prefix + entity.replace ( /\D/g , '' ) ;
		property = property.replace ( /\D/g , '' ) ;
		var value2 = JSON.parse ( value ) ;
		var nid = value2['numeric-id'] ;
		$.getJSON ( self.api , {
			action : 'wbgetentities' ,
			format : 'json' ,
			ids : entity ,
			props : 'info|claims'
		} , function ( data ) {
			if ( undefined !== data.entities[entity] ) {
				if ( undefined !== data.entities[entity].claims ) {
					if ( undefined !== data.entities[entity].claims[self.p_prefix+property] ) {
						var n = data.entities[entity].claims[self.p_prefix+property] ;
						var exists = false ;
						var id ;
						$.each ( n , function ( k , v ) {
							if ( v.mainsnak.datavalue.value['numeric-id'] == value.replace(/\D/g,'') ) {
								exists = true ;
								id = v.id ;
								return false ;
							}
						} ) ;
						if ( exists ) {
							self.removeClaim ( { revid:data.entities[entity].lastrevid , claim:id , entity:entity } ) ; // entity , property , value
//							console.log ( "p"+property+' exists for '+entity ) ;
							return ;
						}
					}
				}
			}
			console.log ( "Failed to remove " + entity + " / " + property + " : " + value ) ;
			self.processNextQueueItem() ;
		} ) ;
	} ,
		
	removeClaim : function ( o ) {
		var self = this ;
//		console.log ( "REMOVING" ) ;
//		console.log ( o ) ;
		$.post ( self.api , {
			action : 'query' ,
			prop : 'info' ,
			intoken : 'edit' ,
			titles : o.entity ,
			format : 'json'
		} , function ( data ) {
			var token , lastrevid ;
			$.each ( (data.query.pages||[]) , function ( k , v ) {
				token = v.edittoken ;
				lastrevid = v.lastrevid ;
			} ) ;
			
			if ( undefined === token ) {
				console.log ( "Cannot get edit token for " + entity ) ;
				self.processNextQueueItem() ;
				return ;
			}

			$.post ( self.api , {
				action : 'wbremoveclaims' ,
				claim : o.claim ,
				token : token ,
				baserevid : o.revid ,
				format : 'json'
			} , function ( data ) {
				var h = "<div style='color:red'>Removed " + JSON.stringify ( o ) + "</div>" ;
				$($('div.wb-claims').get(0)).append ( h ) ;

				self.processed++ ;
				self.processNextQueueItem() ;
			} , 'json' ) ;
			
			
			
		} , 'json' ) ;
	} ,

	tryCreateClaim : function ( entity , property , value ) {
		var self = this ;
		entity = self.q_prefix + entity.replace ( /\D/g , '' ) ;
		property = property.replace ( /\D/g , '' ) ;
		var value2 = JSON.parse ( value ) ;
		var nid = value2['numeric-id'] === undefined ? value2 : value2['numeric-id'] ;
		$.getJSON ( self.api , {
			action : 'wbgetentities' ,
			format : 'json' ,
			ids : entity ,
			props : 'info|claims'
		} , function ( data ) {
			if ( undefined !== data.entities[entity] ) {
				if ( undefined !== data.entities[entity].claims ) {
					if ( undefined !== data.entities[entity].claims[self.p_prefix+property] ) {
						var n = data.entities[entity].claims[self.p_prefix+property] ;
						var exists = false ;
						$.each ( n , function ( k , v ) {
							var the_val = v.mainsnak.datavalue.value['numeric-id'] === undefined ? v.mainsnak.datavalue.value : v.mainsnak.datavalue.value['numeric-id'] ;
							if ( the_val == nid ) {
								exists = true ;
								return false ;
							}
						} ) ;
						if ( exists ) {
							console.log ( "P"+property+' exists for '+entity ) ;
							self.processNextQueueItem() ;
							return ;
						}
					}
				}
			}
			self.createClaim ( entity , property , value ) ;
		} ) ;
	} ,
		
		
	createClaim : function ( entity , property , value ) {
//		console.log ( "Creating " + entity + " / " + property + " / " + value ) ;
		var self = this ;
		$.post ( self.api , {
			action : 'query' ,
			prop : 'info' ,
			intoken : 'edit' ,
			titles : entity ,
			format : 'json'
		} , function ( data ) {
			var token , lastrevid ;
			$.each ( (data.query.pages||[]) , function ( k , v ) {
				token = v.edittoken ;
				lastrevid = v.lastrevid ;
			} ) ;
			
			if ( undefined === token ) {
				console.log ( "Cannot get edit token for " + entity ) ;
				self.processNextQueueItem() ;
				return ;
			}
			
			property = property.replace(/\D/g,'') ;
			entity = entity.replace(/\D/g,'') ;
			var vo = JSON.parse ( value ) ;
//			console.log ( vo ) ;
			var is_item_target = vo['numeric-id'] !== undefined ;
			var value_id = is_item_target ? vo['numeric-id']+'' : vo ;
			
			var other_entity = ( entity.replace(/\D/g,'') != self.q.replace(/\D/g,'') ) ;
			
			$.post ( self.api , {
				action : 'wbcreateclaim' ,
				entity : self.q_prefix+entity ,
				snaktype : 'value' ,
				property : self.p_prefix+property ,
				value : value ,
				token : token ,
				baserevid : lastrevid ,
				format : 'json'
			} , function ( data ) {
				var id = 'added_' + self.id_cnt ;
				var h = "<div id='" + id + "'>" ;
				h += "Added " ;
				h += "<span class='added_entity_P'>" + property + "</span>" ;
				h += " &Rarr; " ;
				h += "<span class='added_entity_Q'>" + value_id + "</span>" ;
				if ( other_entity ) h += " to entity <span class='added_entity_x'>" + entity + "</span>" ;
				h += ".</div>" ;
				$($('div.wb-claims').get(0)).append ( h ) ;
				self.updateEntity ( id , property , self.p_prefix ) ;
				if ( is_item_target ) self.updateEntity ( id , value_id , self.q_prefix ) ;
				if ( is_item_target && other_entity ) self.updateEntity ( id , entity.replace(/\D/g,'') , 'x' ) ;
				self.id_cnt++ ;
				
				self.processed++ ;
				self.processNextQueueItem() ;
			} , 'json' ) ;
			
			
			
		} , 'json' ) ;
	
	} ,
	
	updateEntity : function ( id , value , prefix ) {
		var self = this ;
		var q = prefix+value ;
		if ( prefix == 'x' ) q = self.q_prefix + value ;
		console.log ( q ) ;
		$.getJSON ( self.api , {
			action : 'wbgetentities' ,
			ids : q ,
			format : 'json'
		} , function ( data ) {
			var labels = data.entities[q].labels ;
			var title = q ;
			if ( undefined !== labels ) {
				$.each ( ['en','de','fr'] , function ( k , v ) {
					if ( undefined === labels[v] ) return ;
					title = labels[v].value ;
					return false ;
				} ) ;
			}
			var h = "<a href='/wiki/" + q + "'>" + title + "</a>" ;
			$('#'+id+' span.added_entity_'+prefix).html ( h ) ;
		} ) ;
	} ,


	wdUsefulprocessExtract : function ( t ) {
		var months = {
			'january' : [ 'januar' , 'januari' , 'janvier' , 'jänner' , 'de enero de' , 'gennaio' ] ,
			'february' : [ 'februar' , 'februari' , 'février' , 'febbraio' , 'de febrero de' ] ,
			'march' : [ 'märz' , 'maart' , 'marzo' , 'mars' , 'de Marzo del' ] ,
			'april' : [ 'avril' , 'de abril de' , 'aprile' ] ,
			'may' : [ 'mei' , 'mai' , 'de mayo de' , 'maggio' ] ,
			'june' : [ 'juni' , 'juin' , 'de junio de' , 'giugno' ] ,
			'july' : [ 'juli' , 'juillet' , 'de julio de' ] ,
			'august' : [ 'augustus' , 'août', 'aout' , 'agosto' , 'de agosto de' ] ,
			'september' : [ 'septembre' , 'setiembre' , 'de septiembre de' ] ,
			'october' : [ 'oktober' , 'octobre','października' , 'de octubre de' ] ,
			'november' : [ 'novembre' , 'de noviembre de' ] ,
			'december' : [ 'dezember' , 'décembre' , 'diciembre','grudnia','de diciembre de','dicembre']
		} ;
		var m2n = {
			january:'01',
			february:'02',
			march:'03',
			april:'04',
			may:'05',
			june:'06',
			july:'07',
			august:'08',
			september:'09',
			october:'10',
			november:'11',
			december:'12'	
		} ;
		
		var found = false ;
		var h = '<div style="margin-top:5px;border-top:1px solid black">' ;
		h += "<div>Auto-detected birth/death dates:</div>" ;
		
		// Dates
		t = t.replace ( /<b>.+?<\/b>/ ) ;
		var m = t.match ( /\((.+?)\)/ ) ;
		if ( m == null  ) m = [ '' , t ] ; // Fallback
		if ( m != null ) {
			var s = m[1] ;
			s = s.toLowerCase() ;
			s = s.replace ( /&#160;/g , ' ' ) ; // Weird French template
			$.each ( months , function ( en , other ) {
				$.each ( other , function ( k , v ) {
					var r = new RegExp ( '\\b,*de\\s'+v+'\\sde,*\\b' , 'ig' ) ;
					s = s.replace ( r , en ) ;
					r = new RegExp ( '\\b'+v+'\\b' , 'ig' ) ;
					s = s.replace ( r , en ) ;
				} ) ; 
			} ) ;

			m = s.match ( /(\d{1,2})\.{0,1}\s+(january|february|march|april|may|june|july|august|september|october|november|december)\s+(\d{3,4})/g ) ;
			if ( m == null ) {
				m = s.match ( /\b(january|february|march|april|may|june|july|august|september|october|november|december)\s+(\d{1,2})\.{0,1}\,{0,1}\s+(\d{3,4})/g ) ;
			}
			
			var had_year = {} ;
			if ( m != null ) {
				$.each ( m , function ( k , v ) {
					var d = v.toLowerCase().replace(/,/g,'').replace(/\./g,'').split(' ') ;
					var day = '' , month = '' , year = '' ;
					$.each ( d , function ( k2 , v2 ) {
						if ( undefined !== m2n[v2] ) month = m2n[v2] ;
						else if ( v2.match(/^\d{3,4}$/) ) year = v2 ;
						else if ( v2.match(/^\d{1,2}$/) ) day = v2 ;
					} ) ;
					while ( year.length < 4 ) year = '0'+year ;
					while ( day.length < 2 ) day = '0'+day ;
					var time = "+0000000"+year+"-"+month+"-"+day+"T00:00:00Z" ;
					
					found = true ;
					var h2 = '' ;
					h2 += "<div>" + v ;
					h2 += " <a href='#' onclick='wd_useful.setDate(569,\""+time+"\",11);return false'>born</a>" ; // Born
					h2 += " <a href='#' onclick='wd_useful.setDate(570,\""+time+"\",11);return false'>died</a>" ; // Died
					h2 += "</div>" ;
					had_year[year] = h2 ;
	
				} ) ;
			}
			
			// try years only
			m = s.match ( /\b(\d{3,4})\b/g ) ;
			if ( m != null ) {
				$.each ( m , function ( k , year ) {
					year += '' ;
					while ( year.length < 4 ) year = '0'+year ;
					if ( undefined !== had_year[year] ) return ;
					var time = "+0000000"+year+"-01-01T00:00:00Z" ;
					found = true ;
					var h2 = '' ;
					h2 += "<div>" + year ;
					h2 += " <a href='#' onclick='wd_useful.setDate(569,\""+time+"\",9);return false'>born</a>" ; // Born
					h2 += " <a href='#' onclick='wd_useful.setDate(570,\""+time+"\",9);return false'>died</a>" ; // Died
					h2 += "</div>" ;
					had_year[year] = h2 ;
				} ) ;
			}

			var yk = [] ;
			$.each ( had_year , function ( k , v ) { yk.push ( k ) } ) ;
			yk.sort () ;
			$.each ( yk , function ( dummy , year ) { h += had_year[year] ;	})
			
		}


		h += "</div>" ;
		if ( found ) {
			$('#wd_useful_dialog > div').after ( h ) ;
			$('#wd_useful_dialog a').css ( { color:'#0b0080' } ) ;
		}
	} ,

	setDate : function (prop,date,prec) {
		var val = '{"time":"'+date+'","timezone": 0,"before": 0,"after": 0,"precision": '+prec+',"calendarmodel": "http://www.wikidata.org/entity/Q1985727"}' ;
//		console.log ( val ) ;
		wd_useful.createClaim ( wd_useful.q+'' , prop+'' , val ) ;
	} ,

	setTitleTool : function () {
		if ( $($('.wb-ui-propertyedittool-editablevalueinterface').get(0)).text() != '' ) return ; // Already has title
		$('td.wb-sitelinks-link').each ( function () {
			var o = $(this) ;
			var t = o.text() ;
			if ( t === undefined ) return ;
			t = t.replace(/\s*\(.+\)/,'')
			var h = " <a href='#' class='set-title-tool'>&uArr;</a>" ;
			o.parent().append ( "<td>"+h+"</td>" ) ;
			o.parent().find('a.set-title-tool').click ( function () {
				$('a.set-title-tool').remove() ;
				$($('input.wb-ui-propertyedittool-editablevalueinterface').get(0)).val(t).focus().click().keypress() ;
				return false ;
			}) ;
		})
	} ,


	the_end : ''
} ;

jQuery(document).ready ( function() {
	if ( mw.config.get('wgNamespaceNumber') != 0 ) return ;
	if ( mw.config.get('wgAction') != 'view' ) return ;
	
	setTimeout ( function(){wd_useful.init () ;} , 300 ) ;
});