MediaWiki:Wikibugs.js
Appearance
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
; 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", '\
<p><b>This system is <u>only</u> for reporting errors in Wikipedia articles</b>.</p>\
<div style="float:right;width:200px;padding:4px 10px;margin:2px 0px 0px 10px;font-size:90%;border:2px solid #900"><p><b>DO NOT REPORT</b> errors on other websites (such as <b>Facebook</b> or <b>Twitter</b>), as Wikipedia volunteers cannot help you with those.</p>\
<p>Please do not report missing articles here - instead go to <a href="' + link_tocreate + '">request an article be created</a>.</p></div>\
<p style="margin-top:0">If you\'ve found an error, try to fix it yourself, since <a href="' + link_wiki + '" target="_blank">wiki technology</a> means <strong><a href="//wiki.riteme.site/wiki/Help:Introduction" target="_blank">anyone can edit</a></strong>.</p>\
<p>Don\'t be afraid to do it yourself - one of Wikipedia\'s rules is "<a href="' + link_bebold + '" target="_blank">be bold in editing articles</a>"!.</p>\
<p>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.</p>\
<p style="color:red"><b><u>Do not</u> provide contact details such as telephone or email</b> (this is unnecessary and they would be public).</p>\
<p><a href="' + link_buglist + '" target="_blank">See current error reports</a>.</p>\
<p>See the <a href="//wikimediafoundation.org/wiki/Terms_of_Use" target="_blank">Terms of Use</a> and the <a href="//wikimediafoundation.org/wiki/Privacy_policy" target="_blank">Privacy Policy</a>.</p>\
')
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 + '<p><b>Note.</b> Your IP address is recorded in the public page history. To avoid this you can <a href="//wiki.riteme.site/w/index.php?title=Special:UserLogin&type=signup" target="_blank">create a user account</a>.</p>'
nel.innerHTML += '<p style="text-align:center;margin-top:15px">\
'+(can_edit ? '<input type="button" value="I\'ll try and fix it" onclick="wb$goToEditPage()" />' : '')+ '\
<input type="button" value="Report the error" onclick="wb$elementsRemove(\'specpop-info\')" /> \
<input type="button" value="Cancel" onclick="wb$elementsRemove(\'specpop-info\',\'specpop-form\',\'specpop-globhidden\',\'specpop-pos\')" />\
</p>'
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 = '<form id="fm1" action="'+action_url+'" method="post" enctype="multipart/form-data" onsubmit="return wb$checkForm(this)">\
Página:<br /><input type="text" name="wpSummary" id="wpSummary" width="320px" /><br />\
<input type="hidden" name="wpSection" value="new" />\
<input type="hidden" name="wpSave" value="Save" />\
<input type="hidden" id="Starttime" name="wpStarttime" value="" />\
<input type="hidden" id="Edittime" name="wpEdittime" value="" />\
<input type="hidden" id="EditToken" name="wpEditToken" value="" />\
<input type="hidden" id="AutoSummary" name="wpAutoSummary" value="" />\
<input type="hidden" name="wpScrolltop" value="0" />\
Mensaje:<br /><textarea id="TextBox" name="wpTextbox1" style="width:320px;height:200px" onfocus="if (this.value == wb$description) {this.value = \'\'}">' + wb$description + '</textarea><br />\
<input type="submit" id="submit" value="Submit" /> \
<input type="button" value="Cancel" onclick="wb$elementsRemove(\'specpop-form\',\'specpop-globhidden\',\'specpop-pos\')" />\
</form>'
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)
}
}