User:Dr pda/persondata.js: Difference between revisions

Content deleted Content added
m modifying regexp to correctly remove flag images when followed by more wikilinks
added whitespace before and after persondata template, added check for no categories, made 'add pdata' tab only appear for articles (namespace 0)
Line 142:
NAME = format_name(pagename);
}
var persondata = "\n\n<!-- Metadata: see [[Wikipedia:Persondata]] -->\n{{Persondata\n|NAME="+NAME+"\n|ALTERNATIVE NAMES="+ALTERNATIVE_NAMES+"\n|SHORT DESCRIPTION="+SHORT_DESCRIPTION+"\n|DATE OF BIRTH="+DATE_OF_BIRTH+"\n|PLACE OF BIRTH="+PLACE_OF_BIRTH+"\n|DATE OF DEATH="+DATE_OF_DEATH+"\n|PLACE OF DEATH="+PLACE_OF_DEATH+"\n}}\n\n";
 
var persondata = "<!-- Metadata: see [[Wikipedia:Persondata]] -->\n{{Persondata\n|NAME="+NAME+"\n|ALTERNATIVE NAMES="+ALTERNATIVE_NAMES+"\n|SHORT DESCRIPTION="+SHORT_DESCRIPTION+"\n|DATE OF BIRTH="+DATE_OF_BIRTH+"\n|PLACE OF BIRTH="+PLACE_OF_BIRTH+"\n|DATE OF DEATH="+DATE_OF_DEATH+"\n|PLACE OF DEATH="+PLACE_OF_DEATH+"\n}}\n";
 
var insertPosition = text.indexOf('[[Category:')-1;
if(text.match('{{DEFAULTSORT')) insertPosition = text.indexOf('{{DEFAULTSORT')-1;
if(insertPosition != -2){
document.getElementById('wpTextbox1').value = text.substr(0,insertPosition)+persondata+text.substr(insertPosition+1);
document.getElementById('wpSummarywpTextbox1').value += 'adding [[WP:PDATA|text.substr(0,insertPosition)+persondata]]'+text.substr(insertPosition+1);
}
else{
alert('This article does not belong to any categories! Consider adding some.');
document.getElementById('wpTextbox1').value = text.substr(0,insertPosition)+persondata+text.substr(insertPosition+1);
}
document.getElementById('wpSummary').value += ' adding [[WP:PDATA|persondata]] using [[User talk:Dr pda/persondata.js|this script]]';
document.getElementById('wpDiff').click();
 
}
 
Line 172 ⟶ 178:
}
else{
if (wgNamespaceNumber == 0 && document.getElementById('wpTextbox1').value.match(/persondata/i) == null){
addPortletLink('p-cactions', 'javascript:suggestPersonData()', 'add persondata', 'ca-pdata', 'add persondata metadata', '', '');
}