User:Gregbard/resolve.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Gregbard/resolve. |
function getElementsByClass(searchClass,node,tag) {
var classElements = new Array();
if (node == null)
node = document;
if (tag == null)
tag = '*';
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
for (i = 0, j = 0; i < elsLen; i++) {
if (pattern.test(els[i].className) ) {
classElements[j] = els[i];
j++;
}
}
return classElements;
}
// If TwinkleConfig aint exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
twinkleConfig = {};
}
if( typeof( TwinkleConfig.summaryRatedAd ) == 'undefined' ) {
TwinkleConfig.summaryRatedAd = " (script assisted)";
}
if( typeof( TwinkleConfig.watchResolvePages ) == 'undefined' ) {
TwinkleConfig.watchResolvePages = true;
}
function twinkleresolve() {
var links = getElementsByClass('editsection', document, 'span');
var editLinks = new Array();
for ( var i = 0; i < links.length; i++) {
editLinks.push(links[i].getElementsByTagName('a')[0]);
}
links = editLinks;
for (var i = 0; i < links.length; i++) {
var resolveLink = document.createElement('a');
resolveLink.title = "Resolve";
resolveLink.onclick = makeCallback(i + 1);
resolveLink.appendChild(document.createTextNode("unwatch"));
links[i].parentNode.insertBefore(resolveLink, links[i]);
var delim = document.createTextNode(" · ");
links[i].parentNode.insertBefore(delim, links[i]);
}
}
addOnloadHook(twinkleresolve);
function makeCallback(num) {
function twinkleResolveCallback() {
var Window = new SimpleWindow( 600, 250 );
Window.setTitle( "Resolve section" );
var form = new QuickForm( twinkleresolve.evaluate );
form.append( {
type: 'hidden',
name: 'secnum',
value: num
} );
var field = form.append( {
type: 'field',
label: 'Message: '
} );
field.append( {
type: 'textarea',
name: 'reason',
label: 'Reason:'
} );
form.append( { type:'submit' } );
var result = form.render();
Window.setContent( result );
Window.display();
}
return twinkleResolveCallback;
}
twinkleresolve.callbacks = {
main: function( self ) {
var form = self.responseXML.getElementById('editform');
var text = form.wpTextbox1.value;
if( text.search(/\{\{[mM]ath(s)? rating/) != -1 ) {
self.statelem.warn('Removing previous rating templates');
text = text.replace(/\{\{[mM]aths? rating([a-zA-Z |=])*\}\}/g, '');
if( text.search(/\{\{[mM]ath(s)? rating/) != -1 ) {
self.statelem.warn('Failed to remove previous templates, aborting');
alert(text);
return;
}
}
var postData = {
'wpMinoredit': undefined, // Per memo
'wpWatchthis': TwinkleConfig.watchRatedMathPages ? 'true' : undefined,
'wpStarttime': form.wpStarttime.value,
'wpEdittime': form.wpEdittime.value,
'wpAutoSummary': form.wpAutoSummary.value,
'wpEditToken': form.wpEditToken.value,
'wpSummary': "Rating article for WikiProject Mathematics. Quality: "
+ self.params.quality
+ " Priority: " + self.params.priority
+ " Field: " +self.params.field + " "
+ TwinkleConfig.summaryRatedAd,
'wpTextbox1': "\{\{maths rating|class=" + self.params.quality
+ "|priority=" + self.params.priority
+ "|field=" +self.params.field + "}}\n" + text
};
self.post( postData );
},
}
twinkleresolve.evaluate = function twinkleresolveCallbackEvaluate(e) {
var form = e.target;
var secnum = form.secnum.value;
var reason = form.reason.value;
alert(secnum);
alert(reason);
return;
wgPageName = wgPageName.replace(/_/g, ' ');
if ( wgNamespaceNumber == 0){
wgPageName = 'Talk:' + wgPageName;
}
Status.init( form );
var query = {
'title': wgPageName,
'action': 'submit'
};
Wikipedia.actionCompleted.redirect = wgPageName;
Wikipedia.actionCompleted.notice = "Tagging complete, reloading talk page";
var wikipedia_wiki = new Wikipedia.wiki('Tagging page', query,
twinklerate.callbacks.main);
wikipedia_wiki.params = { quality: quality, priority: priority, field: field};
wikipedia_wiki.followRedirect = false;
wikipedia_wiki.get();
}