User:Microchip08/PermissionOTRS.js

// /* ========================================================================== *\ \* ========================================================================== */ var otrs = { addTicket: function ( template, ticket, reason ) { var req = sajax_init_object; req.open( 'GET', wgScriptPath + '/api.php?action=query&prop=info|revisions&' +			'format=json&intoken=edit&rvprop=content|timestamp&titles=' +			encodeURIComponent( wgPageName ), false ); req.send( null ); var info = JSON.parse( req.responseText ); for ( var key in info.query.pages ) { var page = info.query.pages[key]; var token = page.edittoken; var content = page.revisions[0]['*']; var editTime = page.revisions[0].timestamp.replace( /[^0-9]/g, '' );
 * MediaWiki:PermissionOTRS.js                                               *
 * Maintainer: User:Bryan                                                *
 * Copyright (c) 2007 Bryan Tong Minh.                                       *
 * Licensed under the terms of the MIT license                               *
 * Forked from https://en.wikipedia.org/wiki/User:Mdann52/PermissionOTRS.js  *
 * This scripts allows you to add OTRS permission links in an easy manner.   *
 * It will replace by the correct permission template.      *
 * If no occurrence of can be found, it will OVERWRITE      *
 * the permission field of the information template. If the information      *
 * template is not available, the script will fail.                          *
 * Tested with: Mozilla Firefox 2.0.0.6                                      *
 * Install this script by adding the following code to your monobook.js:     *
 * // MediaWiki:PermissionOTRS.js                                       *
 * importScript( 'MediaWiki:PermissionOTRS.js' );                           *
 * template is not available, the script will fail.                          *
 * Tested with: Mozilla Firefox 2.0.0.6                                      *
 * Install this script by adding the following code to your monobook.js:     *
 * // MediaWiki:PermissionOTRS.js                                       *
 * importScript( 'MediaWiki:PermissionOTRS.js' );                           *
 * Install this script by adding the following code to your monobook.js:     *
 * // MediaWiki:PermissionOTRS.js                                       *
 * importScript( 'MediaWiki:PermissionOTRS.js' );                           *

if ( reason ) { ticket += '|reason=' + reason; }			var rOTRS = new RegExp( '\\{\\{Otrs[_ ]pending\\}\\}', 'i' ); if ( rOTRS.test( content ) ) { content = content.replace(rOTRS, ''); } else { var rPermission = new RegExp('\\n\\|Permission[ \\t]*=.*', 'i'); if ( rPermission.test(content) ) { content = content.replace(rPermission, '\n|Permission='); } else { alert('No suitable place found to insert template!'); return; }			}			var postdata = 'wpTextbox1=' + encodeURIComponent(content); postdata += '&wpSummary=' + encodeURIComponent('Adding OTRS tag '); postdata += '&wpSave=save'; postdata += '&wpEditToken=' + encodeURIComponent(token); postdata += '&wpEdittime=' + editTime; postdata += '&wpStarttime=' + editTime;

req = sajax_init_object; req.open('POST', wgScriptPath + '/index.php?action=submit&title=' + encodeURIComponent(mw.config.get('wgPageName')), false); req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); req.setRequestHeader('Content-Length', postdata.length); req.send(postdata);

document.close; location.href = location.href; //Reload return; }	},

addPermission: function  { var ticket = prompt('Ticket number?'); if (ticket) otrs.addTicket( 'PermissionOTRS', ticket ); },

addReceived: function { var ticket = prompt( 'Ticket number?' ); if ( ticket ) { var reason = prompt( 'You were unable to process this ticket because…' ); otrs.addTicket( 'OTRS received', ticket, reason ); }	},	init: function { if (wgNamespaceNumber == 6) { //NS_IMAGE var t = document.getElementById('t-whatlinkshere'); if (!t) return; var templates = [ {					"caption": "OTRS accepted", "action": "addPermission" },				{					"caption": "OTRS received", "action": "addReceived" }			];			for ( var i = 0; i < templates.length; i++ ) { var li = document.createElement('li'); var a = document.createElement('a'); a.setAttribute( 'href', 'javascript:otrs.' + templates[i].action ); a.appendChild( document.createTextNode( templates[i].caption ) ); li.appendChild(a); t.parentNode.appendChild(li); }		}	} };

addOnloadHook( otrs.init ); //