User:AzaToth/testcase.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:AzaToth/testcase. |
// If TwinkleConfig aint exist.
if( typeof( TwinkleConfig ) == 'undefined' ) {
TwinkleConfig = function() {};
}
/**
TwinkleConfig.summaryAd (string)
If ad should be added or not to summary, default [[WP:TWINKLE|TWINKLE]]
*/
if( typeof( TwinkleConfig.summaryAd ) == 'undefined' ) {
TwinkleConfig.summaryAd = " using [[WP:TWINKLE|TW]]";
}
/**
TwinkleConfig.toolboxButtons (string)
If id defined in this array, the button of the action is located inthe toolbox instead of in
the actions bar.
*/
if( typeof( TwinkleConfig.toolboxButtons ) == 'undefined' ) {
TwinkleConfig.toolboxButtons = [];
}
function twinkleXfdButton() {
if( wgNamespaceNumber < 0 || wgCurRevisionId == false ) {
return;
}
addPortletLink( chooseBox( 'tw-xfd', TwinkleConfig.toolboxButtons ), "javascript:testcase()", "testcase", "tw-testcase", "Testcase", "");
}
addOnloadHook(twinkleXfdButton);
function num2order( num ) {
switch( num ) {
case 1: return '';
case 2: return '2nd';
case 3: return '3rd';
default: return num + 'th';
}
}
function createOption( data ) {
var option = document.createElement( 'option' );
option.setAttribute( 'value', data.value );
if( data.selected ) {
option.setAttribute( 'selected', 'selected' );
}
option.setAttribute( 'label', data.label );
option.appendChild( document.createTextNode( data.label ) );
return option;
}
function createInput( data ) {
var div = document.createElement( data.elem || 'span' );
var input = document.createElement( 'input' );
input.setAttribute( 'value', data.value );
input.setAttribute( 'name', data.name );
input.setAttribute( 'id', data.id );
input.setAttribute( 'type', data.type );
if( data.size ) {
input.setAttribute( 'size', data.size );
}
if( data.checked ) {
input.setAttribute( 'checked', 'checked' );
}
if( data.disabled ) {
input.setAttribute( 'disabled', 'disabled' );
}
if( data.event && data.type == 'button' ){
input.addEventListener( 'click', data.event, true );
}
if( data.type == 'button' || data.type == 'submit' || data.type == 'reset' ) {
div.appendChild( input );
} else {
var label = document.createElement( 'label' );
label.setAttribute( 'for', data.id );
label.appendChild( document.createTextNode( data.text ) );
if( [ 'radio', 'checkbox' ].indexOf( data.type ) != -1 ) {
div.appendChild( input );
div.appendChild( label );
} else {
div.appendChild( label );
div.appendChild( input );
}
}
return div;
}
function testcase() {
Window = new SimpleWindow( 600, 300 );
Window.setTitle( "Testing testing" );
div = document.createElement( 'div' );
Window.setContent( div );
wndow.display();
Status.init( div );
wgPageName = wgPageName.replace( '_', ' ' ); // for queen/king/whatever and country!
Status.status( 'Tagging all pages including said image' );
var xmlhttp = sajax_init_object();
xmlhttp.query = {
'action': 'query',
'list': 'imageusage',
'titles': wgPageName,
'iulimit': 50, // test 500, // Maximum, if it's more than 500 images, ignore the rest for now...
'format': 'xml'
};
var link = document.createElement( 'a' );
link.setAttribute( 'href', wgServer + wgScriptPath + '/api.php?' + QueryString.create( xmlhttp.query ) );
link.appendChild( document.createTextNode( wgServer + wgScriptPath + '/api.php?' + QueryString.create( xmlhttp.query ) ) );
Status.info( ["going for ", link ] );
xmlhttp.overrideMimeType('text/xml');
xmlhttp.open( 'GET' , wgServer + wgScriptPath + '/api.php?' + QueryString.create( xmlhttp.query ), true);
xmlhttp.onload = function() {
var xmlDoc = this.responseXML;
var nsResolver = xmlDoc.createNSResolver( xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement);
var count = xmlDoc.evaluate( 'count(//imageusage/iu)', xmlDoc, nsResolver, XPathResult.ANY_TYPE, null );
Status.info( "got " + count.numberValue + " nodes" );
var snapshot = xmlDoc.evaluate('//imageusage/iu/@title', xmlDoc, nsResolver, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );
for ( var i = 0; i < snapshot.snapshotLength; ++i ) {
var title = snapshot.snapshotItem(i).value;
var xmlhttp = sajax_init_object();
xmlhttp.current = title;
xmlhttp.query = {
'title': title,
'action': 'submit'
};
xmlhttp.overrideMimeType('text/xml');
xmlhttp.open( 'GET' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( xmlhttp.query ), true);
xmlhttp.onload = function() {
var form = this.responseXML.getElementById('editform');
var text = form.wpTextbox1.value;
var old_text = text;
var re = new RegExp( "(\\[\\[" + wgPageName + ".*?)(\\]\\])", 'g' ); // simple regexp, might not always work
text = text.replace( re, "$1\{\{ifdc|" + wgPageName + "\}\}$2" );
if( text == old_text ) {
Status.info( 'No tag for ' + this.current );
return;
} else {
Status.info( 'Added tag for ' + this.current );
}
var postData = {
'wpMinoredit': form.wpMinoredit.checked,
'wpWatchthis': form.wpWatchthis.checked,
'wpStarttime': form.wpStarttime.value,
'wpEdittime': form.wpEdittime.value,
'wpAutoSummary': form.wpAutoSummary.value,
'wpEditToken': form.wpEditToken.value,
'wpSummary': "Adding notice of possible deletion of image [[:" + wgPageName + ']].' + TwinkleConfig.summaryAd,
'wpTextbox1': text
};
}
xmlhttp.send( null );
}
}
xmlhttp.send( null );
}