User:Technical 13/Scripts/helpOTRS.js

// ( function ( mw, $ ) {	function processResult( doAction ) {		var ticket = prompt( 'Ticket number or process with empty parameter if left blank: ',  );		if ( ticket === null || ticket ===  ) ticket = '';		mw.notify( 'Processing request to tag with "' + doAction + '" with Ticket: ' + ticket, { title: 'Processing...', autoHide: false } );		var pageid = mw.config.get( 'wgArticleId' );		new mw.Api.get( { action: 'query', prop: 'revisions', rvprop: 'content', pageids: pageid } ).done( function( pageContents ) { mw.notify( 'Got page contents...', { title: 'Processing...', autoHide: false } ); var txt = pageContents.query.pages[ pageid ].revisions[ 0 ][ '*' ]; var summary = 'Marked as '; var OtrsRep = , PermRep = ; switch ( doAction ) { case 'perm' : OtrsRep = ''; PermRep = '\n|Permission='; summary += ' done'; break; case 'queued' : OtrsRep = ''; PermRep = '\n|Permission='; summary += ' and queued'; break; case 'received' : OtrsRep = ''; PermRep = '\n|Permission='; summary += ''; 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; }			summary += ' using helpOTRS.'; var rOTRS = new RegExp( /\{\{Otrs[_ ]pending\}\}/i ); if ( rOTRS.test( txt ) ) { txt = txt.replace( rOTRS, OtrsRep ); } else { var rPermission = new RegExp( /\n\| *Permission[ \t]*=.*/i ); if ( rPermission.test( txt ) ) { txt = txt.replace( rPermission, PermRep ); } else { mw.notify( 'No suitable place found to insert template!',						{ title: 'Error!', autoHide: false } ); return; }			}			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 perm = mw.util.addPortletLink( 'p-tb', '#', 'OTRSpermission' ); $( perm ).click( function ( e ) {			e.preventDefault;			processResult( 'perm' );		} ); var queued = mw.util.addPortletLink( 'p-tb', '#', 'Queued OTRS' ); $( queued ).click( function ( e ) {			e.preventDefault;			processResult( 'queued' );		} ); var received = mw.util.addPortletLink( 'p-tb', '#', 'Received OTRS' ); $( received ).click( function ( e ) {			e.preventDefault;			processResult( 'received' );		} ); } } ( mediaWiki, jQuery ) ); //