User:Jackmcbarn/editProtectedHelper.js and User:Jackmcbarn/editProtectedHelper-unstable.js: Difference between pages
(Difference between pages)
Content deleted Content added
this is functional enough now |
Jackmcbarn (talk | contribs) avoid deprecated load |
||
Line 39: | Line 39: | ||
// Global variable. In onParsoidDomReceived, this is set |
// Global variable. In onParsoidDomReceived, this is set |
||
// to the ETag header so that we can pass it back later |
// to the ETag header so that we can pass it back later |
||
// in convertModifiedDom. |
// in convertModifiedDom. |
||
var gEtag; |
var gEtag; |
||
Line 158: | Line 158: | ||
parsoidObj = e.data; |
parsoidObj = e.data; |
||
parsoidObj.resultObj.text('Preparing new wikitext...'); |
parsoidObj.resultObj.text('Preparing new wikitext...'); |
||
$(parsoidObj).before(parsoidObj.templateMarker); |
|||
// Don't break about continuity - get to the first |
|||
// element of the tranclusion block |
|||
while (editReqTpl && editReqTpl.attr('data-mw') === undefined) { |
|||
editReqTpl = editReqTpl.prev(); |
|||
⚫ | |||
⚫ | |||
console.log("Error 3: Unexpected error traversing DOM. Cannot save!"); |
|||
⚫ | |||
⚫ | |||
var error = false; |
|||
editReqTpl.before(parsoidObj.templateMarker); |
|||
$('h1,h2,h3,h4,h5,h6,.editrequest', parsoidDom).each(function() { |
$('h1,h2,h3,h4,h5,h6,.editrequest', parsoidDom).each(function() { |
||
var obj = $(this); |
var obj = $(this); |
||
if(!obj.hasClass('editrequest')) { |
if(!obj.hasClass('editrequest')) { |
||
// |
// a heading |
||
if(obj.closest('[typeof="mw:Transclusion"]').length) { |
if(obj.closest('[typeof="mw:Transclusion"]').length) { |
||
// it's from a template transclusion. ignore |
// it's from a template transclusion. ignore |
||
Line 179: | Line 168: | ||
} |
} |
||
if(obj.add(parsoidObj)[0] === this) { |
if(obj.add(parsoidObj)[0] === this) { |
||
⚫ | |||
// (section) heading shows up before the edit request banner. |
|||
⚫ | |||
parsoidObj.section = obj; |
parsoidObj.section = obj; |
||
return true; |
return true; |
||
} |
} |
||
⚫ | |||
⚫ | |||
⚫ | |||
} else { |
} else { |
||
⚫ | |||
// obj is a (potentially different) edit request. |
|||
⚫ | |||
⚫ | |||
return true; |
|||
} else { |
|||
⚫ | |||
} |
|||
} |
|||
if (obj.attr('about')) { |
|||
// Don't break about continuity - get to the first |
|||
// element of the tranclusion block |
|||
while (obj && obj.attr('data-mw') === undefined) { |
|||
obj = obj.prev(); |
|||
} |
|||
if (!obj) { |
|||
error = true; // Don't know what happened here! |
|||
return false; |
|||
} |
|||
} |
} |
||
obj.before(parsoidObj.responseMarker); |
obj.before(parsoidObj.responseMarker); |
||
Line 208: | Line 182: | ||
return false; |
return false; |
||
}); |
}); |
||
⚫ | |||
if (error) { |
|||
⚫ | |||
console.log("Error 4: Unexpected error traversing DOM. Cannot save!"); |
|||
return; |
|||
} |
|||
⚫ | |||
// Do this before removing the edit req (template) |
|||
⚫ | |||
parsoidObj.section.remove(); |
parsoidObj.section.remove(); |
||
} |
} |
||
// Remove the edit req (template) |
|||
$('[about="' + $(parsoidObj).attr('about').replace('\\', '\\\\').replace('"', '\\"') + '"]', parsoidDom).remove(); |
$('[about="' + $(parsoidObj).attr('about').replace('\\', '\\\\').replace('"', '\\"') + '"]', parsoidDom).remove(); |
||
$.ajax({ |
$.ajax({ |
||
Line 237: | Line 205: | ||
var form = $('<form class="editProtectedHelper" style="display: none" />'); |
var form = $('<form class="editProtectedHelper" style="display: none" />'); |
||
form.append('<style scoped>.mw-ui-input { background-color: white; }</style>'); |
form.append('<style scoped>.mw-ui-input { background-color: white; }</style>'); |
||
⚫ | form.append('<label>Level: <select name="level" class="mw-ui-input mw-ui-input-inline"><option value="semi"' + selectedLevel[level][0] + '>Semi-protected</option><option value="extended"' + selectedLevel[level][1] + '>Extended-confirmed-protected</option><option value="template"' + selectedLevel[level][2] + '>Template-protected</option><option value="full"' + selectedLevel[level][3] + '>Fully protected</option><option value="interface"' + selectedLevel[level][4] + '>Interface-protected</option></select></label> '); |
||
if(selectedLevel[level]) { |
|||
⚫ | |||
} |
|||
if(force) { |
if(force) { |
||
form.append('<label>Disable protection level autodetection (use only if necessary): <input type="checkbox" name="force" checked="checked" /></label> ' ); |
form.append('<label>Disable protection level autodetection (use only if necessary): <input type="checkbox" name="force" checked="checked" /></label> ' ); |
||
Line 293: | Line 259: | ||
} |
} |
||
function parsoidSetupFieldsForTemplate(index) { |
function parsoidSetupFieldsForTemplate(index) { |
||
var |
var obj = $(this); |
||
var |
var data_mw = obj.attr('data-mw'); |
||
⚫ | |||
⚫ | |||
// Get to the first element of the tranclusion block |
|||
// to correctly recover 'data-mw'. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
return; |
return; |
||
} |
} |
||
var data_mw = obj.attr('data-mw'); |
|||
var done = data_mw !== undefined; |
|||
while (!done) { |
|||
obj = obj.prev(); |
|||
if (!obj || obj.attr('about') !== aboutId) { |
|||
console.log("Error 2: The HTML seems broken. Either the script is broken and needs an update or this is a Parsoid bug."); |
|||
return; |
|||
} |
|||
data_mw = obj.attr('data-mw'); |
|||
done = data_mw !== undefined; |
|||
} |
|||
data_mw = JSON.parse(data_mw); |
data_mw = JSON.parse(data_mw); |
||
var |
var templateName = data_mw.parts[0].template.target.wt; |
||
⚫ | |||
if (autoFixLevel) { |
|||
⚫ | |||
switch(this.id) { |
switch(this.id) { |
||
case 'editsemiprotected': |
case 'editsemiprotected': |
||
Line 339: | Line 290: | ||
params[key] = data_mw.parts[0].template.params[key].wt; |
params[key] = data_mw.parts[0].template.params[key].wt; |
||
} |
} |
||
⚫ | |||
// this only runs on numerical parameters |
// this only runs on numerical parameters |
||
params.forEach(function(value, key) { |
params.forEach(function(value, key) { |
||
Line 346: | Line 297: | ||
} |
} |
||
}); |
}); |
||
⚫ | |||
var pagename = params.join('|').replace(/^\|+|\|+$/g, '').replace(/\|+/g, '|'); |
var pagename = params.join('|').replace(/^\|+|\|+$/g, '').replace(/\|+/g, '|'); |
||
var answered = yesno(params.ans || params.answered, true); |
var answered = yesno(params.ans || params.answered, true); |
||
Line 388: | Line 339: | ||
url: '/api/rest_v1/page/html/' + encodeURIComponent(mw.config.get('wgPageName')) + '/' + mw.config.get('wgRevisionId'), |
url: '/api/rest_v1/page/html/' + encodeURIComponent(mw.config.get('wgPageName')) + '/' + mw.config.get('wgRevisionId'), |
||
headers: { |
headers: { |
||
Accept: 'text/html; charset=utf-8; profile="https://www.mediawiki.org/wiki/Specs/HTML/2. |
Accept: 'text/html; charset=utf-8; profile="https://www.mediawiki.org/wiki/Specs/HTML/2.0.0"', |
||
'Api-User-Agent': 'editProtectedHelper (https://en.wikipedia.org/wiki/User:Jackmcbarn/editProtectedHelper)' |
'Api-User-Agent': 'editProtectedHelper (https://en.wikipedia.org/wiki/User:Jackmcbarn/editProtectedHelper)' |
||
}, |
}, |