মিডিয়াউইকি:Gadget-TemplatePreloader.js: সংশোধিত সংস্করণের মধ্যে পার্থক্য

বিষয়বস্তু বিয়োগ হয়েছে বিষয়বস্তু যোগ হয়েছে
Pathoschild (আলোচনা | অবদান)
fix
Phe (আলোচনা | অবদান)
update, do some automatic filling of Author:* when creating a new page
২০৩ নং লাইন:
wpTextbox1.value = "{{textinfo\n | edition = \n | source = \n | contributors = \n | progress = \n | notes = \n | proofreaders = \n}}\n"
}
}
 
// When creating an author page try to fill some field if an
// article is available on wp:en
function author_fill_cb(data)
{
try {
var wpTextbox1 = document.getElementById("wpTextbox1");
if (wpTextbox1 && !data.query.pages["-1"]) {
for (var ids in data.query.pages) {
wpTextbox1.value = wpTextbox1.value.replace(/( *\\| *wikipedia_link *= *)/, "$1" + data.query.pages[ids].title);
var cats = data.query.pages[ids].categories;
for (var i = 0; i < cats.length; ++i) {
var m = cats[i].title.match(/Category:(\d+) deaths/);
if (m)
wpTextbox1.value = wpTextbox1.value.replace(/( *\\| *deathyear *= *)/, "$1" + m[1]);
m = cats[i].title.match(/Category:(\d+) births/);
if (m)
wpTextbox1.value = wpTextbox1.value.replace(/( *\\| *birthyear *= *)/, "$1" + m[1]);
}
break;
}
}
}
catch (err) { }
}
 
function create_script_obj(url)
{
var scriptObj = document.createElement("script");
scriptObj.setAttribute("type", "text/javascript");
scriptObj.setAttribute("src", url);
document.body.appendChild(scriptObj);
}
 
২০৯ ⟶ ২৪২ নং লাইন:
{
var wpTextbox1 = document.getElementById("wpTextbox1")
if (wpTextbox1.value =!= "") return;
 
{
// try to figure out what value we can fill, broken in some case because
wpTextbox1.value = "{{author\n | firstname = \n | lastname = \n | last_initial = \n | birthyear = \n | deathyear = \n | description = \n | image = \n | wikipedia_link = \n | wikiquote_link = \n | commons_link = \n}}\n\n==Works==\n\n"
// it's difficult to handle name like Tom Van Moore
}
var words = wgTitle.split(" ");
var lastname = words[words.length - 1];
words = words.slice(0, -1);
var firstname = words.join(" ");
var last_initial = lastname.slice(0, 2);
// O'Donnel --> Od
if (lastname.length > 2 && last_initial.charAt(1) == "'")
last_initial = last_initial.charAt(0) + lastname.charAt(2).toLowerCase();
 
text_box.value = "{{" + "author\n" +
" | firstname = " + firstname + "\n" +
" | lastname = " + lastname + "\n" +
" | last_initial = " + last_initial + "\n" +
" | birthyear = \n" +
" | deathyear = \n" +
" | description = \n" +
" | image = \n" +
" | wikipedia_link = \n" +
" | wikiquote_link = \n" +
" | commons_link = \n" +
"}}\n\n" +
"==Works==\n\n";
 
var base_url = "http://en.wikipedia.org"
+ wgScriptPath
+ "/api.php?format=json&redirects";
 
var url = base_url
+ "&callback=author_fill_cb&action=query&prop=categories&cllimit=20&titles="
+ encodeURIComponent(wgTitle);
 
create_script_obj(url);
}