User:Technical 13/Scripts/imageTagger.js
//<nowiki>
( function ( mw, $ ) {
function processResult( doAction ) {
mw.notify( 'Processing request to tag with "' + doAction + '".', { title: 'Processing...', autoHide: false } );
var pageid = mw.config.get( 'wgArticleId' );
new mw.Api().get( {
action: 'query',
pageids: pageid,
prop: 'revisions',
rvprop: 'content',
indexpageids: 1,
continue: ''
} ).done( function( pageContents ) {
mw.notify( 'Got page contents...', { title: 'Processing...', autoHide: false } );
var txt = pageContents.query.pages[ pageid ].revisions[ 0 ][ '*' ];
var summary = '';
if ( !txt ) return;
switch ( doAction ) {
case 'nfr' :
txt = '{{Non-free reduce}}\n\n' + txt;
summary += 'Tagging image - non free reduce - for image reduction as per non-free guideline [[Wikipedia:Image resolution]]';
break;
case 'ncd' :
txt.replace( /\{\{[\s\t\n\r]*([mc]t?w?c|needs[ -_]commons[ -_]category|((copy|move)[ -_]?)?to[ -_]?(wikimedia[ -_])?commons)[\s\t\n\r]*\}\}/ig, '' );
txt = '{{subst:ncd}}\n\n' + txt;
summary += 'Tagging image as on already on commons ({{[[Template:NowCommons|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 'pdc' :
if ( txt.match( 'Category:PD chem' ) !== null ) return;
txt = txt + '\n[[Category:PD chem]]\n';
summary += 'Tagging image to be in [[:Category:PD chem]]';
break;
case 'ccs' :
if ( txt.match( 'Category:Classified Chemical Structures' ) !== null ) return;
txt = txt + '\n[[Category:Classified Chemical Structures]]\n';
summary += 'Tagging image to be in [[:Category:Classified Chemical Structures]]';
break;
case 'struct' :
if ( txt.match( 'Category:Chemical structures' ) !== null ) return;
txt = txt + '\n[[Category:Chemical structures]]\n';
summary += 'Tagging image to be in [[:Category:Chemical structures]]';
break;
default :
mw.notify( 'There was an error processing your request.\n\n\t\t\t\t\tPlease try again.', { title: 'Error!', autoHide: false } );
return;
}
mw.notify( 'Posting new page contents...', { title: 'Processing...', autoHide: false } );
new mw.Api().postWithToken( 'edit', {
action: 'edit',
pageid: pageid,
text: txt,
summary: summary
} ).done( function( endResult ) {
mw.notify( '"' + doAction + '" was posted. Reloading page.', { title: 'Done!', autoHide: false } );
location.reload();
} );
} );
}
if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) {
var doNfr = mw.util.addPortletLink( 'p-cactions', '#', 'nfr', 'ca-nfr' );
$( doNfr ).click( function ( e ) {
e.preventDefault();
processResult( 'nfr' );
} );
var doMtc = mw.util.addPortletLink( 'p-cactions', '#', 'mtc', 'ca-mtc' );
$( doMtc ).click( function ( e ) {
e.preventDefault();
processResult( 'mtc' );
} );
var doNcd = mw.util.addPortletLink( 'p-cactions', '#', 'ncd', 'ca-ncd' );
$( doNcd ).click( function ( e ) {
e.preventDefault();
processResult( 'ncd' );
} );
var doPdc = mw.util.addPortletLink( 'p-cactions', '#', 'pdc', 'ca-pdc' );
$( doPdc ).click( function ( e ) {
e.preventDefault();
processResult( 'pdc' );
} );
var doCcs = mw.util.addPortletLink( 'p-cactions', '#', 'ccs', 'ca-ccs' );
$( doCcs ).click( function ( e ) {
e.preventDefault();
processResult( 'ccs' );
} );
var doStruct = mw.util.addPortletLink( 'p-cactions', '#', 'struct', 'ca-struct' );
$( doStruct ).click( function ( e ) {
e.preventDefault();
processResult( 'struct' );
} );
}
} ( mediaWiki, jQuery ) );
//</nowiki>
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.