User:Ronhjones/pdcV2.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:Ronhjones/pdcV2. |
//<nowiki>
( function ( mw, $ ) {
function processResult( doAction ) {
var txt = $( '#wpTextbox1' ).val();
var summary = $( '#wpSummary' ).val();
if ( !txt ) return;
switch ( doAction ) {
case 'nfr' :
txt = '{{Non-free'+' reduce}}\n' + txt;
summary += 'Tagging image - non free reduce - for image reduction as per non-free guideline [[Wikipedia:Image resolution]]';
break;
case 'nor' :
txt = '{{Non-free'+' no reduce}}\n' + txt;
summary += 'Tagging image for no reduction';
break;
case 'ncs' :
txt.replace( /\{\{[\s\t\n\r]*([mc]t?w?c|needs[ -_]commons[ -_]category|((copy|move)[ -_]?)?to[ -_]?(wikimedia[ -_])?commons)[\s\t\n\r]*\}\}/ig, '' );
txt = '{{Now'+' Commons}}\n\n' + txt;
summary += 'Tagging image as on already on commons ({{[[TemplateNowCommons|NowCommons]]}})';
break;
case 'mtc' :
txt = '\{\{Copy to Wikimedia Commons|human=' + mw.config.get( 'wgUserName' ) + '\}\}\n\n' + txt;
summary += 'Tagging image to be [[WP:MITTC|Copied to Wikimedia Commons]] ({{[[Template:Copy to Wikimedia Commons|Copy to Wikimedia Commons]]}})';
break;
case 'dnm' :
txt = '\{\{Do not move to Commons|' + 'reason=USonly\}\}\n' + txt;
summary += 'Tagging image "Do not move to Commons"';
break;
default :
alert( 'There was an error processing your request.\n\n\t\t\t\t\tPlease try again.' );
return;
}
$( '#wpTextbox1' ).val( txt );
$( '#wpSummary' ).val( summary );
$( '#editform' ).submit();// uncomment this line when you're sure it's working as intended and you won't have to hit [Save page]
}
function getEdit( doAction ) {
if ( doAction && ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' ) ) {
processResult( doAction );
} else {
location.assign( mw.util.getUrl( mw.config.get( 'wgPageName' ), { action: 'edit', runThis: doAction } ) );
}
}
if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) {
var runThis = mw.util.getParamValue( 'runThis' );
if ( runThis ) {
getEdit( runThis );
} else {
var doNfr = mw.util.addPortletLink( 'p-cactions', '#', 'nfr', 'ca-nfr' );
$( doNfr ).click( function ( e ) {
e.preventDefault();
getEdit( 'nfr' );
} );
var donor = mw.util.addPortletLink( 'p-cactions', '#', 'nor', 'ca-nor' );
$( donor ).click( function ( e ) {
e.preventDefault();
getEdit( 'nor' );
} );
var doMtc = mw.util.addPortletLink( 'p-cactions', '#', 'mtc', 'ca-mtc' );
$( doMtc ).click( function ( e ) {
e.preventDefault();
getEdit( 'mtc' );
} );
var dodnm = mw.util.addPortletLink( 'p-cactions', '#', 'dnm', 'ca-dnm' );
$( dodnm ).click( function ( e ) {
e.preventDefault();
getEdit( 'dnm' );
} );
var doNcs = mw.util.addPortletLink( 'p-cactions', '#', 'ncs', 'ca-ncs' );
$( doNcs ).click( function ( e ) {
e.preventDefault();
getEdit( 'ncs' );
} );
}
}
} ( mediaWiki, jQuery ) );
//</nowiki>