Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F11125834
Gadget-EasyQuery.js
rafidaslam (Rafid Aslam)
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
rafidaslam
Dec 1 2017, 5:51 PM
2017-12-01 17:51:17 (UTC+0)
Size
5 KB
Referenced Files
None
Subscribers
None
Gadget-EasyQuery.js
View Options
$
(
function
()
{
if
(
mw
.
config
.
get
(
'wgNamespaceNumber'
)
!==
0
)
{
return
;
}
function
createPopupAndAddIcon
(
element
,
url
,
title
,
label
)
{
mw
.
loader
.
using
(
[
'oojs-ui-core'
,
'oojs-ui-widgets'
]
).
done
(
function
()
{
var
searchIcon
=
new
OO
.
ui
.
IconWidget
(
{
icon
:
'ellipsis'
,
iconTitle
:
title
,
$element
:
$
(
'<a>'
,
{
href
:
'https://query.wikidata.org/'
+
url
,
target
:
'_blank'
,
style
:
'background-size: 20px 20px; opacity: 0.5;'
}
)
}
);
var
$content
=
$
(
'<div>'
);
var
popup
=
new
OO
.
ui
.
PopupWidget
(
{
$content
:
$content
,
width
:
500
,
head
:
true
,
padded
:
false
,
label
:
label
,
align
:
'force-right'
}
);
$
(
document
).
keydown
(
function
(
e
)
{
// ESCAPE key pressed
if
(
e
.
keyCode
===
27
)
{
popup
.
onCloseButtonClick
();
}
}
);
searchIcon
.
$element
.
click
(
function
()
{
$content
.
html
(
$
(
'<iframe scrolling="yes" frameborder="0">'
)
.
attr
(
'src'
,
'https://query.wikidata.org/embed.html'
+
url
)
.
width
(
500
)
.
height
(
400
)
);
popup
.
$element
.
attr
(
'style'
,
'position:absolute; z-index:100;'
);
popup
.
toggle
(
true
);
return
false
;
}
);
$
(
element
).
append
(
searchIcon
.
$element
);
$
(
element
).
append
(
popup
.
$element
);
}
);
}
// Title lable popup
var
$title
=
$
(
'.wikibase-title'
),
id
=
$title
.
find
(
'.wikibase-title-id'
).
text
().
replace
(
/[()]/g
,
''
),
url
=
'#%23defaultView%3AGraph%0ASELECT%20%3Fnode%20%3FnodeLabel%20%3FnodeImage%20%3FchildNode%20%3FchildNodeLabel%20%3FchildNodeImage%20%3Frgb%20WHERE%20%7B%0A%20%20%7B%0A%20%20%20%20BIND%28wd%3A'
+
id
+
'%20AS%20%3Fnode%29%0A%20%20%20%20%3Fnode%20%3Fp%20%3Fi.%0A%20%20%20%20OPTIONAL%20%7B%20%3Fnode%20wdt%3AP18%20%3FnodeImage.%20%7D%0A%20%20%20%20%3FchildNode%20%3Fx%20%3Fp.%0A%20%20%20%20%3FchildNode%20rdf%3Atype%20wikibase%3AProperty.%0A%20%20%20%20FILTER%28STRSTARTS%28STR%28%3Fi%29%2C%20%22http%3A%2F%2Fwww.wikidata.org%2Fentity%2FQ%22%29%29%0A%20%20%20%20FILTER%28STRSTARTS%28STR%28%3FchildNode%29%2C%20%22http%3A%2F%2Fwww.wikidata.org%2Fentity%2FP%22%29%29%0A%20%20%7D%0A%20%20UNION%0A%20%20%7B%0A%20%20%20%20BIND%28%22EFFBD8%22%20AS%20%3Frgb%29%0A%20%20%20%20wd%3A'
+
id
+
'%20%3Fp%20%3FchildNode.%0A%20%20%20%20OPTIONAL%20%7B%20%3FchildNode%20wdt%3AP18%20%3FchildNodeImage.%20%7D%0A%20%20%20%20%3Fnode%20%3Fx%20%3Fp.%0A%20%20%20%20%3Fnode%20rdf%3Atype%20wikibase%3AProperty.%0A%20%20%20%20FILTER%28STRSTARTS%28STR%28%3FchildNode%29%2C%20%22http%3A%2F%2Fwww.wikidata.org%2Fentity%2FQ%22%29%29%0A%20%20%7D%0A%20%20OPTIONAL%20%7B%0A%20%20%20%20%3Fnode%20wdt%3AP18%20%3FnodeImage.%0A%20%20%20%20%3FchildNode%20wdt%3AP18%20%3FchildNodeImage.%0A%20%20%7D%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22'
+
mw
.
config
.
get
(
'wgUserLanguage'
)
+
'%22.%20%7D%0A%7D'
;
createPopupAndAddIcon
(
$title
.
find
(
'.wikibase-title-id'
),
url
,
'Click to see graph'
,
'Entity Graph'
);
mw
.
hook
(
'wikibase.entityPage.entityLoaded'
).
add
(
function
(
entityData
)
{
// Statement popups
$
(
'.wikibase-statementgroupview'
).
each
(
function
()
{
var
pid
=
$
(
this
).
attr
(
'id'
),
pLabel
=
$
(
this
).
find
(
'.wikibase-statementgroupview-property-label'
).
text
();
$
(
'.wikibase-statementgroupview#'
+
pid
)
.
find
(
'.wikibase-statementview-mainsnak-container'
)
.
find
(
'.wikibase-snakview-value'
)
.
each
(
function
()
{
var
pidTemp
,
pLabelTemp
,
qid
,
qLabel
,
type
,
value
,
pElement
=
$
(
this
).
parents
(
'.wikibase-snakview'
)
.
find
(
'.wikibase-snakview-property'
).
find
(
'a'
);
if
(
pElement
.
length
)
{
pidTemp
=
pElement
.
attr
(
'title'
).
split
(
':'
)[
1
];
pLabelTemp
=
pElement
.
text
();
}
else
{
pidTemp
=
pid
;
pLabelTemp
=
pLabel
;
}
qid
=
$
(
this
).
find
(
'a'
).
attr
(
'title'
);
qLabel
=
$
(
this
).
find
(
'a'
).
text
();
if
(
!
qid
)
{
if
(
$
(
this
).
find
(
'a'
).
length
===
0
)
{
if
(
$
(
this
).
find
(
'.wb-monolingualtext-value'
).
length
)
{
qLabel
=
$
(
this
).
find
(
'.wb-monolingualtext-value'
).
html
();
qid
=
null
;
}
else
{
qLabel
=
$
(
this
).
html
();
try
{
datavalue
=
entityData
.
claims
[
pidTemp
][
0
].
mainsnak
.
datavalue
;
type
=
datavalue
.
type
;
}
catch
(
e
)
{
type
=
null
;
}
if
(
type
===
'time'
)
{
time
=
datavalue
.
value
.
time
;
qid
=
'"'
+
time
+
'"^^xsd:dateTime'
;
}
else
if
(
type
===
'quantity'
)
{
amount
=
datavalue
.
value
.
amount
;
qid
=
amount
;
}
else
{
qid
=
'"'
+
qLabel
+
'"'
;
}
}
}
}
else
{
qid
=
'wd:'
+
qid
;
}
if
(
qid
)
{
// console.log(qid);
var
url
=
'#SELECT%20%3Fitem%20%3Flabel%20%3F_image%20WHERE%20%7B%0A%20%20%3Fitem%20wdt%3A'
+
pidTemp
+
'%20'
+
qid
+
'.%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%0A%20%20%20%20bd%3AserviceParam%20wikibase%3Alanguage%20%22'
+
mw
.
config
.
get
(
'wgUserLanguage'
)
+
'%22%20.%20%0A%20%20%20%20%3Fitem%20rdfs%3Alabel%20%3Flabel%0A%20%20%7D%0A%20%20%0AOPTIONAL%20%7B%20%3Fitem%20wdt%3AP18%20%3F_image.%20%7D%0A%7D%0ALIMIT%20100'
;
createPopupAndAddIcon
(
this
,
url
,
'More "'
+
pLabelTemp
+
'" "'
+
qLabel
+
'"'
,
'"'
+
pLabelTemp
+
'" "'
+
qLabel
+
'"'
);
}
}
);
}
);
}
);
}
);
File Metadata
Details
Attached
Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5146264
Default Alt Text
Gadget-EasyQuery.js (5 KB)
Attached To
Mode
T176565: Fix the "Query is malformed" error in the "EasyQuery" JavaScript gadget on wikidata.org
Attached
Detach File
Event Timeline
Log In to Comment