Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
// <nowiki>/* ========================================================================== *\* ** MediaWiki:PermissionOTRS.js ** Maintainer: [[User:Bryan]] ** Copyright (c) 2007 Bryan Tong Minh. ** Licensed under the terms of the MIT license ** ** ========================================================================== ** ** This scripts allows you to add OTRS permission links in an easy manner. ** It will replace {{OTRS pending}} by the correct permission template. ** If no occurrence of {{OTRS pending}} 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' ); ** *\* ========================================================================== *//* Modified by myself */functionaddPermission(ticket){varreq=sajax_init_object();req.open('GET',wgScriptPath+'/api.php?action=query&prop=info|revisions&'+'format=json&intoken=edit&rvprop=content|timestamp&titles='+encodeURIComponent(mw.config.get('wgPageName')),false);req.send(null);varinfo=eval('('+req.responseText+')');for(varkeyininfo['query']['pages']){varpage=info['query']['pages'][key];vartoken=page['edittoken'];varcontent=page['revisions'][0]['*'];vareditTime=page['revisions'][0]['timestamp'].replace(/[^0-9]/g,'');varrOTRS=newRegExp('\\{\\{Otrs[_ ]pending\\}\\}','i');if(rOTRS.test(content)){content=content.replace(rOTRS,'{{PermissionOTRS|id='+ticket+'}}');}else{varrPermission=newRegExp('\\n\\|Permission[ \\t]*=.*','i');if(rPermission.test(content)){content=content.replace(rPermission,'\n|Permission={{PermissionOTRS|id='+ticket+'}}');}else{alert('No suitable place found to insert template!');return;}}varrNPD=newRegExp('\\{\\{no permission since.+\n','i');if(rNPD.test(content))content=content.replace(rNPD,'');varpostdata='';postdata+='wpTextbox1='+encodeURIComponent(content);postdata+='&wpSummary='+encodeURIComponent('Adding [[Commons:OTRS|OTRS]] permission using modified [[MediaWiki:PermissionOTRS.js|PermissionOTRS.js]]');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();document.open();document.write(req.responseText);return;}}functionOTRS(){varticket=prompt('Ticket link?');if(ticket)addPermission(ticket);}$(function(){if(wgNamespaceNumber==6){//NS_IMAGEvart=document.getElementById('t-whatlinkshere');if(!t)return;varli=document.createElement('li');vara=document.createElement('a');a.setAttribute('href','javascript:void(OTRS())');a.appendChild(document.createTextNode('PermissionOTRS'));li.appendChild(a);t.parentNode.appendChild(li);}});// </nowiki>