User:Alex Smotrov/adm/delreason.js

var delReason = new function{

//*** On article page: try to find wpReason from template

var caDelete

this.onArticlePage = function { if (caDelete = document.getElementById('ca-delete')) caDelete.onclick = delReason.fixDelLink }

this.fixDelLink = function { var template, i, links, wpReason = '' if (template = document.getElementById('delete')){ //search for CSD criteria inside {Db-xxx} links = template.getElementsByTagName('a') for (i=0; i<links.length; i++) if (links[i].title == 'WP:CSD') { wpReason = links[i].href.split('#')[1] break } }else if (template = document.getElementById('afd')){ links = template.getElementsByTagName('a') for (i=0; i<links.length; i++) //search for discussion link inside {afd} if (links[i].title.indexOf('Wikipedia:Articles for deletion/') != -1) { wpReason = 'After discussion at ['+'[' + links[i].title + ']]' break } }else if (template = document.getElementById('prod')){ wpReason = 'Prod left uncontested for five days' if (i = document.getElementById('delete-reason')) wpReason += ' (' + i.innerHTML + ')' } if (wpReason) caDelete.firstChild.href += '&wpReason=' + wpReason }

//*** On delete page

var reasons = { 'CSD Reasons':'', "G1 - Nonsense":"CSD G1: Patent Nonsense", "G2 - Test Pages":"CSD G2: Test Pages", "G3 - Pure Vandalism":"CSD G3: Pure Vandalism", "G4 - Recreated Deleted":"CSD G4: Recreation of deleted material", "G5 - Banned User":"CSD G5: Contributions by Banned User", "G6 - Housekeeping":"CSD G6: Housekeeping", "G7 - Author Request":"CSD G7: Author Requests Deletion", "G8 - Talk Page":"CSD G8: Talkpage of non-Existent Article", "G9 - Office Actions":"CSD G9: Office Actions", "G10 - Attack Pages":"CSD G10: Attack Page", "G11 - Advertising":"CSD G11: Blatant Advertising", "G12 - Copyright":"CSD G12: Blatant Copyright infringement", "A1 - No Context":"CSD A1: Very short article providing little or no context", "A2 - Foreign Language":"CSD A2: Foreign language article that exists on another Wikipedia", "A3 - No Content":"CSD A3: No content", "A5 - Transwikied":"CSD A5: Has been transwikied", "A7 - Unremarkable Bio":"CSD A7 (Bio): Biographical article that does not assert significance", "A7 - Unremarkable Group":"CSD A7 (Group): Article about a club or group that does not assert significance", "A7 - Unremarkable Band":"CSD A7 (Band): Article about a band that does not assert significance", "A7 - Unremarkable Firm":"CSD A7 (Corp): Article about a company that doesn't assert significance", "A7 - Unremarkable Web":"CSD A7 (Web): Article about a web site that does not assert significance", "A7 - Other":"CSD A7: Article about subject that does not assert significance.", "R1 - Bad Target":"CSD R1: Redirect to non-existent page", "R2 - Crossnamespace":"CSD R2: Redirect to User/User talk namespaces from mainspace", "R3 - Bad Typo":"CSD R3: Implausible typo", "I1 - Redundant":"CSD I1: Redundant to another image", "I2 - Corrupt/Empty":"CSD I2: Image is corrupted", "I3 - Improper License":"CSD I3: Improper license", "I4 - Lack of License":"CSD I4: No license or No Source Information", "I5 - Unused Unfree":"CSD I5: Is unused and not free", "I6 - No Fair Use":"CSD I6: No justification given for fair use", "I7 - Invalid Fair Use":"CSD I7: Bad justification given for fair use", "I8 - On Commons":"CSD I8: Image exists on the Commons", "C1 - Empty":"CSD C1: Category is Empty (and has been for 4 days or more)", "C2 - Speedy Rename":"CSD C2: Speedy Renaming", "C3 - Template":"CSD C3: Corresponding template was deleted", "U1 - User Request":"CSD U1: User requested deletion", "U2 - No User":"CSD U2: Userpage of non-existent user", "U3 - Fair Use Gallery":"CSD U3: Userpage that is primarily a gallery of fair use images", "T1 - Divisive":"CSD T1: Template that is divisive and inflammatory.", "P2 - Underpopulated":"CSD P2: Underpopulated", "AFD close":"AFD: Deleted after discussion at Articles for Deletion", "Prod close":"Prod left uncontested for five days." }

var wpReason, wpSelect, csdLink, defReason

this.onDeletePage = function{ //get wpReason wpReason = document.getElementById('wpReason') if (!wpReason) return if (window.wpReasonSize) wpReason.size = wpReasonSize //create drop-down box wpSelect = document.createElement('select') wpSelect.style.marginLeft = '5px' var i, ma, option for (i in reasons){ option = document.createElement('option') option.value = reasons[i] option.title = reasons[i] option.appendChild(document.createTextNode(i)) wpSelect.appendChild(option) } wpSelect.options[0].style.color = 'gray' wpReason.parentNode.insertBefore(wpSelect, wpReason.nextSibling) //CSD link csdLink = document.createElement('span') wpSelect.parentNode.insertBefore(csdLink, wpSelect.nextSibling) //'append default reason' link if (document.URL.indexOf('&wpReason=') == -1){ defReason = wpReason.value var a = document.createElement('a') a.innerHTML = '<' a.title = 'Append default reason' a.href = 'javascript:delReason.appendDefaultReason' a.style.marginLeft = '4px' wpReason.parentNode.insertBefore(a, wpReason.nextSibling) } //assign events addEvent(wpSelect, 'change', delReason.replaceReason) addEvent(wpReason, 'keyup', delReason.autoReplace) addEvent(wpReason, 'mouseup', delReason.autoReplace) delReason.autoReplace }

this.replaceReason = function{ wpReason.value = wpSelect.value var ma = wpSelect.value.match(/\[\[([^\]]+)#([^\]]+)\|.+\]\]/) if (ma && ma.length==3) //show CSD link csdLink.innerHTML = ' (' + ma[2] + ')' else csdLink.innerHTML = '' }

this.autoReplace = function{ if (!wpReason.value.match(/^[GARICUTP]\d\d?$/)) return for (var i=1; i<wpSelect.options.length; i++) if (wpSelect.options[i].value.indexOf('#'+wpReason.value+'|') != -1){ wpSelect.selectedIndex = i    delReason.replaceReason break } }

this.appendDefaultReason = function{ if (wpReason.value.indexOf(defReason.substring(0,15)) != -1) return if (wpReason.value) wpReason.value += '; ' wpReason.value += defReason }

}//delReason

function addEvent(obj, event, func) { if (obj.addEventListener) obj.addEventListener( event, func, false ); else if (obj.attachEvent) obj.attachEvent ('on'+event, func) }

if (wgAction == 'delete') addOnloadHook(delReason.onDeletePage) else if (wgNamespaceNumber >= 0) addOnloadHook(delReason.onArticlePage)

//ru:User:Alex Smotrov/adm/delreason.js