User:Topbanana/RLRL SR Utility.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:Topbanana/RLRL SR Utility. |
Gerbrant = {fw: {load: [
"Gerbrant.edit.regexReplace"
]}}
document.write('<script type="text/javascript" src="http://en.wikipedia.org/w/index.php?title=User:Gerbrant/fw.js&action=raw&ctype=text/javascript&dontcountme=s"><\u002fscript>');
function RLRL_SR_Utility()
{
// If we're not editing, do nothing
if ( !document.getElementById("editform") )
return;
// Check for and extract 'RLRLS' (search) and 'RLRLR' (replace) parameters
// Method based on 'gup' (http://www.netlobo.com/url_query_string_javascript.html)
param_match = new RegExp( '[\\?&]RLRLS=([^&#]*)' ).exec( window.location.href );
parSearch = param_match ? param_match[1] : '';
param_match = new RegExp( '[\\?&]RLRLR=([^&#]*)' ).exec( window.location.href );
parReplace = param_match ? param_match[1] : '';
// If we've not got a useful set of parameters, give up
if( parSearch.length == 0 || parReplace.length == 0 )
return;
// Okay, do some work
// Ideally this would use a clever existing system with preview such as User:Gerbrant/edit/regexReplace.js
// Gerbrant.regexReplace.replace( parSearch, true, parReplace, false );
// Gerbrant.regexReplace.tbRegex.value = parSearch;
// Gerbrant.regexReplace.tbRegex.findMatches();
/*
txt = document.editform.wpTextbox1.value;
sr_match = new RegExp( '\\[' + parSearch + '[\\]\\|]' );
document.editform.wpTextbox1.value = txt.replace( sr_match, parReplace );
*/
// Post up a summary of what's been done
document.getElementById('editpage-copywarn').innerHTML +=
'<B>v0.18: RLRL Search and Replace:<BR>' +
'Searching for "' + parSearch + '", to replace with "' + parReplace + '"<BR>' +
'</B>';
// Populate the edit summary
document.forms.editform.wpSummary.value =
'Link repair (' + parSearch + ' -> ' + parReplace + ') - [[Wikipedia:WikiProject Red Link Recovery|You can help!]]';
};
addOnloadHook( RLRL_SR_Utility );