מדיה ויקי:Gadget-WikidataTab.js: הבדלים בין גרסאות בדף
מראה
מ ←using [[mw:CodeEditor|CodeEditor]]: הוספת פורטלים |
מ 9 גרסאות של הדף wikipedia:he:מדיה_ויקי:Gadget-WikidataTab.js יובאו |
||
| (4 גרסאות ביניים של 3 משתמשים אינן מוצגות) | |||
| שורה 1: | שורה 1: | ||
if ($.inArray(mw.config.get('wgNamespaceNumber'), [0, 4, 10, 12, 14, 100]) + 1) | if ($.inArray(mw.config.get('wgNamespaceNumber'), [0, 4, 10, 12, 14, 100]) + 1) | ||
$(function ($) { | $(function($) { | ||
var translate = { | |||
'he': { | |||
notfound: "לא נמצאה כותרת ויקינתונים", | |||
nolabel: "(אין תווית)", | |||
nodescription: "(אין תיאור)" | |||
}, | |||
'en': { | |||
notfound: "Wikidata item not found", | |||
nolabel: "(No label)", | |||
nodescription: "(no description given)" | |||
} | |||
}, | }, | ||
pagename = mw.config.get('wgPageName').replace(/_/g, " "); | |||
$.ajax({ | |||
url: '//www.wikidata.org/w/api.php', | |||
data: { | |||
'format': 'json', | |||
'action': 'wbgetentities', | |||
'sites': mw.config.get('wgDBname'), | |||
'titles': pagename, | |||
'props': 'info|labels|descriptions|aliases', | |||
'languages': mw.config.get('wgPageContentLanguage') | |||
}, | |||
dataType: 'jsonp', | |||
success: function(data) { | |||
var d = $("<li>") | |||
.addClass("mw-list-item") | |||
.appendTo("#p-views ul"); | |||
if (data.success) { | |||
var lang = mw.config.get('wgPageContentLanguage'), | |||
m = translate[lang] || translate.he; | |||
for (var i in data.entities) { | |||
if (i == -1) { | |||
d.append( | |||
$("<span>") | |||
.append( | |||
$("<a>") | |||
.attr("href", "//www.wikidata.org/wiki/Special:CreateItem?setlang=he&label=" + pagename + "&site=hewiki&page=" + pagename) | |||
.attr("title", m.notfound) | |||
.append( | |||
$("<img>") | |||
.attr("src", "//upload.wikimedia.org/wikipedia/commons/e/e8/Wikidata-favicon.png") | |||
.attr("style", "margin-bottom: 5px; opacity:0.3; filter:alpha(opacity=30);") | |||
) | |||
) | |||
); | |||
} else { | |||
var item = data.entities[i], | |||
i = 0, | |||
aliases = []; | |||
try { | |||
for (; i < item.aliases[lang].length; i++) { | |||
aliases.push(item.aliases[lang][i].value); | |||
}); | } | ||
}); | } catch (e) { } | ||
d.append( | |||
$("<span>") | |||
.append( | |||
$("<a>") | |||
.attr("href", "//www.wikidata.org/wiki/" + item.title) | |||
.attr("title", ((item.labels && item.labels[lang]) ? item.labels[lang].value : m.nolabel) + " (" + item.title + "):" + ((item.descriptions && item.descriptions[lang]) ? item.descriptions[lang].value : m.nodescription)) | |||
.append( | |||
$("<img>") | |||
.attr("src", "//upload.wikimedia.org/wikipedia/commons/e/e8/Wikidata-favicon.png") | |||
.attr("style", "margin-bottom: 5px;") | |||
) | |||
) | |||
); | |||
} // else | |||
} // for | |||
} // if success | |||
} // succeess function | |||
}); // ajax | |||
}); // ready | |||
גרסה אחרונה מ־07:25, 5 בדצמבר 2022
if ($.inArray(mw.config.get('wgNamespaceNumber'), [0, 4, 10, 12, 14, 100]) + 1)
$(function($) {
var translate = {
'he': {
notfound: "לא נמצאה כותרת ויקינתונים",
nolabel: "(אין תווית)",
nodescription: "(אין תיאור)"
},
'en': {
notfound: "Wikidata item not found",
nolabel: "(No label)",
nodescription: "(no description given)"
}
},
pagename = mw.config.get('wgPageName').replace(/_/g, " ");
$.ajax({
url: '//www.wikidata.org/w/api.php',
data: {
'format': 'json',
'action': 'wbgetentities',
'sites': mw.config.get('wgDBname'),
'titles': pagename,
'props': 'info|labels|descriptions|aliases',
'languages': mw.config.get('wgPageContentLanguage')
},
dataType: 'jsonp',
success: function(data) {
var d = $("<li>")
.addClass("mw-list-item")
.appendTo("#p-views ul");
if (data.success) {
var lang = mw.config.get('wgPageContentLanguage'),
m = translate[lang] || translate.he;
for (var i in data.entities) {
if (i == -1) {
d.append(
$("<span>")
.append(
$("<a>")
.attr("href", "//www.wikidata.org/wiki/Special:CreateItem?setlang=he&label=" + pagename + "&site=hewiki&page=" + pagename)
.attr("title", m.notfound)
.append(
$("<img>")
.attr("src", "//upload.wikimedia.org/wikipedia/commons/e/e8/Wikidata-favicon.png")
.attr("style", "margin-bottom: 5px; opacity:0.3; filter:alpha(opacity=30);")
)
)
);
} else {
var item = data.entities[i],
i = 0,
aliases = [];
try {
for (; i < item.aliases[lang].length; i++) {
aliases.push(item.aliases[lang][i].value);
}
} catch (e) { }
d.append(
$("<span>")
.append(
$("<a>")
.attr("href", "//www.wikidata.org/wiki/" + item.title)
.attr("title", ((item.labels && item.labels[lang]) ? item.labels[lang].value : m.nolabel) + " (" + item.title + "):" + ((item.descriptions && item.descriptions[lang]) ? item.descriptions[lang].value : m.nodescription))
.append(
$("<img>")
.attr("src", "//upload.wikimedia.org/wikipedia/commons/e/e8/Wikidata-favicon.png")
.attr("style", "margin-bottom: 5px;")
)
)
);
} // else
} // for
} // if success
} // succeess function
}); // ajax
}); // ready