MediaWiki:Wikibugs.js
/*
; Original source: http://pl.wikipedia.org/wiki/MediaWiki:Wikibugs.js
; Russian adaptation: :ru:User:Александр Сигачёв, :ru:User:Putnik, :ru:User:LEMeZza
; English adaptation: :ru:User:Claymore
; Spanish adaptation: :es:User:Emijrp
; English adaptation: :en:User:Rd232
; Original idea: :pl:User:Dodek, :pl:User:Adziura
; Implementation: :pl:User:Nux, :pl:User:Saper, :pl:User:Beau, :ru:User:Putnik
- /
// Define pages where it's not needed or tends to encourage submission of large volumes of unrelated errors; instead, these load CSS which hides Report A Bug
var excludedPages = [
"Main_Page", "Wikipedia:Content_noticeboard",
"MSN", "Hotmail", "Facebook", "Twitter", "Skype", "Amazon", "Windows_Live_Messenger", "Yahoo!_Mail", "Windows_Live", "Internet_Explorer"
];
// special pages, file pages and file talk pages, and MediaWiki pages are excluded
if ($.inArray(mw.config.get('wgNamespaceNumber'), [-1 , 6 , 7 , 8]) !== -1) {
importStylesheet('MediaWiki:Wikibugs.css')
} else {
for (var i=excludedPages.length; i>=0; i--) {
if (mw.config.get('wgPageName')==excludedPages[i]) {
importStylesheet('MediaWiki:Wikibugs.css')
break
}
}
}
var wb$description = "Please provide as much information as possible about the error you\'ve found in Wikipedia, so that volunteers can act on your report and improve Wikipedia. If possible, please provide a reference or website allowing them to verify any information you provide."
$(function(){
var el = document.getElementById('n-bug_in_article')
if (el)
el.getElementsByTagName('a')[0].onclick = wb$popWikibug
});
function wb$popWikibug(){
var link_wiki = mw.config.get('wgArticlePath').replace(/\$1/, 'wiki')
var link_tocreate = mw.config.get('wgArticlePath').replace(/\$1/, 'Wikipedia:Requested_articles')
var link_bebold = mw.config.get('wgArticlePath').replace(/\$1/, 'Wikipedia:Be_bold')
var link_buglist = mw.config.get('wgArticlePath').replace(/\$1/, 'Wikipedia:Content_noticeboard')
wb$popBugBoth("Wikipedia:Content_noticeboard", '\
This system is only for reporting errors in Wikipedia articles.
\DO NOT REPORT errors on other websites (such as Facebook or Twitter), as Wikipedia volunteers cannot help you with those.
\Please do not report missing articles here - instead go to request an article be created.
If you\'ve found an error, try to fix it yourself, since wiki technology means anyone can edit.
\Don\'t be afraid to do it yourself - one of Wikipedia\'s rules is "be bold in editing articles"!.
\If you can\'t or don\'t know how to fix the error, then report it here and other Wikipedia volunteer editors will look into it.
\Do not provide contact details such as telephone or email (this is unnecessary and they would be public).
\ \See the Terms of Use and the Privacy Policy.
\')
return false
}
function wb$getEditToken(page){
var objhttp = (window.XMLHttpRequest) ? new XMLHttpRequest(): new ActiveXObject('Microsoft.XMLHTTP')
if (!objhttp)
return
objhttp.onreadystatechange=function() {
if (objhttp.readyState == 4) {
if (objhttp.status == 200) {
var r_sti = /value="(\d+)" name=["']wpStarttime["']/
var r_eti = /value="(\d+)" name=["']wpEdittime["']/
var r_etk = /value="(.*?)" name=["']wpEditToken["']/
var r_asm = /name="wpAutoSummary" type="hidden" value="(.*?)"/
sti = r_sti.exec(objhttp.responseText)
eri = r_eti.exec(objhttp.responseText)
etk = r_etk.exec(objhttp.responseText)
asm = r_asm.exec(objhttp.responseText)
document.getElementById('Starttime').value=sti[1]
document.getElementById('Edittime').value=eri[1]
document.getElementById('EditToken').value=etk[1]
document.getElementById('AutoSummary').value=asm[1]
}
else
alert(objhttp.status)
}
}
objhttp.open("GET", mw.config.get('wgServer')+mw.config.get('wgScript')+"?title="+encodeURIComponent(page)+"&action=edit")
objhttp.send("")
}
function wb$isValidPageName(name){
if (name=="")
return false
else
return true
}
function wb$checkForm(form){
var page = form.wpSummary.value
var content = form.wpTextbox1.value
if (content=="" || content==wb$description || content.length<20 || !content.match(' ')) {
alert("The report is too short - please provide more details.")
form.wpTextbox1.focus()
return false
}
page = page.replace(/^https?:\/\/en\.wikipedia\.org\/wiki\/(.+)$/, "$1")
page = page.replace(/_/g, " ")
page = decodeURIComponent(page)
if (page == mw.config.get('wgPageName').replace(/_/g, " ") && wb$isValidPageName(mw.config.get('wgPageName'))) {
page = page.replace(/^(Category:|\/)/, ":$1")
page = ""+page+""
} else {
page = page.replace(/\[\[([^\[\]\|]+)\|[^\[\]\|]+\]\]/g, "$1")
page = page.replace(/[\[\]\|]/g, "")
page = page.replace(/^\s+/g, "")
page = page.replace(/\s+$/g, "")
if (! wb$isValidPageName(page) ) {
alert("Enter the article name.")
if ( wb$isValidPageName(mw.config.get('wgPageName')) )
form.wpSummary.value = mw.config.get('wgPageName')
else {
form.wpSummary.value = ""
form.wpSummary.focus()
}
return false
}
if (page.indexOf(':') > 0)
page = ':'+page+''
else
page = ''+page+''
}
form.submit.disabled = 'disabled'
content += '\r\n\r\nSubmitted by: ~~'+'~~'
form.wpTextbox1.value = content
form.wpSummary.value = page
return true
}
function wb$goToEditPage(){
var edit_el = document.getElementById('ca-edit')
var edit_href = mw.config.get('wgArticlePath').replace(/\$1/, 'Wikipedia:Content_noticeboard')
if (edit_el)
edit_href = edit_el.getElementsByTagName('a')[0].href
window.location = edit_href
}
function wb$popBugBoth(action_page, infoHTML){
var glob = document.body;
// shadow
var nel = document.createElement('div')
nel.id='specpop-globhidden'
nel.style.cssText = 'background:white;filter:alpha(opacity=75);opacity:0.75;position:absolute;left:0px;top:0px;z-index:2000'
nel.style.width = document.documentElement.scrollWidth+'px'
nel.style.height= document.documentElement.scrollHeight+'px'
glob.appendChild(nel)
// move the dialog
window.scroll(0, 150)
// information
var edit_el = document.getElementById('ca-edit')
if (edit_el)
var can_edit = true
else
var can_edit = false
nel = document.createElement('div')
nel.id='specpop-info'
nel.style.cssText = 'font-size:13px;background:white;padding:21px 30px;border:1px solid black;position:absolute;width:520px;min-height:300px;top:200px;z-index:2002'
if (nel.style.maxHeight==undefined)
nel.style.height='300px' // IE blah
var tmp = Math.floor(glob.clientWidth/2)-300
if (tmp<5)
tmp = 5
nel.style.left = tmp+'px'
nel.innerHTML = infoHTML
if (mw.config.get('wgUserName') == null)
nel.innerHTML = nel.innerHTML + '
Note. Your IP address is recorded in the public page history. To avoid this you can create a user account.
'nel.innerHTML += '
\
'+(can_edit ? '' : '')+ '\
\
\
'glob.appendChild(nel)
var action_url = mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" +encodeURIComponent(action_page) + "&action=submit"
// form
nel = document.createElement('div')
nel.id = 'specpop-form'
nel.style.cssText = 'background:white;padding:5px 10px;border:1px solid black;position:absolute;width:330px;min-height:300px;top:200px;z-index:2001'
if (nel.style.maxHeight==undefined)
nel.style.height='300px' // IE blah
nel.style.left = (Math.floor(glob.clientWidth/2)-165)+'px'
//nel.style.top = (this.offsetTop-100)+'px'
nel.innerHTML = '
'glob.appendChild(nel)
if (wb$isValidPageName(mw.config.get('wgPageName')))
document.getElementById('wpSummary').value = mw.config.get('wgPageName').replace(/_/g, " ")
wb$getEditToken(action_page)
}
function wb$elementsRemove(){
var el
for (var i=arguments.length-1; i>=0; i--) {
el = document.getElementById(arguments[i])
if (el)
el.parentNode.removeChild(el)
}
}