Pretty sure you can do this without completely replacing the core wplink.js file (which is dangerous because of the issues discussed in this thread). This method uses some javascript trickery in order to call all the original wplink functions, but modify their output.
Here’s example plugin code specifically for the tinymce wplink replacement. Feel free to use it in your plugin:
nofollow.php:
// Add the javascript that extends TinyMCE plugin wplink.js.
function wplink_nofollow_enqueue_scripts( $admin_page ) {
// Only load on edit pages.
if ( 'edit.php' !== $admin_page && 'post-new.php' !== $admin_page ) {
return;
}
wp_enqueue_script( 'wplink_nofollow', plugin_dir_url( __FILE__ ) . 'wplink-nofollow.js' );
}
add_filter( 'admin_enqueue_scripts', 'wplink_nofollow_enqueue_scripts' );
wplink-nofollow.js:
( function ( $ ) {
$( document ).ready( function () {
// Add a function that inserts the nofollow checkbox in the wplink modal.
wpLink.addNofollowCheckbox = function () {
var html = '<br /><label><span> </span><input type="checkbox" id="link-nofollow-checkbox" /> Add <code>rel="nofollow"</code> to link</label>';
$('#wp-link .link-target').append( html );
}
// Extend wpLink.getAttrs to include rel=nofollow.
var coreGetAttrs = wpLink.getAttrs;
wpLink.getAttrs = function () {
var attributes = coreGetAttrs.apply( coreGetAttrs );
if ( $( '#link-nofollow-checkbox' ).is( ':checked' ) ) {
attributes.rel = 'nofollow';
}
return attributes;
}
// Add the nofollow checkbox to the wplink modal (on edit.php and post-new.php pages).
wpLink.addNofollowCheckbox();
});
})( jQuery );
Much simpler!