User:Magnus Manske/LinkFixr.js

if ( $.inArray(mw.config.get('wgAction'), ["edit", "submit" ]) !== -1) $( init_linkfixr );

function init_linkfixr { var tools = document.getElementById("p-tb") ; var out = '' ;

var ot = document.editform.wpTextbox1.value ; var t = get_linkfixr_text ( ot ) ; if ( t != ot ) { out += "LinkFixr" ; } else { out += " LinkFixr " ; } tools = tools.getElementsByTagName("ul")[0] ; tools.innerHTML += out ; }

function get_linkfixr_text ( ot ) { var t = ot ;

var ct ; do { ct = t ; t = t.split('"').join('"[[') ;   t = t.split('"').join(']]"') ;

t = t.split("'").join("'[[") ;   t = t.split("'").join("]]'") ;

t = t.split(',]]').join(']],') ; t = t.split(':]]').join(']]:') ; t = t.split(';]]').join(']];') ;

} while ( ct != t ) ;

return t ; }

function run_linkfixr { var ot = document.editform.wpTextbox1.value ; var t = get_linkfixr_text ( ot ) ; if ( t != ot ) { document.editform.wpTextbox1.value = t ; var s = document.editform.wpSummary.value ; if ( s != "" ) s += "; " ; s += "fixed link(s) using MediaWiki:LinkFixr.js" ; document.editform.wpSummary.value = s ; } }